mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 02:19:41 +00:00
(svn r21408) -Codechange: limit president name by amount of characters, not bytes
This commit is contained in:
parent
66c7f00b60
commit
9a18050646
@ -468,16 +468,16 @@ restart:;
|
||||
|
||||
/* Reserve space for extra unicode character. We need to do this to be able
|
||||
* to detect too long president name. */
|
||||
char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
|
||||
char buffer[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
|
||||
SetDParam(0, c->index);
|
||||
GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
|
||||
if (strlen(buffer) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) continue;
|
||||
if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
|
||||
|
||||
Company *cc;
|
||||
FOR_ALL_COMPANIES(cc) {
|
||||
if (c != cc) {
|
||||
/* Reserve extra space so even overlength president names can be compared. */
|
||||
char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH];
|
||||
char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
|
||||
SetDParam(0, cc->index);
|
||||
GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2));
|
||||
if (strcmp(buffer2, buffer) == 0) goto restart;
|
||||
@ -1094,7 +1094,7 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
bool reset = StrEmpty(text);
|
||||
|
||||
if (!reset) {
|
||||
if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
|
||||
if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR;
|
||||
if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
|
||||
}
|
||||
|
||||
|
@ -1946,7 +1946,7 @@ struct CompanyWindow : Window
|
||||
case CW_WIDGET_PRESIDENT_NAME:
|
||||
this->query_widget = CW_WIDGET_PRESIDENT_NAME;
|
||||
SetDParam(0, this->window_number);
|
||||
ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
|
||||
ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
|
||||
break;
|
||||
|
||||
case CW_WIDGET_COMPANY_NAME:
|
||||
|
@ -37,7 +37,7 @@ enum Owner {
|
||||
};
|
||||
DECLARE_POSTFIX_INCREMENT(Owner)
|
||||
|
||||
static const uint MAX_LENGTH_PRESIDENT_NAME_BYTES = 31; ///< The maximum length of a president name in bytes including '\0'
|
||||
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS = 31; ///< The maximum length of a president name in characters including '\0'
|
||||
static const uint MAX_LENGTH_PRESIDENT_NAME_PIXELS = 94; ///< The maximum length of a president name in pixels
|
||||
static const uint MAX_LENGTH_COMPANY_NAME_BYTES = 31; ///< The maximum length of a company name in bytes including '\0'
|
||||
static const uint MAX_LENGTH_COMPANY_NAME_PIXELS = 150; ///< The maximum length of a company name in pixels
|
||||
|
Loading…
Reference in New Issue
Block a user