Index: company_gui.cpp =================================================================== --- company_gui.cpp (revision 15297) +++ company_gui.cpp (working copy) @@ -41,56 +41,130 @@ static void DoShowCompanyFinances(CompanyID company, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL); static void DoSelectCompanyManagerFace(Window *parent, bool show_big, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL); +static void DrawPlayerEconomySingleStat(Money cost, int x, int y, bool showAlways) +{ + StringID str; + + /* draw one row in the price column */ + if (cost != 0 || showAlways) + { + if (cost > 0) { + str = STR_701E; + } else { + cost = -cost; + str = STR_701F; + } + + SetDParam(0, cost); + DrawStringRightAligned(x, y, str, TC_FROMSTRING); + } +} + static void DrawCompanyEconomyStats(const Company *c, bool small) { - int x, y, i, j, year; + int x, y, j, year; const Money (*tbl)[EXPENSES_END]; - Money sum, cost; - StringID str; + Money cost, sum, total; if (!small) { // normal sized economics window - /* draw categories */ DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING); - for (i = 0; i != EXPENSES_END; i++) - DrawString(2, 27 + i * 10, STR_7011_CONSTRUCTION + i, TC_FROMSTRING); - DrawStringRightAligned(111, 27 + 10 * EXPENSES_END + 2, STR_7020_TOTAL, TC_FROMSTRING); - /* draw the price columns */ + /* draw the column values */ year = _cur_year - 2; j = 3; - x = 215; + x = 255; tbl = c->yearly_expenses + 2; do { if (year >= c->inaugurated_year) { SetDParam(0, year); DrawStringRightAlignedUnderline(x, 15, STR_7010, TC_FROMSTRING); + + total = 0; + + /* recurring income */ sum = 0; - for (i = 0; i != EXPENSES_END; i++) { - /* draw one row in the price column */ - cost = (*tbl)[i]; - if (cost != 0) { - sum += cost; - str = STR_701E; - if (cost < 0) { cost = -cost; str++; } - SetDParam(0, cost); - DrawStringRightAligned(x, 27 + i * 10, str, TC_FROMSTRING); - } - } + cost = (*tbl)[EXPENSES_TRAIN_INC]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 27, false); - str = STR_701E; - if (sum < 0) { sum = -sum; str++; } - SetDParam(0, sum); - DrawStringRightAligned(x, 27 + EXPENSES_END * 10 + 2, str, TC_FROMSTRING); + cost = (*tbl)[EXPENSES_ROADVEH_INC]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 37, false); - GfxFillRect(x - 75, 27 + 10 * EXPENSES_END, x, 27 + 10 * EXPENSES_END, 215); - x += 95; + cost = (*tbl)[EXPENSES_AIRCRAFT_INC]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 47, false); + + cost = (*tbl)[EXPENSES_SHIP_INC]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 57, false); + + total += sum; + DrawPlayerEconomySingleStat(sum, x, 69, true); + + /* recurring expenses */ + sum = 0; + + cost = (*tbl)[EXPENSES_TRAIN_RUN]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 87, false); + + cost = (*tbl)[EXPENSES_ROADVEH_RUN]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 97, false); + + cost = (*tbl)[EXPENSES_AIRCRAFT_RUN]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 107, false); + + cost = (*tbl)[EXPENSES_SHIP_RUN]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 117, false); + + cost = (*tbl)[EXPENSES_PROPERTY]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 127, false); + + cost = (*tbl)[EXPENSES_LOAN_INT]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 137, false); + + total += sum; + DrawPlayerEconomySingleStat(cost, x, 149, true); + + /* others */ + sum = 0; + + cost = (*tbl)[EXPENSES_CONSTRUCTION]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 167, false); + + cost = (*tbl)[EXPENSES_NEW_VEHICLES]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 177, false); + + cost = (*tbl)[EXPENSES_OTHER]; + sum += cost; + DrawPlayerEconomySingleStat(cost, x, 187, false); + + total += sum; + DrawPlayerEconomySingleStat(cost, x, 199, true); + + /* grand total */ + DrawPlayerEconomySingleStat(total, x, 219, true); + + GfxFillRect(x - 75, 67, x, 67, 215); + GfxFillRect(x - 75, 147, x, 147, 215); + GfxFillRect(x - 75, 197, x, 197, 215); + GfxFillRect(x - 75, 217, x, 217, 215); + x += 135; } year++; tbl--; } while (--j != 0); - y = 27 + 10 * EXPENSES_END + 14; + y = 231; /* draw max loan aligned to loan below (y += 10) */ SetDParam(0, _economy.max_loan); @@ -124,15 +199,31 @@ }; static const Widget _company_finances_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 379, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_IMGBTN, RESIZE_NONE, COLOUR_GREY, 380, 394, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW}, -{ WWT_STICKYBOX, RESIZE_NONE, COLOUR_GREY, 395, 406, 0, 13, 0x0, STR_STICKY_BUTTON}, -{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 406, 14, 39 + 10 * EXPENSES_END, 0x0, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 406, 40 + 10 * EXPENSES_END, 73 + 10 * EXPENSES_END, 0x0, STR_NULL}, -{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 0, 202, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN}, -{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_GREY, 203, 406, 74 + 10 * EXPENSES_END, 85 + 10 * EXPENSES_END, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN}, -{ WIDGETS_END}, +{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, +{ WWT_CAPTION, RESIZE_NONE, 14, 11, 499, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS}, +{ WWT_IMGBTN, RESIZE_NONE, 14, 500, 514, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW}, +{ WWT_STICKYBOX, RESIZE_NONE, 14, 515, 526, 0, 13, 0x0, STR_STICKY_BUTTON}, +{ WWT_PANEL, RESIZE_NONE, 14, 0, 526, 14, 229, 0x0, STR_NULL}, +{ WWT_PANEL, RESIZE_NONE, 14, 0, 526, 230, 263, 0x0, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 27, 36, STR_7018_TRAIN_INCOME, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 37, 46, STR_7019_ROAD_VEHICLES_INCOME, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 47, 56, STR_701A_AIRCRAFT_INCOME, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 57, 86, STR_701B_SHIP_INCOME, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 81, 130, 69, 78, STR_7020_TOTAL, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 87, 96, STR_7013_TRAIN_RUNNING_COSTS, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 97, 106, STR_7014_ROAD_VEH_RUNNING_COSTS, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 107, 116, STR_7015_AIRCRAFT_RUNNING_COSTS, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 117, 126, STR_7016_SHIP_RUNNING_COSTS, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 127, 136, STR_7017_PROPERTY_MAINTENANCE, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 137, 146, STR_701C_LOAN_INTEREST, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 81, 130, 149, 158, STR_7020_TOTAL, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 167, 176, STR_7011_CONSTRUCTION, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 177, 186, STR_7012_NEW_VEHICLES, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 2, 130, 187, 196, STR_701D_OTHER, STR_NULL}, +{ WWT_TEXT, RESIZE_NONE, 0, 81, 130, 199, 208, STR_7020_TOTAL, STR_NULL}, +{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 262, 264, 275, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN}, +{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 263, 526, 264, 275, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN}, +{ WIDGETS_END}, }; static const Widget _company_finances_small_widgets[] = { @@ -174,7 +265,7 @@ const Company *c = GetCompany(company); /* Recheck the size of the window as it might need to be resized due to the local company changing */ - int new_height = ((company != _local_company) ? 0 : 12) + ((this->small != 0) ? 48 : 74 + 10 * EXPENSES_END); + int new_height = ((company != _local_company) ? 0 : 12) + ((this->small != 0) ? 48 : 264); if (this->height != new_height) { /* Make window dirty before and after resizing */ this->SetDirty(); @@ -227,7 +318,7 @@ }; static const WindowDesc _company_finances_desc = { - WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END, + WDP_AUTO, WDP_AUTO, 527, 276, 527, 276, WC_FINANCES, WC_NONE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, _company_finances_widgets,