1 /* This file is part of KsirK. 2 Copyright (C) 2001-2007 Gael de Chalendar <kleag@free.fr> 3 4 KsirK is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public 6 License as published by the Free Software Foundation, either version 2 7 of the License, or (at your option) any later version. 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 GNU 12 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 Street, Fifth Floor, Boston, MA 17 02110-1301, USA 18 */ 19 20 #ifndef KGAMEWIN_H 21 #define KGAMEWIN_H 22 23 #include "krightdialog.h" 24 #include "KsirkGlobalDefinitions.h" 25 #include "decoratedgameframe.h" 26 #include "fightArena.h" 27 #include "mainMenu.h" 28 #include "GameLogic/onu.h" 29 #include "GameLogic/gameautomaton.h" 30 #include "GameLogic/player.h" 31 #include "GameLogic/country.h" 32 #include "Dialogs/InvasionSlider.h" 33 #include "Sprites/animspriteslist.h" 34 #include "Jabber/jabberclient.h" 35 36 #include "qca.h" 37 38 // include files for Qt 39 #include <QPointF> 40 #include <QPixmap> 41 #include <QLabel> 42 #include <QPushButton> 43 #include <QStackedWidget> 44 #include <QGroupBox> 45 #include <QSplitter> 46 #include <QSlider> 47 #include <QHBoxLayout> 48 #include <QVBoxLayout> 49 // include files for KDE 50 #include <KSharedConfig> 51 #include <KXmlGuiWindow> 52 #include <QStandardPaths> 53 54 // #include <kdialogbase.h> 55 56 class KsirkJabberGameWidget; 57 class mainMenu; 58 class NewGameSetup; 59 60 class QAction; 61 class KGameChat; 62 class KGamePopupItem; 63 class QDialog; 64 class QAction; 65 66 class QEvent; 67 class QDockWidget; 68 class QGraphicsScene; 69 70 // class JabberClient; 71 72 namespace Phonon 73 { 74 class MediaObject; 75 } 76 77 namespace Ksirk 78 { 79 80 // forward declaration of the KsirK classes 81 class DecoratedGameFrame; 82 class FightArena; 83 class AnimSpritesGroup; 84 class KRightDialog; 85 class NewGameWidget; 86 class KPlayerSetupWidget; 87 class NewGameSummaryWidget; 88 class TcpConnectWidget; 89 90 namespace Sprites 91 { 92 class ArrowSprite; 93 } 94 95 namespace GameLogic 96 { 97 class ONU; 98 class KMessageParts; 99 class Player; 100 } 101 102 /** 103 * This is the main window. Due to the history of KsirK, this GUI class 104 * contain really too much code about game logics. This will change in the 105 * future. 106 * 107 * @author Gael de Chalendar (aka Kleag) 108 * @version $Id: kgamewin.h 243 2007-02-24 00:22:58Z kleag $ 109 */ 110 class KGameWindow: public KXmlGuiWindow 111 { 112 Q_OBJECT 113 114 public: 115 enum MessageShowingType {OnConfig, ForceShowing}; 116 enum FightType {Attack, Defense}; 117 enum TabbedWidgetsIndexesType 118 { 119 MAINMENU_INDEX /*0*/, 120 NEWGAME_INDEX /*1*/, 121 JABBERGAME_INDEX /*2*/, 122 NEWPLAYER_INDEX /*3*/, 123 NEWGAMESUMMARY_INDEX /*4*/, 124 TCPCONNECT_INDEX /*5*/, 125 MAP_INDEX /*6*/, 126 ARENA_INDEX /*7*/ 127 }; 128 /** 129 * Create the window and initializes its members 130 */ 131 explicit KGameWindow(QWidget* parent=0); 132 133 /** 134 * Deletes the background and the pool 135 */ 136 ~KGameWindow() override; 137 138 /** Returns the game graphics view */ frame()139 DecoratedGameFrame* frame() {return m_frame;} 140 /** Returns the game graphics scene*/ 141 // QGraphicsScene* graphicsscene() {return m_ 142 143 /** Returns the arena graphics view */ arena()144 FightArena* arena() {return m_arena;} 145 146 /** Returns the menu graphics view */ mMenu()147 mainMenu* mMenu() {return m_mainMenu;} 148 newGameSetup()149 NewGameSetup* newGameSetup() {return m_newGameSetup;} 150 151 /** 152 * Ask all the sprites to repaint themselves 153 */ 154 // void paint(); 155 156 /** 157 * Returns the country inside which the argument point is. 0 if none. 158 */ 159 GameLogic::Country* clickIn(const QPointF& Point); 160 161 /** 162 * Loads a new skin. 163 */ 164 void newSkin(const QString& onuDefinitionFileName = ""); 165 setStateBeforeNewGame(GameLogic::GameAutomaton::GameState state)166 void setStateBeforeNewGame(GameLogic::GameAutomaton::GameState state) {m_stateBeforeNewGame = state;} 167 168 /************** METHODS BELOW ARE DEFINED IN gestionSprites.cpp **************/ 169 /** 170 * Prepares the sprites to be moved : removes the nb necessary sprites from 171 * source, creates the moving sprites and gives them their destination, etc 172 */ 173 bool initArmiesMovement(unsigned int nb, GameLogic::Country* src, GameLogic::Country* dest); 174 175 AnimSprite* initArmiesMultipleCombat(unsigned int nb, 176 GameLogic::Country* src, 177 GameLogic::Country* dest, QPointF); 178 179 QPointF determinePointDepartArena(GameLogic::Country *pays, int relativePos); 180 181 void determinePointArrivee( 182 QPointF& pointArriveeAttaquant, 183 QPointF& pointArriveeDefenseur); 184 185 void determinePointArriveeForArena( 186 int relative, 187 QPointF& pointArriveeAttaquant, 188 QPointF& pointArriveeDefenseur); 189 190 191 /** 192 * Initializes the sprites that will fight for the attacker and the 193 * defender. Prepares them for moving 194 */ 195 void initCombatMovement(); 196 197 /** 198 * Prepare the fighting animation : replace the sprites sequence by the 199 * sequence of explosion 200 */ 201 202 void animCombat(); 203 /** 204 * Center the map on the fight so that the user can see what's happening 205 */ 206 void centerOnFight(); 207 208 /** 209 * Replaces the animated fighters by the simple cannon image 210 */ 211 void stopCombat(); 212 213 /** 214 * Replaces the sequence of destroyed cannon(s) by the explosion sequence. 215 */ 216 void animExplosion(int who); 217 218 void animExplosionForArena(); 219 220 /** 221 * When all the explosion sequence has been shown for all explosing 222 * devices, removes these sprites 223 */ 224 void stopExplosion(); 225 226 /** 227 * Set up the eventual survivor(s) to come back home 228 */ 229 void initCombatBringBackForArena(GameLogic::Country *, GameLogic::Country *); 230 231 /** 232 * Tests if there is currently moving armies (infantrymen, cavalrymen, 233 * cannons or fighters) 234 * @return true if there is moving armies; false otherwise 235 */ haveMovingArmies()236 bool haveMovingArmies() const {return !m_animSpritesGroups.empty();} 237 238 /************** END OF METHODS DEFINED IN gestionSprites.cpp *****************/ 239 240 bool setupOnePlayer(); 241 bool setupOneWaitedPlayer(); 242 bool createWaitedPlayer(quint32 waitedPlayerId); 243 244 /** 245 * Do the distribution of armies for all players in function of their 246 * number of countries 247 */ 248 void distributeArmies(); 249 250 /** 251 * Computes the number of armies to be distributed to p at the beginning of 252 * the turn, function of the number of countries he owns 253 * @todo : this method should be a method of Player 254 */ 255 int nbNewArmies(GameLogic::Player *p); 256 257 /** 258 * Changes the owner of the attacked country if its number of armies 259 * becomes negative or null. Handle the end of the game of the 260 * winning conditions are fulfilled. 261 */ 262 bool attackEnd(); 263 264 /** 265 * Computes the results of the fight 266 */ 267 void resolveAttack(); 268 269 //@{ 270 /** 271 * Display and removes various toolbar buttons in function of the state 272 * of the game. 273 */ 274 void displayRecyclingButtons(); 275 void clearHighlighting(); 276 void startLocalCurrentAI(); 277 void displayDefenseWindow(); 278 279 //@} 280 281 /** 282 * Updates the flag in the statusbar with the one of the current player 283 */ 284 void setBarFlagButton(const GameLogic::Player* player = 0); 285 286 /** 287 * @brief Shortcut for "statusBar()-> changeItem(text, id)" 288 */ 289 void changeItem ( const QString& text, int id = ID_NO_STATUS_MSG, bool log = true); 290 291 /** 292 * @brief Receives pixmaps and strings to internationalize and display in a 293 * collection with stream API. 294 * 295 * When encountering a serie of strings, the first one is the pattern and 296 * those following are the fillers. The end of the collection or a pixmap 297 * signals that all fillers have been given. 298 * @note No check is made (e.g. on the number of fillers) 299 * 300 * @param strings @b IN/OUT <I>KsirK::GameLogic::KMessageParts&</I> 301 * the collection holding strings to display. 302 * @param id @b IN <I>int</I> 303 * The id of the status bar where to display the internationalized message. 304 */ 305 void changeItem(Ksirk::GameLogic::KMessageParts& strings, 306 int id = ID_NO_STATUS_MSG, bool log = true); 307 308 /** 309 * @brief Receives strings to internationalize and display in a collection 310 * with stream API and broadcasts the message to all clients. 311 * @param strings @b IN/OUT <I>KsirK::GameLogic::KMessageParts&</I> 312 * the collection holding strings to display. 313 * @param id @b IN <I>int</I> 314 * The id of the status bar where to display the internationalized message. 315 */ 316 void broadcastChangeItem(Ksirk::GameLogic::KMessageParts& strings, 317 int id = ID_NO_STATUS_MSG, bool log = true ); 318 319 /** 320 * @brief Reconnect the mouse events signals to their slots to allow human players 321 * to play 322 */ 323 void reconnectMouse(); 324 325 /** 326 * Disconnects the mouse events signals from their slots to avoid human 327 * player actions when it is the turn of the AI 328 */ 329 void disconnectMouse(); 330 331 /** Returns the current state of the game */ 332 GameLogic::GameAutomaton::GameState getState() const; 333 334 /** Return true if the state of the game is the argument; false otherwise */ 335 bool isMyState(GameLogic::GameAutomaton::GameState state) const; 336 337 /** @brief sets the current player to be the one pointed by the argument. 338 * Makes associated actions: 339 * 340 * Changes the flag in the status bar. 341 * @return Returns true in case of success; false otherwise. 342 */ 343 // bool setCurrentPlayer(const GameLogic::Player* player); 344 345 /** sets the current player to be the first one. Makes associated actions. */ 346 int setCurrentPlayerToFirst(); 347 348 /** 349 * Sets the current player to be the next one in the list. Makes the 350 * associated actions : 351 * Changes the flag in the status bar,... 352 * @return 0 in case of success; non-zero otherwise. For example, it returns 353 * 1 the current player was the last one 354 */ 355 int setCurrentPlayerToNext(bool restartRunningAIs = true); 356 357 358 bool playerPutsArmy(const QPointF& point, bool removable); 359 bool playerPutsInitialArmy(const QPointF& point); 360 bool playerRemovesArmy(const QPointF& point); 361 362 /** Sets the attacker country to be the one at the given point */ 363 bool attacker(const QPointF& point); 364 365 /** Sets the attacked country to be the one at the given point */ 366 unsigned int attacked(const QPointF& point); 367 368 /** Sets the first country in a fight to be the one at the given point. */ 369 bool firstCountryAt(const QPointF& point); 370 371 /** Sets the second country in a fight to be the one at the given point. */ 372 bool secondCountryAt(const QPointF& point); 373 374 /** 375 * @brief setups window for recycling 376 */ 377 void initRecycling(); 378 379 /** Test if there is some sprites animated for a fight */ 380 bool haveAnimFighters() const; 381 382 /** Clears all animated sprites lists and shows the post-fight buttons */ 383 bool terminateAttackSequence(); 384 385 /** Called whenever a player choses to end the recycling. */ 386 bool nextPlayerRecycling(); 387 388 /** 389 * @return if true next state will be NEWARMIES else it will be WAIT 390 */ 391 bool nextPlayerNormal(); 392 393 /** Called whenever a player choses to attack with nb armies. */ 394 void attack(unsigned int nb); 395 396 /** Called whenever a player choses to defend with nb armies. */ 397 void defense(unsigned int nb); 398 399 /** Called whenever a player choses the cancel button. */ 400 void cancelAction(); 401 402 /** 403 * Called whenever a player choses to cancel the started end of turn move of 404 * armies. 405 */ 406 void cancelShiftSource(); 407 408 /** Called when the user clicks the new game button. */ 409 bool actionNewGame(GameLogic::GameAutomaton::NetworkGameType socket); 410 411 /** Called when the user clicks the open game button. */ 412 bool actionOpenGame(); 413 414 /** Called when the user clicks the recycling button. */ 415 void actionRecycling(); 416 417 /** */ 418 void postActionRecycling(); 419 420 /** Called when the user clicks the recycling finished button. */ 421 void actionRecyclingFinished(); 422 423 /** 424 * Tests if the move finishing at the given point is valid. 425 * @return true if the move is valid; false otherwise. 426 */ 427 bool isMoveValid(const QPointF& point); 428 429 /** 430 * Tests if the fight finishing at the given point is valid. 431 * @return true if the fight is valid; false otherwise. 432 */ 433 bool isFightValid(const QPointF& point); 434 435 /** 436 * @brief Accessor to the world 437 * @return A pointer to the world 438 */ 439 GameLogic::ONU* theWorld(); 440 441 /** 442 * @brief Adds a player 443 */ 444 GameLogic::Player* addPlayer(const QString& playerName, 445 unsigned int nbAvailArmies, 446 unsigned int nbCountries, 447 const QString& nationName, 448 bool isAI, 449 const QString& password = "", 450 unsigned int nbAttack = 0, 451 unsigned int nbDefense = 0); 452 453 //@{ 454 /** 455 * accessors and manipulators of the number of armies moved during an invasion 456 * or an end of turn move 457 */ 458 int nbMovedArmies(); 459 void incrNbMovedArmies(unsigned int nb = 1); 460 void decrNbMovedArmies(unsigned int nb = 1); 461 //@} 462 463 //@{ 464 /** 465 * causes the move to/from the first country stored from/to the second one 466 * during an invasion or an end of turn move 467 */ 468 bool invade(unsigned int nb = 1); 469 AnimSprite* simultaneousAttack(int nbArmies, FightType type); 470 bool retreat(unsigned int nb = 1); 471 //@} 472 473 //@{ 474 /** 475 * causes the end of an invasion or an end of turn move 476 */ 477 void invasionFinished(); 478 void shiftFinished(); 479 //@} 480 481 /** @return true if the given player is the last one ; false otherwise */ 482 bool isLastPlayer(const GameLogic::Player& player); 483 automaton()484 inline GameLogic::GameAutomaton* automaton() {return m_automaton;} 485 486 /** 487 * Gets the background world map sprite. Gives access to the scene and, furthermore, 488 * the background size, thus giving hints for positioning and annimation. 489 */ backGndWorld()490 inline BackGnd* backGndWorld() {return m_backGnd_world;} backGndWorld()491 inline const BackGnd* backGndWorld() const {return m_backGnd_world;} 492 493 /** 494 * Gets the background arena sprite. Gives access to the scene and, furthermore, 495 * the background size, thus giving hints for positioning and annimation. 496 */ backGndArena()497 inline BackGnd* backGndArena() {return m_backGnd_arena;} backGndArena()498 inline const BackGnd* backGndArena() const {return m_backGnd_arena;} 499 500 /** 501 * Gets the current background sprite. Gives access to the scene and, furthermore, 502 * the background size, thus giving hints for positioning and annimation. 503 */ 504 BackGnd* backGnd(); 505 506 //@{ 507 /** 508 * Accessors to the number of available armies. This one is inherited from a 509 * long time ago and should probably be replaced by available armies local 510 * to players. 511 */ 512 /* inline void availArmies(unsigned int nb) {m_nbAvailArmies = nb;} 513 inline unsigned int availArmies() {return m_nbAvailArmies;}*/ 514 //@} 515 516 //@{ 517 /** 518 * Accessors to the firstly and secondly clicked countries that will become 519 * the attacker and the defender countries (or the source and the target) if 520 * the move is valid 521 */ 522 void firstCountry(GameLogic::Country* country); 523 void secondCountry(GameLogic::Country* country); 524 GameLogic::Country* firstCountry(); 525 GameLogic::Country* secondCountry(); 526 //@} 527 528 /** 529 * Forces all moving sprites to finish their move be clearing moving 530 * sprites collections. 531 */ 532 void finishMoves(); 533 534 /** 535 * Returns the list of players definitions whose connection from the network 536 * is waited after loading a saved game. 537 */ waitedPlayers()538 inline QList<GameLogic::PlayerMatrix>& waitedPlayers() {return m_waitedPlayers;} 539 540 /** Displays the buttons associated to the given game state. */ 541 void displayButtonsForState(GameLogic::GameAutomaton::GameState state); 542 543 /** 544 * The game is over. The given player is the winner. Displays the dialog 545 * stating this fact, depending on if this player is local or distant. 546 */ 547 void winner(const GameLogic::Player* player); 548 549 /** Returns a list of the nations names associated to their flag's file name. */ 550 QMap< QString, QString > nationsList(); 551 552 /** Returns a pointer to the chat widget used to chat and to display messages. */ chatWidget()553 inline KGameChat* chatWidget() {return m_chatDlg;} 554 555 /** Returns a pointer to the title chat message label used to display messages. */ titleChatMessage()556 inline QLabel* titleChatMessage() {return m_titleChatMsg;} 557 558 void showMessage(const QString& message, quint32 delay=5, MessageShowingType forcing=OnConfig); 559 560 /** 561 * Replace the map widget by the arena widget. 562 */ 563 void showArena(); 564 565 /** 566 * Replace the arena widget by the map widget. 567 */ 568 void showMap(); 569 570 /** 571 * Replace the mainMenu widget by the map widget. 572 */ 573 void showMainMenu(); 574 575 /** 576 * The three types of possible central widget. This enum is used to know which 577 * one is currently displayed (see m_currentDisplayedWidget member below). 578 */ 579 enum WidgetType {MainMenu, Map, Arena}; 580 581 /** 582 * Give type of the central widget currently displayed. 583 * @return current widget type 584 */ 585 WidgetType currentWidgetType(); 586 587 /** 588 * Give the central widget currently displayed. 589 * @return current widget 590 */ 591 QGraphicsView* currentWidget(); 592 /** 593 * Return the right dialog 594 */ 595 KRightDialog * getRightDialog(); 596 597 /** Arena state */ 598 bool isArena(); 599 600 enum DiceColor {Blue,Red}; 601 602 QPixmap getDice(DiceColor color, int num); 603 604 /** 605 * Returns the current player 606 */ 607 GameLogic::Player* currentPlayer(); 608 609 void slideInvade(GameLogic::Country *,GameLogic::Country *, Ksirk::InvasionSlider::InvasionType invasionType = Ksirk::InvasionSlider::Invasion); 610 611 void setNextPlayerActionEnabled(bool value); 612 void setSaveGameActionEnabled(bool value); 613 void setContextualHelpActionEnabled(GameLogic::GameAutomaton::GameState gameState, bool isPlayerAI); 614 615 void updateScrollArrows(); 616 617 bool newGameDialog(const QString& skin, GameLogic::GameAutomaton::NetworkGameType netGameType); 618 619 bool finishSetupPlayers(); 620 jabberClient()621 inline JabberClient* jabberClient() {return m_jabberClient;} 622 void askForJabberGames(); 623 void sendGameInfoToJabber(); 624 serverJid()625 inline XMPP::Jid& serverJid() {return m_serverJid;} setServerJid(const XMPP::Jid & jid)626 inline void setServerJid(const XMPP::Jid& jid) {m_serverJid = jid;} 627 628 /** 629 * Sets our own presence. Updates our resource in the 630 * resource pool and sends a presence packet to the server. 631 */ 632 void setPresence ( const XMPP::Status &status ); 633 setGroupchatHost(const QString & str)634 inline void setGroupchatHost(const QString& str) {m_groupchatHost = str;} setGroupchatRoom(const QString & str)635 inline void setGroupchatRoom(const QString& str) {m_groupchatRoom = str;} setGroupchatNick(const QString & str)636 inline void setGroupchatNick(const QString& str) {m_groupchatNick = str;} setGroupchatPassword(const QString & str)637 inline void setGroupchatPassword(const QString& str) {m_groupchatPassword = str;} 638 groupchatHost()639 const QString& groupchatHost() const {return m_groupchatHost;} groupchatRoom()640 const QString& groupchatRoom() const {return m_groupchatRoom;} groupchatNick()641 const QString& groupchatNick() const {return m_groupchatNick;} groupchatPassword()642 const QString& groupchatPassword() const {return m_groupchatPassword;} 643 644 void joinNetworkGame(); 645 646 void updateNewGameSummary(); 647 void showNewGameSummary(); 648 649 protected: 650 651 /** 652 * Connected to the frame timer, it manages the behavior of the game in 653 * function of the value of the state. 654 * 655 * Fundamental method !!! 656 */ 657 // void slotTimerEvent(); 658 659 // void resizeEvent ( QResizeEvent * event ); 660 661 /** 662 * Add the main toolbar buttons 663 */ 664 void initActions(); 665 666 /** 667 * Prepares the status bar 668 */ 669 void initStatusBar(); 670 671 /** 672 * creates and display the main frame with the background 673 */ 674 void initView(); 675 676 /** 677 * Reimplementation of the inherited function : starts the timer. 678 */ 679 void enterEvent(QEvent* ev) override; 680 681 /** 682 * Reimplementation of the inherited function : stops the timer. 683 */ 684 void leaveEvent(QEvent* ev) override; 685 686 void clear(); 687 688 /** 689 * Reimplementation of the inherited function called when a window close event arise 690 */ 691 bool queryClose() override; 692 693 /** Shows some explanations on how to start playing */ 694 void explain(); 695 696 void reduceChat(); 697 void unreduceChat(); 698 699 Q_SIGNALS: 700 void newJabberGame(const QString&, int, const QString&); 701 702 public Q_SLOTS: 703 704 void mouseMoveEvent ( QMouseEvent * event ) override; 705 706 //@{ 707 /** 708 * The slots associated to the buttons 709 */ 710 void slotJabberGame(); 711 void slotNewGame(); 712 void slotNewJabberGame(); 713 void slotNewSocketGame(); 714 void slotJoinNetworkGame(); 715 void slotOpenGame(); 716 void slotSaveGame(); 717 void slotRecycling(); 718 void slotRecyclingFinished(); 719 void slotNextPlayer(); 720 void slotAttack1(); 721 void slotAttack2(); 722 void slotAttack3(); 723 void slotDefense1(); 724 void slotDefense2(); 725 void slotDefAuto(); 726 void slotWindowDef1(); 727 void slotWindowDef2(); 728 void slotInvade1(); 729 730 void slotInvade5(); 731 void slotInvade10(); 732 void slotInvasionFinished(); 733 void slotRetreat1(); 734 void slotRetreat5(); 735 void slotRetreat10(); 736 void slotMove(); 737 void slotCancel(); 738 void slotDumpGameInformations(); 739 void slotFinishMoves(); 740 void slotArena(bool); 741 void slotContextualHelp(); 742 //@} 743 744 /** 745 * The standard slotShowAboutApplication slot 746 */ 747 void slotShowAboutApplication(); 748 749 //@{ 750 /** 751 * Connected to the frame mouse buttons signals, they manages the reaction 752 * of the game to user interaction inside its main widget in function of 753 * the state of the game. 754 * 755 * Fundamental methods !!! 756 */ 757 void slotLeftButtonDown(const QPointF&); 758 void slotLeftButtonUp(const QPointF&); 759 void slotRightButtonDown(const QPointF&); 760 void slotRightButtonUp(const QPointF&); 761 //@} 762 763 /** 764 * This slot displays a dialog explaining the goal of the current player and 765 * describing her progress in this way. 766 */ 767 void slotShowGoal(); 768 769 /** 770 * Connected to the chat signals. 771 */ 772 void slotChatMessage(); 773 void slotChatReduceButton(); 774 void slotChatFloatButtonPressed(); 775 void slotChatFloatChanged(bool value = true); 776 777 void slotMovingFightersArrived(AnimSpritesGroup* sprites); 778 void slotFiringFinished(AnimSpritesGroup*); 779 void slotExplosionFinished(AnimSpritesGroup*); 780 void slotMovingArmiesArrived(AnimSpritesGroup*); 781 void slotBring(AnimSprite*); 782 void slotMovingArmyArrived(AnimSprite*); 783 784 void slotZoomIn(); 785 void slotZoomOut(); 786 787 void slotNewGameNext(); 788 // void slotNewGameOK(unsigned int nbPlayers, const QString& skin, unsigned int nbNetworkPlayers, bool useGoals); 789 void slotNewGameKO(); 790 791 void slotJabberGameCanceled(int previousIndex); 792 793 void slotNewPlayerNext(); 794 void slotNewPlayerPrevious(); 795 void slotNewPlayerCancel(); 796 797 void slotStartNewGame(); 798 void slotTcpConnectCancel(); 799 void slotTcpConnectPrevious(); 800 801 private Q_SLOTS: 802 void optionsConfigure(); 803 804 /** 805 * Called every 50ms, it causes the scrolling of the world if necessary the 806 * movement of the moving sprites. After it call the paint method to do the 807 * animation of the sprites and it asks the pool to update 808 */ 809 void evenementTimer(); 810 811 void slotRemoveMessage(); 812 813 void slotDisableHelp(const QString &); 814 815 void slotArmiesNumberChanged(int); 816 817 /* Connects to the server. */ 818 // void slotConnect (); 819 820 /* Disconnects from the server. */ 821 // void slotDisconnect (); 822 823 // handle a TLS warning 824 void slotHandleTLSWarning ( QCA::TLS::IdentityResult identityResult, QCA::Validity validityResult ); 825 826 // handle client errors 827 void slotClientError ( JabberClient::ErrorCode errorCode ); 828 829 // we are connected to the server 830 void slotConnected (); 831 832 /* Called from Psi: tells us when we've been disconnected from the server. */ 833 void slotCSDisconnected (); 834 835 /* Called from Psi: alerts us to a protocol error. */ 836 void slotCSError (int); 837 838 /* Called from Psi: roster request finished */ 839 void slotRosterRequestFinished ( bool success ); 840 841 /* Called from Psi: incoming file transfer */ 842 // void slotIncomingFileTransfer (); 843 844 /* Called from Psi: debug messages from the backend. */ 845 void slotClientDebugMessage (const QString &msg); 846 847 /* XMPP console dialog */ 848 // void slotXMPPConsole (); 849 850 /* Slots for handling groupchats. */ 851 // void slotJoinNewChat (); 852 void slotGroupChatJoined ( const XMPP::Jid &jid ); 853 void slotGroupChatLeft ( const XMPP::Jid &jid ); 854 void slotGroupChatPresence ( const XMPP::Jid &jid, const XMPP::Status &status ); 855 void slotGroupChatError ( const XMPP::Jid &jid, int error, const QString &reason ); 856 857 /* Incoming subscription request. */ 858 // void slotSubscription ( const XMPP::Jid &jid, const QString &type ); 859 860 /* the dialog that asked to add the contact was closed (that dialog is shown in slotSubscription) */ 861 // void slotAddedInfoEventActionActivated ( uint actionId ); 862 863 /** 864 * A new item appeared in our roster, synch it with the 865 * contact list. 866 * (or the contact has been updated 867 */ 868 // void slotContactUpdated ( const XMPP::RosterItem & ); 869 870 /** 871 * An item has been deleted from our roster, 872 * delete it from our contact pool. 873 */ 874 // void slotContactDeleted ( const XMPP::RosterItem & ); 875 876 877 /* Someone on our contact list had (another) resource come online. */ 878 // void slotResourceAvailable ( const XMPP::Jid &, const XMPP::Resource & ); 879 880 /* Someone on our contact list had (another) resource go offline. */ 881 // void slotResourceUnavailable ( const XMPP::Jid &, const XMPP::Resource & ); 882 883 /* Displays a new message. */ 884 void slotReceivedMessage ( const XMPP::Message & ); 885 886 /* Gets the user's vCard from the server for editing. */ 887 // void slotEditVCard (); 888 889 /* Get the services list from the server for management. */ 890 // void slotGetServices (); 891 892 /* we received a voice invitation */ 893 // void slotIncomingVoiceCall(const Jid&); 894 895 /* the unregister task finished */ 896 // void slotUnregisterFinished(); 897 void slotExit(); 898 899 void slotConnectToServer(); 900 901 private: // Private methods 902 void createDefenseDialog(); 903 void moveArmies(GameLogic::Country& src, GameLogic::Country& dest, unsigned int nb); 904 void saveXml(QTextStream& xmlStream); 905 void loadDices(); 906 QPixmap buildDice(const QString& id); 907 void setupPopupMessage(); 908 QString defenseLabel(); 909 910 911 private: // Private members 912 QDockWidget * m_rightDock; 913 914 KRightDialog * m_rightDialog; 915 916 QStackedWidget *m_centralWidget; 917 918 GameLogic::GameAutomaton* m_automaton; 919 920 InvasionSlider * m_wSlide; 921 922 /** 923 * State that say the widget that is currently displayed between the map and the arena. 924 */ 925 WidgetType m_currentDisplayedWidget; 926 927 /** 928 * The widget initialy docked at bottom where is displayed the events history 929 */ 930 QDockWidget* m_bottomDock; 931 932 //@{ 933 /** 934 * NKD = Numberof Killed Defenders 935 * NKA = Numberof Killed Attackers 936 * These numbers are set up by resolveAttack() and are used to compute 937 * in various methods 938 * @todo: this solution is ugly. Change that. 939 */ 940 int NKD, NKA; 941 //@} 942 943 bool m_useArena; 944 945 int nbSpriteAttacking; 946 int nbSpriteDefending; 947 948 int relativePosInArenaAttack; 949 int relativePosInArenaDefense; 950 951 /** 952 * the countries, continents, etc. 953 */ 954 GameLogic::ONU* m_theWorld; 955 956 /** 957 * The main canvas of the world map 958 */ 959 QGraphicsScene* m_scene_world; 960 961 /** 962 * The main canvas of the arena 963 */ 964 QGraphicsScene* m_scene_arena; 965 966 /** 967 * The background sprite of the world map. Gives access to the scene and, furthermore, 968 * the background size, thus giving hints for positioning and annimation. 969 */ 970 BackGnd* m_backGnd_world; 971 972 /** 973 * The background sprite of the arena. Gives access to the scene and, furthermore, 974 * the background size, thus giving hints for positioning and animation. 975 */ 976 BackGnd* m_backGnd_arena; 977 978 /** 979 * The fighting fighters (represented by firing cannons) 980 */ 981 AnimSpritesGroup* m_animFighters; 982 983 /** 984 * The number of armies to move/moving/moved from one country to another 985 */ 986 int m_nbMovedArmies; 987 988 //@{ 989 /** 990 * The 2 countries involved in a fight or in a armies move 991 */ 992 GameLogic::Country* m_firstCountry; 993 GameLogic::Country* m_secondCountry; 994 //@} 995 996 /** 997 * 998 */ 999 // 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 1138