Changeset - r16673:d4cdf063a299
[Not reviewed]
master
0 4 0
rubidium - 14 years ago 2010-12-05 22:25:21
rubidium@openttd.org
(svn r21414) -Codechange: limit town name by amount of characters, not bytes
4 files changed with 10 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/town_cmd.cpp
Show inline comments
 
@@ -1543,7 +1543,7 @@ CommandCost CmdFoundTown(TileIndex tile,
 
		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
 
	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);
 
	}
 

	
src/town_gui.cpp
Show inline comments
 
@@ -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;
 
		}
src/town_type.h
Show inline comments
 
@@ -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 */
src/townname.cpp
Show inline comments
 
@@ -80,13 +80,13 @@ char *GetTownName(char *buff, const Town
 
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) {
0 comments (0 inline, 0 general)