00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "highscore.h"
00014 #include "table/strings.h"
00015 #include "gfx_func.h"
00016 #include "table/sprites.h"
00017 #include "window_gui.h"
00018 #include "window_func.h"
00019 #include "network/network.h"
00020 #include "command_func.h"
00021 #include "company_func.h"
00022 #include "company_base.h"
00023 #include "strings_func.h"
00024 #include "hotkeys.h"
00025
00026 #include "widgets/highscore_widget.h"
00027
00028 struct EndGameHighScoreBaseWindow : Window {
00029 uint32 background_img;
00030 int8 rank;
00031
00032 EndGameHighScoreBaseWindow(const WindowDesc *desc) : Window()
00033 {
00034 this->InitNested(desc);
00035 CLRBITS(this->flags, WF_WHITE_BORDER);
00036 ResizeWindow(this, _screen.width - this->width, _screen.height - this->height);
00037 }
00038
00039
00040 void SetupHighScoreEndWindow()
00041 {
00042
00043 if (this->width != _screen.width || this->height != _screen.height) ResizeWindow(this, _screen.width - this->width, _screen.height - this->height);
00044
00045 this->DrawWidgets();
00046
00047 Point pt = this->GetTopLeft640x480();
00048
00049 for (uint i = 0; i < 10; i++) {
00050 DrawSprite(this->background_img + i, PAL_NONE, pt.x, pt.y + (i * 50));
00051 }
00052 }
00053
00055 Point GetTopLeft640x480()
00056 {
00057 Point pt = {max(0, (_screen.width / 2) - (640 / 2)), max(0, (_screen.height / 2) - (480 / 2))};
00058 return pt;
00059 }
00060
00061 virtual void OnClick(Point pt, int widget, int click_count)
00062 {
00063 delete this;
00064 }
00065
00066 virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00067 {
00068
00069
00070
00071 if (IsQuitKey(keycode)) return ES_NOT_HANDLED;
00072
00073 switch (keycode) {
00074
00075 case WKC_RETURN:
00076 case WKC_ESC:
00077 case WKC_SPACE:
00078 delete this;
00079 return ES_HANDLED;
00080
00081 default:
00082
00083
00084
00085 return ES_HANDLED;
00086 }
00087 }
00088 };
00089
00091 struct EndGameWindow : EndGameHighScoreBaseWindow {
00092 EndGameWindow(const WindowDesc *desc) : EndGameHighScoreBaseWindow(desc)
00093 {
00094
00095 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
00096
00097 this->background_img = SPR_TYCOON_IMG1_BEGIN;
00098
00099 if (_local_company != COMPANY_SPECTATOR) {
00100 const Company *c = Company::Get(_local_company);
00101 if (c->old_economy[0].performance_history == SCORE_MAX) {
00102 this->background_img = SPR_TYCOON_IMG2_BEGIN;
00103 }
00104 }
00105
00106
00107
00108 if (_networking) {
00109 this->window_number = lengthof(_highscore_table) - 1;
00110 this->rank = SaveHighScoreValueNetwork();
00111 } else {
00112
00113 const Company *c = Company::Get(_local_company);
00114 this->window_number = _settings_game.difficulty.diff_level;
00115 this->rank = SaveHighScoreValue(c);
00116 }
00117
00118 MarkWholeScreenDirty();
00119 }
00120
00121 ~EndGameWindow()
00122 {
00123 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
00124 ShowHighscoreTable(this->window_number, this->rank);
00125 }
00126
00127 virtual void OnPaint()
00128 {
00129 this->SetupHighScoreEndWindow();
00130 Point pt = this->GetTopLeft640x480();
00131
00132 const Company *c = Company::GetIfValid(_local_company);
00133 if (c == NULL) return;
00134
00135
00136
00137 if (this->background_img == SPR_TYCOON_IMG2_BEGIN) {
00138 SetDParam(0, c->index);
00139 SetDParam(1, c->index);
00140 SetDParam(2, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
00141 DrawStringMultiLine(pt.x + 15, pt.x + 640 - 25, pt.y + 90, pt.y + 160, STR_HIGHSCORE_PRESIDENT_OF_COMPANY_ACHIEVES_STATUS, TC_FROMSTRING, SA_CENTER);
00142 } else {
00143 SetDParam(0, c->index);
00144 SetDParam(1, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
00145 DrawStringMultiLine(pt.x + 36, pt.x + 640, pt.y + 140, pt.y + 206, STR_HIGHSCORE_COMPANY_ACHIEVES_STATUS, TC_FROMSTRING, SA_CENTER);
00146 }
00147 }
00148 };
00149
00150 struct HighScoreWindow : EndGameHighScoreBaseWindow {
00151 HighScoreWindow(const WindowDesc *desc, int difficulty, int8 ranking) : EndGameHighScoreBaseWindow(desc)
00152 {
00153
00154 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
00155
00156
00157 if (_game_mode != GM_MENU) HideVitalWindows();
00158
00159 MarkWholeScreenDirty();
00160 this->window_number = difficulty;
00161 this->background_img = SPR_HIGHSCORE_CHART_BEGIN;
00162 this->rank = ranking;
00163 }
00164
00165 ~HighScoreWindow()
00166 {
00167 if (_game_mode != GM_MENU) ShowVitalWindows();
00168
00169 if (!_networking) DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
00170 }
00171
00172 virtual void OnPaint()
00173 {
00174 const HighScore *hs = _highscore_table[this->window_number];
00175
00176 this->SetupHighScoreEndWindow();
00177 Point pt = this->GetTopLeft640x480();
00178
00179 SetDParam(0, ORIGINAL_END_YEAR);
00180 SetDParam(1, this->window_number + STR_DIFFICULTY_LEVEL_EASY);
00181 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);
00182
00183
00184 for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
00185 SetDParam(0, i + 1);
00186 DrawString(pt.x + 40, pt.x + 600, pt.y + 140 + (i * 55), STR_HIGHSCORE_POSITION);
00187
00188 if (hs[i].company[0] != '\0') {
00189 TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK;
00190
00191 DrawString(pt.x + 71, pt.x + 569, pt.y + 140 + (i * 55), hs[i].company, colour);
00192 SetDParam(0, hs[i].title);
00193 SetDParam(1, hs[i].score);
00194 DrawString(pt.x + 71, pt.x + 569, pt.y + 140 + FONT_HEIGHT_LARGE + (i * 55), STR_HIGHSCORE_STATS, colour);
00195 }
00196 }
00197 }
00198 };
00199
00200 static const NWidgetPart _nested_highscore_widgets[] = {
00201 NWidget(WWT_PANEL, COLOUR_END, WID_H_BACKGROUND), SetMinimalSize(641, 481), SetResize(1, 1), EndContainer(),
00202 };
00203
00204 static const WindowDesc _highscore_desc(
00205 WDP_MANUAL, 0, 0,
00206 WC_HIGHSCORE, WC_NONE,
00207 0,
00208 _nested_highscore_widgets, lengthof(_nested_highscore_widgets)
00209 );
00210
00211 static const WindowDesc _endgame_desc(
00212 WDP_MANUAL, 0, 0,
00213 WC_ENDSCREEN, WC_NONE,
00214 0,
00215 _nested_highscore_widgets, lengthof(_nested_highscore_widgets)
00216 );
00217
00223 void ShowHighscoreTable(int difficulty, int8 ranking)
00224 {
00225 DeleteWindowByClass(WC_HIGHSCORE);
00226 new HighScoreWindow(&_highscore_desc, difficulty, ranking);
00227 }
00228
00233 void ShowEndGameChart()
00234 {
00235
00236 if (_network_dedicated || (!_networking && !Company::IsValidID(_local_company))) return;
00237
00238 HideVitalWindows();
00239 DeleteWindowByClass(WC_ENDSCREEN);
00240 new EndGameWindow(&_endgame_desc);
00241 }