OpenXcom  1.0
Open-source clone of the original X-Com
State.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <vector>
21 #include <string>
22 #include <SDL.h>
23 #include "../Savegame/Soldier.h"
24 
25 namespace OpenXcom
26 {
27 
28 class Game;
29 class Surface;
30 class InteractiveSurface;
31 class Action;
32 class LocalizedText;
33 class SavedBattleGame;
34 class RuleInterface;
35 
44 class State
45 {
46  friend class Timer;
47 
48 protected:
49  static Game *_game;
50  std::vector<Surface*> _surfaces;
51  bool _screen;
52  InteractiveSurface *_modal;
53  RuleInterface *_ruleInterface;
54  RuleInterface *_ruleInterfaceParent;
55 
56  SDL_Color _palette[256];
57  Uint8 _cursorColor;
58 public:
60  State();
62  virtual ~State();
64  void setInterface(const std::string &s, bool alterPal = false, SavedBattleGame *battleGame = 0);
66  void add(Surface *surface);
68  void add(Surface *surface, const std::string &id, const std::string &category, Surface *parent = 0);
70  bool isScreen() const;
72  void toggleScreen();
74  virtual void init();
76  virtual void handle(Action *action);
78  virtual void think();
80  virtual void blit();
82  void hideAll();
84  void showAll();
86  void resetAll();
88  const LocalizedText &tr(const std::string &id) const;
90  LocalizedText tr(const std::string &id, unsigned n) const;
92  const LocalizedText &tr(const std::string &id, SoldierGender gender) const;
94  void redrawText();
96  void centerAllSurfaces();
98  void lowerAllSurfaces();
100  void applyBattlescapeTheme();
102  static void setGamePtr(Game* game);
104  void setModal(InteractiveSurface *surface);
106  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256, bool immediately = true);
108  void setPalette(const std::string &palette, int backpals = -1);
110  SDL_Color *getPalette();
112  virtual void resize(int &dX, int &dY);
114  virtual void recenter(int dX, int dY);
115 };
116 
117 }
void setModal(InteractiveSurface *surface)
Sets a modal surface.
Definition: State.cpp:455
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
void centerAllSurfaces()
center all surfaces relative to the screen.
Definition: State.cpp:382
virtual void recenter(int dX, int dY)
Re-orients all the surfaces in the state.
Definition: State.cpp:544
State()
Creates a new state linked to a game.
Definition: State.cpp:51
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:35
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
void hideAll()
Hides all the state surfaces.
Definition: State.cpp:312
bool isScreen() const
Gets whether the state is a full-screen.
Definition: State.cpp:217
const LocalizedText & tr(const std::string &id) const
Get the localized text.
Definition: State.cpp:350
virtual void think()
Runs state functionality every cycle.
Definition: State.cpp:271
Definition: RuleInterface.h:35
static Game * _game
Initializes static member.
Definition: State.h:49
void showAll()
Shws all the state surfaces.
Definition: State.cpp:321
A string that is already translated.
Definition: LocalizedText.h:43
void toggleScreen()
Toggles whether the state is a full-screen.
Definition: State.cpp:227
void applyBattlescapeTheme()
switch the colours to use the battlescape palette.
Definition: State.cpp:405
SDL_Color * getPalette()
Gets the state&#39;s 8bpp palette.
Definition: State.cpp:523
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256, bool immediately=true)
Changes a set of colors on the state&#39;s 8bpp palette.
Definition: State.cpp:467
void resetAll()
Resets all the state surfaces.
Definition: State.cpp:331
static void setGamePtr(Game *game)
Sets game object pointer.
Definition: State.cpp:553
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
virtual void init()
Initializes the state.
Definition: State.cpp:240
void setInterface(const std::string &s, bool alterPal=false, SavedBattleGame *battleGame=0)
Set interface rules.
Definition: State.cpp:75
virtual void blit()
Blits the state to the screen.
Definition: State.cpp:303
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
virtual void handle(Action *action)
Handles any events.
Definition: State.cpp:282
The core of the game engine, manages the game&#39;s entire contents and structure.
Definition: Game.h:41
virtual void resize(int &dX, int &dY)
Let the state know the window has been resized.
Definition: State.cpp:534
void lowerAllSurfaces()
lower all surfaces by half the screen height.
Definition: State.cpp:394
void add(Surface *surface)
Adds a child element to the state.
Definition: State.cpp:131
Definition: BaseInfoState.cpp:40
void redrawText()
redraw all the text-type surfaces.
Definition: State.cpp:433
virtual ~State()
Cleans up the state.
Definition: State.cpp:61