73 |
73 |
74 HWForm::HWForm(QWidget *parent) |
74 HWForm::HWForm(QWidget *parent) |
75 : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) |
75 : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) |
76 { |
76 { |
77 #ifdef USE_XFIRE |
77 #ifdef USE_XFIRE |
78 xfire_init(); |
78 xfire_init(); |
79 #endif |
79 #endif |
80 gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
80 gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat); |
81 frontendEffects = gameSettings->value("video/frontendeffects", true).toBool(); |
81 frontendEffects = gameSettings->value("video/frontendeffects", true).toBool(); |
82 playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex()); |
82 playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex()); |
83 |
83 |
84 ui.setupUi(this); |
84 ui.setupUi(this); |
85 |
85 |
86 CustomizePalettes(); |
86 CustomizePalettes(); |
87 |
87 |
88 ui.pageOptions->CBResolution->addItems(sdli.getResolutions()); |
88 ui.pageOptions->CBResolution->addItems(sdli.getResolutions()); |
89 |
89 |
90 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
90 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
91 |
91 |
92 namegen = new HWNamegen(); |
92 namegen = new HWNamegen(); |
93 |
93 |
94 #ifdef __APPLE__ |
94 #ifdef __APPLE__ |
95 panel = new M3Panel; |
95 panel = new M3Panel; |
96 #ifdef SPARKLE_ENABLED |
96 #ifdef SPARKLE_ENABLED |
97 AutoUpdater* updater; |
97 AutoUpdater* updater; |
98 CocoaInitializer initializer; |
98 CocoaInitializer initializer; |
99 updater = new SparkleAutoUpdater(SPARKLE_APPCAST_URL); |
99 updater = new SparkleAutoUpdater(SPARKLE_APPCAST_URL); |
100 if(updater && config->isAutoUpdateEnabled()) |
100 if(updater && config->isAutoUpdateEnabled()) |
101 updater->checkForUpdates(); |
101 updater->checkForUpdates(); |
102 #endif |
102 #endif |
103 #endif |
103 #endif |
104 |
104 |
105 UpdateTeamsLists(); |
105 UpdateTeamsLists(); |
106 UpdateWeapons(); |
106 UpdateWeapons(); |
107 |
107 |
108 connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool))); |
108 connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool))); |
109 onFrontendFullscreen(config->isFrontendFullscreen()); |
109 onFrontendFullscreen(config->isFrontendFullscreen()); |
110 |
110 |
111 connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
111 connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
112 connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
112 connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
113 connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNetType())); |
113 connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNetType())); |
114 connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
114 connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
115 connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); |
115 connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); |
116 connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); |
116 connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); |
117 |
117 |
118 connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
118 connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
119 connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
119 connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
120 |
120 |
121 connect(ui.pageEditTeam->signalMapper, SIGNAL(mapped(const int &)), this, SLOT(RandomName(const int &))); |
121 connect(ui.pageEditTeam->signalMapper, SIGNAL(mapped(const int &)), this, SLOT(RandomName(const int &))); |
122 connect(ui.pageEditTeam->randTeamButton, SIGNAL(clicked()), this, SLOT(RandomNames())); |
122 connect(ui.pageEditTeam->randTeamButton, SIGNAL(clicked()), this, SLOT(RandomNames())); |
123 |
123 |
124 connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
124 connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
125 connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
125 connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
126 connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
126 connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
127 ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
127 ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
128 connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
128 connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
129 connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToSchemes()), this, SLOT(GoToSchemes())); |
129 connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToSchemes()), this, SLOT(GoToSchemes())); |
130 connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToWeapons(const QString &)), this, SLOT(GoToSelectWeaponSet(const QString &))); |
130 connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToWeapons(const QString &)), this, SLOT(GoToSelectWeaponSet(const QString &))); |
131 |
131 |
132 connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
132 connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
133 connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
133 connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
134 connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
134 connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
135 |
135 |
136 connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
136 connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
137 connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
137 connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
138 connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
138 connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
139 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
139 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
140 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
140 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
141 |
141 |
142 connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); |
142 connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); |
143 connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon())); |
143 connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon())); |
144 connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons())); |
144 connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons())); |
145 |
145 |
146 connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
146 connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
147 connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
147 connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
148 connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
148 connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
149 connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
149 connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
150 |
150 |
151 connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
151 connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
152 connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
152 connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
153 |
153 |
154 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
154 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
155 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
155 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
156 ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
156 ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
157 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
157 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
158 ui.pageNetGame->BtnStart, SLOT(setEnabled(bool))); |
158 ui.pageNetGame->BtnStart, SLOT(setEnabled(bool))); |
159 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
159 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
160 connect(ui.pageNetGame->pGameCFG, SIGNAL(goToSchemes()), this, SLOT(GoToSchemes())); |
160 connect(ui.pageNetGame->pGameCFG, SIGNAL(goToSchemes()), this, SLOT(GoToSchemes())); |
161 connect(ui.pageNetGame->pGameCFG, SIGNAL(goToWeapons(const QString &)), this, SLOT(GoToSelectWeaponSet(const QString &))); |
161 connect(ui.pageNetGame->pGameCFG, SIGNAL(goToWeapons(const QString &)), this, SLOT(GoToSelectWeaponSet(const QString &))); |
162 |
162 |
163 connect(ui.pageRoomsList->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
163 connect(ui.pageRoomsList->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
164 connect(ui.pageRoomsList->BtnAdmin, SIGNAL(clicked()), this, SLOT(GoToAdmin())); |
164 connect(ui.pageRoomsList->BtnAdmin, SIGNAL(clicked()), this, SLOT(GoToAdmin())); |
165 |
165 |
166 connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
166 connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
167 |
167 |
168 connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
168 connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
169 |
169 |
170 connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
170 connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
171 connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining())); |
171 connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining())); |
172 connect(ui.pageSinglePlayer->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
172 connect(ui.pageSinglePlayer->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
173 connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
173 connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
174 connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
174 connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
175 connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
175 connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
176 |
176 |
177 connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); |
177 connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); |
178 connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
178 connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
179 |
179 |
180 connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
180 connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
181 |
181 |
182 connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()), |
182 connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()), |
183 ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first |
183 ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first |
184 connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
184 connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
185 this, SLOT(UpdateWeapons())); // executed second |
185 this, SLOT(UpdateWeapons())); // executed second |
186 connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
186 connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
187 this, SLOT(GoBack())); // executed third |
187 this, SLOT(GoBack())); // executed third |
188 |
188 |
189 connect(ui.pageScheme->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
189 connect(ui.pageScheme->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
190 |
190 |
191 connect(ui.pageAdmin->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
191 connect(ui.pageAdmin->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
192 |
192 |
193 connect(ui.pageNetType->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
193 connect(ui.pageNetType->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
194 connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet())); |
194 connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet())); |
195 connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer())); |
195 connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer())); |
196 |
196 |
197 |
197 |
198 ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini"); |
198 ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini"); |
199 ui.pageScheme->setModel(ammoSchemeModel); |
199 ui.pageScheme->setModel(ammoSchemeModel); |
200 ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel); |
200 ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel); |
201 |
201 |
202 wBackground = NULL; |
202 wBackground = NULL; |
203 if (config->isFrontendEffects()) { |
203 if (config->isFrontendEffects()) { |
204 wBackground = new BGWidget(this); |
204 wBackground = new BGWidget(this); |
205 wBackground->setFixedSize(this->width(), this->height()); |
205 wBackground->setFixedSize(this->width(), this->height()); |
206 wBackground->lower(); |
206 wBackground->lower(); |
207 wBackground->init(); |
207 wBackground->init(); |
208 wBackground->startAnimation(); |
208 wBackground->startAnimation(); |
209 } |
209 } |
210 |
210 |
211 PagesStack.push(ID_PAGE_MAIN); |
211 PagesStack.push(ID_PAGE_MAIN); |
212 GoBack(); |
212 GoBack(); |
213 } |
213 } |
214 |
214 |
215 #ifdef USE_XFIRE |
215 #ifdef USE_XFIRE |
216 void HWForm::updateXfire(void) |
216 void HWForm::updateXfire(void) |
217 { |
217 { |
218 if(hwnet) |
218 if(hwnet) |
219 { |
219 { |
220 xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii()); |
220 xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii()); |
221 switch(hwnet->getClientState()) |
221 switch(hwnet->getClientState()) |
222 { |
222 { |
223 case 1: // Connecting |
223 case 1: // Connecting |
224 xfire_setvalue(XFIRE_STATUS, "Connecting"); |
224 xfire_setvalue(XFIRE_STATUS, "Connecting"); |
225 xfire_setvalue(XFIRE_NICKNAME, "-"); |
225 xfire_setvalue(XFIRE_NICKNAME, "-"); |
226 xfire_setvalue(XFIRE_ROOM, "-"); |
226 xfire_setvalue(XFIRE_ROOM, "-"); |
227 case 2: // In lobby |
227 case 2: // In lobby |
228 xfire_setvalue(XFIRE_STATUS, "Online"); |
228 xfire_setvalue(XFIRE_STATUS, "Online"); |
229 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); |
229 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); |
230 xfire_setvalue(XFIRE_ROOM, "In game lobby"); |
230 xfire_setvalue(XFIRE_ROOM, "In game lobby"); |
231 break; |
231 break; |
232 case 3: // In room |
232 case 3: // In room |
233 xfire_setvalue(XFIRE_STATUS, "Online"); |
233 xfire_setvalue(XFIRE_STATUS, "Online"); |
234 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); |
234 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); |
235 xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii()); |
235 xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii()); |
236 break; |
236 break; |
237 case 5: // In game |
237 case 5: // In game |
238 xfire_setvalue(XFIRE_STATUS, "Online"); |
238 xfire_setvalue(XFIRE_STATUS, "Online"); |
239 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); |
239 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); |
240 xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii()); |
240 xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii()); |
241 break; |
241 break; |
242 default: |
242 default: |
243 break; |
243 break; |
244 } |
244 } |
245 } |
245 } |
246 else |
246 else |
247 { |
247 { |
248 xfire_setvalue(XFIRE_STATUS, "Offline"); |
248 xfire_setvalue(XFIRE_STATUS, "Offline"); |
249 xfire_setvalue(XFIRE_NICKNAME, "-"); |
249 xfire_setvalue(XFIRE_NICKNAME, "-"); |
250 xfire_setvalue(XFIRE_ROOM, "-"); |
250 xfire_setvalue(XFIRE_ROOM, "-"); |
251 xfire_setvalue(XFIRE_SERVER, "-"); |
251 xfire_setvalue(XFIRE_SERVER, "-"); |
252 } |
252 } |
253 xfire_update(); |
253 xfire_update(); |
254 } |
254 } |
255 #endif |
255 #endif |
256 |
256 |
257 void HWForm::onFrontendFullscreen(bool value) |
257 void HWForm::onFrontendFullscreen(bool value) |
258 { |
258 { |
263 } |
263 } |
264 } |
264 } |
265 |
265 |
266 void HWForm::CustomizePalettes() |
266 void HWForm::CustomizePalettes() |
267 { |
267 { |
268 QList<QScrollBar *> allSBars = findChildren<QScrollBar *>(); |
268 QList<QScrollBar *> allSBars = findChildren<QScrollBar *>(); |
269 QPalette pal = palette(); |
269 QPalette pal = palette(); |
270 pal.setColor(QPalette::WindowText, QColor(0xff, 0xcc, 0x00)); |
270 pal.setColor(QPalette::WindowText, QColor(0xff, 0xcc, 0x00)); |
271 pal.setColor(QPalette::Button, QColor(0x00, 0x35, 0x1d)); |
271 pal.setColor(QPalette::Button, QColor(0x00, 0x35, 0x1d)); |
272 pal.setColor(QPalette::Base, QColor(0x00, 0x35, 0x1d)); |
272 pal.setColor(QPalette::Base, QColor(0x00, 0x35, 0x1d)); |
273 pal.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); |
273 pal.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); |
274 |
274 |
275 for (int i = 0; i < allSBars.size(); ++i) |
275 for (int i = 0; i < allSBars.size(); ++i) |
276 allSBars.at(i)->setPalette(pal); |
276 allSBars.at(i)->setPalette(pal); |
277 } |
277 } |
278 |
278 |
279 void HWForm::UpdateWeapons() |
279 void HWForm::UpdateWeapons() |
280 { |
280 { |
281 QVector<QComboBox*> combos; |
281 QVector<QComboBox*> combos; |
282 combos.push_back(ui.pageOptions->WeaponsName); |
282 combos.push_back(ui.pageOptions->WeaponsName); |
283 combos.push_back(ui.pageMultiplayer->gameCFG->WeaponsName); |
283 combos.push_back(ui.pageMultiplayer->gameCFG->WeaponsName); |
284 combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName); |
284 combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName); |
285 |
285 |
286 QStringList names = ui.pageSelectWeapon->pWeapons->getWeaponNames(); |
286 QStringList names = ui.pageSelectWeapon->pWeapons->getWeaponNames(); |
287 |
287 |
288 for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it) { |
288 for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it) { |
289 (*it)->clear(); |
289 (*it)->clear(); |
290 |
290 |
291 for(int i = 0; i < names.size(); ++i) |
291 for(int i = 0; i < names.size(); ++i) |
292 (*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i])); |
292 (*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i])); |
293 |
293 |
294 int pos = (*it)->findText("Default"); |
294 int pos = (*it)->findText("Default"); |
295 if (pos != -1) { |
295 if (pos != -1) { |
296 (*it)->setCurrentIndex(pos); |
296 (*it)->setCurrentIndex(pos); |
297 } |
297 } |
298 } |
298 } |
299 } |
299 } |
300 |
300 |
301 void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
301 void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
302 { |
302 { |
303 QStringList teamslist; |
303 QStringList teamslist; |
304 if(editable_teams) { |
304 if(editable_teams) { |
305 teamslist =* editable_teams; |
305 teamslist =* editable_teams; |
306 } else { |
306 } else { |
307 teamslist = config->GetTeamsList(); |
307 teamslist = config->GetTeamsList(); |
308 } |
308 } |
309 |
309 |
310 if(teamslist.empty()) { |
310 if(teamslist.empty()) { |
311 HWTeam defaultTeam("DefaultTeam"); |
311 HWTeam defaultTeam("DefaultTeam"); |
312 defaultTeam.SaveToFile(); |
312 defaultTeam.SaveToFile(); |
313 teamslist.push_back("DefaultTeam"); |
313 teamslist.push_back("DefaultTeam"); |
314 } |
314 } |
315 |
315 |
316 ui.pageOptions->CBTeamName->clear(); |
316 ui.pageOptions->CBTeamName->clear(); |
317 ui.pageOptions->CBTeamName->addItems(teamslist); |
317 ui.pageOptions->CBTeamName->addItems(teamslist); |
318 } |
318 } |
319 |
319 |
320 void HWForm::GoToMain() |
320 void HWForm::GoToMain() |
321 { |
321 { |
322 GoToPage(ID_PAGE_MAIN); |
322 GoToPage(ID_PAGE_MAIN); |
323 } |
323 } |
324 |
324 |
325 void HWForm::GoToSinglePlayer() |
325 void HWForm::GoToSinglePlayer() |
326 { |
326 { |
327 GoToPage(ID_PAGE_SINGLEPLAYER); |
327 GoToPage(ID_PAGE_SINGLEPLAYER); |
328 } |
328 } |
329 |
329 |
330 void HWForm::GoToTraining() |
330 void HWForm::GoToTraining() |
331 { |
331 { |
332 GoToPage(ID_PAGE_TRAINING); |
332 GoToPage(ID_PAGE_TRAINING); |
333 } |
333 } |
334 |
334 |
335 void HWForm::GoToSetup() |
335 void HWForm::GoToSetup() |
336 { |
336 { |
337 GoToPage(ID_PAGE_SETUP); |
337 GoToPage(ID_PAGE_SETUP); |
338 } |
338 } |
339 |
339 |
340 void HWForm::GoToSelectNewWeapon() |
340 void HWForm::GoToSelectNewWeapon() |
341 { |
341 { |
342 ui.pageSelectWeapon->pWeapons->setWeaponsName(tr("new")); |
342 ui.pageSelectWeapon->pWeapons->setWeaponsName(tr("new")); |
343 GoToPage(ID_PAGE_SELECTWEAPON); |
343 GoToPage(ID_PAGE_SELECTWEAPON); |
344 } |
344 } |
345 |
345 |
346 void HWForm::GoToSelectWeapon() |
346 void HWForm::GoToSelectWeapon() |
347 { |
347 { |
348 ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText()); |
348 ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText()); |
349 GoToPage(ID_PAGE_SELECTWEAPON); |
349 GoToPage(ID_PAGE_SELECTWEAPON); |
350 } |
350 } |
351 |
351 |
352 void HWForm::GoToSelectWeaponSet(const QString & name) |
352 void HWForm::GoToSelectWeaponSet(const QString & name) |
353 { |
353 { |
354 ui.pageSelectWeapon->pWeapons->setWeaponsName(name); |
354 ui.pageSelectWeapon->pWeapons->setWeaponsName(name); |
355 GoToPage(ID_PAGE_SELECTWEAPON); |
355 GoToPage(ID_PAGE_SELECTWEAPON); |
356 } |
356 } |
357 |
357 |
358 void HWForm::GoToInfo() |
358 void HWForm::GoToInfo() |
359 { |
359 { |
360 GoToPage(ID_PAGE_INFO); |
360 GoToPage(ID_PAGE_INFO); |
361 } |
361 } |
362 |
362 |
363 void HWForm::GoToMultiplayer() |
363 void HWForm::GoToMultiplayer() |
364 { |
364 { |
365 GoToPage(ID_PAGE_MULTIPLAYER); |
365 GoToPage(ID_PAGE_MULTIPLAYER); |
366 } |
366 } |
367 |
367 |
368 void HWForm::GoToSaves() |
368 void HWForm::GoToSaves() |
369 { |
369 { |
370 ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Save); |
370 ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Save); |
371 |
371 |
372 GoToPage(ID_PAGE_DEMOS); |
372 GoToPage(ID_PAGE_DEMOS); |
373 } |
373 } |
374 |
374 |
375 void HWForm::GoToDemos() |
375 void HWForm::GoToDemos() |
376 { |
376 { |
377 ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Demo); |
377 ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Demo); |
378 |
378 |
379 GoToPage(ID_PAGE_DEMOS); |
379 GoToPage(ID_PAGE_DEMOS); |
380 } |
380 } |
381 |
381 |
382 void HWForm::GoToNet() |
382 void HWForm::GoToNet() |
383 { |
383 { |
384 ui.pageNet->updateServersList(); |
384 ui.pageNet->updateServersList(); |
385 |
385 |
386 GoToPage(ID_PAGE_NET); |
386 GoToPage(ID_PAGE_NET); |
387 } |
387 } |
388 |
388 |
389 void HWForm::GoToNetType() |
389 void HWForm::GoToNetType() |
390 { |
390 { |
391 GoToPage(ID_PAGE_NETTYPE); |
391 GoToPage(ID_PAGE_NETTYPE); |
392 } |
392 } |
393 |
393 |
394 void HWForm::GoToNetServer() |
394 void HWForm::GoToNetServer() |
395 { |
395 { |
396 GoToPage(ID_PAGE_NETSERVER); |
396 GoToPage(ID_PAGE_NETSERVER); |
397 } |
397 } |
398 |
398 |
399 void HWForm::GoToSchemes() |
399 void HWForm::GoToSchemes() |
400 { |
400 { |
401 GoToPage(ID_PAGE_SCHEME); |
401 GoToPage(ID_PAGE_SCHEME); |
402 } |
402 } |
403 |
403 |
404 void HWForm::GoToAdmin() |
404 void HWForm::GoToAdmin() |
405 { |
405 { |
406 GoToPage(ID_PAGE_ADMIN); |
406 GoToPage(ID_PAGE_ADMIN); |
407 } |
407 } |
408 |
408 |
409 void HWForm::OnPageShown(quint8 id, quint8 lastid) |
409 void HWForm::OnPageShown(quint8 id, quint8 lastid) |
410 { |
410 { |
411 #ifdef USE_XFIRE |
411 #ifdef USE_XFIRE |
412 updateXfire(); |
412 updateXfire(); |
413 #endif |
413 #endif |
414 if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) { |
414 if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) { |
415 QStringList tmNames = config->GetTeamsList(); |
415 QStringList tmNames = config->GetTeamsList(); |
416 TeamSelWidget* curTeamSelWidget; |
416 TeamSelWidget* curTeamSelWidget; |
417 |
417 |
418 if(id == ID_PAGE_MULTIPLAYER) { |
418 if(id == ID_PAGE_MULTIPLAYER) { |
419 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
419 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
420 } else { |
420 } else { |
421 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
421 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
422 } |
422 } |
423 |
423 |
424 QList<HWTeam> teamsList; |
424 QList<HWTeam> teamsList; |
425 for(QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++) { |
425 for(QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++) { |
426 HWTeam team(*it); |
426 HWTeam team(*it); |
427 team.LoadFromFile(); |
427 team.LoadFromFile(); |
428 teamsList.push_back(team); |
428 teamsList.push_back(team); |
429 } |
429 } |
430 |
430 |
431 if(lastid == ID_PAGE_SETUP) { // _TEAM |
431 if(lastid == ID_PAGE_SETUP) { // _TEAM |
432 if (editedTeam) { |
432 if (editedTeam) { |
433 curTeamSelWidget->addTeam(*editedTeam); |
433 curTeamSelWidget->addTeam(*editedTeam); |
434 } |
434 } |
435 } else if(lastid != ID_PAGE_GAMESTATS |
435 } else if(lastid != ID_PAGE_GAMESTATS |
436 && lastid != ID_PAGE_INGAME |
436 && lastid != ID_PAGE_INGAME |
437 && lastid != ID_PAGE_SCHEME |
437 && lastid != ID_PAGE_SCHEME |
438 && lastid != ID_PAGE_SELECTWEAPON) { |
438 && lastid != ID_PAGE_SELECTWEAPON) { |
439 curTeamSelWidget->resetPlayingTeams(teamsList); |
439 curTeamSelWidget->resetPlayingTeams(teamsList); |
440 } |
440 } |
441 } else |
441 } else |
442 if (id == ID_PAGE_GAMESTATS) |
442 if (id == ID_PAGE_GAMESTATS) |
443 { |
443 { |
444 ui.pageGameStats->renderStats(); |
444 ui.pageGameStats->renderStats(); |
445 } |
445 } |
446 |
446 |
447 // load and save ignore/friends lists |
447 // load and save ignore/friends lists |
448 if(lastid == ID_PAGE_MULTIPLAYER || lastid == ID_PAGE_NETGAME) // leaving a room |
448 if(lastid == ID_PAGE_MULTIPLAYER || lastid == ID_PAGE_NETGAME) // leaving a room |
449 ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text()); |
449 ui.pageNetGame->pChatWidget->saveLists(ui.pageOptions->editNetNick->text()); |
450 else if(lastid == ID_PAGE_ROOMSLIST) // leaving the lobby |
450 else if(lastid == ID_PAGE_ROOMSLIST) // leaving the lobby |
451 ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text()); |
451 ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text()); |
452 if(id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) // joining a room |
452 if(id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) // joining a room |
453 ui.pageNetGame->pChatWidget->loadLists(ui.pageOptions->editNetNick->text()); |
453 ui.pageNetGame->pChatWidget->loadLists(ui.pageOptions->editNetNick->text()); |
454 else if(id == ID_PAGE_ROOMSLIST) // joining the lobby |
454 else if(id == ID_PAGE_ROOMSLIST) // joining the lobby |
455 ui.pageRoomsList->chatWidget->loadLists(ui.pageOptions->editNetNick->text()); |
455 ui.pageRoomsList->chatWidget->loadLists(ui.pageOptions->editNetNick->text()); |
456 } |
456 } |
457 |
457 |
458 void HWForm::GoToPage(quint8 id) |
458 void HWForm::GoToPage(quint8 id) |
459 { |
459 { |
460 quint8 lastid = ui.Pages->currentIndex(); |
460 quint8 lastid = ui.Pages->currentIndex(); |
461 PagesStack.push(ui.Pages->currentIndex()); |
461 PagesStack.push(ui.Pages->currentIndex()); |
462 OnPageShown(id, lastid); |
462 OnPageShown(id, lastid); |
463 ui.Pages->setCurrentIndex(id); |
463 ui.Pages->setCurrentIndex(id); |
464 } |
464 } |
465 |
465 |
466 void HWForm::GoBack() |
466 void HWForm::GoBack() |
467 { |
467 { |
468 quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
468 quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
469 quint8 curid = ui.Pages->currentIndex(); |
469 quint8 curid = ui.Pages->currentIndex(); |
470 ui.Pages->setCurrentIndex(id); |
470 ui.Pages->setCurrentIndex(id); |
471 OnPageShown(id, curid); |
471 OnPageShown(id, curid); |
472 |
472 |
473 if (id == ID_PAGE_CONNECTING) |
473 if (id == ID_PAGE_CONNECTING) |
474 GoBack(); |
474 GoBack(); |
475 if (id == ID_PAGE_NETSERVER) |
475 if (id == ID_PAGE_NETSERVER) |
476 GoBack(); |
476 GoBack(); |
477 if ((!hwnet) && (id == ID_PAGE_ROOMSLIST)) |
477 if ((!hwnet) && (id == ID_PAGE_ROOMSLIST)) |
478 GoBack(); |
478 GoBack(); |
479 |
479 |
480 if ((!hwnet) || (!hwnet->isInRoom())) |
480 if ((!hwnet) || (!hwnet->isInRoom())) |
481 if (id == ID_PAGE_NETGAME || id == ID_PAGE_NETGAME) |
481 if (id == ID_PAGE_NETGAME || id == ID_PAGE_NETGAME) |
482 GoBack(); |
482 GoBack(); |
483 |
483 |
484 if (curid == ID_PAGE_ROOMSLIST) NetDisconnect(); |
484 if (curid == ID_PAGE_ROOMSLIST) NetDisconnect(); |
485 |
485 |
486 if (curid == ID_PAGE_SCHEME) |
486 if (curid == ID_PAGE_SCHEME) |
487 ammoSchemeModel->Save(); |
487 ammoSchemeModel->Save(); |
488 } |
488 } |
489 |
489 |
490 void HWForm::btnExitPressed() |
490 void HWForm::btnExitPressed() |
491 { |
491 { |
492 eggTimer.start(); |
492 eggTimer.start(); |
493 } |
493 } |
494 |
494 |
495 void HWForm::btnExitClicked() |
495 void HWForm::btnExitClicked() |
496 { |
496 { |
497 if (eggTimer.elapsed() < 3000){ |
497 if (eggTimer.elapsed() < 3000){ |
498 #ifdef __APPLE__ |
498 #ifdef __APPLE__ |
499 panel->showInstallController(); |
499 panel->showInstallController(); |
500 #endif |
500 #endif |
501 close(); |
501 close(); |
502 } |
502 } |
503 else |
503 else |
504 { |
504 { |
505 QPushButton * btn = findChild<QPushButton *>("imageButt"); |
505 QPushButton * btn = findChild<QPushButton *>("imageButt"); |
506 if (btn) |
506 if (btn) |
507 { |
507 { |
508 btn->setIcon(QIcon(":/res/bonus.png")); |
508 btn->setIcon(QIcon(":/res/bonus.png")); |
509 } |
509 } |
510 } |
510 } |
511 } |
511 } |
512 |
512 |
513 void HWForm::IntermediateSetup() |
513 void HWForm::IntermediateSetup() |
514 { |
514 { |
515 quint8 id=ui.Pages->currentIndex(); |
515 quint8 id=ui.Pages->currentIndex(); |
516 TeamSelWidget* curTeamSelWidget; |
516 TeamSelWidget* curTeamSelWidget; |
517 |
517 |
518 if(id == ID_PAGE_MULTIPLAYER) { |
518 if(id == ID_PAGE_MULTIPLAYER) { |
519 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
519 curTeamSelWidget = ui.pageMultiplayer->teamsSelect; |
520 } else { |
520 } else { |
521 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
521 curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget; |
522 } |
522 } |
523 |
523 |
524 QList<HWTeam> teams = curTeamSelWidget->getDontPlayingTeams(); |
524 QList<HWTeam> teams = curTeamSelWidget->getDontPlayingTeams(); |
525 QStringList tmnames; |
525 QStringList tmnames; |
526 for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) { |
526 for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) { |
527 tmnames += it->TeamName; |
527 tmnames += it->TeamName; |
528 } |
528 } |
529 UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring |
529 UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring |
530 |
530 |
531 GoToPage(ID_PAGE_SETUP); |
531 GoToPage(ID_PAGE_SETUP); |
532 } |
532 } |
533 |
533 |
534 void HWForm::NewTeam() |
534 void HWForm::NewTeam() |
535 { |
535 { |
536 editedTeam = new HWTeam("unnamed"); |
536 editedTeam = new HWTeam("unnamed"); |
537 editedTeam->SetToPage(this); |
537 editedTeam->SetToPage(this); |
538 GoToPage(ID_PAGE_SETUP_TEAM); |
538 GoToPage(ID_PAGE_SETUP_TEAM); |
539 } |
539 } |
540 |
540 |
541 void HWForm::EditTeam() |
541 void HWForm::EditTeam() |
542 { |
542 { |
543 editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
543 editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
544 editedTeam->LoadFromFile(); |
544 editedTeam->LoadFromFile(); |
545 editedTeam->SetToPage(this); |
545 editedTeam->SetToPage(this); |
546 GoToPage(ID_PAGE_SETUP_TEAM); |
546 GoToPage(ID_PAGE_SETUP_TEAM); |
547 } |
547 } |
548 |
548 |
549 void HWForm::RandomNames() |
549 void HWForm::RandomNames() |
550 { |
550 { |
551 editedTeam->GetFromPage(this); |
551 editedTeam->GetFromPage(this); |
552 namegen->TeamRandomNames(editedTeam,FALSE); |
552 namegen->TeamRandomNames(editedTeam,FALSE); |
553 editedTeam->SetToPage(this); |
553 editedTeam->SetToPage(this); |
554 } |
554 } |
555 |
555 |
556 void HWForm::RandomName(const int &i) |
556 void HWForm::RandomName(const int &i) |
557 { |
557 { |
558 editedTeam->GetFromPage(this); |
558 editedTeam->GetFromPage(this); |
559 namegen->TeamRandomName(editedTeam,i); |
559 namegen->TeamRandomName(editedTeam,i); |
560 editedTeam->SetToPage(this); |
560 editedTeam->SetToPage(this); |
561 } |
561 } |
562 |
562 |
563 void HWForm::TeamSave() |
563 void HWForm::TeamSave() |
564 { |
564 { |
565 editedTeam->GetFromPage(this); |
565 editedTeam->GetFromPage(this); |
566 editedTeam->SaveToFile(); |
566 editedTeam->SaveToFile(); |
567 delete editedTeam; |
567 delete editedTeam; |
568 editedTeam=0; |
568 editedTeam=0; |
569 UpdateTeamsLists(); |
569 UpdateTeamsLists(); |
570 GoBack(); |
570 GoBack(); |
571 } |
571 } |
572 |
572 |
573 void HWForm::TeamDiscard() |
573 void HWForm::TeamDiscard() |
574 { |
574 { |
575 delete editedTeam; |
575 delete editedTeam; |
576 editedTeam=0; |
576 editedTeam=0; |
577 GoBack(); |
577 GoBack(); |
578 } |
578 } |
579 |
579 |
580 void HWForm::SimpleGame() |
580 void HWForm::SimpleGame() |
581 { |
581 { |
582 CreateGame(0, 0, *cDefaultAmmoStore); |
582 CreateGame(0, 0, *cDefaultAmmoStore); |
583 game->StartQuick(); |
583 game->StartQuick(); |
584 } |
584 } |
585 |
585 |
586 void HWForm::PlayDemo() |
586 void HWForm::PlayDemo() |
587 { |
587 { |
588 QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
588 QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
589 if (!curritem) |
589 if (!curritem) |
590 { |
590 { |
591 QMessageBox::critical(this, |
591 QMessageBox::critical(this, |
592 tr("Error"), |
592 tr("Error"), |
593 tr("Please select record from the list above"), |
593 tr("Please select record from the list above"), |
594 tr("OK")); |
594 tr("OK")); |
595 return ; |
595 return ; |
596 } |
596 } |
597 CreateGame(0, 0, 0); |
597 CreateGame(0, 0, 0); |
598 game->PlayDemo(curritem->data(Qt::UserRole).toString()); |
598 game->PlayDemo(curritem->data(Qt::UserRole).toString()); |
599 } |
599 } |
600 |
600 |
601 void HWForm::NetConnectServer(const QString & host, quint16 port) |
601 void HWForm::NetConnectServer(const QString & host, quint16 port) |
602 { |
602 { |
603 _NetConnect(host, port, ui.pageOptions->editNetNick->text()); |
603 _NetConnect(host, port, ui.pageOptions->editNetNick->text()); |
604 } |
604 } |
605 |
605 |
606 void HWForm::NetConnectOfficialServer() |
606 void HWForm::NetConnectOfficialServer() |
607 { |
607 { |
608 NetConnectServer("netserver.hedgewars.org", 46631); |
608 NetConnectServer("netserver.hedgewars.org", 46631); |
609 } |
609 } |
610 |
610 |
611 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
611 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
612 { |
612 { |
613 if(hwnet) { |
613 if(hwnet) { |
614 hwnet->Disconnect(); |
614 hwnet->Disconnect(); |
615 delete hwnet; |
615 delete hwnet; |
616 hwnet=0; |
616 hwnet=0; |
617 } |
617 } |
618 |
618 |
619 ui.pageRoomsList->chatWidget->clear(); |
619 ui.pageRoomsList->chatWidget->clear(); |
620 |
620 |
621 hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
621 hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
622 |
622 |
623 GoToPage(ID_PAGE_CONNECTING); |
623 GoToPage(ID_PAGE_CONNECTING); |
624 |
624 |
625 connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
625 connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
626 |
626 |
627 connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
627 connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
628 connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected())); |
628 connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected())); |
629 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
629 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
630 connect(hwnet, SIGNAL(LeftRoom()), this, SLOT(NetLeftRoom())); |
630 connect(hwnet, SIGNAL(LeftRoom()), this, SLOT(NetLeftRoom())); |
631 connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); |
631 connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); |
632 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
632 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
633 |
633 |
634 // rooms list page stuff |
634 // rooms list page stuff |
635 connect(hwnet, SIGNAL(roomsList(const QStringList&)), |
635 connect(hwnet, SIGNAL(roomsList(const QStringList&)), |
636 ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
636 ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
637 connect(hwnet, SIGNAL(adminAccess(bool)), |
637 connect(hwnet, SIGNAL(adminAccess(bool)), |
638 ui.pageRoomsList, SLOT(setAdmin(bool))); |
638 ui.pageRoomsList, SLOT(setAdmin(bool))); |
639 connect(hwnet, SIGNAL(adminAccess(bool)), |
639 connect(hwnet, SIGNAL(adminAccess(bool)), |
640 ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool))); |
640 ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool))); |
641 |
641 |
642 connect(hwnet, SIGNAL(serverMessage(const QString&)), |
642 connect(hwnet, SIGNAL(serverMessage(const QString&)), |
643 ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&))); |
643 ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&))); |
644 |
644 |
645 connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
645 connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
646 hwnet, SLOT(CreateRoom(const QString&))); |
646 hwnet, SLOT(CreateRoom(const QString&))); |
647 connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)), |
647 connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)), |
648 hwnet, SLOT(JoinRoom(const QString&))); |
648 hwnet, SLOT(JoinRoom(const QString&))); |
649 // connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
649 // connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
650 // this, SLOT(NetGameMaster())); |
650 // this, SLOT(NetGameMaster())); |
651 // connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)), |
651 // connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)), |
652 // this, SLOT(NetGameSlave())); |
652 // this, SLOT(NetGameSlave())); |
653 connect(ui.pageRoomsList, SIGNAL(askForRoomList()), |
653 connect(ui.pageRoomsList, SIGNAL(askForRoomList()), |
654 hwnet, SLOT(askRoomsList())); |
654 hwnet, SLOT(askRoomsList())); |
655 |
655 |
656 // room status stuff |
656 // room status stuff |
657 connect(hwnet, SIGNAL(roomMaster(bool)), |
657 connect(hwnet, SIGNAL(roomMaster(bool)), |
658 this, SLOT(NetGameChangeStatus(bool))); |
658 this, SLOT(NetGameChangeStatus(bool))); |
659 |
659 |
660 // net page stuff |
660 // net page stuff |
661 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
661 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
662 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&))); |
662 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&))); |
663 connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)), |
663 connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)), |
664 ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool))); |
664 ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool))); |
665 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
665 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
666 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&))); |
666 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&))); |
667 connect(hwnet, SIGNAL(roomMaster(bool)), |
667 connect(hwnet, SIGNAL(roomMaster(bool)), |
668 ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool))); |
668 ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool))); |
669 connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
669 connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
670 hwnet, SLOT(chatLineToNet(const QString&))); |
670 hwnet, SLOT(chatLineToNet(const QString&))); |
671 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
671 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
672 connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
672 connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
673 ui.pageNetGame, SLOT(setReadyStatus(bool))); |
673 ui.pageNetGame, SLOT(setReadyStatus(bool))); |
674 |
674 |
675 // chat widget actions |
675 // chat widget actions |
676 connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)), |
676 connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)), |
677 hwnet, SLOT(kickPlayer(const QString&))); |
677 hwnet, SLOT(kickPlayer(const QString&))); |
678 connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)), |
678 connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)), |
679 hwnet, SLOT(banPlayer(const QString&))); |
679 hwnet, SLOT(banPlayer(const QString&))); |
680 connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)), |
680 connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)), |
681 hwnet, SLOT(infoPlayer(const QString&))); |
681 hwnet, SLOT(infoPlayer(const QString&))); |
682 connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)), |
682 connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)), |
683 hwnet, SLOT(followPlayer(const QString&))); |
683 hwnet, SLOT(followPlayer(const QString&))); |
684 connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
684 connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
685 hwnet, SLOT(kickPlayer(const QString&))); |
685 hwnet, SLOT(kickPlayer(const QString&))); |
686 connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
686 connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
687 hwnet, SLOT(banPlayer(const QString&))); |
687 hwnet, SLOT(banPlayer(const QString&))); |
688 connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)), |
688 connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)), |
689 hwnet, SLOT(infoPlayer(const QString&))); |
689 hwnet, SLOT(infoPlayer(const QString&))); |
690 connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)), |
690 connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)), |
691 hwnet, SLOT(followPlayer(const QString&))); |
691 hwnet, SLOT(followPlayer(const QString&))); |
692 |
692 |
693 // chatting |
693 // chatting |
694 connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)), |
694 connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)), |
695 hwnet, SLOT(chatLineToLobby(const QString&))); |
695 hwnet, SLOT(chatLineToLobby(const QString&))); |
696 connect(hwnet, SIGNAL(chatStringLobby(const QString&)), |
696 connect(hwnet, SIGNAL(chatStringLobby(const QString&)), |
697 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&))); |
697 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&))); |
698 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
698 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
699 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&))); |
699 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&))); |
700 |
700 |
701 // nick list stuff |
701 // nick list stuff |
702 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
702 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
703 ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool))); |
703 ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool))); |
704 connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
704 connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
705 ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
705 ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
706 connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)), |
706 connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)), |
707 ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool))); |
707 ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool))); |
708 connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)), |
708 connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)), |
709 ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&))); |
709 ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&))); |
710 |
710 |
711 // teams selecting stuff |
711 // teams selecting stuff |
712 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
712 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
713 hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
713 hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
714 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
714 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
715 hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
715 hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
716 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
716 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
717 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
717 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
718 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&))); |
718 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&))); |
719 connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
719 connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
720 ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
720 ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
721 connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
721 connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
722 ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
722 ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
723 |
723 |
724 // admin stuff |
724 // admin stuff |
725 connect(hwnet, SIGNAL(serverMessage(const QString&)), ui.pageAdmin, SLOT(serverMessage(const QString &))); |
725 connect(hwnet, SIGNAL(serverMessage(const QString&)), ui.pageAdmin, SLOT(serverMessage(const QString &))); |
726 connect(ui.pageAdmin, SIGNAL(setServerMessage(const QString&)), hwnet, SLOT(newServerMessage(const QString &))); |
726 connect(ui.pageAdmin, SIGNAL(setServerMessage(const QString&)), hwnet, SLOT(newServerMessage(const QString &))); |
727 connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); |
727 connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); |
728 |
728 |
729 // disconnect |
729 // disconnect |
730 connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
730 connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
731 |
731 |
732 hwnet->Connect(hostName, port, nick); |
732 hwnet->Connect(hostName, port, nick); |
733 } |
733 } |
734 |
734 |
735 void HWForm::NetConnect() |
735 void HWForm::NetConnect() |
736 { |
736 { |
737 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
737 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
738 hpd->leHost->setText(*netHost); |
738 hpd->leHost->setText(*netHost); |
739 hpd->sbPort->setValue(netPort); |
739 hpd->sbPort->setValue(netPort); |
740 |
740 |
741 if (hpd->exec() == QDialog::Accepted) |
741 if (hpd->exec() == QDialog::Accepted) |
742 { |
742 { |
743 config->SaveOptions(); |
743 config->SaveOptions(); |
744 delete netHost; |
744 delete netHost; |
745 netHost = new QString(hpd->leHost->text()); |
745 netHost = new QString(hpd->leHost->text()); |
746 netPort = hpd->sbPort->value(); |
746 netPort = hpd->sbPort->value(); |
747 NetConnectServer(*netHost, netPort); |
747 NetConnectServer(*netHost, netPort); |
748 } |
748 } |
749 } |
749 } |
750 |
750 |
751 void HWForm::NetStartServer() |
751 void HWForm::NetStartServer() |
752 { |
752 { |
753 config->SaveOptions(); |
753 config->SaveOptions(); |
754 |
754 |
755 pnetserver = new HWNetServer; |
755 pnetserver = new HWNetServer; |
756 if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value())) |
756 if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value())) |
757 { |
757 { |
758 QMessageBox::critical(0, tr("Error"), |
758 QMessageBox::critical(0, tr("Error"), |
759 tr("Unable to start the server")); |
759 tr("Unable to start the server")); |
760 delete pnetserver; |
760 delete pnetserver; |
761 pnetserver = 0; |
761 pnetserver = 0; |
762 return; |
762 return; |
763 } |
763 } |
764 |
764 |
765 QTimer::singleShot(250, this, SLOT(AsyncNetServerStart())); |
765 QTimer::singleShot(250, this, SLOT(AsyncNetServerStart())); |
766 |
766 |
767 pRegisterServer = new HWNetUdpServer(0, |
767 pRegisterServer = new HWNetUdpServer(0, |
768 ui.pageNetServer->leServerDescr->text(), |
768 ui.pageNetServer->leServerDescr->text(), |
769 ui.pageNetServer->sbPort->value()); |
769 ui.pageNetServer->sbPort->value()); |
770 } |
770 } |
771 |
771 |
772 void HWForm::AsyncNetServerStart() |
772 void HWForm::AsyncNetServerStart() |
773 { |
773 { |
774 NetConnectServer("localhost", pnetserver->getRunningPort()); |
774 NetConnectServer("localhost", pnetserver->getRunningPort()); |
775 } |
775 } |
776 |
776 |
777 void HWForm::NetDisconnect() |
777 void HWForm::NetDisconnect() |
778 { |
778 { |
779 //qDebug("NetDisconnect"); |
779 //qDebug("NetDisconnect"); |
780 if(hwnet) { |
780 if(hwnet) { |
781 hwnet->Disconnect(); |
781 hwnet->Disconnect(); |
782 delete hwnet; |
782 delete hwnet; |
783 hwnet = 0; |
783 hwnet = 0; |
784 } |
784 } |
785 if(pnetserver) { |
785 if(pnetserver) { |
786 if (pRegisterServer) |
786 if (pRegisterServer) |
787 { |
787 { |
788 pRegisterServer->unregister(); |
788 pRegisterServer->unregister(); |
789 pRegisterServer = 0; |
789 pRegisterServer = 0; |
790 } |
790 } |
791 |
791 |
792 pnetserver->StopServer(); |
792 pnetserver->StopServer(); |
793 delete pnetserver; |
793 delete pnetserver; |
794 pnetserver = 0; |
794 pnetserver = 0; |
795 } |
795 } |
796 } |
796 } |
797 |
797 |
798 void HWForm::ForcedDisconnect() |
798 void HWForm::ForcedDisconnect() |
799 { |
799 { |
800 if(pnetserver) return; // we have server - let it care of all things |
800 if(pnetserver) return; // we have server - let it care of all things |
801 if (hwnet) { |
801 if (hwnet) { |
802 hwnet->deleteLater(); |
802 hwnet->deleteLater(); |
803 hwnet = 0; |
803 hwnet = 0; |
804 QMessageBox::warning(this, QMessageBox::tr("Network"), |
804 QMessageBox::warning(this, QMessageBox::tr("Network"), |
805 QMessageBox::tr("Connection to server is lost")); |
805 QMessageBox::tr("Connection to server is lost")); |
806 |
806 |
807 } |
807 } |
808 if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); |
808 if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); |
809 } |
809 } |
810 |
810 |
811 void HWForm::NetConnected() |
811 void HWForm::NetConnected() |
812 { |
812 { |
813 GoToPage(ID_PAGE_ROOMSLIST); |
813 GoToPage(ID_PAGE_ROOMSLIST); |
814 } |
814 } |
815 |
815 |
816 void HWForm::NetGameEnter() |
816 void HWForm::NetGameEnter() |
817 { |
817 { |
818 ui.pageNetGame->pChatWidget->clear(); |
818 ui.pageNetGame->pChatWidget->clear(); |
819 GoToPage(ID_PAGE_NETGAME); |
819 GoToPage(ID_PAGE_NETGAME); |
820 } |
820 } |
821 |
821 |
822 void HWForm::AddNetTeam(const HWTeam& team) |
822 void HWForm::AddNetTeam(const HWTeam& team) |
823 { |
823 { |
824 ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
824 ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
825 } |
825 } |
826 |
826 |
827 void HWForm::StartMPGame() |
827 void HWForm::StartMPGame() |
828 { |
828 { |
829 QString ammo; |
829 QString ammo; |
830 ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData( |
830 ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData( |
831 ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex() |
831 ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex() |
832 ).toString(); |
832 ).toString(); |
833 |
833 |
834 CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo); |
834 CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo); |
835 |
835 |
836 game->StartLocal(); |
836 game->StartLocal(); |
837 } |
837 } |
838 |
838 |
839 void HWForm::GameStateChanged(GameState gameState) |
839 void HWForm::GameStateChanged(GameState gameState) |
840 { |
840 { |
841 switch(gameState) { |
841 switch(gameState) { |
842 case gsStarted: { |
842 case gsStarted: { |
843 Music(false); |
843 Music(false); |
844 if (wBackground) wBackground->stopAnimation(); |
844 if (wBackground) wBackground->stopAnimation(); |
845 GoToPage(ID_PAGE_INGAME); |
845 GoToPage(ID_PAGE_INGAME); |
846 ui.pageGameStats->clear(); |
846 ui.pageGameStats->clear(); |
847 if (pRegisterServer) |
847 if (pRegisterServer) |
848 { |
848 { |
849 pRegisterServer->unregister(); |
849 pRegisterServer->unregister(); |
850 pRegisterServer = 0; |
850 pRegisterServer = 0; |
851 } |
851 } |
852 //setVisible(false); |
852 //setVisible(false); |
853 setFocusPolicy(Qt::NoFocus); |
853 setFocusPolicy(Qt::NoFocus); |
854 break; |
854 break; |
855 } |
855 } |
856 case gsFinished: { |
856 case gsFinished: { |
857 //setVisible(true); |
857 //setVisible(true); |
858 setFocusPolicy(Qt::StrongFocus); |
858 setFocusPolicy(Qt::StrongFocus); |
859 GoBack(); |
859 GoBack(); |
860 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked()); |
860 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked()); |
861 if (wBackground) wBackground->startAnimation(); |
861 if (wBackground) wBackground->startAnimation(); |
862 GoToPage(ID_PAGE_GAMESTATS); |
862 GoToPage(ID_PAGE_GAMESTATS); |
863 if (hwnet) hwnet->gameFinished(); |
863 if (hwnet) hwnet->gameFinished(); |
864 break; |
864 break; |
865 } |
865 } |
866 default: { |
866 default: { |
867 //setVisible(true); |
867 //setVisible(true); |
868 setFocusPolicy(Qt::StrongFocus); |
868 setFocusPolicy(Qt::StrongFocus); |
869 quint8 id = ui.Pages->currentIndex(); |
869 quint8 id = ui.Pages->currentIndex(); |
870 if (id == ID_PAGE_INGAME) { |
870 if (id == ID_PAGE_INGAME) { |
871 GoBack(); |
871 GoBack(); |
872 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked()); |
872 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked()); |
873 if (wBackground) wBackground->startAnimation(); |
873 if (wBackground) wBackground->startAnimation(); |
874 if (hwnet) hwnet->gameFinished(); |
874 if (hwnet) hwnet->gameFinished(); |
875 } |
875 } |
876 }; |
876 }; |
877 } |
877 } |
878 } |
878 } |
879 |
879 |
880 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo) |
880 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo) |
881 { |
881 { |
882 game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
882 game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
883 connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
883 connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
884 connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &))); |
884 connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &))); |
885 connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
885 connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
886 connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
886 connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
887 } |
887 } |
888 |
888 |
889 void HWForm::ShowErrorMessage(const QString & msg) |
889 void HWForm::ShowErrorMessage(const QString & msg) |
890 { |
890 { |
891 QMessageBox::warning(this, |
891 QMessageBox::warning(this, |
892 "Hedgewars", |
892 "Hedgewars", |
893 msg); |
893 msg); |
894 } |
894 } |
895 |
895 |
896 void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
896 void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
897 { |
897 { |
898 QString filename; |
898 QString filename; |
899 QByteArray demo = record; |
899 QByteArray demo = record; |
900 QString recordFileName = |
900 QString recordFileName = |
901 config->appendDateTimeToRecordName() ? |
901 config->appendDateTimeToRecordName() ? |
902 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") : |
902 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") : |
903 "LastRound"; |
903 "LastRound"; |
904 |
904 |
905 if (isDemo) |
905 if (isDemo) |
906 { |
906 { |
907 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
907 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
908 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
908 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
909 demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
909 demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
910 filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd"; |
910 filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd"; |
911 } else |
911 } else |
912 { |
912 { |
913 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
913 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
914 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
914 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
915 filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws"; |
915 filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws"; |
916 } |
916 } |
917 |
917 |
918 |
918 |
919 QFile demofile(filename); |
919 QFile demofile(filename); |
920 if (!demofile.open(QIODevice::WriteOnly)) |
920 if (!demofile.open(QIODevice::WriteOnly)) |
921 { |
921 { |
922 ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
922 ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
923 return ; |
923 return ; |
924 } |
924 } |
925 demofile.write(demo.constData(), demo.size()); |
925 demofile.write(demo.constData(), demo.size()); |
926 demofile.close(); |
926 demofile.close(); |
927 } |
927 } |
928 |
928 |
929 void HWForm::StartTraining() |
929 void HWForm::StartTraining() |
930 { |
930 { |
931 CreateGame(0, 0, 0); |
931 CreateGame(0, 0, 0); |
932 |
932 |
933 game->StartTraining(ui.pageTraining->CBSelect->currentText()); |
933 game->StartTraining(ui.pageTraining->CBSelect->currentText()); |
934 } |
934 } |
935 |
935 |
936 void HWForm::CreateNetGame() |
936 void HWForm::CreateNetGame() |
937 { |
937 { |
938 QString ammo; |
938 QString ammo; |
939 ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData( |
939 ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData( |
940 ui.pageNetGame->pGameCFG->WeaponsName->currentIndex() |
940 ui.pageNetGame->pGameCFG->WeaponsName->currentIndex() |
941 ).toString(); |
941 ).toString(); |
942 |
942 |
943 CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo); |
943 CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo); |
944 |
944 |
945 connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
945 connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
946 connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &))); |
946 connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &))); |
947 connect(game, SIGNAL(SendTeamMessage(const QString &)), hwnet, SLOT(SendTeamMessage(const QString &))); |
947 connect(game, SIGNAL(SendTeamMessage(const QString &)), hwnet, SLOT(SendTeamMessage(const QString &))); |
948 connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
948 connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
949 connect(hwnet, SIGNAL(chatStringFromNet(const QString &)), game, SLOT(FromNetChat(const QString &))); |
949 connect(hwnet, SIGNAL(chatStringFromNet(const QString &)), game, SLOT(FromNetChat(const QString &))); |
950 |
950 |
951 game->StartNet(); |
951 game->StartNet(); |
952 } |
952 } |
953 |
953 |
954 void HWForm::closeEvent(QCloseEvent *event) |
954 void HWForm::closeEvent(QCloseEvent *event) |
955 { |
955 { |
956 #ifdef USE_XFIRE |
956 #ifdef USE_XFIRE |
957 xfire_free(); |
957 xfire_free(); |
958 #endif |
958 #endif |
959 config->SaveOptions(); |
959 config->SaveOptions(); |
960 event->accept(); |
960 event->accept(); |
961 } |
961 } |
962 |
962 |
963 void HWForm::Music(bool checked) |
963 void HWForm::Music(bool checked) |
964 { |
964 { |
965 if (checked) |
965 if (checked) |
966 sdli.StartMusic(); |
966 sdli.StartMusic(); |
967 else |
967 else |
968 sdli.StopMusic(); |
968 sdli.StopMusic(); |
969 } |
969 } |
970 |
970 |
971 void HWForm::NetGameChangeStatus(bool isMaster) |
971 void HWForm::NetGameChangeStatus(bool isMaster) |
972 { |
972 { |
973 if (isMaster) |
973 if (isMaster) |
974 NetGameMaster(); |
974 NetGameMaster(); |
975 else |
975 else |
976 NetGameSlave(); |
976 NetGameSlave(); |
977 } |
977 } |
978 |
978 |
979 void HWForm::NetGameMaster() |
979 void HWForm::NetGameMaster() |
980 { |
980 { |
981 ui.pageNetGame->setMasterMode(true); |
981 ui.pageNetGame->setMasterMode(true); |
982 ui.pageNetGame->restrictJoins->setChecked(false); |
982 ui.pageNetGame->restrictJoins->setChecked(false); |
983 ui.pageNetGame->restrictTeamAdds->setChecked(false); |
983 ui.pageNetGame->restrictTeamAdds->setChecked(false); |
984 ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel); |
984 ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel); |
985 ui.pageNetGame->pGameCFG->setEnabled(true); |
985 ui.pageNetGame->pGameCFG->setEnabled(true); |
986 ui.pageNetGame->pNetTeamsWidget->setInteractivity(true); |
986 ui.pageNetGame->pNetTeamsWidget->setInteractivity(true); |
987 |
987 |
988 if (hwnet) |
988 if (hwnet) |
989 { |
989 { |
990 // disconnect connections first to ensure their inexistance and not to connect twice |
990 // disconnect connections first to ensure their inexistance and not to connect twice |
991 ui.pageNetGame->BtnStart->disconnect(hwnet); |
991 ui.pageNetGame->BtnStart->disconnect(hwnet); |
992 ui.pageNetGame->restrictJoins->disconnect(hwnet); |
992 ui.pageNetGame->restrictJoins->disconnect(hwnet); |
993 ui.pageNetGame->restrictTeamAdds->disconnect(hwnet); |
993 ui.pageNetGame->restrictTeamAdds->disconnect(hwnet); |
994 connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), hwnet, SLOT(startGame())); |
994 connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), hwnet, SLOT(startGame())); |
995 connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins())); |
995 connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins())); |
996 connect(ui.pageNetGame->restrictTeamAdds, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictTeamAdds())); |
996 connect(ui.pageNetGame->restrictTeamAdds, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictTeamAdds())); |
997 connect(ui.pageNetGame->pGameCFG->GameSchemes->model(), |
997 connect(ui.pageNetGame->pGameCFG->GameSchemes->model(), |
998 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |
998 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |
999 ui.pageNetGame->pGameCFG, |
999 ui.pageNetGame->pGameCFG, |
1000 SLOT(resendSchemeData()) |
1000 SLOT(resendSchemeData()) |
1001 ); |
1001 ); |
1002 } |
1002 } |
1003 } |
1003 } |
1004 |
1004 |
1005 void HWForm::NetGameSlave() |
1005 void HWForm::NetGameSlave() |
1006 { |
1006 { |
1007 ui.pageNetGame->pGameCFG->setEnabled(false); |
1007 ui.pageNetGame->pGameCFG->setEnabled(false); |
1008 ui.pageNetGame->pNetTeamsWidget->setInteractivity(false); |
1008 ui.pageNetGame->pNetTeamsWidget->setInteractivity(false); |
1009 |
1009 |
1010 if (hwnet) |
1010 if (hwnet) |
1011 { |
1011 { |
1012 NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet); |
1012 NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet); |
1013 connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), netAmmo, SLOT(setNetSchemeConfig(QStringList &))); |
1013 connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), netAmmo, SLOT(setNetSchemeConfig(QStringList &))); |
1014 ui.pageNetGame->pGameCFG->GameSchemes->setModel(netAmmo); |
1014 ui.pageNetGame->pGameCFG->GameSchemes->setModel(netAmmo); |
1015 |
1015 |
1016 ui.pageNetGame->pGameCFG->GameSchemes->view()->disconnect(hwnet); |
1016 ui.pageNetGame->pGameCFG->GameSchemes->view()->disconnect(hwnet); |
1017 connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), |
1017 connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), |
1018 this, SLOT(selectFirstNetScheme())); |
1018 this, SLOT(selectFirstNetScheme())); |
1019 } |
1019 } |
1020 |
1020 |
1021 ui.pageNetGame->setMasterMode(false); |
1021 ui.pageNetGame->setMasterMode(false); |
1022 } |
1022 } |
1023 |
1023 |
1024 void HWForm::selectFirstNetScheme() |
1024 void HWForm::selectFirstNetScheme() |
1025 { |
1025 { |
1026 ui.pageNetGame->pGameCFG->GameSchemes->setCurrentIndex(0); |
1026 ui.pageNetGame->pGameCFG->GameSchemes->setCurrentIndex(0); |
1027 } |
1027 } |
1028 |
1028 |
1029 void HWForm::NetLeftRoom() |
1029 void HWForm::NetLeftRoom() |
1030 { |
1030 { |
1031 if (ui.Pages->currentIndex() == ID_PAGE_NETGAME) |
1031 if (ui.Pages->currentIndex() == ID_PAGE_NETGAME) |
1032 GoBack(); |
1032 GoBack(); |
1033 else |
1033 else |
1034 qWarning("Left room while not in room"); |
1034 qWarning("Left room while not in room"); |
1035 } |
1035 } |
1036 |
1036 |
1037 void HWForm::resizeEvent(QResizeEvent * event) |
1037 void HWForm::resizeEvent(QResizeEvent * event) |
1038 { |
1038 { |
1039 int w = event->size().width(); |
1039 int w = event->size().width(); |
1040 int h = event->size().height(); |
1040 int h = event->size().height(); |
1041 if (wBackground) { |
1041 if (wBackground) { |
1042 wBackground->setFixedSize(w, h); |
1042 wBackground->setFixedSize(w, h); |
1043 wBackground->move(0, 0); |
1043 wBackground->move(0, 0); |
1044 } |
1044 } |
1045 } |
1045 } |