1
0
Fork 0

Change: Only resort industry directory window on production change if necessary

pull/7934/head
Jonathan G Rennison 2020-01-06 20:31:57 +00:00 committed by Charles Pigott
parent 22ba048c89
commit f1734e7815
3 changed files with 25 additions and 9 deletions

View File

@ -197,4 +197,12 @@ struct IndustryBuildData {
extern IndustryBuildData _industry_builder; 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 */ #endif /* INDUSTRY_H */

View File

@ -204,7 +204,7 @@ Industry::~Industry()
*/ */
void Industry::PostDestructor(size_t index) void Industry::PostDestructor(size_t index)
{ {
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD);
} }
@ -1900,7 +1900,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) { if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
for (uint j = 0; j != 50; j++) PlantRandomFarmField(i); 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 (!_generating_world) PopulateStationsNearby(i);
} }
@ -2829,7 +2829,7 @@ void IndustryDailyLoop()
cur_company.Restore(); cur_company.Restore();
/* production-change */ /* production-change */
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1); InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
} }
void IndustryMonthlyLoop() void IndustryMonthlyLoop()
@ -2851,7 +2851,7 @@ void IndustryMonthlyLoop()
cur_company.Restore(); cur_company.Restore();
/* production-change */ /* production-change */
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1); InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
} }

View File

@ -1708,11 +1708,19 @@ public:
*/ */
void OnInvalidateData(int data = 0, bool gui_scope = true) override void OnInvalidateData(int data = 0, bool gui_scope = true) override
{ {
if (data == 0) { switch (data) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */ case IDIWD_FORCE_REBUILD:
this->industries.ForceRebuild(); /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
} else { this->industries.ForceRebuild();
this->industries.ForceResort(); break;
case IDIWD_PRODUCTION_CHANGE:
if (this->industries.SortType() == 2) this->industries.ForceResort();
break;
default:
this->industries.ForceResort();
break;
} }
} }
}; };