author | displacer |
Sun, 01 Oct 2006 20:31:48 +0000 | |
changeset 179 | 06e472d3f9f8 |
parent 157 | 8e3e11bb0a5f |
child 183 | 57c2ef19f719 |
permissions | -rw-r--r-- |
20 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
20 | 4 |
* |
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*/ |
|
33 |
||
34 |
#include <QtGui> |
|
35 |
#include <QStringList> |
|
36 |
#include <QProcess> |
|
37 |
#include <QDir> |
|
38 |
#include <QPixmap> |
|
39 |
#include <QRegExp> |
|
40 |
#include <QIcon> |
|
41 |
#include <QFile> |
|
42 |
#include <QTextStream> |
|
43 |
||
44 |
#include "hwform.h" |
|
87 | 45 |
#include "game.h" |
46 |
#include "team.h" |
|
47 |
#include "netclient.h" |
|
48 |
#include "teamselect.h" |
|
49 |
#include "gameuiconfig.h" |
|
50 |
#include "pages.h" |
|
20 | 51 |
#include "hwconsts.h" |
52 |
||
53 |
HWForm::HWForm(QWidget *parent) |
|
54 |
: QMainWindow(parent) |
|
55 |
{ |
|
56 |
ui.setupUi(this); |
|
57 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
58 |
config = new GameUIConfig(this); |
84 | 59 |
|
60 |
QStringList teamslist = config->GetTeamsList(); |
|
25 | 61 |
|
84 | 62 |
if(teamslist.empty()) { |
116 | 63 |
HWTeam defaultTeam("DefaultTeam"); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
64 |
defaultTeam.SaveToFile(); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
65 |
teamslist.push_back("DefaultTeam"); |
44 | 66 |
} |
67 |
||
84 | 68 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) |
21 | 69 |
{ |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
137
diff
changeset
|
70 |
ui.pageMultiplayer->teamsSelect->addTeam(*it); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
137
diff
changeset
|
71 |
ui.pageOptions->CBTeamName->addItem(*it); |
21 | 72 |
} |
25 | 73 |
|
87 | 74 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
75 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
76 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
77 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
78 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
79 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close())); |
|
80 |
||
81 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
82 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
|
83 |
||
84 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
85 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
86 |
||
87 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
133 | 88 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
87 | 89 |
|
90 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
91 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
|
92 |
||
93 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
94 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
|
95 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
96 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
97 |
||
98 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
99 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
|
100 |
||
101 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToNetChat())); |
|
102 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
|
103 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
|
104 |
||
105 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect())); |
|
106 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin())); |
|
107 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate())); |
|
108 |
||
20 | 109 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
110 |
} |
|
111 |
||
112 |
void HWForm::GoToMain() |
|
113 |
{ |
|
114 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
|
115 |
} |
|
116 |
||
117 |
void HWForm::GoToSinglePlayer() |
|
118 |
{ |
|
119 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER); |
|
120 |
} |
|
121 |
||
122 |
void HWForm::GoToSetup() |
|
123 |
{ |
|
124 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
125 |
} |
|
126 |
||
25 | 127 |
void HWForm::GoToMultiplayer() |
128 |
{ |
|
151 | 129 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(config->GetTeamsList()); |
25 | 130 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
131 |
} |
|
26 | 132 |
|
133 |
void HWForm::GoToDemos() |
|
134 |
{ |
|
135 |
QDir tmpdir; |
|
157 | 136 |
tmpdir.cd(cfgdir->absolutePath()); |
26 | 137 |
tmpdir.cd("Demos"); |
138 |
tmpdir.setFilter(QDir::Files); |
|
87 | 139 |
ui.pagePlayDemo->DemosList->clear(); |
140 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); |
|
26 | 141 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
142 |
} |
|
143 |
||
28 | 144 |
void HWForm::GoToNet() |
145 |
{ |
|
146 |
ui.Pages->setCurrentIndex(ID_PAGE_NET); |
|
147 |
} |
|
148 |
||
149 |
void HWForm::GoToNetChat() |
|
150 |
{ |
|
151 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT); |
|
152 |
} |
|
153 |
||
20 | 154 |
void HWForm::NewTeam() |
155 |
{ |
|
116 | 156 |
tmpTeam = new HWTeam("unnamed"); |
144 | 157 |
tmpTeam->SetToPage(this); |
20 | 158 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
159 |
} |
|
160 |
||
161 |
void HWForm::EditTeam() |
|
162 |
{ |
|
116 | 163 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
21 | 164 |
tmpTeam->LoadFromFile(); |
165 |
tmpTeam->SetToPage(this); |
|
20 | 166 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
167 |
} |
|
168 |
||
169 |
void HWForm::TeamSave() |
|
170 |
{ |
|
21 | 171 |
tmpTeam->GetFromPage(this); |
172 |
tmpTeam->SaveToFile(); |
|
173 |
delete tmpTeam; |
|
20 | 174 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
175 |
} |
|
176 |
||
177 |
void HWForm::TeamDiscard() |
|
178 |
{ |
|
179 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
180 |
} |
|
181 |
||
182 |
void HWForm::SimpleGame() |
|
183 |
{ |
|
87 | 184 |
game = new HWGame(config, ui.pageLocalGame->gameCFG); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
185 |
game->StartQuick(); |
20 | 186 |
} |
187 |
||
26 | 188 |
void HWForm::PlayDemo() |
189 |
{ |
|
87 | 190 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
26 | 191 |
if (!curritem) |
192 |
{ |
|
193 |
QMessageBox::critical(this, |
|
194 |
tr("Error"), |
|
195 |
tr("Please, select demo from the list above"), |
|
196 |
tr("OK")); |
|
197 |
return ; |
|
198 |
} |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
199 |
game = new HWGame(config, 0); |
157 | 200 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1"); |
26 | 201 |
} |
202 |
||
28 | 203 |
void HWForm::NetConnect() |
204 |
{ |
|
84 | 205 |
hwnet = new HWNet(config); |
28 | 206 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
207 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
208 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
209 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
111
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
210 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text()); |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
211 |
config->SaveOptions(); |
28 | 212 |
} |
26 | 213 |
|
28 | 214 |
void HWForm::NetDisconnect() |
215 |
{ |
|
216 |
hwnet->Disconnect(); |
|
217 |
GoToNet(); |
|
218 |
} |
|
219 |
||
220 |
void HWForm::AddGame(const QString & chan) |
|
221 |
{ |
|
87 | 222 |
ui.pageNetChat->ChannelsList->addItem(chan); |
28 | 223 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
224 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
225 |
void HWForm::NetGameEnter() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
226 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
227 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
228 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
229 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
230 |
void HWForm::NetJoin() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
231 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
232 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
233 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
234 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
235 |
void HWForm::NetCreate() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
236 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
237 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
238 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
239 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
240 |
void HWForm::NetAddTeam() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
241 |
{ |
116 | 242 |
HWTeam team("DefaultTeam"); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
243 |
team.LoadFromFile(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
244 |
hwnet->AddTeam(team); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
245 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
246 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
247 |
void HWForm::NetStartGame() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
248 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
249 |
hwnet->StartGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
250 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
251 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
252 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
253 |
{ |
87 | 254 |
ui.pageNetGame->listNetTeams->clear(); |
255 |
ui.pageNetGame->listNetTeams->addItems(teams); |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
256 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
257 |
|
133 | 258 |
void HWForm::StartMPGame() |
259 |
{ |
|
137 | 260 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG); |
152 | 261 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams(); |
262 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
263 |
game->AddTeam(it->TeamName, ui.pageMultiplayer->teamsSelect->numHedgedogs(it->TeamName)); |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
137
diff
changeset
|
264 |
} |
133 | 265 |
game->StartLocal(); |
266 |
} |