OpenXcom
1.0
Open-source clone of the original X-Com
|
A game state that receives user input and reacts accordingly. More...
#include <State.h>
Public Member Functions | |
State (Game *game) | |
Creates a new state linked to a game. More... | |
virtual | ~State () |
Cleans up the state. More... | |
void | add (Surface *surface) |
Adds a child element to the state. More... | |
bool | isScreen () const |
Gets whether the state is a full-screen. More... | |
void | toggleScreen () |
Toggles whether the state is a full-screen. More... | |
virtual void | init () |
Initializes the state. More... | |
virtual void | handle (Action *action) |
Handles any events. More... | |
virtual void | think () |
Runs state functionality every cycle. More... | |
virtual void | blit () |
Blits the state to the screen. More... | |
void | hideAll () |
Hides all the state surfaces. More... | |
void | showAll () |
Shws all the state surfaces. More... | |
void | resetAll () |
Resets all the state surfaces. More... | |
const LocalizedText & | tr (const std::string &id) const |
Get the localized text. More... | |
LocalizedText | tr (const std::string &id, unsigned n) const |
Get the localized text. More... | |
void | redrawText () |
redraw all the text-type surfaces. | |
void | centerAllSurfaces () |
center all surfaces relative to the screen. More... | |
void | lowerAllSurfaces () |
lower all surfaces by half the screen height. More... | |
void | applyBattlescapeTheme () |
switch the colours to use the battlescape palette. More... | |
void | setModal (InteractiveSurface *surface) |
Sets a modal surface. More... | |
void | setPalette (SDL_Color *colors, int firstcolor=0, int ncolors=256, bool immediately=true) |
Changes a set of colors on the state's 8bpp palette. More... | |
void | setPalette (const std::string &palette, int backpals=-1) |
Changes the state's 8bpp palette with certain resources. More... | |
SDL_Color *const | getPalette () |
Gets the state's 8bpp palette. More... | |
virtual void | resize (int &dX, int &dY) |
Let the state know the window has been resized. More... | |
virtual void | recenter (int dX, int dY) |
Re-orients all the surfaces in the state. More... | |
A game state that receives user input and reacts accordingly.
Game states typically represent a whole window or screen that the user interacts with, making the game... well, interactive. They automatically handle child elements used to transmit information from/to the user, and are linked to the core game engine which manages them.
OpenXcom::State::State | ( | Game * | game | ) |
Creates a new state linked to a game.
Initializes a brand new state with no child elements.
By default states are full-screen.
game | Pointer to the core game. |
|
virtual |
Cleans up the state.
Deletes all the child elements contained in the state.
void OpenXcom::State::add | ( | Surface * | surface | ) |
Adds a child element to the state.
Adds a new child surface for the state to take care of, giving it the game's display palette.
Once associated, the state handles all of the surface's behaviour and management automatically.
surface | Child surface. |
void OpenXcom::State::applyBattlescapeTheme | ( | ) |
switch the colours to use the battlescape palette.
switch all the colours to something a little more battlescape appropriate.
|
virtual |
Blits the state to the screen.
Blits all the visible Surface child elements onto the display screen, by order of addition.
Reimplemented in OpenXcom::GeoscapeState, and OpenXcom::TestState.
void OpenXcom::State::centerAllSurfaces | ( | ) |
center all surfaces relative to the screen.
centers all the surfaces on the screen.
SDL_Color *const OpenXcom::State::getPalette | ( | ) |
Gets the state's 8bpp palette.
Returns the state's 8bpp palette.
|
virtual |
Handles any events.
Takes care of any events from the core game engine, and passes them on to its InteractiveSurface child elements.
action | Pointer to an action. |
Reimplemented in OpenXcom::BattlescapeState, OpenXcom::OptionsVideoState, OpenXcom::InventoryState, OpenXcom::UnitInfoState, OpenXcom::GeoscapeState, OpenXcom::BuildNewBaseState, OpenXcom::StartState, OpenXcom::MedikitState, OpenXcom::MiniMapState, OpenXcom::SelectDestinationState, OpenXcom::PrimeGrenadeState, OpenXcom::NextTurnState, OpenXcom::ScannerState, OpenXcom::ActionMenuState, and OpenXcom::InfoboxState.
void OpenXcom::State::hideAll | ( | ) |
Hides all the state surfaces.
Hides all the Surface child elements on display.
|
virtual |
Initializes the state.
Initializes the state and its child elements.
This is used for settings that have to be reset every time the state is returned to focus (eg. palettes), so can't just be put in the constructor (remember there's a stack of states, so they can be created once while being repeatedly switched back into focus).
Reimplemented in OpenXcom::BattlescapeState, OpenXcom::UnitInfoState, OpenXcom::BaseInfoState, OpenXcom::GeoscapeState, OpenXcom::ListGamesState, OpenXcom::SoldierInfoState, OpenXcom::CraftInfoState, OpenXcom::NewBattleState, OpenXcom::OptionsBaseState, OpenXcom::CraftEquipmentState, OpenXcom::ResearchState, OpenXcom::BuildNewBaseState, OpenXcom::BuildFacilitiesState, OpenXcom::StartState, OpenXcom::NewResearchListState, OpenXcom::MultipleTargetsState, OpenXcom::BasescapeState, OpenXcom::CraftSoldiersState, OpenXcom::InventoryState, OpenXcom::ManufactureState, OpenXcom::SelectDestinationState, OpenXcom::OptionsControlsState, OpenXcom::CraftArmorState, OpenXcom::OptionsAdvancedState, OpenXcom::SaveGameState, OpenXcom::CraftsState, OpenXcom::NewManufactureListState, OpenXcom::SoldiersState, OpenXcom::LoadGameState, OpenXcom::ConfirmLandingState, and OpenXcom::IntroState.
bool OpenXcom::State::isScreen | ( | ) | const |
Gets whether the state is a full-screen.
Returns whether this is a full-screen state.
This is used to optimize the state machine since full-screen states automatically cover the whole screen, (whether they actually use it all or not) so states behind them can be safely ignored since they'd be covered up.
void OpenXcom::State::lowerAllSurfaces | ( | ) |
lower all surfaces by half the screen height.
drop all the surfaces by half the screen height
|
virtual |
Re-orients all the surfaces in the state.
dX | delta of X; |
dY | delta of Y; |
void OpenXcom::State::resetAll | ( | ) |
Resets all the state surfaces.
Resets the status of all the Surface child elements, like unpressing buttons.
|
virtual |
Let the state know the window has been resized.
Each state will probably need its own resize handling, so this space intentionally left blank.
dX | delta of X; |
dY | delta of Y; |
Reimplemented in OpenXcom::BattlescapeState, OpenXcom::GeoscapeState, OpenXcom::BuildNewBaseState, OpenXcom::SelectDestinationState, OpenXcom::OptionsVideoState, OpenXcom::OptionsBaseState, OpenXcom::MainMenuState, and OpenXcom::ActionMenuState.
void OpenXcom::State::setModal | ( | InteractiveSurface * | surface | ) |
Sets a modal surface.
Changes the current modal surface.
If a surface is modal, then only that surface can receive events. This is used when an element needs to take priority over everything else, eg. focus.
surface | Pointer to modal surface, NULL for no modal. |
void OpenXcom::State::setPalette | ( | SDL_Color * | colors, |
int | firstcolor = 0 , |
||
int | ncolors = 256 , |
||
bool | immediately = true |
||
) |
Changes a set of colors on the state's 8bpp palette.
Replaces a certain amount of colors in the state's palette.
colors | Pointer to the set of colors. |
firstcolor | Offset of the first color to replace. |
ncolors | Amount of colors to replace. |
immediately | Apply changes immediately, otherwise wait in case of multiple setPalettes. |
void OpenXcom::State::setPalette | ( | const std::string & | palette, |
int | backpals = -1 |
||
) |
Changes the state's 8bpp palette with certain resources.
Loads palettes from the game resources into the state.
palette | String ID of the palette to load. |
backpals | BACKPALS.DAT offset to use. |
void OpenXcom::State::showAll | ( | ) |
Shws all the state surfaces.
Shows all the hidden Surface child elements.
|
virtual |
Runs state functionality every cycle.
Runs any code the state needs to keep updating every game cycle, like timers and other real-time elements.
Reimplemented in OpenXcom::BattlescapeState, OpenXcom::ResearchInfoState, OpenXcom::SellState, OpenXcom::TransferItemsState, OpenXcom::DogfightState, OpenXcom::SellState, OpenXcom::GeoscapeState, OpenXcom::PurchaseState, OpenXcom::ManageAlienContainmentState, OpenXcom::PurchaseState, OpenXcom::TestState, OpenXcom::CraftEquipmentState, OpenXcom::BuildNewBaseState, OpenXcom::MiniMapState, OpenXcom::BaseDefenseState, OpenXcom::StartState, OpenXcom::SelectDestinationState, OpenXcom::NextTurnState, OpenXcom::ScannerState, OpenXcom::OptionsConfirmState, OpenXcom::InfoboxState, OpenXcom::DefeatState, and OpenXcom::VictoryState.
void OpenXcom::State::toggleScreen | ( | ) |
Toggles whether the state is a full-screen.
Toggles the full-screen flag.
Used by windows to keep the previous screen in display while the window is still "popping up".
const LocalizedText & OpenXcom::State::tr | ( | const std::string & | id | ) | const |
Get the localized text.
Get the localized text for dictionary key id.
This function forwards the call to Language::getString(const std::string &).
id | The dictionary key to search for. |
LocalizedText OpenXcom::State::tr | ( | const std::string & | id, |
unsigned | n | ||
) | const |
Get the localized text.
Get a modifiable copy of the localized text for dictionary key id.
This function forwards the call to Language::getString(const std::string &, unsigned).
id | The dictionary key to search for. |
n | The number to use for the proper version. |