1
0
Fork 0

(svn r22252) [1.1] -Backport from trunk:

- Fix: Do not resort town, industry and signs list directly in OnInvalidateData(). There might be a scheduled rebuild which needs execution first. So, only set a trigger for resorting [FS#4546] (r22249, r22248, r22247, r22246, r22245, r22244, r22243, r22242, r22241, r22236, r22228, r22227, r22226)
release/1.1
rubidium 2011-03-14 19:03:17 +00:00
parent fbea0fc6b1
commit 633454f0dd
45 changed files with 533 additions and 129 deletions

View File

@ -182,13 +182,20 @@ struct AIListWindow : public Window {
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) { if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
delete this; delete this;
return; return;
} }
if (!gui_scope) return;
this->vscroll->SetCount((int)this->ai_info_list->size() + 1); this->vscroll->SetCount((int)this->ai_info_list->size() + 1);
/* selected goes from -1 .. length of ai list - 1. */ /* selected goes from -1 .. length of ai list - 1. */
@ -437,7 +444,12 @@ struct AISettingsWindow : public Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) delete this; if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) delete this;
} }
@ -692,12 +704,19 @@ struct AIConfigWindow : public Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!IsEditable(this->selected_slot)) { if (!IsEditable(this->selected_slot)) {
this->selected_slot = INVALID_COMPANY; this->selected_slot = INVALID_COMPANY;
} }
if (!gui_scope) return;
this->SetWidgetDisabledState(AIC_WIDGET_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0); this->SetWidgetDisabledState(AIC_WIDGET_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
this->SetWidgetDisabledState(AIC_WIDGET_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1); this->SetWidgetDisabledState(AIC_WIDGET_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
this->SetWidgetDisabledState(AIC_WIDGET_CHANGE, this->selected_slot == INVALID_COMPANY); this->SetWidgetDisabledState(AIC_WIDGET_CHANGE, this->selected_slot == INVALID_COMPANY);
@ -1032,11 +1051,16 @@ struct AIDebugWindow : public QueryStringBaseWindow {
return state; return state;
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == -1 || ai_debug_company == data) this->SetDirty(); if (data == -1 || ai_debug_company == data) this->SetDirty();
if (data == -2) { if (gui_scope && data == -2) {
/* The continue button should be disabled when the game is unpaused and /* The continue button should be disabled when the game is unpaused and
* it was previously paused by the break string ( = a line in the log * it was previously paused by the break string ( = a line in the log
* was highlighted )*/ * was highlighted )*/
@ -1048,8 +1072,9 @@ struct AIDebugWindow : public QueryStringBaseWindow {
} }
} }
/* If the log message is related to the active company tab, check the break string */ /* If the log message is related to the active company tab, check the break string.
if (data == ai_debug_company && this->break_check_enabled && !StrEmpty(this->edit_str_buf)) { * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
if (!gui_scope && data == ai_debug_company && this->break_check_enabled && !StrEmpty(this->edit_str_buf)) {
/* Get the log instance of the active company */ /* Get the log instance of the active company */
Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE); Backup<CompanyByte> cur_company(_current_company, ai_debug_company, FILE_LINE);
AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer(); AILog::LogData *log = (AILog::LogData *)AIObject::GetLogPointer();

View File

@ -75,7 +75,7 @@
/* Also still print to debug window */ /* Also still print to debug window */
DEBUG(ai, level, "[%d] [%c] %s", (uint)_current_company, logc, log->lines[log->pos]); DEBUG(ai, level, "[%d] [%c] %s", (uint)_current_company, logc, log->lines[log->pos]);
InvalidateWindowData(WC_AI_DEBUG, 0, _current_company, true); // breakpoint handling needs calling Invalidate immediately. InvalidateWindowData(WC_AI_DEBUG, 0, _current_company);
} }
/* static */ void AILog::FreeLogPointer() /* static */ void AILog::FreeLogPointer()

View File

@ -491,9 +491,15 @@ public:
this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll[0]->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll[0]->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data != 0) { if (data != 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->engines[0].ForceRebuild(); this->engines[0].ForceRebuild();
} else { } else {
this->engines[1].ForceRebuild(); this->engines[1].ForceRebuild();

View File

@ -1218,8 +1218,14 @@ struct BuildVehicleWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */ /* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
if (this->vehicle_type == VEH_ROAD && if (this->vehicle_type == VEH_ROAD &&
_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL &&

View File

@ -800,8 +800,14 @@ public:
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetWidgetsDisabledState(true, SCLW_WIDGET_CLASS_RAIL, SCLW_WIDGET_CLASS_ROAD, SCLW_WIDGET_CLASS_SHIP, SCLW_WIDGET_CLASS_AIRCRAFT, WIDGET_LIST_END); this->SetWidgetsDisabledState(true, SCLW_WIDGET_CLASS_RAIL, SCLW_WIDGET_CLASS_ROAD, SCLW_WIDGET_CLASS_SHIP, SCLW_WIDGET_CLASS_AIRCRAFT, WIDGET_LIST_END);
bool current_class_valid = this->livery_class == LC_OTHER; bool current_class_valid = this->livery_class == LC_OTHER;

View File

@ -635,7 +635,12 @@ struct DepotWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
this->generate_list = true; this->generate_list = true;
} }

View File

@ -119,8 +119,14 @@ struct BuildDocksToolbarWindow : Window {
if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
} }
void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP), this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP),
DTW_DEPOT, DTW_DEPOT,
DTW_STATION, DTW_STATION,

View File

@ -659,17 +659,24 @@ public:
this->vscroll->SetCapacityFromWidget(this, SLWW_DRIVES_DIRECTORIES_LIST); this->vscroll->SetCapacityFromWidget(this, SLWW_DRIVES_DIRECTORIES_LIST);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
switch (data) { switch (data) {
case 0: case 0:
/* Rescan files */ /* Rescan files */
this->selected = NULL; this->selected = NULL;
_load_check_data.Clear(); _load_check_data.Clear();
if (!gui_scope) break;
BuildFileList(); BuildFileList();
/* FALL THROUGH */ /* FALL THROUGH */
case 1: case 1:
/* Selection changes */ /* Selection changes */
if (!gui_scope) break;
if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
this->SetWidgetDisabledState(SLWW_LOAD_BUTTON, this->SetWidgetDisabledState(SLWW_LOAD_BUTTON,
this->selected == NULL || _load_check_data.HasErrors() || !(_load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs())); this->selected == NULL || _load_check_data.HasErrors() || !(_load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()));

View File

@ -425,8 +425,14 @@ struct GenerateLandscapeWindow : public QueryStringBaseWindow {
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* Update the climate buttons */ /* Update the climate buttons */
this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE); this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
this->SetWidgetLoweredState(GLAND_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC); this->SetWidgetLoweredState(GLAND_ARCTIC, _settings_newgame.game_creation.landscape == LT_ARCTIC);

View File

@ -91,8 +91,14 @@ struct GraphLegendWindow : Window {
InvalidateWindowData(WC_COMPANY_VALUE, 0); InvalidateWindowData(WC_COMPANY_VALUE, 0);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (Company::IsValidID(data)) return; if (Company::IsValidID(data)) return;
SetBit(_legend_excluded_companies, data); SetBit(_legend_excluded_companies, data);
@ -543,8 +549,14 @@ public:
this->UpdateStatistics(false); this->UpdateStatistics(false);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->UpdateStatistics(true); this->UpdateStatistics(true);
} }
@ -1013,8 +1025,14 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
/* Override default OnTick */ /* Override default OnTick */
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->OnHundredthTick(); this->OnHundredthTick();
} }
@ -1247,9 +1265,15 @@ public:
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == 0) { if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->companies.ForceRebuild(); this->companies.ForceRebuild();
} else { } else {
this->companies.ForceResort(); this->companies.ForceResort();
@ -1488,11 +1512,13 @@ struct PerformanceRatingDetailWindow : Window {
} }
/** /**
* Invalidate the data of this window. * Some data on this window has become invalid.
* @param data the company ID of the company that is going to be removed * @param data the company ID of the company that is going to be removed
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/ */
virtual void OnInvalidateData(int data) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* Disable the companies who are not active */ /* Disable the companies who are not active */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !Company::IsValidID(i)); this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !Company::IsValidID(i));

View File

@ -253,9 +253,15 @@ public:
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == 0) { if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->vehicles.ForceRebuild(); this->vehicles.ForceRebuild();
this->groups.ForceRebuild(); this->groups.ForceRebuild();
} else { } else {
@ -263,6 +269,7 @@ public:
this->groups.ForceResort(); this->groups.ForceResort();
} }
/* Process ID-invalidation in command-scope as well */
if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) { if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) {
DeleteWindowByClass(WC_QUERY_STRING); DeleteWindowByClass(WC_QUERY_STRING);
this->group_rename = INVALID_GROUP; this->group_rename = INVALID_GROUP;

View File

@ -597,8 +597,14 @@ public:
this->RaiseButtons(); this->RaiseButtons();
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetupArrays(); this->SetupArrays();
const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type); const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
@ -947,8 +953,14 @@ public:
this->SetDirty(); this->SetDirty();
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
const Industry *i = Industry::Get(this->window_number); const Industry *i = Industry::Get(this->window_number);
if (IsProductionAlterable(i)) { if (IsProductionAlterable(i)) {
const IndustrySpec *ind = GetIndustrySpec(i->type); const IndustrySpec *ind = GetIndustrySpec(i->type);
@ -1334,20 +1346,31 @@ public:
this->vscroll->SetCapacityFromWidget(this, IDW_INDUSTRY_LIST); this->vscroll->SetCapacityFromWidget(this, IDW_INDUSTRY_LIST);
} }
virtual void OnPaint()
{
if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
this->DrawWidgets();
}
virtual void OnHundredthTick() virtual void OnHundredthTick()
{ {
this->industries.ForceResort(); this->industries.ForceResort();
this->BuildSortIndustriesList(); this->BuildSortIndustriesList();
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == 0) { if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->industries.ForceRebuild(); this->industries.ForceRebuild();
} else { } else {
this->industries.ForceResort(); this->industries.ForceResort();
} }
this->BuildSortIndustriesList();
} }
}; };
@ -2386,13 +2409,15 @@ struct IndustryCargoesWindow : public Window {
} }
/** /**
* Notify the window about external events. * Some data on this window has become invalid.
* @param data Information about the changed data.
* - data = 0 .. NUM_INDUSTRYTYPES - 1: Display the chain around the given industry. * - data = 0 .. NUM_INDUSTRYTYPES - 1: Display the chain around the given industry.
* - data = NUM_INDUSTRYTYPES: Stop sending updates to the smallmap window. * - data = NUM_INDUSTRYTYPES: Stop sending updates to the smallmap window.
* @param data The event. * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/ */
virtual void OnInvalidateData(int data) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (data == NUM_INDUSTRYTYPES) { if (data == NUM_INDUSTRYTYPES) {
if (this->IsWidgetLowered(ICW_NOTIFY)) { if (this->IsWidgetLowered(ICW_NOTIFY)) {
this->RaiseWidget(ICW_NOTIFY); this->RaiseWidget(ICW_NOTIFY);

View File

@ -55,8 +55,14 @@ struct SelectGameWindow : public Window {
this->OnInvalidateData(); this->OnInvalidateData();
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetWidgetLoweredState(SGI_TEMPERATE_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TEMPERATE); this->SetWidgetLoweredState(SGI_TEMPERATE_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
this->SetWidgetLoweredState(SGI_ARCTIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_ARCTIC); this->SetWidgetLoweredState(SGI_ARCTIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_ARCTIC);
this->SetWidgetLoweredState(SGI_TROPIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TROPIC); this->SetWidgetLoweredState(SGI_TROPIC_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TROPIC);

View File

@ -432,8 +432,14 @@ struct MainWindow : Window
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* Forward the message to the appropiate toolbar (ingame or scenario editor) */ /* Forward the message to the appropiate toolbar (ingame or scenario editor) */
InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true); InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true);
} }

View File

@ -331,8 +331,14 @@ public:
::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile); ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
switch (data) { switch (data) {
case 1: case 1:
/* ReInit, "debug" sprite might have changed */ /* ReInit, "debug" sprite might have changed */
@ -638,7 +644,12 @@ public:
return pt; return pt;
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
/* If company gets shut down, while displaying an error about it, remove the error message. */ /* If company gets shut down, while displaying an error about it, remove the error message. */
if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) delete this; if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) delete this;

View File

@ -312,8 +312,14 @@ struct MusicTrackSelectionWindow : public Window {
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
this->SetWidgetLoweredState(MTSW_ALL + i, i == _msf.playlist); this->SetWidgetLoweredState(MTSW_ALL + i, i == _msf.playlist);
} }
@ -637,8 +643,14 @@ struct MusicWindow : public Window {
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
this->SetWidgetLoweredState(MW_ALL + i, i == _msf.playlist); this->SetWidgetLoweredState(MW_ALL + i, i == _msf.playlist);
} }

View File

@ -531,7 +531,12 @@ struct NetworkChatWindow : public QueryStringBaseWindow {
ShowOnScreenKeyboard(this, wid, NWCW_CLOSE, NWCW_SENDBUTTON); ShowOnScreenKeyboard(this, wid, NWCW_CLOSE, NWCW_SENDBUTTON);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == this->dest) delete this; if (data == this->dest) delete this;
} }

View File

@ -751,8 +751,14 @@ public:
this->InvalidateData(); this->InvalidateData();
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (this->content.NeedRebuild()) this->BuildContentList(); if (this->content.NeedRebuild()) this->BuildContentList();
/* To sum all the bytes we intend to download */ /* To sum all the bytes we intend to download */

View File

@ -794,7 +794,12 @@ public:
if (this->field == NGWW_CLIENT) this->HandleEditBox(NGWW_CLIENT); if (this->field == NGWW_CLIENT) this->HandleEditBox(NGWW_CLIENT);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == 1) { if (data == 1) {
this->server = NULL; this->server = NULL;

View File

@ -772,8 +772,14 @@ struct SpriteAlignerWindow : Window {
this->SetDirty(); this->SetDirty();
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (data == 1) { if (data == 1) {
/* Sprite picker finished */ /* Sprite picker finished */
this->RaiseWidget(SAW_PICKER); this->RaiseWidget(SAW_PICKER);

View File

@ -379,8 +379,14 @@ struct NewGRFParametersWindow : public Window {
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (!this->action14present) { if (!this->action14present) {
this->SetWidgetDisabledState(GRFPAR_WIDGET_NUMPAR_DEC, this->grf_config->num_params == 0); this->SetWidgetDisabledState(GRFPAR_WIDGET_NUMPAR_DEC, this->grf_config->num_params == 0);
this->SetWidgetDisabledState(GRFPAR_WIDGET_NUMPAR_INC, this->grf_config->num_params >= this->grf_config->num_valid_params); this->SetWidgetDisabledState(GRFPAR_WIDGET_NUMPAR_INC, this->grf_config->num_params >= this->grf_config->num_valid_params);
@ -1025,15 +1031,18 @@ struct NewGRFWindow : public QueryStringBaseWindow {
} }
/** /**
* Calback to update internal data. * Some data on this window has become invalid.
* @param data Information about the changed data.
* - 0: (optionally) build availables, update button status. * - 0: (optionally) build availables, update button status.
* - 1: build availables, Add newly found grfs, update button status. * - 1: build availables, Add newly found grfs, update button status.
* - 2: (optionally) build availables, Reset preset, + 3 * - 2: (optionally) build availables, Reset preset, + 3
* - 3: (optionally) build availables, Update active scrollbar, update button status. * - 3: (optionally) build availables, Update active scrollbar, update button status.
* - 4: Force a rebuild of the availables, + 2 * - 4: Force a rebuild of the availables, + 2
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/ */
virtual void OnInvalidateData(int data = 0) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
switch (data) { switch (data) {
default: NOT_REACHED(); default: NOT_REACHED();
case 0: case 0:

View File

@ -498,8 +498,14 @@ struct NewsWindow : Window {
return ES_NOT_HANDLED; return ES_NOT_HANDLED;
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* The chatbar has notified us that is was either created or closed */ /* The chatbar has notified us that is was either created or closed */
int newtop = this->top + this->chat_height - data; int newtop = this->top + this->chat_height - data;
this->chat_height = data; this->chat_height = data;
@ -1035,8 +1041,14 @@ struct MessageHistoryWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->vscroll->SetCount(_total_news); this->vscroll->SetCount(_total_news);
} }
@ -1201,8 +1213,14 @@ struct MessageOptionsWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* Update the dropdown value for 'set all categories'. */ /* Update the dropdown value for 'set all categories'. */
this->GetWidget<NWidgetCore>(WIDGET_NEWSOPT_DROP_SUMMARY)->widget_data = this->message_opt[this->state]; this->GetWidget<NWidgetCore>(WIDGET_NEWSOPT_DROP_SUMMARY)->widget_data = this->message_opt[this->state];

View File

@ -805,13 +805,18 @@ public:
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
VehicleOrderID from = GB(data, 0, 8); VehicleOrderID from = INVALID_VEH_ORDER_ID;
VehicleOrderID to = GB(data, 8, 8); VehicleOrderID to = INVALID_VEH_ORDER_ID;
switch (data) { switch (data) {
case 0: case -666:
/* Autoreplace replaced the vehicle */ /* Autoreplace replaced the vehicle */
this->vehicle = Vehicle::Get(this->window_number); this->vehicle = Vehicle::Get(this->window_number);
break; break;
@ -830,6 +835,11 @@ public:
break; break;
default: default:
if (data < 0) break;
if (gui_scope) break; // only do this once; from command scope
from = GB(data, 0, 8);
to = GB(data, 8, 8);
/* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
* the order is being created / removed */ * the order is being created / removed */
if (this->selected_order == -1) break; if (this->selected_order == -1) break;
@ -859,7 +869,7 @@ public:
} }
this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1); this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
this->UpdateButtonState(); if (gui_scope) this->UpdateButtonState();
/* Scroll to the new order. */ /* Scroll to the new order. */
if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) { if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {

View File

@ -247,8 +247,14 @@ struct OskWindow : public Window {
this->parent->SetWidgetDirty(this->text_btn); this->parent->SetWidgetDirty(this->text_btn);
} }
virtual void OnInvalidateData(int) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetWidgetDirty(OSK_WIDGET_TEXT); this->SetWidgetDirty(OSK_WIDGET_TEXT);
} }
}; };

View File

@ -1617,8 +1617,14 @@ public:
this->InvalidateData(); this->InvalidateData();
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->LowerWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type); this->LowerWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type);
this->SetWidgetLoweredState(BSW_CONVERT, _convert_signal_button); this->SetWidgetLoweredState(BSW_CONVERT, _convert_signal_button);

View File

@ -341,8 +341,14 @@ struct BuildRoadToolbarWindow : Window {
if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
} }
void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD), this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
RTW_DEPOT, RTW_DEPOT,
RTW_BUS_STATION, RTW_BUS_STATION,

View File

@ -460,8 +460,14 @@ struct GameOptionsWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->SetWidgetLoweredState(GOW_FULLSCREEN_BUTTON, _fullscreen); this->SetWidgetLoweredState(GOW_FULLSCREEN_BUTTON, _fullscreen);
bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0; bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
@ -724,8 +730,14 @@ public:
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
uint i; uint i;
const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i); const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) { for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {

View File

@ -164,9 +164,7 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
/* Create initial list. */ /* Create initial list. */
this->signs.ForceRebuild(); this->signs.ForceRebuild();
this->signs.ForceResort(); this->signs.ForceResort();
this->BuildSignsList(); this->BuildSortSignList();
this->SortSignsList();
this->vscroll->SetCount(this->signs.Length());
} }
/** /**
@ -214,6 +212,7 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
virtual void OnPaint() virtual void OnPaint()
{ {
if (this->signs.NeedRebuild()) this->BuildSortSignList();
this->DrawWidgets(); this->DrawWidgets();
if (!this->IsShaded()) this->DrawEditBox(SLW_FILTER_TEXT); if (!this->IsShaded()) this->DrawEditBox(SLW_FILTER_TEXT);
} }
@ -352,23 +351,38 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
this->HandleEditBox(SLW_FILTER_TEXT); this->HandleEditBox(SLW_FILTER_TEXT);
} }
void BuildSortSignList()
{
if (this->signs.NeedRebuild()) {
this->BuildSignsList();
this->vscroll->SetCount(this->signs.Length());
this->SetWidgetDirty(SLW_CAPTION);
}
this->SortSignsList();
}
virtual void OnInvalidateData(int data) virtual void OnHundredthTick()
{
this->BuildSortSignList();
this->SetDirty();
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
/* When there is a filter string, we always need to rebuild the list even if /* When there is a filter string, we always need to rebuild the list even if
* the amount of signs in total is unchanged, as the subset of signs that is * the amount of signs in total is unchanged, as the subset of signs that is
* accepted by the filter might has changed. * accepted by the filter might has changed. */
*/
if (data == 0 || !StrEmpty(this->filter_string)) { // New or deleted sign, or there is a filter string if (data == 0 || !StrEmpty(this->filter_string)) { // New or deleted sign, or there is a filter string
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->signs.ForceRebuild(); this->signs.ForceRebuild();
this->BuildSignsList();
this->SetWidgetDirty(SLW_CAPTION);
this->vscroll->SetCount(this->signs.Length());
} else { // Change of sign contents while there is no filter string } else { // Change of sign contents while there is no filter string
this->signs.ForceResort(); this->signs.ForceResort();
} }
this->SortSignsList();
} }
static Hotkey<SignListWindow> signlist_hotkeys[]; static Hotkey<SignListWindow> signlist_hotkeys[];

View File

@ -1423,12 +1423,15 @@ public:
} }
/** /**
* Notifications for the smallmap window. * Some data on this window has become invalid.
* @param data Information about the changed data.
* - data = 0: Displayed industries at the industry chain window have changed. * - data = 0: Displayed industries at the industry chain window have changed.
* - data = 1: Companies have changed. * - data = 1: Companies have changed.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/ */
virtual void OnInvalidateData(int data) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
switch (data) { switch (data) {
case 1: case 1:
/* The owner legend has already been rebuilt. */ /* The owner legend has already been rebuilt. */

View File

@ -687,9 +687,15 @@ public:
this->vscroll->SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM); this->vscroll->SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == 0) { if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->stations.ForceRebuild(); this->stations.ForceRebuild();
} else { } else {
this->stations.ForceResort(); this->stations.ForceResort();
@ -1448,8 +1454,14 @@ struct SelectStationWindow : Window {
this->vscroll->SetCapacityFromWidget(this, JSW_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM); this->vscroll->SetCapacityFromWidget(this, JSW_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
FindStationsNearby<T>(this->area, true); FindStationsNearby<T>(this->area, true);
this->vscroll->SetCount(_stations_nearby_list.Length() + 1); this->vscroll->SetCount(_stations_nearby_list.Length() + 1);
this->SetDirty(); this->SetDirty();

View File

@ -183,8 +183,14 @@ struct StatusBarWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
switch (data) { switch (data) {
default: NOT_REACHED(); default: NOT_REACHED();
case SBI_SAVELOAD_START: this->saving = true; break; case SBI_SAVELOAD_START: this->saving = true; break;

View File

@ -215,8 +215,14 @@ struct SubsidyListWindow : Window {
this->vscroll->SetCapacityFromWidget(this, SLW_PANEL); this->vscroll->SetCapacityFromWidget(this, SLW_PANEL);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->vscroll->SetCount(this->CountLines()); this->vscroll->SetCount(this->CountLines());
} }
}; };

View File

@ -243,10 +243,15 @@ struct TimetableWindow : Window {
return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER; return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER;
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
switch (data) { switch (data) {
case 0: case -666:
/* Autoreplace replaced the vehicle */ /* Autoreplace replaced the vehicle */
this->vehicle = Vehicle::Get(this->window_number); this->vehicle = Vehicle::Get(this->window_number);
break; break;
@ -260,11 +265,14 @@ struct TimetableWindow : Window {
break; break;
case -2: case -2:
if (!gui_scope) break;
this->UpdateSelectionStates(); this->UpdateSelectionStates();
this->ReInit(); this->ReInit();
break; break;
default: { default: {
if (gui_scope) break; // only do this once; from command scope
/* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
* the order is being created / removed */ * the order is being created / removed */
if (this->sel_index == -1) break; if (this->sel_index == -1) break;

View File

@ -1482,8 +1482,14 @@ struct MainToolbarWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, TBN_ZOOMIN, TBN_ZOOMOUT); if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, TBN_ZOOMIN, TBN_ZOOMOUT);
} }
@ -1792,8 +1798,14 @@ struct ScenarioEditorToolbarWindow : Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, TBSE_ZOOMIN, TBSE_ZOOMOUT); if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, TBSE_ZOOMIN, TBSE_ZOOMOUT);
} }

View File

@ -523,8 +523,14 @@ public:
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* Called when setting station noise or required cargos have changed, in order to resize the window */ /* Called when setting station noise or required cargos have changed, in order to resize the window */
this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
this->ResizeWindowAsNeeded(); this->ResizeWindowAsNeeded();
@ -846,6 +852,12 @@ public:
} }
} }
virtual void OnPaint()
{
if (this->towns.NeedRebuild()) this->BuildSortTownList();
this->DrawWidgets();
}
virtual void OnHundredthTick() virtual void OnHundredthTick()
{ {
this->BuildSortTownList(); this->BuildSortTownList();
@ -857,14 +869,19 @@ public:
this->vscroll->SetCapacityFromWidget(this, TDW_CENTERTOWN); this->vscroll->SetCapacityFromWidget(this, TDW_CENTERTOWN);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == 0) { if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->towns.ForceRebuild(); this->towns.ForceRebuild();
} else { } else {
this->towns.ForceResort(); this->towns.ForceResort();
} }
this->BuildSortTownList();
} }
}; };
@ -1157,8 +1174,14 @@ public:
this->UpdateButtons(false); this->UpdateButtons(false);
} }
virtual void OnInvalidateData(int) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->UpdateButtons(true); this->UpdateButtons(true);
} }
}; };

View File

@ -264,7 +264,7 @@ void Train::ConsistChanged(bool same_length)
if (this->IsFrontEngine()) { if (this->IsFrontEngine()) {
this->UpdateAcceleration(); this->UpdateAcceleration();
SetWindowDirty(WC_VEHICLE_DETAILS, this->index); SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
InvalidateWindowData(WC_VEHICLE_REFIT, this->index); // Important, do not invalidate immediately. The refit window tests commands. InvalidateWindowData(WC_VEHICLE_REFIT, this->index);
} }
} }
@ -1092,7 +1092,7 @@ static void NormaliseTrainHead(Train *head)
if (!head->IsFrontEngine()) return; if (!head->IsFrontEngine()) return;
/* Update the refit button and window */ /* Update the refit button and window */
InvalidateWindowData(WC_VEHICLE_REFIT, head->index); // Important, do not invalidate immediately. The refit window tests commands. InvalidateWindowData(WC_VEHICLE_REFIT, head->index);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, VVW_WIDGET_REFIT_VEH); SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, VVW_WIDGET_REFIT_VEH);
/* If we don't have a unit number yet, set one. */ /* If we don't have a unit number yet, set one. */

View File

@ -125,8 +125,14 @@ public:
return pt; return pt;
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
for (uint i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) { for (uint i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) {
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_BEGIN))); this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_BEGIN)));
} }

View File

@ -144,8 +144,14 @@ public:
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
this->base = _tree_base_by_landscape[_settings_game.game_creation.landscape]; this->base = _tree_base_by_landscape[_settings_game.game_creation.landscape];
this->count = _tree_count_by_landscape[_settings_game.game_creation.landscape]; this->count = _tree_count_by_landscape[_settings_game.game_creation.landscape];
} }

View File

@ -2270,7 +2270,7 @@ void Vehicle::RemoveFromShared()
} else if (were_first) { } else if (were_first) {
/* If we were the first one, update to the new first one. /* If we were the first one, update to the new first one.
* Note: FirstShared() is already the new first */ * Note: FirstShared() is already the new first */
InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.Pack(), this->FirstShared()->index | (1U << 31), true); InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.Pack(), this->FirstShared()->index | (1U << 31));
} }
this->next_shared = NULL; this->next_shared = NULL;

View File

@ -683,9 +683,15 @@ struct RefitWindow : public Window {
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
switch (data) { switch (data) {
case -666: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
case 0: { // The consist has changed; rebuild the entire list. case 0: { // The consist has changed; rebuild the entire list.
/* Clear the selection. */ /* Clear the selection. */
Vehicle *v = Vehicle::Get(this->window_number); Vehicle *v = Vehicle::Get(this->window_number);
@ -695,6 +701,7 @@ struct RefitWindow : public Window {
} }
case 2: { // The vehicle selection has changed; rebuild the entire list. case 2: { // The vehicle selection has changed; rebuild the entire list.
if (!gui_scope) break;
this->BuildRefitList(); this->BuildRefitList();
/* The vehicle width has changed too. */ /* The vehicle width has changed too. */
@ -720,6 +727,7 @@ struct RefitWindow : public Window {
} }
case 1: // A new cargo has been selected. case 1: // A new cargo has been selected.
if (!gui_scope) break;
this->cargo = GetRefitOption(); this->cargo = GetRefitOption();
break; break;
} }
@ -1120,8 +1128,8 @@ static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_
_thd.window_number = to_index; _thd.window_number = to_index;
} }
/* Notify the window immediately, without scheduling. */ /* Notify the window. */
w->InvalidateData(); w->InvalidateData(-666, false);
} }
} }
@ -1594,9 +1602,15 @@ public:
this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) { if (!gui_scope && HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) {
/* Needs to be done in command-scope, so everything stays valid */
this->vli.index = GB(data, 0, 20); this->vli.index = GB(data, 0, 20);
this->window_number = this->vli.Pack(); this->window_number = this->vli.Pack();
this->vehicles.ForceRebuild(); this->vehicles.ForceRebuild();
@ -1604,6 +1618,7 @@ public:
} }
if (data == 0) { if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
this->vehicles.ForceRebuild(); this->vehicles.ForceRebuild();
} else { } else {
this->vehicles.ForceResort(); this->vehicles.ForceResort();
@ -1778,8 +1793,19 @@ struct VehicleDetailsWindow : Window {
this->tab = TDW_TAB_CARGO; this->tab = TDW_TAB_CARGO;
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (data == -666) {
/* Autoreplace replaced the vehicle.
* Nothing to do for this window. */
return;
}
if (!gui_scope) return;
const Vehicle *v = Vehicle::Get(this->window_number); const Vehicle *v = Vehicle::Get(this->window_number);
if (v->type == VEH_ROAD) { if (v->type == VEH_ROAD) {
const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(VLD_WIDGET_MIDDLE_DETAILS); const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(VLD_WIDGET_MIDDLE_DETAILS);
@ -2581,6 +2607,20 @@ public:
} }
} }
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
if (data == -666) {
/* Autoreplace replaced the vehicle.
* Nothing to do for this window. */
return;
}
}
virtual bool IsNewGRFInspectable() const virtual bool IsNewGRFInspectable() const
{ {
return ::IsNewGRFInspectable(GetGrfSpecFeature(Vehicle::Get(this->window_number)->type), this->window_number); return ::IsNewGRFInspectable(GetGrfSpecFeature(Vehicle::Get(this->window_number)->type), this->window_number);

View File

@ -148,8 +148,14 @@ public:
} }
} }
virtual void OnInvalidateData(int data = 0) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */ /* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */
HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT); HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT);
} }

View File

@ -114,8 +114,14 @@ public:
} }
} }
virtual void OnInvalidateData(int data) /**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
/* You can only change your own waypoints */ /* You can only change your own waypoints */
this->SetWidgetDisabledState(WAYPVW_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE)); this->SetWidgetDisabledState(WAYPVW_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE));
/* Disable the widget for waypoints with no use */ /* Disable the widget for waypoints with no use */

View File

@ -2403,6 +2403,11 @@ void InputLoop()
void UpdateWindows() void UpdateWindows()
{ {
Window *w; Window *w;
FOR_ALL_WINDOWS_FROM_FRONT(w) {
w->ProcessScheduledInvalidations();
}
static int we4_timer = 0; static int we4_timer = 0;
int t = we4_timer + 1; int t = we4_timer + 1;
@ -2420,7 +2425,6 @@ void UpdateWindows()
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) w->SetDirty(); if (!(w->flags4 & WF_WHITE_BORDER_MASK)) w->SetDirty();
} }
w->ProcessScheduledInvalidations();
} }
DrawDirtyBlocks(); DrawDirtyBlocks();
@ -2477,46 +2481,55 @@ void SetWindowClassesDirty(WindowClass cls)
/** /**
* Mark window data of the window of a given class and specific window number as invalid (in need of re-computing) * Mark window data of the window of a given class and specific window number as invalid (in need of re-computing)
* Note that by default the invalidation is not executed immediately but is scheduled till the next redraw. *
* Note that by default the invalidation is not considered to be called from GUI scope.
* That means only a part of invalidation is executed immediately. The rest is scheduled for the next redraw.
* The asynchronous execution is important to prevent GUI code being executed from command scope. * The asynchronous execution is important to prevent GUI code being executed from command scope.
* When not in GUI-scope:
* - OnInvalidateData() may not do test-runs on commands, as they might affect the execution of
* the command which triggered the invalidation. (town rating and such)
* - OnInvalidateData() may not rely on _current_company == _local_company.
* This implies that no NewGRF callbacks may be run.
*
* However, when invalidations are scheduled, then multiple calls may be scheduled before execution starts. Earlier scheduled
* invalidations may be called with invalidation-data, which is already invalid at the point of execution.
* That means some stuff requires to be executed immediately in command scope, while not everything may be executed in command
* scope. While GUI-scope calls have no restrictions on what they may do, they cannot assume the game to still be in the state
* when the invalidation was scheduled; passed IDs may have got invalid in the mean time.
*
* Finally, note that invalidations triggered from commands or the game loop result in OnInvalidateData() being called twice.
* Once in command-scope, once in GUI-scope. So make sure to not process differential-changes twice.
*
* @param cls Window class * @param cls Window class
* @param number Window number within the class * @param number Window number within the class
* @param data The data to invalidate with * @param data The data to invalidate with
* @param immediately If true then do not schedule the event, but execute immediately. * @param gui_scope Whether the call is done from GUI scope
*/ */
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool immediately) void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
{ {
Window *w; Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) { FOR_ALL_WINDOWS_FROM_BACK(w) {
if (w->window_class == cls && w->window_number == number) { if (w->window_class == cls && w->window_number == number) {
if (immediately) { w->InvalidateData(data, gui_scope);
w->InvalidateData(data);
} else {
w->ScheduleInvalidateData(data);
}
} }
} }
} }
/** /**
* Mark window data of all windows of a given class as invalid (in need of re-computing) * Mark window data of all windows of a given class as invalid (in need of re-computing)
* Note that by default the invalidation is not executed immediately but is scheduled till the next redraw. * Note that by default the invalidation is not considered to be called from GUI scope.
* The asynchronous execution is important to prevent GUI code being executed from command scope. * See InvalidateWindowData() for details on GUI-scope vs. command-scope.
* @param cls Window class * @param cls Window class
* @param data The data to invalidate with * @param data The data to invalidate with
* @param immediately If true then do not schedule the event, but execute immediately. * @param gui_scope Whether the call is done from GUI scope
*/ */
void InvalidateWindowClassesData(WindowClass cls, int data, bool immediately) void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
{ {
Window *w; Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) { FOR_ALL_WINDOWS_FROM_BACK(w) {
if (w->window_class == cls) { if (w->window_class == cls) {
if (immediately) { w->InvalidateData(data, gui_scope);
w->InvalidateData(data);
} else {
w->ScheduleInvalidateData(data);
}
} }
} }
} }

View File

@ -34,8 +34,8 @@ void ResetWindowSystem();
void SetupColoursAndInitialWindow(); void SetupColoursAndInitialWindow();
void InputLoop(); void InputLoop();
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data = 0, bool immediately = false); void InvalidateWindowData(WindowClass cls, WindowNumber number, int data = 0, bool gui_scope = false);
void InvalidateWindowClassesData(WindowClass cls, int data = 0, bool immediately = false); void InvalidateWindowClassesData(WindowClass cls, int data = 0, bool gui_scope = false);
void DeleteNonVitalWindows(); void DeleteNonVitalWindows();
void DeleteAllNonVitalWindows(); void DeleteAllNonVitalWindows();

View File

@ -434,22 +434,16 @@ public:
/** /**
* Mark this window's data as invalid (in need of re-computing) * Mark this window's data as invalid (in need of re-computing)
* @param data The data to invalidate with * @param data The data to invalidate with
* @param gui_scope Whether the funtion is called from GUI scope.
*/ */
void InvalidateData(int data = 0) void InvalidateData(int data = 0, bool gui_scope = true)
{ {
this->SetDirty(); this->SetDirty();
this->OnInvalidateData(data); if (!gui_scope) {
} /* Schedule GUI-scope invalidation for next redraw. */
*this->scheduled_invalidation_data.Append() = data;
/** }
* Schedule a invalidation call for next redraw. this->OnInvalidateData(data, gui_scope);
* Important for asynchronous invalidation from commands.
* @param data The data to invalidate with
*/
void ScheduleInvalidateData(int data = 0)
{
this->SetDirty();
*this->scheduled_invalidation_data.Append() = data;
} }
/** /**
@ -458,7 +452,7 @@ public:
void ProcessScheduledInvalidations() void ProcessScheduledInvalidations()
{ {
for (int *data = this->scheduled_invalidation_data.Begin(); this->window_class != WC_INVALID && data != this->scheduled_invalidation_data.End(); data++) { for (int *data = this->scheduled_invalidation_data.Begin(); this->window_class != WC_INVALID && data != this->scheduled_invalidation_data.End(); data++) {
this->OnInvalidateData(*data); this->OnInvalidateData(*data, true);
} }
this->scheduled_invalidation_data.Clear(); this->scheduled_invalidation_data.Clear();
} }
@ -651,9 +645,9 @@ public:
/** /**
* Some data on this window has become invalid. * Some data on this window has become invalid.
* @param data information about the changed data. * @param data information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/ */
virtual void OnInvalidateData(int data = 0) {} virtual void OnInvalidateData(int data = 0, bool gui_scope = true) {}
/** /**
* The user clicked some place on the map when a tile highlight mode * The user clicked some place on the map when a tile highlight mode