summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-05 22:25:21 +0000
committerrubidium <rubidium@openttd.org>2010-12-05 22:25:21 +0000
commit5c9c3f1acf9a49b8da6fcbea0e4072750181a48c (patch)
tree2a5c4d4e8be234c7024da472f2fe9d5344417fe9
parent6e69b943d685c3b485d415d4fce53af28f0eba85 (diff)
downloadopenttd-5c9c3f1acf9a49b8da6fcbea0e4072750181a48c.tar.xz
(svn r21414) -Codechange: limit town name by amount of characters, not bytes
-rw-r--r--src/town_cmd.cpp4
-rw-r--r--src/town_gui.cpp8
-rw-r--r--src/town_type.h2
-rw-r--r--src/townname.cpp6
4 files changed, 10 insertions, 10 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index bf2ea082b..9ab7eacda 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1543,7 +1543,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (!VerifyTownName(townnameparts, &par)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
} else {
/* If name is not empty, it has to be unique custom name */
- if (strlen(text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR;
+ if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
@@ -2295,7 +2295,7 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
bool reset = StrEmpty(text);
if (!reset) {
- if (strlen(text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR;
+ if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index f4c302100..00421ccc2 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -451,7 +451,7 @@ public:
case TVW_CHANGENAME: // rename
SetDParam(0, this->window_number);
- ShowQueryString(STR_TOWN_NAME, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
+ ShowQueryString(STR_TOWN_NAME, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_CHARS, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
break;
case TVW_EXPAND: { // expand town - only available on Scenario editor
@@ -1007,13 +1007,13 @@ private:
public:
FoundTownWindow(const WindowDesc *desc, WindowNumber window_number) :
- QueryStringBaseWindow(MAX_LENGTH_TOWN_NAME_BYTES),
+ QueryStringBaseWindow(MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS),
town_size(TSZ_MEDIUM),
town_layout(_settings_game.economy.town_layout),
params(_settings_game.game_creation.town_name)
{
this->InitNested(desc, window_number);
- InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, MAX_LENGTH_TOWN_NAME_PIXELS);
+ InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars, MAX_LENGTH_TOWN_NAME_PIXELS);
this->RandomTownName();
this->UpdateButtons(true);
}
@@ -1063,7 +1063,7 @@ public:
name = this->edit_str_buf;
} else {
/* If user changed the name, send it */
- char buf[MAX_LENGTH_TOWN_NAME_BYTES];
+ char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
GetTownName(buf, &this->params, this->townnameparts, lastof(buf));
if (strcmp(buf, this->edit_str_buf) != 0) name = this->edit_str_buf;
}
diff --git a/src/town_type.h b/src/town_type.h
index 8af2af8e1..224df5ff9 100644
--- a/src/town_type.h
+++ b/src/town_type.h
@@ -105,7 +105,7 @@ enum TownFounding {
/** It needs to be 8bits, because we save and load it as such */
typedef SimpleTinyEnumT<TownFounding, byte> TownFoundingByte;
-static const uint MAX_LENGTH_TOWN_NAME_BYTES = 31; ///< The maximum length of a town name in bytes including '\0'
+static const uint MAX_LENGTH_TOWN_NAME_CHARS = 31; ///< The maximum length of a town name in characters including '\0'
static const uint MAX_LENGTH_TOWN_NAME_PIXELS = 130; ///< The maximum length of a town name in pixels
#endif /* TOWN_TYPE_H */
diff --git a/src/townname.cpp b/src/townname.cpp
index 5377a7ae5..77f0abe66 100644
--- a/src/townname.cpp
+++ b/src/townname.cpp
@@ -80,13 +80,13 @@ char *GetTownName(char *buff, const Town *t, const char *last)
bool VerifyTownName(uint32 r, const TownNameParams *par)
{
/* reserve space for extra unicode character and terminating '\0' */
- char buf1[MAX_LENGTH_TOWN_NAME_BYTES + MAX_CHAR_LENGTH];
- char buf2[MAX_LENGTH_TOWN_NAME_BYTES + MAX_CHAR_LENGTH];
+ char buf1[(MAX_LENGTH_TOWN_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
+ char buf2[(MAX_LENGTH_TOWN_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
GetTownName(buf1, par, r, lastof(buf1));
/* Check size and width */
- if (strlen(buf1) >= MAX_LENGTH_TOWN_NAME_BYTES) return false;
+ if (Utf8StringLength(buf1) >= MAX_LENGTH_TOWN_NAME_CHARS) return false;
const Town *t;
FOR_ALL_TOWNS(t) {