From 736d38e8c33d86f7e4f126839148bc78aeffab08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Mon, 15 May 2023 02:48:17 -0300 Subject: [PATCH] add StartGameDirect function --- src/g_level.cpp | 2 +- src/menu/doommenu.cpp | 73 +++++++++++++++++++-- src/menu/doommenu.h | 3 +- wadsrc/static/zscript/ui/menu/playermenu.zs | 2 + 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/g_level.cpp b/src/g_level.cpp index 4b7229ab0e..d161059e6c 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -271,7 +271,7 @@ void G_DeferedInitNew (const char *mapname, int newskill) void G_DeferedInitNew (FNewGameStartup *gs) { - if (gs->PlayerClass != NULL) playerclass = gs->PlayerClass; + if (gs->hasPlayerClass) playerclass = gs->PlayerClass; d_mapname = AllEpisodes[gs->Episode].mEpisodeMap; d_skill = gs->Skill; CheckWarpTransMap (d_mapname, true); diff --git a/src/menu/doommenu.cpp b/src/menu/doommenu.cpp index 5fd3542021..c8fb9cd3af 100644 --- a/src/menu/doommenu.cpp +++ b/src/menu/doommenu.cpp @@ -86,6 +86,59 @@ bool OkForLocalization(FTextureID texnum, const char* substitute); FNewGameStartup NewGameStartupInfo; int LastSkill = -1; +void StartGameDirect(bool hasPlayerClass, bool randomPlayerClass, PClassActor * playerClass, int Episode, int Skill) +{ + // shouldn't work outside of a menu + if (DMenu::InMenu) + { + NewGameStartupInfo.hasPlayerClass = hasPlayerClass; + + if(hasPlayerClass) + { + if(randomPlayerClass) + { + NewGameStartupInfo.PlayerClass = "Random"; + } + else if(!playerClass) + { + NullParam("playerClass"); + } + else + { + NewGameStartupInfo.PlayerClass = playerClass->GetDisplayName(); + } + } + + NewGameStartupInfo.Episode = Episode; + NewGameStartupInfo.Skill = Skill; + + G_DeferedInitNew (&NewGameStartupInfo); + + if (gamestate == GS_FULLCONSOLE) + { + gamestate = GS_HIDECONSOLE; + gameaction = ga_newgame; + } + + M_ClearMenus (); + } + else + { + ThrowAbortException(X_OTHER, "Attempt to start a new game outside of menu code"); + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(DPlayerMenu, StartGameDirect, StartGameDirect) +{ + PARAM_PROLOGUE; + PARAM_BOOL(hasPlayerClass); + PARAM_BOOL(randomPlayerClass); + PARAM_POINTER(playerClass, PClassActor); + PARAM_INT(Episode); + PARAM_INT(Skill); + StartGameDirect(hasPlayerClass, randomPlayerClass, playerClass, Episode, Skill); + return 0; +} bool M_SetSpecialMenu(FName& menu, int param) { @@ -127,9 +180,17 @@ bool M_SetSpecialMenu(FName& menu, int param) // sent from the player class menu NewGameStartupInfo.Skill = -1; NewGameStartupInfo.Episode = -1; - NewGameStartupInfo.PlayerClass = - param == -1000? nullptr : - param == -1? "Random" : GetPrintableDisplayName(PlayerClasses[param].Type).GetChars(); + + if(param == -1000) + { + NewGameStartupInfo.hasPlayerClass = false; + } + else + { + NewGameStartupInfo.hasPlayerClass = true; + NewGameStartupInfo.PlayerClass = (param == -1) ? FString("Random") : PlayerClasses[param].Type->GetDisplayName(); + } + M_StartupEpisodeMenu(&NewGameStartupInfo); // needs player class name from class menu (later) break; @@ -1180,7 +1241,7 @@ void M_StartupSkillMenu(FNewGameStartup *gs) DMenuItemBase *li = nullptr; FString *pItemText = nullptr; - if (gs->PlayerClass != nullptr) + if (gs->hasPlayerClass) { pItemText = skill.MenuNamesForPlayerClass.CheckKey(gs->PlayerClass); } @@ -1207,7 +1268,7 @@ void M_StartupSkillMenu(FNewGameStartup *gs) FName action = (skill.MustConfirm && !AllEpisodes[gs->Episode].mNoSkill) ? NAME_StartgameConfirm : NAME_Startgame; FString *pItemText = nullptr; - if (gs->PlayerClass != nullptr) + if (gs->hasPlayerClass) { pItemText = skill.MenuNamesForPlayerClass.CheckKey(gs->PlayerClass); } @@ -1277,7 +1338,7 @@ fail: "StartgameConfirm" : "Startgame"; FString *pItemText = nullptr; - if (gs->PlayerClass != nullptr) + if (gs->hasPlayerClass) { pItemText = skill.MenuNamesForPlayerClass.CheckKey(gs->PlayerClass); } diff --git a/src/menu/doommenu.h b/src/menu/doommenu.h index f80c7571fd..3e9b5a75aa 100644 --- a/src/menu/doommenu.h +++ b/src/menu/doommenu.h @@ -4,7 +4,8 @@ struct FNewGameStartup { - const char *PlayerClass; + bool hasPlayerClass; + FString PlayerClass; int Episode; int Skill; }; diff --git a/wadsrc/static/zscript/ui/menu/playermenu.zs b/wadsrc/static/zscript/ui/menu/playermenu.zs index 6404ac7133..38a577a6dc 100644 --- a/wadsrc/static/zscript/ui/menu/playermenu.zs +++ b/wadsrc/static/zscript/ui/menu/playermenu.zs @@ -40,6 +40,8 @@ class PlayerMenu : ListMenu PlayerClass mPlayerClass; Array PlayerColorSets; Array mPlayerSkins; + + static native void StartGameDirect(bool hasPlayerClass, bool randomPlayerClass, Class playerClass, int Episode, int Skill); // All write function for the player config are native to prevent abuse. static native void AutoaimChanged(float val);