OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::State Class Reference

A game state that receives user input and reacts accordingly. More...

#include <State.h>

Inheritance diagram for OpenXcom::State:
OpenXcom::AbandonGameState OpenXcom::AbortMissionState OpenXcom::ActionMenuState OpenXcom::AlienBaseState OpenXcom::AliensCrashState OpenXcom::AlienTerrorState OpenXcom::AllocatePsiTrainingState OpenXcom::ArticleState OpenXcom::BaseDefenseState OpenXcom::BaseDestroyedState OpenXcom::BaseInfoState OpenXcom::BaseNameState OpenXcom::BasescapeState OpenXcom::BattlescapeState OpenXcom::BriefingState OpenXcom::BuildFacilitiesState OpenXcom::BuildNewBaseState OpenXcom::CannotReequipState OpenXcom::ConfirmCydoniaState OpenXcom::ConfirmDestinationState OpenXcom::ConfirmLandingState OpenXcom::ConfirmLoadState OpenXcom::ConfirmNewBaseState OpenXcom::CraftArmorState OpenXcom::CraftEquipmentState OpenXcom::CraftErrorState OpenXcom::CraftInfoState OpenXcom::CraftPatrolState OpenXcom::CraftSoldiersState OpenXcom::CraftsState OpenXcom::CraftWeaponsState OpenXcom::DebriefingState OpenXcom::DefeatState OpenXcom::DeleteGameState OpenXcom::DismantleFacilityState OpenXcom::DogfightState OpenXcom::ErrorMessageState OpenXcom::FundingState OpenXcom::GeoscapeCraftState OpenXcom::GeoscapeState OpenXcom::GraphsState OpenXcom::InfoboxOKState OpenXcom::InfoboxState OpenXcom::InterceptState OpenXcom::IntroState OpenXcom::InventoryState OpenXcom::ItemsArrivingState OpenXcom::ListGamesState OpenXcom::LoadGameState OpenXcom::LowFuelState OpenXcom::MainMenuState OpenXcom::ManageAlienContainmentState OpenXcom::ManufactureInfoState OpenXcom::ManufactureStartState OpenXcom::ManufactureState OpenXcom::MedikitState OpenXcom::MiniMapState OpenXcom::MonthlyCostsState OpenXcom::MonthlyReportState OpenXcom::MultipleTargetsState OpenXcom::NewBattleState OpenXcom::NewGameState OpenXcom::NewManufactureListState OpenXcom::NewPossibleManufactureState OpenXcom::NewPossibleResearchState OpenXcom::NewResearchListState OpenXcom::NextTurnState OpenXcom::NoContainmentState OpenXcom::OptionsBaseState OpenXcom::OptionsConfirmState OpenXcom::OptionsDefaultsState OpenXcom::PauseState OpenXcom::PlaceFacilityState OpenXcom::PlaceLiftState OpenXcom::PrimeGrenadeState OpenXcom::ProductionCompleteState OpenXcom::PromotionsState OpenXcom::PsiTrainingState OpenXcom::PurchaseState OpenXcom::PurchaseState OpenXcom::ResearchCompleteState OpenXcom::ResearchInfoState OpenXcom::ResearchRequiredState OpenXcom::ResearchState OpenXcom::SackSoldierState OpenXcom::SaveGameState OpenXcom::ScannerState OpenXcom::SelectDestinationState OpenXcom::SellState OpenXcom::SellState OpenXcom::SoldierArmorState OpenXcom::SoldierInfoState OpenXcom::SoldierMemorialState OpenXcom::SoldiersState OpenXcom::StartState OpenXcom::StoresState OpenXcom::TargetInfoState OpenXcom::TestState OpenXcom::TransferBaseState OpenXcom::TransferConfirmState OpenXcom::TransferItemsState OpenXcom::TransfersState OpenXcom::UfoDetectedState OpenXcom::UfoLostState OpenXcom::UfopaediaSelectState OpenXcom::UfopaediaStartState OpenXcom::UnitInfoState OpenXcom::VictoryState

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 LocalizedTexttr (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
gamePointer to the core game.
OpenXcom::State::~State ( )
virtual

Cleans up the state.

Deletes all the child elements contained in the state.

Member Function Documentation

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.

Parameters
surfaceChild surface.
Note
Since visible elements can overlap one another, they have to be added in ascending Z-Order to be blitted correctly onto the screen.
void OpenXcom::State::applyBattlescapeTheme ( )

switch the colours to use the battlescape palette.

switch all the colours to something a little more battlescape appropriate.

void OpenXcom::State::blit ( )
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.

Returns
Pointer to the palette's colors.
void OpenXcom::State::handle ( Action action)
virtual
void OpenXcom::State::hideAll ( )

Hides all the state surfaces.

Hides all the Surface child elements on display.

void OpenXcom::State::init ( )
virtual
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.

Returns
True if it's a screen, False otherwise.
void OpenXcom::State::lowerAllSurfaces ( )

lower all surfaces by half the screen height.

drop all the surfaces by half the screen height

void OpenXcom::State::recenter ( int  dX,
int  dY 
)
virtual

Re-orients all the surfaces in the state.

Parameters
dXdelta of X;
dYdelta of Y;
void OpenXcom::State::resetAll ( )

Resets all the state surfaces.

Resets the status of all the Surface child elements, like unpressing buttons.

void OpenXcom::State::resize ( int &  dX,
int &  dY 
)
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.

Parameters
dXdelta of X;
dYdelta 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.

Parameters
surfacePointer 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.

Parameters
colorsPointer to the set of colors.
firstcolorOffset of the first color to replace.
ncolorsAmount of colors to replace.
immediatelyApply 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.

Parameters
paletteString ID of the palette to load.
backpalsBACKPALS.DAT offset to use.
void OpenXcom::State::showAll ( )

Shws all the state surfaces.

Shows all the hidden Surface child elements.

void OpenXcom::State::think ( )
virtual
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 &).

Parameters
idThe dictionary key to search for.
Returns
A reference to the localized text.
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).

Parameters
idThe dictionary key to search for.
nThe number to use for the proper version.
Returns
A copy of the localized text.

The documentation for this class was generated from the following files: