184
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <QtGui>
|
|
20 |
#include <QStringList>
|
|
21 |
#include <QProcess>
|
|
22 |
#include <QDir>
|
|
23 |
#include <QPixmap>
|
|
24 |
#include <QRegExp>
|
|
25 |
#include <QIcon>
|
|
26 |
#include <QFile>
|
|
27 |
#include <QTextStream>
|
|
28 |
|
|
29 |
#include "hwform.h"
|
|
30 |
#include "game.h"
|
|
31 |
#include "team.h"
|
|
32 |
#include "netclient.h"
|
|
33 |
#include "teamselect.h"
|
|
34 |
#include "gameuiconfig.h"
|
|
35 |
#include "pages.h"
|
|
36 |
#include "hwconsts.h"
|
|
37 |
|
|
38 |
HWForm::HWForm(QWidget *parent)
|
|
39 |
: QMainWindow(parent)
|
|
40 |
{
|
|
41 |
ui.setupUi(this);
|
|
42 |
|
|
43 |
config = new GameUIConfig(this);
|
|
44 |
|
|
45 |
QStringList teamslist = config->GetTeamsList();
|
|
46 |
|
|
47 |
if(teamslist.empty()) {
|
|
48 |
HWTeam defaultTeam("DefaultTeam");
|
|
49 |
defaultTeam.SaveToFile();
|
|
50 |
teamslist.push_back("DefaultTeam");
|
|
51 |
}
|
|
52 |
|
|
53 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it )
|
|
54 |
{
|
|
55 |
ui.pageMultiplayer->teamsSelect->addTeam(*it);
|
|
56 |
ui.pageOptions->CBTeamName->addItem(*it);
|
|
57 |
}
|
|
58 |
|
|
59 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer()));
|
|
60 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup()));
|
|
61 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer()));
|
|
62 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
|
|
63 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet()));
|
187
|
64 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo()));
|
184
|
65 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close()));
|
|
66 |
|
|
67 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
68 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame()));
|
|
69 |
|
|
70 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
|
|
71 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
|
|
72 |
|
|
73 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
74 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
|
|
75 |
|
|
76 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
77 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
|
|
78 |
|
|
79 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
80 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
|
|
81 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
|
|
82 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
|
|
83 |
|
|
84 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
85 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect()));
|
|
86 |
|
|
87 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToNetChat()));
|
|
88 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam()));
|
|
89 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame()));
|
|
90 |
|
|
91 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
|
|
92 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin()));
|
|
93 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate()));
|
|
94 |
|
187
|
95 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
96 |
|
184
|
97 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
|
|
98 |
}
|
|
99 |
|
|
100 |
void HWForm::GoToMain()
|
|
101 |
{
|
|
102 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
|
|
103 |
}
|
|
104 |
|
|
105 |
void HWForm::GoToSinglePlayer()
|
|
106 |
{
|
|
107 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
|
|
108 |
}
|
|
109 |
|
|
110 |
void HWForm::GoToSetup()
|
|
111 |
{
|
|
112 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
113 |
}
|
|
114 |
|
187
|
115 |
void HWForm::GoToInfo()
|
|
116 |
{
|
|
117 |
ui.Pages->setCurrentIndex(ID_PAGE_INFO);
|
|
118 |
}
|
|
119 |
|
184
|
120 |
void HWForm::GoToMultiplayer()
|
|
121 |
{
|
|
122 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(config->GetTeamsList());
|
|
123 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
|
|
124 |
}
|
|
125 |
|
|
126 |
void HWForm::GoToDemos()
|
|
127 |
{
|
|
128 |
QDir tmpdir;
|
|
129 |
tmpdir.cd(cfgdir->absolutePath());
|
|
130 |
tmpdir.cd("Demos");
|
|
131 |
tmpdir.setFilter(QDir::Files);
|
|
132 |
ui.pagePlayDemo->DemosList->clear();
|
|
133 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
|
|
134 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
|
|
135 |
}
|
|
136 |
|
|
137 |
void HWForm::GoToNet()
|
|
138 |
{
|
|
139 |
ui.Pages->setCurrentIndex(ID_PAGE_NET);
|
|
140 |
}
|
|
141 |
|
|
142 |
void HWForm::GoToNetChat()
|
|
143 |
{
|
|
144 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT);
|
|
145 |
}
|
|
146 |
|
|
147 |
void HWForm::NewTeam()
|
|
148 |
{
|
|
149 |
tmpTeam = new HWTeam("unnamed");
|
|
150 |
tmpTeam->SetToPage(this);
|
|
151 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
152 |
}
|
|
153 |
|
|
154 |
void HWForm::EditTeam()
|
|
155 |
{
|
|
156 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
|
|
157 |
tmpTeam->LoadFromFile();
|
|
158 |
tmpTeam->SetToPage(this);
|
|
159 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
160 |
}
|
|
161 |
|
|
162 |
void HWForm::TeamSave()
|
|
163 |
{
|
|
164 |
tmpTeam->GetFromPage(this);
|
|
165 |
tmpTeam->SaveToFile();
|
|
166 |
delete tmpTeam;
|
|
167 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
168 |
}
|
|
169 |
|
|
170 |
void HWForm::TeamDiscard()
|
|
171 |
{
|
|
172 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
173 |
}
|
|
174 |
|
|
175 |
void HWForm::SimpleGame()
|
|
176 |
{
|
|
177 |
game = new HWGame(config, ui.pageLocalGame->gameCFG);
|
|
178 |
game->StartQuick();
|
|
179 |
}
|
|
180 |
|
|
181 |
void HWForm::PlayDemo()
|
|
182 |
{
|
|
183 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
|
|
184 |
if (!curritem)
|
|
185 |
{
|
|
186 |
QMessageBox::critical(this,
|
|
187 |
tr("Error"),
|
|
188 |
tr("Please, select demo from the list above"),
|
|
189 |
tr("OK"));
|
|
190 |
return ;
|
|
191 |
}
|
|
192 |
game = new HWGame(config, 0);
|
|
193 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1");
|
|
194 |
}
|
|
195 |
|
|
196 |
void HWForm::NetConnect()
|
|
197 |
{
|
|
198 |
hwnet = new HWNet(config);
|
|
199 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
|
|
200 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
|
|
201 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
|
|
202 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
|
|
203 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
|
|
204 |
config->SaveOptions();
|
|
205 |
}
|
|
206 |
|
|
207 |
void HWForm::NetDisconnect()
|
|
208 |
{
|
|
209 |
hwnet->Disconnect();
|
|
210 |
GoToNet();
|
|
211 |
}
|
|
212 |
|
|
213 |
void HWForm::AddGame(const QString & chan)
|
|
214 |
{
|
|
215 |
ui.pageNetChat->ChannelsList->addItem(chan);
|
|
216 |
}
|
|
217 |
|
|
218 |
void HWForm::NetGameEnter()
|
|
219 |
{
|
|
220 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG);
|
|
221 |
}
|
|
222 |
|
|
223 |
void HWForm::NetJoin()
|
|
224 |
{
|
|
225 |
hwnet->JoinGame("#hw");
|
|
226 |
}
|
|
227 |
|
|
228 |
void HWForm::NetCreate()
|
|
229 |
{
|
|
230 |
hwnet->JoinGame("#hw");
|
|
231 |
}
|
|
232 |
|
|
233 |
void HWForm::NetAddTeam()
|
|
234 |
{
|
|
235 |
HWTeam team("DefaultTeam");
|
|
236 |
team.LoadFromFile();
|
|
237 |
hwnet->AddTeam(team);
|
|
238 |
}
|
|
239 |
|
|
240 |
void HWForm::NetStartGame()
|
|
241 |
{
|
|
242 |
hwnet->StartGame();
|
|
243 |
}
|
|
244 |
|
|
245 |
void HWForm::ChangeInNetTeams(const QStringList & teams)
|
|
246 |
{
|
|
247 |
ui.pageNetGame->listNetTeams->clear();
|
|
248 |
ui.pageNetGame->listNetTeams->addItems(teams);
|
|
249 |
}
|
|
250 |
|
|
251 |
void HWForm::StartMPGame()
|
|
252 |
{
|
|
253 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG);
|
|
254 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams();
|
|
255 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
|
256 |
game->AddTeam(it->TeamName, ui.pageMultiplayer->teamsSelect->numHedgedogs(it->TeamName));
|
|
257 |
}
|
|
258 |
game->StartLocal();
|
|
259 |
}
|