mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r21414) -Codechange: limit town name by amount of characters, not bytes
This commit is contained in:
parent
6e69b943d6
commit
5c9c3f1acf
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user