From 194824f810a547c6931ac36a9845261c852fabbd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Oct 2020 09:16:37 +0100 Subject: [PATCH] - some fixes for the console. * it is now possible to switch back to the main intro loop from the fullscreen console. * do not distort the background of the fullscreen console. Always draw the console on top of what the main loop currently displays with a translucent black overlay. * do not use the CONPIC for the fullscreen console as it tends to be more of a distraction than an asset when filling the entire screen. * cleaned up c_console.cpp and moved several pieces of code unrelated to actual console management out of it. --- src/common/console/c_console.h | 3 - src/common/engine/i_interface.h | 1 + src/common/fonts/v_font.cpp | 1 + src/common/scripting/interface/vmnatives.cpp | 12 --- src/console/c_console.cpp | 81 +++++--------------- src/d_main.cpp | 9 +++ src/d_main.h | 4 + src/g_game.cpp | 27 ++++++- src/g_statusbar/hudmessages.cpp | 37 +++++++++ src/g_statusbar/sbar.h | 4 + src/gamedata/a_keys.cpp | 2 +- src/gamestate.h | 1 + src/menu/doommenu.cpp | 4 +- src/playsim/fragglescript/t_func.cpp | 2 +- src/scripting/vmthunks.cpp | 13 ++++ wadsrc/static/zscript/base.zs | 1 - wadsrc/static/zscript/doombase.zs | 5 ++ 17 files changed, 122 insertions(+), 85 deletions(-) diff --git a/src/common/console/c_console.h b/src/common/console/c_console.h index 88415b1fc..b0fb2cf04 100644 --- a/src/common/console/c_console.h +++ b/src/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/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index d50acb81b..cd400f441 100644 --- a/src/common/engine/i_interface.h +++ b/src/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/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index b90a74866..7f54e7bf1 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -819,6 +819,7 @@ void V_InitFonts() BigFont = OriginalBigFont; } AlternativeSmallFont = OriginalSmallFont; + AlternativeBigFont = OriginalBigFont; } void V_LoadTranslations() diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 25d5ccba8..bc98d7c20 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/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/src/console/c_console.cpp b/src/console/c_console.cpp index 345206ab7..3454172eb 100644 --- a/src/console/c_console.cpp +++ b/src/console/c_console.cpp @@ -68,6 +68,7 @@ #include "i_time.h" #include "texturemanager.h" #include "v_draw.h" +#include "i_interface.h" #include "gi.h" @@ -77,10 +78,6 @@ #define RIGHTMARGIN 8 #define BOTTOMARGIN 12 -extern bool hud_toggled; -void D_ToggleHud(); - - CUSTOM_CVAR(Int, con_buffersize, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { // ensure a minimum size @@ -95,7 +92,6 @@ static bool conline; extern int gametic; extern bool automapactive; // in AM_map.c -extern bool advancedemo; extern FBaseCVar *CVars; extern FConsoleCommand *Commands[FConsoleCommand::HASH_SIZE]; @@ -847,7 +843,7 @@ void C_DrawConsole () visheight = ConBottom; - if (conback.isValid()) + if (conback.isValid() && gamestate != GS_FULLCONSOLE) { DrawTexture (twod, TexMan.GetGameTexture(conback), 0, visheight - screen->GetHeight(), DTA_DestWidth, twod->GetWidth(), @@ -862,6 +858,7 @@ void C_DrawConsole () PalEntry pe((uint8_t)(con_alpha * 255), 0, 0, 0); twod->AddColorOnlyQuad(0, 0, screen->GetWidth(), visheight, pe); } + if (conline && visheight < screen->GetHeight()) { twod->AddColorOnlyQuad(0, visheight, screen->GetWidth(), 1, 0xff000000); @@ -947,35 +944,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; - primaryLevel->Music = ""; - S_Start (); - S_StopMusic(true); - P_FreeLevelData (); - } - else - { - C_AdjustBottom (); - } + gamestate = GS_FULLCONSOLE; + C_AdjustBottom (); } void C_ToggleConsole () { - if (gamestate == GS_DEMOSCREEN || demoplayback) + int togglestate; + if (gamestate == GS_INTRO) // blocked + { + return; + } + if (gamestate == GS_MENUSCREEN) { gameaction = ga_fullconsole; + togglestate = c_down; } else if (!chatmodeon && (ConsoleState == c_up || ConsoleState == c_rising) && menuactive == MENU_Off) { @@ -983,14 +970,17 @@ void C_ToggleConsole () HistPos = NULL; TabbedLast = false; TabbedList = false; - if (hud_toggled) - D_ToggleHud(); + 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 () @@ -1434,38 +1424,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 (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')); - } -} - diff --git a/src/d_main.cpp b/src/d_main.cpp index e8559652d..be7210c2c 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1080,6 +1080,7 @@ void D_Display () switch (gamestate) { case GS_FULLCONSOLE: + D_PageDrawer(); C_DrawConsole (); M_Drawer (); End2DAndUpdate (); @@ -2831,6 +2832,13 @@ FString System_GetPlayerName(int node) { return players[node].userinfo.GetName(); } + +void System_ConsoleToggled(int state) +{ + if (state == c_falling && hud_toggled) + D_ToggleHud(); +} + //========================================================================== // // DoomSpecificInfo @@ -3057,6 +3065,7 @@ static int D_DoomMain_Internal (void) StrTable_GetGender, nullptr, CheckSkipGameOptionBlock, + System_ConsoleToggled, }; diff --git a/src/d_main.h b/src/d_main.h index ad6929422..e2159af64 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -33,6 +33,10 @@ #include "startupinfo.h" #include "c_cvars.h" +extern bool advancedemo; +extern bool hud_toggled; +void D_ToggleHud(); + struct event_t; // diff --git a/src/g_game.cpp b/src/g_game.cpp index 81bc38e8b..fbe8fb55f 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -75,6 +75,8 @@ #include "i_system.h" #include "p_conversation.h" #include "v_palette.h" +#include "s_music.h" +#include "p_setup.h" #include "v_video.h" #include "g_hub.h" @@ -1048,6 +1050,29 @@ bool G_Responder (event_t *ev) ev->type == EV_Mouse); } + +static void G_FullConsole() +{ + int oldgs = gamestate; + + if (hud_toggled) + D_ToggleHud(); + if (demoplayback) + G_CheckDemoStatus(); + D_QuitNetGame(); + advancedemo = false; + C_FullConsole(); + + if (oldgs != GS_STARTUP) + { + primaryLevel->Music = ""; + S_Start(); + S_StopMusic(true); + P_FreeLevelData(); + } + +} + //========================================================================== // // FRandom :: StaticSumSeeds @@ -1158,7 +1183,7 @@ void G_Ticker () gameaction = ga_nothing; break; case ga_fullconsole: - C_FullConsole (); + G_FullConsole (); gameaction = ga_nothing; break; case ga_togglemap: diff --git a/src/g_statusbar/hudmessages.cpp b/src/g_statusbar/hudmessages.cpp index 21321ab19..0f97a980b 100644 --- a/src/g_statusbar/hudmessages.cpp +++ b/src/g_statusbar/hudmessages.cpp @@ -42,6 +42,7 @@ #include "serialize_obj.h" #include "doomstat.h" #include "vm.h" +#include "c_console.h" #include "v_draw.h" EXTERN_CVAR(Int, con_scaletext) @@ -890,3 +891,39 @@ void DHUDMessageTypeOnFadeOut::DoDraw (int linenum, int x, int y, bool clean, in DHUDMessageFadeOut::DoDraw (linenum, x, y, clean, hudheight); } } + +/* 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 (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')); + } +} + diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index bd4b719ad..b9b501846 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -540,6 +540,10 @@ extern FGameTexture *CrosshairImage; int GetInventoryIcon(AActor *item, uint32_t flags, int *applyscale = nullptr); +class FFont; +void C_MidPrint(FFont* font, const char* message, bool bold = false); + + enum DI_Flags { diff --git a/src/gamedata/a_keys.cpp b/src/gamedata/a_keys.cpp index 24c9211ec..d34e31caf 100644 --- a/src/gamedata/a_keys.cpp +++ b/src/gamedata/a_keys.cpp @@ -36,7 +36,7 @@ #include "gi.h" #include "gstrings.h" #include "d_player.h" -#include "c_console.h" +#include "sbar.h" #include "filesystem.h" #include "v_font.h" #include "vm.h" diff --git a/src/gamestate.h b/src/gamestate.h index 49f015c9a..21652392a 100644 --- a/src/gamestate.h +++ b/src/gamestate.h @@ -14,6 +14,7 @@ enum gamestate_t : int GS_STARTUP, // [RH] Console is fullscreen, and game is just starting GS_TITLELEVEL, // [RH] A combination of GS_LEVEL and GS_DEMOSCREEN GS_INTRO, + GS_MENUSCREEN = GS_DEMOSCREEN, GS_FORCEWIPE = -1, GS_FORCEWIPEFADE = -2, diff --git a/src/menu/doommenu.cpp b/src/menu/doommenu.cpp index 7fc4fa765..6a2de05cb 100644 --- a/src/menu/doommenu.cpp +++ b/src/menu/doommenu.cpp @@ -74,11 +74,8 @@ EXTERN_CVAR(Bool, show_messages) typedef void(*hfunc)(); DMenu* CreateMessageBoxMenu(DMenu* parent, const char* message, int messagemode, bool playsound, FName action = NAME_None, hfunc handler = nullptr); bool OkForLocalization(FTextureID texnum, const char* substitute); -void D_ToggleHud(); void I_WaitVBL(int count); -extern bool hud_toggled; - FNewGameStartup NewGameStartupInfo; @@ -1268,6 +1265,7 @@ void SetDefaultMenuColors() CCMD (menu_main) { + if (gamestate == GS_FULLCONSOLE) gamestate = GS_MENUSCREEN; M_StartControlPanel(true); M_SetMenu(NAME_Mainmenu, -1); } diff --git a/src/playsim/fragglescript/t_func.cpp b/src/playsim/fragglescript/t_func.cpp index 889d820f2..e0d85cfab 100644 --- a/src/playsim/fragglescript/t_func.cpp +++ b/src/playsim/fragglescript/t_func.cpp @@ -37,7 +37,7 @@ #include "templates.h" #include "p_local.h" #include "t_script.h" -#include "c_console.h" +#include "sbar.h" #include "c_dispatch.h" #include "d_player.h" #include "filesystem.h" diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 5076ddae4..cbcc2dc72 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -2738,6 +2738,19 @@ DEFINE_ACTION_FUNCTION(_Screen, GetViewWindow) return MIN(numret, 4); } +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; +} + + //========================================================================== // // 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/doombase.zs b/wadsrc/static/zscript/doombase.zs index 3e0e80a58..68569dd5f 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -42,6 +42,11 @@ extend struct Screen } } +extend struct Console +{ + native static void MidPrint(Font fontname, string textlabel, bool bold = false); +} + extend struct Translation { Color colors[256];