|
|
@ -48,14 +48,14 @@ enum {
|
|
|
|
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
|
|
|
|
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
|
|
|
|
static void DoSelectPlayerFace(Window *parent, bool show_big, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
|
|
|
|
static void DoSelectPlayerFace(Window *parent, bool show_big, int top = FIRST_GUI_CALL, int left = FIRST_GUI_CALL);
|
|
|
|
|
|
|
|
|
|
|
|
static void DrawPlayerEconomyStats(const Player *p, byte mode)
|
|
|
|
static void DrawPlayerEconomyStats(const Player *p, bool small)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int x, y, i, j, year;
|
|
|
|
int x, y, i, j, year;
|
|
|
|
const Money (*tbl)[EXPENSES_END];
|
|
|
|
const Money (*tbl)[EXPENSES_END];
|
|
|
|
Money sum, cost;
|
|
|
|
Money sum, cost;
|
|
|
|
StringID str;
|
|
|
|
StringID str;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
|
|
|
|
if (!small) { // normal sized economics window
|
|
|
|
/* draw categories */
|
|
|
|
/* draw categories */
|
|
|
|
DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING);
|
|
|
|
DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING);
|
|
|
|
for (i = 0; i != EXPENSES_END; i++)
|
|
|
|
for (i = 0; i != EXPENSES_END; i++)
|
|
|
@ -154,52 +154,69 @@ static const Widget _player_finances_small_widgets[] = {
|
|
|
|
{ WIDGETS_END},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct PlayerFinancesWindow : Window {
|
|
|
|
|
|
|
|
bool small;
|
|
|
|
|
|
|
|
|
|
|
|
static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
|
|
|
|
PlayerFinancesWindow(const WindowDesc *desc, PlayerID player, bool show_small,
|
|
|
|
|
|
|
|
bool show_stickied, int top, int left) :
|
|
|
|
|
|
|
|
Window(desc, player),
|
|
|
|
|
|
|
|
small(show_small)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
this->caption_color = this->window_number;
|
|
|
|
case WE_PAINT: {
|
|
|
|
|
|
|
|
PlayerID player = (PlayerID)w->window_number;
|
|
|
|
if (show_stickied) this->flags4 |= WF_STICKY;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if repositioning from default is required */
|
|
|
|
|
|
|
|
if (top != FIRST_GUI_CALL && left != FIRST_GUI_CALL) {
|
|
|
|
|
|
|
|
this->top = top;
|
|
|
|
|
|
|
|
this->left = left;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PlayerID player = (PlayerID)this->window_number;
|
|
|
|
const Player *p = GetPlayer(player);
|
|
|
|
const Player *p = GetPlayer(player);
|
|
|
|
|
|
|
|
|
|
|
|
/* Recheck the size of the window as it might need to be resized due to the local player changing */
|
|
|
|
/* 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 : 74 + 10 * EXPENSES_END);
|
|
|
|
int new_height = ((player != _local_player) ? 0 : 12) + ((this->small != 0) ? 48 : 74 + 10 * EXPENSES_END);
|
|
|
|
if (w->height != new_height) {
|
|
|
|
if (this->height != new_height) {
|
|
|
|
/* Make window dirty before and after resizing */
|
|
|
|
/* Make window dirty before and after resizing */
|
|
|
|
w->SetDirty();
|
|
|
|
this->SetDirty();
|
|
|
|
w->height = new_height;
|
|
|
|
this->height = new_height;
|
|
|
|
w->SetDirty();
|
|
|
|
this->SetDirty();
|
|
|
|
|
|
|
|
|
|
|
|
w->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player);
|
|
|
|
this->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player);
|
|
|
|
w->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN, player != _local_player);
|
|
|
|
this->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN, player != _local_player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Borrow button only shows when there is any more money to loan */
|
|
|
|
/* Borrow button only shows when there is any more money to loan */
|
|
|
|
w->SetWidgetDisabledState(PFW_WIDGET_INCREASE_LOAN, p->current_loan == _economy.max_loan);
|
|
|
|
this->SetWidgetDisabledState(PFW_WIDGET_INCREASE_LOAN, p->current_loan == _economy.max_loan);
|
|
|
|
|
|
|
|
|
|
|
|
/* Repay button only shows when there is any more money to repay */
|
|
|
|
/* Repay button only shows when there is any more money to repay */
|
|
|
|
w->SetWidgetDisabledState(PFW_WIDGET_REPAY_LOAN, player != _local_player || p->current_loan == 0);
|
|
|
|
this->SetWidgetDisabledState(PFW_WIDGET_REPAY_LOAN, player != _local_player || p->current_loan == 0);
|
|
|
|
|
|
|
|
|
|
|
|
SetDParam(0, p->index);
|
|
|
|
SetDParam(0, p->index);
|
|
|
|
SetDParam(1, p->index);
|
|
|
|
SetDParam(1, p->index);
|
|
|
|
SetDParam(2, LOAN_INTERVAL);
|
|
|
|
SetDParam(2, LOAN_INTERVAL);
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
DrawWindowWidgets(this);
|
|
|
|
|
|
|
|
|
|
|
|
DrawPlayerEconomyStats(p, (byte)WP(w, def_d).data_1);
|
|
|
|
DrawPlayerEconomyStats(p, this->small);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
switch (e->we.click.widget) {
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case PFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
|
|
|
|
case PFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
|
|
|
|
byte mode = (byte)WP(w, def_d).data_1;
|
|
|
|
bool new_mode = !this->small;
|
|
|
|
bool stickied = !!(w->flags4 & WF_STICKY);
|
|
|
|
bool stickied = !!(this->flags4 & WF_STICKY);
|
|
|
|
int oldtop = w->top; ///< current top position of the window before closing it
|
|
|
|
int oldtop = this->top; ///< current top position of the window before closing it
|
|
|
|
int oldleft = w->left; ///< current left position of the window before closing it
|
|
|
|
int oldleft = this->left; ///< current left position of the window before closing it
|
|
|
|
PlayerID player = (PlayerID)w->window_number;
|
|
|
|
PlayerID player = (PlayerID)this->window_number;
|
|
|
|
|
|
|
|
|
|
|
|
delete w;
|
|
|
|
delete this;
|
|
|
|
/* Open up the (toggled size) Finance window at the same position as the previous */
|
|
|
|
/* Open up the (toggled size) Finance window at the same position as the previous */
|
|
|
|
DoShowPlayerFinances(player, !HasBit(mode, 0), stickied, oldtop, oldleft);
|
|
|
|
DoShowPlayerFinances(player, new_mode, stickied, oldtop, oldleft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -211,16 +228,15 @@ static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
|
|
|
|
DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
|
|
|
|
DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _player_finances_desc = {
|
|
|
|
static const WindowDesc _player_finances_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END,
|
|
|
|
WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END,
|
|
|
|
WC_FINANCES, WC_NONE,
|
|
|
|
WC_FINANCES, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
|
|
|
_player_finances_widgets,
|
|
|
|
_player_finances_widgets,
|
|
|
|
PlayerFinancesWndProc
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _player_finances_small_desc = {
|
|
|
|
static const WindowDesc _player_finances_small_desc = {
|
|
|
@ -228,7 +244,7 @@ static const WindowDesc _player_finances_small_desc = {
|
|
|
|
WC_FINANCES, WC_NONE,
|
|
|
|
WC_FINANCES, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
|
|
|
_player_finances_small_widgets,
|
|
|
|
_player_finances_small_widgets,
|
|
|
|
PlayerFinancesWndProc
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -246,19 +262,8 @@ static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_sti
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
|
|
|
|
|
|
|
Window *w = AllocateWindowDescFront<Window>(show_small ? &_player_finances_small_desc : &_player_finances_desc, player);
|
|
|
|
if (BringWindowToFrontById(WC_FINANCES, player)) return;
|
|
|
|
if (w != NULL) {
|
|
|
|
new PlayerFinancesWindow(show_small ? &_player_finances_small_desc : &_player_finances_desc, player, show_small, show_stickied, top, left);
|
|
|
|
w->caption_color = w->window_number;
|
|
|
|
|
|
|
|
WP(w, def_d).data_1 = show_small;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (show_stickied) w->flags4 |= WF_STICKY;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if repositioning from default is required */
|
|
|
|
|
|
|
|
if (top != FIRST_GUI_CALL && left != FIRST_GUI_CALL) {
|
|
|
|
|
|
|
|
w->top = top;
|
|
|
|
|
|
|
|
w->left = left;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShowPlayerFinances(PlayerID player)
|
|
|
|
void ShowPlayerFinances(PlayerID player)
|
|
|
|