From fa1992116c1fc3b25942ad163413ab7c3acffb02 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 22 Mar 2015 23:59:05 +0100 Subject: [PATCH] Cleanup welcome dialog code and add 2 sanity checks --- qcsrc/menu/xonotic/dialog_welcome.qc | 15 ++++++++------- qcsrc/menu/xonotic/textlistbox.qc | 5 ++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/qcsrc/menu/xonotic/dialog_welcome.qc b/qcsrc/menu/xonotic/dialog_welcome.qc index b99f81be4..93d948c55 100644 --- a/qcsrc/menu/xonotic/dialog_welcome.qc +++ b/qcsrc/menu/xonotic/dialog_welcome.qc @@ -50,6 +50,7 @@ void XonoticWelcomeDialog_readInputArgs(entity me, float argsbuf) int i = 0; string s; welcomeDialog_resetStrings(me); + if(argsbuf >= 0) while((s = bufstr_get(argsbuf, i)) != "") { if(s == "name") @@ -96,18 +97,18 @@ void XonoticWelcomeDialog_fill(entity me) entity e; me.TR(me); - me.TD(me, 4, 2, me.serverinfo_pic_ent = makeXonoticImage(string_null, 4.0/3.0)); + me.TD(me, 4, me.columns / 2, me.serverinfo_pic_ent = makeXonoticImage(string_null, 4.0/3.0)); - me.gotoRC(me, 1, 2); - me.TD(me, 1, 2, me.serverinfo_name_ent = makeXonoticTextLabel(0, "")); - me.gotoRC(me, 2, 2); - me.TD(me, 1, 2, me.serverinfo_ip_ent = makeXonoticTextLabel(0, "")); + me.gotoRC(me, 1, me.columns / 2); + me.TD(me, 1, me.columns / 2, me.serverinfo_name_ent = makeXonoticTextLabel(0, "")); + me.gotoRC(me, 2, me.columns / 2); + me.TD(me, 1, me.columns / 2, me.serverinfo_ip_ent = makeXonoticTextLabel(0, "")); me.gotoRC(me, 4, 0); - me.TD(me, me.rows - 4 - 1, 4, me.serverinfo_MOTD_ent = makeXonoticTextListBox()); + me.TD(me, me.rows - 4 - 1, me.columns, 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)); + me.TD(me, 1, me.columns / 2, e = makeXonoticCommandButton(_("Disconnect"), '0 0 0', "disconnect", COMMANDBUTTON_CLOSE)); } #endif diff --git a/qcsrc/menu/xonotic/textlistbox.qc b/qcsrc/menu/xonotic/textlistbox.qc index 48451ee1f..7c6ec9a44 100644 --- a/qcsrc/menu/xonotic/textlistbox.qc +++ b/qcsrc/menu/xonotic/textlistbox.qc @@ -17,6 +17,7 @@ CLASS(XonoticTextListBox) EXTENDS(ListBox) METHOD(XonoticTextListBox, setSelected, void(entity, float)) METHOD(XonoticTextListBox, destroy, void(entity)) ATTRIB(XonoticTextListBox, textbuf, float, -1) + ATTRIB(XonoticTextListBox, textbufSize, float, 0) ATTRIB(XonoticTextListBox, allowColors, float, 0) METHOD(XonoticTextListBox, setText, void(entity, string)) METHOD(XonoticTextListBox, drawListBoxItem, void(entity, float, vector, float)) // item number, width/height, selected @@ -78,6 +79,7 @@ void XonoticTextListBox_setText(entity me, string theText) } } strunzone(s); + me.textbufSize = buf_getsize(me.textbuf); } void XonoticTextListBox_destroy(entity me) { @@ -86,6 +88,7 @@ void XonoticTextListBox_destroy(entity me) } 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); + if(me.textbufSize > 0) + draw_CenterText(me.realUpperMargin * eY + 0.5 * eX, bufstr_get(me.textbuf, i), me.realFontSize, '1 1 1', 1, me.allowColors); } #endif -- 2.39.2