mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r25102) [1.3] -Backport from trunk:
- Fix: Limit aircraft property 0D to 19, since the conversion result to km-ish/h needs to fit into a byte [FS#5492] (r25099) - Fix: Clicking the statusbar crashed, when news were pending but no news were shown yet [FS#5486] (r25093) - Fix: Make editbox character filters also apply to pasted content from clipboard (r25090, r25089) - Fix: Catch exception anonymously, if the exception content is not of interest [FS#5500] (r25081)
This commit is contained in:
parent
278cebf202
commit
42e569e0d1
|
@ -266,7 +266,6 @@ public:
|
|||
|
||||
this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
|
||||
this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
|
||||
this->filename_editbox.afilter = CS_ALPHANUMERAL;
|
||||
|
||||
this->CreateNestedTree(desc, true);
|
||||
if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
|
||||
|
|
|
@ -320,7 +320,7 @@ struct GenerateLandscapeWindow : public Window {
|
|||
this->querystrings[WID_GL_RANDOM_EDITBOX] = &this->seed_editbox;
|
||||
this->seed_editbox.text.Print("%u", _settings_newgame.game_creation.generation_seed);
|
||||
this->seed_editbox.caption = STR_NULL;
|
||||
this->seed_editbox.afilter = CS_NUMERAL;
|
||||
this->seed_editbox.text.afilter = CS_NUMERAL;
|
||||
|
||||
this->mode = (GenenerateLandscapeWindowMode)this->window_number;
|
||||
|
||||
|
|
|
@ -753,7 +753,7 @@ HandleEditBoxResult QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key
|
|||
break;
|
||||
|
||||
default:
|
||||
if (IsValidChar(key, this->afilter)) {
|
||||
if (IsValidChar(key, this->text.afilter)) {
|
||||
edited = this->text.InsertChar(key);
|
||||
} else {
|
||||
state = ES_NOT_HANDLED;
|
||||
|
@ -878,7 +878,7 @@ struct QueryStringWindow : public Window
|
|||
this->editbox.caption = caption;
|
||||
this->editbox.cancel_button = WID_QS_CANCEL;
|
||||
this->editbox.ok_button = WID_QS_OK;
|
||||
this->editbox.afilter = afilter;
|
||||
this->editbox.text.afilter = afilter;
|
||||
this->flags = flags;
|
||||
|
||||
this->InitNested(desc, WN_QUERY_STRING);
|
||||
|
|
|
@ -303,7 +303,6 @@ struct NetworkChatWindow : public Window {
|
|||
this->querystrings[WID_NC_TEXTBOX] = &this->message_editbox;
|
||||
this->message_editbox.cancel_button = WID_NC_CLOSE;
|
||||
this->message_editbox.ok_button = WID_NC_SENDBUTTON;
|
||||
this->message_editbox.afilter = CS_ALPHANUMERAL;
|
||||
|
||||
static const StringID chat_captions[] = {
|
||||
STR_NETWORK_CHAT_ALL_CAPTION,
|
||||
|
|
|
@ -486,7 +486,6 @@ public:
|
|||
|
||||
this->querystrings[WID_NCL_FILTER] = &this->filter_editbox;
|
||||
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
|
||||
this->filter_editbox.afilter = CS_ALPHANUMERAL;
|
||||
this->SetFocusedWidget(WID_NCL_FILTER);
|
||||
this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select);
|
||||
|
||||
|
|
|
@ -454,7 +454,6 @@ public:
|
|||
|
||||
this->querystrings[WID_NG_CLIENT] = &this->name_editbox;
|
||||
this->name_editbox.text.Assign(_settings_client.network.client_name);
|
||||
this->name_editbox.afilter = CS_ALPHANUMERAL;
|
||||
|
||||
this->querystrings[WID_NG_FILTER] = &this->filter_editbox;
|
||||
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
|
||||
|
@ -1042,7 +1041,6 @@ struct NetworkStartServerWindow : public Window {
|
|||
this->querystrings[WID_NSS_GAMENAME] = &this->name_editbox;
|
||||
this->name_editbox.text.Assign(_settings_client.network.server_name);
|
||||
|
||||
this->name_editbox.afilter = CS_ALPHANUMERAL;
|
||||
this->SetFocusedWidget(WID_NSS_GAMENAME);
|
||||
}
|
||||
|
||||
|
@ -2147,7 +2145,6 @@ struct NetworkCompanyPasswordWindow : public Window {
|
|||
this->querystrings[WID_NCP_PASSWORD] = &this->password_editbox;
|
||||
this->password_editbox.cancel_button = WID_NCP_CANCEL;
|
||||
this->password_editbox.ok_button = WID_NCP_OK;
|
||||
this->password_editbox.afilter = CS_ALPHANUMERAL;
|
||||
this->SetFocusedWidget(WID_NCP_PASSWORD);
|
||||
}
|
||||
|
||||
|
|
|
@ -1618,9 +1618,15 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int
|
|||
avi->max_speed = (buf->ReadByte() * 128) / 10;
|
||||
break;
|
||||
|
||||
case 0x0D: // Acceleration
|
||||
avi->acceleration = (buf->ReadByte() * 128) / 10;
|
||||
case 0x0D: { // Acceleration
|
||||
uint acceleration = (buf->ReadByte() * 128) / 10;
|
||||
if (acceleration > UINT8_MAX) {
|
||||
grfmsg(1, "Acceleration property of aircraft %d is too big.", engine + i);
|
||||
acceleration = UINT8_MAX;
|
||||
}
|
||||
avi->acceleration = acceleration;
|
||||
break;
|
||||
}
|
||||
|
||||
case PROP_AIRCRAFT_RUNNING_COST_FACTOR: // 0x0E Running cost factor
|
||||
avi->running_cost = buf->ReadByte();
|
||||
|
|
|
@ -909,8 +909,14 @@ void ShowLastNewsMessage()
|
|||
} else if (_forced_news == NULL) {
|
||||
/* Not forced any news yet, show the current one, unless a news window is
|
||||
* open (which can only be the current one), then show the previous item */
|
||||
const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
|
||||
ni = (w == NULL || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
|
||||
if (_current_news == NULL) {
|
||||
/* No news were shown yet resp. the last shown one was already deleted.
|
||||
* Threat this as if _forced_news reached _oldest_news; so, wrap around and start anew with the latest. */
|
||||
ni = _latest_news;
|
||||
} else {
|
||||
const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
|
||||
ni = (w == NULL || (_current_news == _oldest_news)) ? _current_news : _current_news->prev;
|
||||
}
|
||||
} else if (_forced_news == _oldest_news) {
|
||||
/* We have reached the oldest news, start anew with the latest */
|
||||
ni = _latest_news;
|
||||
|
|
|
@ -83,9 +83,9 @@ struct OskWindow : public Window {
|
|||
|
||||
for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
|
||||
this->SetWidgetDisabledState(WID_OSK_LETTERS + i,
|
||||
!IsValidChar(_keyboard[this->shift][i], this->qs->afilter) || _keyboard[this->shift][i] == ' ');
|
||||
!IsValidChar(_keyboard[this->shift][i], this->qs->text.afilter) || _keyboard[this->shift][i] == ' ');
|
||||
}
|
||||
this->SetWidgetDisabledState(WID_OSK_SPACE, !IsValidChar(' ', this->qs->afilter));
|
||||
this->SetWidgetDisabledState(WID_OSK_SPACE, !IsValidChar(' ', this->qs->text.afilter));
|
||||
|
||||
this->SetWidgetLoweredState(WID_OSK_SHIFT, HasBit(_keystate, KEYS_SHIFT));
|
||||
this->SetWidgetLoweredState(WID_OSK_CAPS, HasBit(_keystate, KEYS_CAPS));
|
||||
|
@ -113,7 +113,7 @@ struct OskWindow : public Window {
|
|||
if (widget >= WID_OSK_LETTERS) {
|
||||
WChar c = _keyboard[this->shift][widget - WID_OSK_LETTERS];
|
||||
|
||||
if (!IsValidChar(c, this->qs->afilter)) return;
|
||||
if (!IsValidChar(c, this->qs->text.afilter)) return;
|
||||
|
||||
if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ struct QueryString {
|
|||
int cancel_button; ///< Widget button of parent window to simulate when pressing CANCEL in OSK.
|
||||
Textbuf text;
|
||||
const char *orig;
|
||||
CharSetFilter afilter;
|
||||
bool handled;
|
||||
|
||||
/**
|
||||
|
|
|
@ -160,7 +160,6 @@ struct SignListWindow : Window, SignList {
|
|||
this->querystrings[WID_SIL_FILTER_TEXT] = &this->filter_editbox;
|
||||
this->filter_editbox.ok_button = WID_SIL_FILTER_ENTER_BTN;
|
||||
this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
|
||||
this->filter_editbox.afilter = CS_ALPHANUMERAL;
|
||||
|
||||
/* Initialize the filtering variables */
|
||||
this->SetFilterString("");
|
||||
|
@ -419,7 +418,6 @@ struct SignWindow : Window, SignList {
|
|||
this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
|
||||
this->name_editbox.cancel_button = WID_QES_CANCEL;
|
||||
this->name_editbox.ok_button = WID_QES_OK;
|
||||
this->name_editbox.afilter = CS_ALPHANUMERAL;
|
||||
|
||||
this->InitNested(desc, WN_QUERY_STRING_SIGN);
|
||||
|
||||
|
|
|
@ -862,7 +862,7 @@ static void GfxInitSpriteCache()
|
|||
try {
|
||||
/* Try to allocate 50% more to make sure we do not allocate almost all available. */
|
||||
_spritecache_ptr = reinterpret_cast<MemBlock *>(new byte[_allocated_sprite_cache_size + _allocated_sprite_cache_size / 2]);
|
||||
} catch (std::bad_alloc &oom) {
|
||||
} catch (std::bad_alloc &) {
|
||||
_spritecache_ptr = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ bool Textbuf::InsertClipboard()
|
|||
uint16 pixels = 0, bytes = 0, chars = 0;
|
||||
WChar c;
|
||||
for (const char *ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) {
|
||||
if (!IsPrintable(c)) break;
|
||||
if (!IsValidChar(c, this->afilter)) break;
|
||||
|
||||
byte len = Utf8CharLen(c);
|
||||
if (this->bytes + bytes + len > this->max_bytes) break;
|
||||
|
@ -364,6 +364,7 @@ Textbuf::Textbuf(uint16 max_bytes, uint16 max_chars)
|
|||
assert(max_bytes != 0);
|
||||
assert(max_chars != 0);
|
||||
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->max_bytes = max_bytes;
|
||||
this->max_chars = max_chars == UINT16_MAX ? max_bytes : max_chars;
|
||||
this->caret = true;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
/** Helper/buffer for input fields. */
|
||||
struct Textbuf {
|
||||
CharSetFilter afilter; ///< Allowed characters
|
||||
char * const buf; ///< buffer in which text is saved
|
||||
uint16 max_bytes; ///< the maximum size of the buffer in bytes (including terminating '\0')
|
||||
uint16 max_chars; ///< the maximum size of the buffer in characters (including terminating '\0')
|
||||
|
|
Loading…
Reference in New Issue