1 /* 2 * Hedgewars, a free turn based strategy game 3 * Copyright (c) 2004-2015 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef HWFORM_H 20 #define HWFORM_H 21 22 #include <QMainWindow> 23 #include <QStack> 24 #include <QTime> 25 #include <QPointer> 26 #include <QPropertyAnimation> 27 #include <QUrl> 28 #include <QNetworkReply> 29 #include <QNetworkRequest> 30 #include <QNetworkAccessManager> 31 32 #include "netserver.h" 33 #include "game.h" 34 #include "ui_hwform.h" 35 #include "SDLInteraction.h" 36 #include "bgwidget.h" 37 #include "campaign.h" 38 39 #ifdef __APPLE__ 40 #include "InstallController.h" 41 #endif 42 43 class HWGame; 44 class HWTeam; 45 class HWNamegen; 46 class HWNewNet; 47 class GameUIConfig; 48 class HWNetRegisterServer; 49 class QCloseEvent; 50 class GameSchemeModel; 51 class QSettings; 52 class QSignalMapper; 53 54 extern bool frontendEffects; 55 extern bool demoIsPresent; 56 extern QString playerHash; 57 58 class HWForm : public QMainWindow 59 { 60 Q_OBJECT 61 62 public: 63 HWForm(QWidget *parent = 0, QString styleSheet = ""); 64 Ui_HWForm ui; 65 static GameUIConfig * config; 66 void exit(); 67 void setButtonDescription(QString desc); 68 void backDescription(); 69 void GoToVideos(); 70 void GoToTraining(); 71 72 void NetConnectQuick(const QString & host, quint16 port); 73 void PlayDemoQuick(const QString & demofilename); 74 75 private slots: 76 void GoToSaves(); 77 void GoToDemos(); 78 void GoToNet(); 79 void GoToHelp(); 80 void GoToEditWeapons(); 81 void GoToNewWeapons(); 82 void GoToWeapons(int index); 83 void GoToScheme(int index); 84 void GoToEditScheme(); 85 void GoToNewScheme(); 86 void GoToPage(int id); 87 void GoBack(); 88 void OpenSnapshotFolder(); 89 QString getDemoArguments(); 90 void AssociateFiles(); 91 void btnExitPressed(); 92 void IntermediateSetup(); 93 void NewTeam(); 94 void EditTeam(const QString & teamName); 95 void AfterTeamEdit(); 96 void DeleteTeam(const QString & teamName); 97 void DeleteScheme(); 98 void DeleteWeaponSet(); 99 void SimpleGame(); 100 void PlayDemo(); 101 void startTraining(const QString&, const QString&); 102 void StartCampaign(); 103 void NetConnect(); 104 void NetConnectServer(const QString & host, quint16 port, bool useTls); 105 void NetConnectOfficialServer(); 106 void NetStartServer(); 107 void NetRedirected(quint16 port); 108 void NetDisconnect(); 109 void NetConnected(); 110 void NetError(const QString & errmsg); 111 void NetWarning(const QString & wrnmsg); 112 void NetGameEnter(); 113 void NetPassword(const QString & nick); 114 void NetNickRegistered(const QString & nick); 115 void NetNickNotRegistered(const QString & nick); 116 void NetNickTaken(const QString & nick); 117 void NetAuthFailed(); 118 void askRoomPassword(); 119 bool RetryDialog(const QString & title, const QString & label); 120 void NetTeamAccepted(const QString& team); 121 void AddNetTeam(const HWTeam& team); 122 void RemoveNetTeam(const HWTeam& team); 123 void StartMPGame(); 124 void GameStateChanged(GameState gameState); 125 void DemoPresenceChanged(bool hasDemo); 126 void ForcedDisconnect(const QString & reason); 127 void ShowFatalErrorMessage(const QString &); 128 void GetRecord(RecordType type, const QByteArray & record); 129 void CreateNetGame(); 130 void PlayOfficialServerDemo(); 131 void UpdateWeapons(); 132 void DeleteWeapons(QString weaponsName); 133 void AddWeapons(QString weaponsName, QString ammo); 134 void EditWeapons(QString oldWeaponsName, QString newWeaponsName, QString ammo); 135 void onFrontendFullscreen(bool value); 136 void onFrontendEffects(bool value); 137 void onFrontendSoundsToggled(bool value); 138 void Music(bool checked); 139 void UpdateCampaignPage(int index); 140 void UpdateCampaignPageTeam(int index); 141 void UpdateCampaignPageProgress(int index); 142 void UpdateCampaignPageMission(int index); 143 void UpdateTrainingPageTeam(int index); 144 void InitCampaignPage(); 145 void RestoreSingleplayerTeamSelection(); 146 void showFeedbackDialog(); 147 void showFeedbackDialogNetChecked(); 148 149 void NetGameChangeStatus(bool isMaster); 150 void NetGameMaster(); 151 void NetGameSlave(); 152 153 void AsyncNetServerStart(); 154 void NetLeftRoom(const QString & reason); 155 void selectFirstNetScheme(); 156 157 void saveDemoWithCustomName(); 158 void openRegistrationPage(); 159 160 void startGame(); 161 void restartGame(); 162 163 void FromNetProxySlot(const QByteArray &); 164 165 private: 166 void _NetConnect(const QString & hostName, quint16 port, bool useTls, QString nick); 167 int AskForNickAndPwd(void); 168 void UpdateTeamsLists(); 169 void CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo); 170 void closeEvent(QCloseEvent *event); 171 void CustomizePalettes(); 172 void resizeEvent(QResizeEvent * event); 173 QString stringifyPageId(quint32 id); 174 //void keyReleaseEvent(QKeyEvent *event); 175 176 enum PageIDs 177 { 178 ID_PAGE_SETUP_TEAM , 179 ID_PAGE_SETUP , 180 ID_PAGE_MULTIPLAYER , 181 ID_PAGE_DEMOS , 182 ID_PAGE_NET , 183 ID_PAGE_NETGAME , 184 ID_PAGE_INFO , 185 ID_PAGE_MAIN , 186 ID_PAGE_GAMESTATS , 187 ID_PAGE_SINGLEPLAYER , 188 ID_PAGE_TRAINING , 189 ID_PAGE_SELECTWEAPON , 190 ID_PAGE_NETSERVER , 191 ID_PAGE_INGAME , 192 ID_PAGE_ROOMSLIST , 193 ID_PAGE_CONNECTING , 194 ID_PAGE_SCHEME , 195 ID_PAGE_ADMIN , 196 ID_PAGE_CAMPAIGN , 197 ID_PAGE_DRAWMAP , 198 ID_PAGE_DATADOWNLOAD , 199 ID_PAGE_VIDEOS , 200 MAX_PAGE 201 }; 202 QPointer<HWGame> game; 203 QPointer<HWNetServer> pnetserver; 204 QPointer<HWNetRegisterServer> pRegisterServer; 205 QPointer<HWTeam> editedTeam; 206 QPointer<HWNewNet> hwnet; 207 HWNamegen * namegen; 208 GameSchemeModel * gameSchemeModel; 209 QStack<int> PagesStack; 210 QString previousCampaignName; 211 QString previousTeamName; 212 QList<MissionInfo> campaignMissionInfo; 213 QTime eggTimer; 214 BGWidget * wBackground; 215 QSignalMapper * pageSwitchMapper; 216 QByteArray m_lastDemo; 217 218 QPropertyAnimation *animationNewSlide; 219 QPropertyAnimation *animationOldSlide; 220 QPropertyAnimation *animationNewOpacity; 221 QPropertyAnimation *animationOldOpacity; 222 223 #ifdef __APPLE__ 224 InstallController * panel; 225 #endif 226 227 void OnPageShown(quint8 id, quint8 lastid=0); 228 }; 229 230 #endif 231