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 |
|
|
45 |
QStringList teamslist = config->GetTeamsList();
|
|
46 |
|
|
47 |
if(teamslist.empty()) {
|
|
48 |
HWTeam defaultTeam("DefaultTeam");
|
|
49 |
defaultTeam.SaveToFile();
|
|
50 |
teamslist.push_back("DefaultTeam");
|
|
51 |
}
|
|
52 |
|
|
53 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it )
|
|
54 |
{
|
|
55 |
ui.pageMultiplayer->teamsSelect->addTeam(*it);
|
|
56 |
ui.pageOptions->CBTeamName->addItem(*it);
|
|
57 |
}
|
|
58 |
|
|
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()));
|
187
|
64 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo()));
|
184
|
65 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close()));
|
|
66 |
|
|
67 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
68 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame()));
|
|
69 |
|
|
70 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
|
|
71 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
|
|
72 |
|
|
73 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
74 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
|
|
75 |
|
|
76 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
77 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo()));
|
|
78 |
|
|
79 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
80 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
|
|
81 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
|
|
82 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions()));
|
|
83 |
|
|
84 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
85 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect()));
|
|
86 |
|
|
87 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoToNetChat()));
|
|
88 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam()));
|
|
89 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame()));
|
|
90 |
|
|
91 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
|
|
92 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin()));
|
|
93 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate()));
|
|
94 |
|
187
|
95 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
|
|
96 |
|
184
|
97 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
|
|
98 |
}
|
|
99 |
|
|
100 |
void HWForm::GoToMain()
|
|
101 |
{
|
|
102 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
|
|
103 |
}
|
|
104 |
|
|
105 |
void HWForm::GoToSinglePlayer()
|
|
106 |
{
|
|
107 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
|
|
108 |
}
|
|
109 |
|
|
110 |
void HWForm::GoToSetup()
|
|
111 |
{
|
|
112 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
113 |
}
|
|
114 |
|
187
|
115 |
void HWForm::GoToInfo()
|
|
116 |
{
|
|
117 |
ui.Pages->setCurrentIndex(ID_PAGE_INFO);
|
|
118 |
}
|
|
119 |
|
184
|
120 |
void HWForm::GoToMultiplayer()
|
|
121 |
{
|
231
|
122 |
QStringList tmNames=config->GetTeamsList();
|
|
123 |
QList<HWTeam> teamsList;
|
|
124 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) {
|
|
125 |
HWTeam team(*it);
|
|
126 |
team.LoadFromFile();
|
|
127 |
teamsList.push_back(team);
|
|
128 |
}
|
|
129 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList);
|
184
|
130 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
|
|
131 |
}
|
|
132 |
|
|
133 |
void HWForm::GoToDemos()
|
|
134 |
{
|
|
135 |
QDir tmpdir;
|
|
136 |
tmpdir.cd(cfgdir->absolutePath());
|
|
137 |
tmpdir.cd("Demos");
|
|
138 |
tmpdir.setFilter(QDir::Files);
|
|
139 |
ui.pagePlayDemo->DemosList->clear();
|
|
140 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
|
|
141 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
|
|
142 |
}
|
|
143 |
|
|
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 |
|
|
154 |
void HWForm::NewTeam()
|
|
155 |
{
|
|
156 |
tmpTeam = new HWTeam("unnamed");
|
|
157 |
tmpTeam->SetToPage(this);
|
|
158 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
159 |
}
|
|
160 |
|
|
161 |
void HWForm::EditTeam()
|
|
162 |
{
|
|
163 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
|
|
164 |
tmpTeam->LoadFromFile();
|
|
165 |
tmpTeam->SetToPage(this);
|
|
166 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
167 |
}
|
|
168 |
|
|
169 |
void HWForm::TeamSave()
|
|
170 |
{
|
|
171 |
tmpTeam->GetFromPage(this);
|
|
172 |
tmpTeam->SaveToFile();
|
|
173 |
delete tmpTeam;
|
|
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 |
{
|
|
184 |
game = new HWGame(config, ui.pageLocalGame->gameCFG);
|
|
185 |
game->StartQuick();
|
|
186 |
}
|
|
187 |
|
|
188 |
void HWForm::PlayDemo()
|
|
189 |
{
|
|
190 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
|
|
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 |
}
|
|
199 |
game = new HWGame(config, 0);
|
|
200 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1");
|
|
201 |
}
|
|
202 |
|
|
203 |
void HWForm::NetConnect()
|
|
204 |
{
|
|
205 |
hwnet = new HWNet(config);
|
|
206 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
|
|
207 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
|
|
208 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
|
|
209 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
|
|
210 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
|
|
211 |
config->SaveOptions();
|
|
212 |
}
|
|
213 |
|
|
214 |
void HWForm::NetDisconnect()
|
|
215 |
{
|
|
216 |
hwnet->Disconnect();
|
|
217 |
GoToNet();
|
|
218 |
}
|
|
219 |
|
|
220 |
void HWForm::AddGame(const QString & chan)
|
|
221 |
{
|
|
222 |
ui.pageNetChat->ChannelsList->addItem(chan);
|
|
223 |
}
|
|
224 |
|
|
225 |
void HWForm::NetGameEnter()
|
|
226 |
{
|
|
227 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG);
|
|
228 |
}
|
|
229 |
|
|
230 |
void HWForm::NetJoin()
|
|
231 |
{
|
|
232 |
hwnet->JoinGame("#hw");
|
|
233 |
}
|
|
234 |
|
|
235 |
void HWForm::NetCreate()
|
|
236 |
{
|
|
237 |
hwnet->JoinGame("#hw");
|
|
238 |
}
|
|
239 |
|
|
240 |
void HWForm::NetAddTeam()
|
|
241 |
{
|
|
242 |
HWTeam team("DefaultTeam");
|
|
243 |
team.LoadFromFile();
|
|
244 |
hwnet->AddTeam(team);
|
|
245 |
}
|
|
246 |
|
|
247 |
void HWForm::NetStartGame()
|
|
248 |
{
|
|
249 |
hwnet->StartGame();
|
|
250 |
}
|
|
251 |
|
|
252 |
void HWForm::ChangeInNetTeams(const QStringList & teams)
|
|
253 |
{
|
|
254 |
ui.pageNetGame->listNetTeams->clear();
|
|
255 |
ui.pageNetGame->listNetTeams->addItems(teams);
|
|
256 |
}
|
|
257 |
|
|
258 |
void HWForm::StartMPGame()
|
|
259 |
{
|
|
260 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG);
|
|
261 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams();
|
|
262 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
207
|
263 |
HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName);
|
213
|
264 |
game->AddTeam(it->TeamName, params);
|
184
|
265 |
}
|
|
266 |
game->StartLocal();
|
|
267 |
}
|