From 7b9887561acba9f7f64114ff813116b2d43195ce Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 8 Apr 2022 16:45:55 +0200 Subject: [PATCH] Fix #2682 "Bad welcome dialog's backwards compatibility"; behaviour of the welcome message key is slightly different in old servers: on key press it shows the message for 2 seconds and then hides it --- qcsrc/menu/menu.qc | 11 ++++++++--- qcsrc/menu/xonotic/dialog_welcome.qc | 21 +++++++++++++++++++-- qcsrc/menu/xonotic/dialog_welcome.qh | 2 ++ xonotic-client.cfg | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index d26066d19..f2a71d967 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -672,6 +672,7 @@ void m_tooltip(vector pos) } } +const int MIN_DISCONNECTION_TIME = 1; float autocvar_menu_force_on_disconnection; bool autocvar_g_campaign; void m_draw(float width, float height) @@ -681,7 +682,7 @@ void m_draw(float width, float height) { if (autocvar_g_campaign) { - if (connected_time && time - connected_time > 1) + if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME) { // in the case player uses the disconnect command (in the console or with a key) // reset g_campaign and update menu items to reflect cvar values that may have been restored after quiting the campaign @@ -692,12 +693,16 @@ void m_draw(float width, float height) } if (autocvar_menu_force_on_disconnection > 0) { - if (connected_time && time - connected_time > autocvar_menu_force_on_disconnection) + if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME) { m_toggle(true); - connected_time = 0; } } + if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME) + { + localcmd("\nmenu_cmd directmenu Welcome RESET\n"); + connected_time = 0; + } } else connected_time = time; diff --git a/qcsrc/menu/xonotic/dialog_welcome.qc b/qcsrc/menu/xonotic/dialog_welcome.qc index 787393158..a7646047e 100644 --- a/qcsrc/menu/xonotic/dialog_welcome.qc +++ b/qcsrc/menu/xonotic/dialog_welcome.qc @@ -9,8 +9,8 @@ void welcomeDialog_resetStrings(entity me) { - strcpy(me.serverinfo_name, ""); - strcpy(me.serverinfo_MOTD, ""); + strcpy(me.serverinfo_name, _("Welcome")); + strcpy(me.serverinfo_MOTD, ""); } float XonoticWelcomeDialog_keyDown(entity me, float key, float ascii, float shift) @@ -56,6 +56,11 @@ void XonoticWelcomeDialog_readInputArgs(entity me, int argsbuf) strcpy(me.serverinfo_name, bufstr_get(argsbuf, ++i)); else if(s == "WELCOME") strcpy(me.serverinfo_MOTD, bufstr_get(argsbuf, ++i)); + else if(s == "RESET") + { + welcomeDialog_resetStrings(me); + break; + } ++i; } //me.serverinfo_name_ent.setText(me.serverinfo_name_ent, me.serverinfo_name); @@ -63,6 +68,18 @@ void XonoticWelcomeDialog_readInputArgs(entity me, int argsbuf) me.frame.setText(me.frame, me.serverinfo_name); } +void XonoticWelcomeDialog_draw(entity me) +{ + SUPER(XonoticWelcomeDialog).draw(me); + if(me.serverinfo_MOTD == "" && gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) + { + // if serverinfo_MOTD is empty while connected it means we are connected to an old server + // in this case show the csqc welcome message and instantly close the dialog + localcmd("\n+show_info0; defer 2 -show_info0\n"); + me.close(me); + } +} + void XonoticWelcomeDialog_fill(entity me) { registercvar("_menu_welcome_dialog_available", "0", 0); diff --git a/qcsrc/menu/xonotic/dialog_welcome.qh b/qcsrc/menu/xonotic/dialog_welcome.qh index 4a6394285..d02cd6e73 100644 --- a/qcsrc/menu/xonotic/dialog_welcome.qh +++ b/qcsrc/menu/xonotic/dialog_welcome.qh @@ -10,6 +10,7 @@ CLASS(XonoticWelcomeDialog, XonoticRootDialog) ATTRIB(XonoticWelcomeDialog, columns, float, 4); ATTRIB(XonoticWelcomeDialog, name, string, "Welcome"); + METHOD(XonoticWelcomeDialog, draw, void(entity)); METHOD(XonoticWelcomeDialog, mouseRelease, bool(entity, vector)); METHOD(XonoticWelcomeDialog, keyDown, float(entity, float, float, float)); METHOD(XonoticWelcomeDialog, destroy, void(entity)); @@ -18,4 +19,5 @@ CLASS(XonoticWelcomeDialog, XonoticRootDialog) //ATTRIB(XonoticWelcomeDialog, serverinfo_name_ent, entity, world); ATTRIB(XonoticWelcomeDialog, serverinfo_MOTD, string, string_null); ATTRIB(XonoticWelcomeDialog, serverinfo_MOTD_ent, entity, world); + ATTRIB(XonoticWelcomeDialog, requiresConnection, bool, true); ENDCLASS(XonoticWelcomeDialog) diff --git a/xonotic-client.cfg b/xonotic-client.cfg index 2a4c2c5c7..940ff2e26 100644 --- a/xonotic-client.cfg +++ b/xonotic-client.cfg @@ -493,7 +493,7 @@ seta menu_tooltips 1 "menu tooltips: 0 disabled, 1 enabled, 2 also shows cvar or set menu_picmip_bypass 0 "bypass texture quality enforcement based on system resources, not recommended and may cause crashes!" set menu_showboxes 0 "show item bounding boxes (debug)" set menu_cvarlist_onlymodified 0 "show only modified cvars in the cvar list" -set menu_force_on_disconnection 1 "force to show the menu this number of seconds after you get disconnected (0 to disable)" +set menu_force_on_disconnection 1 "force to show the menu after you get disconnected" set _menu_credits_export 0 "set to 1 and restart the menu to export credits to credits.txt (menu will automatically reset to 0)" alias menu_credits_export "_menu_credits_export 1; menu_restart" -- 2.39.2