From 57cc661c86cd2bde6155b745aef448b35a2993c7 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Sun, 27 Sep 2020 14:25:10 +0200 Subject: [PATCH] Menu/Client/Server: Background map support for menus. This should be handled differently in that SV_ShouldPause ought to control Singleplayer as well. Engine hardcodes suck --- src/client/entry.c | 12 ++++- src/menu-fn/defs.h | 1 + src/menu-fn/entry.cpp | 20 ++++++-- src/menu-fn/m_main.cpp | 4 +- src/menu-vgui/background.cpp | 3 +- src/menu-vgui/defs.h | 1 + src/menu-vgui/main.cpp | 94 ++++++++++++++++++++++++++---------- src/server/entry.c | 17 +++++++ src/vgui/ui_menubutton.cpp | 6 +-- 9 files changed, 123 insertions(+), 35 deletions(-) diff --git a/src/client/entry.c b/src/client/entry.c index c7cf19e6..bb13d067 100644 --- a/src/client/entry.c +++ b/src/client/entry.c @@ -150,6 +150,12 @@ CSQC_UpdateView(float w, float h, float focus) video_res[0] = w; video_res[1] = h; + cvar_set("_background", serverkey("background")); + + if (serverkeyfloat("background") == 1) { + setpause(FALSE); + } + if (g_iCubeProcess == TRUE) { clearscene(); setproperty(VF_DRAWWORLD, TRUE); @@ -430,13 +436,17 @@ CSQC_Input_Frame(void) int s = (float)getproperty(VF_ACTIVESEAT); pSeat = &g_seats[s]; - // If we are inside a VGUI, don't let the client do stuff outside + /* If we are inside a VGUI, don't let the client do stuff outside */ if (g_vguiWidgetCount > 0) { input_impulse = 0; input_buttons = 0; return; } + /* background maps have no input */ + if (serverkeyfloat("background") == 1) + return; + /* The HUD needs more time */ if ((pSeat->m_iHUDWeaponSelected) && (input_buttons & INPUT_BUTTON0)) { HUD_DrawWeaponSelect_Trigger(); diff --git a/src/menu-fn/defs.h b/src/menu-fn/defs.h index 5d89f091..fc0b7fe0 100644 --- a/src/menu-fn/defs.h +++ b/src/menu-fn/defs.h @@ -33,6 +33,7 @@ int g_lastmousepos[2]; int g_active; float g_btnofs; float frametime; +var int g_background = FALSE; /* Font IDs */ int font_label; diff --git a/src/menu-fn/entry.cpp b/src/menu-fn/entry.cpp index 48715582..70860919 100644 --- a/src/menu-fn/entry.cpp +++ b/src/menu-fn/entry.cpp @@ -95,6 +95,7 @@ m_init(void) print("\n\n"); registercommand("menu_customgame"); + registercommand("map_background"); font_console = loadfont("font", "", "12", -1); font_label = loadfont("label", "gfx/shell/mssansserif.ttf", "10 12 14", -1); font_arial = loadfont("label", "gfx/shell/arial.ttf", "14 11 12", -1); @@ -181,15 +182,24 @@ m_draw(vector screensize) Menu_AutoScale(); } + g_background = cvar("_background"); + + if (g_background) { + setkeydest(KEY_MENU); + setmousetarget(TARGET_MENU); + setcursormode(TRUE, "gfx/cursor"); + } + /* to prevent TCP timeouts */ menu_chatrooms_keepalive(); - if (!g_active) { + if (!g_active && !g_background) { return; } if (clientstate() == 2) { - drawfill([0,0], screensize, [0,0,0], 0.75f); + if (!g_background) + drawfill([0,0], screensize, [0,0,0], 0.75f); } else { drawfill([0,0], screensize, [0,0,0], 1.0f); drawpic([g_menuofs[0],g_menuofs[1]], g_bmp[SPLASH], @@ -226,7 +236,7 @@ Menu_InputEvent(float evtype, float scanx, float chary, float devid) switch (evtype) { case IE_KEYDOWN: if (chary == K_ESCAPE) { - if (clientstate() == 2) { + if (clientstate() == 2 && !g_background) { m_toggle(0); } } @@ -301,6 +311,10 @@ m_consolecommand(string cmd) case "togglemenu": m_display(); break; + case "map_background": + localcmd(sprintf("maxplayers 2\nset coop 1\nset sv_background 1\nmap %s\n", + argv(1))); + break; default: return FALSE; } diff --git a/src/menu-fn/m_main.cpp b/src/menu-fn/m_main.cpp index 6ae51d7e..d9130c9e 100644 --- a/src/menu-fn/m_main.cpp +++ b/src/menu-fn/m_main.cpp @@ -351,7 +351,7 @@ menu_main_init(void) void menu_main_draw(void) { - if (clientstate() == 2) { + if (clientstate() == 2 && !g_background) { Widget_Draw(fn_main2); WLabel_Static(235, 216, m_reslbl[IDS_MAIN_RETURNHELP], 10, 10, col_help,1.0f, 0, font_label); @@ -429,7 +429,7 @@ menu_main_input(float evtype, float scanx, float chary, float devid) if (main_quitdialog) { Widget_Input(main_dgQuit, evtype, scanx, chary, devid); } else { - if (clientstate() == 2) { + if (clientstate() == 2 && !g_background) { Widget_Input(fn_main2, evtype, scanx, chary, devid); } else { Widget_Input(fn_main, evtype, scanx, chary, devid); diff --git a/src/menu-vgui/background.cpp b/src/menu-vgui/background.cpp index 2934b301..36f108d8 100755 --- a/src/menu-vgui/background.cpp +++ b/src/menu-vgui/background.cpp @@ -36,7 +36,8 @@ void Background_Init ( void ) void Background_Draw ( vector vecSize ) { if ( clientstate() == 2 ) { - drawfill( [ 0, 0 ], vecSize, [ 0, 0, 0 ], 0.5f ); + if (!g_background) + drawfill( [ 0, 0 ], vecSize, [ 0, 0, 0 ], 0.5f ); } else { if ( g_iBackgroundLoaded == TRUE ) { drawpic( [ 0, 0 ], BACKGROUND_IMG, vecSize, [ 1, 1, 1 ], 1.0f ); diff --git a/src/menu-vgui/defs.h b/src/menu-vgui/defs.h index 5ce2ca73..473611a9 100755 --- a/src/menu-vgui/defs.h +++ b/src/menu-vgui/defs.h @@ -16,6 +16,7 @@ int g_iMenuActive; vector video_res; +var int g_background = FALSE; var float frametime; var float lasttime; diff --git a/src/menu-vgui/main.cpp b/src/menu-vgui/main.cpp index a9d9045f..75879fec 100755 --- a/src/menu-vgui/main.cpp +++ b/src/menu-vgui/main.cpp @@ -41,6 +41,7 @@ void m_init ( void ) registercommand( "menu_quit" ); registercommand( "menu_music" ); + registercommand( "map_background" ); Menu_AutoScale(); } @@ -62,7 +63,15 @@ void m_draw ( vector vecScreensize ) Menu_AutoScale(); } - if ( !g_iMenuActive ) { + g_background = cvar("_background"); + + if (g_background) { + setkeydest(KEY_MENU); + setmousetarget(TARGET_MENU); + setcursormode(TRUE, "gfx/cursor"); + } + + if ( !g_iMenuActive && !g_background ) { return; } @@ -74,26 +83,57 @@ void m_draw ( vector vecScreensize ) Desktop_Draw(); } -float Menu_InputEvent ( float flEvType, float flScanX, float flCharY, float flDevID ) +float Menu_InputEvent ( float evtype, float scanx, float chary, float devid ) { - g_uiDesktop.Input( flEvType, flScanX, flCharY, flDevID ); + switch (evtype) { + case IE_KEYDOWN: + if (chary == K_ESCAPE) { + if (clientstate() == 2 && !g_background) { + m_toggle(0); + } + } + break; + } + + g_uiDesktop.Input( evtype, scanx, chary, devid ); return (float)g_iMenuActive; } -void m_toggle ( float flWantMode ) +void +m_display(void) { - dprint( sprintf( "[MENU] m_toggle: %d\n", flWantMode ) ); + g_iMenuActive = TRUE; + setkeydest(KEY_MENU); + setmousetarget(TARGET_MENU); + setcursormode(TRUE, "gfx/cursor"); +} - if ( flWantMode == 0 ) { - g_iMenuActive = FALSE; - setkeydest( KEY_GAME ); - setmousetarget( TARGET_CLIENT ); - setcursormode( FALSE ); +/* +================= +m_hide +================= +*/ +void +m_hide(void) +{ + g_iMenuActive = FALSE; + setkeydest(KEY_GAME); + setmousetarget(TARGET_CLIENT); + setcursormode(FALSE); +} + +/* +================= +m_toggle +================= +*/ +void +m_toggle(float fMode) +{ + if (fMode == FALSE) { + m_hide(); } else { - g_iMenuActive = TRUE; - setkeydest( KEY_MENU ); - setmousetarget( TARGET_MENU ); - setcursormode( TRUE, "gfx/cursor" ); + m_display(); } } @@ -103,17 +143,21 @@ float m_consolecommand ( string strCommand ) tokenize( strCommand ); switch ( argv( 0 ) ) { - case "menu_quit": - UI_QuitGame_Show(); - break; - case "menu_music": - UI_MusicPlayer_Show(); - break; - case "showconsole": - UI_Console_Show(); - break; - default: - return FALSE; + case "menu_quit": + UI_QuitGame_Show(); + break; + case "menu_music": + UI_MusicPlayer_Show(); + break; + case "showconsole": + UI_Console_Show(); + break; + case "map_background": + localcmd(sprintf("maxplayers 2\nset coop 1\nset sv_background 1\nmap %s\n", + argv(1))); + break; + default: + return FALSE; } return TRUE; diff --git a/src/server/entry.c b/src/server/entry.c index 916f8ec9..9ff35d49 100644 --- a/src/server/entry.c +++ b/src/server/entry.c @@ -243,6 +243,14 @@ void initents(void) entity respawntimer = spawn(); respawntimer.think = init_respawn; respawntimer.nextthink = time + 0.1f; + + /* menu background lock */ + if (cvar("sv_background") == 1) { + forceinfokey(world, "background", "1"); + localcmd("sv_background 0\n"); + } else { + forceinfokey(world, "background", "0"); + } } void worldspawn(void) @@ -268,3 +276,12 @@ float ConsoleCmd(string cmd) player pl = (player)self; return g_grMode.ConsoleCommand(pl, cmd); } + +float SV_ShouldPause(float newstatus) +{ + if (serverkeyfloat("background") == 1) { + return FALSE; + } + + return newstatus; +} diff --git a/src/vgui/ui_menubutton.cpp b/src/vgui/ui_menubutton.cpp index 1bce3974..739ba754 100644 --- a/src/vgui/ui_menubutton.cpp +++ b/src/vgui/ui_menubutton.cpp @@ -54,12 +54,12 @@ void CUIMenuButton::CUIMenuButton(void) void CUIMenuButton::Draw(void) { // If we're not ingame - if (clientstate() != 2) { - if (!(m_iFlags & MBUTTON_SHOWOFFLINE)) { + if (clientstate() == 2 && !g_background) { + if (!(m_iFlags & MBUTTON_SHOWSP)) { return; } } else { - if (!(m_iFlags & MBUTTON_SHOWSP)) { + if (!(m_iFlags & MBUTTON_SHOWOFFLINE)) { return; } }