1
/* $Id: highscore_gui.cpp 15723 2009-03-15 15:12:06Z rubidium $ */
3
/** @file highscore_gui.cpp Definition of the HighScore and EndGame windows */
6
#include "table/strings.h"
8
#include "table/sprites.h"
9
#include "window_gui.h"
10
#include "window_func.h"
11
#include "network/network.h"
12
#include "command_func.h"
13
#include "company_func.h"
14
#include "company_base.h"
15
#include "settings_type.h"
16
#include "strings_func.h"
19
struct EndGameHighScoreBaseWindow : Window {
20
uint32 background_img;
23
EndGameHighScoreBaseWindow(const WindowDesc *desc) : Window(desc)
27
/* Always draw a maximized window and within there the centered background */
28
void SetupHighScoreEndWindow(uint *x, uint *y)
30
/* resize window to "full-screen" */
31
this->width = _screen.width;
32
this->height = _screen.height;
33
this->widget[0].right = this->width - 1;
34
this->widget[0].bottom = this->height - 1;
38
/* Center Highscore/Endscreen background */
39
*x = max(0, (_screen.width / 2) - (640 / 2));
40
*y = max(0, (_screen.height / 2) - (480 / 2));
41
for (uint i = 0; i < 10; i++) { // the image is split into 10 50px high parts
42
DrawSprite(this->background_img + i, PAL_NONE, *x, *y + (i * 50));
46
virtual void OnClick(Point pt, int widget)
52
/** End game window shown at the end of the game */
53
struct EndGameWindow : EndGameHighScoreBaseWindow {
54
EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc)
56
/* Pause in single-player to have a look at the highscore at your own leisure */
57
if (!_networking) DoCommandP(0, 1, 0, CMD_PAUSE);
59
this->background_img = SPR_TYCOON_IMG1_BEGIN;
61
if (_local_company != COMPANY_SPECTATOR) {
62
const Company *c = GetCompany(_local_company);
63
if (c->old_economy[0].performance_history == SCORE_MAX) {
64
this->background_img = SPR_TYCOON_IMG2_BEGIN;
68
/* In a network game show the endscores of the custom difficulty 'network' which is the last one
69
* as well as generate a TOP5 of that game, and not an all-time top5. */
71
this->window_number = lengthof(_highscore_table) - 1;
72
this->rank = SaveHighScoreValueNetwork();
74
/* in single player _local company is always valid */
75
const Company *c = GetCompany(_local_company);
76
this->window_number = _settings_game.difficulty.diff_level;
77
this->rank = SaveHighScoreValue(c);
80
MarkWholeScreenDirty();
85
if (!_networking) DoCommandP(0, 0, 0, CMD_PAUSE); // unpause
86
ShowHighscoreTable(this->window_number, this->rank);
89
virtual void OnPaint()
94
this->SetupHighScoreEndWindow(&x, &y);
96
if (!IsValidCompanyID(_local_company)) return;
98
c = GetCompany(_local_company);
99
/* We need to get performance from last year because the image is shown
100
* at the start of the new year when these things have already been copied */
101
if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
102
SetDParam(0, c->index);
103
SetDParam(1, c->index);
104
SetDParam(2, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
105
DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640);
107
SetDParam(0, c->index);
108
SetDParam(1, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
109
DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640);
114
struct HighScoreWindow : EndGameHighScoreBaseWindow {
115
HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc)
117
/* pause game to show the chart */
118
if (!_networking) DoCommandP(0, 1, 0, CMD_PAUSE);
120
/* Close all always on-top windows to get a clean screen */
121
if (_game_mode != GM_MENU) HideVitalWindows();
123
MarkWholeScreenDirty();
124
this->window_number = difficulty; // show highscore chart for difficulty...
125
this->background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show
126
this->rank = ranking;
131
if (_game_mode != GM_MENU) ShowVitalWindows();
133
if (!_networking) DoCommandP(0, 0, 0, CMD_PAUSE); // unpause
136
virtual void OnPaint()
138
const HighScore *hs = _highscore_table[this->window_number];
141
this->SetupHighScoreEndWindow(&x, &y);
143
SetDParam(0, ORIGINAL_END_YEAR);
144
SetDParam(1, this->window_number + STR_6801_EASY);
145
DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500);
147
/* Draw Highscore peepz */
148
for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
150
DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK);
152
if (hs[i].company[0] != '\0') {
153
TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK; // draw new highscore in red
155
DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour);
156
SetDParam(0, hs[i].title);
157
SetDParam(1, hs[i].score);
158
DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour);
164
static const Widget _highscore_widgets[] = {
165
{ WWT_PANEL, RESIZE_NONE, COLOUR_END, 0, 640, 0, 480, 0x0, STR_NULL},
169
static const WindowDesc _highscore_desc(
170
0, 0, 641, 481, 641, 481,
171
WC_HIGHSCORE, WC_NONE,
176
static const WindowDesc _endgame_desc(
177
0, 0, 641, 481, 641, 481,
178
WC_ENDSCREEN, WC_NONE,
183
/** Show the highscore table for a given difficulty. When called from
184
* endgame ranking is set to the top5 element that was newly added
185
* and is thus highlighted */
186
void ShowHighscoreTable(int difficulty, int8 ranking)
188
DeleteWindowByClass(WC_HIGHSCORE);
189
new HighScoreWindow(&_highscore_desc, difficulty, ranking);
192
/** Show the endgame victory screen in 2050. Update the new highscore
193
* if it was high enough */
194
void ShowEndGameChart()
196
/* Dedicated server doesn't need the highscore window and neither does -v null. */
197
if (_network_dedicated || (!_networking && !IsValidCompanyID(_local_company))) return;
200
DeleteWindowByClass(WC_ENDSCREEN);
201
new EndGameWindow(&_endgame_desc);