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 
24 namespace OpenXcom
25 {
26 
27 class Game;
28 class Surface;
29 class InteractiveSurface;
30 class Action;
31 class LocalizedText;
32 class SavedBattleGame;
33 class RuleInterface;
34 
43 class State
44 {
45  friend class Timer;
46 
47 protected:
48  static Game *_game;
49  std::vector<Surface*> _surfaces;
50  bool _screen;
51  InteractiveSurface *_modal;
52  RuleInterface *_ruleInterface;
53  RuleInterface *_ruleInterfaceParent;
54 
55  SDL_Color _palette[256];
56  Uint8 _cursorColor;
57 public:
59  State();
61  virtual ~State();
63  void setInterface(const std::string &s, bool alterPal = false, SavedBattleGame *battleGame = 0);
65  void add(Surface *surface);
67  void add(Surface *surface, const std::string &id, const std::string &category, Surface *parent = 0);
69  bool isScreen() const;
71  void toggleScreen();
73  virtual void init();
75  virtual void handle(Action *action);
77  virtual void think();
79  virtual void blit();
81  void hideAll();
83  void showAll();
85  void resetAll();
87  const LocalizedText &tr(const std::string &id) const;
89  LocalizedText tr(const std::string &id, unsigned n) const;
91  void redrawText();
93  void centerAllSurfaces();
95  void lowerAllSurfaces();
97  void applyBattlescapeTheme();
99  static void setGamePtr(Game* game);
101  void setModal(InteractiveSurface *surface);
103  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256, bool immediately = true);
105  void setPalette(const std::string &palette, int backpals = -1);
107  SDL_Color *getPalette();
109  virtual void resize(int &dX, int &dY);
111  virtual void recenter(int dX, int dY);
112 };
113 
114 }
void setModal(InteractiveSurface *surface)
Sets a modal surface.
Definition: State.cpp:445
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:372
virtual void recenter(int dX, int dY)
Re-orients all the surfaces in the state.
Definition: State.cpp:534
State()
Creates a new state linked to a game.
Definition: State.cpp:53
A game state that receives user input and reacts accordingly.
Definition: State.h:43
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:314
bool isScreen() const
Gets whether the state is a full-screen.
Definition: State.cpp:219
const LocalizedText & tr(const std::string &id) const
Get the localized text.
Definition: State.cpp:352
virtual void think()
Runs state functionality every cycle.
Definition: State.cpp:273
Definition: RuleInterface.h:35
static Game * _game
Initializes static member.
Definition: State.h:48
void showAll()
Shws all the state surfaces.
Definition: State.cpp:323
A string that is already translated.
Definition: LocalizedText.h:43
void toggleScreen()
Toggles whether the state is a full-screen.
Definition: State.cpp:229
void applyBattlescapeTheme()
switch the colours to use the battlescape palette.
Definition: State.cpp:395
SDL_Color * getPalette()
Gets the state&#39;s 8bpp palette.
Definition: State.cpp:513
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:457
void resetAll()
Resets all the state surfaces.
Definition: State.cpp:333
static void setGamePtr(Game *game)
Sets game object pointer.
Definition: State.cpp:543
Element that is blit (rendered) onto the screen.
Definition: Surface.h:36
virtual void init()
Initializes the state.
Definition: State.cpp:242
void setInterface(const std::string &s, bool alterPal=false, SavedBattleGame *battleGame=0)
Set interface rules.
Definition: State.cpp:77
virtual void blit()
Blits the state to the screen.
Definition: State.cpp:305
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:284
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:524
void lowerAllSurfaces()
lower all surfaces by half the screen height.
Definition: State.cpp:384
void add(Surface *surface)
Adds a child element to the state.
Definition: State.cpp:133
Definition: BaseInfoState.cpp:40
void redrawText()
redraw all the text-type surfaces.
Definition: State.cpp:423
virtual ~State()
Cleans up the state.
Definition: State.cpp:63