OpenXcom  1.0
Open-source clone of the original X-Com
Public Member Functions | Static Public Member Functions | Static Protected Attributes | 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::AllocatePsiTrainingState OpenXcom::ArticleState OpenXcom::BaseDefenseState OpenXcom::BaseDestroyedState OpenXcom::BaseInfoState OpenXcom::BaseNameState OpenXcom::BasescapeState OpenXcom::BattlescapeState OpenXcom::BriefingState OpenXcom::BuildFacilitiesState OpenXcom::BuildNewBaseState OpenXcom::CannotReequipState OpenXcom::CommendationLateState OpenXcom::CommendationState 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::CutsceneState OpenXcom::DebriefingState OpenXcom::DeleteGameState OpenXcom::DismantleFacilityState OpenXcom::DogfightErrorState OpenXcom::DogfightState OpenXcom::ErrorMessageState OpenXcom::FundingState OpenXcom::GeoscapeCraftState OpenXcom::GeoscapeState OpenXcom::GoToMainMenuState OpenXcom::GraphsState OpenXcom::InfoboxOKState OpenXcom::InfoboxState OpenXcom::InterceptState OpenXcom::InventoryState OpenXcom::ItemsArrivingState OpenXcom::ListGamesState OpenXcom::ListLoadOriginalState OpenXcom::LoadGameState OpenXcom::LowFuelState OpenXcom::MainMenuState OpenXcom::ManageAlienContainmentState OpenXcom::ManufactureInfoState OpenXcom::ManufactureStartState OpenXcom::ManufactureState OpenXcom::MedikitState OpenXcom::MiniMapState OpenXcom::MissionDetectedState OpenXcom::MonthlyCostsState OpenXcom::MonthlyReportState OpenXcom::MultipleTargetsState OpenXcom::NewBattleState OpenXcom::NewGameState OpenXcom::NewManufactureListState OpenXcom::NewPossibleManufactureState OpenXcom::NewPossibleResearchState OpenXcom::NewResearchListState OpenXcom::NextTurnState OpenXcom::OptionsBaseState OpenXcom::OptionsConfirmState OpenXcom::OptionsDefaultsState OpenXcom::OptionsInformExtendedState OpenXcom::PauseState OpenXcom::PlaceFacilityState OpenXcom::PlaceLiftState OpenXcom::PrimeGrenadeState OpenXcom::ProductionCompleteState OpenXcom::PromotionsState OpenXcom::PsiTrainingState OpenXcom::PurchaseState OpenXcom::ResearchCompleteState OpenXcom::ResearchInfoState OpenXcom::ResearchRequiredState OpenXcom::ResearchState OpenXcom::SackSoldierState OpenXcom::SaveGameState OpenXcom::ScannerState OpenXcom::SelectDestinationState OpenXcom::SellState OpenXcom::SetWindowedRootState OpenXcom::SlideshowState OpenXcom::SoldierArmorState OpenXcom::SoldierDiaryMissionState OpenXcom::SoldierDiaryOverviewState OpenXcom::SoldierDiaryPerformanceState OpenXcom::SoldierInfoState OpenXcom::SoldierMemorialState OpenXcom::SoldiersState OpenXcom::StartState OpenXcom::StatisticsState 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::VideoState

Public Member Functions

 State ()
 Creates a new state linked to a game. More...
 
virtual ~State ()
 Cleans up the state. More...
 
void setInterface (const std::string &s, bool alterPal=false, SavedBattleGame *battleGame=0)
 Set interface rules. More...
 
void add (Surface *surface)
 Adds a child element to the state. More...
 
void add (Surface *surface, const std::string &id, const std::string &category, Surface *parent=0)
 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...
 
const LocalizedTexttr (const std::string &id, SoldierGender gender) 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 * 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...
 

Static Public Member Functions

static void setGamePtr (Game *game)
 Sets game object pointer.
 

Static Protected Attributes

static Game_game = 0
 Initializes static member.
 

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

◆ State()

OpenXcom::State::State ( )

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.

◆ ~State()

OpenXcom::State::~State ( )
virtual

Cleans up the state.

Deletes all the child elements contained in the state.

Member Function Documentation

◆ add() [1/2]

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.

◆ add() [2/2]

void OpenXcom::State::add ( Surface surface,
const std::string &  id,
const std::string &  category,
Surface parent = 0 
)

Adds a child element to the state.

As above, except this adds a surface based on an interface element defined in the ruleset.

Note
that this function REQUIRES the ruleset to have been loaded prior to use.
Parameters
surfaceChild surface.
idthe ID of the element defined in the ruleset, if any.
categorythe category of elements this interface is associated with.
parentthe surface to base the coordinates of this element off.
Note
if no parent is defined the element will not be moved.

◆ applyBattlescapeTheme()

void OpenXcom::State::applyBattlescapeTheme ( )

switch the colours to use the battlescape palette.

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

◆ blit()

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.

◆ centerAllSurfaces()

void OpenXcom::State::centerAllSurfaces ( )

center all surfaces relative to the screen.

centers all the surfaces on the screen.

◆ getPalette()

SDL_Color * OpenXcom::State::getPalette ( )

Gets the state's 8bpp palette.

Returns the state's 8bpp palette.

Returns
Pointer to the palette's colors.

◆ handle()

void OpenXcom::State::handle ( Action action)
virtual

◆ hideAll()

void OpenXcom::State::hideAll ( )

Hides all the state surfaces.

Hides all the Surface child elements on display.

◆ init()

void OpenXcom::State::init ( )
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::DebriefingState, OpenXcom::BattlescapeState, OpenXcom::SoldierDiaryPerformanceState, OpenXcom::UnitInfoState, OpenXcom::GeoscapeState, OpenXcom::BaseInfoState, OpenXcom::CraftSoldiersState, OpenXcom::SoldierInfoState, OpenXcom::InventoryState, OpenXcom::CraftEquipmentState, OpenXcom::MonthlyReportState, OpenXcom::ListGamesState, OpenXcom::OptionsBaseState, OpenXcom::CraftInfoState, OpenXcom::SoldierDiaryOverviewState, OpenXcom::NewBattleState, OpenXcom::ResearchState, OpenXcom::BuildNewBaseState, OpenXcom::BuildFacilitiesState, OpenXcom::StartState, OpenXcom::SoldierDiaryMissionState, OpenXcom::NewManufactureListState, OpenXcom::NewResearchListState, OpenXcom::MultipleTargetsState, OpenXcom::BasescapeState, OpenXcom::ListLoadOriginalState, OpenXcom::ManufactureState, OpenXcom::SelectDestinationState, OpenXcom::LoadGameState, OpenXcom::OptionsControlsState, OpenXcom::CraftArmorState, OpenXcom::ConfirmLandingState, OpenXcom::CraftsState, OpenXcom::SoldiersState, OpenXcom::BriefingState, OpenXcom::OptionsAdvancedState, OpenXcom::UfopaediaSelectState, OpenXcom::CutsceneState, OpenXcom::VideoState, and OpenXcom::GoToMainMenuState.

◆ isScreen()

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.

◆ lowerAllSurfaces()

void OpenXcom::State::lowerAllSurfaces ( )

lower all surfaces by half the screen height.

drop all the surfaces by half the screen height

◆ recenter()

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

Re-orients all the surfaces in the state.

Parameters
dXdelta of X;
dYdelta of Y;

◆ resetAll()

void OpenXcom::State::resetAll ( )

Resets all the state surfaces.

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

◆ resize()

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::OptionsVideoState, OpenXcom::SelectDestinationState, OpenXcom::OptionsBaseState, OpenXcom::MainMenuState, OpenXcom::NextTurnState, and OpenXcom::ActionMenuState.

◆ setInterface()

void OpenXcom::State::setInterface ( const std::string &  category,
bool  alterPal = false,
SavedBattleGame battleGame = 0 
)

Set interface rules.

Set interface data from the ruleset, also sets the palette for the state.

Parameters
categoryName of the interface set.
alterPalShould we swap out the backpal colors?
battleGameShould we use battlescape palette? (this only applies to options screens)

◆ setModal()

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.

◆ setPalette() [1/2]

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.

◆ setPalette() [2/2]

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.

◆ showAll()

void OpenXcom::State::showAll ( )

Shws all the state surfaces.

Shows all the hidden Surface child elements.

◆ think()

void OpenXcom::State::think ( )
virtual

◆ toggleScreen()

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".

◆ tr() [1/3]

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.

◆ tr() [2/3]

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.

◆ tr() [3/3]

const LocalizedText & OpenXcom::State::tr ( const std::string &  id,
SoldierGender  gender 
) 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 &, SoldierGender).

Parameters
idThe dictionary key to search for.
genderCurrent soldier gender.
Returns
A reference to the localized text.

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