mirror of https://github.com/OpenTTD/OpenTTD
(svn r24740) -Codechange: Remove duplicate members from QueryStringBaseWindow and directly use QueryString.
parent
6653ac6b36
commit
6e6d94a2d1
|
@ -1356,7 +1356,7 @@ struct AIDebugWindow : public QueryStringBaseWindow {
|
||||||
{
|
{
|
||||||
if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
|
if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
|
||||||
/* Save the current string to static member so it can be restored next time the window is opened. */
|
/* Save the current string to static member so it can be restored next time the window is opened. */
|
||||||
strecpy(this->break_string, this->edit_str_buf, lastof(this->break_string));
|
strecpy(this->break_string, this->text.buf, lastof(this->break_string));
|
||||||
break_string_filter.SetFilterTerm(this->break_string);
|
break_string_filter.SetFilterTerm(this->break_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ public:
|
||||||
/** Generate a default save filename. */
|
/** Generate a default save filename. */
|
||||||
void GenerateFileName()
|
void GenerateFileName()
|
||||||
{
|
{
|
||||||
GenerateDefaultSaveName(this->edit_str_buf, &this->edit_str_buf[this->edit_str_size - 1]);
|
GenerateDefaultSaveName(this->text.buf, &this->text.buf[this->text.max_bytes - 1]);
|
||||||
this->text.UpdateSize();
|
this->text.UpdateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -698,7 +698,7 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
|
||||||
* As UINT32_MAX is a 'magic' value (use random seed) it
|
* As UINT32_MAX is a 'magic' value (use random seed) it
|
||||||
* should not be possible to be entered into the input
|
* should not be possible to be entered into the input
|
||||||
* field; the generate seed button can be used instead. */
|
* field; the generate seed button can be used instead. */
|
||||||
_settings_newgame.game_creation.generation_seed = minu(strtoul(this->edit_str_buf, NULL, 10), UINT32_MAX - 1);
|
_settings_newgame.game_creation.generation_seed = minu(strtoul(this->text.buf, NULL, 10), UINT32_MAX - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -819,18 +819,18 @@ struct QueryStringWindow : public QueryStringBaseWindow
|
||||||
QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, const WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
|
QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, const WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
|
||||||
QueryStringBaseWindow(max_bytes, max_chars)
|
QueryStringBaseWindow(max_bytes, max_chars)
|
||||||
{
|
{
|
||||||
GetString(this->edit_str_buf, str, &this->edit_str_buf[max_bytes - 1]);
|
GetString(this->text.buf, str, &this->text.buf[this->text.max_bytes - 1]);
|
||||||
str_validate(this->edit_str_buf, &this->edit_str_buf[max_bytes - 1], SVS_NONE);
|
str_validate(this->text.buf, &this->text.buf[this->text.max_bytes - 1], SVS_NONE);
|
||||||
|
|
||||||
/* Make sure the name isn't too long for the text buffer in the number of
|
/* Make sure the name isn't too long for the text buffer in the number of
|
||||||
* characters (not bytes). max_chars also counts the '\0' characters. */
|
* characters (not bytes). max_chars also counts the '\0' characters. */
|
||||||
while (Utf8StringLength(this->edit_str_buf) + 1 > max_chars) {
|
while (Utf8StringLength(this->text.buf) + 1 > this->text.max_chars) {
|
||||||
*Utf8PrevChar(this->edit_str_buf + strlen(this->edit_str_buf)) = '\0';
|
*Utf8PrevChar(this->text.buf + strlen(this->text.buf)) = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
this->text.UpdateSize();
|
this->text.UpdateSize();
|
||||||
|
|
||||||
if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf);
|
if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->text.buf);
|
||||||
|
|
||||||
this->caption = caption;
|
this->caption = caption;
|
||||||
this->cancel_button = WID_QS_CANCEL;
|
this->cancel_button = WID_QS_CANCEL;
|
||||||
|
|
|
@ -383,7 +383,7 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
|
||||||
void ChatTabCompletion()
|
void ChatTabCompletion()
|
||||||
{
|
{
|
||||||
static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
|
static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
|
||||||
assert(this->edit_str_size == lengthof(_chat_tab_completion_buf));
|
assert(this->text.max_bytes == lengthof(_chat_tab_completion_buf));
|
||||||
|
|
||||||
Textbuf *tb = &this->text;
|
Textbuf *tb = &this->text;
|
||||||
size_t len, tb_len;
|
size_t len, tb_len;
|
||||||
|
|
|
@ -780,7 +780,7 @@ public:
|
||||||
virtual void OnEditboxChanged(int wid)
|
virtual void OnEditboxChanged(int wid)
|
||||||
{
|
{
|
||||||
if (wid == WID_NCL_FILTER) {
|
if (wid == WID_NCL_FILTER) {
|
||||||
this->string_filter.SetFilterTerm(this->edit_str_buf);
|
this->string_filter.SetFilterTerm(this->text.buf);
|
||||||
this->content.SetFilterState(!this->string_filter.IsEmpty());
|
this->content.SetFilterState(!this->string_filter.IsEmpty());
|
||||||
this->content.ForceRebuild();
|
this->content.ForceRebuild();
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
|
|
|
@ -850,8 +850,8 @@ public:
|
||||||
{
|
{
|
||||||
if (wid == WID_NG_CLIENT) {
|
if (wid == WID_NG_CLIENT) {
|
||||||
/* The name is only allowed when it starts with a letter! */
|
/* The name is only allowed when it starts with a letter! */
|
||||||
if (!StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
|
if (!StrEmpty(this->text.buf) && this->text.buf[0] != ' ') {
|
||||||
strecpy(_settings_client.network.client_name, this->edit_str_buf, lastof(_settings_client.network.client_name));
|
strecpy(_settings_client.network.client_name, this->text.buf, lastof(_settings_client.network.client_name));
|
||||||
} else {
|
} else {
|
||||||
strecpy(_settings_client.network.client_name, "Player", lastof(_settings_client.network.client_name));
|
strecpy(_settings_client.network.client_name, "Player", lastof(_settings_client.network.client_name));
|
||||||
}
|
}
|
||||||
|
@ -2116,10 +2116,10 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
||||||
void OnOk()
|
void OnOk()
|
||||||
{
|
{
|
||||||
if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) {
|
if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) {
|
||||||
snprintf(_settings_client.network.default_company_pass, lengthof(_settings_client.network.default_company_pass), "%s", this->edit_str_buf);
|
strecpy(_settings_client.network.default_company_pass, this->text.buf, lastof(_settings_client.network.default_company_pass));
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkChangeCompanyPassword(_local_company, this->edit_str_buf);
|
NetworkChangeCompanyPassword(_local_company, this->text.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnClick(Point pt, int widget, int click_count)
|
virtual void OnClick(Point pt, int widget, int click_count)
|
||||||
|
|
|
@ -1279,7 +1279,7 @@ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback {
|
||||||
{
|
{
|
||||||
if (!this->editable) return;
|
if (!this->editable) return;
|
||||||
|
|
||||||
string_filter.SetFilterTerm(this->edit_str_buf);
|
string_filter.SetFilterTerm(this->text.buf);
|
||||||
this->avails.SetFilterState(!string_filter.IsEmpty());
|
this->avails.SetFilterState(!string_filter.IsEmpty());
|
||||||
this->avails.ForceRebuild();
|
this->avails.ForceRebuild();
|
||||||
this->InvalidateData(0);
|
this->InvalidateData(0);
|
||||||
|
|
|
@ -65,11 +65,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryStringBaseWindow : public Window, public QueryString {
|
struct QueryStringBaseWindow : public Window, public QueryString {
|
||||||
char *edit_str_buf; ///< Buffer for string.
|
QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), QueryString(size, chars)
|
||||||
const uint16 edit_str_size; ///< Maximum length of string (in bytes), including terminating '\0'.
|
|
||||||
const uint16 max_chars; ///< Maximum length of string (in characters), including terminating '\0'.
|
|
||||||
|
|
||||||
QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), QueryString(size, chars), edit_str_buf(text.buf), edit_str_size(text.max_bytes), max_chars(text.max_chars)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2408,7 +2408,7 @@ struct GameSettingsWindow : QueryStringBaseWindow {
|
||||||
virtual void OnEditboxChanged(int wid)
|
virtual void OnEditboxChanged(int wid)
|
||||||
{
|
{
|
||||||
if (wid == WID_GS_FILTER) {
|
if (wid == WID_GS_FILTER) {
|
||||||
string_filter.SetFilterTerm(this->edit_str_buf);
|
string_filter.SetFilterTerm(this->text.buf);
|
||||||
if (!string_filter.IsEmpty() && !this->manually_changed_folding) {
|
if (!string_filter.IsEmpty() && !this->manually_changed_folding) {
|
||||||
/* User never expanded/collapsed single pages and entered a filter term.
|
/* User never expanded/collapsed single pages and entered a filter term.
|
||||||
* Expand everything, to save weird expand clicks, */
|
* Expand everything, to save weird expand clicks, */
|
||||||
|
|
|
@ -1006,7 +1006,7 @@ public:
|
||||||
if (!this->townnamevalid) {
|
if (!this->townnamevalid) {
|
||||||
this->text.DeleteAll();
|
this->text.DeleteAll();
|
||||||
} else {
|
} else {
|
||||||
GetTownName(this->edit_str_buf, &this->params, this->townnameparts, &this->edit_str_buf[this->edit_str_size - 1]);
|
GetTownName(this->text.buf, &this->params, this->townnameparts, &this->text.buf[this->text.max_bytes - 1]);
|
||||||
this->text.UpdateSize();
|
this->text.UpdateSize();
|
||||||
}
|
}
|
||||||
UpdateOSKOriginalText(this, WID_TF_TOWN_NAME_EDITBOX);
|
UpdateOSKOriginalText(this, WID_TF_TOWN_NAME_EDITBOX);
|
||||||
|
@ -1041,12 +1041,12 @@ public:
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
if (!this->townnamevalid) {
|
if (!this->townnamevalid) {
|
||||||
name = this->edit_str_buf;
|
name = this->text.buf;
|
||||||
} else {
|
} else {
|
||||||
/* If user changed the name, send it */
|
/* If user changed the name, send it */
|
||||||
char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
|
char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||||
GetTownName(buf, &this->params, this->townnameparts, lastof(buf));
|
GetTownName(buf, &this->params, this->townnameparts, lastof(buf));
|
||||||
if (strcmp(buf, this->edit_str_buf) != 0) name = this->edit_str_buf;
|
if (strcmp(buf, this->text.buf) != 0) name = this->text.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6,
|
bool success = DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6,
|
||||||
|
|
Loading…
Reference in New Issue