author | unc0rr |
Sun, 03 Sep 2006 18:01:34 +0000 | |
changeset 139 | 340ded7cc336 |
parent 137 | bcab861a3262 |
child 140 | 50ccde437ea1 |
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 |
{ |
50 | 70 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1"); |
87 | 71 |
ui.pageMultiplayer->teamsSelect->addTeam(tmpTeamStr); |
72 |
ui.pageOptions->CBTeamName->addItem(tmpTeamStr); |
|
21 | 73 |
} |
25 | 74 |
|
87 | 75 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
76 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
77 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
78 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
79 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
80 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close())); |
|
81 |
||
82 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
83 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
|
84 |
||
85 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
86 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
87 |
||
88 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
133 | 89 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
87 | 90 |
|
91 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
92 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
|
93 |
||
94 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
95 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
|
96 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
97 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
98 |
||
99 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
100 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
|
101 |
||
102 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToNetChat())); |
|
103 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
|
104 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
|
105 |
||
106 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect())); |
|
107 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin())); |
|
108 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate())); |
|
109 |
||
20 | 110 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
111 |
} |
|
112 |
||
113 |
void HWForm::GoToMain() |
|
114 |
{ |
|
115 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
|
116 |
} |
|
117 |
||
118 |
void HWForm::GoToSinglePlayer() |
|
119 |
{ |
|
120 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER); |
|
121 |
} |
|
122 |
||
123 |
void HWForm::GoToSetup() |
|
124 |
{ |
|
125 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
126 |
} |
|
127 |
||
25 | 128 |
void HWForm::GoToMultiplayer() |
129 |
{ |
|
130 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
|
131 |
} |
|
26 | 132 |
|
133 |
void HWForm::GoToDemos() |
|
134 |
{ |
|
135 |
QDir tmpdir; |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
136 |
tmpdir.cd(datadir->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"); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
157 |
|
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); |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
200 |
game->PlayDemo(datadir->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); |
133 | 261 |
game->AddTeam("DefaultTeam"); |
262 |
game->AddTeam("DefaultTeam"); |
|
263 |
game->StartLocal(); |
|
264 |
} |