File indexing completed on 2024-07-14 04:01:18

0001 /*
0002     SPDX-FileCopyrightText: 2003 Russell Steffen <rsteffen@bayarea.net>
0003     SPDX-FileCopyrightText: 2003 Stephan Zehetner <s.zehetner@nevox.org>
0004     SPDX-FileCopyrightText: 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0005     SPDX-FileCopyrightText: 2006 Inge Wallin <inge@lysator.liu.se>
0006     SPDX-FileCopyrightText: 2006 Pierre Ducroquet <pinaraf@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef KONQUEST_GAMEVIEW_H
0012 #define KONQUEST_GAMEVIEW_H
0013 
0014 #include <QWidget>
0015 
0016 #include "planet.h"
0017 #include "players/player.h"
0018 #include "game.h"
0019 
0020 //************************************************************************
0021 // forward declarations
0022 //************************************************************************
0023 
0024 class QCheckBox;
0025 class QDockWidget;
0026 class QLabel;
0027 class QPushButton;
0028 class QLineEdit;
0029 class QTextEdit;
0030 class QIntValidator;
0031 
0032 class KLocalizedString;
0033 
0034 class Player;
0035 class MapView;
0036 class MapScene;
0037 class StandingsWidget;
0038 
0039 
0040 struct GameMessage {
0041     QString  text;
0042     Player  *sender;
0043     Player  *receiver;
0044 };
0045 
0046 
0047 enum GUIState { 
0048     NONE, 
0049     SOURCE_PLANET, 
0050     DEST_PLANET, 
0051     SHIP_COUNT, 
0052     RULER_SOURCE, 
0053     RULER_DEST
0054 };
0055 
0056 
0057 //************************************************************************
0058 // GameView Widget
0059 //************************************************************************
0060 
0061 
0062 class GameView : public QWidget
0063 {
0064     Q_OBJECT
0065 
0066 public:
0067     explicit  GameView(QWidget *parent, Game *game, QDockWidget *messagesDock, QDockWidget *standingsDock);
0068     ~GameView() override;
0069     bool  confirmNewGame();
0070 
0071     bool  shutdownGame();
0072     void  planetSelected( Planet * );
0073     void  newShipCount();
0074     void  nextPlayer();
0075     void  standingOrdersClicked();
0076 
0077     //***************************************************************
0078     // Toolbar items
0079     //***************************************************************
0080     void  measureDistance();
0081     void  showFleets();
0082 
0083     void  startNewGame();
0084     void  gameMsg(const KLocalizedString &msg, Player *player = nullptr,
0085           Planet *planet = nullptr, Player *planetPlayer = nullptr);
0086     void  turnPreparation();
0087 
0088 Q_SIGNALS:
0089     void  newGUIState( GUIState newState );
0090 
0091     //***************************************************************
0092     // Event Handlers
0093     //***************************************************************
0094 protected:
0095     void  keyPressEvent( QKeyEvent * ) override;
0096     void  resizeEvent ( QResizeEvent * event ) override;
0097 
0098 private:
0099     void  gameOver();
0100 
0101     void  changeGameView();
0102     void  cleanupGame();
0103 
0104     void  turn();
0105 
0106     //***************************************************************
0107     // Display Widgets
0108     //***************************************************************
0109 
0110     MapView       *m_mapWidget;
0111     MapScene      *m_mapScene;
0112     QLabel        *m_gameMessage;
0113     QPushButton   *m_endTurnBtn;
0114     QLineEdit     *m_shipCountEdit;
0115     QCheckBox     *m_standingOrder;
0116     QIntValidator *m_shipValidator;
0117     QLabel        *m_splashScreen;
0118 
0119     QTextEdit     *m_msgWidget;
0120     int            m_msgWidgetLastTurn;
0121 
0122     StandingsWidget *m_standingsWidget;
0123 
0124     QDockWidget   *m_messagesDock;
0125     QDockWidget   *m_standingsDock;
0126 
0127     //***************************************************************
0128     // Game objects
0129     //***************************************************************
0130 
0131     Game *m_game;
0132 
0133     bool                m_queueMessages;
0134     QList<GameMessage>  m_messageQueue;
0135     bool                m_showInformations;
0136     bool                m_initCompleted, m_cleanupNeeded;
0137 
0138     // States in the user interaction
0139     // FIXME: Break out into another file?
0140     bool                haveSourcePlanet;
0141     Planet             *sourcePlanet;
0142 
0143     bool                haveDestPlanet;
0144     Planet             *destPlanet;
0145 
0146     bool                haveShipCount, standingOrder;
0147     long long           shipCount;
0148 
0149     //***************************************************************
0150     // Game State information
0151     //***************************************************************
0152     GUIState            m_guiState;
0153 };
0154 
0155 #endif // KONQUEST_GAMEVIEW_H