annotate src/highscore_gui.cpp @ 13419:ddfb6a69b9c3 draft

(svn r17928) -Codechange: ShowErrorMessage() now takes the summary string before the details string. Gentlemen, swap your string parameters.
author alberth <alberth@openttd.org>
date Sat, 31 Oct 2009 19:46:51 +0000
parents a5ccb03e737b
children bae287664b02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
1 /* $Id$ */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 11949
diff changeset
9
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
10 /** @file highscore_gui.cpp Definition of the HighScore and EndGame windows */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
11
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
12 #include "highscore.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
13 #include "table/strings.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
14 #include "gfx_func.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
15 #include "table/sprites.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
16 #include "window_gui.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
17 #include "window_func.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
18 #include "network/network.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
19 #include "command_func.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
20 #include "company_func.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
21 #include "company_base.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
22 #include "strings_func.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
23 #include "openttd.h"
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
24
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
25 enum HighscoreWidgets {
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
26 HSW_BACKGROUND,
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
27 };
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
28
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
29 struct EndGameHighScoreBaseWindow : Window {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
30 uint32 background_img;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
31 int8 rank;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
32
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
33 EndGameHighScoreBaseWindow(const WindowDesc *desc) : Window()
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
34 {
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
35 this->InitNested(desc);
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
36 ResizeWindow(this, _screen.width - this->width, _screen.height - this->height);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
37 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
38
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
39 /* Always draw a maximized window and within it the centered background */
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
40 void SetupHighScoreEndWindow()
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
41 {
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
42 /* Resize window to "full-screen". */
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
43 if (this->width != _screen.width || this->height != _screen.height) ResizeWindow(this, _screen.width - this->width, _screen.height - this->height);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
44
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
45 this->DrawWidgets();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
46
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
47 Point pt = this->GetTopLeft640x480();
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
48 /* Center Highscore/Endscreen background */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
49 for (uint i = 0; i < 10; i++) { // the image is split into 10 50px high parts
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
50 DrawSprite(this->background_img + i, PAL_NONE, pt.x, pt.y + (i * 50));
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
51 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
52 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
53
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
54 /** Return the coordinate of the screen such that a window of 640x480 is centered at the screen. */
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
55 Point GetTopLeft640x480()
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
56 {
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
57 Point pt = {max(0, (_screen.width / 2) - (640 / 2)), max(0, (_screen.height / 2) - (480 / 2))};
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
58 return pt;
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
59 }
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
60
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
61 virtual void OnClick(Point pt, int widget)
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
62 {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
63 delete this;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
64 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
65 };
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
66
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
67 /** End game window shown at the end of the game */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
68 struct EndGameWindow : EndGameHighScoreBaseWindow {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
69 EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc)
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
70 {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
71 /* Pause in single-player to have a look at the highscore at your own leisure */
11852
862dd1024fe7 (svn r16242) -Codechange: rework pausing
rubidium <rubidium@openttd.org>
parents: 11772
diff changeset
72 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
73
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
74 this->background_img = SPR_TYCOON_IMG1_BEGIN;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
75
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
76 if (_local_company != COMPANY_SPECTATOR) {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11852
diff changeset
77 const Company *c = Company::Get(_local_company);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
78 if (c->old_economy[0].performance_history == SCORE_MAX) {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
79 this->background_img = SPR_TYCOON_IMG2_BEGIN;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
80 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
81 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
82
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
83 /* In a network game show the endscores of the custom difficulty 'network' which is the last one
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
84 * as well as generate a TOP5 of that game, and not an all-time top5. */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
85 if (_networking) {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
86 this->window_number = lengthof(_highscore_table) - 1;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
87 this->rank = SaveHighScoreValueNetwork();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
88 } else {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
89 /* in single player _local company is always valid */
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11852
diff changeset
90 const Company *c = Company::Get(_local_company);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
91 this->window_number = _settings_game.difficulty.diff_level;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
92 this->rank = SaveHighScoreValue(c);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
93 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
94
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
95 MarkWholeScreenDirty();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
96 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
97
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
98 ~EndGameWindow()
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
99 {
11852
862dd1024fe7 (svn r16242) -Codechange: rework pausing
rubidium <rubidium@openttd.org>
parents: 11772
diff changeset
100 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE); // unpause
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
101 ShowHighscoreTable(this->window_number, this->rank);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
102 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
103
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
104 virtual void OnPaint()
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
105 {
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
106 this->SetupHighScoreEndWindow();
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
107 Point pt = this->GetTopLeft640x480();
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
108
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
109 const Company *c = Company::GetIfValid(_local_company);
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
110 if (c == NULL) return;
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
111
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
112 /* We need to get performance from last year because the image is shown
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
113 * at the start of the new year when these things have already been copied */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
114 if (this->background_img == SPR_TYCOON_IMG2_BEGIN) { // Tycoon of the century \o/
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
115 SetDParam(0, c->index);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
116 SetDParam(1, c->index);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
117 SetDParam(2, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
118 DrawStringMultiLine(pt.x, pt.x + 640, pt.y + 140, pt.y + 206, STR_HIGHSCORE_PRESIDENT_OF_COMPANY_ACHIEVES_STATUS, TC_FROMSTRING, SA_CENTER);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
119 } else {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
120 SetDParam(0, c->index);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
121 SetDParam(1, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
122 DrawStringMultiLine(pt.x, pt.x + 640, pt.y + 90, pt.y + 210, STR_HIGHSCORE_COMPANY_ACHIEVES_STATUS, TC_FROMSTRING, SA_CENTER);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
123 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
124 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
125 };
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
126
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
127 struct HighScoreWindow : EndGameHighScoreBaseWindow {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
128 HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc)
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
129 {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
130 /* pause game to show the chart */
11852
862dd1024fe7 (svn r16242) -Codechange: rework pausing
rubidium <rubidium@openttd.org>
parents: 11772
diff changeset
131 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
132
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
133 /* Close all always on-top windows to get a clean screen */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
134 if (_game_mode != GM_MENU) HideVitalWindows();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
135
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
136 MarkWholeScreenDirty();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
137 this->window_number = difficulty; // show highscore chart for difficulty...
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
138 this->background_img = SPR_HIGHSCORE_CHART_BEGIN; // which background to show
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
139 this->rank = ranking;
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
140 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
141
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
142 ~HighScoreWindow()
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
143 {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
144 if (_game_mode != GM_MENU) ShowVitalWindows();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
145
11852
862dd1024fe7 (svn r16242) -Codechange: rework pausing
rubidium <rubidium@openttd.org>
parents: 11772
diff changeset
146 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE); // unpause
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
147 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
148
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
149 virtual void OnPaint()
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
150 {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
151 const HighScore *hs = _highscore_table[this->window_number];
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
152
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
153 this->SetupHighScoreEndWindow();
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
154 Point pt = this->GetTopLeft640x480();
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
155
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
156 SetDParam(0, ORIGINAL_END_YEAR);
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11651
diff changeset
157 SetDParam(1, this->window_number + STR_DIFFICULTY_LEVEL_EASY);
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
158 DrawStringMultiLine(pt.x + 70, pt.x + 570, pt.y, pt.y + 140, !_networking ? STR_HIGHSCORE_TOP_COMPANIES_WHO_REACHED : STR_HIGHSCORE_TOP_COMPANIES_NETWORK_GAME, TC_FROMSTRING, SA_CENTER);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
159
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
160 /* Draw Highscore peepz */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
161 for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
162 SetDParam(0, i + 1);
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
163 DrawString(pt.x + 40, pt.x + 600, pt.y + 140 + (i * 55), STR_HIGHSCORE_POSITION);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
164
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
165 if (hs[i].company[0] != '\0') {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
166 TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK; // draw new highscore in red
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
167
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
168 DrawString(pt.x + 71, pt.x + 569, pt.y + 140 + (i * 55), hs[i].company, colour);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
169 SetDParam(0, hs[i].title);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
170 SetDParam(1, hs[i].score);
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
171 DrawString(pt.x + 71, pt.x + 569, pt.y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour);
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
172 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
173 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
174 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
175 };
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
176
11651
2c781c4528a2 (svn r16031) -Codechange: Added nested widgets to highscore and endgame windows.
alberth <alberth@openttd.org>
parents: 11478
diff changeset
177 static const NWidgetPart _nested_highscore_widgets[] = {
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
178 NWidget(WWT_PANEL, COLOUR_END, HSW_BACKGROUND), SetMinimalSize(641, 481), SetResize(1, 1), EndContainer(),
11651
2c781c4528a2 (svn r16031) -Codechange: Added nested widgets to highscore and endgame windows.
alberth <alberth@openttd.org>
parents: 11478
diff changeset
179 };
2c781c4528a2 (svn r16031) -Codechange: Added nested widgets to highscore and endgame windows.
alberth <alberth@openttd.org>
parents: 11478
diff changeset
180
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11201
diff changeset
181 static const WindowDesc _highscore_desc(
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
182 0, 0, 641, 481, 641, 481,
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
183 WC_HIGHSCORE, WC_NONE,
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
184 0,
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
185 NULL, _nested_highscore_widgets, lengthof(_nested_highscore_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11201
diff changeset
186 );
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
187
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11201
diff changeset
188 static const WindowDesc _endgame_desc(
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
189 0, 0, 641, 481, 641, 481,
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
190 WC_ENDSCREEN, WC_NONE,
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
191 0,
13282
a5ccb03e737b (svn r17791) -Codechange: Highscore and endgame windows use pure nested widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
192 NULL, _nested_highscore_widgets, lengthof(_nested_highscore_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11201
diff changeset
193 );
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
194
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
195 /** Show the highscore table for a given difficulty. When called from
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
196 * endgame ranking is set to the top5 element that was newly added
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
197 * and is thus highlighted */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
198 void ShowHighscoreTable(int difficulty, int8 ranking)
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
199 {
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
200 DeleteWindowByClass(WC_HIGHSCORE);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
201 new HighScoreWindow(&_highscore_desc, difficulty, ranking);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
202 }
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
203
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
204 /** Show the endgame victory screen in 2050. Update the new highscore
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
205 * if it was high enough */
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
206 void ShowEndGameChart()
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
207 {
11201
f95a5d4fa0db (svn r15554) -Fix: -v null crashing in 2051 due to trying to show the high score of the spectator.
rubidium <rubidium@openttd.org>
parents: 10960
diff changeset
208 /* Dedicated server doesn't need the highscore window and neither does -v null. */
11924
fccc9cea27a7 (svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents: 11922
diff changeset
209 if (_network_dedicated || (!_networking && !Company::IsValidID(_local_company))) return;
10558
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
210
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
211 HideVitalWindows();
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
212 DeleteWindowByClass(WC_ENDSCREEN);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
213 new EndGameWindow(&_endgame_desc);
15517829eb17 (svn r14815) -Codechange: separate 'highscore' code from 'company' code
smatz <smatz@openttd.org>
parents:
diff changeset
214 }