author | displacer |
Fri, 18 Aug 2006 19:59:16 +0000 | |
changeset 116 | 00d3d6d2e699 |
parent 111 | 30ca06092a64 |
child 133 | c79cb5e5b24a |
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())); |
|
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 |
{ |
|
129 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
|
130 |
} |
|
26 | 131 |
|
132 |
void HWForm::GoToDemos() |
|
133 |
{ |
|
134 |
QDir tmpdir; |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
135 |
tmpdir.cd(datadir->absolutePath()); |
26 | 136 |
tmpdir.cd("Demos"); |
137 |
tmpdir.setFilter(QDir::Files); |
|
87 | 138 |
ui.pagePlayDemo->DemosList->clear(); |
139 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); |
|
26 | 140 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
141 |
} |
|
142 |
||
28 | 143 |
void HWForm::GoToNet() |
144 |
{ |
|
145 |
ui.Pages->setCurrentIndex(ID_PAGE_NET); |
|
146 |
} |
|
147 |
||
148 |
void HWForm::GoToNetChat() |
|
149 |
{ |
|
150 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT); |
|
151 |
} |
|
152 |
||
20 | 153 |
void HWForm::NewTeam() |
154 |
{ |
|
116 | 155 |
tmpTeam = new HWTeam("unnamed"); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
156 |
|
20 | 157 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
158 |
} |
|
159 |
||
160 |
void HWForm::EditTeam() |
|
161 |
{ |
|
116 | 162 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
21 | 163 |
tmpTeam->LoadFromFile(); |
164 |
tmpTeam->SetToPage(this); |
|
20 | 165 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
166 |
} |
|
167 |
||
168 |
void HWForm::TeamSave() |
|
169 |
{ |
|
21 | 170 |
tmpTeam->GetFromPage(this); |
171 |
tmpTeam->SaveToFile(); |
|
172 |
delete tmpTeam; |
|
20 | 173 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
174 |
} |
|
175 |
||
176 |
void HWForm::TeamDiscard() |
|
177 |
{ |
|
178 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
179 |
} |
|
180 |
||
181 |
void HWForm::SimpleGame() |
|
182 |
{ |
|
87 | 183 |
game = new HWGame(config, ui.pageLocalGame->gameCFG); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
184 |
game->StartQuick(); |
20 | 185 |
} |
186 |
||
26 | 187 |
void HWForm::PlayDemo() |
188 |
{ |
|
87 | 189 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
26 | 190 |
if (!curritem) |
191 |
{ |
|
192 |
QMessageBox::critical(this, |
|
193 |
tr("Error"), |
|
194 |
tr("Please, select demo from the list above"), |
|
195 |
tr("OK")); |
|
196 |
return ; |
|
197 |
} |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
198 |
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
|
199 |
game->PlayDemo(datadir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1"); |
26 | 200 |
} |
201 |
||
28 | 202 |
void HWForm::NetConnect() |
203 |
{ |
|
84 | 204 |
hwnet = new HWNet(config); |
28 | 205 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
config->SaveOptions(); |
28 | 211 |
} |
26 | 212 |
|
28 | 213 |
void HWForm::NetDisconnect() |
214 |
{ |
|
215 |
hwnet->Disconnect(); |
|
216 |
GoToNet(); |
|
217 |
} |
|
218 |
||
219 |
void HWForm::AddGame(const QString & chan) |
|
220 |
{ |
|
87 | 221 |
ui.pageNetChat->ChannelsList->addItem(chan); |
28 | 222 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
223 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
224 |
void HWForm::NetGameEnter() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
225 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
226 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
227 |
} |
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 |
void HWForm::NetJoin() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
230 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
231 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
232 |
} |
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 |
void HWForm::NetCreate() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
235 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
236 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
237 |
} |
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 |
void HWForm::NetAddTeam() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
240 |
{ |
116 | 241 |
HWTeam team("DefaultTeam"); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
242 |
team.LoadFromFile(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
243 |
hwnet->AddTeam(team); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
244 |
} |
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 |
void HWForm::NetStartGame() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
247 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
248 |
hwnet->StartGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
249 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
250 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
251 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
252 |
{ |
87 | 253 |
ui.pageNetGame->listNetTeams->clear(); |
254 |
ui.pageNetGame->listNetTeams->addItems(teams); |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
255 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
256 |