File indexing completed on 2024-12-08 06:48:02
0001 /* This file is part of KsirK. 0002 Copyright (C) 2001-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KsirK is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, either version 2 0007 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA 0018 */ 0019 0020 #ifndef KGAMEWIN_H 0021 #define KGAMEWIN_H 0022 0023 #include "config-ksirk.h" 0024 #include "krightdialog.h" 0025 #include "KsirkGlobalDefinitions.h" 0026 #include "decoratedgameframe.h" 0027 #include "fightArena.h" 0028 #include "mainMenu.h" 0029 #include "GameLogic/onu.h" 0030 #include "GameLogic/gameautomaton.h" 0031 #include "GameLogic/player.h" 0032 #include "GameLogic/country.h" 0033 #include "Dialogs/InvasionSlider.h" 0034 #include "Sprites/animspriteslist.h" 0035 #if HAVE_JABBER_SUPPORT 0036 #include "Jabber/jabberclient.h" 0037 #include "qca.h" 0038 #endif 0039 0040 0041 // include files for Qt 0042 #include <QPointF> 0043 #include <QPixmap> 0044 #include <QLabel> 0045 #include <QPushButton> 0046 #include <QStackedWidget> 0047 #include <QGroupBox> 0048 #include <QSplitter> 0049 #include <QSlider> 0050 #include <QHBoxLayout> 0051 #include <QVBoxLayout> 0052 // include files for KDE 0053 #include <KSharedConfig> 0054 #include <KXmlGuiWindow> 0055 #include <QStandardPaths> 0056 0057 // #include <kdialogbase.h> 0058 0059 class KsirkJabberGameWidget; 0060 class mainMenu; 0061 class NewGameSetup; 0062 0063 class QAction; 0064 class KGameChat; 0065 class KGamePopupItem; 0066 class QDialog; 0067 class QAction; 0068 0069 class QEvent; 0070 class QDockWidget; 0071 class QGraphicsScene; 0072 0073 class QMediaPlayer; 0074 0075 namespace Ksirk 0076 { 0077 0078 // forward declaration of the KsirK classes 0079 class DecoratedGameFrame; 0080 class FightArena; 0081 class AnimSpritesGroup; 0082 class KRightDialog; 0083 class NewGameWidget; 0084 class KPlayerSetupWidget; 0085 class NewGameSummaryWidget; 0086 class TcpConnectWidget; 0087 0088 namespace Sprites 0089 { 0090 class ArrowSprite; 0091 } 0092 0093 namespace GameLogic 0094 { 0095 class ONU; 0096 class KMessageParts; 0097 class Player; 0098 } 0099 0100 /** 0101 * This is the main window. Due to the history of KsirK, this GUI class 0102 * contain really too much code about game logics. This will change in the 0103 * future. 0104 * 0105 * @author Gael de Chalendar (aka Kleag) 0106 * @version $Id: kgamewin.h 243 2007-02-24 00:22:58Z kleag $ 0107 */ 0108 class KGameWindow: public KXmlGuiWindow 0109 { 0110 Q_OBJECT 0111 0112 public: 0113 enum MessageShowingType {OnConfig, ForceShowing}; 0114 enum FightType {Attack, Defense}; 0115 enum TabbedWidgetsIndexesType 0116 { 0117 MAINMENU_INDEX /*0*/, 0118 NEWGAME_INDEX /*1*/, 0119 #if HAVE_JABBER_SUPPORT 0120 JABBERGAME_INDEX /*2*/, 0121 #endif 0122 NEWPLAYER_INDEX /*3*/, 0123 NEWGAMESUMMARY_INDEX /*4*/, 0124 TCPCONNECT_INDEX /*5*/, 0125 MAP_INDEX /*6*/, 0126 ARENA_INDEX /*7*/ 0127 }; 0128 /** 0129 * Create the window and initializes its members 0130 */ 0131 explicit KGameWindow(QWidget* parent=nullptr); 0132 0133 /** 0134 * Deletes the background and the pool 0135 */ 0136 ~KGameWindow() override; 0137 0138 /** Returns the game graphics view */ 0139 DecoratedGameFrame* frame() {return m_frame;} 0140 /** Returns the game graphics scene*/ 0141 // QGraphicsScene* graphicsscene() {return m_ 0142 0143 /** Returns the arena graphics view */ 0144 FightArena* arena() {return m_arena;} 0145 0146 /** Returns the menu graphics view */ 0147 mainMenu* mMenu() {return m_mainMenu;} 0148 0149 NewGameSetup* newGameSetup() {return m_newGameSetup;} 0150 0151 /** 0152 * Ask all the sprites to repaint themselves 0153 */ 0154 // void paint(); 0155 0156 /** 0157 * Returns the country inside which the argument point is. 0 if none. 0158 */ 0159 GameLogic::Country* clickIn(const QPointF& Point); 0160 0161 /** 0162 * Loads a new skin. 0163 */ 0164 void newSkin(const QString& onuDefinitionFileName = ""); 0165 0166 void setStateBeforeNewGame(GameLogic::GameAutomaton::GameState state) {m_stateBeforeNewGame = state;} 0167 0168 /************** METHODS BELOW ARE DEFINED IN gestionSprites.cpp **************/ 0169 /** 0170 * Prepares the sprites to be moved : removes the nb necessary sprites from 0171 * source, creates the moving sprites and gives them their destination, etc 0172 */ 0173 bool initArmiesMovement(unsigned int nb, GameLogic::Country* src, GameLogic::Country* dest); 0174 0175 AnimSprite* initArmiesMultipleCombat(unsigned int nb, 0176 GameLogic::Country* src, 0177 GameLogic::Country* dest, QPointF); 0178 0179 QPointF determinePointDepartArena(GameLogic::Country *pays, int relativePos); 0180 0181 void determinePointArrivee( 0182 QPointF& pointArriveeAttaquant, 0183 QPointF& pointArriveeDefenseur); 0184 0185 void determinePointArriveeForArena( 0186 int relative, 0187 QPointF& pointArriveeAttaquant, 0188 QPointF& pointArriveeDefenseur); 0189 0190 0191 /** 0192 * Initializes the sprites that will fight for the attacker and the 0193 * defender. Prepares them for moving 0194 */ 0195 void initCombatMovement(); 0196 0197 /** 0198 * Prepare the fighting animation : replace the sprites sequence by the 0199 * sequence of explosion 0200 */ 0201 0202 void animCombat(); 0203 /** 0204 * Center the map on the fight so that the user can see what's happening 0205 */ 0206 void centerOnFight(); 0207 0208 /** 0209 * Replaces the animated fighters by the simple cannon image 0210 */ 0211 void stopCombat(); 0212 0213 /** 0214 * Replaces the sequence of destroyed cannon(s) by the explosion sequence. 0215 */ 0216 void animExplosion(int who); 0217 0218 void animExplosionForArena(); 0219 0220 /** 0221 * When all the explosion sequence has been shown for all explosing 0222 * devices, removes these sprites 0223 */ 0224 void stopExplosion(); 0225 0226 /** 0227 * Set up the eventual survivor(s) to come back home 0228 */ 0229 void initCombatBringBackForArena(GameLogic::Country *, GameLogic::Country *); 0230 0231 /** 0232 * Tests if there is currently moving armies (infantrymen, cavalrymen, 0233 * cannons or fighters) 0234 * @return true if there is moving armies; false otherwise 0235 */ 0236 bool haveMovingArmies() const {return !m_animSpritesGroups.empty();} 0237 0238 /************** END OF METHODS DEFINED IN gestionSprites.cpp *****************/ 0239 0240 bool setupOnePlayer(); 0241 bool setupOneWaitedPlayer(); 0242 bool createWaitedPlayer(quint32 waitedPlayerId); 0243 0244 /** 0245 * Do the distribution of armies for all players in function of their 0246 * number of countries 0247 */ 0248 void distributeArmies(); 0249 0250 /** 0251 * Computes the number of armies to be distributed to p at the beginning of 0252 * the turn, function of the number of countries he owns 0253 * @todo : this method should be a method of Player 0254 */ 0255 int nbNewArmies(GameLogic::Player *p); 0256 0257 /** 0258 * Changes the owner of the attacked country if its number of armies 0259 * becomes negative or null. Handle the end of the game of the 0260 * winning conditions are fulfilled. 0261 */ 0262 bool attackEnd(); 0263 0264 /** 0265 * Computes the results of the fight 0266 */ 0267 void resolveAttack(); 0268 0269 //@{ 0270 /** 0271 * Display and removes various toolbar buttons in function of the state 0272 * of the game. 0273 */ 0274 void displayRecyclingButtons(); 0275 void clearHighlighting(); 0276 void startLocalCurrentAI(); 0277 void displayDefenseWindow(); 0278 0279 //@} 0280 0281 /** 0282 * Updates the flag in the statusbar with the one of the current player 0283 */ 0284 void setBarFlagButton(const GameLogic::Player* player = nullptr); 0285 0286 /** 0287 * @brief Shortcut for "statusBar()-> changeItem(text, id)" 0288 */ 0289 void changeItem ( const QString& text, int id = ID_NO_STATUS_MSG, bool log = true); 0290 0291 /** 0292 * @brief Receives pixmaps and strings to internationalize and display in a 0293 * collection with stream API. 0294 * 0295 * When encountering a serie of strings, the first one is the pattern and 0296 * those following are the fillers. The end of the collection or a pixmap 0297 * signals that all fillers have been given. 0298 * @note No check is made (e.g. on the number of fillers) 0299 * 0300 * @param strings @b IN/OUT <I>KsirK::GameLogic::KMessageParts&</I> 0301 * the collection holding strings to display. 0302 * @param id @b IN <I>int</I> 0303 * The id of the status bar where to display the internationalized message. 0304 */ 0305 void changeItem(Ksirk::GameLogic::KMessageParts& strings, 0306 int id = ID_NO_STATUS_MSG, bool log = true); 0307 0308 /** 0309 * @brief Receives strings to internationalize and display in a collection 0310 * with stream API and broadcasts the message to all clients. 0311 * @param strings @b IN/OUT <I>KsirK::GameLogic::KMessageParts&</I> 0312 * the collection holding strings to display. 0313 * @param id @b IN <I>int</I> 0314 * The id of the status bar where to display the internationalized message. 0315 */ 0316 void broadcastChangeItem(Ksirk::GameLogic::KMessageParts& strings, 0317 int id = ID_NO_STATUS_MSG, bool log = true ); 0318 0319 /** 0320 * @brief Reconnect the mouse events signals to their slots to allow human players 0321 * to play 0322 */ 0323 void reconnectMouse(); 0324 0325 /** 0326 * Disconnects the mouse events signals from their slots to avoid human 0327 * player actions when it is the turn of the AI 0328 */ 0329 void disconnectMouse(); 0330 0331 /** Returns the current state of the game */ 0332 GameLogic::GameAutomaton::GameState getState() const; 0333 0334 /** Return true if the state of the game is the argument; false otherwise */ 0335 bool isMyState(GameLogic::GameAutomaton::GameState state) const; 0336 0337 /** @brief sets the current player to be the one pointed by the argument. 0338 * Makes associated actions: 0339 * 0340 * Changes the flag in the status bar. 0341 * @return Returns true in case of success; false otherwise. 0342 */ 0343 // bool setCurrentPlayer(const GameLogic::Player* player); 0344 0345 /** sets the current player to be the first one. Makes associated actions. */ 0346 int setCurrentPlayerToFirst(); 0347 0348 /** 0349 * Sets the current player to be the next one in the list. Makes the 0350 * associated actions : 0351 * Changes the flag in the status bar,... 0352 * @return 0 in case of success; non-zero otherwise. For example, it returns 0353 * 1 the current player was the last one 0354 */ 0355 int setCurrentPlayerToNext(bool restartRunningAIs = true); 0356 0357 0358 bool playerPutsArmy(const QPointF& point, bool removable); 0359 bool playerPutsInitialArmy(const QPointF& point); 0360 bool playerRemovesArmy(const QPointF& point); 0361 0362 /** Sets the attacker country to be the one at the given point */ 0363 bool attacker(const QPointF& point); 0364 0365 /** Sets the attacked country to be the one at the given point */ 0366 unsigned int attacked(const QPointF& point); 0367 0368 /** Sets the first country in a fight to be the one at the given point. */ 0369 bool firstCountryAt(const QPointF& point); 0370 0371 /** Sets the second country in a fight to be the one at the given point. */ 0372 bool secondCountryAt(const QPointF& point); 0373 0374 /** 0375 * @brief setups window for recycling 0376 */ 0377 void initRecycling(); 0378 0379 /** Test if there is some sprites animated for a fight */ 0380 bool haveAnimFighters() const; 0381 0382 /** Clears all animated sprites lists and shows the post-fight buttons */ 0383 bool terminateAttackSequence(); 0384 0385 /** Called whenever a player choses to end the recycling. */ 0386 bool nextPlayerRecycling(); 0387 0388 /** 0389 * @return if true next state will be NEWARMIES else it will be WAIT 0390 */ 0391 bool nextPlayerNormal(); 0392 0393 /** Called whenever a player choses to attack with nb armies. */ 0394 void attack(unsigned int nb); 0395 0396 /** Called whenever a player choses to defend with nb armies. */ 0397 void defense(unsigned int nb); 0398 0399 /** Called whenever a player choses the cancel button. */ 0400 void cancelAction(); 0401 0402 /** 0403 * Called whenever a player choses to cancel the started end of turn move of 0404 * armies. 0405 */ 0406 void cancelShiftSource(); 0407 0408 /** Called when the user clicks the new game button. */ 0409 bool actionNewGame(GameLogic::GameAutomaton::NetworkGameType socket); 0410 0411 /** Called when the user clicks the open game button. */ 0412 bool actionOpenGame(); 0413 0414 /** Called when the user clicks the recycling button. */ 0415 void actionRecycling(); 0416 0417 /** */ 0418 void postActionRecycling(); 0419 0420 /** Called when the user clicks the recycling finished button. */ 0421 void actionRecyclingFinished(); 0422 0423 /** 0424 * Tests if the move finishing at the given point is valid. 0425 * @return true if the move is valid; false otherwise. 0426 */ 0427 bool isMoveValid(const QPointF& point); 0428 0429 /** 0430 * Tests if the fight finishing at the given point is valid. 0431 * @return true if the fight is valid; false otherwise. 0432 */ 0433 bool isFightValid(const QPointF& point); 0434 0435 /** 0436 * @brief Accessor to the world 0437 * @return A pointer to the world 0438 */ 0439 GameLogic::ONU* theWorld(); 0440 0441 /** 0442 * @brief Adds a player 0443 */ 0444 GameLogic::Player* addPlayer(const QString& playerName, 0445 unsigned int nbAvailArmies, 0446 unsigned int nbCountries, 0447 const QString& nationName, 0448 bool isAI, 0449 const QString& password = "", 0450 unsigned int nbAttack = 0, 0451 unsigned int nbDefense = 0); 0452 0453 //@{ 0454 /** 0455 * accessors and manipulators of the number of armies moved during an invasion 0456 * or an end of turn move 0457 */ 0458 int nbMovedArmies(); 0459 void incrNbMovedArmies(unsigned int nb = 1); 0460 void decrNbMovedArmies(unsigned int nb = 1); 0461 //@} 0462 0463 //@{ 0464 /** 0465 * causes the move to/from the first country stored from/to the second one 0466 * during an invasion or an end of turn move 0467 */ 0468 bool invade(unsigned int nb = 1); 0469 AnimSprite* simultaneousAttack(int nbArmies, FightType type); 0470 bool retreat(unsigned int nb = 1); 0471 //@} 0472 0473 //@{ 0474 /** 0475 * causes the end of an invasion or an end of turn move 0476 */ 0477 void invasionFinished(); 0478 void shiftFinished(); 0479 //@} 0480 0481 /** @return true if the given player is the last one ; false otherwise */ 0482 bool isLastPlayer(const GameLogic::Player& player); 0483 0484 inline GameLogic::GameAutomaton* automaton() {return m_automaton;} 0485 0486 /** 0487 * Gets the background world map sprite. Gives access to the scene and, furthermore, 0488 * the background size, thus giving hints for positioning and annimation. 0489 */ 0490 inline BackGnd* backGndWorld() {return m_backGnd_world;} 0491 inline const BackGnd* backGndWorld() const {return m_backGnd_world;} 0492 0493 /** 0494 * Gets the background arena sprite. Gives access to the scene and, furthermore, 0495 * the background size, thus giving hints for positioning and annimation. 0496 */ 0497 inline BackGnd* backGndArena() {return m_backGnd_arena;} 0498 inline const BackGnd* backGndArena() const {return m_backGnd_arena;} 0499 0500 /** 0501 * Gets the current background sprite. Gives access to the scene and, furthermore, 0502 * the background size, thus giving hints for positioning and annimation. 0503 */ 0504 BackGnd* backGnd(); 0505 0506 //@{ 0507 /** 0508 * Accessors to the number of available armies. This one is inherited from a 0509 * long time ago and should probably be replaced by available armies local 0510 * to players. 0511 */ 0512 /* inline void availArmies(unsigned int nb) {m_nbAvailArmies = nb;} 0513 inline unsigned int availArmies() {return m_nbAvailArmies;}*/ 0514 //@} 0515 0516 //@{ 0517 /** 0518 * Accessors to the firstly and secondly clicked countries that will become 0519 * the attacker and the defender countries (or the source and the target) if 0520 * the move is valid 0521 */ 0522 void firstCountry(GameLogic::Country* country); 0523 void secondCountry(GameLogic::Country* country); 0524 GameLogic::Country* firstCountry(); 0525 GameLogic::Country* secondCountry(); 0526 //@} 0527 0528 /** 0529 * Forces all moving sprites to finish their move be clearing moving 0530 * sprites collections. 0531 */ 0532 void finishMoves(); 0533 0534 /** 0535 * Returns the list of players definitions whose connection from the network 0536 * is waited after loading a saved game. 0537 */ 0538 inline QList<GameLogic::PlayerMatrix>& waitedPlayers() {return m_waitedPlayers;} 0539 0540 /** Displays the buttons associated to the given game state. */ 0541 void displayButtonsForState(GameLogic::GameAutomaton::GameState state); 0542 0543 /** 0544 * The game is over. The given player is the winner. Displays the dialog 0545 * stating this fact, depending on if this player is local or distant. 0546 */ 0547 void winner(const GameLogic::Player* player); 0548 0549 /** Returns a list of the nations names associated to their flag's file name. */ 0550 QMap< QString, QString > nationsList(); 0551 0552 /** Returns a pointer to the chat widget used to chat and to display messages. */ 0553 inline KGameChat* chatWidget() {return m_chatDlg;} 0554 0555 /** Returns a pointer to the title chat message label used to display messages. */ 0556 inline QLabel* titleChatMessage() {return m_titleChatMsg;} 0557 0558 void showMessage(const QString& message, quint32 delay=5, MessageShowingType forcing=OnConfig); 0559 0560 /** 0561 * Replace the map widget by the arena widget. 0562 */ 0563 void showArena(); 0564 0565 /** 0566 * Replace the arena widget by the map widget. 0567 */ 0568 void showMap(); 0569 0570 /** 0571 * Replace the mainMenu widget by the map widget. 0572 */ 0573 void showMainMenu(); 0574 0575 /** 0576 * The three types of possible central widget. This enum is used to know which 0577 * one is currently displayed (see m_currentDisplayedWidget member below). 0578 */ 0579 enum WidgetType {MainMenu, Map, Arena}; 0580 0581 /** 0582 * Give type of the central widget currently displayed. 0583 * @return current widget type 0584 */ 0585 WidgetType currentWidgetType(); 0586 0587 /** 0588 * Give the central widget currently displayed. 0589 * @return current widget 0590 */ 0591 QGraphicsView* currentWidget(); 0592 /** 0593 * Return the right dialog 0594 */ 0595 KRightDialog * getRightDialog(); 0596 0597 /** Arena state */ 0598 bool isArena(); 0599 0600 enum DiceColor {Blue,Red}; 0601 0602 QPixmap getDice(DiceColor color, int num); 0603 0604 /** 0605 * Returns the current player 0606 */ 0607 GameLogic::Player* currentPlayer(); 0608 0609 void slideInvade(GameLogic::Country *,GameLogic::Country *, Ksirk::InvasionSlider::InvasionType invasionType = Ksirk::InvasionSlider::Invasion); 0610 0611 void setNextPlayerActionEnabled(bool value); 0612 void setSaveGameActionEnabled(bool value); 0613 void setContextualHelpActionEnabled(GameLogic::GameAutomaton::GameState gameState, bool isPlayerAI); 0614 0615 void updateScrollArrows(); 0616 0617 bool newGameDialog(const QString& skin, GameLogic::GameAutomaton::NetworkGameType netGameType); 0618 0619 bool finishSetupPlayers(); 0620 0621 #if HAVE_JABBER_SUPPORT 0622 inline JabberClient* jabberClient() {return m_jabberClient;} 0623 void askForJabberGames(); 0624 void sendGameInfoToJabber(); 0625 0626 inline XMPP::Jid& serverJid() {return m_serverJid;} 0627 inline void setServerJid(const XMPP::Jid& jid) {m_serverJid = jid;} 0628 0629 /** 0630 * Sets our own presence. Updates our resource in the 0631 * resource pool and sends a presence packet to the server. 0632 */ 0633 void setPresence ( const XMPP::Status &status ); 0634 0635 inline void setGroupchatHost(const QString& str) {m_groupchatHost = str;} 0636 inline void setGroupchatRoom(const QString& str) {m_groupchatRoom = str;} 0637 inline void setGroupchatNick(const QString& str) {m_groupchatNick = str;} 0638 inline void setGroupchatPassword(const QString& str) {m_groupchatPassword = str;} 0639 0640 const QString& groupchatHost() const {return m_groupchatHost;} 0641 const QString& groupchatRoom() const {return m_groupchatRoom;} 0642 const QString& groupchatNick() const {return m_groupchatNick;} 0643 const QString& groupchatPassword() const {return m_groupchatPassword;} 0644 #endif 0645 0646 void joinNetworkGame(); 0647 0648 void updateNewGameSummary(); 0649 void showNewGameSummary(); 0650 0651 protected: 0652 0653 /** 0654 * Connected to the frame timer, it manages the behavior of the game in 0655 * function of the value of the state. 0656 * 0657 * Fundamental method !!! 0658 */ 0659 // void slotTimerEvent(); 0660 0661 // void resizeEvent ( QResizeEvent * event ); 0662 0663 /** 0664 * Add the main toolbar buttons 0665 */ 0666 void initActions(); 0667 0668 /** 0669 * Prepares the status bar 0670 */ 0671 void initStatusBar(); 0672 0673 /** 0674 * creates and display the main frame with the background 0675 */ 0676 void initView(); 0677 0678 /** 0679 * Reimplementation of the inherited function : starts the timer. 0680 */ 0681 void enterEvent(QEnterEvent* ev) override; 0682 0683 /** 0684 * Reimplementation of the inherited function : stops the timer. 0685 */ 0686 void leaveEvent(QEvent* ev) override; 0687 0688 void clear(); 0689 0690 /** 0691 * Reimplementation of the inherited function called when a window close event arise 0692 */ 0693 bool queryClose() override; 0694 0695 /** Shows some explanations on how to start playing */ 0696 void explain(); 0697 0698 void reduceChat(); 0699 void unreduceChat(); 0700 0701 #if HAVE_JABBER_SUPPORT 0702 Q_SIGNALS: 0703 void newJabberGame(const QString&, int, const QString&); 0704 #endif 0705 0706 public Q_SLOTS: 0707 0708 void mouseMoveEvent ( QMouseEvent * event ) override; 0709 0710 //@{ 0711 /** 0712 * The slots associated to the buttons 0713 */ 0714 #if HAVE_JABBER_SUPPORT 0715 void slotJabberGame(); 0716 void slotNewJabberGame(); 0717 #endif 0718 void slotNewGame(); 0719 void slotNewSocketGame(); 0720 void slotJoinNetworkGame(); 0721 void slotOpenGame(); 0722 void slotSaveGame(); 0723 void slotRecycling(); 0724 void slotRecyclingFinished(); 0725 void slotNextPlayer(); 0726 void slotAttack1(); 0727 void slotAttack2(); 0728 void slotAttack3(); 0729 void slotDefense1(); 0730 void slotDefense2(); 0731 void slotDefAuto(); 0732 void slotWindowDef1(); 0733 void slotWindowDef2(); 0734 void slotInvade1(); 0735 0736 void slotInvade5(); 0737 void slotInvade10(); 0738 void slotInvasionFinished(); 0739 void slotRetreat1(); 0740 void slotRetreat5(); 0741 void slotRetreat10(); 0742 void slotMove(); 0743 void slotCancel(); 0744 void slotDumpGameInformations(); 0745 void slotFinishMoves(); 0746 void slotArena(bool); 0747 void slotContextualHelp(); 0748 //@} 0749 0750 /** 0751 * The standard slotShowAboutApplication slot 0752 */ 0753 void slotShowAboutApplication(); 0754 0755 //@{ 0756 /** 0757 * Connected to the frame mouse buttons signals, they manages the reaction 0758 * of the game to user interaction inside its main widget in function of 0759 * the state of the game. 0760 * 0761 * Fundamental methods !!! 0762 */ 0763 void slotLeftButtonDown(const QPointF&); 0764 void slotLeftButtonUp(const QPointF&); 0765 void slotRightButtonDown(const QPointF&); 0766 void slotRightButtonUp(const QPointF&); 0767 //@} 0768 0769 /** 0770 * This slot displays a dialog explaining the goal of the current player and 0771 * describing her progress in this way. 0772 */ 0773 void slotShowGoal(); 0774 0775 /** 0776 * Connected to the chat signals. 0777 */ 0778 void slotChatMessage(); 0779 void slotChatReduceButton(); 0780 void slotChatFloatButtonPressed(); 0781 void slotChatFloatChanged(bool value = true); 0782 0783 void slotMovingFightersArrived(AnimSpritesGroup* sprites); 0784 void slotFiringFinished(AnimSpritesGroup*); 0785 void slotExplosionFinished(AnimSpritesGroup*); 0786 void slotMovingArmiesArrived(AnimSpritesGroup*); 0787 void slotBring(AnimSprite*); 0788 void slotMovingArmyArrived(AnimSprite*); 0789 0790 void slotZoomIn(); 0791 void slotZoomOut(); 0792 0793 void slotNewGameNext(); 0794 // void slotNewGameOK(unsigned int nbPlayers, const QString& skin, unsigned int nbNetworkPlayers, bool useGoals); 0795 void slotNewGameKO(); 0796 0797 #if HAVE_JABBER_SUPPORT 0798 void slotJabberGameCanceled(int previousIndex); 0799 #endif 0800 0801 void slotNewPlayerNext(); 0802 void slotNewPlayerPrevious(); 0803 void slotNewPlayerCancel(); 0804 0805 void slotStartNewGame(); 0806 void slotTcpConnectCancel(); 0807 void slotTcpConnectPrevious(); 0808 0809 private Q_SLOTS: 0810 void optionsConfigure(); 0811 0812 /** 0813 * Called every 50ms, it causes the scrolling of the world if necessary the 0814 * movement of the moving sprites. After it call the paint method to do the 0815 * animation of the sprites and it asks the pool to update 0816 */ 0817 void evenementTimer(); 0818 0819 void slotRemoveMessage(); 0820 0821 void slotDisableHelp(const QString &); 0822 0823 void slotArmiesNumberChanged(int); 0824 0825 /* Connects to the server. */ 0826 // void slotConnect (); 0827 0828 /* Disconnects from the server. */ 0829 // void slotDisconnect (); 0830 0831 #if HAVE_JABBER_SUPPORT 0832 // handle a TLS warning 0833 void slotHandleTLSWarning ( QCA::TLS::IdentityResult identityResult, QCA::Validity validityResult ); 0834 0835 // handle client errors 0836 void slotClientError ( JabberClient::ErrorCode errorCode ); 0837 0838 // we are connected to the server 0839 void slotConnected (); 0840 0841 /* Called from Psi: tells us when we've been disconnected from the server. */ 0842 void slotCSDisconnected (); 0843 0844 /* Called from Psi: alerts us to a protocol error. */ 0845 void slotCSError (int); 0846 0847 /* Called from Psi: roster request finished */ 0848 void slotRosterRequestFinished ( bool success ); 0849 0850 /* Called from Psi: incoming file transfer */ 0851 // void slotIncomingFileTransfer (); 0852 0853 /* Called from Psi: debug messages from the backend. */ 0854 void slotClientDebugMessage (const QString &msg); 0855 0856 /* XMPP console dialog */ 0857 // void slotXMPPConsole (); 0858 0859 /* Slots for handling groupchats. */ 0860 // void slotJoinNewChat (); 0861 void slotGroupChatJoined ( const XMPP::Jid &jid ); 0862 void slotGroupChatLeft ( const XMPP::Jid &jid ); 0863 void slotGroupChatPresence ( const XMPP::Jid &jid, const XMPP::Status &status ); 0864 void slotGroupChatError ( const XMPP::Jid &jid, int error, const QString &reason ); 0865 0866 /* Incoming subscription request. */ 0867 // void slotSubscription ( const XMPP::Jid &jid, const QString &type ); 0868 0869 /* the dialog that asked to add the contact was closed (that dialog is shown in slotSubscription) */ 0870 // void slotAddedInfoEventActionActivated ( uint actionId ); 0871 0872 /** 0873 * A new item appeared in our roster, synch it with the 0874 * contact list. 0875 * (or the contact has been updated 0876 */ 0877 // void slotContactUpdated ( const XMPP::RosterItem & ); 0878 0879 /** 0880 * An item has been deleted from our roster, 0881 * delete it from our contact pool. 0882 */ 0883 // void slotContactDeleted ( const XMPP::RosterItem & ); 0884 0885 0886 /* Someone on our contact list had (another) resource come online. */ 0887 // void slotResourceAvailable ( const XMPP::Jid &, const XMPP::Resource & ); 0888 0889 /* Someone on our contact list had (another) resource go offline. */ 0890 // void slotResourceUnavailable ( const XMPP::Jid &, const XMPP::Resource & ); 0891 0892 /* Displays a new message. */ 0893 void slotReceivedMessage ( const XMPP::Message & ); 0894 0895 /* Gets the user's vCard from the server for editing. */ 0896 // void slotEditVCard (); 0897 0898 /* Get the services list from the server for management. */ 0899 // void slotGetServices (); 0900 0901 /* we received a voice invitation */ 0902 // void slotIncomingVoiceCall(const Jid&); 0903 0904 /* the unregister task finished */ 0905 // void slotUnregisterFinished(); 0906 #endif 0907 void slotExit(); 0908 0909 void slotConnectToServer(); 0910 0911 private: // Private methods 0912 void createDefenseDialog(); 0913 void moveArmies(GameLogic::Country& src, GameLogic::Country& dest, unsigned int nb); 0914 void saveXml(QTextStream& xmlStream); 0915 void loadDices(); 0916 QPixmap buildDice(const QString& id); 0917 void setupPopupMessage(); 0918 QString defenseLabel(); 0919 0920 0921 private: // Private members 0922 QDockWidget * m_rightDock; 0923 0924 KRightDialog * m_rightDialog; 0925 0926 QStackedWidget *m_centralWidget; 0927 0928 GameLogic::GameAutomaton* m_automaton; 0929 0930 InvasionSlider * m_wSlide; 0931 0932 /** 0933 * State that say the widget that is currently displayed between the map and the arena. 0934 */ 0935 WidgetType m_currentDisplayedWidget; 0936 0937 /** 0938 * The widget initialy docked at bottom where is displayed the events history 0939 */ 0940 QDockWidget* m_bottomDock; 0941 0942 //@{ 0943 /** 0944 * NKD = Numberof Killed Defenders 0945 * NKA = Numberof Killed Attackers 0946 * These numbers are set up by resolveAttack() and are used to compute 0947 * in various methods 0948 * @todo: this solution is ugly. Change that. 0949 */ 0950 int NKD, NKA; 0951 //@} 0952 0953 bool m_useArena; 0954 0955 int nbSpriteAttacking; 0956 int nbSpriteDefending; 0957 0958 int relativePosInArenaAttack; 0959 int relativePosInArenaDefense; 0960 0961 /** 0962 * the countries, continents, etc. 0963 */ 0964 GameLogic::ONU* m_theWorld; 0965 0966 /** 0967 * The main canvas of the world map 0968 */ 0969 QGraphicsScene* m_scene_world; 0970 0971 /** 0972 * The main canvas of the arena 0973 */ 0974 QGraphicsScene* m_scene_arena; 0975 0976 /** 0977 * The background sprite of the world map. Gives access to the scene and, furthermore, 0978 * the background size, thus giving hints for positioning and annimation. 0979 */ 0980 BackGnd* m_backGnd_world; 0981 0982 /** 0983 * The background sprite of the arena. Gives access to the scene and, furthermore, 0984 * the background size, thus giving hints for positioning and animation. 0985 */ 0986 BackGnd* m_backGnd_arena; 0987 0988 /** 0989 * The fighting fighters (represented by firing cannons) 0990 */ 0991 AnimSpritesGroup* m_animFighters; 0992 0993 /** 0994 * The number of armies to move/moving/moved from one country to another 0995 */ 0996 int m_nbMovedArmies; 0997 0998 //@{ 0999 /** 1000 * The 2 countries involved in a fight or in a armies move 1001 */ 1002 GameLogic::Country* m_firstCountry; 1003 GameLogic::Country* m_secondCountry; 1004 //@} 1005 1006 /** 1007 * 1008 */ 1009 // QDialog *dialog; 1010 1011 /** 1012 * The map frame of the game, its visual component ; the main widget 1013 */ 1014 DecoratedGameFrame* m_frame; 1015 1016 /** 1017 * The arena frame of the game, its visual component ; the main widget 1018 */ 1019 FightArena* m_arena; 1020 1021 /** 1022 * The menu frame of the game, its visual component ; the main widget 1023 */ 1024 mainMenu* m_mainMenu; 1025 1026 /** 1027 * This button is used to display the flag of the currently active player 1028 * in the status bar. 1029 */ 1030 QAction * m_goalAction; 1031 #if HAVE_JABBER_SUPPORT 1032 QAction* m_jabberAction; 1033 #endif 1034 QLabel* m_barFlag; 1035 1036 // KAccel m_accels; 1037 1038 QList<QString> m_temporaryAccelerators; 1039 1040 /** Used during countries distribution to handle network lags on the player member */ 1041 // unsigned int m_nbAvailArmies; 1042 1043 /** 1044 * The list of players description whose connection is waited after loading 1045 * a saved game. 1046 */ 1047 QList<GameLogic::PlayerMatrix> m_waitedPlayers; 1048 1049 /** 1050 * The prompter where the game events and chat between network players are 1051 * displayed 1052 */ 1053 KGameChat *m_chatDlg; 1054 1055 /** 1056 * Show the beginning of the last message received. 1057 */ 1058 QLabel* m_titleChatMsg; 1059 1060 /** 1061 * Reduced state of the chat widget. 1062 */ 1063 bool m_chatIsReduced; 1064 1065 /** 1066 * Contains all dices of the game. 1067 */ 1068 QMap< DiceColor, QList<QPixmap> > m_dices; 1069 1070 /** 1071 * Audio player object: play all the sounds of the game. 1072 */ 1073 QMediaPlayer* m_audioPlayer; 1074 1075 /** 1076 * This timer is used to scroll the window if the mouse stay unmoving near 1077 * the window border. 1078 */ 1079 QTimer m_timer; 1080 1081 QList<AnimSpritesGroup*> m_animSpritesGroups; 1082 1083 KGamePopupItem * m_message; 1084 1085 GameLogic::Country* m_mouseLocalisation; 1086 1087 QDialog * m_defenseDialog; 1088 1089 // components that will be re-used of the chat 1090 QPixmap m_upChatFloatPix; 1091 QPixmap m_downChatFloatPix; 1092 1093 // last width of the floating chat not reduced 1094 int m_lastWidthChat; 1095 1096 QPushButton* m_reduceChatButton; 1097 QPushButton* m_floatChatButton; 1098 1099 // the current saved game file name 1100 QString m_fileName; 1101 1102 QAction* m_nextPlayerAction; 1103 QAction * m_saveGameAction; 1104 QAction * m_zoomInAction; 1105 QAction * m_zoomOutAction; 1106 QAction * m_contextualHelpAction; 1107 1108 Sprites::ArrowSprite* m_uparrow; 1109 Sprites::ArrowSprite* m_downarrow; 1110 Sprites::ArrowSprite* m_leftarrow; 1111 Sprites::ArrowSprite* m_rightarrow; 1112 1113 int m_port; 1114 bool m_reinitializingGame; 1115 1116 NewGameWidget* m_newGameDialog; 1117 KPlayerSetupWidget* m_newPlayerWidget; 1118 1119 GameLogic::GameAutomaton::GameState m_stateBeforeNewGame; 1120 int m_stackWidgetBeforeNewGame; 1121 1122 #if HAVE_JABBER_SUPPORT 1123 JabberClient* m_jabberClient; 1124 XMPP::Jid m_serverJid; 1125 1126 /* Initial presence to set after connecting. */ 1127 XMPP::Status m_initialPresence; 1128 1129 QString m_groupchatHost; 1130 QString m_groupchatRoom; 1131 QString m_groupchatNick; 1132 QString m_groupchatPassword; 1133 1134 QString m_advertizedHostName; 1135 1136 KsirkJabberGameWidget* m_jabberGameWidget; 1137 1138 QSet<QString> m_presents; 1139 #endif 1140 1141 NewGameSetup* m_newGameSetup; 1142 NewGameSummaryWidget* m_newGameSummaryWidget; 1143 TcpConnectWidget* m_tcpConnectWidget; 1144 1145 QLabel* m_labDef; 1146 }; 1147 1148 } // closing namespace Ksirk 1149 1150 #endif // KGAMEWINDOW_H 1151