From 9af59929b4debd80f0933cbf172747814f7a85ec Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 31 Dec 2020 15:09:40 +0100 Subject: [PATCH] Use the same variable names as minigame_getWrappedLine as they are a clearer --- qcsrc/common/minigames/cl_minigames.qc | 12 ++---- qcsrc/common/util.qc | 52 +++++++++++--------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/qcsrc/common/minigames/cl_minigames.qc b/qcsrc/common/minigames/cl_minigames.qc index e5fe71642..eaf8e0d65 100644 --- a/qcsrc/common/minigames/cl_minigames.qc +++ b/qcsrc/common/minigames/cl_minigames.qc @@ -248,12 +248,7 @@ NET_HANDLE(ENT_CLIENT_MINIGAME, bool isnew) string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw) { - int last_word; - string s; - int take_until; - int skip = 0; - - s = getWrappedLine_remaining; + string s = getWrappedLine_remaining; if(w <= 0) { @@ -261,11 +256,12 @@ string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_ return s; // the line has no size ANYWAY, nothing would be displayed. } - take_until = textLengthUpToWidth(s, w, theFontSize, tw); + int take_until = textLengthUpToWidth(s, w, theFontSize, tw); if ( take_until > strlen(s) ) take_until = strlen(s); + int skip = 0; for ( int i = 0; i < take_until; i++ ) if ( substring(s,i,1) == "\n" ) { @@ -278,7 +274,7 @@ string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_ { if ( skip == 0 && take_until < strlen(s) ) { - last_word = take_until; + int last_word = take_until; while(last_word > 0 && substring(s, last_word, 1) != " ") --last_word; diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 27aa5f3f2..d823eeec2 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -922,11 +922,7 @@ string find_last_color_code(string s) string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw) { - float cantake; - float take; - string s; - - s = getWrappedLine_remaining; + string s = getWrappedLine_remaining; if(w <= 0) { @@ -934,26 +930,26 @@ string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunc return s; // the line has no size ANYWAY, nothing would be displayed. } - cantake = textLengthUpToWidth(s, w, theFontSize, tw); - if(cantake > 0 && cantake < strlen(s)) + int take_until = textLengthUpToWidth(s, w, theFontSize, tw); + if(take_until > 0 && take_until < strlen(s)) { - take = cantake - 1; - while(take > 0 && substring(s, take, 1) != " ") - --take; + int last_word = take_until - 1; + while(last_word > 0 && substring(s, last_word, 1) != " ") + --last_word; int skip = 0; - if(take != 0) + if(last_word != 0) { - cantake = take; + take_until = last_word; skip = 1; } - getWrappedLine_remaining = substring(s, cantake + skip, strlen(s) - cantake); + getWrappedLine_remaining = substring(s, take_until + skip, strlen(s) - take_until); if(getWrappedLine_remaining == "") getWrappedLine_remaining = string_null; else if (tw("^7", theFontSize) == 0) - getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, cantake)), getWrappedLine_remaining); - return substring(s, 0, cantake); + getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, take_until)), getWrappedLine_remaining); + return substring(s, 0, take_until); } else { @@ -964,11 +960,7 @@ string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunc string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw) { - float cantake; - float take; - string s; - - s = getWrappedLine_remaining; + string s = getWrappedLine_remaining; if(w <= 0) { @@ -976,26 +968,26 @@ string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw) return s; // the line has no size ANYWAY, nothing would be displayed. } - cantake = textLengthUpToLength(s, w, tw); - if(cantake > 0 && cantake < strlen(s)) + int take_until = textLengthUpToLength(s, w, tw); + if(take_until > 0 && take_until < strlen(s)) { - take = cantake - 1; - while(take > 0 && substring(s, take, 1) != " ") - --take; + int last_word = take_until - 1; + while(last_word > 0 && substring(s, last_word, 1) != " ") + --last_word; int skip = 0; - if(take != 0) + if(last_word != 0) { - cantake = take; + take_until = last_word; skip = 1; } - getWrappedLine_remaining = substring(s, cantake + skip, strlen(s) - cantake); + getWrappedLine_remaining = substring(s, take_until + skip, strlen(s) - take_until); if(getWrappedLine_remaining == "") getWrappedLine_remaining = string_null; else if (tw("^7") == 0) - getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, cantake)), getWrappedLine_remaining); - return substring(s, 0, cantake); + getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, take_until)), getWrappedLine_remaining); + return substring(s, 0, take_until); } else { -- 2.39.2