summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-05-16 07:34:48 +0000
committerrubidium <rubidium@openttd.org>2008-05-16 07:34:48 +0000
commit5a85fb104ea63dbbfb60e833db194edbf4310a9b (patch)
treeadf51ede042e04411ba82b69ea41389e99e20283 /src
parent804b9f1d3a29257ff856fc8045a33dc3346662cf (diff)
downloadopenttd-5a85fb104ea63dbbfb60e833db194edbf4310a9b.tar.xz
(svn r13117) -Codechange: make a window class of the PlayerFinancesWindow.
Diffstat (limited to 'src')
-rw-r--r--src/player_gui.cpp135
-rw-r--r--src/window_gui.h5
2 files changed, 70 insertions, 70 deletions
diff --git a/src/player_gui.cpp b/src/player_gui.cpp
index 9f03b5fb3..89b6cbf06 100644
--- a/src/player_gui.cpp
+++ b/src/player_gui.cpp
@@ -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 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;
const Money (*tbl)[EXPENSES_END];
Money sum, cost;
StringID str;
- if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status
+ if (!small) { // normal sized economics window
/* draw categories */
DrawStringCenterUnderline(61, 15, STR_700F_EXPENDITURE_INCOME, TC_FROMSTRING);
for (i = 0; i != EXPENSES_END; i++)
@@ -154,73 +154,89 @@ static const Widget _player_finances_small_widgets[] = {
{ WIDGETS_END},
};
+struct PlayerFinancesWindow : Window {
+ bool small;
-static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
-{
- switch (e->event) {
- case WE_PAINT: {
- PlayerID player = (PlayerID)w->window_number;
- 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 : 74 + 10 * EXPENSES_END);
- if (w->height != new_height) {
- /* Make window dirty before and after resizing */
- w->SetDirty();
- w->height = new_height;
- w->SetDirty();
-
- w->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player);
- w->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN, player != _local_player);
- }
+ PlayerFinancesWindow(const WindowDesc *desc, PlayerID player, bool show_small,
+ bool show_stickied, int top, int left) :
+ Window(desc, player),
+ small(show_small)
+ {
+ this->caption_color = this->window_number;
- /* Borrow button only shows when there is any more money to loan */
- w->SetWidgetDisabledState(PFW_WIDGET_INCREASE_LOAN, p->current_loan == _economy.max_loan);
+ if (show_stickied) this->flags4 |= WF_STICKY;
- /* 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);
+ /* Check if repositioning from default is required */
+ if (top != FIRST_GUI_CALL && left != FIRST_GUI_CALL) {
+ this->top = top;
+ this->left = left;
+ }
+ }
- SetDParam(0, p->index);
- SetDParam(1, p->index);
- SetDParam(2, LOAN_INTERVAL);
- DrawWindowWidgets(w);
+ virtual void OnPaint()
+ {
+ PlayerID player = (PlayerID)this->window_number;
+ const Player *p = GetPlayer(player);
- DrawPlayerEconomyStats(p, (byte)WP(w, def_d).data_1);
- } break;
+ /* 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) + ((this->small != 0) ? 48 : 74 + 10 * EXPENSES_END);
+ if (this->height != new_height) {
+ /* Make window dirty before and after resizing */
+ this->SetDirty();
+ this->height = new_height;
+ this->SetDirty();
- case WE_CLICK:
- switch (e->we.click.widget) {
- case PFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
- byte mode = (byte)WP(w, def_d).data_1;
- bool stickied = !!(w->flags4 & WF_STICKY);
- int oldtop = w->top; ///< current top position of the window before closing it
- int oldleft = w->left; ///< current left position of the window before closing it
- PlayerID player = (PlayerID)w->window_number;
+ this->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player);
+ this->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN, player != _local_player);
+ }
- delete w;
- /* Open up the (toggled size) Finance window at the same position as the previous */
- DoShowPlayerFinances(player, !HasBit(mode, 0), stickied, oldtop, oldleft);
- }
- break;
+ /* Borrow button only shows when there is any more money to loan */
+ this->SetWidgetDisabledState(PFW_WIDGET_INCREASE_LOAN, p->current_loan == _economy.max_loan);
- case PFW_WIDGET_INCREASE_LOAN: /* increase loan */
- DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
- break;
+ /* Repay button only shows when there is any more money to repay */
+ this->SetWidgetDisabledState(PFW_WIDGET_REPAY_LOAN, player != _local_player || p->current_loan == 0);
- case PFW_WIDGET_REPAY_LOAN: /* repay loan */
- DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
- break;
+ SetDParam(0, p->index);
+ SetDParam(1, p->index);
+ SetDParam(2, LOAN_INTERVAL);
+ DrawWindowWidgets(this);
+
+ DrawPlayerEconomyStats(p, this->small);
+ }
+
+ virtual void OnClick(Point pt, int widget)
+ {
+ switch (widget) {
+ case PFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
+ bool new_mode = !this->small;
+ bool stickied = !!(this->flags4 & WF_STICKY);
+ int oldtop = this->top; ///< current top position of the window before closing it
+ int oldleft = this->left; ///< current left position of the window before closing it
+ PlayerID player = (PlayerID)this->window_number;
+
+ delete this;
+ /* Open up the (toggled size) Finance window at the same position as the previous */
+ DoShowPlayerFinances(player, new_mode, stickied, oldtop, oldleft);
}
break;
+
+ case PFW_WIDGET_INCREASE_LOAN: /* increase loan */
+ DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
+ break;
+
+ case PFW_WIDGET_REPAY_LOAN: /* repay loan */
+ DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
+ break;
+ }
}
-}
+};
static const WindowDesc _player_finances_desc = {
WDP_AUTO, WDP_AUTO, 407, 86 + 10 * EXPENSES_END, 407, 86 + 10 * EXPENSES_END,
WC_FINANCES, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
_player_finances_widgets,
- PlayerFinancesWndProc
+ NULL
};
static const WindowDesc _player_finances_small_desc = {
@@ -228,7 +244,7 @@ static const WindowDesc _player_finances_small_desc = {
WC_FINANCES, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
_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;
- Window *w = AllocateWindowDescFront<Window>(show_small ? &_player_finances_small_desc : &_player_finances_desc, player);
- if (w != NULL) {
- 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;
- }
- }
+ if (BringWindowToFrontById(WC_FINANCES, player)) return;
+ new PlayerFinancesWindow(show_small ? &_player_finances_small_desc : &_player_finances_desc, player, show_small, show_stickied, top, left);
}
void ShowPlayerFinances(PlayerID player)
diff --git a/src/window_gui.h b/src/window_gui.h
index e63716279..b6636e2cc 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -515,11 +515,6 @@ public:
/*** End of the event handling ***/
};
-struct def_d {
- int16 data_1, data_2, data_3;
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
-
enum SortListFlags {
VL_NONE = 0, ///< no sort
VL_DESC = 1 << 0, ///< sort descending or ascending