File indexing completed on 2024-12-08 03:48:03
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 /* begin : Thu Jul 19 2001 */ 0021 0022 #ifndef DECORATEDGAMEFRAME_H 0023 #define DECORATEDGAMEFRAME_H 0024 0025 #include "KsirkGlobalDefinitions.h" 0026 0027 #include "GameLogic/gameautomaton.h" 0028 0029 #include <stdlib.h> 0030 #include <QTimer> 0031 #include <QMouseEvent> 0032 #include <QGraphicsView> 0033 #include <QMenu> 0034 0035 class KGameIO; 0036 0037 namespace Ksirk 0038 { 0039 0040 class ArenaAction : public QAction 0041 { 0042 Q_OBJECT 0043 public: 0044 ArenaAction(QObject* parent = nullptr) : QAction(parent), m_arenaEnabled(false) {} 0045 explicit ArenaAction(const QString& text, QObject* parent = nullptr) : QAction(text, parent), m_arenaEnabled(false) {} 0046 inline bool isArenaEnabled() {return m_arenaEnabled;} 0047 inline void setArenaEnabled(bool value) {m_arenaEnabled = value;} 0048 private: 0049 bool m_arenaEnabled; 0050 }; 0051 0052 0053 /** 0054 * The DecoratedGameFrame class is the central widget of the application where 0055 * all the sprites are displayed. It is linked to its parent widget (the main 0056 * window) 0057 */ 0058 class DecoratedGameFrame: public QGraphicsView 0059 { 0060 Q_OBJECT 0061 0062 public: 0063 /** 0064 * Creates the frame, its timer and set some parameters 0065 * @param parent The parent widget, the main window 0066 * @param mapW The width of the map. Will be the width given in size hint. 0067 * @param mapH The height of the map. Will be the height given in size hint. 0068 */ 0069 DecoratedGameFrame(QWidget* parent, unsigned int mapW, unsigned int mapH, GameLogic::GameAutomaton* m_automaton); 0070 0071 /** 0072 * Destroy the frame : stops and deletes the timer 0073 */ 0074 ~DecoratedGameFrame() override; 0075 0076 /** 0077 * Returns the size given to the constructor. 0078 * @return The size given to the constructor. 0079 */ 0080 QSize sizeHint() const override; 0081 0082 /** 0083 * initialisation of the contextual menu 0084 */ 0085 void initMenu (); 0086 void initAttackMenu (); 0087 void initMoveMenu (); 0088 0089 /** 0090 * Redefinition of the contextMenuEvent function 0091 */ 0092 void contextMenuEvent( QContextMenuEvent * ) override; 0093 0094 /** 0095 * Getter to the context menu 0096 */ 0097 QMenu * getContextMenu(); 0098 QMenu * getAttackContextMenu(); 0099 QMenu * getMoveContextMenu(); 0100 0101 /** 0102 * Getter to the action of the context menu 0103 */ 0104 QAction* getAttack1Action(); 0105 QAction* getAttack2Action(); 0106 QAction* getAttack3Action(); 0107 QAction* getMove1Action(); 0108 QAction* getMove5Action(); 0109 QAction* getMove10Action(); 0110 0111 void setMenuPoint(QPoint); 0112 0113 void setIcon(); 0114 0115 void setArenaOptionEnabled(bool option); 0116 0117 public slots: 0118 /** 0119 * Slot connected in the game/document object to catch and 0120 * process mouse events. This is a KGame function which 0121 * ends up generating the move for the game. 0122 * @param input is the KGameIO input object 0123 * @param stream is the output command stream 0124 * @param mouse is a mouse event 0125 * @param eatevent is to be set to true if you processed the event 0126 * 0127 */ 0128 void slotMouseInput(KGameIO *input,QDataStream &stream, 0129 QMouseEvent *mouse, bool *eatevent); 0130 0131 void arenaState(); 0132 0133 void slotDetails(); 0134 0135 void attackAuto(); 0136 0137 signals: 0138 /** 0139 * Signal that redirect the mouse event to the kmainwindows in 0140 * order to process the event. 0141 * @param event is the event received 0142 */ 0143 void mouseMoveEventReceived(QMouseEvent * event); 0144 0145 void arenaStateSignal(bool); 0146 0147 protected: 0148 0149 void mouseMoveEvent (QMouseEvent* event) override; 0150 bool viewportEvent (QEvent* event) override; 0151 0152 private: 0153 unsigned int m_mapW; 0154 unsigned int m_mapH; 0155 QWidget* m_parent; 0156 GameLogic::GameAutomaton* m_automaton; 0157 QMenu* menu; 0158 QMenu* attackMenu; 0159 QMenu* moveMenu; 0160 ArenaAction* m_arenaAction; 0161 QAction* AutoAction; 0162 QAction* detailsAction; 0163 QAction* goalAction; 0164 QAction* nextPlayer; 0165 QAction* Attack1Action; 0166 QAction* Attack2Action; 0167 QAction* Attack3Action; 0168 QAction* Move1Action; 0169 QAction* Move5Action; 0170 QAction* Move10Action; 0171 QAction* QuitAction; 0172 QPoint menuPoint; 0173 QPoint detailPoint; 0174 }; 0175 0176 } 0177 0178 #endif // DECORATEDGAMEFRAME_H 0179