1 /* 2 * Copyright 2010-2014 OpenXcom Developers. 3 * 4 * This file is part of OpenXcom. 5 * 6 * OpenXcom is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * OpenXcom is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with OpenXcom. If not, see <http:///www.gnu.org/licenses/>. 18 */ 19 #ifndef OPENXCOM_BATTLESCAPESTATE_H 20 #define OPENXCOM_BATTLESCAPESTATE_H 21 22 #include "../Engine/State.h" 23 #include "Position.h" 24 25 #include <vector> 26 #include <string> 27 28 namespace OpenXcom 29 { 30 31 class Surface; 32 class Map; 33 class ImageButton; 34 class InteractiveSurface; 35 class Text; 36 class Bar; 37 class NumberText; 38 class BattleUnit; 39 class SavedBattleGame; 40 class BattleItem; 41 class Timer; 42 class WarningMessage; 43 class BattlescapeGame; 44 45 /** 46 * Battlescape screen which shows the tactical battle. 47 */ 48 class BattlescapeState : public State 49 { 50 private: 51 Surface *_rank; 52 InteractiveSurface *_icons; 53 Map *_map; 54 InteractiveSurface *_btnUnitUp, *_btnUnitDown, *_btnMapUp, *_btnMapDown, *_btnShowMap, *_btnKneel; 55 InteractiveSurface *_btnInventory, *_btnCenter, *_btnNextSoldier, *_btnNextStop, *_btnShowLayers, *_btnHelp; 56 InteractiveSurface *_btnEndTurn, *_btnAbort, *_btnStats, *_btnLaunch, *_btnPsi; 57 ImageButton *_reserve; 58 ImageButton *_btnReserveNone, *_btnReserveSnap, *_btnReserveAimed, *_btnReserveAuto, *_btnReserveKneel, *_btnZeroTUs; 59 InteractiveSurface *_btnLeftHandItem, *_btnRightHandItem; 60 static const int VISIBLE_MAX = 10; 61 InteractiveSurface *_btnVisibleUnit[VISIBLE_MAX]; 62 NumberText *_numVisibleUnit[VISIBLE_MAX]; 63 BattleUnit *_visibleUnit[VISIBLE_MAX]; 64 WarningMessage *_warning; 65 Text *_txtName; 66 NumberText *_numTimeUnits, *_numEnergy, *_numHealth, *_numMorale, *_numLayers, *_numAmmoLeft, *_numAmmoRight; 67 Bar *_barTimeUnits, *_barEnergy, *_barHealth, *_barMorale; 68 Timer *_animTimer, *_gameTimer; 69 SavedBattleGame *_save; 70 Text *_txtDebug, *_txtTooltip; 71 std::vector<State*> _popups; 72 BattlescapeGame *_battleGame; 73 bool _firstInit; 74 bool _isMouseScrolling, _isMouseScrolled; 75 int _xBeforeMouseScrolling, _yBeforeMouseScrolling; 76 Position _mapOffsetBeforeMouseScrolling; 77 Uint32 _mouseScrollingStartTime; 78 int _totalMouseMoveX, _totalMouseMoveY; 79 bool _mouseMovedOverThreshold; 80 bool _mouseOverIcons; 81 std::string _currentTooltip; 82 Position _cursorPosition; 83 /// Popups a context sensitive list of actions the user can choose from. 84 void handleItemClick(BattleItem *item); 85 /// Shifts the red colors of the visible unit buttons backgrounds. 86 void blinkVisibleUnitButtons(); 87 public: 88 /// Selects the next soldier. 89 void selectNextPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false); 90 /// Selects the previous soldier. 91 void selectPreviousPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false); 92 static const int DEFAULT_ANIM_SPEED = 100; 93 /// Creates the Battlescape state. 94 BattlescapeState(Game *game); 95 /// Cleans up the Battlescape state. 96 ~BattlescapeState(); 97 /// Initilizes the battlescapestate. 98 void init(); 99 /// Runs the timers and handles popups. 100 void think(); 101 /// Handler for moving mouse over the map. 102 void mapOver(Action *action); 103 /// Handler for pressing the map. 104 void mapPress(Action *action); 105 /// Handler for clicking the map. 106 void mapClick(Action *action); 107 /// Handler for entering with mouse to the map surface. 108 void mapIn(Action *action); 109 /// Handler for clicking the Unit Up button. 110 void btnUnitUpClick(Action *action); 111 /// Handler for clicking the Unit Down button. 112 void btnUnitDownClick(Action *action); 113 /// Handler for clicking the Map Up button. 114 void btnMapUpClick(Action *action); 115 /// Handler for clicking the Map Down button. 116 void btnMapDownClick(Action *action); 117 /// Handler for clicking the Show Map button. 118 void btnShowMapClick(Action *action); 119 /// Handler for clicking the Kneel button. 120 void btnKneelClick(Action *action); 121 /// Handler for clicking the Soldier button. 122 void btnInventoryClick(Action *action); 123 /// Handler for clicking the Center button. 124 void btnCenterClick(Action *action); 125 /// Handler for clicking the Next Soldier button. 126 void btnNextSoldierClick(Action *action); 127 /// Handler for clicking the Next Stop button. 128 void btnNextStopClick(Action *action); 129 /// Handler for clicking the Previous Soldier button. 130 void btnPrevSoldierClick(Action *action); 131 /// Handler for clicking the Show Layers button. 132 void btnShowLayersClick(Action *action); 133 /// Handler for clicking the Help button. 134 void btnHelpClick(Action *action); 135 /// Handler for clicking the End Turn button. 136 void btnEndTurnClick(Action *action); 137 /// Handler for clicking the Abort button. 138 void btnAbortClick(Action *action); 139 /// Handler for clicking the stats. 140 void btnStatsClick(Action *action); 141 /// Handler for clicking the left hand item button. 142 void btnLeftHandItemClick(Action *action); 143 /// Handler for clicking the right hand item button. 144 void btnRightHandItemClick(Action *action); 145 /// Handler for clicking a visible unit button. 146 void btnVisibleUnitClick(Action *action); 147 /// Handler for clicking the launch rocket button. 148 void btnLaunchClick(Action *action); 149 /// Handler for clicking the use psi button. 150 void btnPsiClick(Action *action); 151 /// Handler for clicking a reserved button. 152 void btnReserveClick(Action *action); 153 /// Handler for clicking the reload button. 154 void btnReloadClick(Action *action); 155 /// Handler for clicking the lighting button. 156 void btnPersonalLightingClick(Action *action); 157 /// Determines whether a playable unit is selected. 158 bool playableUnitSelected(); 159 /// Updates soldier name/rank/tu/energy/health/morale. 160 void updateSoldierInfo(); 161 /// Animates map objects on the map, also smoke,fire, ... 162 void animate(); 163 /// Handles the battle game state. 164 void handleState(); 165 /// Sets the state timer interval. 166 void setStateInterval(Uint32 interval); 167 /// Gets game. 168 Game *getGame() const; 169 /// Gets map. 170 Map *getMap() const; 171 /// Show debug message. 172 void debug(const std::wstring &message); 173 /// Show warning message. 174 void warning(const std::string &message); 175 /// Handles keypresses. 176 void handle(Action *action); 177 /// Displays a popup window. 178 void popup(State *state); 179 /// Finishes a battle. 180 void finishBattle(bool abort, int inExitArea); 181 /// Show the launch button. 182 void showLaunchButton(bool show); 183 /// Shows the PSI button. 184 void showPsiButton(bool show); 185 /// Clears mouse-scrolling state. 186 void clearMouseScrollingState(); 187 /// Returns a pointer to the battlegame, in case we need its functions. 188 BattlescapeGame *getBattleGame(); 189 /// Saves a map as used by the AI. 190 void saveAIMap(); 191 /// Saves each layer of voxels on the bettlescape as a png. 192 void saveVoxelMap(); 193 /// Saves a first-person voxel view of the battlescape. 194 void saveVoxelView(); 195 /// Handler for the mouse moving over the icons, disables the tile selection cube. 196 void mouseInIcons(Action *action); 197 /// Handler for the mouse going out of the icons, enabling the tile selection cube. 198 void mouseOutIcons(Action *action); 199 /// Checks if the mouse is over the icons. 200 bool getMouseOverIcons() const; 201 /// Is the player allowed to press buttons? 202 bool allowButtons(bool allowSaving = false) const; 203 /// Handler for clicking the reserve TUs to kneel button. 204 void btnReserveKneelClick(Action *action); 205 /// Handler for clicking the expend all TUs button. 206 void btnZeroTUsClick(Action *action); 207 /// Handler for showing tooltip. 208 void txtTooltipIn(Action *action); 209 /// Handler for hiding tooltip. 210 void txtTooltipOut(Action *action); 211 /// Update the resolution settings, we just resized the window. 212 void resize(int &dX, int &dY); 213 /// Move the mouse back to where it started after we finish drag scrolling. 214 void stopScrolling(Action *action); 215 }; 216 217 } 218 219 #endif 220