diff options
author | rubidium <rubidium@openttd.org> | 2008-05-16 13:21:43 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-05-16 13:21:43 +0000 |
commit | e7b3c3fa342a9f7ee76aa6189bd470edfb637a30 (patch) | |
tree | 1540cd2210cbb6a6ac5e900897aa952517a8f7cf | |
parent | 5a85fb104ea63dbbfb60e833db194edbf4310a9b (diff) | |
download | openttd-e7b3c3fa342a9f7ee76aa6189bd470edfb637a30.tar.xz |
(svn r13118) -Codechange: make classes of the EndGameWindow and the HighScoreWindow.
-rw-r--r-- | src/player_gui.cpp | 264 |
1 files changed, 132 insertions, 132 deletions
diff --git a/src/player_gui.cpp b/src/player_gui.cpp index 89b6cbf06..b7fb61b40 100644 --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -35,12 +35,6 @@ #include "table/sprites.h" #include "table/strings.h" -struct highscore_d { - uint32 background_img; - int8 rank; -}; -assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d)); - enum { FIRST_GUI_CALL = INT_MAX, ///< default value to specify thuis is the first call of the resizable gui }; @@ -1421,106 +1415,155 @@ void ShowBuyCompanyDialog(uint player) /********** HIGHSCORE and ENDGAME windows */ -/* Always draw a maximized window and within there the centered background */ -static void SetupHighScoreEndWindow(Window *w, uint *x, uint *y) -{ - uint i; - /* resize window to "full-screen" */ - w->width = _screen.width; - w->height = _screen.height; - w->widget[0].right = w->width - 1; - w->widget[0].bottom = w->height - 1; - - DrawWindowWidgets(w); - - /* Center Highscore/Endscreen background */ - *x = max(0, (_screen.width / 2) - (640 / 2)); - *y = max(0, (_screen.height / 2) - (480 / 2)); - for (i = 0; i < 10; i++) // the image is split into 10 50px high parts - DrawSprite(WP(w, highscore_d).background_img + i, PAL_NONE, *x, *y + (i * 50)); -} - extern StringID EndGameGetPerformanceTitleFromValue(uint value); -/** End game window shown at the end of the game */ -static void EndGameWndProc(Window *w, WindowEvent *e) + +struct EndGameHighScoreBaseWindow : Window { - switch (e->event) { - case WE_PAINT: { - const Player *p; - uint x, y; + uint32 background_img; + int8 rank; - SetupHighScoreEndWindow(w, &x, &y); + EndGameHighScoreBaseWindow(const WindowDesc *desc) : Window(desc) + { + } - if (!IsValidPlayer(_local_player)) break; + /* Always draw a maximized window and within there the centered background */ + void SetupHighScoreEndWindow(uint *x, uint *y) + { + /* resize window to "full-screen" */ + this->width = _screen.width; + this->height = _screen.height; + this->widget[0].right = this->width - 1; + this->widget[0].bottom = this->height - 1; - p = GetPlayer(_local_player); - /* We need to get performance from last year because the image is shown - * at the start of the new year when these things have already been copied */ - if (WP(w, highscore_d).background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/ - SetDParam(0, p->index); - SetDParam(1, p->index); - SetDParam(2, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history)); - DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640); - } else { - SetDParam(0, p->index); - SetDParam(1, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history)); - DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640); + DrawWindowWidgets(this); + + /* Center Highscore/Endscreen background */ + *x = max(0, (_screen.width / 2) - (640 / 2)); + *y = max(0, (_screen.height / 2) - (480 / 2)); + for (uint i = 0; i < 10; i++) { // the image is split into 10 50px high parts + DrawSprite(this->background_img + i, PAL_NONE, *x, *y + (i * 50)); + } + } + + virtual void OnClick(Point pt, int widget) + { + delete this; + } +}; + +/** End game window shown at the end of the game */ +struct EndGameWindow : EndGameHighScoreBaseWindow { + EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc) + { + /* Pause in single-player to have a look at the highscore at your own leisure */ + if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); + + this->background_img = SPR_TYCOON_IMG1_BEGIN; + + if (_local_player != PLAYER_SPECTATOR) { + const Player *p = GetPlayer(_local_player); + if (p->old_economy[0].performance_history == SCORE_MAX) { + this->background_img = SPR_TYCOON_IMG2_BEGIN; } - } break; + } - case WE_CLICK: /* Close the window (and show the highscore window) */ - delete w; - break; + /* In a network game show the endscores of the custom difficulty 'network' which is the last one + * as well as generate a TOP5 of that game, and not an all-time top5. */ + if (_networking) { + this->window_number = lengthof(_highscore_table) - 1; + this->rank = SaveHighScoreValueNetwork(); + } else { + /* in single player _local player is always valid */ + const Player *p = GetPlayer(_local_player); + this->window_number = _opt.diff_level; + this->rank = SaveHighScoreValue(p); + } - case WE_DESTROY: /* Show the highscore window when this one is closed */ - if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause - ShowHighscoreTable(w->window_number, WP(w, highscore_d).rank); - break; + MarkWholeScreenDirty(); } -} -static void HighScoreWndProc(Window *w, WindowEvent *e) + ~EndGameWindow() + { + if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause + ShowHighscoreTable(this->window_number, this->rank); + } + + virtual void OnPaint() + { + const Player *p; + uint x, y; + + this->SetupHighScoreEndWindow(&x, &y); + + if (!IsValidPlayer(_local_player)) return; + + p = GetPlayer(_local_player); + /* We need to get performance from last year because the image is shown + * at the start of the new year when these things have already been copied */ + if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/ + SetDParam(0, p->index); + SetDParam(1, p->index); + SetDParam(2, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history)); + DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640); + } else { + SetDParam(0, p->index); + SetDParam(1, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history)); + DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640); + } + } +}; + +struct HighScoreWindow : EndGameHighScoreBaseWindow { - switch (e->event) { - case WE_PAINT: { - const HighScore *hs = _highscore_table[w->window_number]; - uint x, y; - uint8 i; + HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc) + { + /* pause game to show the chart */ + if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); - SetupHighScoreEndWindow(w, &x, &y); + /* Close all always on-top windows to get a clean screen */ + if (_game_mode != GM_MENU) HideVitalWindows(); - SetDParam(0, _patches.ending_year); - SetDParam(1, w->window_number + STR_6801_EASY); - DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500); + MarkWholeScreenDirty(); + this->window_number = difficulty; // show highscore chart for difficulty... + this->background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show + this->rank = ranking; + } - /* Draw Highscore peepz */ - for (i = 0; i < lengthof(_highscore_table[0]); i++) { - SetDParam(0, i + 1); - DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK); + ~HighScoreWindow() + { + if (_game_mode != GM_MENU) ShowVitalWindows(); - if (hs[i].company[0] != '\0') { - TextColour colour = (WP(w, highscore_d).rank == (int8)i) ? TC_RED : TC_BLACK; // draw new highscore in red + if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause + } - DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour); - SetDParam(0, hs[i].title); - SetDParam(1, hs[i].score); - DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour); - } - } - } break; + virtual void OnPaint() + { + const HighScore *hs = _highscore_table[this->window_number]; + uint x, y; - case WE_CLICK: /* Onclick to close window, and in destroy event handle the rest */ - delete w; - break; + this->SetupHighScoreEndWindow(&x, &y); - case WE_DESTROY: /* Get back all the hidden windows */ - if (_game_mode != GM_MENU) ShowVitalWindows(); + SetDParam(0, _patches.ending_year); + SetDParam(1, this->window_number + STR_6801_EASY); + DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500); - if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause - break; + /* Draw Highscore peepz */ + for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) { + SetDParam(0, i + 1); + DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK); + + if (hs[i].company[0] != '\0') { + TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK; // draw new highscore in red + + DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour); + SetDParam(0, hs[i].title); + SetDParam(1, hs[i].score); + DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour); + } } -} + } +}; static const Widget _highscore_widgets[] = { { WWT_PANEL, RESIZE_NONE, 16, 0, 640, 0, 480, 0x0, STR_NULL}, @@ -1532,7 +1575,7 @@ static const WindowDesc _highscore_desc = { WC_HIGHSCORE, WC_NONE, 0, _highscore_widgets, - HighScoreWndProc + NULL }; static const WindowDesc _endgame_desc = { @@ -1540,7 +1583,7 @@ static const WindowDesc _endgame_desc = { WC_ENDSCREEN, WC_NONE, 0, _highscore_widgets, - EndGameWndProc + NULL }; /** Show the highscore table for a given difficulty. When called from @@ -1548,61 +1591,18 @@ static const WindowDesc _endgame_desc = { * and is thus highlighted */ void ShowHighscoreTable(int difficulty, int8 ranking) { - Window *w; - - /* pause game to show the chart */ - if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); - - /* Close all always on-top windows to get a clean screen */ - if (_game_mode != GM_MENU) HideVitalWindows(); - DeleteWindowByClass(WC_HIGHSCORE); - w = new Window(&_highscore_desc); - - if (w != NULL) { - MarkWholeScreenDirty(); - w->window_number = difficulty; // show highscore chart for difficulty... - WP(w, highscore_d).background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show - WP(w, highscore_d).rank = ranking; - } + new HighScoreWindow(&_highscore_desc, difficulty, ranking); } /** Show the endgame victory screen in 2050. Update the new highscore * if it was high enough */ void ShowEndGameChart() { - Window *w; - /* Dedicated server doesn't need the highscore window */ if (_network_dedicated) return; - /* Pause in single-player to have a look at the highscore at your own leisure */ - if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); HideVitalWindows(); DeleteWindowByClass(WC_ENDSCREEN); - w = new Window(&_endgame_desc); - - if (w != NULL) { - MarkWholeScreenDirty(); - - WP(w, highscore_d).background_img = SPR_TYCOON_IMG1_BEGIN; - - if (_local_player != PLAYER_SPECTATOR) { - const Player *p = GetPlayer(_local_player); - if (p->old_economy[0].performance_history == SCORE_MAX) - WP(w, highscore_d).background_img = SPR_TYCOON_IMG2_BEGIN; - } - - /* In a network game show the endscores of the custom difficulty 'network' which is the last one - * as well as generate a TOP5 of that game, and not an all-time top5. */ - if (_networking) { - w->window_number = lengthof(_highscore_table) - 1; - WP(w, highscore_d).rank = SaveHighScoreValueNetwork(); - } else { - /* in single player _local player is always valid */ - const Player *p = GetPlayer(_local_player); - w->window_number = _opt.diff_level; - WP(w, highscore_d).rank = SaveHighScoreValue(p); - } - } + new EndGameWindow(&_endgame_desc); } |