mirror of https://github.com/OpenTTD/OpenTTD
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
parent
0c04966dc3
commit
0446123194
|
@ -129,6 +129,7 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
|
||||||
InvalidateWindowClassesData(WC_BUS_STATION, 0);
|
InvalidateWindowClassesData(WC_BUS_STATION, 0);
|
||||||
InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
|
InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
|
||||||
InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
|
InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
|
||||||
|
InvalidateWindowClassesData(WC_FINANCES, 0);
|
||||||
ResetSignalVariant();
|
ResetSignalVariant();
|
||||||
return TimerGameCalendar::year.base();
|
return TimerGameCalendar::year.base();
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,7 +796,7 @@ static IntervalTimer<TimerGameEconomy> _economy_companies_yearly({TimerGameEcono
|
||||||
/* Move expenses to previous years. */
|
/* Move expenses to previous years. */
|
||||||
std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses));
|
std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses));
|
||||||
c->yearly_expenses[0] = {};
|
c->yearly_expenses[0] = {};
|
||||||
SetWindowDirty(WC_FINANCES, c->index);
|
InvalidateWindowData(WC_FINANCES, c->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
|
if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
|
||||||
|
|
|
@ -333,8 +333,11 @@ static constexpr NWidgetPart _nested_company_finances_widgets[] = {
|
||||||
|
|
||||||
/** Window class displaying the company finances. */
|
/** Window class displaying the company finances. */
|
||||||
struct CompanyFinancesWindow : Window {
|
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'
|
static Money max_money; ///< The maximum amount of money a company has had this 'run'
|
||||||
bool small; ///< Window is toggled to 'small'.
|
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)
|
CompanyFinancesWindow(WindowDesc &desc, CompanyID company) : Window(desc)
|
||||||
{
|
{
|
||||||
|
@ -344,6 +347,7 @@ struct CompanyFinancesWindow : Window {
|
||||||
this->FinishInitNested(company);
|
this->FinishInitNested(company);
|
||||||
|
|
||||||
this->owner = (Owner)this->window_number;
|
this->owner = (Owner)this->window_number;
|
||||||
|
this->InvalidateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetStringParameters(WidgetID widget) const override
|
void SetStringParameters(WidgetID widget) const override
|
||||||
|
@ -426,12 +430,12 @@ struct CompanyFinancesWindow : Window {
|
||||||
case WID_CF_EXPS_PRICE1:
|
case WID_CF_EXPS_PRICE1:
|
||||||
case WID_CF_EXPS_PRICE2:
|
case WID_CF_EXPS_PRICE2:
|
||||||
case WID_CF_EXPS_PRICE3: {
|
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);
|
const Company *c = Company::Get((CompanyID)this->window_number);
|
||||||
auto age = std::min(TimerGameEconomy::year - c->inaugurated_year, TimerGameEconomy::Year(2));
|
const auto &expenses = c->yearly_expenses[NUM_PERIODS - period - 1];
|
||||||
int wid_offset = widget - WID_CF_EXPS_PRICE1;
|
DrawYearColumn(r, TimerGameEconomy::year - (NUM_PERIODS - period - 1), expenses);
|
||||||
if (wid_offset <= age) {
|
|
||||||
DrawYearColumn(r, TimerGameEconomy::year - (age - wid_offset), c->yearly_expenses[(age - wid_offset).base()]);
|
|
||||||
}
|
|
||||||
break;
|
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.
|
* Check on a regular interval if the maximum amount of money has changed.
|
||||||
* If it has, rescale the window to fit the new amount.
|
* If it has, rescale the window to fit the new amount.
|
||||||
|
|
Loading…
Reference in New Issue