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()));
|
|
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()));
|
|
73 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
|
|
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 |
|
|
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 |
|
|
112 |
void HWForm::GoToMultiplayer()
|
|
113 |
{
|
|
114 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(config->GetTeamsList());
|
|
115 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
|
|
116 |
}
|
|
117 |
|
|
118 |
void HWForm::GoToDemos()
|
|
119 |
{
|
|
120 |
QDir tmpdir;
|
|
121 |
tmpdir.cd(cfgdir->absolutePath());
|
|
122 |
tmpdir.cd("Demos");
|
|
123 |
tmpdir.setFilter(QDir::Files);
|
|
124 |
ui.pagePlayDemo->DemosList->clear();
|
|
125 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
|
|
126 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
|
|
127 |
}
|
|
128 |
|
|
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 |
|
|
139 |
void HWForm::NewTeam()
|
|
140 |
{
|
|
141 |
tmpTeam = new HWTeam("unnamed");
|
|
142 |
tmpTeam->SetToPage(this);
|
|
143 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
144 |
}
|
|
145 |
|
|
146 |
void HWForm::EditTeam()
|
|
147 |
{
|
|
148 |
tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
|
|
149 |
tmpTeam->LoadFromFile();
|
|
150 |
tmpTeam->SetToPage(this);
|
|
151 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
|
|
152 |
}
|
|
153 |
|
|
154 |
void HWForm::TeamSave()
|
|
155 |
{
|
|
156 |
tmpTeam->GetFromPage(this);
|
|
157 |
tmpTeam->SaveToFile();
|
|
158 |
delete tmpTeam;
|
|
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 |
{
|
|
169 |
game = new HWGame(config, ui.pageLocalGame->gameCFG);
|
|
170 |
game->StartQuick();
|
|
171 |
}
|
|
172 |
|
|
173 |
void HWForm::PlayDemo()
|
|
174 |
{
|
|
175 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
|
|
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 |
}
|
|
184 |
game = new HWGame(config, 0);
|
|
185 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1");
|
|
186 |
}
|
|
187 |
|
|
188 |
void HWForm::NetConnect()
|
|
189 |
{
|
|
190 |
hwnet = new HWNet(config);
|
|
191 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
|
|
192 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
|
|
193 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
|
|
194 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
|
|
195 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
|
|
196 |
config->SaveOptions();
|
|
197 |
}
|
|
198 |
|
|
199 |
void HWForm::NetDisconnect()
|
|
200 |
{
|
|
201 |
hwnet->Disconnect();
|
|
202 |
GoToNet();
|
|
203 |
}
|
|
204 |
|
|
205 |
void HWForm::AddGame(const QString & chan)
|
|
206 |
{
|
|
207 |
ui.pageNetChat->ChannelsList->addItem(chan);
|
|
208 |
}
|
|
209 |
|
|
210 |
void HWForm::NetGameEnter()
|
|
211 |
{
|
|
212 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG);
|
|
213 |
}
|
|
214 |
|
|
215 |
void HWForm::NetJoin()
|
|
216 |
{
|
|
217 |
hwnet->JoinGame("#hw");
|
|
218 |
}
|
|
219 |
|
|
220 |
void HWForm::NetCreate()
|
|
221 |
{
|
|
222 |
hwnet->JoinGame("#hw");
|
|
223 |
}
|
|
224 |
|
|
225 |
void HWForm::NetAddTeam()
|
|
226 |
{
|
|
227 |
HWTeam team("DefaultTeam");
|
|
228 |
team.LoadFromFile();
|
|
229 |
hwnet->AddTeam(team);
|
|
230 |
}
|
|
231 |
|
|
232 |
void HWForm::NetStartGame()
|
|
233 |
{
|
|
234 |
hwnet->StartGame();
|
|
235 |
}
|
|
236 |
|
|
237 |
void HWForm::ChangeInNetTeams(const QStringList & teams)
|
|
238 |
{
|
|
239 |
ui.pageNetGame->listNetTeams->clear();
|
|
240 |
ui.pageNetGame->listNetTeams->addItems(teams);
|
|
241 |
}
|
|
242 |
|
|
243 |
void HWForm::StartMPGame()
|
|
244 |
{
|
|
245 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG);
|
|
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));
|
|
249 |
}
|
|
250 |
game->StartLocal();
|
|
251 |
}
|