~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/highscore_gui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: highscore_gui.cpp 15723 2009-03-15 15:12:06Z rubidium $ */
 
2
 
 
3
/** @file highscore_gui.cpp Definition of the HighScore and EndGame windows */
 
4
 
 
5
#include "highscore.h"
 
6
#include "table/strings.h"
 
7
#include "gfx_func.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"
 
17
#include "openttd.h"
 
18
 
 
19
struct EndGameHighScoreBaseWindow : Window {
 
20
        uint32 background_img;
 
21
        int8 rank;
 
22
 
 
23
        EndGameHighScoreBaseWindow(const WindowDesc *desc) : Window(desc)
 
24
        {
 
25
        }
 
26
 
 
27
        /* Always draw a maximized window and within there the centered background */
 
28
        void SetupHighScoreEndWindow(uint *x, uint *y)
 
29
        {
 
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;
 
35
 
 
36
                this->DrawWidgets();
 
37
 
 
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));
 
43
                }
 
44
        }
 
45
 
 
46
        virtual void OnClick(Point pt, int widget)
 
47
        {
 
48
                delete this;
 
49
        }
 
50
};
 
51
 
 
52
/** End game window shown at the end of the game */
 
53
struct EndGameWindow : EndGameHighScoreBaseWindow {
 
54
        EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc)
 
55
        {
 
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);
 
58
 
 
59
                this->background_img = SPR_TYCOON_IMG1_BEGIN;
 
60
 
 
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;
 
65
                        }
 
66
                }
 
67
 
 
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. */
 
70
                if (_networking) {
 
71
                        this->window_number = lengthof(_highscore_table) - 1;
 
72
                        this->rank = SaveHighScoreValueNetwork();
 
73
                } else {
 
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);
 
78
                }
 
79
 
 
80
                MarkWholeScreenDirty();
 
81
        }
 
82
 
 
83
        ~EndGameWindow()
 
84
        {
 
85
                if (!_networking) DoCommandP(0, 0, 0, CMD_PAUSE); // unpause
 
86
                ShowHighscoreTable(this->window_number, this->rank);
 
87
        }
 
88
 
 
89
        virtual void OnPaint()
 
90
        {
 
91
                const Company *c;
 
92
                uint x, y;
 
93
 
 
94
                this->SetupHighScoreEndWindow(&x, &y);
 
95
 
 
96
                if (!IsValidCompanyID(_local_company)) return;
 
97
 
 
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);
 
106
                } else {
 
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);
 
110
                }
 
111
        }
 
112
};
 
113
 
 
114
struct HighScoreWindow : EndGameHighScoreBaseWindow {
 
115
        HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc)
 
116
        {
 
117
                /* pause game to show the chart */
 
118
                if (!_networking) DoCommandP(0, 1, 0, CMD_PAUSE);
 
119
 
 
120
                /* Close all always on-top windows to get a clean screen */
 
121
                if (_game_mode != GM_MENU) HideVitalWindows();
 
122
 
 
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;
 
127
        }
 
128
 
 
129
        ~HighScoreWindow()
 
130
        {
 
131
                if (_game_mode != GM_MENU) ShowVitalWindows();
 
132
 
 
133
                if (!_networking) DoCommandP(0, 0, 0, CMD_PAUSE); // unpause
 
134
        }
 
135
 
 
136
        virtual void OnPaint()
 
137
        {
 
138
                const HighScore *hs = _highscore_table[this->window_number];
 
139
                uint x, y;
 
140
 
 
141
                this->SetupHighScoreEndWindow(&x, &y);
 
142
 
 
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);
 
146
 
 
147
                /* Draw Highscore peepz */
 
148
                for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
 
149
                        SetDParam(0, i + 1);
 
150
                        DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK);
 
151
 
 
152
                        if (hs[i].company[0] != '\0') {
 
153
                                TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK; // draw new highscore in red
 
154
 
 
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);
 
159
                        }
 
160
                }
 
161
        }
 
162
};
 
163
 
 
164
static const Widget _highscore_widgets[] = {
 
165
{      WWT_PANEL, RESIZE_NONE,  COLOUR_END, 0, 640, 0, 480, 0x0, STR_NULL},
 
166
{   WIDGETS_END},
 
167
};
 
168
 
 
169
static const WindowDesc _highscore_desc(
 
170
        0, 0, 641, 481, 641, 481,
 
171
        WC_HIGHSCORE, WC_NONE,
 
172
        0,
 
173
        _highscore_widgets
 
174
);
 
175
 
 
176
static const WindowDesc _endgame_desc(
 
177
        0, 0, 641, 481, 641, 481,
 
178
        WC_ENDSCREEN, WC_NONE,
 
179
        0,
 
180
        _highscore_widgets
 
181
);
 
182
 
 
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)
 
187
{
 
188
        DeleteWindowByClass(WC_HIGHSCORE);
 
189
        new HighScoreWindow(&_highscore_desc, difficulty, ranking);
 
190
}
 
191
 
 
192
/** Show the endgame victory screen in 2050. Update the new highscore
 
193
 * if it was high enough */
 
194
void ShowEndGameChart()
 
195
{
 
196
        /* Dedicated server doesn't need the highscore window and neither does -v null. */
 
197
        if (_network_dedicated || (!_networking && !IsValidCompanyID(_local_company))) return;
 
198
 
 
199
        HideVitalWindows();
 
200
        DeleteWindowByClass(WC_ENDSCREEN);
 
201
        new EndGameWindow(&_endgame_desc);
 
202
}