changeset 15560:787178c1c88f draft

(svn r20220) -Fix [FS#3974]: strip non-printable characters before showing it in an edit box, so when renaming a vehicle type you won't get the "SETX stuff" that some NewGRFs use
author rubidium <rubidium@openttd.org>
date Sun, 25 Jul 2010 23:14:59 +0000
parents 1e92b05b786c
children 1f61dc11fd8c
files known-bugs.txt src/misc_gui.cpp src/string.cpp
diffstat 3 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/known-bugs.txt
+++ b/known-bugs.txt
@@ -82,6 +82,15 @@
 	is the default driver for OpenTTD. You can change this default by
 	setting the "musicdriver" in your openttd.cfg to "dmusic".
 
+Custom vehicle type name is incorrectly aligned
+	Some NewGRFs use sprites that are bigger than normal in the "buy
+	vehicle" window. Due to this they have to encode an offset for the
+	vehicle type name. Upon renaming the vehicle type this encoded offset
+	is stripped from the name because the "edit box" cannot show this
+	encoding. As a result the custom vehicle type names will get the
+	default alignment. The only way to (partly) fix this is by adding
+	spaces to the custom name.
+
 Clipping problems [FS#119]
 	In some cases sprites are not drawn as one would expect. Examples of
 	this are aircraft that might be hidden below the runway or trees that
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -1282,7 +1282,7 @@
 			QueryStringBaseWindow(maxsize)
 	{
 		GetString(this->edit_str_buf, str, &this->edit_str_buf[maxsize - 1]);
-		this->edit_str_buf[maxsize - 1] = '\0';
+		str_validate(this->edit_str_buf, &this->edit_str_buf[maxsize - 1], false, true);
 
 		if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf);
 
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -113,7 +113,7 @@
 	/* Assume the ABSOLUTE WORST to be in str as it comes from the outside. */
 
 	char *dst = str;
-	while (*str != '\0') {
+	while (str <= last && *str != '\0') {
 		size_t len = Utf8EncodedCharLen(*str);
 		/* If the character is unknown, i.e. encoded length is 0
 		 * we assume worst case for the length check.
@@ -146,6 +146,16 @@
 			/* Replace the undesirable character with a question mark */
 			str += len;
 			if (!ignore) *dst++ = '?';
+
+			/* In case of these two special cases assume that they really
+			 * mean SETX/SETXY and also "eat" the paramater. If this was
+			 * not the case the string was broken to begin with and this
+			 * would not break much more. */
+			if (c == SCC_SETX) {
+				str++;
+			} else if (c == SCC_SETXY) {
+				str += 2;
+			}
 		}
 	}