1
0
Fork 0

(svn r13118) -Codechange: make classes of the EndGameWindow and the HighScoreWindow.

release/0.7
rubidium 2008-05-16 13:21:43 +00:00
parent b39525581d
commit feba3ac1e7
1 changed files with 144 additions and 144 deletions

View File

@ -35,12 +35,6 @@
#include "table/sprites.h" #include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
struct highscore_d {
uint32 background_img;
int8 rank;
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(highscore_d));
enum { enum {
FIRST_GUI_CALL = INT_MAX, ///< default value to specify thuis is the first call of the resizable gui FIRST_GUI_CALL = INT_MAX, ///< default value to specify thuis is the first call of the resizable gui
}; };
@ -1421,43 +1415,93 @@ void ShowBuyCompanyDialog(uint player)
/********** HIGHSCORE and ENDGAME windows */ /********** HIGHSCORE and ENDGAME windows */
/* Always draw a maximized window and within there the centered background */ extern StringID EndGameGetPerformanceTitleFromValue(uint value);
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);
struct EndGameHighScoreBaseWindow : Window
{
uint32 background_img;
int8 rank;
EndGameHighScoreBaseWindow(const WindowDesc *desc) : Window(desc)
{
}
/* 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;
DrawWindowWidgets(this);
/* Center Highscore/Endscreen background */ /* Center Highscore/Endscreen background */
*x = max(0, (_screen.width / 2) - (640 / 2)); *x = max(0, (_screen.width / 2) - (640 / 2));
*y = max(0, (_screen.height / 2) - (480 / 2)); *y = max(0, (_screen.height / 2) - (480 / 2));
for (i = 0; i < 10; i++) // the image is split into 10 50px high parts for (uint 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)); DrawSprite(this->background_img + i, PAL_NONE, *x, *y + (i * 50));
} }
}
extern StringID EndGameGetPerformanceTitleFromValue(uint value); virtual void OnClick(Point pt, int widget)
{
delete this;
}
};
/** End game window shown at the end of the game */ /** End game window shown at the end of the game */
static void EndGameWndProc(Window *w, WindowEvent *e) struct EndGameWindow : EndGameHighScoreBaseWindow {
{ EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc)
switch (e->event) { {
case WE_PAINT: { /* 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;
}
}
/* 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);
}
MarkWholeScreenDirty();
}
~EndGameWindow()
{
if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
ShowHighscoreTable(this->window_number, this->rank);
}
virtual void OnPaint()
{
const Player *p; const Player *p;
uint x, y; uint x, y;
SetupHighScoreEndWindow(w, &x, &y); this->SetupHighScoreEndWindow(&x, &y);
if (!IsValidPlayer(_local_player)) break; if (!IsValidPlayer(_local_player)) return;
p = GetPlayer(_local_player); p = GetPlayer(_local_player);
/* We need to get performance from last year because the image is shown /* 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 */ * 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/ if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
SetDParam(0, p->index); SetDParam(0, p->index);
SetDParam(1, p->index); SetDParam(1, p->index);
SetDParam(2, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history)); SetDParam(2, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history));
@ -1467,40 +1511,50 @@ static void EndGameWndProc(Window *w, WindowEvent *e)
SetDParam(1, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history)); SetDParam(1, EndGameGetPerformanceTitleFromValue(p->old_economy[0].performance_history));
DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640); DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640);
} }
} break;
case WE_CLICK: /* Close the window (and show the highscore window) */
delete w;
break;
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;
} }
} };
static void HighScoreWndProc(Window *w, WindowEvent *e) struct HighScoreWindow : EndGameHighScoreBaseWindow
{ {
switch (e->event) { HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc)
case WE_PAINT: { {
const HighScore *hs = _highscore_table[w->window_number]; /* pause game to show the chart */
uint x, y; if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
uint8 i;
SetupHighScoreEndWindow(w, &x, &y); /* Close all always on-top windows to get a clean screen */
if (_game_mode != GM_MENU) HideVitalWindows();
MarkWholeScreenDirty();
this->window_number = difficulty; // show highscore chart for difficulty...
this->background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show
this->rank = ranking;
}
~HighScoreWindow()
{
if (_game_mode != GM_MENU) ShowVitalWindows();
if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
}
virtual void OnPaint()
{
const HighScore *hs = _highscore_table[this->window_number];
uint x, y;
this->SetupHighScoreEndWindow(&x, &y);
SetDParam(0, _patches.ending_year); SetDParam(0, _patches.ending_year);
SetDParam(1, w->window_number + STR_6801_EASY); 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); DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500);
/* Draw Highscore peepz */ /* Draw Highscore peepz */
for (i = 0; i < lengthof(_highscore_table[0]); i++) { for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
SetDParam(0, i + 1); SetDParam(0, i + 1);
DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK); DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK);
if (hs[i].company[0] != '\0') { if (hs[i].company[0] != '\0') {
TextColour colour = (WP(w, highscore_d).rank == (int8)i) ? TC_RED : TC_BLACK; // draw new highscore in red 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); DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour);
SetDParam(0, hs[i].title); SetDParam(0, hs[i].title);
@ -1508,19 +1562,8 @@ static void HighScoreWndProc(Window *w, WindowEvent *e)
DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour); DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour);
} }
} }
} break;
case WE_CLICK: /* Onclick to close window, and in destroy event handle the rest */
delete w;
break;
case WE_DESTROY: /* Get back all the hidden windows */
if (_game_mode != GM_MENU) ShowVitalWindows();
if (!_networking) DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // unpause
break;
} }
} };
static const Widget _highscore_widgets[] = { static const Widget _highscore_widgets[] = {
{ WWT_PANEL, RESIZE_NONE, 16, 0, 640, 0, 480, 0x0, STR_NULL}, { 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, WC_HIGHSCORE, WC_NONE,
0, 0,
_highscore_widgets, _highscore_widgets,
HighScoreWndProc NULL
}; };
static const WindowDesc _endgame_desc = { static const WindowDesc _endgame_desc = {
@ -1540,7 +1583,7 @@ static const WindowDesc _endgame_desc = {
WC_ENDSCREEN, WC_NONE, WC_ENDSCREEN, WC_NONE,
0, 0,
_highscore_widgets, _highscore_widgets,
EndGameWndProc NULL
}; };
/** Show the highscore table for a given difficulty. When called from /** Show the highscore table for a given difficulty. When called from
@ -1548,61 +1591,18 @@ static const WindowDesc _endgame_desc = {
* and is thus highlighted */ * and is thus highlighted */
void ShowHighscoreTable(int difficulty, int8 ranking) 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); DeleteWindowByClass(WC_HIGHSCORE);
w = new Window(&_highscore_desc); new HighScoreWindow(&_highscore_desc, difficulty, ranking);
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;
}
} }
/** Show the endgame victory screen in 2050. Update the new highscore /** Show the endgame victory screen in 2050. Update the new highscore
* if it was high enough */ * if it was high enough */
void ShowEndGameChart() void ShowEndGameChart()
{ {
Window *w;
/* Dedicated server doesn't need the highscore window */ /* Dedicated server doesn't need the highscore window */
if (_network_dedicated) return; 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(); HideVitalWindows();
DeleteWindowByClass(WC_ENDSCREEN); DeleteWindowByClass(WC_ENDSCREEN);
w = new Window(&_endgame_desc); new EndGameWindow(&_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);
}
}
} }