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 |
|
245
|
45 |
UpdateTeamsLists();
|
184
|
46 |
|
|
47 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer()));
|
|
48 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup()));
|
|
49 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer()));
|
|
50 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
|
|
51 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet()));
|
187
|
52 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo()));
|
184
|
53 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close()));
|
|
54 |
|
|
55 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
56 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame()));
|
|
57 |
|
|
58 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
|
|
59 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
|
|
60 |
|
|
61 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
62 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
|
|
63 |
|
|
64 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
65 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
|
|
66 |
|
|
67 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
68 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
|
|
69 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
|
|
70 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
|
|
71 |
|
|
72 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
73 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect()));
|
|
74 |
|
|
75 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToNetChat()));
|
|
76 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam()));
|
|
77 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame()));
|
|
78 |
|
|
79 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
|
|
80 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin()));
|
|
81 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate()));
|
|
82 |
|
187
|
83 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
84 |
|
184
|
85 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
|
|
86 |
}
|
|
87 |
|
245
|
88 |
void HWForm::UpdateTeamsLists()
|
|
89 |
{
|
|
90 |
QStringList teamslist = config->GetTeamsList();
|
|
91 |
|
|
92 |
if(teamslist.empty()) {
|
|
93 |
HWTeam defaultTeam("DefaultTeam");
|
|
94 |
defaultTeam.SaveToFile();
|
|
95 |
teamslist.push_back("DefaultTeam");
|
|
96 |
}
|
|
97 |
|
|
98 |
ui.pageOptions->CBTeamName->clear();
|
|
99 |
ui.pageOptions->CBTeamName->addItems(teamslist);
|
|
100 |
}
|
|
101 |
|
184
|
102 |
void HWForm::GoToMain()
|
|
103 |
{
|
|
104 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
|
|
105 |
}
|
|
106 |
|
|
107 |
void HWForm::GoToSinglePlayer()
|
|
108 |
{
|
|
109 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
|
|
110 |
}
|
|
111 |
|
|
112 |
void HWForm::GoToSetup()
|
|
113 |
{
|
|
114 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
115 |
}
|
|
116 |
|
187
|
117 |
void HWForm::GoToInfo()
|
|
118 |
{
|
|
119 |
ui.Pages->setCurrentIndex(ID_PAGE_INFO);
|
|
120 |
}
|
|
121 |
|
184
|
122 |
void HWForm::GoToMultiplayer()
|
|
123 |
{
|
231
|
124 |
QStringList tmNames=config->GetTeamsList();
|
|
125 |
QList<HWTeam> teamsList;
|
|
126 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) {
|
|
127 |
HWTeam team(*it);
|
|
128 |
team.LoadFromFile();
|
|
129 |
teamsList.push_back(team);
|
|
130 |
}
|
|
131 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList);
|
184
|
132 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
|
|
133 |
}
|
|
134 |
|
|
135 |
void HWForm::GoToDemos()
|
|
136 |
{
|
|
137 |
QDir tmpdir;
|
|
138 |
tmpdir.cd(cfgdir->absolutePath());
|
|
139 |
tmpdir.cd("Demos");
|
|
140 |
tmpdir.setFilter(QDir::Files);
|
|
141 |
ui.pagePlayDemo->DemosList->clear();
|
|
142 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
|
|
143 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
|
|
144 |
}
|
|
145 |
|
|
146 |
void HWForm::GoToNet()
|
|
147 |
{
|
|
148 |
ui.Pages->setCurrentIndex(ID_PAGE_NET);
|
|
149 |
}
|
|
150 |
|
|
151 |
void HWForm::GoToNetChat()
|
|
152 |
{
|
|
153 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT);
|
|
154 |
}
|
|
155 |
|
|
156 |
void HWForm::NewTeam()
|
|
157 |
{
|
245
|
158 |
editedTeam = new HWTeam("unnamed");
|
|
159 |
editedTeam->SetToPage(this);
|
184
|
160 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
161 |
}
|
|
162 |
|
|
163 |
void HWForm::EditTeam()
|
|
164 |
{
|
245
|
165 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
|
|
166 |
editedTeam->LoadFromFile();
|
|
167 |
editedTeam->SetToPage(this);
|
184
|
168 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
169 |
}
|
|
170 |
|
|
171 |
void HWForm::TeamSave()
|
|
172 |
{
|
245
|
173 |
editedTeam->GetFromPage(this);
|
|
174 |
editedTeam->SaveToFile();
|
|
175 |
delete editedTeam;
|
|
176 |
UpdateTeamsLists();
|
184
|
177 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
178 |
}
|
|
179 |
|
|
180 |
void HWForm::TeamDiscard()
|
|
181 |
{
|
245
|
182 |
delete editedTeam;
|
184
|
183 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
184 |
}
|
|
185 |
|
|
186 |
void HWForm::SimpleGame()
|
|
187 |
{
|
|
188 |
game = new HWGame(config, ui.pageLocalGame->gameCFG);
|
|
189 |
game->StartQuick();
|
|
190 |
}
|
|
191 |
|
|
192 |
void HWForm::PlayDemo()
|
|
193 |
{
|
|
194 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
|
|
195 |
if (!curritem)
|
|
196 |
{
|
|
197 |
QMessageBox::critical(this,
|
|
198 |
tr("Error"),
|
|
199 |
tr("Please, select demo from the list above"),
|
|
200 |
tr("OK"));
|
|
201 |
return ;
|
|
202 |
}
|
|
203 |
game = new HWGame(config, 0);
|
|
204 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1");
|
|
205 |
}
|
|
206 |
|
|
207 |
void HWForm::NetConnect()
|
|
208 |
{
|
|
209 |
hwnet = new HWNet(config);
|
|
210 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
|
|
211 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
|
|
212 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
|
|
213 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
|
|
214 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
|
|
215 |
config->SaveOptions();
|
|
216 |
}
|
|
217 |
|
|
218 |
void HWForm::NetDisconnect()
|
|
219 |
{
|
|
220 |
hwnet->Disconnect();
|
|
221 |
GoToNet();
|
|
222 |
}
|
|
223 |
|
|
224 |
void HWForm::AddGame(const QString & chan)
|
|
225 |
{
|
|
226 |
ui.pageNetChat->ChannelsList->addItem(chan);
|
|
227 |
}
|
|
228 |
|
|
229 |
void HWForm::NetGameEnter()
|
|
230 |
{
|
|
231 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG);
|
|
232 |
}
|
|
233 |
|
|
234 |
void HWForm::NetJoin()
|
|
235 |
{
|
|
236 |
hwnet->JoinGame("#hw");
|
|
237 |
}
|
|
238 |
|
|
239 |
void HWForm::NetCreate()
|
|
240 |
{
|
|
241 |
hwnet->JoinGame("#hw");
|
|
242 |
}
|
|
243 |
|
|
244 |
void HWForm::NetAddTeam()
|
|
245 |
{
|
|
246 |
HWTeam team("DefaultTeam");
|
|
247 |
team.LoadFromFile();
|
|
248 |
hwnet->AddTeam(team);
|
|
249 |
}
|
|
250 |
|
|
251 |
void HWForm::NetStartGame()
|
|
252 |
{
|
|
253 |
hwnet->StartGame();
|
|
254 |
}
|
|
255 |
|
|
256 |
void HWForm::ChangeInNetTeams(const QStringList & teams)
|
|
257 |
{
|
|
258 |
ui.pageNetGame->listNetTeams->clear();
|
|
259 |
ui.pageNetGame->listNetTeams->addItems(teams);
|
|
260 |
}
|
|
261 |
|
|
262 |
void HWForm::StartMPGame()
|
|
263 |
{
|
|
264 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG);
|
|
265 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams();
|
|
266 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
207
|
267 |
HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName);
|
213
|
268 |
game->AddTeam(it->TeamName, params);
|
184
|
269 |
}
|
|
270 |
game->StartLocal();
|
|
271 |
}
|