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