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();
|
233
|
127 |
team.TeamName=*it; // FIXME: we can have different different teamnames in config files
|
231
|
128 |
teamsList.push_back(team);
|
|
129 |
}
|
|
130 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList);
|
184
|
131 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
|
|
132 |
}
|
|
133 |
|
|
134 |
void HWForm::GoToDemos()
|
|
135 |
{
|
|
136 |
QDir tmpdir;
|
|
137 |
tmpdir.cd(cfgdir->absolutePath());
|
|
138 |
tmpdir.cd("Demos");
|
|
139 |
tmpdir.setFilter(QDir::Files);
|
|
140 |
ui.pagePlayDemo->DemosList->clear();
|
|
141 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
|
|
142 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
|
|
143 |
}
|
|
144 |
|
|
145 |
void HWForm::GoToNet()
|
|
146 |
{
|
|
147 |
ui.Pages->setCurrentIndex(ID_PAGE_NET);
|
|
148 |
}
|
|
149 |
|
|
150 |
void HWForm::GoToNetChat()
|
|
151 |
{
|
|
152 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT);
|
|
153 |
}
|
|
154 |
|
|
155 |
void HWForm::NewTeam()
|
|
156 |
{
|
|
157 |
tmpTeam = new HWTeam("unnamed");
|
|
158 |
tmpTeam->SetToPage(this);
|
|
159 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
160 |
}
|
|
161 |
|
|
162 |
void HWForm::EditTeam()
|
|
163 |
{
|
|
164 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
|
|
165 |
tmpTeam->LoadFromFile();
|
|
166 |
tmpTeam->SetToPage(this);
|
|
167 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
168 |
}
|
|
169 |
|
|
170 |
void HWForm::TeamSave()
|
|
171 |
{
|
|
172 |
tmpTeam->GetFromPage(this);
|
|
173 |
tmpTeam->SaveToFile();
|
|
174 |
delete tmpTeam;
|
|
175 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
176 |
}
|
|
177 |
|
|
178 |
void HWForm::TeamDiscard()
|
|
179 |
{
|
|
180 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
|
|
181 |
}
|
|
182 |
|
|
183 |
void HWForm::SimpleGame()
|
|
184 |
{
|
|
185 |
game = new HWGame(config, ui.pageLocalGame->gameCFG);
|
|
186 |
game->StartQuick();
|
|
187 |
}
|
|
188 |
|
|
189 |
void HWForm::PlayDemo()
|
|
190 |
{
|
|
191 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
|
|
192 |
if (!curritem)
|
|
193 |
{
|
|
194 |
QMessageBox::critical(this,
|
|
195 |
tr("Error"),
|
|
196 |
tr("Please, select demo from the list above"),
|
|
197 |
tr("OK"));
|
|
198 |
return ;
|
|
199 |
}
|
|
200 |
game = new HWGame(config, 0);
|
|
201 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1");
|
|
202 |
}
|
|
203 |
|
|
204 |
void HWForm::NetConnect()
|
|
205 |
{
|
|
206 |
hwnet = new HWNet(config);
|
|
207 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
|
|
208 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
|
|
209 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
|
|
210 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
|
|
211 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
|
|
212 |
config->SaveOptions();
|
|
213 |
}
|
|
214 |
|
|
215 |
void HWForm::NetDisconnect()
|
|
216 |
{
|
|
217 |
hwnet->Disconnect();
|
|
218 |
GoToNet();
|
|
219 |
}
|
|
220 |
|
|
221 |
void HWForm::AddGame(const QString & chan)
|
|
222 |
{
|
|
223 |
ui.pageNetChat->ChannelsList->addItem(chan);
|
|
224 |
}
|
|
225 |
|
|
226 |
void HWForm::NetGameEnter()
|
|
227 |
{
|
|
228 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG);
|
|
229 |
}
|
|
230 |
|
|
231 |
void HWForm::NetJoin()
|
|
232 |
{
|
|
233 |
hwnet->JoinGame("#hw");
|
|
234 |
}
|
|
235 |
|
|
236 |
void HWForm::NetCreate()
|
|
237 |
{
|
|
238 |
hwnet->JoinGame("#hw");
|
|
239 |
}
|
|
240 |
|
|
241 |
void HWForm::NetAddTeam()
|
|
242 |
{
|
|
243 |
HWTeam team("DefaultTeam");
|
|
244 |
team.LoadFromFile();
|
|
245 |
hwnet->AddTeam(team);
|
|
246 |
}
|
|
247 |
|
|
248 |
void HWForm::NetStartGame()
|
|
249 |
{
|
|
250 |
hwnet->StartGame();
|
|
251 |
}
|
|
252 |
|
|
253 |
void HWForm::ChangeInNetTeams(const QStringList & teams)
|
|
254 |
{
|
|
255 |
ui.pageNetGame->listNetTeams->clear();
|
|
256 |
ui.pageNetGame->listNetTeams->addItems(teams);
|
|
257 |
}
|
|
258 |
|
|
259 |
void HWForm::StartMPGame()
|
|
260 |
{
|
|
261 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG);
|
|
262 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams();
|
|
263 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
207
|
264 |
HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName);
|
213
|
265 |
game->AddTeam(it->TeamName, params);
|
184
|
266 |
}
|
|
267 |
game->StartLocal();
|
|
268 |
}
|