From 273ad5e133bae9518ed697ed3fdff9ab63df4b40 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Oct 2020 09:20:26 +0100 Subject: [PATCH] - backend update --- source/common/console/c_console.h | 3 - source/common/engine/i_interface.h | 1 + .../common/scripting/interface/vmnatives.cpp | 12 ---- source/core/console/c_console.cpp | 65 +++---------------- source/core/gamestate.h | 2 + source/core/mainloop.cpp | 6 ++ wadsrc/static/zscript/base.zs | 1 - .../static/zscript/ui/menu/optionmenuitems.zs | 62 ++++++++++++++++++ 8 files changed, 81 insertions(+), 71 deletions(-) diff --git a/source/common/console/c_console.h b/source/common/console/c_console.h index 88415b1fc..b0fb2cf04 100644 --- a/source/common/console/c_console.h +++ b/source/common/console/c_console.h @@ -77,9 +77,6 @@ void C_HideConsole (void); void C_AdjustBottom (void); void C_FlushDisplay (void); -class FFont; -void C_MidPrint (FFont *font, const char *message, bool bold = false); - bool C_Responder (event_t *ev); void C_SetNotifyFontScale(double scale); diff --git a/source/common/engine/i_interface.h b/source/common/engine/i_interface.h index d50acb81b..cd400f441 100644 --- a/source/common/engine/i_interface.h +++ b/source/common/engine/i_interface.h @@ -26,6 +26,7 @@ struct SystemCallbacks int (*GetGender)(); void (*MenuClosed)(); bool (*CheckMenudefOption)(const char* opt); + void (*ConsoleToggled)(int state); }; extern SystemCallbacks sysCallbacks; diff --git a/source/common/scripting/interface/vmnatives.cpp b/source/common/scripting/interface/vmnatives.cpp index 25d5ccba8..bc98d7c20 100644 --- a/source/common/scripting/interface/vmnatives.cpp +++ b/source/common/scripting/interface/vmnatives.cpp @@ -637,18 +637,6 @@ DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand) return 0; } -DEFINE_ACTION_FUNCTION(_Console, MidPrint) -{ - PARAM_PROLOGUE; - PARAM_POINTER(fnt, FFont); - PARAM_STRING(text); - PARAM_BOOL(bold); - - const char* txt = text[0] == '$' ? GStrings(&text[1]) : text.GetChars(); - C_MidPrint(fnt, txt, bold); - return 0; -} - DEFINE_ACTION_FUNCTION(_Console, HideConsole) { C_HideConsole(); diff --git a/source/core/console/c_console.cpp b/source/core/console/c_console.cpp index 1241e7b9b..816b20e44 100644 --- a/source/core/console/c_console.cpp +++ b/source/core/console/c_console.cpp @@ -1012,37 +1012,25 @@ void C_DrawConsole () void C_FullConsole () { - /* - if (hud_toggled) - D_ToggleHud(); - if (demoplayback) - G_CheckDemoStatus (); - D_QuitNetGame (); - advancedemo = false; - */ ConsoleState = c_down; HistPos = NULL; TabbedLast = false; TabbedList = false; - if (gamestate != GS_STARTUP) - { - gamestate = GS_FULLCONSOLE; - Mus_Stop(); - } + gamestate = GS_FULLCONSOLE; C_AdjustBottom (); } - void C_ToggleConsole () { + int togglestate; if (gamestate == GS_INTRO) // blocked { return; } if (gamestate == GS_MENUSCREEN) { - gamestate = GS_FULLCONSOLE; - C_FullConsole(); + gameaction = ga_fullconsole; + togglestate = c_down; } else if (!chatmodeon && (ConsoleState == c_up || ConsoleState == c_rising) && menuactive == MENU_Off) { @@ -1050,13 +1038,17 @@ void C_ToggleConsole () HistPos = NULL; TabbedLast = false; TabbedList = false; - + togglestate = c_falling; } else if (gamestate != GS_FULLCONSOLE && gamestate != GS_STARTUP) { ConsoleState = c_rising; - C_FlushDisplay (); + C_FlushDisplay(); + togglestate = c_rising; } + else return; + // This must be done as an event callback because the client code does not control the console toggling. + if (sysCallbacks.ConsoleToggled) sysCallbacks.ConsoleToggled(togglestate); } void C_HideConsole () @@ -1500,40 +1492,3 @@ CCMD(toggleconsole) C_ToggleConsole(); } -/* Printing in the middle of the screen */ - -CVAR(Float, con_midtime, 3.f, CVAR_ARCHIVE) - -const char *console_bar = "----------------------------------------"; - -void C_MidPrint (FFont *font, const char *msg, bool bold) -{ -#if 0 // The Build engine cannot do this at the moment. Q: Implement and redirect some messages here? - if (StatusBar == nullptr || screen == nullptr) - return; - - // [MK] allow the status bar to take over MidPrint - IFVIRTUALPTR(StatusBar, DBaseStatusBar, ProcessMidPrint) - { - FString msgstr = msg; - VMValue params[] = { (DObject*)StatusBar, font, &msgstr, bold }; - int rv; - VMReturn ret(&rv); - VMCall(func, params, countof(params), &ret, 1); - if (!!rv) return; - } - - if (msg != nullptr) - { - auto color = (EColorRange)PrintColors[bold? PRINTLEVELS+1 : PRINTLEVELS]; - Printf(PRINT_HIGH|PRINT_NONOTIFY, TEXTCOLOR_ESCAPESTR "%c%s\n%s\n%s\n", color, console_bar, msg, console_bar); - - StatusBar->AttachMessage (Create(font, msg, 1.5f, 0.375f, 0, 0, color, con_midtime), MAKE_ID('C','N','T','R')); - } - else - { - StatusBar->DetachMessage (MAKE_ID('C','N','T','R')); - } -#endif -} - diff --git a/source/core/gamestate.h b/source/core/gamestate.h index 8a601e86b..523ead5d0 100644 --- a/source/core/gamestate.h +++ b/source/core/gamestate.h @@ -43,6 +43,8 @@ enum gameaction_t : int ga_nextlevel, // Actually start the next level. ga_loadgamehidecon, ga_newgamenostopsound, // start a new game + + ga_fullconsole, }; extern gamestate_t gamestate; extern gameaction_t gameaction; diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 5e56e44b7..a5028693b 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -244,6 +244,12 @@ static void GameTicker() gamestate = GS_INTERMISSION; break; + case ga_fullconsole: + C_FullConsole(); + Mus_Stop(); + gameaction = ga_nothing; + break; + // for later // case ga_recordgame, // start a new demo recording (later) // case ga_loadgameplaydemo, // load a savegame and play a demo. diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index 4f0e64f9a..a62ea5f1a 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -493,7 +493,6 @@ struct Font native struct Console native { native static void HideConsole(); - native static void MidPrint(Font fontname, string textlabel, bool bold = false); native static vararg void Printf(string fmt, ...); } diff --git a/wadsrc/static/zscript/ui/menu/optionmenuitems.zs b/wadsrc/static/zscript/ui/menu/optionmenuitems.zs index 3a69f5bee..c56b4796d 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenuitems.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenuitems.zs @@ -1234,3 +1234,65 @@ class OptionMenuItemScaleSlider : OptionMenuItemSlider } +//============================================================================= +// +// Flag option by Accensus +// +//============================================================================= + +class OptionMenuItemFlagOption : OptionMenuItemOption +{ + int mBitShift; + + OptionMenuItemFlagOption Init(String label, Name command, Name values, int bitShift, CVar greycheck = null, int center = 0) + { + Super.Init(label, command, values, greycheck, center); + mBitShift = bitShift; + + return self; + } + + override int GetSelection() + { + int Selection = 0; + int cnt = OptionValues.GetCount(mValues); + if (cnt > 0 && mCVar != null) + { + if (OptionValues.GetTextValue(mValues, 0).Length() == 0) + { + int CurrentFlags = mCVar.GetInt(); + + for (int i = 0; i < cnt; i++) + { + int OptionValue = int(OptionValues.GetValue(mValues, i)); + if (CurrentFlags & (OptionValue << mBitShift)) + { + Selection = i; + break; + } + } + } + } + return Selection; + } + + override void SetSelection(int Selection) + { + int cnt = OptionValues.GetCount(mValues); + if (cnt > 0 && mCVar != null) + { + if (OptionValues.GetTextValue(mValues, 0).Length() == 0) + { + int OptionValue = int(OptionValues.GetValue(mValues, Selection)); + int CurrentFlags = mCVar.GetInt(); + + switch (OptionValue) + { + case 0: CurrentFlags &= ~(1 << mBitShift); break; + case 1: CurrentFlags |= (1 << mBitShift); break; + } + mCVar.SetInt(CurrentFlags); + } + } + } +} \ No newline at end of file