From 9a80d149a0ae2afdab329a8f79b10a6b29018c04 Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 22 Aug 2013 10:20:45 +0200 Subject: [PATCH] Properly network the MOTD message and display it in the Welcome dialog by using the new class TextListBox --- qcsrc/client/Main.qc | 5 +- qcsrc/menu/classes.c | 1 + qcsrc/menu/command/menu_cmd.qc | 16 +++++-- qcsrc/menu/xonotic/dialog_welcome.c | 38 ++++++++------- qcsrc/menu/xonotic/textlistbox.c | 74 +++++++++++++++++++++++++++++ qcsrc/server/cl_client.qc | 3 +- 6 files changed, 114 insertions(+), 23 deletions(-) create mode 100644 qcsrc/menu/xonotic/textlistbox.c diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index 973325c38..c36543bab 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -1189,7 +1189,10 @@ void Net_WeaponComplain() void Net_ReadServerInfo() { - localcmd("\nmenu_cmd directmenu Welcome serverinfo_name \"", ReadString() , "\" serverinfo_ip \"", ReadString(), "\" serverinfo_MOTD \"", ReadString(), "\"\n"); + localcmd("\nmenu_cmd directmenu Welcome serverinfo_name \"", ReadString(), + "\" serverinfo_ip \"", ReadString(), + "\" serverinfo_MOTD \"", strreplace("\n", "\\n", ReadString()), + "\"\n"); } // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer. diff --git a/qcsrc/menu/classes.c b/qcsrc/menu/classes.c index f1f4905bf..e43282060 100644 --- a/qcsrc/menu/classes.c +++ b/qcsrc/menu/classes.c @@ -54,6 +54,7 @@ #include "xonotic/dialog_multiplayer_join_serverinfo.c" #include "xonotic/playerlist.c" #include "xonotic/listbox.c" +#include "xonotic/textlistbox.c" #include "xonotic/serverlist.c" #include "xonotic/inputbox.c" #include "xonotic/dialog_quit.c" diff --git a/qcsrc/menu/command/menu_cmd.qc b/qcsrc/menu/command/menu_cmd.qc index f4d056539..4b59146bc 100644 --- a/qcsrc/menu/command/menu_cmd.qc +++ b/qcsrc/menu/command/menu_cmd.qc @@ -82,13 +82,23 @@ void GameCommand(string theCommand) m_goto(strcat(filter, argv(1))); // switch to a menu item else if(argc > 2 && !isdemo()) { + float argsbuf = 0; + s = strzone(argv(1)); // dialog name for(i = 0, e = world; (e = nextent(e)); ) - if(e.classname != "vtbl" && e.name == strcat(filter, argv(1))) + if(e.classname != "vtbl" && e.name == strcat(filter, s)) + { + argsbuf = buf_create(); + if(argsbuf >= 0) if(e.readInputArgs) { - e.readInputArgs(e, 2, argc - 1); - m_goto(strcat(filter, argv(1))); + for(i = 2; i < argc; ++i) + bufstr_add(argsbuf, argv(i), 1); + e.readInputArgs(e, argsbuf); + m_goto(strcat(filter, s)); } + if(argsbuf >= 0) + buf_del(argsbuf); + } } if(filter) strunzone(filter); diff --git a/qcsrc/menu/xonotic/dialog_welcome.c b/qcsrc/menu/xonotic/dialog_welcome.c index 837797831..97982c6d3 100644 --- a/qcsrc/menu/xonotic/dialog_welcome.c +++ b/qcsrc/menu/xonotic/dialog_welcome.c @@ -4,12 +4,12 @@ CLASS(XonoticWelcomeDialog) EXTENDS(XonoticRootDialog) ATTRIB(XonoticWelcomeDialog, title, string, _("Welcome")) ATTRIB(XonoticWelcomeDialog, color, vector, SKINCOLOR_DIALOG_WELCOME) ATTRIB(XonoticWelcomeDialog, intendedWidth, float, 0.7) - ATTRIB(XonoticWelcomeDialog, rows, float, 16) + ATTRIB(XonoticWelcomeDialog, rows, float, 14) ATTRIB(XonoticWelcomeDialog, columns, float, 4) ATTRIB(XonoticWelcomeDialog, name, string, "Welcome") METHOD(XonoticWelcomeDialog, configureDialog, void(entity)) - METHOD(XonoticWelcomeDialog, readInputArgs, void(entity, float, float)) + METHOD(XonoticWelcomeDialog, readInputArgs, void(entity, float)) ATTRIB(XonoticWelcomeDialog, serverinfo_name, string, string_null) ATTRIB(XonoticWelcomeDialog, serverinfo_name_ent, entity, world) ATTRIB(XonoticWelcomeDialog, serverinfo_ip, string, string_null) @@ -39,37 +39,39 @@ void XonoticWelcomeDialog_configureDialog(entity me) welcomeDialog_resetStrings(me); SUPER(XonoticWelcomeDialog).configureDialog(me); } -void XonoticWelcomeDialog_readInputArgs(entity me, float starting_arg, float arg_count) +void XonoticWelcomeDialog_readInputArgs(entity me, float argsbuf) { - float i; + float i = 0; + string s; welcomeDialog_resetStrings(me); - for(i = starting_arg; i < arg_count; ++i) + while((s = bufstr_get(argsbuf, i)) != "") { - if(argv(i) == "serverinfo_name") + if(s == "serverinfo_name") { if(me.serverinfo_name) strunzone(me.serverinfo_name); - me.serverinfo_name = strzone(argv(i + 1)); - me.serverinfo_name_ent.setText(me.serverinfo_name_ent, me.serverinfo_name); + me.serverinfo_name = strzone(bufstr_get(argsbuf, i + 1)); ++i; } - else if(argv(i) == "serverinfo_ip") + else if(s == "serverinfo_ip") { if(me.serverinfo_ip) strunzone(me.serverinfo_ip); - me.serverinfo_ip = strzone(argv(i + 1)); - me.serverinfo_ip_ent.setText(me.serverinfo_ip_ent, me.serverinfo_ip); + me.serverinfo_ip = strzone(bufstr_get(argsbuf, i + 1)); ++i; } - else if(argv(i) == "serverinfo_MOTD") + else if(s == "serverinfo_MOTD") { if(me.serverinfo_MOTD) strunzone(me.serverinfo_MOTD); - me.serverinfo_MOTD = strzone(argv(i + 1)); - me.serverinfo_MOTD_ent.setText(me.serverinfo_MOTD_ent, me.serverinfo_MOTD); + me.serverinfo_MOTD = strzone(bufstr_get(argsbuf, i + 1)); ++i; } + ++i; } + me.serverinfo_name_ent.setText(me.serverinfo_name_ent, me.serverinfo_name); + me.serverinfo_ip_ent.setText(me.serverinfo_ip_ent, me.serverinfo_ip); + me.serverinfo_MOTD_ent.setText(me.serverinfo_MOTD_ent, me.serverinfo_MOTD); } void XonoticWelcomeDialog_fill(entity me) @@ -82,8 +84,10 @@ void XonoticWelcomeDialog_fill(entity me) me.TD(me, 1, 4, me.serverinfo_ip_ent = makeXonoticTextLabel(0.5, "")); me.TR(me); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0.5, _("MOTD"))); - me.TR(me); - me.TD(me, 1, 4, me.serverinfo_MOTD_ent = makeXonoticTextLabel(0.5, "")); + me.TD(me, 10, 4, me.serverinfo_MOTD_ent = makeXonoticTextListBox()); + me.serverinfo_MOTD_ent.allowColors = 1; + me.gotoRC(me, me.rows - 1, 0); + me.TDempty(me, 1); + me.TD(me, 1, 2, e = makeXonoticCommandButton(_("Disconnect"), '0 0 0', "disconnect", COMMANDBUTTON_CLOSE)); } #endif diff --git a/qcsrc/menu/xonotic/textlistbox.c b/qcsrc/menu/xonotic/textlistbox.c new file mode 100644 index 000000000..45bbc986c --- /dev/null +++ b/qcsrc/menu/xonotic/textlistbox.c @@ -0,0 +1,74 @@ +#ifdef INTERFACE +CLASS(XonoticTextListBox) EXTENDS(ListBox) + METHOD(XonoticTextListBox, configureXonoticTextListBox, void(entity)) + ATTRIB(XonoticTextListBox, fontSize, float, SKINFONTSIZE_NORMAL) + ATTRIB(XonoticTextListBox, scrollbarWidth, float, SKINWIDTH_SCROLLBAR) + ATTRIB(XonoticTextListBox, src, string, SKINGFX_SCROLLBAR) + ATTRIB(XonoticTextListBox, tolerance, vector, SKINTOLERANCE_SLIDER) + ATTRIB(XonoticTextListBox, rowsPerItem, float, 1) + METHOD(XonoticTextListBox, resizeNotify, void(entity, vector, vector, vector, vector)) + ATTRIB(XonoticTextListBox, color, vector, SKINCOLOR_SCROLLBAR_N) + ATTRIB(XonoticTextListBox, colorF, vector, SKINCOLOR_SCROLLBAR_F) + ATTRIB(XonoticTextListBox, color2, vector, SKINCOLOR_SCROLLBAR_S) + ATTRIB(XonoticTextListBox, colorC, vector, SKINCOLOR_SCROLLBAR_C) + ATTRIB(XonoticTextListBox, colorBG, vector, SKINCOLOR_LISTBOX_BACKGROUND) + ATTRIB(XonoticTextListBox, alphaBG, float, SKINALPHA_LISTBOX_BACKGROUND) + + METHOD(XonoticTextListBox, setSelected, void(entity, float)) + METHOD(XonoticTextListBox, destroy, void(entity)) + ATTRIB(XonoticTextListBox, textbuf, float, -1) + ATTRIB(XonoticTextListBox, allowColors, float, 0) + METHOD(XonoticTextListBox, setText, void(entity, string)) + METHOD(XonoticTextListBox, drawListBoxItem, void(entity, float, vector, float)) // item number, width/height, selected +ENDCLASS(XonoticTextListBox) +entity makeXonoticTextListBox(); +#endif + +#ifdef IMPLEMENTATION +entity makeXonoticTextListBox() +{ + entity me; + me = spawnXonoticTextListBox(); + me.configureXonoticTextListBox(me); + return me; +} +void XonoticTextListBox_configureXonoticTextListBox(entity me) +{ + me.configureListBox(me, me.scrollbarWidth, 1); // item height gets set up later +} +void XonoticTextListBox_setSelected(entity me, float i) +{ + // nothing +} +void XonoticTextListBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + me.itemHeight = me.rowsPerItem * me.fontSize / absSize_y; + SUPER(XonoticTextListBox).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + + me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight); + me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth)); + me.realUpperMargin = 0.5 * (1 - me.realFontSize_y); +} +void XonoticTextListBox_setText(entity me, string theText) +{ + float i, k; + if(me.textbuf >= 0) + buf_del(me.textbuf); + me.textbuf = buf_create(); + string s = strzone(theText); + k = tokenizebyseparator(s, "\\n"); + for(i = 0; i < k; ++i) + bufstr_add(me.textbuf, argv(i), 1); + strunzone(s); + me.nItems = k; +} +void XonoticTextListBox_destroy(entity me) +{ + if(me.textbuf >= 0) + buf_del(me.textbuf); +} +void XonoticTextListBox_drawListBoxItem(entity me, float i, vector absSize, float isSelected) +{ + draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, bufstr_get(me.textbuf, i), me.realFontSize, '1 1 1', 1, me.allowColors); +} +#endif diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 3e897f343..145e5146c 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -733,8 +733,7 @@ void MOTD_send() WriteByte(MSG_ONE, TE_CSQC_SERVERINFO); WriteString(MSG_ONE, "128.03.192.999"); // FIXME: send the real server ip WriteString(MSG_ONE, autocvar_hostname); - //WriteString(MSG_ONE, getwelcomemessage()); - WriteString(MSG_ONE, "Welcome to this server. Have fun!"); + WriteString(MSG_ONE, getwelcomemessage()); } /* -- 2.39.2