author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 157 | 8e3e11bb0a5f |
child 184 | f97a7a3dc8f6 |
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 |
* |
183 | 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 |
|
20 | 8 |
* |
183 | 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. |
|
20 | 13 |
* |
183 | 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 |
|
20 | 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" |
|
87 | 30 |
#include "game.h" |
31 |
#include "team.h" |
|
32 |
#include "netclient.h" |
|
33 |
#include "teamselect.h" |
|
34 |
#include "gameuiconfig.h" |
|
35 |
#include "pages.h" |
|
20 | 36 |
#include "hwconsts.h" |
37 |
||
38 |
HWForm::HWForm(QWidget *parent) |
|
39 |
: QMainWindow(parent) |
|
40 |
{ |
|
41 |
ui.setupUi(this); |
|
42 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
43 |
config = new GameUIConfig(this); |
84 | 44 |
|
45 |
QStringList teamslist = config->GetTeamsList(); |
|
25 | 46 |
|
84 | 47 |
if(teamslist.empty()) { |
116 | 48 |
HWTeam defaultTeam("DefaultTeam"); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
49 |
defaultTeam.SaveToFile(); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
50 |
teamslist.push_back("DefaultTeam"); |
44 | 51 |
} |
52 |
||
84 | 53 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) |
21 | 54 |
{ |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
137
diff
changeset
|
55 |
ui.pageMultiplayer->teamsSelect->addTeam(*it); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
137
diff
changeset
|
56 |
ui.pageOptions->CBTeamName->addItem(*it); |
21 | 57 |
} |
25 | 58 |
|
87 | 59 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
60 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
61 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
62 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
63 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
64 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close())); |
|
65 |
||
66 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
67 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
|
68 |
||
69 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
70 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
71 |
||
72 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
133 | 73 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
87 | 74 |
|
75 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
76 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
|
77 |
||
78 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
79 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
|
80 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
81 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
82 |
||
83 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
84 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
|
85 |
||
86 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToNetChat())); |
|
87 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
|
88 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
|
89 |
||
90 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect())); |
|
91 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin())); |
|
92 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate())); |
|
93 |
||
20 | 94 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
95 |
} |
|
96 |
||
97 |
void HWForm::GoToMain() |
|
98 |
{ |
|
99 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
|
100 |
} |
|
101 |
||
102 |
void HWForm::GoToSinglePlayer() |
|
103 |
{ |
|
104 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER); |
|
105 |
} |
|
106 |
||
107 |
void HWForm::GoToSetup() |
|
108 |
{ |
|
109 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
110 |
} |
|
111 |
||
25 | 112 |
void HWForm::GoToMultiplayer() |
113 |
{ |
|
151 | 114 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(config->GetTeamsList()); |
25 | 115 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
116 |
} |
|
26 | 117 |
|
118 |
void HWForm::GoToDemos() |
|
119 |
{ |
|
120 |
QDir tmpdir; |
|
157 | 121 |
tmpdir.cd(cfgdir->absolutePath()); |
26 | 122 |
tmpdir.cd("Demos"); |
123 |
tmpdir.setFilter(QDir::Files); |
|
87 | 124 |
ui.pagePlayDemo->DemosList->clear(); |
125 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); |
|
26 | 126 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
127 |
} |
|
128 |
||
28 | 129 |
void HWForm::GoToNet() |
130 |
{ |
|
131 |
ui.Pages->setCurrentIndex(ID_PAGE_NET); |
|
132 |
} |
|
133 |
||
134 |
void HWForm::GoToNetChat() |
|
135 |
{ |
|
136 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT); |
|
137 |
} |
|
138 |
||
20 | 139 |
void HWForm::NewTeam() |
140 |
{ |
|
116 | 141 |
tmpTeam = new HWTeam("unnamed"); |
144 | 142 |
tmpTeam->SetToPage(this); |
20 | 143 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
144 |
} |
|
145 |
||
146 |
void HWForm::EditTeam() |
|
147 |
{ |
|
116 | 148 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
21 | 149 |
tmpTeam->LoadFromFile(); |
150 |
tmpTeam->SetToPage(this); |
|
20 | 151 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
152 |
} |
|
153 |
||
154 |
void HWForm::TeamSave() |
|
155 |
{ |
|
21 | 156 |
tmpTeam->GetFromPage(this); |
157 |
tmpTeam->SaveToFile(); |
|
158 |
delete tmpTeam; |
|
20 | 159 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
160 |
} |
|
161 |
||
162 |
void HWForm::TeamDiscard() |
|
163 |
{ |
|
164 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
165 |
} |
|
166 |
||
167 |
void HWForm::SimpleGame() |
|
168 |
{ |
|
87 | 169 |
game = new HWGame(config, ui.pageLocalGame->gameCFG); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
170 |
game->StartQuick(); |
20 | 171 |
} |
172 |
||
26 | 173 |
void HWForm::PlayDemo() |
174 |
{ |
|
87 | 175 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
26 | 176 |
if (!curritem) |
177 |
{ |
|
178 |
QMessageBox::critical(this, |
|
179 |
tr("Error"), |
|
180 |
tr("Please, select demo from the list above"), |
|
181 |
tr("OK")); |
|
182 |
return ; |
|
183 |
} |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
184 |
game = new HWGame(config, 0); |
157 | 185 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1"); |
26 | 186 |
} |
187 |
||
28 | 188 |
void HWForm::NetConnect() |
189 |
{ |
|
84 | 190 |
hwnet = new HWNet(config); |
28 | 191 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
192 |
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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
config->SaveOptions(); |
28 | 197 |
} |
26 | 198 |
|
28 | 199 |
void HWForm::NetDisconnect() |
200 |
{ |
|
201 |
hwnet->Disconnect(); |
|
202 |
GoToNet(); |
|
203 |
} |
|
204 |
||
205 |
void HWForm::AddGame(const QString & chan) |
|
206 |
{ |
|
87 | 207 |
ui.pageNetChat->ChannelsList->addItem(chan); |
28 | 208 |
} |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
209 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
210 |
void HWForm::NetGameEnter() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
211 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
212 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
213 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
214 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
215 |
void HWForm::NetJoin() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
216 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
217 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
218 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
219 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
220 |
void HWForm::NetCreate() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
221 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
222 |
hwnet->JoinGame("#hw"); |
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 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
225 |
void HWForm::NetAddTeam() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
226 |
{ |
116 | 227 |
HWTeam team("DefaultTeam"); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
228 |
team.LoadFromFile(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
229 |
hwnet->AddTeam(team); |
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 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
232 |
void HWForm::NetStartGame() |
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 |
hwnet->StartGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
235 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
236 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
237 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
238 |
{ |
87 | 239 |
ui.pageNetGame->listNetTeams->clear(); |
240 |
ui.pageNetGame->listNetTeams->addItems(teams); |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
241 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
242 |
|
133 | 243 |
void HWForm::StartMPGame() |
244 |
{ |
|
137 | 245 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG); |
152 | 246 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams(); |
247 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
248 |
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
|
249 |
} |
133 | 250 |
game->StartLocal(); |
251 |
} |