Index: player_gui.cpp =================================================================== --- player_gui.cpp (revision 12083) +++ player_gui.cpp (working copy) @@ -43,56 +43,145 @@ static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied); static void DoSelectPlayerFace(PlayerID player, bool show_big); +static void DrawPlayerEconomySingleStat(Money *sum, const Money (*tbl)[13], int x, ExpensesType i, int y) +{ + StringID str; + Money cost; + + cost = (*tbl)[i]; + /* draw one row in the price column */ + if (cost != 0) + { + sum += cost; + + if (cost >= 0) { + str = STR_701E; + } else { + cost = -cost; + str = STR_701F; + } + + SetDParam(0, cost); + DrawStringRightAligned(x, y, str, TC_FROMSTRING); + } +} + +static void DrawPlayerEconomyTotal(Money total, int x, int y) +{ + StringID str; + + if (total >= 0) + { + str = STR_701E; + } else { + total = -total; + str = STR_701F; + } + + SetDParam(0, total); + DrawStringRightAligned(x, y, str, TC_FROMSTRING); +} + +static void DrawPlayerEconomySum(Money *total, Money sum, int x, int y) +{ + StringID str; + + total += sum; + if (sum >= 0) + { + str = STR_701E; + } else { + sum = -sum; + str = STR_701F; + } + + SetDParam(0, sum); + DrawStringRightAligned(x, y, str, TC_FROMSTRING); +} + static void DrawPlayerEconomyStats(const Player *p, byte mode) { - int x, y, i, j, year; + int x, y, j, year; const Money (*tbl)[13]; - Money sum, cost; - StringID str; + Money sum, total; if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status - /* draw categories */ DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING); - for (i = 0; i != 13; i++) - DrawString(2, 27 + i * 10, STR_7011_CONSTRUCTION + i, TC_FROMSTRING); - DrawStringRightAligned(111, 27 + 10 * 13 + 2, STR_7020_TOTAL, TC_FROMSTRING); - /* draw the price columns */ + /* draw income column names */ + DrawString(2, 27, STR_7018_TRAIN_INCOME, 0); + DrawString(2, 37, STR_7019_ROAD_VEHICLES_INCOME, 0); + DrawString(2, 47, STR_701A_AIRCRAFT_INCOME, 0); + DrawString(2, 57, STR_701B_SHIP_INCOME, 0); + DrawStringRightAligned(111, 69, STR_7020_TOTAL, 0); + + /* draw expenses column names */ + DrawString(2, 87, STR_7013_TRAIN_RUNNING_COSTS, 0); + DrawString(2, 97, STR_7014_ROAD_VEH_RUNNING_COSTS, 0); + DrawString(2, 107, STR_7015_AIRCRAFT_RUNNING_COSTS, 0); + DrawString(2, 117, STR_7016_SHIP_RUNNING_COSTS, 0); + DrawString(2, 127, STR_7017_PROPERTY_MAINTENANCE, 0); + DrawString(2, 137, STR_701C_LOAN_INTEREST, 0); + DrawStringRightAligned(111, 149, STR_7020_TOTAL, 0); + + /* draw other column names */ + DrawString(2, 167, STR_7011_CONSTRUCTION + 0, 0); + DrawString(2, 177, STR_7012_NEW_VEHICLES, 0); + DrawString(2, 187, STR_701D_OTHER, 0); + DrawStringRightAligned(111, 199, STR_7020_TOTAL, 0); + + DrawStringRightAligned(111, 219, STR_7020_TOTAL, 0); + + /* draw the column values */ year = _cur_year - 2; j = 3; - x = 215; + x = 255; tbl = p->yearly_expenses + 2; do { if (year >= p->inaugurated_year) { SetDParam(0, year); DrawStringRightAlignedUnderline(x, 15, STR_7010, TC_FROMSTRING); + + total = 0; + + /* recurring income */ + sum = 0; + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_TRAIN_INC, 27); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_ROADVEH_INC, 37); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_AIRCRAFT_INC, 47); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_SHIP_INC, 57); + DrawPlayerEconomySum(&total, sum, x, 69); + + /* recurring expenses */ sum = 0; - for (i = 0; i != 13; i++) { - /* draw one row in the price column */ - cost = (*tbl)[i]; - if (cost != 0) { - sum += cost; + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_TRAIN_RUN, 87); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_ROADVEH_RUN, 97); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_AIRCRAFT_RUN, 107); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_SHIP_RUN, 117); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_PROPERTY, 127); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_LOAN_INT, 137); + DrawPlayerEconomySum(&total, sum, x, 149); - str = STR_701E; - if (cost < 0) { cost = -cost; str++; } - SetDParam(0, cost); - DrawStringRightAligned(x, 27 + i * 10, str, TC_FROMSTRING); - } - } + /* others */ + sum = 0; + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_CONSTRUCTION, 167); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_NEW_VEHICLES, 177); + DrawPlayerEconomySingleStat(&sum, tbl, x, EXPENSES_OTHER, 187); + DrawPlayerEconomySum(&total, sum, x, 199); - str = STR_701E; - if (sum < 0) { sum = -sum; str++; } - SetDParam(0, sum); - DrawStringRightAligned(x, 27 + 13 * 10 + 2, str, TC_FROMSTRING); + DrawPlayerEconomyTotal(total, x, 219); - GfxFillRect(x - 75, 27 + 10 * 13, x, 27 + 10 * 13, 215); - x += 95; + 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 = 171; + y = 231; /* draw max loan aligned to loan below (y += 10) */ SetDParam(0, _economy.max_loan); @@ -113,7 +202,7 @@ y += 12; - GfxFillRect(182 - 75, y - 2, 182, y - 2, 215); + GfxFillRect(107, y - 2, 182, y - 2, 215); SetDParam(0, p->player_money - p->current_loan); DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING); @@ -127,14 +216,14 @@ static const Widget _player_finances_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, 14, 11, 379, 0, 13, STR_700E_FINANCES, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_IMGBTN, RESIZE_NONE, 14, 380, 394, 0, 13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW}, -{ WWT_STICKYBOX, RESIZE_NONE, 14, 395, 406, 0, 13, 0x0, STR_STICKY_BUTTON}, -{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 14, 169, 0x0, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, 14, 0, 406, 170, 203, 0x0, STR_NULL}, -{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 202, 204, 215, STR_7029_BORROW, STR_7035_INCREASE_SIZE_OF_LOAN}, -{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 203, 406, 204, 215, STR_702A_REPAY, STR_7036_REPAY_PART_OF_LOAN}, -{ WIDGETS_END}, +{ 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_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 _player_finances_small_widgets[] = { @@ -158,7 +247,7 @@ const Player *p = GetPlayer(player); /* Recheck the size of the window as it might need to be resized due to the local player changing */ - int new_height = ((player != _local_player) ? 0 : 12) + ((WP(w, def_d).data_1 != 0) ? 48 : 204); + int new_height = ((player != _local_player) ? 0 : 12) + ((WP(w, def_d).data_1 != 0) ? 48 : 264); if (w->height != new_height) { /* Make window dirty before and after resizing */ SetWindowDirty(w); @@ -206,7 +295,7 @@ } static const WindowDesc _player_finances_desc = { - WDP_AUTO, WDP_AUTO, 407, 216, 407, 216, + 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, _player_finances_widgets,