mirror of https://github.com/OpenTTD/OpenTTD
(svn r21413) -Codechange: limit sign name by amount of characters, not bytes
parent
cf61c2f11f
commit
6e69b943d6
|
@ -30,7 +30,7 @@
|
||||||
{
|
{
|
||||||
EnforcePrecondition(false, IsValidSign(sign_id));
|
EnforcePrecondition(false, IsValidSign(sign_id));
|
||||||
EnforcePrecondition(false, !::StrEmpty(name));
|
EnforcePrecondition(false, !::StrEmpty(name));
|
||||||
EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_SIGN_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_SIGN_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name);
|
return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
{
|
{
|
||||||
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
||||||
EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text));
|
EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text));
|
||||||
EnforcePreconditionCustomError(false, ::strlen(text) < MAX_LENGTH_SIGN_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||||
|
|
||||||
if (!AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN;
|
if (!AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS);
|
if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS);
|
||||||
|
|
||||||
/* Check sign text length if any */
|
/* Check sign text length if any */
|
||||||
if (!StrEmpty(text) && strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
|
if (!StrEmpty(text) && Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
|
||||||
|
|
||||||
/* When we execute, really make the sign */
|
/* When we execute, really make the sign */
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
@ -80,7 +80,7 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
|
|
||||||
/* Rename the signs when empty, otherwise remove it */
|
/* Rename the signs when empty, otherwise remove it */
|
||||||
if (!StrEmpty(text)) {
|
if (!StrEmpty(text)) {
|
||||||
if (strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
|
if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
/* Delete the old name */
|
/* Delete the old name */
|
||||||
|
|
|
@ -50,8 +50,8 @@ struct SignList {
|
||||||
static const Sign *last_sign;
|
static const Sign *last_sign;
|
||||||
GUISignList signs;
|
GUISignList signs;
|
||||||
|
|
||||||
char filter_string[MAX_LENGTH_SIGN_NAME_BYTES]; ///< The match string to be used when the GUIList is (re)-sorted.
|
char filter_string[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; ///< The match string to be used when the GUIList is (re)-sorted.
|
||||||
static bool match_case; ///< Should case sensitive matching be used?
|
static bool match_case; ///< Should case sensitive matching be used?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SignList with filtering disabled by default.
|
* Creates a SignList with filtering disabled by default.
|
||||||
|
@ -109,7 +109,7 @@ struct SignList {
|
||||||
static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info)
|
static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info)
|
||||||
{
|
{
|
||||||
/* Get sign string */
|
/* Get sign string */
|
||||||
char buf1[MAX_LENGTH_SIGN_NAME_BYTES];
|
char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||||
SetDParam(0, (*a)->index);
|
SetDParam(0, (*a)->index);
|
||||||
GetString(buf1, STR_SIGN_NAME, lastof(buf1));
|
GetString(buf1, STR_SIGN_NAME, lastof(buf1));
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
|
||||||
int text_offset; ///< Offset of the sign text relative to the left edge of the SLW_LIST widget.
|
int text_offset; ///< Offset of the sign text relative to the left edge of the SLW_LIST widget.
|
||||||
Scrollbar *vscroll;
|
Scrollbar *vscroll;
|
||||||
|
|
||||||
SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES)
|
SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
|
||||||
{
|
{
|
||||||
this->CreateNestedTree(desc);
|
this->CreateNestedTree(desc);
|
||||||
this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
|
this->vscroll = this->GetScrollbar(SLW_SCROLLBAR);
|
||||||
|
@ -155,7 +155,7 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
|
||||||
|
|
||||||
/* Initialize the text edit widget */
|
/* Initialize the text edit widget */
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_BYTES, MAX_LENGTH_SIGN_NAME_PIXELS); // Allow MAX_LENGTH_SIGN_NAME_BYTES characters (including \0)
|
InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS, MAX_LENGTH_SIGN_NAME_PIXELS);
|
||||||
ClearFilterTextWidget();
|
ClearFilterTextWidget();
|
||||||
|
|
||||||
/* Initialize the filtering variables */
|
/* Initialize the filtering variables */
|
||||||
|
@ -462,7 +462,7 @@ enum QueryEditSignWidgets {
|
||||||
struct SignWindow : QueryStringBaseWindow, SignList {
|
struct SignWindow : QueryStringBaseWindow, SignList {
|
||||||
SignID cur_sign;
|
SignID cur_sign;
|
||||||
|
|
||||||
SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES)
|
SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
|
||||||
{
|
{
|
||||||
this->caption = STR_EDIT_SIGN_CAPTION;
|
this->caption = STR_EDIT_SIGN_CAPTION;
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
|
@ -488,7 +488,7 @@ struct SignWindow : QueryStringBaseWindow, SignList {
|
||||||
*last_of = '\0';
|
*last_of = '\0';
|
||||||
|
|
||||||
this->cur_sign = si->index;
|
this->cur_sign = si->index;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, MAX_LENGTH_SIGN_NAME_PIXELS);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars, MAX_LENGTH_SIGN_NAME_PIXELS);
|
||||||
|
|
||||||
this->SetWidgetDirty(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
this->SetWidgetDirty(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||||
this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||||
|
|
|
@ -17,7 +17,7 @@ struct Sign;
|
||||||
|
|
||||||
static const SignID INVALID_SIGN = 0xFFFF;
|
static const SignID INVALID_SIGN = 0xFFFF;
|
||||||
|
|
||||||
static const uint MAX_LENGTH_SIGN_NAME_BYTES = 31; ///< The maximum length of a sign name in bytes including '\0'
|
static const uint MAX_LENGTH_SIGN_NAME_CHARS = 31; ///< The maximum length of a sign name in characters including '\0'
|
||||||
static const uint MAX_LENGTH_SIGN_NAME_PIXELS = 255; ///< The maximum length of a sign name in pixels
|
static const uint MAX_LENGTH_SIGN_NAME_PIXELS = 255; ///< The maximum length of a sign name in pixels
|
||||||
|
|
||||||
#endif /* SIGNS_TYPE_H */
|
#endif /* SIGNS_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue