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

This commit is contained in:
Marco Cawthorne 2020-09-27 14:25:10 +02:00
parent 54f0c5d24c
commit 57cc661c86
9 changed files with 123 additions and 35 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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 );

View File

@ -16,6 +16,7 @@
int g_iMenuActive;
vector video_res;
var int g_background = FALSE;
var float frametime;
var float lasttime;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}