mirror of https://github.com/OpenTTD/OpenTTD
(svn r14046) -Codechange: make the size of querystring "widgets" more configurable.
parent
3b4c3a3df6
commit
6995365535
|
@ -251,12 +251,12 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
|
||||||
char name[64];
|
char name[64];
|
||||||
glwp_modes mode;
|
glwp_modes mode;
|
||||||
|
|
||||||
GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(desc, number)
|
GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(11, desc, number)
|
||||||
{
|
{
|
||||||
this->LowerWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
|
this->LowerWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
|
||||||
|
|
||||||
snprintf(this->edit_str_buf, sizeof(this->edit_str_buf), "%u", _settings_newgame.game_creation.generation_seed);
|
snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 120);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
|
||||||
this->caption = STR_NULL;
|
this->caption = STR_NULL;
|
||||||
this->afilter = CS_NUMERAL;
|
this->afilter = CS_NUMERAL;
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
|
||||||
|
|
||||||
case GLAND_RANDOM_BUTTON: // Random seed
|
case GLAND_RANDOM_BUTTON: // Random seed
|
||||||
_settings_newgame.game_creation.generation_seed = InteractiveRandom();
|
_settings_newgame.game_creation.generation_seed = InteractiveRandom();
|
||||||
snprintf(this->edit_str_buf, lengthof(this->edit_str_buf), "%u", _settings_newgame.game_creation.generation_seed);
|
snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
|
||||||
UpdateTextBufferSize(&this->text);
|
UpdateTextBufferSize(&this->text);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1056,7 +1056,7 @@ enum QueryStringWidgets {
|
||||||
|
|
||||||
struct QueryStringWindow : public QueryStringBaseWindow
|
struct QueryStringWindow : public QueryStringBaseWindow
|
||||||
{
|
{
|
||||||
QueryStringWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(desc)
|
QueryStringWindow(size_t size, const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(size, desc)
|
||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
SetBit(_no_scroll, SCROLL_EDIT);
|
SetBit(_no_scroll, SCROLL_EDIT);
|
||||||
|
@ -1167,19 +1167,12 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
|
||||||
DeleteWindowById(WC_QUERY_STRING, 0);
|
DeleteWindowById(WC_QUERY_STRING, 0);
|
||||||
DeleteWindowById(WC_SAVELOAD, 0);
|
DeleteWindowById(WC_SAVELOAD, 0);
|
||||||
|
|
||||||
QueryStringWindow *w = new QueryStringWindow(&_query_string_desc, parent);
|
QueryStringWindow *w = new QueryStringWindow(realmaxlen + 1, &_query_string_desc, parent);
|
||||||
|
|
||||||
assert(realmaxlen < lengthof(w->edit_str_buf));
|
GetString(w->edit_str_buf, str, &w->edit_str_buf[realmaxlen]);
|
||||||
|
w->edit_str_buf[realmaxlen] = '\0';
|
||||||
|
|
||||||
GetString(w->edit_str_buf, str, lastof(w->edit_str_buf));
|
if (!(maxlen & 0x1000)) w->orig = strdup(w->edit_str_buf);
|
||||||
w->edit_str_buf[realmaxlen - 1] = '\0';
|
|
||||||
|
|
||||||
if (maxlen & 0x1000) {
|
|
||||||
w->orig = NULL;
|
|
||||||
} else {
|
|
||||||
strecpy(w->orig_str_buf, w->edit_str_buf, lastof(w->orig_str_buf));
|
|
||||||
w->orig = w->orig_str_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
w->LowerWidget(QUERY_STR_WIDGET_TEXT);
|
w->LowerWidget(QUERY_STR_WIDGET_TEXT);
|
||||||
w->caption = caption;
|
w->caption = caption;
|
||||||
|
@ -1414,11 +1407,11 @@ struct SaveLoadWindow : public QueryStringBaseWindow {
|
||||||
|
|
||||||
SetDParam(0, p->index);
|
SetDParam(0, p->index);
|
||||||
SetDParam(1, _date);
|
SetDParam(1, _date);
|
||||||
GetString(this->edit_str_buf, STR_4004, lastof(this->edit_str_buf));
|
GetString(this->edit_str_buf, STR_4004, &this->edit_str_buf[this->edit_str_size - 1]);
|
||||||
SanitizeFilename(this->edit_str_buf);
|
SanitizeFilename(this->edit_str_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(desc)
|
SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64, desc)
|
||||||
{
|
{
|
||||||
static const StringID saveload_captions[] = {
|
static const StringID saveload_captions[] = {
|
||||||
STR_4001_LOAD_GAME,
|
STR_4001_LOAD_GAME,
|
||||||
|
@ -1445,7 +1438,7 @@ struct SaveLoadWindow : public QueryStringBaseWindow {
|
||||||
this->LowerWidget(7);
|
this->LowerWidget(7);
|
||||||
|
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 240);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 240);
|
||||||
|
|
||||||
/* pause is only used in single-player, non-editor mode, non-menu mode. It
|
/* pause is only used in single-player, non-editor mode, non-menu mode. It
|
||||||
* will be unpaused in the WE_DESTROY event handler. */
|
* will be unpaused in the WE_DESTROY event handler. */
|
||||||
|
|
|
@ -288,11 +288,11 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(desc)
|
NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_NAME_LENGTH, desc)
|
||||||
{
|
{
|
||||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.player_name, lengthof(this->edit_str_buf));
|
ttd_strlcpy(this->edit_str_buf, _settings_client.network.player_name, this->edit_str_size);
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 120);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
|
||||||
|
|
||||||
UpdateNetworkGameWindow(true);
|
UpdateNetworkGameWindow(true);
|
||||||
|
|
||||||
|
@ -758,9 +758,9 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
||||||
FiosItem *map; ///< Selected map
|
FiosItem *map; ///< Selected map
|
||||||
byte widget_id; ///< The widget that has the pop-up input menu
|
byte widget_id; ///< The widget that has the pop-up input menu
|
||||||
|
|
||||||
NetworkStartServerWindow(const WindowDesc *desc) : QueryStringBaseWindow(desc)
|
NetworkStartServerWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_NAME_LENGTH, desc)
|
||||||
{
|
{
|
||||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.server_name, lengthof(this->edit_str_buf));
|
ttd_strlcpy(this->edit_str_buf, _settings_client.network.server_name, this->edit_str_size);
|
||||||
|
|
||||||
_saveload_mode = SLD_NEW_GAME;
|
_saveload_mode = SLD_NEW_GAME;
|
||||||
BuildFileList();
|
BuildFileList();
|
||||||
|
@ -768,7 +768,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
||||||
this->vscroll.count = _fios_items.Length() + 1;
|
this->vscroll.count = _fios_items.Length() + 1;
|
||||||
|
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 160);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 160);
|
||||||
|
|
||||||
this->field = NSSW_GAMENAME;
|
this->field = NSSW_GAMENAME;
|
||||||
|
|
||||||
|
@ -1747,13 +1747,13 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
|
||||||
DestType dtype;
|
DestType dtype;
|
||||||
int dest;
|
int dest;
|
||||||
|
|
||||||
NetworkChatWindow (const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(desc)
|
NetworkChatWindow (const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(NETWORK_CHAT_LENGTH, desc)
|
||||||
{
|
{
|
||||||
this->LowerWidget(2);
|
this->LowerWidget(2);
|
||||||
this->dtype = type;
|
this->dtype = type;
|
||||||
this->dest = dest;
|
this->dest = dest;
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 0);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 0);
|
||||||
|
|
||||||
InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height);
|
InvalidateWindowData(WC_NEWS_WINDOW, 0, this->height);
|
||||||
SetBit(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
|
SetBit(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
|
||||||
|
@ -1822,7 +1822,9 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
|
||||||
*/
|
*/
|
||||||
void ChatTabCompletion()
|
void ChatTabCompletion()
|
||||||
{
|
{
|
||||||
static char _chat_tab_completion_buf[lengthof(this->edit_str_buf)];
|
static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
|
||||||
|
assert(this->edit_str_size == lengthof(_chat_tab_completion_buf));
|
||||||
|
|
||||||
Textbuf *tb = &this->text;
|
Textbuf *tb = &this->text;
|
||||||
size_t len, tb_len;
|
size_t len, tb_len;
|
||||||
uint item;
|
uint item;
|
||||||
|
@ -1875,9 +1877,9 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
|
||||||
|
|
||||||
/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
|
/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
|
||||||
if (pre_buf == tb_buf) {
|
if (pre_buf == tb_buf) {
|
||||||
snprintf(tb->buf, lengthof(this->edit_str_buf), "%s: ", cur_name);
|
snprintf(tb->buf, this->edit_str_size, "%s: ", cur_name);
|
||||||
} else {
|
} else {
|
||||||
snprintf(tb->buf, lengthof(this->edit_str_buf), "%s %s", pre_buf, cur_name);
|
snprintf(tb->buf, this->edit_str_size, "%s %s", pre_buf, cur_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the textbuffer */
|
/* Update the textbuffer */
|
||||||
|
@ -1988,11 +1990,11 @@ enum NetworkCompanyPasswordWindowWidgets {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
||||||
NetworkCompanyPasswordWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(desc)
|
NetworkCompanyPasswordWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(lengthof(_settings_client.network.default_company_pass), desc)
|
||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
this->afilter = CS_ALPHANUMERAL;
|
this->afilter = CS_ALPHANUMERAL;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, min(lengthof(_settings_client.network.default_company_pass), lengthof(this->edit_str_buf)), 0);
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 0);
|
||||||
|
|
||||||
this->FindWindowPlacementAndResize(desc);
|
this->FindWindowPlacementAndResize(desc);
|
||||||
}
|
}
|
||||||
|
@ -2004,7 +2006,7 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* empty password is a '*' because of console argument */
|
/* empty password is a '*' because of console argument */
|
||||||
if (StrEmpty(this->edit_str_buf)) snprintf(this->edit_str_buf, lengthof(this->edit_str_buf), "*");
|
if (StrEmpty(this->edit_str_buf)) snprintf(this->edit_str_buf, this->edit_str_size, "*");
|
||||||
char *password = this->edit_str_buf;
|
char *password = this->edit_str_buf;
|
||||||
NetworkChangeCompanyPassword(1, &password);
|
NetworkChangeCompanyPassword(1, &password);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ struct OskWindow : public Window {
|
||||||
int ok_btn; ///< widget number of parent's ok button (=0 when ok shouldn't be passed on)
|
int ok_btn; ///< widget number of parent's ok button (=0 when ok shouldn't be passed on)
|
||||||
int cancel_btn; ///< widget number of parent's cancel button (=0 when cancel shouldn't be passed on; text will be reverted to original)
|
int cancel_btn; ///< widget number of parent's cancel button (=0 when cancel shouldn't be passed on; text will be reverted to original)
|
||||||
Textbuf *text; ///< pointer to parent's textbuffer (to update caret position)
|
Textbuf *text; ///< pointer to parent's textbuffer (to update caret position)
|
||||||
char orig_str_buf[64]; ///< Original string.
|
char *orig_str_buf; ///< Original string.
|
||||||
|
|
||||||
OskWindow(const WindowDesc *desc, QueryStringBaseWindow *parent, int button, int cancel, int ok) : Window(desc)
|
OskWindow(const WindowDesc *desc, QueryStringBaseWindow *parent, int button, int cancel, int ok) : Window(desc)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +64,7 @@ struct OskWindow : public Window {
|
||||||
this->text = &parent->text;
|
this->text = &parent->text;
|
||||||
|
|
||||||
/* make a copy in case we need to reset later */
|
/* make a copy in case we need to reset later */
|
||||||
strcpy(this->orig_str_buf, this->qs->text.buf);
|
this->orig_str_buf = strdup(this->qs->text.buf);
|
||||||
|
|
||||||
SetBit(_no_scroll, SCROLL_EDIT);
|
SetBit(_no_scroll, SCROLL_EDIT);
|
||||||
/* Not needed by default. */
|
/* Not needed by default. */
|
||||||
|
@ -73,6 +73,11 @@ struct OskWindow : public Window {
|
||||||
this->FindWindowPlacementAndResize(desc);
|
this->FindWindowPlacementAndResize(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~OskWindow()
|
||||||
|
{
|
||||||
|
free(this->orig_str_buf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only show valid characters; do not show characters that would
|
* Only show valid characters; do not show characters that would
|
||||||
* only insert a space when we have a spacebar to do that or
|
* only insert a space when we have a spacebar to do that or
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
#include "textbuf_gui.h"
|
#include "textbuf_gui.h"
|
||||||
#include "window_gui.h"
|
#include "window_gui.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data stored about a string that can be modified in the GUI
|
||||||
|
*/
|
||||||
struct QueryString {
|
struct QueryString {
|
||||||
StringID caption;
|
StringID caption;
|
||||||
Textbuf text;
|
Textbuf text;
|
||||||
|
@ -15,17 +18,39 @@ struct QueryString {
|
||||||
CharSetFilter afilter;
|
CharSetFilter afilter;
|
||||||
bool handled;
|
bool handled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure everything gets initialized properly.
|
||||||
|
*/
|
||||||
|
QueryString() : orig(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure everything gets freed.
|
||||||
|
*/
|
||||||
|
~QueryString()
|
||||||
|
{
|
||||||
|
free((void*)this->orig);
|
||||||
|
}
|
||||||
|
|
||||||
void DrawEditBox(Window *w, int wid);
|
void DrawEditBox(Window *w, int wid);
|
||||||
void HandleEditBox(Window *w, int wid);
|
void HandleEditBox(Window *w, int wid);
|
||||||
int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state);
|
int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, Window::EventState &state);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryStringBaseWindow : public Window, public QueryString {
|
struct QueryStringBaseWindow : public Window, public QueryString {
|
||||||
char edit_str_buf[64];
|
const size_t edit_str_size;
|
||||||
char orig_str_buf[64];
|
char *edit_str_buf;
|
||||||
|
char *orig_str_buf;
|
||||||
|
|
||||||
QueryStringBaseWindow(const WindowDesc *desc, WindowNumber window_number = 0) : Window(desc, window_number)
|
QueryStringBaseWindow(size_t size, const WindowDesc *desc, WindowNumber window_number = 0) : Window(desc, window_number), edit_str_size(size)
|
||||||
{
|
{
|
||||||
|
this->edit_str_buf = CallocT<char>(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
~QueryStringBaseWindow()
|
||||||
|
{
|
||||||
|
free(this->edit_str_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawEditBox(int wid);
|
void DrawEditBox(int wid);
|
||||||
|
|
|
@ -188,7 +188,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(desc)
|
SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(31, desc)
|
||||||
{
|
{
|
||||||
SetBit(_no_scroll, SCROLL_EDIT);
|
SetBit(_no_scroll, SCROLL_EDIT);
|
||||||
this->caption = STR_280B_EDIT_SIGN_TEXT;
|
this->caption = STR_280B_EDIT_SIGN_TEXT;
|
||||||
|
@ -206,17 +206,19 @@ struct SignWindow : QueryStringBaseWindow, SignList {
|
||||||
|
|
||||||
void UpdateSignEditWindow(const Sign *si)
|
void UpdateSignEditWindow(const Sign *si)
|
||||||
{
|
{
|
||||||
|
char *last_of = &this->edit_str_buf[this->edit_str_size - 1];
|
||||||
|
|
||||||
/* Display an empty string when the sign hasnt been edited yet */
|
/* Display an empty string when the sign hasnt been edited yet */
|
||||||
if (si->name != NULL) {
|
if (si->name != NULL) {
|
||||||
SetDParam(0, si->index);
|
SetDParam(0, si->index);
|
||||||
GetString(this->edit_str_buf, STR_SIGN_NAME, lastof(this->edit_str_buf));
|
GetString(this->edit_str_buf, STR_SIGN_NAME, last_of);
|
||||||
} else {
|
} else {
|
||||||
GetString(this->edit_str_buf, STR_EMPTY, lastof(this->edit_str_buf));
|
GetString(this->edit_str_buf, STR_EMPTY, last_of);
|
||||||
}
|
}
|
||||||
this->edit_str_buf[lengthof(this->edit_str_buf) - 1] = '\0';
|
*last_of = '\0';
|
||||||
|
|
||||||
this->cur_sign = si->index;
|
this->cur_sign = si->index;
|
||||||
InitializeTextBuffer(&this->text, this->edit_str_buf, 31, 255); // Allow 31 characters (including \0)
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 255);
|
||||||
|
|
||||||
this->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
this->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue