1
0
Fork 0

Change: Show company finances column if it has any values in it. (#13112)

This solves finances not being show if the company inauguration date is in the future.

Current period is now always shown in the same position instead of moving for the first 2 years.
pull/13122/head
Peter Nelson 2024-11-24 11:59:30 +00:00 committed by GitHub
parent 0c04966dc3
commit 0446123194
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 6 deletions

View File

@ -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();
}

View File

@ -796,7 +796,7 @@ static IntervalTimer<TimerGameEconomy> _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) {

View File

@ -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.