Warning, file /games/ksirk/ksirk/kgamewin.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 "krightdialog.h"
0024 #include "KsirkGlobalDefinitions.h"
0025 #include "decoratedgameframe.h"
0026 #include "fightArena.h"
0027 #include "mainMenu.h"
0028 #include "GameLogic/onu.h"
0029 #include "GameLogic/gameautomaton.h"
0030 #include "GameLogic/player.h"
0031 #include "GameLogic/country.h"
0032 #include "Dialogs/InvasionSlider.h"
0033 #include "Sprites/animspriteslist.h"
0034 #include "Jabber/jabberclient.h"
0035 
0036 #include "qca.h"
0037 
0038 // include files for Qt
0039 #include <QPointF>
0040 #include <QPixmap>
0041 #include <QLabel>
0042 #include <QPushButton>
0043 #include <QStackedWidget>
0044 #include <QGroupBox>
0045 #include <QSplitter>
0046 #include <QSlider>
0047 #include <QHBoxLayout>
0048 #include <QVBoxLayout>
0049 // include files for KDE
0050 #include <KSharedConfig>
0051 #include <KXmlGuiWindow>
0052 #include <QStandardPaths>
0053 
0054 // #include <kdialogbase.h>
0055 
0056 class KsirkJabberGameWidget;
0057 class mainMenu;
0058 class NewGameSetup;
0059 
0060 class QAction;
0061 class KGameChat;
0062 class KGamePopupItem;
0063 class QDialog;
0064 class QAction;
0065 
0066 class QEvent;
0067 class QDockWidget;
0068 class QGraphicsScene;
0069 
0070 // class JabberClient;
0071 
0072 namespace Phonon
0073 {
0074   class MediaObject;
0075 }
0076 
0077 namespace Ksirk
0078 {
0079 
0080   // forward declaration of the KsirK classes
0081   class DecoratedGameFrame;
0082   class FightArena;
0083   class AnimSpritesGroup;
0084   class KRightDialog;
0085   class NewGameWidget;
0086   class KPlayerSetupWidget;
0087   class NewGameSummaryWidget;
0088   class TcpConnectWidget;
0089   
0090 namespace Sprites
0091 {
0092   class ArrowSprite;
0093 }
0094 
0095 namespace GameLogic
0096 {
0097   class ONU;
0098   class KMessageParts;
0099   class Player;
0100 }
0101 
0102 /**
0103   * This is the main window. Due to the history of KsirK, this GUI class 
0104   * contain really too much code about game logics. This will change in the
0105   * future.
0106   *
0107   * @author Gael de Chalendar (aka Kleag)
0108   * @version $Id: kgamewin.h 243 2007-02-24 00:22:58Z kleag $
0109   */
0110 class KGameWindow: public KXmlGuiWindow
0111 {
0112   Q_OBJECT
0113 
0114 public:
0115   enum MessageShowingType {OnConfig, ForceShowing};
0116   enum FightType {Attack, Defense};
0117   enum TabbedWidgetsIndexesType
0118   {
0119     MAINMENU_INDEX /*0*/,
0120     NEWGAME_INDEX /*1*/,
0121     JABBERGAME_INDEX /*2*/,
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   inline JabberClient* jabberClient() {return m_jabberClient;}
0622   void askForJabberGames();
0623   void sendGameInfoToJabber();
0624 
0625   inline XMPP::Jid& serverJid() {return m_serverJid;}
0626   inline void setServerJid(const XMPP::Jid& jid) {m_serverJid = jid;}
0627 
0628   /**
0629   * Sets our own presence. Updates our resource in the
0630   * resource pool and sends a presence packet to the server.
0631   */
0632   void setPresence ( const XMPP::Status &status );
0633 
0634   inline void setGroupchatHost(const QString& str) {m_groupchatHost = str;}
0635   inline void setGroupchatRoom(const QString& str) {m_groupchatRoom = str;}
0636   inline void setGroupchatNick(const QString& str) {m_groupchatNick = str;}
0637   inline void setGroupchatPassword(const QString& str) {m_groupchatPassword = str;}
0638   
0639   const QString& groupchatHost() const {return m_groupchatHost;}
0640   const QString& groupchatRoom() const {return m_groupchatRoom;}
0641   const QString& groupchatNick() const {return m_groupchatNick;}
0642   const QString& groupchatPassword() const {return m_groupchatPassword;}
0643 
0644   void joinNetworkGame();
0645 
0646   void updateNewGameSummary();
0647   void showNewGameSummary();
0648 
0649 protected:
0650 
0651   /**
0652     * Connected to the frame timer, it manages the behavior of the game in
0653     * function of the value of the state.
0654     *
0655     * Fundamental method !!!
0656     */
0657 //   void slotTimerEvent();
0658 
0659 //   void resizeEvent ( QResizeEvent * event );
0660 
0661   /**
0662     * Add the main toolbar buttons
0663     */
0664   void initActions();
0665 
0666   /**
0667     * Prepares the status bar
0668     */
0669   void initStatusBar();
0670 
0671   /**
0672     * creates and display the main frame with the background
0673     */
0674   void initView();
0675 
0676   /**
0677     * Reimplementation of the inherited function : starts the timer.
0678     */
0679   void enterEvent(QEvent* ev) override;
0680 
0681   /**
0682     * Reimplementation of the inherited function : stops the timer.
0683     */
0684   void leaveEvent(QEvent* ev) override;
0685 
0686   void clear();
0687   
0688   /**
0689     * Reimplementation of the inherited function called when a window close event arise
0690     */
0691   bool queryClose() override;
0692     
0693   /** Shows some explanations on how to start playing */
0694   void explain();
0695 
0696   void reduceChat();
0697   void unreduceChat();
0698 
0699 Q_SIGNALS:
0700   void newJabberGame(const QString&, int, const QString&);
0701     
0702 public Q_SLOTS:
0703 
0704   void mouseMoveEvent ( QMouseEvent * event ) override;
0705 
0706   //@{
0707   /**
0708     * The slots associated to the buttons
0709     */
0710   void slotJabberGame();
0711   void slotNewGame();
0712   void slotNewJabberGame();
0713   void slotNewSocketGame();
0714   void slotJoinNetworkGame();
0715   void slotOpenGame();
0716   void slotSaveGame();
0717   void slotRecycling();
0718   void slotRecyclingFinished();
0719   void slotNextPlayer();
0720   void slotAttack1();
0721   void slotAttack2();
0722   void slotAttack3();
0723   void slotDefense1();
0724   void slotDefense2();
0725   void slotDefAuto();
0726   void slotWindowDef1();
0727   void slotWindowDef2();
0728   void slotInvade1();
0729 
0730   void slotInvade5();
0731   void slotInvade10();
0732   void slotInvasionFinished();
0733   void slotRetreat1();
0734   void slotRetreat5();
0735   void slotRetreat10();
0736   void slotMove();
0737   void slotCancel();
0738   void slotDumpGameInformations();
0739   void slotFinishMoves();
0740   void slotArena(bool);
0741   void slotContextualHelp();
0742   //@}
0743 
0744   /**
0745     * The standard slotShowAboutApplication slot
0746     */
0747   void slotShowAboutApplication();
0748 
0749   //@{
0750   /**
0751     * Connected to the frame mouse buttons signals, they manages the reaction
0752     * of the game to user interaction inside its main widget in function of
0753     * the state of the game.
0754     *
0755     * Fundamental methods !!!
0756     */
0757   void slotLeftButtonDown(const QPointF&);
0758   void slotLeftButtonUp(const QPointF&);
0759   void slotRightButtonDown(const QPointF&);
0760   void slotRightButtonUp(const QPointF&);
0761   //@}
0762 
0763   /** 
0764     * This slot displays a dialog explaining the goal of the current player and 
0765     * describing her progress in this way.
0766     */
0767   void slotShowGoal();
0768   
0769   /** 
0770     * Connected to the chat signals.
0771     */
0772   void slotChatMessage();
0773   void slotChatReduceButton();
0774   void slotChatFloatButtonPressed();
0775   void slotChatFloatChanged(bool value = true);
0776 
0777   void slotMovingFightersArrived(AnimSpritesGroup* sprites);
0778   void slotFiringFinished(AnimSpritesGroup*);
0779   void slotExplosionFinished(AnimSpritesGroup*);
0780   void slotMovingArmiesArrived(AnimSpritesGroup*);
0781   void slotBring(AnimSprite*);
0782   void slotMovingArmyArrived(AnimSprite*);
0783 
0784   void slotZoomIn();
0785   void slotZoomOut();
0786 
0787   void slotNewGameNext();
0788 //   void slotNewGameOK(unsigned int nbPlayers, const QString& skin, unsigned int nbNetworkPlayers, bool useGoals);
0789   void slotNewGameKO();
0790 
0791   void slotJabberGameCanceled(int previousIndex);
0792 
0793   void slotNewPlayerNext();
0794   void slotNewPlayerPrevious();
0795   void slotNewPlayerCancel();
0796   
0797   void slotStartNewGame();
0798   void slotTcpConnectCancel();
0799   void slotTcpConnectPrevious();
0800   
0801 private Q_SLOTS:
0802   void optionsConfigure();
0803 
0804   /**
0805     * Called every 50ms, it causes the scrolling of the world if necessary the
0806     * movement of the moving sprites. After it call the paint method to do the
0807     * animation of the sprites and it asks the pool to update
0808     */
0809   void evenementTimer();
0810 
0811   void slotRemoveMessage();
0812 
0813   void slotDisableHelp(const QString &);
0814 
0815   void slotArmiesNumberChanged(int);
0816 
0817   /* Connects to the server. */
0818 //   void slotConnect ();
0819   
0820   /* Disconnects from the server. */
0821 //   void slotDisconnect ();
0822   
0823   // handle a TLS warning
0824   void slotHandleTLSWarning ( QCA::TLS::IdentityResult identityResult, QCA::Validity validityResult );
0825   
0826   // handle client errors
0827   void slotClientError ( JabberClient::ErrorCode errorCode );
0828   
0829   // we are connected to the server
0830   void slotConnected ();
0831   
0832   /* Called from Psi: tells us when we've been disconnected from the server. */
0833   void slotCSDisconnected ();
0834   
0835   /* Called from Psi: alerts us to a protocol error. */
0836   void slotCSError (int);
0837   
0838   /* Called from Psi: roster request finished */
0839   void slotRosterRequestFinished ( bool success );
0840   
0841   /* Called from Psi: incoming file transfer */
0842 //   void slotIncomingFileTransfer ();
0843   
0844   /* Called from Psi: debug messages from the backend. */
0845   void slotClientDebugMessage (const QString &msg);
0846   
0847   /* XMPP console dialog */
0848 //   void slotXMPPConsole ();
0849   
0850   /* Slots for handling groupchats. */
0851 //   void slotJoinNewChat ();
0852   void slotGroupChatJoined ( const XMPP::Jid &jid );
0853   void slotGroupChatLeft ( const XMPP::Jid &jid );
0854   void slotGroupChatPresence ( const XMPP::Jid &jid, const XMPP::Status &status );
0855   void slotGroupChatError ( const XMPP::Jid &jid, int error, const QString &reason );
0856   
0857   /* Incoming subscription request. */
0858 //   void slotSubscription ( const XMPP::Jid &jid, const QString &type );
0859   
0860   /* the dialog that asked to add the contact was closed   (that dialog is shown in slotSubscription) */
0861 //   void slotAddedInfoEventActionActivated ( uint actionId );
0862   
0863   /**
0864   * A new item appeared in our roster, synch it with the
0865   * contact list.
0866   * (or the contact has been updated
0867   */
0868 //   void slotContactUpdated ( const XMPP::RosterItem & );
0869   
0870   /**
0871   * An item has been deleted from our roster,
0872   * delete it from our contact pool.
0873   */
0874 //   void slotContactDeleted ( const XMPP::RosterItem & );
0875   
0876   
0877   /* Someone on our contact list had (another) resource come online. */
0878 //   void slotResourceAvailable ( const XMPP::Jid &, const XMPP::Resource & );
0879   
0880   /* Someone on our contact list had (another) resource go offline. */
0881 //   void slotResourceUnavailable ( const XMPP::Jid &, const XMPP::Resource & );
0882   
0883   /* Displays a new message. */
0884   void slotReceivedMessage ( const XMPP::Message & );
0885   
0886   /* Gets the user's vCard from the server for editing. */
0887 //   void slotEditVCard ();
0888   
0889   /* Get the services list from the server for management. */
0890 //   void slotGetServices ();
0891   
0892   /* we received a voice invitation */
0893 //  void slotIncomingVoiceCall(const Jid&);
0894 
0895 /* the unregister task finished */
0896 //   void slotUnregisterFinished();
0897   void slotExit();
0898 
0899   void slotConnectToServer();
0900   
0901 private: // Private methods
0902   void createDefenseDialog();
0903   void moveArmies(GameLogic::Country& src, GameLogic::Country& dest, unsigned int nb);
0904   void saveXml(QTextStream& xmlStream);
0905   void loadDices();
0906   QPixmap buildDice(const QString& id);
0907   void setupPopupMessage();
0908   QString defenseLabel();
0909   
0910     
0911 private: // Private members
0912   QDockWidget * m_rightDock;
0913 
0914   KRightDialog * m_rightDialog;
0915 
0916   QStackedWidget *m_centralWidget;
0917 
0918   GameLogic::GameAutomaton* m_automaton;
0919 
0920   InvasionSlider * m_wSlide;
0921 
0922   /**
0923     * State that say the widget that is currently displayed between the map and the arena.
0924     */
0925   WidgetType m_currentDisplayedWidget;
0926 
0927   /**
0928    * The widget initialy docked at bottom where is displayed the events history
0929    */
0930   QDockWidget* m_bottomDock;
0931   
0932   //@{
0933   /**
0934     * NKD = Numberof Killed Defenders
0935     * NKA = Numberof Killed Attackers
0936     * These numbers are set up by resolveAttack() and are used to compute
0937     * in various methods
0938     * @todo: this solution is ugly. Change that.
0939     */
0940   int NKD, NKA;
0941   //@}
0942   
0943   bool m_useArena;
0944 
0945   int nbSpriteAttacking;
0946   int nbSpriteDefending;
0947 
0948   int relativePosInArenaAttack;
0949   int relativePosInArenaDefense;
0950 
0951   /**
0952     * the countries, continents, etc.
0953     */
0954   GameLogic::ONU* m_theWorld;
0955 
0956   /**
0957     * The main canvas of the world map
0958     */
0959   QGraphicsScene* m_scene_world;
0960 
0961   /**
0962     * The main canvas of the arena
0963     */
0964   QGraphicsScene* m_scene_arena;
0965 
0966   /** 
0967     * The background sprite of the world map. Gives access to the scene and, furthermore, 
0968     * the background size, thus giving hints for positioning and annimation.
0969     */
0970   BackGnd* m_backGnd_world;
0971 
0972   /** 
0973     * The background sprite of the arena. Gives access to the scene and, furthermore, 
0974     * the background size, thus giving hints for positioning and animation.
0975     */
0976   BackGnd* m_backGnd_arena;
0977 
0978   /**
0979     * The fighting fighters (represented by firing cannons)
0980     */
0981   AnimSpritesGroup* m_animFighters;
0982 
0983   /**
0984     * The number of armies to move/moving/moved from one country to another
0985     */
0986   int m_nbMovedArmies;
0987 
0988   //@{
0989   /**
0990     * The 2 countries involved in a fight or in a armies move
0991     */
0992   GameLogic::Country* m_firstCountry;
0993   GameLogic::Country* m_secondCountry;
0994   //@}
0995 
0996   /**
0997     *
0998     */
0999 //    QDialog *dialog;
1000 
1001   /**
1002     * The map frame of the game, its visual component ; the main widget
1003     */
1004   DecoratedGameFrame* m_frame;
1005 
1006   /**
1007     * The arena frame of the game, its visual component ; the main widget
1008     */
1009   FightArena* m_arena;
1010 
1011   /**
1012     * The menu frame of the game, its visual component ; the main widget
1013     */
1014   mainMenu* m_mainMenu;
1015 
1016   /**
1017     * This button is used to display the flag of the currently active player
1018     * in the status bar.
1019     */
1020   QAction * m_goalAction;
1021   QAction* m_jabberAction;
1022   QLabel* m_barFlag;
1023     
1024 //   KAccel m_accels;
1025   
1026   QList<QString> m_temporaryAccelerators;
1027     
1028   /** Used during countries distribution to handle network lags on the player member */
1029 //   unsigned int m_nbAvailArmies; 
1030   
1031   /** 
1032     * The list of players description whose connection is waited after loading 
1033     * a saved game. 
1034     */
1035   QList<GameLogic::PlayerMatrix> m_waitedPlayers;
1036 
1037   /**
1038    * The prompter where the game events and chat between network players are 
1039    * displayed
1040    */
1041   KGameChat *m_chatDlg;
1042 
1043   /**
1044     * Show the beginning of the last message received.
1045     */
1046   QLabel* m_titleChatMsg;
1047 
1048   /**
1049     * Reduced state of the chat widget.
1050     */
1051   bool m_chatIsReduced;
1052 
1053   /**
1054     * Contains all dices of the game.
1055     */
1056   QMap< DiceColor, QList<QPixmap> > m_dices;
1057 
1058   /**
1059     * Audio player object: play all the sounds of the game.
1060     */
1061   Phonon::MediaObject* m_audioPlayer;
1062 
1063   /** 
1064     * This timer is used to scroll the window if the mouse stay unmoving near 
1065     * the window border. 
1066     */
1067   QTimer m_timer;
1068 
1069   QList<AnimSpritesGroup*> m_animSpritesGroups;
1070 
1071   KGamePopupItem * m_message;
1072 
1073   GameLogic::Country* m_mouseLocalisation;
1074 
1075   QDialog * m_defenseDialog;
1076 
1077   // components that will be re-used of the chat
1078   QPixmap m_upChatFloatPix;
1079   QPixmap m_downChatFloatPix;
1080 
1081   // last width of the floating chat not reduced
1082   int m_lastWidthChat;
1083 
1084   QPushButton* m_reduceChatButton;
1085   QPushButton* m_floatChatButton;
1086 
1087   // the current saved game file name
1088   QString m_fileName;
1089 
1090   QAction* m_nextPlayerAction;
1091   QAction * m_saveGameAction;
1092   QAction * m_zoomInAction;
1093   QAction * m_zoomOutAction;
1094   QAction * m_contextualHelpAction;
1095 
1096   Sprites::ArrowSprite* m_uparrow;
1097   Sprites::ArrowSprite* m_downarrow;
1098   Sprites::ArrowSprite* m_leftarrow;
1099   Sprites::ArrowSprite* m_rightarrow;
1100   
1101   int m_port;
1102   bool m_reinitializingGame;
1103   
1104   NewGameWidget* m_newGameDialog;
1105   KPlayerSetupWidget* m_newPlayerWidget;
1106   
1107   GameLogic::GameAutomaton::GameState m_stateBeforeNewGame;
1108   int m_stackWidgetBeforeNewGame;
1109   
1110   JabberClient* m_jabberClient;
1111   XMPP::Jid m_serverJid;
1112   
1113   /* Initial presence to set after connecting. */
1114   XMPP::Status m_initialPresence;
1115   
1116   QString m_groupchatHost;
1117   QString m_groupchatRoom;
1118   QString m_groupchatNick;
1119   QString m_groupchatPassword;
1120   
1121   QString m_advertizedHostName;
1122   
1123   KsirkJabberGameWidget* m_jabberGameWidget;
1124   
1125   QSet<QString> m_presents;
1126 
1127   NewGameSetup* m_newGameSetup;
1128   NewGameSummaryWidget* m_newGameSummaryWidget;
1129   TcpConnectWidget* m_tcpConnectWidget;
1130 
1131   QLabel* m_labDef;
1132 };
1133 
1134 } // closing namespace Ksirk
1135 
1136 #endif // KGAMEWINDOW_H
1137