OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BattlescapeState.h
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 
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;
84  void handleItemClick(BattleItem *item);
86  void blinkVisibleUnitButtons();
87 public:
89  void selectNextPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
91  void selectPreviousPlayerUnit(bool checkReselect = false, bool setReselect = false, bool checkInventory = false);
92  static const int DEFAULT_ANIM_SPEED = 100;
94  BattlescapeState(Game *game);
98  void init();
100  void think();
102  void mapOver(Action *action);
104  void mapPress(Action *action);
106  void mapClick(Action *action);
108  void mapIn(Action *action);
110  void btnUnitUpClick(Action *action);
112  void btnUnitDownClick(Action *action);
114  void btnMapUpClick(Action *action);
116  void btnMapDownClick(Action *action);
118  void btnShowMapClick(Action *action);
120  void btnKneelClick(Action *action);
122  void btnInventoryClick(Action *action);
124  void btnCenterClick(Action *action);
126  void btnNextSoldierClick(Action *action);
128  void btnNextStopClick(Action *action);
130  void btnPrevSoldierClick(Action *action);
132  void btnShowLayersClick(Action *action);
134  void btnHelpClick(Action *action);
136  void btnEndTurnClick(Action *action);
138  void btnAbortClick(Action *action);
140  void btnStatsClick(Action *action);
142  void btnLeftHandItemClick(Action *action);
144  void btnRightHandItemClick(Action *action);
146  void btnVisibleUnitClick(Action *action);
148  void btnLaunchClick(Action *action);
150  void btnPsiClick(Action *action);
152  void btnReserveClick(Action *action);
154  void btnReloadClick(Action *action);
156  void btnPersonalLightingClick(Action *action);
158  bool playableUnitSelected();
160  void updateSoldierInfo();
162  void animate();
164  void handleState();
166  void setStateInterval(Uint32 interval);
168  Game *getGame() const;
170  Map *getMap() const;
172  void debug(const std::wstring &message);
174  void warning(const std::string &message);
176  void handle(Action *action);
178  void popup(State *state);
180  void finishBattle(bool abort, int inExitArea);
182  void showLaunchButton(bool show);
184  void showPsiButton(bool show);
190  void saveAIMap();
192  void saveVoxelMap();
194  void saveVoxelView();
196  void mouseInIcons(Action *action);
198  void mouseOutIcons(Action *action);
200  bool getMouseOverIcons() const;
202  bool allowButtons(bool allowSaving = false) const;
204  void btnReserveKneelClick(Action *action);
206  void btnZeroTUsClick(Action *action);
208  void txtTooltipIn(Action *action);
210  void txtTooltipOut(Action *action);
212  void resize(int &dX, int &dY);
214  void stopScrolling(Action *action);
215 };
216 
217 }
218 
219 #endif
void stopScrolling(Action *action)
Move the mouse back to where it started after we finish drag scrolling.
Definition: BattlescapeState.cpp:2156
void btnHelpClick(Action *action)
Handler for clicking the Help button.
Definition: BattlescapeState.cpp:1007
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
void btnInventoryClick(Action *action)
Handler for clicking the Soldier button.
Definition: BattlescapeState.cpp:884
void btnNextSoldierClick(Action *action)
Handler for clicking the Next Soldier button.
Definition: BattlescapeState.cpp:929
void mouseOutIcons(Action *action)
Handler for the mouse going out of the icons, enabling the tile selection cube.
Definition: BattlescapeState.cpp:1996
void debug(const std::wstring &message)
Show debug message.
Definition: BattlescapeState.cpp:1437
void btnReserveClick(Action *action)
Handler for clicking a reserved button.
Definition: BattlescapeState.cpp:1175
BattlescapeGame * getBattleGame()
Returns a pointer to the battlegame, in case we need its functions.
Definition: BattlescapeState.cpp:1978
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Timer used to run code in fixed intervals.
Definition: Timer.h:37
void saveVoxelMap()
Saves each layer of voxels on the bettlescape as a png.
Definition: BattlescapeState.cpp:1806
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
void btnMapUpClick(Action *action)
Handler for clicking the Map Up button.
Definition: BattlescapeState.cpp:828
void saveVoxelView()
Saves a first-person voxel view of the battlescape.
Definition: BattlescapeState.cpp:1678
void handle(Action *action)
Handles keypresses.
Definition: BattlescapeState.cpp:1458
void think()
Runs the timers and handles popups.
Definition: BattlescapeState.cpp:551
void selectPreviousPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the previous soldier.
Definition: BattlescapeState.cpp:981
void mapClick(Action *action)
Handler for clicking the map.
Definition: BattlescapeState.cpp:706
Text string displayed on screen.
Definition: Text.h:41
Bar graphic that represents a certain value.
Definition: Bar.h:33
void txtTooltipIn(Action *action)
Handler for showing tooltip.
Definition: BattlescapeState.cpp:2077
void mapIn(Action *action)
Handler for entering with mouse to the map surface.
Definition: BattlescapeState.cpp:792
void btnLeftHandItemClick(Action *action)
Handler for clicking the left hand item button.
Definition: BattlescapeState.cpp:1076
void mapPress(Action *action)
Handler for pressing the map.
Definition: BattlescapeState.cpp:677
Map * getMap() const
Gets map.
Definition: BattlescapeState.cpp:1428
void btnRightHandItemClick(Action *action)
Handler for clicking the right hand item button.
Definition: BattlescapeState.cpp:1103
void btnAbortClick(Action *action)
Handler for clicking the Abort button.
Definition: BattlescapeState.cpp:1030
void setStateInterval(Uint32 interval)
Sets the state timer interval.
Definition: BattlescapeState.cpp:1410
void btnLaunchClick(Action *action)
Handler for clicking the launch rocket button.
Definition: BattlescapeState.cpp:1155
void init()
Initilizes the battlescapestate.
Definition: BattlescapeState.cpp:506
void finishBattle(bool abort, int inExitArea)
Finishes a battle.
Definition: BattlescapeState.cpp:1889
void btnReloadClick(Action *action)
Handler for clicking the reload button.
Definition: BattlescapeState.cpp:1207
bool playableUnitSelected()
Determines whether a playable unit is selected.
Definition: BattlescapeState.cpp:1231
Regular image that works like a button.
Definition: ImageButton.h:34
void clearMouseScrollingState()
Clears mouse-scrolling state.
Definition: BattlescapeState.cpp:1970
void btnShowMapClick(Action *action)
Handler for clicking the Show Map button.
Definition: BattlescapeState.cpp:848
Represents a single item in the battlescape.
Definition: BattleItem.h:39
void btnShowLayersClick(Action *action)
Handler for clicking the Show Layers button.
Definition: BattlescapeState.cpp:998
Interactive map of the battlescape.
Definition: Map.h:46
void warning(const std::string &message)
Show warning message.
Definition: BattlescapeState.cpp:1449
void resize(int &dX, int &dY)
Update the resolution settings, we just resized the window.
Definition: BattlescapeState.cpp:2106
void mapOver(Action *action)
Handler for moving mouse over the map.
Definition: BattlescapeState.cpp:584
void btnKneelClick(Action *action)
Handler for clicking the Kneel button.
Definition: BattlescapeState.cpp:859
void saveAIMap()
Saves a map as used by the AI.
Definition: BattlescapeState.cpp:1550
void btnNextStopClick(Action *action)
Handler for clicking the Next Stop button.
Definition: BattlescapeState.cpp:939
void showPsiButton(bool show)
Shows the PSI button.
Definition: BattlescapeState.cpp:1962
void btnEndTurnClick(Action *action)
Handler for clicking the End Turn button.
Definition: BattlescapeState.cpp:1018
void btnUnitDownClick(Action *action)
Handler for clicking the Unit Down button.
Definition: BattlescapeState.cpp:815
Coloured box with text inside that fades out after it is displayed.
Definition: WarningMessage.h:35
void popup(State *state)
Displays a popup window.
Definition: BattlescapeState.cpp:1878
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void updateSoldierInfo()
Updates soldier name/rank/tu/energy/health/morale.
Definition: BattlescapeState.cpp:1239
~BattlescapeState()
Cleans up the Battlescape state.
Definition: BattlescapeState.cpp:496
void animate()
Animates map objects on the map, also smoke,fire, ...
Definition: BattlescapeState.cpp:1391
void btnUnitUpClick(Action *action)
Handler for clicking the Unit Up button.
Definition: BattlescapeState.cpp:802
void btnPersonalLightingClick(Action *action)
Handler for clicking the lighting button.
Definition: BattlescapeState.cpp:1220
void mouseInIcons(Action *action)
Handler for the mouse moving over the icons, disables the tile selection cube.
Definition: BattlescapeState.cpp:1987
void btnPrevSoldierClick(Action *action)
Handler for clicking the Previous Soldier button.
Definition: BattlescapeState.cpp:949
void btnVisibleUnitClick(Action *action)
Handler for clicking a visible unit button.
Definition: BattlescapeState.cpp:1130
bool allowButtons(bool allowSaving=false) const
Is the player allowed to press buttons?
Definition: BattlescapeState.cpp:2019
Battlescape game - the core game engine of the battlescape game.
Definition: BattlescapeGame.h:70
void selectNextPlayerUnit(bool checkReselect=false, bool setReselect=false, bool checkInventory=false)
Selects the next soldier.
Definition: BattlescapeState.cpp:961
void showLaunchButton(bool show)
Show the launch button.
Definition: BattlescapeState.cpp:1953
bool getMouseOverIcons() const
Checks if the mouse is over the icons.
Definition: BattlescapeState.cpp:2005
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
void txtTooltipOut(Action *action)
Handler for hiding tooltip.
Definition: BattlescapeState.cpp:2090
void btnReserveKneelClick(Action *action)
Handler for clicking the reserve TUs to kneel button.
Definition: BattlescapeState.cpp:2030
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:44
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
Game * getGame() const
Gets game.
Definition: BattlescapeState.cpp:1419
Number digits displayed on the screen.
Definition: NumberText.h:31
Battlescape screen which shows the tactical battle.
Definition: BattlescapeState.h:48
void btnMapDownClick(Action *action)
Handler for clicking the Map Down button.
Definition: BattlescapeState.cpp:838
void btnZeroTUsClick(Action *action)
Handler for clicking the expend all TUs button.
Definition: BattlescapeState.cpp:2056
void handleState()
Handles the battle game state.
Definition: BattlescapeState.cpp:1401
void btnPsiClick(Action *action)
Handler for clicking the use psi button.
Definition: BattlescapeState.cpp:1165
BattlescapeState(Game *game)
Creates the Battlescape state.
Definition: BattlescapeState.cpp:95
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
void btnStatsClick(Action *action)
Handler for clicking the stats.
Definition: BattlescapeState.cpp:1040
void btnCenterClick(Action *action)
Handler for clicking the Center button.
Definition: BattlescapeState.cpp:917