GameExecutable: Some cleanup for menu code.

This commit is contained in:
zcaliptium 2016-03-30 23:09:51 +03:00
parent de240b4ad7
commit 1f0da8a443
10 changed files with 87 additions and 101 deletions

View File

@ -6,8 +6,6 @@
#include "MenuStuff.h" #include "MenuStuff.h"
#include "MControls.h" #include "MControls.h"
extern void ControlsMenuOn();
extern void ControlsMenuOff();
extern CTFileName _fnmControlsToCustomize; extern CTFileName _fnmControlsToCustomize;

View File

@ -6,9 +6,6 @@
#include "MenuStuff.h" #include "MenuStuff.h"
#include "MCustomizeAxis.h" #include "MCustomizeAxis.h"
extern void ControlsMenuOn();
extern void ControlsMenuOff();
void CCustomizeAxisMenu::Initialize_t(void) void CCustomizeAxisMenu::Initialize_t(void)
{ {

View File

@ -3,11 +3,9 @@
#include "StdH.h" #include "StdH.h"
#include <Engine/CurrentVersion.h> #include <Engine/CurrentVersion.h>
#include "MenuPrinting.h" #include "MenuPrinting.h"
#include "MenuStuff.h"
#include "MCustomizeKeyboard.h" #include "MCustomizeKeyboard.h"
extern void ControlsMenuOn();
extern void ControlsMenuOff();
void CCustomizeKeyboardMenu::FillListItems(void) void CCustomizeKeyboardMenu::FillListItems(void)
{ {

View File

@ -44,8 +44,6 @@ void OnPlayerSelect(void);
TIME _tmMenuLastTickDone = -1; TIME _tmMenuLastTickDone = -1;
// all possible menu entities // all possible menu entities
CListHead lhMenuEntities; CListHead lhMenuEntities;
// controls that are currently customized
CTFileName _fnmControlsToCustomize = CTString("");
extern CTString _strLastPlayerAppearance = ""; extern CTString _strLastPlayerAppearance = "";
extern CTString sam_strNetworkSettings; extern CTString sam_strNetworkSettings;
@ -55,34 +53,8 @@ void (*_pAfterLevelChosen)(void);
// functions for init actions // functions for init actions
void FixupBackButton(CGameMenu *pgm); void FixupBackButton(CGameMenu *pgm);
extern void ControlsMenuOn()
{
_pGame->SavePlayersAndControls();
try {
_pGame->gm_ctrlControlsExtra.Load_t(_fnmControlsToCustomize);
} catch( char *strError) {
WarningMessage(strError);
}
}
extern void ControlsMenuOff()
{
try {
if (_pGame->gm_ctrlControlsExtra.ctrl_lhButtonActions.Count()>0) {
_pGame->gm_ctrlControlsExtra.Save_t(_fnmControlsToCustomize);
}
} catch( char *strError) {
FatalError(strError);
}
FORDELETELIST( CButtonAction, ba_lnNode, _pGame->gm_ctrlControlsExtra.ctrl_lhButtonActions, itAct) {
delete &itAct.Current();
}
_pGame->LoadPlayersAndControls();
}
// mouse cursor position // mouse cursor position
extern PIX _pixCursorPosI = 0; extern PIX _pixCursorPosI = 0;
extern PIX _pixCursorPosJ = 0; extern PIX _pixCursorPosJ = 0;
@ -244,32 +216,11 @@ void StopMenus( BOOL bGoToRoot /*=TRUE*/)
} }
} }
BOOL IsMenusInRoot(void) BOOL IsMenusInRoot(void)
{ {
return pgmCurrentMenu == NULL || pgmCurrentMenu == &_pGUIM->gmMainMenu || pgmCurrentMenu == &_pGUIM->gmInGameMenu; return pgmCurrentMenu == NULL || pgmCurrentMenu == &_pGUIM->gmMainMenu || pgmCurrentMenu == &_pGUIM->gmInGameMenu;
} }
// ---------------------- When activated functions
void StopCurrentGame(void)
{
_pGame->StopGame();
_gmRunningGameMode=GM_NONE;
StopMenus(TRUE);
StartMenus("");
}
void DisabledFunction(void)
{
_pGUIM->gmDisabledFunction.gm_pgmParentMenu = pgmCurrentMenu;
_pGUIM->gmDisabledFunction.gm_mgButton.mg_strText = TRANS("The feature is not available in this version!");
_pGUIM->gmDisabledFunction.gm_mgTitle.mg_strText = TRANS("DISABLED");
ChangeToMenu(&_pGUIM->gmDisabledFunction);
}
extern void InitVideoOptionsButtons(void);
extern void UpdateVideoOptionsButtons(INDEX i);
// ------------------------ Global menu function implementation // ------------------------ Global menu function implementation
void InitializeMenus(void) void InitializeMenus(void)
{ {
@ -485,7 +436,6 @@ void InitializeMenus(void)
} }
} }
void DestroyMenus( void) void DestroyMenus( void)
{ {
_pGUIM->gmMainMenu.Destroy(); _pGUIM->gmMainMenu.Destroy();

View File

@ -108,9 +108,16 @@ void ExitConfirm(void)
ChangeToMenu(&_pGUIM->gmConfirmMenu); ChangeToMenu(&_pGUIM->gmConfirmMenu);
} }
void StopCurrentGame(void)
{
_pGame->StopGame();
_gmRunningGameMode = GM_NONE;
StopMenus(TRUE);
StartMenus("");
}
void StopConfirm(void) void StopConfirm(void)
{ {
extern void StopCurrentGame(void);
_pConfimedYes = &StopCurrentGame; _pConfimedYes = &StopCurrentGame;
_pConfimedNo = NULL; _pConfimedNo = NULL;
_pGUIM->gmConfirmMenu.gm_mgConfirmLabel.mg_strText = TRANS("ARE YOU SERIOUS?"); _pGUIM->gmConfirmMenu.gm_mgConfirmLabel.mg_strText = TRANS("ARE YOU SERIOUS?");
@ -1064,22 +1071,6 @@ void InitActionsForNetworkStartMenu()
_pGUIM->gmNetworkStartMenu.gm_mgStart.mg_pActivatedFunction = &StartSelectPlayersMenuFromNetwork; _pGUIM->gmNetworkStartMenu.gm_mgStart.mg_pActivatedFunction = &StartSelectPlayersMenuFromNetwork;
} }
//
#define ADD_GADGET( gd, box, up, dn, lf, rt, txt) \
gd.mg_boxOnScreen = box; \
gd.mg_pmgUp = up; \
gd.mg_pmgDown = dn; \
gd.mg_pmgLeft = lf; \
gd.mg_pmgRight = rt; \
gd.mg_strText = txt; \
gm_lhGadgets.AddTail(gd.mg_lnNode);
#define SET_CHGPLR( gd, iplayer, bnone, bauto, pmgit) \
gd.mg_pmgInfoTable = pmgit; \
gd.mg_bResetToNone = bnone; \
gd.mg_bAutomatic = bauto; \
gd.mg_iLocalPlayer = iplayer;
// ------------------------ CSelectPlayersMenu implementation // ------------------------ CSelectPlayersMenu implementation
#define CMENU _pGUIM->gmSelectPlayersMenu #define CMENU _pGUIM->gmSelectPlayersMenu

View File

@ -483,15 +483,19 @@ void StartSplitScreenGame(void)
} }
} }
#define CMENU _pGUIM->gmSelectPlayersMenu
void StartSelectPlayersMenuFromSplit(void) void StartSelectPlayersMenuFromSplit(void)
{ {
_pGUIM->gmSelectPlayersMenu.gm_bAllowDedicated = FALSE; CMENU.gm_bAllowDedicated = FALSE;
_pGUIM->gmSelectPlayersMenu.gm_bAllowObserving = FALSE; CMENU.gm_bAllowObserving = FALSE;
_pGUIM->gmSelectPlayersMenu.gm_mgStart.mg_pActivatedFunction = &StartSplitScreenGame; CMENU.gm_mgStart.mg_pActivatedFunction = &StartSplitScreenGame;
_pGUIM->gmSelectPlayersMenu.gm_pgmParentMenu = &_pGUIM->gmSplitStartMenu; CMENU.gm_pgmParentMenu = &_pGUIM->gmSplitStartMenu;
ChangeToMenu(&_pGUIM->gmSelectPlayersMenu); ChangeToMenu(&CMENU);
} }
#undef CMENU
void StartNetworkGame(void) void StartNetworkGame(void)
{ {
// _pGame->gm_MenuSplitScreenCfg = (enum CGame::SplitScreenCfg) mgSplitScreenCfg.mg_iSelected; // _pGame->gm_MenuSplitScreenCfg = (enum CGame::SplitScreenCfg) mgSplitScreenCfg.mg_iSelected;
@ -522,15 +526,19 @@ void StartNetworkGame(void)
} }
} }
#define CMENU _pGUIM->gmSelectPlayersMenu
void StartSelectPlayersMenuFromNetwork(void) void StartSelectPlayersMenuFromNetwork(void)
{ {
_pGUIM->gmSelectPlayersMenu.gm_bAllowDedicated = TRUE; CMENU.gm_bAllowDedicated = TRUE;
_pGUIM->gmSelectPlayersMenu.gm_bAllowObserving = TRUE; CMENU.gm_bAllowObserving = TRUE;
_pGUIM->gmSelectPlayersMenu.gm_mgStart.mg_pActivatedFunction = &StartNetworkGame; CMENU.gm_mgStart.mg_pActivatedFunction = &StartNetworkGame;
_pGUIM->gmSelectPlayersMenu.gm_pgmParentMenu = &_pGUIM->gmNetworkStartMenu; CMENU.gm_pgmParentMenu = &_pGUIM->gmNetworkStartMenu;
ChangeToMenu(&_pGUIM->gmSelectPlayersMenu); ChangeToMenu(&CMENU);
} }
#undef CMENU
void JoinNetworkGame(void) void JoinNetworkGame(void)
{ {
// _pGame->gm_MenuSplitScreenCfg = (enum CGame::SplitScreenCfg) mgSplitScreenCfg.mg_iSelected; // _pGame->gm_MenuSplitScreenCfg = (enum CGame::SplitScreenCfg) mgSplitScreenCfg.mg_iSelected;
@ -566,39 +574,43 @@ void JoinNetworkGame(void)
} }
} }
#define CMENU _pGUIM->gmSelectPlayersMenu
void StartSelectPlayersMenuFromOpen(void) void StartSelectPlayersMenuFromOpen(void)
{ {
_pGUIM->gmSelectPlayersMenu.gm_bAllowDedicated = FALSE; CMENU.gm_bAllowDedicated = FALSE;
_pGUIM->gmSelectPlayersMenu.gm_bAllowObserving = TRUE; CMENU.gm_bAllowObserving = TRUE;
_pGUIM->gmSelectPlayersMenu.gm_mgStart.mg_pActivatedFunction = &JoinNetworkGame; CMENU.gm_mgStart.mg_pActivatedFunction = &JoinNetworkGame;
_pGUIM->gmSelectPlayersMenu.gm_pgmParentMenu = &_pGUIM->gmNetworkOpenMenu; CMENU.gm_pgmParentMenu = &_pGUIM->gmNetworkOpenMenu;
ChangeToMenu(&_pGUIM->gmSelectPlayersMenu); ChangeToMenu(&CMENU);
/*if (sam_strNetworkSettings=="")*/ { /*if (sam_strNetworkSettings=="")*/ {
void StartNetworkSettingsMenu(void); void StartNetworkSettingsMenu(void);
StartNetworkSettingsMenu(); StartNetworkSettingsMenu();
_pGUIM->gmLoadSaveMenu.gm_bNoEscape = TRUE; _pGUIM->gmLoadSaveMenu.gm_bNoEscape = TRUE;
_pGUIM->gmLoadSaveMenu.gm_pgmParentMenu = &_pGUIM->gmNetworkOpenMenu; _pGUIM->gmLoadSaveMenu.gm_pgmParentMenu = &_pGUIM->gmNetworkOpenMenu;
_pGUIM->gmLoadSaveMenu.gm_pgmNextMenu = &_pGUIM->gmSelectPlayersMenu; _pGUIM->gmLoadSaveMenu.gm_pgmNextMenu = &CMENU;
} }
} }
void StartSelectPlayersMenuFromServers(void) void StartSelectPlayersMenuFromServers(void)
{ {
_pGUIM->gmSelectPlayersMenu.gm_bAllowDedicated = FALSE; CMENU.gm_bAllowDedicated = FALSE;
_pGUIM->gmSelectPlayersMenu.gm_bAllowObserving = TRUE; CMENU.gm_bAllowObserving = TRUE;
_pGUIM->gmSelectPlayersMenu.gm_mgStart.mg_pActivatedFunction = &JoinNetworkGame; CMENU.gm_mgStart.mg_pActivatedFunction = &JoinNetworkGame;
_pGUIM->gmSelectPlayersMenu.gm_pgmParentMenu = &_pGUIM->gmServersMenu; CMENU.gm_pgmParentMenu = &_pGUIM->gmServersMenu;
ChangeToMenu(&_pGUIM->gmSelectPlayersMenu); ChangeToMenu(&CMENU);
/*if (sam_strNetworkSettings=="")*/ { /*if (sam_strNetworkSettings=="")*/ {
void StartNetworkSettingsMenu(void); void StartNetworkSettingsMenu(void);
StartNetworkSettingsMenu(); StartNetworkSettingsMenu();
_pGUIM->gmLoadSaveMenu.gm_bNoEscape = TRUE; _pGUIM->gmLoadSaveMenu.gm_bNoEscape = TRUE;
_pGUIM->gmLoadSaveMenu.gm_pgmParentMenu = &_pGUIM->gmServersMenu; _pGUIM->gmLoadSaveMenu.gm_pgmParentMenu = &_pGUIM->gmServersMenu;
_pGUIM->gmLoadSaveMenu.gm_pgmNextMenu = &_pGUIM->gmSelectPlayersMenu; _pGUIM->gmLoadSaveMenu.gm_pgmNextMenu = &CMENU;
} }
} }
#undef CMENU
void StartSelectServerLAN(void) void StartSelectServerLAN(void)
{ {
_pGUIM->gmServersMenu.m_bInternet = FALSE; _pGUIM->gmServersMenu.m_bInternet = FALSE;
@ -777,3 +789,11 @@ void StartNetworkSettingsMenu(void)
} }
#undef CMENU #undef CMENU
void DisabledFunction(void)
{
_pGUIM->gmDisabledFunction.gm_pgmParentMenu = pgmCurrentMenu;
_pGUIM->gmDisabledFunction.gm_mgButton.mg_strText = TRANS("The feature is not available in this version!");
_pGUIM->gmDisabledFunction.gm_mgTitle.mg_strText = TRANS("DISABLED");
ChangeToMenu(&_pGUIM->gmDisabledFunction);
}

View File

@ -63,5 +63,6 @@ void StartAddonsLoadMenu(void);
void StartModsLoadMenu(void); void StartModsLoadMenu(void);
void StartNetworkSettingsMenu(void); void StartNetworkSettingsMenu(void);
void StartSinglePlayerMenu(void); void StartSinglePlayerMenu(void);
void DisabledFunction(void);
#endif /* include-once check. */ #endif /* include-once check. */

View File

@ -8,6 +8,7 @@
#include "MenuManager.h" #include "MenuManager.h"
#include "MenuStartersAF.h" #include "MenuStartersAF.h"
#include "MenuStarters.h" #include "MenuStarters.h"
#include "MenuStuff.h"
CTFileName _fnDemoToPlay; CTFileName _fnDemoToPlay;
CTFileName _fnGameToLoad; CTFileName _fnGameToLoad;
@ -94,9 +95,6 @@ BOOL LSLoadPlayerModel(const CTFileName &fnm)
return TRUE; return TRUE;
} }
extern void ControlsMenuOn();
extern void ControlsMenuOff();
BOOL LSLoadControls(const CTFileName &fnm) BOOL LSLoadControls(const CTFileName &fnm)
{ {
try { try {

View File

@ -262,3 +262,33 @@ enum DisplayDepth SwitchToDepth(INDEX i)
default: ASSERT(FALSE); return DD_DEFAULT; default: ASSERT(FALSE); return DD_DEFAULT;
} }
} }
// controls that are currently customized
CTFileName _fnmControlsToCustomize = CTString("");
void ControlsMenuOn()
{
_pGame->SavePlayersAndControls();
try {
_pGame->gm_ctrlControlsExtra.Load_t(_fnmControlsToCustomize);
}
catch (char *strError) {
WarningMessage(strError);
}
}
void ControlsMenuOff()
{
try {
if (_pGame->gm_ctrlControlsExtra.ctrl_lhButtonActions.Count()>0) {
_pGame->gm_ctrlControlsExtra.Save_t(_fnmControlsToCustomize);
}
}
catch (char *strError) {
FatalError(strError);
}
FORDELETELIST(CButtonAction, ba_lnNode, _pGame->gm_ctrlControlsExtra.ctrl_lhButtonActions, itAct) {
delete &itAct.Current();
}
_pGame->LoadPlayersAndControls();
}

View File

@ -52,4 +52,7 @@ enum GfxAPIType SwitchToAPI(INDEX i);
INDEX DepthToSwitch(enum DisplayDepth dd); INDEX DepthToSwitch(enum DisplayDepth dd);
enum DisplayDepth SwitchToDepth(INDEX i); enum DisplayDepth SwitchToDepth(INDEX i);
void ControlsMenuOn();
void ControlsMenuOff();
#endif /* include-once check. */ #endif /* include-once check. */