diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 5d3475ee80..064c645209 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -129,6 +129,7 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t) InvalidateWindowClassesData(WC_BUS_STATION, 0); InvalidateWindowClassesData(WC_TRUCK_STATION, 0); InvalidateWindowClassesData(WC_BUILD_OBJECT, 0); + InvalidateWindowClassesData(WC_FINANCES, 0); ResetSignalVariant(); return TimerGameCalendar::year.base(); } diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index c2cc0a2581..83aa4d2dd8 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -796,7 +796,7 @@ static IntervalTimer _economy_companies_yearly({TimerGameEcono /* Move expenses to previous years. */ std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses)); c->yearly_expenses[0] = {}; - SetWindowDirty(WC_FINANCES, c->index); + InvalidateWindowData(WC_FINANCES, c->index); } if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) { diff --git a/src/company_gui.cpp b/src/company_gui.cpp index eed9fa3f02..46a8c00da0 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -333,8 +333,11 @@ static constexpr NWidgetPart _nested_company_finances_widgets[] = { /** Window class displaying the company finances. */ struct CompanyFinancesWindow : Window { + static constexpr int NUM_PERIODS = WID_CF_EXPS_PRICE3 - WID_CF_EXPS_PRICE1 + 1; + static Money max_money; ///< The maximum amount of money a company has had this 'run' bool small; ///< Window is toggled to 'small'. + uint8_t first_visible = NUM_PERIODS - 1; ///< First visible expenses column. The last column (current) is always visible. CompanyFinancesWindow(WindowDesc &desc, CompanyID company) : Window(desc) { @@ -344,6 +347,7 @@ struct CompanyFinancesWindow : Window { this->FinishInitNested(company); this->owner = (Owner)this->window_number; + this->InvalidateData(); } void SetStringParameters(WidgetID widget) const override @@ -426,12 +430,12 @@ struct CompanyFinancesWindow : Window { case WID_CF_EXPS_PRICE1: case WID_CF_EXPS_PRICE2: case WID_CF_EXPS_PRICE3: { + int period = widget - WID_CF_EXPS_PRICE1; + if (period < this->first_visible) break; + const Company *c = Company::Get((CompanyID)this->window_number); - auto age = std::min(TimerGameEconomy::year - c->inaugurated_year, TimerGameEconomy::Year(2)); - int wid_offset = widget - WID_CF_EXPS_PRICE1; - if (wid_offset <= age) { - DrawYearColumn(r, TimerGameEconomy::year - (age - wid_offset), c->yearly_expenses[(age - wid_offset).base()]); - } + const auto &expenses = c->yearly_expenses[NUM_PERIODS - period - 1]; + DrawYearColumn(r, TimerGameEconomy::year - (NUM_PERIODS - period - 1), expenses); break; } @@ -514,6 +518,24 @@ struct CompanyFinancesWindow : Window { } } + void RefreshVisibleColumns() + { + for (uint period = 0; period < this->first_visible; ++period) { + const Company *c = Company::Get((CompanyID)this->window_number); + const Expenses &expenses = c->yearly_expenses[NUM_PERIODS - period - 1]; + /* Show expenses column if it has any non-zero value in it. */ + if (std::ranges::any_of(expenses, [](const Money &value) { return value != 0; })) { + this->first_visible = period; + break; + } + } + } + + void OnInvalidateData(int, bool) override + { + this->RefreshVisibleColumns(); + } + /** * Check on a regular interval if the maximum amount of money has changed. * If it has, rescale the window to fit the new amount.