diff --git a/src/industry.h b/src/industry.h index 310977aab7..01942e0ac3 100644 --- a/src/industry.h +++ b/src/industry.h @@ -209,4 +209,12 @@ struct IndustryBuildData { extern IndustryBuildData _industry_builder; + +/** Special values for the industry list window for the data parameter of #InvalidateWindowData. */ +enum IndustryDirectoryInvalidateWindowData { + IDIWD_FORCE_REBUILD, + IDIWD_PRODUCTION_CHANGE, + IDIWD_FORCE_RESORT, +}; + #endif /* INDUSTRY_H */ diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 1f35c14d4d..f010135fb2 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -207,7 +207,7 @@ Industry::~Industry() */ void Industry::PostDestructor(size_t index) { - InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); + InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD); } @@ -1910,7 +1910,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) { for (uint j = 0; j != 50; j++) PlantRandomFarmField(i); } - InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); + InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD); if (!_generating_world) PopulateStationsNearby(i); if (_game_mode == GM_NORMAL) RegisterGameEvents(GEF_INDUSTRY_CREATE); @@ -2857,7 +2857,7 @@ void IndustryDailyLoop() cur_company.Restore(); /* production-change */ - InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1); + InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE); } void IndustryMonthlyLoop() @@ -2879,7 +2879,7 @@ void IndustryMonthlyLoop() cur_company.Restore(); /* production-change */ - InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1); + InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 511f3b5210..f0fab8c78c 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1694,11 +1694,19 @@ public: */ void OnInvalidateData(int data = 0, bool gui_scope = true) override { - if (data == 0) { - /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */ - this->industries.ForceRebuild(); - } else { - this->industries.ForceResort(); + switch (data) { + case IDIWD_FORCE_REBUILD: + /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */ + this->industries.ForceRebuild(); + break; + + case IDIWD_PRODUCTION_CHANGE: + if (this->industries.SortType() == 2) this->industries.ForceResort(); + break; + + case IDIWD_FORCE_RESORT: + this->industries.ForceResort(); + break; } } };