From: terencehill Date: Fri, 18 Oct 2024 16:03:31 +0000 (+0200) Subject: Menu text boxes: fix a couple issues after screen resolution change: X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cd1873ae9f1f19208a9ff186c2005e3dfad91d3f;p=xonotic%2Fxonotic-data.pk3dir.git Menu text boxes: fix a couple issues after screen resolution change: 1. Text wasn't rewrapped correctly for all text boxes 2. campaign and welcome text boxes displayed line feeds as unprintable characters Also remove TOS dialogs' .text attribute since it's redundant now --- diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qc b/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qc index a967dcc26..b39407e7d 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qc @@ -34,13 +34,11 @@ void AdditionalServerInfo_OnGet(entity fh, entity me, int status) } case URL_READY_ERROR: { - me.text = strzone("Error reading ToS"); - me.textBox.setText(me.textBox, me.text); + me.textBox.setText(me.textBox, "Error reading ToS"); break; } case URL_READY_CANREAD: { - strfree(me.text); string temp = ""; for (string s; (s = url_fgets(fh)); ) { @@ -50,8 +48,7 @@ void AdditionalServerInfo_OnGet(entity fh, entity me, int status) temp = s; } url_fclose(fh); - me.text = strzone(temp); - me.textBox.setText(me.textBox, me.text); + me.textBox.setText(me.textBox, temp); break; } default: diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qh b/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qh index ebc2d867e..cbe069e1f 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_join_termsofservice.qh @@ -10,7 +10,6 @@ CLASS(XonoticServerToSTab, XonoticTab) ATTRIB(XonoticServerToSTab, rows, float, 17); ATTRIB(XonoticServerToSTab, columns, float, 6.2); - ATTRIB(XonoticServerToSTab, text, string); ATTRIB(XonoticServerToSTab, textBox, entity); ENDCLASS(XonoticServerToSTab) entity makeXonoticServerToSTab(); diff --git a/qcsrc/menu/xonotic/dialog_termsofservice.qc b/qcsrc/menu/xonotic/dialog_termsofservice.qc index 83839a3f6..f71f0a634 100644 --- a/qcsrc/menu/xonotic/dialog_termsofservice.qc +++ b/qcsrc/menu/xonotic/dialog_termsofservice.qc @@ -37,13 +37,11 @@ void XonoticToS_OnGet(entity fh, entity me, int status) } case URL_READY_ERROR: { - me.text = strzone("Error reading ToS"); - me.textBox.setText(me.textBox, me.text); + me.textBox.setText(me.textBox, "Error reading ToS"); break; } case URL_READY_CANREAD: { - strfree(me.text); string temp = ""; for (string s; (s = url_fgets(fh)); ) { @@ -53,8 +51,7 @@ void XonoticToS_OnGet(entity fh, entity me, int status) temp = s; } url_fclose(fh); - me.text = strzone(temp); - me.textBox.setText(me.textBox, me.text); + me.textBox.setText(me.textBox, temp); break; } default: diff --git a/qcsrc/menu/xonotic/dialog_termsofservice.qh b/qcsrc/menu/xonotic/dialog_termsofservice.qh index 037450f0a..8f6879d66 100644 --- a/qcsrc/menu/xonotic/dialog_termsofservice.qh +++ b/qcsrc/menu/xonotic/dialog_termsofservice.qh @@ -15,7 +15,6 @@ CLASS(XonoticToSDialog, XonoticRootDialog) ATTRIB(XonoticToSDialog, columns, float, 6.2); ATTRIB(XonoticToSDialog, name, string, "TermsOfService"); - ATTRIB(XonoticToSDialog, text, string); ATTRIB(XonoticToSDialog, textBox, entity); ATTRIB(XonoticToSDialog, closable, float, 0); diff --git a/qcsrc/menu/xonotic/textbox.qc b/qcsrc/menu/xonotic/textbox.qc index e79af1e33..f3e5da9d4 100644 --- a/qcsrc/menu/xonotic/textbox.qc +++ b/qcsrc/menu/xonotic/textbox.qc @@ -16,9 +16,10 @@ void XonoticTextBox_destroy(entity me) buf_del(me.stringList); me.stringList = -1; } + strfree(me.text); } -void XonoticTextBox_setText(entity me, string text) +void XonoticTextBox_setText(entity me, string txt) { if (me.stringList >= 0) { @@ -26,6 +27,8 @@ void XonoticTextBox_setText(entity me, string text) me.stringList = -1; } + strcpy(me.text, txt); + int buf; int line = 0; @@ -33,7 +36,7 @@ void XonoticTextBox_setText(entity me, string text) buf = buf_create(); string separator = (me.escapedNewLines) ? "\\n" : "\n"; - for (int i = 0, n = tokenizebyseparator(text, separator); i < n; ++i) + for (int i = 0, n = tokenizebyseparator(txt, separator); i < n; ++i) { t = substring(argv(i), 0, -1); getWrappedLine_remaining = t; @@ -58,8 +61,6 @@ string XonoticTextBox_getTextBoxLine(entity me, int i) return string_null; } -// mostly copied from playerlist -// FIXME: is this really needed void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { me.itemAbsSize = '0 0 0'; @@ -69,19 +70,7 @@ void XonoticTextBox_resizeNotify(entity me, vector relOrigin, vector relSize, ve me.itemAbsSize.x = absSize.x * (1 - me.controlWidth); me.realFontSize.y = me.fontSize / me.itemAbsSize.y; me.realFontSize.x = me.fontSize / me.itemAbsSize.x; - string temp = string_null; - for (int i = 0; i < me.nItems; ++i) - { - if (!temp) - { - temp = me.getTextBoxLine(me, i); - } - else - { - temp = strcat(temp, "\n", me.getTextBoxLine(me, i)); - } - } - me.setText(me, temp); + me.setText(me, strcat(me.text)); // rewrap } void XonoticTextBox_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)