Cavestory Mod API
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
BaseModeInstance Class Referenceabstract

Easy UI management. More...

#include <CSMAPI_BaseModeInstance.h>

Inheritance diagram for BaseModeInstance:
MessageBoxMode

Classes

class  GLOBAL_CONFIG_STRUCT
 Holds all global config variables for BaseModeInstance. More...
 
struct  ModeConfiguration
 Configuration class for BaseModeInstance. More...
 
struct  ModeInput
 Used for handling input. More...
 

Public Types

typedef void(* ModeCallback_OnEnd) (BaseModeInstance *pMode, const int &iResult, bool &bDelete)
 Callback function for when a mode ends.
 

Public Member Functions

 BaseModeInstance ()
 Initialize certain values.
 
ModeThreadId StartAsyncOperation (ModeThreadInstance::ModeCallback_OnThreadLoop pOnLoopFunc, ModeThreadInstance::ModeCallback_OnThreadComplete pOnCompleteFunc=NULL, void *pUserData=NULL)
 Begin a thread-safe asynchronous operation. More...
 
bool StopThread (ModeThreadId iThreadId, bool bWaitForFinish=false)
 Stop a thread. More...
 
void StartAllNewThreads ()
 Start all new threads.
 
void FreeAllThreads ()
 Stop & wait for all threads to finish.
 
void EnforceBasicWindowSize (GUI_RECT *pRect)
 Ensure a rect conforms to the size of a basic window. More...
 
int DrawBasicWindow (GUI_RECT *pRect=NULL)
 Draw a basic window. More...
 
VideoTextureGetLocalVideoTexture (int LocalIndex)
 Get a locally allocated video texture object by its index. More...
 
int AllocTexture (int InsertIndex=-1, int Width=WINDOW_WIDTH, int Height=WINDOW_HEIGHT, int BitsPerPixel=32, int Magnification=-1, int WindowIndex=0)
 Allocate private resources. More...
 
void FreeTexture (int Index)
 Free a previously allocated texture. More...
 
void FreeAllTextures ()
 Free all allocated textures.
 
bool IsLocalTextureAllocated (int Index)
 Check to see if a texture at a given local index is allocated. More...
 
void SelectTexture (int Index)
 Select a previously allocated surface. More...
 
int GetSelectedTexture ()
 Get the currently selected texture. More...
 
void FinishTexture (int Index)
 Finish drawing a texture. More...
 
void DrawTexture (int Index, int X=0, int Y=0, unsigned char Alpha=255, bool bSubPixels=false, bool bWrapCoordinates=false)
 Draw an allocated texture onto the screen. More...
 
int GetTextureCenteredX (int Index)
 Get the screen-centered X position of a texture. More...
 
int GetTextureCenteredY (int Index)
 Get the screen-centered Y position of a texture. More...
 
GUI_POINT GetTextureCentered (int Index)
 Get the screen-centered position of a texture. More...
 
int GetTextureWidth (int Index, bool Magnified=true)
 Get the width of an allocated texture. More...
 
int GetTextureHeight (int Index, bool Magnified=true)
 Get the height of an allocated texture. More...
 
GUI_POINT GetTextureRelativeMousePoint (int Index)
 Get the current mouse position relative to a texture. More...
 
virtual bool StartMode ()
 Initialize the mode in free-call mode. More...
 
virtual void EndMode (int value=0x6FFFFFFF, bool bSchedule=false)
 End this mode. More...
 
void SetModePaused (bool bValue)
 Set the 'paused' value for this mode. More...
 
virtual bool ModeTick ()
 Run this mode for one frame. More...
 
int GetRetValue ()
 Get the return value for this mode. More...
 
bool IsModeFreeRunning ()
 Check to see if this mode is running in freerun mode. More...
 
ModeConfigurationGetModeConfig ()
 Get a pointer to this mode's config. More...
 
virtual void SetDirty ()
 Set this mode as dirty.
 
void ReloadMode ()
 Reload this mode.
 
void ResetMode ()
 Reset the mode.
 
void SetRetValue (int value)
 Set the return value. More...
 
virtual int DoMode ()
 Run this mode until it stops. More...
 

Static Public Member Functions

static void SetGlobalConfig (MODE_GLOBAL_CONFIG_TYPE eType, const char *pValue)
 Set the value of a global config variable. More...
 
static void ProcessScheduleList ()
 Process all schedules.
 
static EventScheduleId Schedule (unsigned int iDelay, EventSchedulePayloadFunc pPayloadFunc, void *pUserData=NULL, BaseModeInstance *pOwner=NULL)
 Schedule an event for later. More...
 
static bool CancelSchedule (EventScheduleId iEventId)
 
static bool IsSchedulePending (EventScheduleId iEventId)
 
static void ShowCursor ()
 Show the cursor. More...
 
static void HideCursor ()
 Hide the cursor. More...
 
static void SetCursor (CSMP_CURSOR_TYPE iType, int iEventId=-1, GUI_RECT *pRect=NULL)
 Set the current cursor. More...
 
static CSMP_CURSOR_TYPE GetCursor (GUI_RECT **pRect=NULL, int *pEventId=NULL)
 Get the current cursor type. More...
 
static void ReloadOpenModes ()
 Reload all currently opened modes.
 
static void ScheduleReloadOpenModes ()
 Reload all currently opened modes.
 
static FontObject * GetDefaultFont (unsigned int iMagnification=0)
 Get the default font that all GUIs should use. More...
 
static void ReloadFont (const char *pFontName, const char *pFontPath, int iFontW=-1, int iFontH=-1, unsigned int iMagnification=0)
 Reload the default font. More...
 
static GameProcessMode ShowTutorialPages (BaseModeInstance *pCaller, int iPageCount,...)
 Show a messagebox that allows the user to scroll through a list of tutorial pages. More...
 
static void RunGameLogic (bool AllowACT=true)
 Run game logic. More...
 
static void DrawGame (bool AllowACT=true, int OffsetX=0, int OffsetY=0, bool DoPutFade=true, bool bRunGameLogic=true)
 Draw game elements. More...
 
static void DrawHUD (int OffsetX=0, int OffsetY=0)
 Draw HUD.
 
static GUI_POINT GetControlKeySize (const KeyControlStruct *Buttons, int ButtonCount, bool StackControls=false, unsigned int CustomMagnification=0)
 Get the size of what DrawControls() would output to the screen. More...
 
static void DrawControls (MENU_CONTROLS_DRAW_POSITION DrawPosition, Surface_Ids destSID, const KeyControlStruct *Buttons, int ButtonCount, bool Flash=false, bool StackControls=false, int Alpha=255, unsigned int CustomMagnification=0)
 Draw standard controls. More...
 

Public Attributes

struct {
   ModeCallback_OnEnd   OnEnd
 This is called when the mode is ending, just before 'Free()'. More...
 
m_Callbacks
 
void * m_PrivData
 Pointer to private data structure, defined by each mode.
 

Protected Member Functions

virtual int Init ()=0
 Initialize this mode. More...
 
virtual int Free ()=0
 De-initialize this mode. More...
 
virtual int GetMagnification ()
 Fetch the magnification level for this UI. More...
 
virtual int ModePixelToScreenPixel (int iInput)
 Convert a mode coordinate to screen coordinates.
 
virtual void QueryMenuControls (KeyControlStruct pControlBuffer[32], int &pControlCount, bool &bStackControls)
 Ask the mode to populate pControlBuffer with its control scheme. More...
 
virtual void ProcessLogic ()=0
 Process the logic of this menu.
 
virtual void ProcessMouse (GUI_POINT mouse_point)=0
 Process this menu's mouse. More...
 
virtual void ProcessKeys ()=0
 Process key input.
 
virtual void PreRender ()=0
 Render everything to surfaces.
 
virtual void Draw ()=0
 Draw rendered surfaces.
 
virtual void PostDraw ()
 Draw rendered surfaces over top of everything else.
 
bool IsTooltipOpen ()
 Check to see if a tooltip is open. More...
 
bool CreateTooltip (GUI_POINT point, FontObject *font, const char *text, int life_time=5000)
 Create a tooltip. More...
 
bool CreateTextureTooltip (GUI_POINT point, FontObject *font, const char *text, int life_time=5000, int Magnification=-1)
 Create a texture tooltip. More...
 
bool CloseTooltip (bool fade_out=true)
 Close the currently opened tooltip. More...
 
GUI_RECTGetTooltipRect ()
 Get a pointer to the tooltip's rect. More...
 
void SetTooltipPosition (GUI_POINT new_position)
 Set the tooltip's position. More...
 
void ProcessTooltips ()
 Process the current & old tooltips.
 
void DrawTooltips ()
 Draw the current & old tooltips.
 
uint32_t GetRectHoverTime (GUI_POINT mouse_point, GUI_RECT rect)
 A helper method. More...
 
void ResetRectHover ()
 Reset rect hover system.
 
bool CreateMenuControls (const KeyControlStruct *Buttons, int ButtonCount, bool StackControls=false)
 Create control surfaces. More...
 
void DrawMenuControls (MENU_CONTROLS_DRAW_POSITION DrawPosition, MENU_CONTROLS_DRAW_FRAME DrawFrame)
 Draw the menu control surfaces generated by CreateMenuControls. More...
 
MENU_CONTROLS_ACTS GetMenuControlsAct ()
 Get the act number of the menu controls menu. More...
 
void SetMenuControlsAct (MENU_CONTROLS_ACTS NewAct)
 Set the act number of the menu controls menu. More...
 
bool GrabScreen ()
 Backup the screen to a surface.
 
void DrawScreenGrab ()
 Draw the backed up screen.
 
void UpdateScreenGrab ()
 Update the screen grab surface.
 
void ReleaseScreenGrab ()
 Release this mode's screengrab.
 
void DoEscapeMenu ()
 Open the escape menu. More...
 
int AllocSurface (int InsertIndex=-1, int Width=WINDOW_WIDTH, int Height=WINDOW_HEIGHT, unsigned int iMagnification=0)
 Allocate private resources. More...
 
int LoadImageToSurface (const char *FileName, int InsertIndex=-1)
 Allocate private resources. More...
 
int LoadImageToTexture (const char *FileName, int InsertIndex=-1)
 Allocate private resources. More...
 
int LoadSurfaceIDToSurface (Surface_Ids SurfaceID, int InsertIndex=-1)
 Allocate private resources. More...
 
int LoadSurfaceIDToTexture (Surface_Ids SurfaceID, int InsertIndex=-1)
 Allocate private resources. More...
 
void FreeSurface (int Index)
 Free a previously allocated surface. More...
 
void FreeAllSurfaces ()
 Free all allocated surfaces.
 
bool IsLocalSurfaceAllocated (int Index)
 Check to see if a surface at a given local index is allocated. More...
 
void SelectSurface (int Index)
 Select a previously allocated surface. More...
 
int GetSelectedSurface ()
 Get the currently selected surface. More...
 
Surface_Ids LocalSurfaceIndexToGlobal (int Index)
 Convert the local index of a surface we own to a global index. More...
 
int GlobalSurfaceIndexToLocal (Surface_Ids sId)
 Convert the global index of a surface to a local index. More...
 
void DrawSurface (int Index, int X=0, int Y=0, unsigned char Alpha=255, bool AbsolutePos=false)
 Draw an allocated surface on the screen. More...
 
int GetSurfaceWidth (int Index)
 Get the width of an allocated surface. More...
 
int GetSurfaceHeight (int Index)
 Get the height of an allocated surface. More...
 
int GetCenteredX (int Index)
 Get the screen-centered X position of a surface. More...
 
int GetCenteredY (int Index)
 Get the screen-centered Y position of a surface. More...
 
virtual GUI_POINT TranslateMousePosition (GUI_POINT *pMouseInput, const GUI_POINT &pWindowOffset)
 Translate the mouse position to relative coordinates. More...
 
virtual GUI_POINT TranslateMousePosition (GUI_POINT *pMouseInput)
 Translate the mouse position to relative coordinates. More...
 
virtual int GetRelativeScreenWidth ()
 Get the game window's width relative to this mode. More...
 
virtual int GetRelativeScreenHeight ()
 Get the game window's height relative to this mode. More...
 
bool IsFocusedMode ()
 Check to see if this mode is the currently focused mode. More...
 
void InitControlMenu ()
 Initialize the control menu.
 
bool IsControlMenuOpen ()
 Check to see if the control menu is open. More...
 
void RemoveKey (int iInputFlags, KeyInputType iType=KeyInputType::KIT_Key)
 Remove key inputs after processing them. More...
 
GUI_POINT GetRelativeMousePosition (int iIndex)
 Get the mouse position relative to a surface. More...
 

Static Protected Member Functions

static void CancelAllModeSchedules (BaseModeInstance *pMode)
 

Protected Attributes

ToolTipStruct m_OldTooltip
 The tooltip that is fading out.
 
ToolTipStruct m_CurTooltip
 The tooltip that is currently being shown.
 
ModeConfiguration m_ModeConfig
 The configuration for this mode.
 
struct BaseModeInstance::ModeInput m_ModeInput
 
Surface_Ids m_ScreenGrabSurf
 The screen grab surface ID.
 
bool m_Dirty
 Controls whether this mode should re-render.
 
bool m_End
 Controls whether this mode should end.
 
bool m_FreeCall
 Controls whether this mode is in free-call mode. More...
 
bool m_FreeCall_Paused
 Controls whether this mode is paused or not.
 
int m_RetValue
 Controls the return value of DoMode() internally. More...
 

Static Protected Attributes

static GLOBAL_CONFIG_STRUCT g_GlobalConfig
 The global configuration.
 

Friends

class ModeInputVector
 
class ModeThreadInstance
 
void SetGameResolution (int iNewWidth, int iNewHeight, int iNewMagnification)
 
void CAVESTORY_MOD_API MessageBox_DrawMode (void *)
 
int ChatEmotes::CheckOpenList (BaseModeInstance *pMode)
 
void Platform::OpenBugReporter ()
 

Detailed Description

Easy UI management.

This class controls most of the new UI in the game, and is packed with features to make developers' lives easy.

FreeRun instances are mode instances that run concurrently with other modes.

Instead of using #gKey, #gKeyTrg, etc. you should use the built-in m_ModeInput struct.

Examples
WelcomeMode.h.

Member Function Documentation

◆ AllocSurface()

int BaseModeInstance::AllocSurface ( int  InsertIndex = -1,
int  Width = WINDOW_WIDTH,
int  Height = WINDOW_HEIGHT,
unsigned int  iMagnification = 0 
)
protected

Allocate private resources.

Said resources are privated simply because they should not be tampered with.

Parameters
InsertIndexThe index in the local surface table to insert the new surface at. Pass '-1' to start from 0.
WidthThe width of the surface.
HeightThe height of the surface.
MagnificationThe magnification level to use. Pass '0' to use GetMagnification() in its place.
Returns
Returns the index (relative to m_SurfaceIDList) where the newly allocated surface resides. Returns -1 on error.

◆ AllocTexture()

int BaseModeInstance::AllocTexture ( int  InsertIndex = -1,
int  Width = WINDOW_WIDTH,
int  Height = WINDOW_HEIGHT,
int  BitsPerPixel = 32,
int  Magnification = -1,
int  WindowIndex = 0 
)

Allocate private resources.

Said resources are privated simply because they should not be tampered with.

Parameters
InsertIndexThe index in the local texture table to insert the new surface at. Pass '-1' to start from 0.
WidthThe width of the texture.
HeightThe height of the texture.
BitsPerPixelThe bits per pixel.
MagnificationMagnification level. Leave as '-1' to use the current magnification.
WindowIndexThe index of the window.
Returns
Returns the index (relative to m_TextureList) where the newly allocated surface resides. Returns -1 on error.

◆ CancelAllModeSchedules()

static void BaseModeInstance::CancelAllModeSchedules ( BaseModeInstance pMode)
staticprotected
Parameters
Cancelall schedules that belong to a mode instance.
pModeThe mode to check ownership for.

◆ CancelSchedule()

static bool BaseModeInstance::CancelSchedule ( EventScheduleId  iEventId)
static
Parameters
Cancela schedule.
iEventIdThe schedule's ID.
Returns
Returns true if the event was canceled successfully, false if the event was not queued.

◆ CloseTooltip()

bool BaseModeInstance::CloseTooltip ( bool  fade_out = true)
protected

Close the currently opened tooltip.

Parameters
fade_outIf true, the tooltip will not fade out, and will instead just instantly dissapear.
Returns
Returns true if the tooltip was closed.

◆ CreateMenuControls()

bool BaseModeInstance::CreateMenuControls ( const KeyControlStruct Buttons,
int  ButtonCount,
bool  StackControls = false 
)
protected

Create control surfaces.

Parameters
ButtonsA list of keys to use.
ButtonCountNumber of keys included in Buttons.
StackControlsWhether to display the controls from top to bottom, or left to right.
Returns
Returns true if the menu controls were configured successfully.

◆ CreateTextureTooltip()

bool BaseModeInstance::CreateTextureTooltip ( GUI_POINT  point,
FontObject *  font,
const char *  text,
int  life_time = 5000,
int  Magnification = -1 
)
protected

Create a texture tooltip.

Parameters
pointThe point at which the tooltip should be shown at.
fontThe font that should be used to create this tooltip object.
textThe text that should be shown on this tooltip.
life_timeThe life time of the tooltip, in milliseconds.
MagnificationThe magnification level of the texture.
Returns
Returns true if the tooltip was created.
Note
This function allocates a new

◆ CreateTooltip()

bool BaseModeInstance::CreateTooltip ( GUI_POINT  point,
FontObject *  font,
const char *  text,
int  life_time = 5000 
)
protected

Create a tooltip.

Parameters
pointThe point at which the tooltip should be shown at.
fontThe font that should be used to create this tooltip object.
textThe text that should be shown on this tooltip.
life_timeThe life time of the tooltip, in milliseconds.
Returns
Returns true if the tooltip was created.
Note
This function allocates a new

◆ DoEscapeMenu()

void BaseModeInstance::DoEscapeMenu ( )
protected

Open the escape menu.

Note
This function automatically sets m_RetValue and m_End if necessary.

◆ DoMode()

virtual int BaseModeInstance::DoMode ( )
virtual

Run this mode until it stops.

This can be overwritten with a custom mode loop function. By default, this function runs in this order:

  1. Call ResetConfiguration().
  2. Call Init(). After this, start the main mode loop: 2a. Call ProcessMouse() if m_ModeConfig.AllowMouseControl is set to true AND if m_ModeConfig.Window has mouse focus (unless m_ModeConfig.IgnoreWindow is set to true). 2b. Call ProcessKeys() if m_ModeConfig.AllowKeyControl is set to true AND if m_ModeConfig.Window has input focus (unless m_ModeConfig.IgnoreWindow is set to true). 2c. Call ProcessLogic() 2d. If m_End is true, then it breaks the loop here. 2e. Call Render() if m_Dirty is set to true. Sets m_Dirty to false afterwards. 2f. Call Draw(). 2g. Flips the window's surface
  3. Call Free().
Returns
The current mode.

◆ DrawBasicWindow()

int BaseModeInstance::DrawBasicWindow ( GUI_RECT pRect = NULL)

Draw a basic window.

Parameters
pRectThe rect to draw the window with. Can be NULL.
Returns
Returns the margin of the window.

◆ DrawControls()

static void BaseModeInstance::DrawControls ( MENU_CONTROLS_DRAW_POSITION  DrawPosition,
Surface_Ids  destSID,
const KeyControlStruct Buttons,
int  ButtonCount,
bool  Flash = false,
bool  StackControls = false,
int  Alpha = 255,
unsigned int  CustomMagnification = 0 
)
static

Draw standard controls.

Parameters
DrawPositionThe position to draw the controls at.
destSIDThe destination surface ID.
ButtonsA list of keys to use.
ButtonCountNumber of keys included in Buttons.
FlashWhether the keys should be pressed or not.
StackControlsWhether to display the controls from top to bottom, or left to right.
AlphaThe alpha of the menu.
CustomMagnificationThe custom magnification level to use. Pass '0' to use UI scale.

◆ DrawGame()

static void BaseModeInstance::DrawGame ( bool  AllowACT = true,
int  OffsetX = 0,
int  OffsetY = 0,
bool  DoPutFade = true,
bool  bRunGameLogic = true 
)
static

Draw game elements.

Parameters
AllowACTAllow game input.
OffsetXX offset for the camera.
OffsetYY offset for the camera.
DoPutFadeWhether to draw the fade.
bRunGameLogicAllow the game logic to run for this call.

◆ DrawMenuControls()

void BaseModeInstance::DrawMenuControls ( MENU_CONTROLS_DRAW_POSITION  DrawPosition,
MENU_CONTROLS_DRAW_FRAME  DrawFrame 
)
protected

Draw the menu control surfaces generated by CreateMenuControls.

Parameters
DrawPositionThe position to draw the menu controls at.
DrawFrameThe frame of the menu controls UI.

◆ DrawSurface()

void BaseModeInstance::DrawSurface ( int  Index,
int  X = 0,
int  Y = 0,
unsigned char  Alpha = 255,
bool  AbsolutePos = false 
)
protected

Draw an allocated surface on the screen.

Parameters
IndexThe index of the surface.
XThe X position to draw the surface at. If MODE_DRAW_CENTERED_SURFACE, it will center it.
YThe Y position to draw the surface at. If MODE_DRAW_CENTERED_SURFACE, it will center it.
AlphaThe alpha of the surface.
AbsolutePosIf this is true, X and Y are not magnified.

◆ DrawTexture()

void BaseModeInstance::DrawTexture ( int  Index,
int  X = 0,
int  Y = 0,
unsigned char  Alpha = 255,
bool  bSubPixels = false,
bool  bWrapCoordinates = false 
)

Draw an allocated texture onto the screen.

Parameters
IndexThe index of the texture.
XThe X position to draw the texture at. If MODE_DRAW_CENTERED_SURFACE, it will center it.
YThe Y position to draw the texture at. If MODE_DRAW_CENTERED_SURFACE, it will center it.
AlphaThe alpha of the texture.
bSubPixelsWhether the specified X and Y values are subpixel coordinates or not.
bWrapCoordinatesWrap the input coordinates.

◆ EndMode()

virtual void BaseModeInstance::EndMode ( int  value = 0x6FFFFFFF,
bool  bSchedule = false 
)
virtual

End this mode.

Parameters
valueThe return value the mode should return.
bScheduleSchedule the deletion if this is a freerun mode.

◆ EnforceBasicWindowSize()

void BaseModeInstance::EnforceBasicWindowSize ( GUI_RECT pRect)

Ensure a rect conforms to the size of a basic window.

Helps to deal with broken tiles in the background of the window.

Parameters
pRectThe rect to enforce the sizing rule on.

◆ FinishTexture()

void BaseModeInstance::FinishTexture ( int  Index)

Finish drawing a texture.

Parameters
Theindex of the texture.

◆ Free()

virtual int BaseModeInstance::Free ( )
protectedpure virtual

De-initialize this mode.

Returns
Returns a non-zero value if an error occured. An exception will be thrown if a non-zero value is encountered.

Implemented in MessageBoxMode.

Examples
WelcomeMode.h.

◆ FreeSurface()

void BaseModeInstance::FreeSurface ( int  Index)
protected

Free a previously allocated surface.

Parameters
IndexThe index of the surface.

◆ FreeTexture()

void BaseModeInstance::FreeTexture ( int  Index)

Free a previously allocated texture.

Parameters
IndexThe index of the texture.

◆ GetCenteredX()

int BaseModeInstance::GetCenteredX ( int  Index)
protected

Get the screen-centered X position of a surface.

Parameters
IndexThe index of the surface.
Returns
The X position.

◆ GetCenteredY()

int BaseModeInstance::GetCenteredY ( int  Index)
protected

Get the screen-centered Y position of a surface.

Parameters
IndexThe index of the surface.
Returns
The Y position.

◆ GetControlKeySize()

static GUI_POINT BaseModeInstance::GetControlKeySize ( const KeyControlStruct Buttons,
int  ButtonCount,
bool  StackControls = false,
unsigned int  CustomMagnification = 0 
)
static

Get the size of what DrawControls() would output to the screen.

Parameters
ButtonsA list of keys to use.
ButtonCountNumber of keys included in Buttons.
StackControlsWhether to display the controls from top to bottom, or left to right.
CustomMagnificationThe custom magnification level to use. Pass '0' to use UI scale.
Returns
Returns the calculated size of the menu controls UI.

◆ GetCursor()

static CSMP_CURSOR_TYPE BaseModeInstance::GetCursor ( GUI_RECT **  pRect = NULL,
int *  pEventId = NULL 
)
static

Get the current cursor type.

Parameters
pValidRectA pointer to a GUI_RECT object that will hold the valid cursortype area. Can be 'NULL'.
pEventIdA pointer to an int object that will hold the event ID. Can be 'NULL'.
Returns
Returns the cursor type.

◆ GetDefaultFont()

static FontObject* BaseModeInstance::GetDefaultFont ( unsigned int  iMagnification = 0)
static

Get the default font that all GUIs should use.

Parameters
iMagnificationThe custom magnification level to use. Pass '0' for default magnification.
Returns
Returns the font that should be used.
Examples
RenderPipeline.cpp, and WelcomeMode.cpp.

◆ GetLocalVideoTexture()

VideoTexture* BaseModeInstance::GetLocalVideoTexture ( int  LocalIndex)

Get a locally allocated video texture object by its index.

Parameters
iLocalIndexThe local index of the texture.
Returns
Returns the video texture object if it exists, otherwise returns 'NULL' if it doesn't.

◆ GetMagnification()

virtual int BaseModeInstance::GetMagnification ( )
protectedvirtual

Fetch the magnification level for this UI.

Returns
Should return the desired magnification level.

◆ GetMenuControlsAct()

MENU_CONTROLS_ACTS BaseModeInstance::GetMenuControlsAct ( )
protected

Get the act number of the menu controls menu.

Returns
Returns the current act descriptor.

◆ GetModeConfig()

BaseModeInstance::ModeConfiguration * BaseModeInstance::GetModeConfig ( )
inline

Get a pointer to this mode's config.

Returns
Returns a pointer to this mode's config.

◆ GetRectHoverTime()

uint32_t BaseModeInstance::GetRectHoverTime ( GUI_POINT  mouse_point,
GUI_RECT  rect 
)
protected

A helper method.

It can be used to count how long the mouse pointer has stayed inside of a rect.

Parameters
mouse_pointThe position of the mouse.
rectThe rect in which the mouse should be in.
Returns
Returns the amount of time the mouse has been inside of the rect for. Returns -1 if it isn't in the given rect, and also returns -2 if the mouse WAS in the given rect, but isn't anymore.
Note
This only works for one rect. When the mouse is detected as 'inside a rect', then it will overwrite the last timer.

◆ GetRelativeMousePosition()

GUI_POINT BaseModeInstance::GetRelativeMousePosition ( int  iIndex)
protected

Get the mouse position relative to a surface.

Parameters
iIndexThe local surface index to make the mouse position relative to.
Returns
Returns the mouse position, relative to the given surface.

◆ GetRelativeScreenHeight()

virtual int BaseModeInstance::GetRelativeScreenHeight ( )
protectedvirtual

Get the game window's height relative to this mode.

Returns
The height of the game window.

◆ GetRelativeScreenWidth()

virtual int BaseModeInstance::GetRelativeScreenWidth ( )
protectedvirtual

Get the game window's width relative to this mode.

Returns
The width of the game window.

◆ GetRetValue()

int BaseModeInstance::GetRetValue ( )

Get the return value for this mode.

Returns
This mode's return value.

◆ GetSelectedSurface()

int BaseModeInstance::GetSelectedSurface ( )
protected

Get the currently selected surface.

Returns
Returns the index (relative to m_SurfaceIDList) where the allocated surface is.

◆ GetSelectedTexture()

int BaseModeInstance::GetSelectedTexture ( )

Get the currently selected texture.

Returns
Returns the index (relative to m_TextureList) where the allocated texture is.

◆ GetSurfaceHeight()

int BaseModeInstance::GetSurfaceHeight ( int  Index)
protected

Get the height of an allocated surface.

Parameters
IndexThe index of the surface.
Returns
The height of the given surface.

◆ GetSurfaceWidth()

int BaseModeInstance::GetSurfaceWidth ( int  Index)
protected

Get the width of an allocated surface.

Parameters
IndexThe index of the surface.
Returns
The width of the given surface.

◆ GetTextureCentered()

GUI_POINT BaseModeInstance::GetTextureCentered ( int  Index)

Get the screen-centered position of a texture.

Parameters
IndexThe index of the surface.
Returns
The coordinates.

◆ GetTextureCenteredX()

int BaseModeInstance::GetTextureCenteredX ( int  Index)

Get the screen-centered X position of a texture.

Parameters
IndexThe index of the surface.
Returns
The X position.

◆ GetTextureCenteredY()

int BaseModeInstance::GetTextureCenteredY ( int  Index)

Get the screen-centered Y position of a texture.

Parameters
IndexThe index of the surface.
Returns
The Y position.

◆ GetTextureHeight()

int BaseModeInstance::GetTextureHeight ( int  Index,
bool  Magnified = true 
)

Get the height of an allocated texture.

Parameters
IndexThe index of the texture.
MagnifiedWhether the width should be magnified or not.
Returns
The height of the given texture.

◆ GetTextureRelativeMousePoint()

GUI_POINT BaseModeInstance::GetTextureRelativeMousePoint ( int  Index)

Get the current mouse position relative to a texture.

Parameters
IndexThe index of the texture.
Returns
Returns the adjusted mouse position.

◆ GetTextureWidth()

int BaseModeInstance::GetTextureWidth ( int  Index,
bool  Magnified = true 
)

Get the width of an allocated texture.

Parameters
IndexThe index of the texture.
MagnifiedWhether the width should be magnified or not.
Returns
The width of the given texture.

◆ GetTooltipRect()

GUI_RECT* BaseModeInstance::GetTooltipRect ( )
protected

Get a pointer to the tooltip's rect.

Returns
Returns a pointer to the rect of the tooltip. Returns NULL if the tooltip is not currently open.

◆ GlobalSurfaceIndexToLocal()

int BaseModeInstance::GlobalSurfaceIndexToLocal ( Surface_Ids  sId)
protected

Convert the global index of a surface to a local index.

Parameters
IndexThe index of the surface.
Returns
Returns the local index of the provided surface.

◆ HideCursor()

static void BaseModeInstance::HideCursor ( )
static

Hide the cursor.

Note
Acts as a ref counter. If you call ShowCursor(), then you should call this when you're finished, or the mouse will never be hidden.

◆ Init()

virtual int BaseModeInstance::Init ( )
protectedpure virtual

Initialize this mode.

Returns
Returns a non-zero value if an error occured. On this occasion, DoMode() will not continue execution.

Implemented in MessageBoxMode.

Examples
WelcomeMode.h.

◆ IsControlMenuOpen()

bool BaseModeInstance::IsControlMenuOpen ( )
protected

Check to see if the control menu is open.

Returns
Returns true if it is open.

◆ IsFocusedMode()

bool BaseModeInstance::IsFocusedMode ( )
protected

Check to see if this mode is the currently focused mode.

Returns
Returns true if this mode is the currently focused mode.

◆ IsLocalSurfaceAllocated()

bool BaseModeInstance::IsLocalSurfaceAllocated ( int  Index)
protected

Check to see if a surface at a given local index is allocated.

Parameters
IndexThe index in the local surface table to check.
Returns
Returns true if the surface at the given index is allocated, false otherwise.

◆ IsLocalTextureAllocated()

bool BaseModeInstance::IsLocalTextureAllocated ( int  Index)

Check to see if a texture at a given local index is allocated.

Parameters
IndexThe index in the local surface table to check.
Returns
Returns true if the surface at the given index is allocated, false otherwise.

◆ IsModeFreeRunning()

bool BaseModeInstance::IsModeFreeRunning ( )

Check to see if this mode is running in freerun mode.

Returns
Returns true if it is, otherwise returns false.

◆ IsSchedulePending()

static bool BaseModeInstance::IsSchedulePending ( EventScheduleId  iEventId)
static
Parameters
Checksif a schedule is still pending.
iEventIdThe schedule's ID.

◆ IsTooltipOpen()

bool BaseModeInstance::IsTooltipOpen ( )
inlineprotected

Check to see if a tooltip is open.

Only checks m_CurTooltip.

Returns
Returns true if a tooltip is currently open.

◆ LoadImageToSurface()

int BaseModeInstance::LoadImageToSurface ( const char *  FileName,
int  InsertIndex = -1 
)
protected

Allocate private resources.

Said resources are privated simply because they should not be tampered with.

Parameters
FileNameThe filename to load.
InsertIndexThe index in the local surface table to insert the new surface at. Pass '-1' to start from 0.
Returns
Returns the index (relative to m_SurfaceIDList) where the newly loaded image's surface resides. Returns -1 on error.

◆ LoadImageToTexture()

int BaseModeInstance::LoadImageToTexture ( const char *  FileName,
int  InsertIndex = -1 
)
protected

Allocate private resources.

Said resources are privated simply because they should not be tampered with.

Parameters
FileNameThe filename to load.
InsertIndexThe index in the local surface table to insert the new texture at. Pass '-1' to start from 0.
Returns
Returns the index (relative to m_TextureIDList) where the newly loaded image's texture resides. Returns -1 on error.

◆ LoadSurfaceIDToSurface()

int BaseModeInstance::LoadSurfaceIDToSurface ( Surface_Ids  SurfaceID,
int  InsertIndex = -1 
)
protected

Allocate private resources.

Said resources are privated simply because they should not be tampered with.

Parameters
SurfaceIDThe ID of the surface to copy.
InsertIndexThe index in the local surface table to insert the new surface at. Pass '-1' to start from 0.
Returns
Returns the index (relative to m_SurfaceIDList) where the newly loaded image's surface resides. Returns -1 on error.

◆ LoadSurfaceIDToTexture()

int BaseModeInstance::LoadSurfaceIDToTexture ( Surface_Ids  SurfaceID,
int  InsertIndex = -1 
)
protected

Allocate private resources.

Said resources are privated simply because they should not be tampered with.

Parameters
SurfaceIDThe ID of the surface to copy.
InsertIndexThe index in the local surface table to insert the new texture at. Pass '-1' to start from 0.
Returns
Returns the index (relative to m_TextureIDList) where the newly loaded image's texture resides. Returns -1 on error.

◆ LocalSurfaceIndexToGlobal()

Surface_Ids BaseModeInstance::LocalSurfaceIndexToGlobal ( int  Index)
protected

Convert the local index of a surface we own to a global index.

Parameters
IndexThe index of the surface.
Returns
Returns the global index of the provided surface.

◆ ModeTick()

virtual bool BaseModeInstance::ModeTick ( )
virtual

Run this mode for one frame.

Returns
True if the mode is still running; False if otherwise.

◆ ProcessMouse()

virtual void BaseModeInstance::ProcessMouse ( GUI_POINT  mouse_point)
protectedpure virtual

Process this menu's mouse.

Parameters
mouse_pointThe mouse point.

Implemented in MessageBoxMode.

Examples
WelcomeMode.h.

◆ QueryMenuControls()

virtual void BaseModeInstance::QueryMenuControls ( KeyControlStruct  pControlBuffer[32],
int &  pControlCount,
bool &  bStackControls 
)
protectedvirtual

Ask the mode to populate pControlBuffer with its control scheme.

If pControlCount is set to 0, then the control menu will not be displayed.

Parameters
pControlBufferPopulate this buffer with KeyControlStruct. Max 32.
pControlCountSet this to how many keys were populated in pControlBuffer.
bStackControlsWhether to display the controls from top to bottom, or left to right.

◆ ReloadFont()

static void BaseModeInstance::ReloadFont ( const char *  pFontName,
const char *  pFontPath,
int  iFontW = -1,
int  iFontH = -1,
unsigned int  iMagnification = 0 
)
static

Reload the default font.

Parameters
pFontNameThe name of the font.
pFontPathThe path of the font to try in. Do not lead with a trailing '/' or '\'.
iMagnificationThe custom magnification level to use. Pass '0' for default magnification.
Returns
Returns the font that should be used.

◆ RemoveKey()

void BaseModeInstance::RemoveKey ( int  iInputFlags,
KeyInputType  iType = KeyInputType::KIT_Key 
)
protected

Remove key inputs after processing them.

Remove a keypress. This should always be used after checking input.

Parameters
iInputFlagsThe flags to remove.
iTypeThe type of input to remove the key from.

◆ RunGameLogic()

static void BaseModeInstance::RunGameLogic ( bool  AllowACT = true)
static

Run game logic.

Parameters
AllowACTAllow game input.

◆ Schedule()

static EventScheduleId BaseModeInstance::Schedule ( unsigned int  iDelay,
EventSchedulePayloadFunc  pPayloadFunc,
void *  pUserData = NULL,
BaseModeInstance pOwner = NULL 
)
static

Schedule an event for later.

Parameters
iDelayThe delay in ms before the payload gets executed.
pPayloadFuncThe function to call after the delay is exceeded.
pUserDataThe data to include in the call to pPayloadFunc.
pOwnerThe owner of this event. This will be passed to pPayloadFunc. Can be NULL.
Returns
Returns a schedule ID, which you can use to cancel an event.

◆ SelectSurface()

void BaseModeInstance::SelectSurface ( int  Index)
protected

Select a previously allocated surface.

Parameters
IndexThe index of the surface.

◆ SelectTexture()

void BaseModeInstance::SelectTexture ( int  Index)

Select a previously allocated surface.

Parameters
IndexThe index of the surface.

◆ SetCursor()

static void BaseModeInstance::SetCursor ( CSMP_CURSOR_TYPE  iType,
int  iEventId = -1,
GUI_RECT pRect = NULL 
)
static

Set the current cursor.

Parameters
iTypeThe cursor type to set.
iEventIdAn attached event ID, so GUI elements can identify if it was themselves that set a cursor.
pRectThe rect that the mouse should stay within to keep this cursor type. If the mouse exits this rect, then it is set back to NORMAL. This can be 'NULL' to ignore this functionality.

◆ SetGlobalConfig()

static void BaseModeInstance::SetGlobalConfig ( MODE_GLOBAL_CONFIG_TYPE  eType,
const char *  pValue 
)
static

Set the value of a global config variable.

Parameters
eTypeThe type of the variable to configure.
pValueThe value to set.

◆ SetMenuControlsAct()

void BaseModeInstance::SetMenuControlsAct ( MENU_CONTROLS_ACTS  NewAct)
protected

Set the act number of the menu controls menu.

Param NewAct The new act descriptor.

◆ SetModePaused()

void BaseModeInstance::SetModePaused ( bool  bValue)

Set the 'paused' value for this mode.

Parameters
bValueIf 'true', then this mode will be paused.
Note
This currently only works for freecall modes.

◆ SetRetValue()

void BaseModeInstance::SetRetValue ( int  value)

Set the return value.

Parameters
valueThe value it should return.

◆ SetTooltipPosition()

void BaseModeInstance::SetTooltipPosition ( GUI_POINT  new_position)
protected

Set the tooltip's position.

Parameters
new_positionThe new position to set the tooltip to.

◆ ShowCursor()

static void BaseModeInstance::ShowCursor ( )
static

Show the cursor.

Note
Acts as a ref counter. If you call ShowCursor(), then you should call this when you're finished, or the mouse will never be hidden.

◆ ShowTutorialPages()

static GameProcessMode BaseModeInstance::ShowTutorialPages ( BaseModeInstance pCaller,
int  iPageCount,
  ... 
)
static

Show a messagebox that allows the user to scroll through a list of tutorial pages.

Parameters
pCallerThe mode that should be drawn underneath the tutorial. Can be NULL.
iPageCountThe number of pages.
...Page text for each page. Only accepts char*.
Returns
Returns a GameProcessMode value.

◆ StartAsyncOperation()

ModeThreadId BaseModeInstance::StartAsyncOperation ( ModeThreadInstance::ModeCallback_OnThreadLoop  pOnLoopFunc,
ModeThreadInstance::ModeCallback_OnThreadComplete  pOnCompleteFunc = NULL,
void *  pUserData = NULL 
)

Begin a thread-safe asynchronous operation.

Parameters
pOnLoopFuncThe onloop callback function.
pOnLoopFuncThe oncomplete callback function. Can be NULL.
pUserDataThe userdata to use for the callback functions. Can be NULL.
Returns
Returns the ID of the created thread on success, otherwise returns MODE_INVALID_THREAD_ID on error.

◆ StartMode()

virtual bool BaseModeInstance::StartMode ( )
virtual

Initialize the mode in free-call mode.

This allows you to do /other/ stuff and not be limited to the code specified in this mode.

Returns
Should return true if started successfully, false if not.

◆ StopThread()

bool BaseModeInstance::StopThread ( ModeThreadId  iThreadId,
bool  bWaitForFinish = false 
)

Stop a thread.

Parameters
iThreadIdThe thread's ID.
bWaitForFinishWait for the thread to finish.
Returns
Returns true if the thread was stopped successfully, false otherwise.

◆ TranslateMousePosition() [1/2]

virtual GUI_POINT BaseModeInstance::TranslateMousePosition ( GUI_POINT pMouseInput)
protectedvirtual

Translate the mouse position to relative coordinates.

Parameters
pMouseInputThe mouse input to translate. Pass 'NULL' to use current mouse position.
Returns
The width of the game window.

◆ TranslateMousePosition() [2/2]

virtual GUI_POINT BaseModeInstance::TranslateMousePosition ( GUI_POINT pMouseInput,
const GUI_POINT pWindowOffset 
)
protectedvirtual

Translate the mouse position to relative coordinates.

Parameters
pMouseInputThe mouse input to translate. Pass 'NULL' to use current mouse position.
pWindowOffsetThe offset of the window.
Returns
The width of the game window.

Member Data Documentation

◆ m_FreeCall

bool BaseModeInstance::m_FreeCall
protected

Controls whether this mode is in free-call mode.

Do NOT change this!

◆ m_RetValue

int BaseModeInstance::m_RetValue
protected

Controls the return value of DoMode() internally.

See also
GameProcessMode

◆ OnEnd

ModeCallback_OnEnd BaseModeInstance::OnEnd

This is called when the mode is ending, just before 'Free()'.

Note
This is only called in FreeCall mode

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