author | unc0rr |
Sun, 19 Nov 2006 16:10:37 +0000 | |
changeset 255 | 97b2d242e2a1 |
parent 247 | 07605d2a2024 |
child 271 | f2f9a3d5b441 |
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(); |
|
143 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); |
|
144 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
|
145 |
} |
|
146 |
||
147 |
void HWForm::GoToNet() |
|
148 |
{ |
|
149 |
ui.Pages->setCurrentIndex(ID_PAGE_NET); |
|
150 |
} |
|
151 |
||
152 |
void HWForm::GoToNetChat() |
|
153 |
{ |
|
154 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT); |
|
155 |
} |
|
156 |
||
157 |
void HWForm::NewTeam() |
|
158 |
{ |
|
245 | 159 |
editedTeam = new HWTeam("unnamed"); |
160 |
editedTeam->SetToPage(this); |
|
184 | 161 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
162 |
} |
|
163 |
||
164 |
void HWForm::EditTeam() |
|
165 |
{ |
|
245 | 166 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
167 |
editedTeam->LoadFromFile(); |
|
168 |
editedTeam->SetToPage(this); |
|
184 | 169 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
170 |
} |
|
171 |
||
172 |
void HWForm::TeamSave() |
|
173 |
{ |
|
245 | 174 |
editedTeam->GetFromPage(this); |
175 |
editedTeam->SaveToFile(); |
|
176 |
delete editedTeam; |
|
177 |
UpdateTeamsLists(); |
|
184 | 178 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
179 |
} |
|
180 |
||
181 |
void HWForm::TeamDiscard() |
|
182 |
{ |
|
245 | 183 |
delete editedTeam; |
184 | 184 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
185 |
} |
|
186 |
||
187 |
void HWForm::SimpleGame() |
|
188 |
{ |
|
189 |
game = new HWGame(config, ui.pageLocalGame->gameCFG); |
|
190 |
game->StartQuick(); |
|
191 |
} |
|
192 |
||
193 |
void HWForm::PlayDemo() |
|
194 |
{ |
|
195 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
196 |
if (!curritem) |
|
197 |
{ |
|
198 |
QMessageBox::critical(this, |
|
199 |
tr("Error"), |
|
200 |
tr("Please, select demo from the list above"), |
|
201 |
tr("OK")); |
|
202 |
return ; |
|
203 |
} |
|
204 |
game = new HWGame(config, 0); |
|
205 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1"); |
|
206 |
} |
|
207 |
||
208 |
void HWForm::NetConnect() |
|
209 |
{ |
|
210 |
hwnet = new HWNet(config); |
|
211 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
|
212 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
|
213 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
|
214 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
|
215 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text()); |
|
216 |
config->SaveOptions(); |
|
217 |
} |
|
218 |
||
219 |
void HWForm::NetDisconnect() |
|
220 |
{ |
|
221 |
hwnet->Disconnect(); |
|
222 |
GoToNet(); |
|
223 |
} |
|
224 |
||
225 |
void HWForm::AddGame(const QString & chan) |
|
226 |
{ |
|
227 |
ui.pageNetChat->ChannelsList->addItem(chan); |
|
228 |
} |
|
229 |
||
230 |
void HWForm::NetGameEnter() |
|
231 |
{ |
|
232 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
|
233 |
} |
|
234 |
||
235 |
void HWForm::NetJoin() |
|
236 |
{ |
|
237 |
hwnet->JoinGame("#hw"); |
|
238 |
} |
|
239 |
||
240 |
void HWForm::NetCreate() |
|
241 |
{ |
|
242 |
hwnet->JoinGame("#hw"); |
|
243 |
} |
|
244 |
||
245 |
void HWForm::NetAddTeam() |
|
246 |
{ |
|
247 |
HWTeam team("DefaultTeam"); |
|
248 |
team.LoadFromFile(); |
|
249 |
hwnet->AddTeam(team); |
|
250 |
} |
|
251 |
||
252 |
void HWForm::NetStartGame() |
|
253 |
{ |
|
254 |
hwnet->StartGame(); |
|
255 |
} |
|
256 |
||
257 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
|
258 |
{ |
|
259 |
ui.pageNetGame->listNetTeams->clear(); |
|
260 |
ui.pageNetGame->listNetTeams->addItems(teams); |
|
261 |
} |
|
262 |
||
263 |
void HWForm::StartMPGame() |
|
264 |
{ |
|
265 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG); |
|
266 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams(); |
|
267 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
207 | 268 |
HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName); |
213 | 269 |
game->AddTeam(it->TeamName, params); |
184 | 270 |
} |
271 |
game->StartLocal(); |
|
272 |
} |