00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "currency.h"
00014 #include "error.h"
00015 #include "gui.h"
00016 #include "textbuf_gui.h"
00017 #include "command_func.h"
00018 #include "screenshot.h"
00019 #include "network/network.h"
00020 #include "town.h"
00021 #include "settings_internal.h"
00022 #include "newgrf_townname.h"
00023 #include "strings_func.h"
00024 #include "window_func.h"
00025 #include "string_func.h"
00026 #include "widgets/dropdown_type.h"
00027 #include "widgets/dropdown_func.h"
00028 #include "highscore.h"
00029 #include "base_media_base.h"
00030 #include "company_base.h"
00031 #include "company_func.h"
00032 #include "viewport_func.h"
00033 #include "core/geometry_func.hpp"
00034 #include "ai/ai.hpp"
00035 #include "blitter/factory.hpp"
00036 #include "language.h"
00037 #include "textfile_gui.h"
00038
00039
00040
00041 static const StringID _units_dropdown[] = {
00042 STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL,
00043 STR_GAME_OPTIONS_MEASURING_UNITS_METRIC,
00044 STR_GAME_OPTIONS_MEASURING_UNITS_SI,
00045 INVALID_STRING_ID
00046 };
00047
00048 static const StringID _driveside_dropdown[] = {
00049 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
00050 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
00051 INVALID_STRING_ID
00052 };
00053
00054 static const StringID _autosave_dropdown[] = {
00055 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
00056 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
00057 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
00058 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
00059 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
00060 INVALID_STRING_ID,
00061 };
00062
00063 int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1;
00064 static StringID *_grf_names = NULL;
00065 static int _nb_grf_names = 0;
00066
00068 void InitGRFTownGeneratorNames()
00069 {
00070 free(_grf_names);
00071 _grf_names = GetGRFTownNameList();
00072 _nb_grf_names = 0;
00073 for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
00074 }
00075
00081 static inline StringID TownName(int town_name)
00082 {
00083 if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
00084 town_name -= _nb_orig_names;
00085 if (town_name < _nb_grf_names) return _grf_names[town_name];
00086 return STR_UNDEFINED;
00087 }
00088
00093 static int GetCurRes()
00094 {
00095 int i;
00096
00097 for (i = 0; i != _num_resolutions; i++) {
00098 if ((int)_resolutions[i].width == _screen.width &&
00099 (int)_resolutions[i].height == _screen.height) {
00100 break;
00101 }
00102 }
00103 return i;
00104 }
00105
00106 static void ShowCustCurrency();
00107
00108 template <class T>
00109 static DropDownList *BuiltSetDropDownList(int *selected_index)
00110 {
00111 int n = T::GetNumSets();
00112 *selected_index = T::GetIndexOfUsedSet();
00113
00114 DropDownList *list = new DropDownList();
00115 for (int i = 0; i < n; i++) {
00116 list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)));
00117 }
00118
00119 return list;
00120 }
00121
00123 template <class TBaseSet>
00124 struct BaseSetTextfileWindow : public TextfileWindow {
00125 const TBaseSet* baseset;
00126 StringID content_type;
00127
00128 BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
00129 {
00130 this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
00131
00132 const char *textfile = this->baseset->GetTextfile(file_type);
00133 this->LoadTextfile(textfile, BASESET_DIR);
00134 }
00135
00136 void SetStringParameters(int widget) const
00137 {
00138 if (widget == WID_TF_CAPTION) {
00139 SetDParam(0, content_type);
00140 SetDParamStr(1, this->baseset->name);
00141 }
00142 }
00143 };
00144
00151 template <class TBaseSet>
00152 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
00153 {
00154 DeleteWindowByClass(WC_TEXTFILE);
00155 new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
00156 }
00157
00158 struct GameOptionsWindow : Window {
00159 GameSettings *opt;
00160 bool reload;
00161
00162 GameOptionsWindow(const WindowDesc *desc) : Window()
00163 {
00164 this->opt = &GetGameSettings();
00165 this->reload = false;
00166
00167 this->InitNested(desc, WN_GAME_OPTIONS_GAME_OPTIONS);
00168 this->OnInvalidateData(0);
00169 }
00170
00171 ~GameOptionsWindow()
00172 {
00173 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
00174 if (this->reload) _switch_mode = SM_MENU;
00175 }
00176
00183 DropDownList *BuildDropDownList(int widget, int *selected_index) const
00184 {
00185 DropDownList *list = NULL;
00186 switch (widget) {
00187 case WID_GO_CURRENCY_DROPDOWN: {
00188 list = new DropDownList();
00189 *selected_index = this->opt->locale.currency;
00190 StringID *items = BuildCurrencyDropdown();
00191 uint disabled = _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies();
00192 int custom_index = -1;
00193
00194
00195 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00196 if (*items == STR_GAME_OPTIONS_CURRENCY_CUSTOM) {
00197 custom_index = i;
00198 } else {
00199 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00200 }
00201 }
00202 list->sort(DropDownListStringItem::NatSortFunc);
00203
00204
00205 if (custom_index >= 0) {
00206 list->push_back(new DropDownListItem(-1, false));
00207 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, custom_index, HasBit(disabled, custom_index)));
00208 }
00209 break;
00210 }
00211
00212 case WID_GO_DISTANCE_DROPDOWN: {
00213 list = new DropDownList();
00214 *selected_index = this->opt->locale.units;
00215 const StringID *items = _units_dropdown;
00216 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00217 list->push_back(new DropDownListStringItem(*items, i, false));
00218 }
00219 break;
00220 }
00221
00222 case WID_GO_ROADSIDE_DROPDOWN: {
00223 list = new DropDownList();
00224 *selected_index = this->opt->vehicle.road_side;
00225 const StringID *items = _driveside_dropdown;
00226 uint disabled = 0;
00227
00228
00229
00230 extern bool RoadVehiclesAreBuilt();
00231 if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
00232 disabled = ~(1 << this->opt->vehicle.road_side);
00233 }
00234
00235 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00236 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00237 }
00238 break;
00239 }
00240
00241 case WID_GO_TOWNNAME_DROPDOWN: {
00242 list = new DropDownList();
00243 *selected_index = this->opt->game_creation.town_name;
00244
00245 int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
00246
00247
00248 for (int i = 0; i < _nb_orig_names; i++) {
00249 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
00250 }
00251 list->sort(DropDownListStringItem::NatSortFunc);
00252
00253
00254 DropDownList newgrf_names;
00255 for (int i = 0; i < _nb_grf_names; i++) {
00256 int result = _nb_orig_names + i;
00257 newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
00258 }
00259 newgrf_names.sort(DropDownListStringItem::NatSortFunc);
00260
00261
00262 if (newgrf_names.size() > 0) {
00263 newgrf_names.push_back(new DropDownListItem(-1, false));
00264 list->splice(list->begin(), newgrf_names);
00265 }
00266 break;
00267 }
00268
00269 case WID_GO_AUTOSAVE_DROPDOWN: {
00270 list = new DropDownList();
00271 *selected_index = _settings_client.gui.autosave;
00272 const StringID *items = _autosave_dropdown;
00273 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00274 list->push_back(new DropDownListStringItem(*items, i, false));
00275 }
00276 break;
00277 }
00278
00279 case WID_GO_LANG_DROPDOWN: {
00280 list = new DropDownList();
00281 for (uint i = 0; i < _languages.Length(); i++) {
00282 if (&_languages[i] == _current_language) *selected_index = i;
00283 list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
00284 }
00285 list->sort(DropDownListStringItem::NatSortFunc);
00286 break;
00287 }
00288
00289 case WID_GO_RESOLUTION_DROPDOWN:
00290 list = new DropDownList();
00291 *selected_index = GetCurRes();
00292 for (int i = 0; i < _num_resolutions; i++) {
00293 list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
00294 }
00295 break;
00296
00297 case WID_GO_SCREENSHOT_DROPDOWN:
00298 list = new DropDownList();
00299 *selected_index = _cur_screenshot_format;
00300 for (uint i = 0; i < _num_screenshot_formats; i++) {
00301 if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
00302 list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false));
00303 }
00304 break;
00305
00306 case WID_GO_BASE_GRF_DROPDOWN:
00307 list = BuiltSetDropDownList<BaseGraphics>(selected_index);
00308 break;
00309
00310 case WID_GO_BASE_SFX_DROPDOWN:
00311 list = BuiltSetDropDownList<BaseSounds>(selected_index);
00312 break;
00313
00314 case WID_GO_BASE_MUSIC_DROPDOWN:
00315 list = BuiltSetDropDownList<BaseMusic>(selected_index);
00316 break;
00317
00318 default:
00319 return NULL;
00320 }
00321
00322 return list;
00323 }
00324
00325 virtual void SetStringParameters(int widget) const
00326 {
00327 switch (widget) {
00328 case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
00329 case WID_GO_DISTANCE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL + this->opt->locale.units); break;
00330 case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
00331 case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
00332 case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
00333 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
00334 case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
00335 case WID_GO_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
00336 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
00337 case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
00338 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
00339 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
00340 case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
00341 }
00342 }
00343
00344 virtual void DrawWidget(const Rect &r, int widget) const
00345 {
00346 switch (widget) {
00347 case WID_GO_BASE_GRF_DESCRIPTION:
00348 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00349 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00350 break;
00351
00352 case WID_GO_BASE_SFX_DESCRIPTION:
00353 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00354 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00355 break;
00356
00357 case WID_GO_BASE_MUSIC_DESCRIPTION:
00358 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00359 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00360 break;
00361 }
00362 }
00363
00364 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00365 {
00366 switch (widget) {
00367 case WID_GO_BASE_GRF_DESCRIPTION:
00368
00369 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00370 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00371 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00372 }
00373 break;
00374
00375 case WID_GO_BASE_GRF_STATUS:
00376
00377 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00378 uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
00379 if (invalid_files == 0) continue;
00380
00381 SetDParam(0, invalid_files);
00382 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
00383 }
00384 break;
00385
00386 case WID_GO_BASE_SFX_DESCRIPTION:
00387
00388 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
00389 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00390 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00391 }
00392 break;
00393
00394 case WID_GO_BASE_MUSIC_DESCRIPTION:
00395
00396 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00397 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00398 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00399 }
00400 break;
00401
00402 case WID_GO_BASE_MUSIC_STATUS:
00403
00404 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00405 uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
00406 if (invalid_files == 0) continue;
00407
00408 SetDParam(0, invalid_files);
00409 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
00410 }
00411 break;
00412
00413 default: {
00414 int selected;
00415 DropDownList *list = this->BuildDropDownList(widget, &selected);
00416 if (list != NULL) {
00417
00418 for (DropDownList::iterator it = list->begin(); it != list->end(); it++) {
00419 static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
00420 Dimension string_dim;
00421 int width = (*it)->Width();
00422 string_dim.width = width + extra.width;
00423 string_dim.height = (*it)->Height(width) + extra.height;
00424 *size = maxdim(*size, string_dim);
00425 delete *it;
00426 }
00427 delete list;
00428 }
00429 }
00430 }
00431 }
00432
00433 virtual void OnClick(Point pt, int widget, int click_count)
00434 {
00435 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
00436 if (BaseGraphics::GetUsedSet() == NULL) return;
00437
00438 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
00439 return;
00440 }
00441 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
00442 if (BaseSounds::GetUsedSet() == NULL) return;
00443
00444 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
00445 return;
00446 }
00447 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
00448 if (BaseMusic::GetUsedSet() == NULL) return;
00449
00450 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
00451 return;
00452 }
00453 switch (widget) {
00454 case WID_GO_FULLSCREEN_BUTTON:
00455
00456 if (!ToggleFullScreen(!_fullscreen)) {
00457 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
00458 }
00459 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00460 this->SetDirty();
00461 break;
00462
00463 default: {
00464 int selected;
00465 DropDownList *list = this->BuildDropDownList(widget, &selected);
00466 if (list != NULL) {
00467 ShowDropDownList(this, list, selected, widget);
00468 }
00469 break;
00470 }
00471 }
00472 }
00473
00479 template <class T>
00480 void SetMediaSet(int index)
00481 {
00482 if (_game_mode == GM_MENU) {
00483 const char *name = T::GetSet(index)->name;
00484
00485 free(T::ini_set);
00486 T::ini_set = strdup(name);
00487
00488 T::SetSet(name);
00489 this->reload = true;
00490 this->InvalidateData();
00491 }
00492 }
00493
00494 virtual void OnDropdownSelect(int widget, int index)
00495 {
00496 switch (widget) {
00497 case WID_GO_CURRENCY_DROPDOWN:
00498 if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
00499 this->opt->locale.currency = index;
00500 ReInitAllWindows();
00501 break;
00502
00503 case WID_GO_DISTANCE_DROPDOWN:
00504 this->opt->locale.units = index;
00505 MarkWholeScreenDirty();
00506 break;
00507
00508 case WID_GO_ROADSIDE_DROPDOWN:
00509 if (this->opt->vehicle.road_side != index) {
00510 uint i;
00511 if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
00512 SetSettingValue(i, index);
00513 MarkWholeScreenDirty();
00514 }
00515 break;
00516
00517 case WID_GO_TOWNNAME_DROPDOWN:
00518 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
00519 this->opt->game_creation.town_name = index;
00520 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00521 }
00522 break;
00523
00524 case WID_GO_AUTOSAVE_DROPDOWN:
00525 _settings_client.gui.autosave = index;
00526 this->SetDirty();
00527 break;
00528
00529 case WID_GO_LANG_DROPDOWN:
00530 ReadLanguagePack(&_languages[index]);
00531 DeleteWindowByClass(WC_QUERY_STRING);
00532 CheckForMissingGlyphs();
00533 UpdateAllVirtCoords();
00534 ReInitAllWindows();
00535 break;
00536
00537 case WID_GO_RESOLUTION_DROPDOWN:
00538 if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
00539 this->SetDirty();
00540 }
00541 break;
00542
00543 case WID_GO_SCREENSHOT_DROPDOWN:
00544 SetScreenshotFormat(index);
00545 this->SetDirty();
00546 break;
00547
00548 case WID_GO_BASE_GRF_DROPDOWN:
00549 this->SetMediaSet<BaseGraphics>(index);
00550 break;
00551
00552 case WID_GO_BASE_SFX_DROPDOWN:
00553 this->SetMediaSet<BaseSounds>(index);
00554 break;
00555
00556 case WID_GO_BASE_MUSIC_DROPDOWN:
00557 this->SetMediaSet<BaseMusic>(index);
00558 break;
00559 }
00560 }
00561
00567 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00568 {
00569 if (!gui_scope) return;
00570 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00571
00572 bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
00573 this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
00574
00575 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
00576 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
00577 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
00578 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
00579 }
00580
00581 missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
00582 this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
00583 }
00584 };
00585
00586 static const NWidgetPart _nested_game_options_widgets[] = {
00587 NWidget(NWID_HORIZONTAL),
00588 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00589 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00590 EndContainer(),
00591 NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
00592 NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
00593 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00594 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
00595 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
00596 EndContainer(),
00597 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
00598 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_ROADSIDE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_TOOLTIP), SetFill(1, 0),
00599 EndContainer(),
00600 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
00601 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
00602 EndContainer(),
00603 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
00604 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 3, 0),
00605 NWidget(NWID_HORIZONTAL),
00606 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
00607 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
00608 EndContainer(),
00609 EndContainer(),
00610 EndContainer(),
00611
00612 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00613 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_MEASURING_UNITS_FRAME, STR_NULL),
00614 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_DISTANCE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_MEASURING_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
00615 EndContainer(),
00616 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
00617 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_TOWNNAME_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
00618 EndContainer(),
00619 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
00620 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
00621 EndContainer(),
00622 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT, STR_NULL),
00623 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_SCREENSHOT_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_SCREENSHOT_FORMAT_TOOLTIP), SetFill(1, 0),
00624 EndContainer(),
00625 NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
00626 EndContainer(),
00627 EndContainer(),
00628
00629 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
00630 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00631 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
00632 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00633 EndContainer(),
00634 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
00635 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00636 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
00637 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
00638 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
00639 EndContainer(),
00640 EndContainer(),
00641
00642 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
00643 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00644 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
00645 NWidget(NWID_SPACER), SetFill(1, 0),
00646 EndContainer(),
00647 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
00648 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00649 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
00650 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
00651 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
00652 EndContainer(),
00653 EndContainer(),
00654
00655 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
00656 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00657 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
00658 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00659 EndContainer(),
00660 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
00661 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00662 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
00663 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
00664 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
00665 EndContainer(),
00666 EndContainer(),
00667 EndContainer(),
00668 };
00669
00670 static const WindowDesc _game_options_desc(
00671 WDP_CENTER, 0, 0,
00672 WC_GAME_OPTIONS, WC_NONE,
00673 WDF_UNCLICK_BUTTONS,
00674 _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
00675 );
00676
00678 void ShowGameOptions()
00679 {
00680 DeleteWindowByClass(WC_GAME_OPTIONS);
00681 new GameOptionsWindow(&_game_options_desc);
00682 }
00683
00684 extern void StartupEconomy();
00685
00686 void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
00687
00688 class GameDifficultyWindow : public Window {
00689 private:
00690
00691 GameSettings opt_mod_temp;
00692
00693 public:
00695 static const uint GAME_DIFFICULTY_NUM = 18;
00697 static const uint WIDGETS_PER_DIFFICULTY = 3;
00698
00699 GameDifficultyWindow(const WindowDesc *desc) : Window()
00700 {
00701 this->InitNested(desc, WN_GAME_OPTIONS_GAME_DIFFICULTY);
00702
00703
00704
00705 this->SetWidgetsDisabledState(_game_mode != GM_MENU,
00706 WID_GD_LVL_EASY,
00707 WID_GD_LVL_MEDIUM,
00708 WID_GD_LVL_HARD,
00709 WID_GD_LVL_CUSTOM,
00710 WIDGET_LIST_END);
00711 this->SetWidgetDisabledState(WID_GD_HIGHSCORE, _game_mode == GM_EDITOR || _networking);
00712 this->SetWidgetDisabledState(WID_GD_ACCEPT, _networking && !_network_server);
00713
00714
00715 this->OnInvalidateData(GOID_DIFFICULTY_CHANGED);
00716 }
00717
00718 virtual void SetStringParameters(int widget) const
00719 {
00720 widget -= WID_GD_OPTIONS_START;
00721 if (widget < 0 || (widget % 3) != 2) return;
00722
00723 widget /= 3;
00724
00725 uint i;
00726 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + widget;
00727 int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00728 SetDParam(0, sd->desc.val_str + value);
00729 }
00730
00731 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00732 {
00733
00734 int index = widget - WID_GD_OPTIONS_START;
00735 if (index < 0 || (index % 3) != 2) return;
00736
00737 index /= 3;
00738
00739 uint i;
00740 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + index;
00741 const SettingDescBase *sdb = &sd->desc;
00742
00743
00744 StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
00745 for (int32 value = sdb->min; (uint32)value <= sdb->max; value += sdb->interval) {
00746 SetDParam(0, sdb->val_str + value);
00747 *size = maxdim(*size, GetStringBoundingBox(str));
00748 }
00749 }
00750
00751 virtual void OnClick(Point pt, int widget, int click_count)
00752 {
00753 if (widget >= WID_GD_OPTIONS_START) {
00754 widget -= WID_GD_OPTIONS_START;
00755 if ((widget % 3) == 2) return;
00756
00757
00758 if (_networking && !_network_server) return;
00759
00760 uint i;
00761 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + (widget / 3);
00762 const SettingDescBase *sdb = &sd->desc;
00763
00764 int32 val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00765 if (widget % 3 == 1) {
00766
00767 val = min(val + sdb->interval, (int32)sdb->max);
00768 } else {
00769
00770 val -= sdb->interval;
00771 val = max(val, sdb->min);
00772 }
00773
00774
00775 WriteValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv, val);
00776 this->RaiseWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00777 SetDifficultyLevel(3, &this->opt_mod_temp.difficulty);
00778 this->LowerWidget(WID_GD_LVL_CUSTOM);
00779 this->InvalidateData();
00780
00781 if (widget / 3 == 0 &&
00782 AI::GetInfoList()->size() == 0 &&
00783 this->opt_mod_temp.difficulty.max_no_competitors != 0) {
00784 ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
00785 }
00786 return;
00787 }
00788
00789 switch (widget) {
00790 case WID_GD_LVL_EASY:
00791 case WID_GD_LVL_MEDIUM:
00792 case WID_GD_LVL_HARD:
00793 case WID_GD_LVL_CUSTOM:
00794
00795 this->RaiseWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00796 SetDifficultyLevel(widget - WID_GD_LVL_EASY, &this->opt_mod_temp.difficulty);
00797 this->LowerWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00798 this->InvalidateData();
00799 break;
00800
00801 case WID_GD_HIGHSCORE:
00802 ShowHighscoreTable(this->opt_mod_temp.difficulty.diff_level, -1);
00803 break;
00804
00805 case WID_GD_ACCEPT: {
00806 GameSettings *opt_ptr = &GetGameSettings();
00807
00808 uint i;
00809 GetSettingFromName("difficulty.diff_level", &i);
00810 DoCommandP(0, i, this->opt_mod_temp.difficulty.diff_level, CMD_CHANGE_SETTING);
00811
00812 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00813 for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
00814 int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00815 int32 cur_val = (int32)ReadValue(GetVariableAddress(opt_ptr, &sd->save), sd->save.conv);
00816
00817 if (new_val != cur_val) {
00818 DoCommandP(0, i + btn, new_val, CMD_CHANGE_SETTING);
00819 }
00820 }
00821 delete this;
00822
00823
00824
00825 if (_game_mode == GM_EDITOR) StartupEconomy();
00826 break;
00827 }
00828
00829 case WID_GD_CANCEL:
00830 delete this;
00831 break;
00832 }
00833 }
00834
00840 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00841 {
00842 if (!gui_scope) return;
00843
00844 if (data == GOID_DIFFICULTY_CHANGED) {
00845
00846
00847
00848
00849 this->opt_mod_temp = GetGameSettings();
00850
00851 this->LowerWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00852 }
00853
00854 uint i;
00855 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00856 for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {
00857 const SettingDescBase *sdb = &sd->desc;
00858
00859 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
00860 int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00861 bool disable = (sd->desc.flags & SGF_NEWGAME_ONLY) &&
00862 (_game_mode == GM_NORMAL ||
00863 (_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0));
00864
00865 this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 0, disable || sdb->min == value);
00866 this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 1, disable || sdb->max == (uint32)value);
00867 }
00868 }
00869 };
00870
00871 static NWidgetBase *MakeDifficultyOptionsWidgets(int *biggest_index)
00872 {
00873 NWidgetVertical *vert_desc = new NWidgetVertical;
00874
00875 int widnum = WID_GD_OPTIONS_START;
00876 uint i, j;
00877 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00878
00879 for (i = 0, j = 0; i < GameDifficultyWindow::GAME_DIFFICULTY_NUM; i++, sd++, widnum += GameDifficultyWindow::WIDGETS_PER_DIFFICULTY) {
00880 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
00881
00882 NWidgetHorizontal *hor = new NWidgetHorizontal;
00883
00884
00885 NWidgetLeaf *leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum, AWV_DECREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
00886 hor->Add(leaf);
00887
00888
00889 leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum + 1, AWV_INCREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
00890 hor->Add(leaf);
00891
00892
00893 NWidgetSpacer *spacer = new NWidgetSpacer(5, 0);
00894 hor->Add(spacer);
00895
00896
00897 leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, widnum + 2, STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS + (j++), STR_NULL);
00898 leaf->SetFill(1, 0);
00899 hor->Add(leaf);
00900 vert_desc->Add(hor);
00901
00902
00903 vert_desc->Add(new NWidgetSpacer(0, 2));
00904 }
00905 *biggest_index = widnum - 1;
00906 return vert_desc;
00907 }
00908
00909
00911 static const NWidgetPart _nested_game_difficulty_widgets[] = {
00912 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_DIFFICULTY_LEVEL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00913 NWidget(WWT_PANEL, COLOUR_MAUVE),
00914 NWidget(NWID_VERTICAL), SetPIP(2, 0, 2),
00915 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
00916 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_EASY), SetDataTip(STR_DIFFICULTY_LEVEL_EASY, STR_NULL), SetFill(1, 0),
00917 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_MEDIUM), SetDataTip(STR_DIFFICULTY_LEVEL_MEDIUM, STR_NULL), SetFill(1, 0),
00918 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_HARD), SetDataTip(STR_DIFFICULTY_LEVEL_HARD, STR_NULL), SetFill(1, 0),
00919 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_CUSTOM), SetDataTip(STR_DIFFICULTY_LEVEL_CUSTOM, STR_NULL), SetFill(1, 0),
00920 EndContainer(),
00921 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
00922 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GD_HIGHSCORE), SetDataTip(STR_DIFFICULTY_LEVEL_HIGH_SCORE_BUTTON, STR_NULL), SetFill(1, 0),
00923 EndContainer(),
00924 EndContainer(),
00925 EndContainer(),
00926 NWidget(WWT_PANEL, COLOUR_MAUVE),
00927 NWidget(NWID_VERTICAL), SetPIP(3, 0, 1),
00928 NWidget(NWID_HORIZONTAL), SetPIP(5, 0, 5),
00929 NWidgetFunction(MakeDifficultyOptionsWidgets),
00930 EndContainer(),
00931 EndContainer(),
00932 EndContainer(),
00933 NWidget(WWT_PANEL, COLOUR_MAUVE),
00934 NWidget(NWID_VERTICAL), SetPIP(2, 0, 2),
00935 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
00936 NWidget(NWID_SPACER), SetFill(1, 0),
00937 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GD_ACCEPT), SetDataTip(STR_DIFFICULTY_LEVEL_SAVE, STR_NULL), SetFill(1, 0),
00938 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GD_CANCEL), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), SetFill(1, 0),
00939 NWidget(NWID_SPACER), SetFill(1, 0),
00940 EndContainer(),
00941 EndContainer(),
00942 EndContainer(),
00943 };
00944
00946 static const WindowDesc _game_difficulty_desc(
00947 WDP_CENTER, 0, 0,
00948 WC_GAME_OPTIONS, WC_NONE,
00949 WDF_UNCLICK_BUTTONS,
00950 _nested_game_difficulty_widgets, lengthof(_nested_game_difficulty_widgets)
00951 );
00952
00954 void ShowGameDifficulty()
00955 {
00956 DeleteWindowByClass(WC_GAME_OPTIONS);
00957 new GameDifficultyWindow(&_game_difficulty_desc);
00958 }
00959
00960 static int SETTING_HEIGHT = 11;
00961 static const int LEVEL_WIDTH = 15;
00962
00967 enum SettingEntryFlags {
00968 SEF_LEFT_DEPRESSED = 0x01,
00969 SEF_RIGHT_DEPRESSED = 0x02,
00970 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED),
00971
00972 SEF_LAST_FIELD = 0x04,
00973
00974
00975 SEF_SETTING_KIND = 0x10,
00976 SEF_SUBTREE_KIND = 0x20,
00977 SEF_KIND_MASK = (SEF_SETTING_KIND | SEF_SUBTREE_KIND),
00978 };
00979
00980 struct SettingsPage;
00981
00983 struct SettingEntrySubtree {
00984 SettingsPage *page;
00985 bool folded;
00986 StringID title;
00987 };
00988
00990 struct SettingEntrySetting {
00991 const char *name;
00992 const SettingDesc *setting;
00993 uint index;
00994 };
00995
00997 struct SettingEntry {
00998 byte flags;
00999 byte level;
01000 union {
01001 SettingEntrySetting entry;
01002 SettingEntrySubtree sub;
01003 } d;
01004
01005 SettingEntry(const char *nm);
01006 SettingEntry(SettingsPage *sub, StringID title);
01007
01008 void Init(byte level, bool last_field);
01009 void FoldAll();
01010 void SetButtons(byte new_val);
01011
01012 uint Length() const;
01013 SettingEntry *FindEntry(uint row, uint *cur_row);
01014
01015 uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last);
01016
01017 private:
01018 void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state);
01019 };
01020
01022 struct SettingsPage {
01023 SettingEntry *entries;
01024 byte num;
01025
01026 void Init(byte level = 0);
01027 void FoldAll();
01028
01029 uint Length() const;
01030 SettingEntry *FindEntry(uint row, uint *cur_row) const;
01031
01032 uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
01033 };
01034
01035
01036
01037
01042 SettingEntry::SettingEntry(const char *nm)
01043 {
01044 this->flags = SEF_SETTING_KIND;
01045 this->level = 0;
01046 this->d.entry.name = nm;
01047 this->d.entry.setting = NULL;
01048 this->d.entry.index = 0;
01049 }
01050
01056 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
01057 {
01058 this->flags = SEF_SUBTREE_KIND;
01059 this->level = 0;
01060 this->d.sub.page = sub;
01061 this->d.sub.folded = true;
01062 this->d.sub.title = title;
01063 }
01064
01070 void SettingEntry::Init(byte level, bool last_field)
01071 {
01072 this->level = level;
01073 if (last_field) this->flags |= SEF_LAST_FIELD;
01074
01075 switch (this->flags & SEF_KIND_MASK) {
01076 case SEF_SETTING_KIND:
01077 this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
01078 assert(this->d.entry.setting != NULL);
01079 break;
01080 case SEF_SUBTREE_KIND:
01081 this->d.sub.page->Init(level + 1);
01082 break;
01083 default: NOT_REACHED();
01084 }
01085 }
01086
01088 void SettingEntry::FoldAll()
01089 {
01090 switch (this->flags & SEF_KIND_MASK) {
01091 case SEF_SETTING_KIND:
01092 break;
01093
01094 case SEF_SUBTREE_KIND:
01095 this->d.sub.folded = true;
01096 this->d.sub.page->FoldAll();
01097 break;
01098
01099 default: NOT_REACHED();
01100 }
01101 }
01102
01103
01109 void SettingEntry::SetButtons(byte new_val)
01110 {
01111 assert((new_val & ~SEF_BUTTONS_MASK) == 0);
01112 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
01113 }
01114
01116 uint SettingEntry::Length() const
01117 {
01118 switch (this->flags & SEF_KIND_MASK) {
01119 case SEF_SETTING_KIND:
01120 return 1;
01121 case SEF_SUBTREE_KIND:
01122 if (this->d.sub.folded) return 1;
01123
01124 return 1 + this->d.sub.page->Length();
01125 default: NOT_REACHED();
01126 }
01127 }
01128
01135 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
01136 {
01137 if (row_num == *cur_row) return this;
01138
01139 switch (this->flags & SEF_KIND_MASK) {
01140 case SEF_SETTING_KIND:
01141 (*cur_row)++;
01142 break;
01143 case SEF_SUBTREE_KIND:
01144 (*cur_row)++;
01145 if (this->d.sub.folded) {
01146 break;
01147 }
01148
01149
01150 return this->d.sub.page->FindEntry(row_num, cur_row);
01151 default: NOT_REACHED();
01152 }
01153 return NULL;
01154 }
01155
01182 uint SettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last)
01183 {
01184 if (cur_row >= max_row) return cur_row;
01185
01186 bool rtl = _current_text_dir == TD_RTL;
01187 int offset = rtl ? -4 : 4;
01188 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
01189
01190 int x = rtl ? right : left;
01191 int y = base_y;
01192 if (cur_row >= first_row) {
01193 int colour = _colour_gradient[COLOUR_ORANGE][4];
01194 y = base_y + (cur_row - first_row) * SETTING_HEIGHT;
01195
01196
01197 for (uint lvl = 0; lvl < this->level; lvl++) {
01198 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
01199 x += level_width;
01200 }
01201
01202 int halfway_y = y + SETTING_HEIGHT / 2;
01203 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
01204 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
01205
01206 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
01207 x += level_width;
01208 }
01209
01210 switch (this->flags & SEF_KIND_MASK) {
01211 case SEF_SETTING_KIND:
01212 if (cur_row >= first_row) {
01213 DrawSetting(settings_ptr, this->d.entry.setting, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK);
01214 }
01215 cur_row++;
01216 break;
01217 case SEF_SUBTREE_KIND:
01218 if (cur_row >= first_row) {
01219 DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
01220 DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
01221 }
01222 cur_row++;
01223 if (!this->d.sub.folded) {
01224 if (this->flags & SEF_LAST_FIELD) {
01225 assert(this->level < sizeof(parent_last));
01226 SetBit(parent_last, this->level);
01227 }
01228
01229 cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last);
01230 }
01231 break;
01232 default: NOT_REACHED();
01233 }
01234 return cur_row;
01235 }
01236
01237 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
01238 {
01239 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01240 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
01241 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
01242 } else {
01243 return GetVariableAddress(&_settings_client.company, &sd->save);
01244 }
01245 } else {
01246 return GetVariableAddress(settings_ptr, &sd->save);
01247 }
01248 }
01249
01259 void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int left, int right, int y, int state)
01260 {
01261 const SettingDescBase *sdb = &sd->desc;
01262 const void *var = ResolveVariableAddress(settings_ptr, sd);
01263 bool editable = true;
01264 bool disabled = false;
01265
01266 bool rtl = _current_text_dir == TD_RTL;
01267 uint buttons_left = rtl ? right - 19 : left;
01268 uint text_left = left + (rtl ? 0 : 25);
01269 uint text_right = right - (rtl ? 25 : 0);
01270 uint button_y = y + (SETTING_HEIGHT - 11) / 2;
01271
01272
01273 if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sdb->flags & SGF_PER_COMPANY)) editable = false;
01274 if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
01275 if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
01276
01277 if (sdb->cmd == SDT_BOOLX) {
01278
01279 bool on = ReadValue(var, sd->save.conv) != 0;
01280
01281 DrawBoolButton(buttons_left, button_y, on, editable);
01282 SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
01283 } else {
01284 int32 value;
01285
01286 value = (int32)ReadValue(var, sd->save.conv);
01287
01288
01289 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state, editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
01290
01291 disabled = (value == 0) && (sdb->flags & SGF_0ISDISABLED);
01292 if (disabled) {
01293 SetDParam(0, STR_CONFIG_SETTING_DISABLED);
01294 } else {
01295 if (sdb->flags & SGF_CURRENCY) {
01296 SetDParam(0, STR_JUST_CURRENCY_LONG);
01297 } else if (sdb->flags & SGF_MULTISTRING) {
01298 SetDParam(0, sdb->val_str - sdb->min + value);
01299 } else {
01300 SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_JUST_INT : STR_JUST_COMMA);
01301 }
01302 SetDParam(1, value);
01303 }
01304 }
01305 DrawString(text_left, text_right, y, (sdb->str) + disabled);
01306 }
01307
01308
01309
01310
01315 void SettingsPage::Init(byte level)
01316 {
01317 for (uint field = 0; field < this->num; field++) {
01318 this->entries[field].Init(level, field + 1 == num);
01319 }
01320 }
01321
01323 void SettingsPage::FoldAll()
01324 {
01325 for (uint field = 0; field < this->num; field++) {
01326 this->entries[field].FoldAll();
01327 }
01328 }
01329
01331 uint SettingsPage::Length() const
01332 {
01333 uint length = 0;
01334 for (uint field = 0; field < this->num; field++) {
01335 length += this->entries[field].Length();
01336 }
01337 return length;
01338 }
01339
01346 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
01347 {
01348 SettingEntry *pe = NULL;
01349
01350 for (uint field = 0; field < this->num; field++) {
01351 pe = this->entries[field].FindEntry(row_num, cur_row);
01352 if (pe != NULL) {
01353 break;
01354 }
01355 }
01356 return pe;
01357 }
01358
01376 uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last) const
01377 {
01378 if (cur_row >= max_row) return cur_row;
01379
01380 for (uint i = 0; i < this->num; i++) {
01381 cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last);
01382 if (cur_row >= max_row) {
01383 break;
01384 }
01385 }
01386 return cur_row;
01387 }
01388
01389
01390 static SettingEntry _settings_ui_display[] = {
01391 SettingEntry("gui.date_format_in_default_names"),
01392 SettingEntry("gui.population_in_label"),
01393 SettingEntry("gui.measure_tooltip"),
01394 SettingEntry("gui.loading_indicators"),
01395 SettingEntry("gui.liveries"),
01396 SettingEntry("gui.show_track_reservation"),
01397 SettingEntry("gui.expenses_layout"),
01398 SettingEntry("gui.smallmap_land_colour"),
01399 SettingEntry("gui.zoom_min"),
01400 SettingEntry("gui.zoom_max"),
01401 SettingEntry("gui.graph_line_thickness"),
01402 };
01404 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
01405
01406 static SettingEntry _settings_ui_interaction[] = {
01407 SettingEntry("gui.window_snap_radius"),
01408 SettingEntry("gui.window_soft_limit"),
01409 SettingEntry("gui.link_terraform_toolbar"),
01410 SettingEntry("gui.prefer_teamchat"),
01411 SettingEntry("gui.autoscroll"),
01412 SettingEntry("gui.reverse_scroll"),
01413 SettingEntry("gui.smooth_scroll"),
01414 SettingEntry("gui.left_mouse_btn_scrolling"),
01415
01416
01417
01418 SettingEntry("gui.scrollwheel_scrolling"),
01419 SettingEntry("gui.scrollwheel_multiplier"),
01420 #ifdef __APPLE__
01421
01422 SettingEntry("gui.right_mouse_btn_emulation"),
01423 #endif
01424 };
01426 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
01427
01428 static SettingEntry _settings_ui[] = {
01429 SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
01430 SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
01431 SettingEntry("gui.show_finances"),
01432 SettingEntry("gui.errmsg_duration"),
01433 SettingEntry("gui.hover_delay"),
01434 SettingEntry("gui.toolbar_pos"),
01435 SettingEntry("gui.statusbar_pos"),
01436 SettingEntry("gui.newgrf_default_palette"),
01437 SettingEntry("gui.pause_on_newgame"),
01438 SettingEntry("gui.advanced_vehicle_list"),
01439 SettingEntry("gui.timetable_in_ticks"),
01440 SettingEntry("gui.timetable_arrival_departure"),
01441 SettingEntry("gui.quick_goto"),
01442 SettingEntry("gui.default_rail_type"),
01443 SettingEntry("gui.disable_unsuitable_building"),
01444 SettingEntry("gui.persistent_buildingtools"),
01445 SettingEntry("gui.coloured_news_year"),
01446 };
01448 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
01449
01450 static SettingEntry _settings_construction_signals[] = {
01451 SettingEntry("construction.train_signal_side"),
01452 SettingEntry("gui.enable_signal_gui"),
01453 SettingEntry("gui.drag_signals_density"),
01454 SettingEntry("gui.drag_signals_fixed_distance"),
01455 SettingEntry("gui.semaphore_build_before"),
01456 SettingEntry("gui.default_signal_type"),
01457 SettingEntry("gui.cycle_signal_types"),
01458 };
01460 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
01461
01462 static SettingEntry _settings_construction[] = {
01463 SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
01464 SettingEntry("construction.build_on_slopes"),
01465 SettingEntry("construction.autoslope"),
01466 SettingEntry("construction.extra_dynamite"),
01467 SettingEntry("construction.max_bridge_length"),
01468 SettingEntry("construction.max_tunnel_length"),
01469 SettingEntry("station.never_expire_airports"),
01470 SettingEntry("construction.freeform_edges"),
01471 SettingEntry("construction.extra_tree_placement"),
01472 SettingEntry("construction.command_pause_level"),
01473 };
01475 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
01476
01477 static SettingEntry _settings_stations_cargo[] = {
01478 SettingEntry("order.improved_load"),
01479 SettingEntry("order.gradual_loading"),
01480 SettingEntry("order.selectgoods"),
01481 };
01483 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
01484
01485 static SettingEntry _settings_stations[] = {
01486 SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
01487 SettingEntry("station.adjacent_stations"),
01488 SettingEntry("station.distant_join_stations"),
01489 SettingEntry("station.station_spread"),
01490 SettingEntry("economy.station_noise_level"),
01491 SettingEntry("station.modified_catchment"),
01492 SettingEntry("construction.road_stop_on_town_road"),
01493 SettingEntry("construction.road_stop_on_competitor_road"),
01494 };
01496 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
01497
01498 static SettingEntry _settings_economy_towns[] = {
01499 SettingEntry("economy.bribe"),
01500 SettingEntry("economy.exclusive_rights"),
01501 SettingEntry("economy.fund_roads"),
01502 SettingEntry("economy.fund_buildings"),
01503 SettingEntry("economy.town_layout"),
01504 SettingEntry("economy.allow_town_roads"),
01505 SettingEntry("economy.allow_town_level_crossings"),
01506 SettingEntry("economy.found_town"),
01507 SettingEntry("economy.mod_road_rebuild"),
01508 SettingEntry("economy.town_growth_rate"),
01509 SettingEntry("economy.larger_towns"),
01510 SettingEntry("economy.initial_city_size"),
01511 };
01513 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
01514
01515 static SettingEntry _settings_economy_industries[] = {
01516 SettingEntry("construction.raw_industry_construction"),
01517 SettingEntry("construction.industry_platform"),
01518 SettingEntry("economy.multiple_industry_per_town"),
01519 SettingEntry("game_creation.oil_refinery_limit"),
01520 };
01522 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
01523
01524 static SettingEntry _settings_economy_scripts[] = {
01525 SettingEntry("script.script_max_opcode_till_suspend"),
01526 };
01528 static SettingsPage _settings_economy_scripts_page = {_settings_economy_scripts, lengthof(_settings_economy_scripts)};
01529
01530 static SettingEntry _settings_economy[] = {
01531 SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
01532 SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
01533 SettingEntry(&_settings_economy_scripts_page, STR_CONFIG_SETTING_ECONOMY_SCRIPTS),
01534 SettingEntry("economy.inflation"),
01535 SettingEntry("economy.smooth_economy"),
01536 SettingEntry("economy.feeder_payment_share"),
01537 SettingEntry("economy.infrastructure_maintenance"),
01538 };
01540 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
01541
01542 static SettingEntry _settings_linkgraph[] = {
01543 SettingEntry("linkgraph.recalc_interval"),
01544 SettingEntry("linkgraph.distribution_pax"),
01545 SettingEntry("linkgraph.distribution_mail"),
01546 SettingEntry("linkgraph.distribution_armoured"),
01547 SettingEntry("linkgraph.distribution_default"),
01548 SettingEntry("linkgraph.accuracy"),
01549 SettingEntry("linkgraph.demand_distance"),
01550 SettingEntry("linkgraph.demand_size"),
01551 SettingEntry("linkgraph.short_path_saturation"),
01552 };
01554 static SettingsPage _settings_linkgraph_page = {_settings_linkgraph, lengthof(_settings_linkgraph)};
01555
01556 static SettingEntry _settings_ai_npc[] = {
01557 SettingEntry("ai.ai_in_multiplayer"),
01558 SettingEntry("ai.ai_disable_veh_train"),
01559 SettingEntry("ai.ai_disable_veh_roadveh"),
01560 SettingEntry("ai.ai_disable_veh_aircraft"),
01561 SettingEntry("ai.ai_disable_veh_ship"),
01562 };
01564 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
01565
01566 static SettingEntry _settings_ai[] = {
01567 SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
01568 SettingEntry("economy.give_money"),
01569 SettingEntry("economy.allow_shares"),
01570 };
01572 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
01573
01574 static SettingEntry _settings_vehicles_routing[] = {
01575 SettingEntry("pf.pathfinder_for_trains"),
01576 SettingEntry("pf.forbid_90_deg"),
01577 SettingEntry("pf.pathfinder_for_roadvehs"),
01578 SettingEntry("pf.roadveh_queue"),
01579 SettingEntry("pf.pathfinder_for_ships"),
01580 };
01582 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
01583
01584 static SettingEntry _settings_vehicles_autorenew[] = {
01585 SettingEntry("company.engine_renew"),
01586 SettingEntry("company.engine_renew_months"),
01587 SettingEntry("company.engine_renew_money"),
01588 };
01590 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
01591
01592 static SettingEntry _settings_vehicles_servicing[] = {
01593 SettingEntry("vehicle.servint_ispercent"),
01594 SettingEntry("vehicle.servint_trains"),
01595 SettingEntry("vehicle.servint_roadveh"),
01596 SettingEntry("vehicle.servint_ships"),
01597 SettingEntry("vehicle.servint_aircraft"),
01598 SettingEntry("order.no_servicing_if_no_breakdowns"),
01599 SettingEntry("order.serviceathelipad"),
01600 };
01602 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
01603
01604 static SettingEntry _settings_vehicles_trains[] = {
01605 SettingEntry("pf.reverse_at_signals"),
01606 SettingEntry("vehicle.train_acceleration_model"),
01607 SettingEntry("vehicle.train_slope_steepness"),
01608 SettingEntry("vehicle.max_train_length"),
01609 SettingEntry("vehicle.wagon_speed_limits"),
01610 SettingEntry("vehicle.disable_elrails"),
01611 SettingEntry("vehicle.freight_trains"),
01612 SettingEntry("gui.stop_location"),
01613 };
01615 static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
01616
01617 static SettingEntry _settings_vehicles[] = {
01618 SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
01619 SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
01620 SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
01621 SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
01622 SettingEntry("gui.new_nonstop"),
01623 SettingEntry("gui.order_review_system"),
01624 SettingEntry("gui.vehicle_income_warn"),
01625 SettingEntry("gui.lost_vehicle_warn"),
01626 SettingEntry("vehicle.never_expire_vehicles"),
01627 SettingEntry("vehicle.max_trains"),
01628 SettingEntry("vehicle.max_roadveh"),
01629 SettingEntry("vehicle.max_aircraft"),
01630 SettingEntry("vehicle.max_ships"),
01631 SettingEntry("vehicle.plane_speed"),
01632 SettingEntry("vehicle.plane_crashes"),
01633 SettingEntry("vehicle.dynamic_engines"),
01634 SettingEntry("vehicle.roadveh_acceleration_model"),
01635 SettingEntry("vehicle.roadveh_slope_steepness"),
01636 SettingEntry("vehicle.smoke_amount"),
01637 };
01639 static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
01640
01641 static SettingEntry _settings_main[] = {
01642 SettingEntry(&_settings_ui_page, STR_CONFIG_SETTING_GUI),
01643 SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
01644 SettingEntry(&_settings_vehicles_page, STR_CONFIG_SETTING_VEHICLES),
01645 SettingEntry(&_settings_stations_page, STR_CONFIG_SETTING_STATIONS),
01646 SettingEntry(&_settings_economy_page, STR_CONFIG_SETTING_ECONOMY),
01647 SettingEntry(&_settings_linkgraph_page, STR_CONFIG_SETTING_LINKGRAPH),
01648 SettingEntry(&_settings_ai_page, STR_CONFIG_SETTING_AI),
01649 };
01650
01652 static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
01653
01654 struct GameSettingsWindow : Window {
01655 static const int SETTINGTREE_LEFT_OFFSET = 5;
01656 static const int SETTINGTREE_RIGHT_OFFSET = 5;
01657 static const int SETTINGTREE_TOP_OFFSET = 5;
01658 static const int SETTINGTREE_BOTTOM_OFFSET = 5;
01659
01660 static GameSettings *settings_ptr;
01661
01662 SettingEntry *valuewindow_entry;
01663 SettingEntry *clicked_entry;
01664
01665 Scrollbar *vscroll;
01666
01667 GameSettingsWindow(const WindowDesc *desc) : Window()
01668 {
01669 static bool first_time = true;
01670
01671 settings_ptr = &GetGameSettings();
01672
01673
01674 if (first_time) {
01675 _settings_main_page.Init();
01676 first_time = false;
01677 } else {
01678 _settings_main_page.FoldAll();
01679 }
01680
01681 this->valuewindow_entry = NULL;
01682 this->clicked_entry = NULL;
01683
01684 this->CreateNestedTree(desc);
01685 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
01686 this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
01687
01688 this->vscroll->SetCount(_settings_main_page.Length());
01689 }
01690
01691 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01692 {
01693 if (widget != WID_GS_OPTIONSPANEL) return;
01694
01695 resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
01696 resize->width = 1;
01697
01698 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
01699 }
01700
01701 virtual void DrawWidget(const Rect &r, int widget) const
01702 {
01703 if (widget != WID_GS_OPTIONSPANEL) return;
01704
01705 _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
01706 this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity());
01707 }
01708
01709 virtual void OnClick(Point pt, int widget, int click_count)
01710 {
01711 if (widget != WID_GS_OPTIONSPANEL) return;
01712
01713 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET - 1);
01714 if (btn == INT_MAX) return;
01715
01716 uint cur_row = 0;
01717 SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
01718
01719 if (pe == NULL) return;
01720
01721 int x = (_current_text_dir == TD_RTL ? this->width - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;
01722 if (x < 0) return;
01723
01724 if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
01725 pe->d.sub.folded = !pe->d.sub.folded;
01726
01727 this->vscroll->SetCount(_settings_main_page.Length());
01728 this->SetDirty();
01729 return;
01730 }
01731
01732 assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01733 const SettingDesc *sd = pe->d.entry.setting;
01734
01735
01736 if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sd->desc.flags & SGF_PER_COMPANY)) return;
01737 if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
01738 if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return;
01739
01740 const void *var = ResolveVariableAddress(settings_ptr, sd);
01741 int32 value = (int32)ReadValue(var, sd->save.conv);
01742
01743
01744 if (x < 21) {
01745 const SettingDescBase *sdb = &sd->desc;
01746 int32 oldvalue = value;
01747
01748 switch (sdb->cmd) {
01749 case SDT_BOOLX: value ^= 1; break;
01750 case SDT_ONEOFMANY:
01751 case SDT_NUMX: {
01752
01753
01754
01755
01756 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
01757 if (step == 0) step = 1;
01758
01759
01760 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
01761 _left_button_clicked = false;
01762 return;
01763 }
01764
01765
01766 if (x >= 10) {
01767 value += step;
01768 if (sdb->min < 0) {
01769 assert((int32)sdb->max >= 0);
01770 if (value > (int32)sdb->max) value = (int32)sdb->max;
01771 } else {
01772 if ((uint32)value > sdb->max) value = (int32)sdb->max;
01773 }
01774 if (value < sdb->min) value = sdb->min;
01775 } else {
01776 value -= step;
01777 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
01778 }
01779
01780
01781 if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
01782 if (this->clicked_entry != NULL) {
01783 this->clicked_entry->SetButtons(0);
01784 }
01785 this->clicked_entry = pe;
01786 this->clicked_entry->SetButtons((x >= 10) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
01787 this->SetTimeout();
01788 _left_button_clicked = false;
01789 }
01790 break;
01791 }
01792
01793 default: NOT_REACHED();
01794 }
01795
01796 if (value != oldvalue) {
01797 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01798 SetCompanySetting(pe->d.entry.index, value);
01799 } else {
01800 SetSettingValue(pe->d.entry.index, value);
01801 }
01802 this->SetDirty();
01803 }
01804 } else {
01805
01806 if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
01807
01808 if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
01809
01810 this->valuewindow_entry = pe;
01811 SetDParam(0, value);
01812 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
01813 }
01814 }
01815 }
01816
01817 virtual void OnTimeout()
01818 {
01819 if (this->clicked_entry != NULL) {
01820 this->clicked_entry->SetButtons(0);
01821 this->clicked_entry = NULL;
01822 this->SetDirty();
01823 }
01824 }
01825
01826 virtual void OnQueryTextFinished(char *str)
01827 {
01828
01829 if (str == NULL) return;
01830
01831 assert(this->valuewindow_entry != NULL);
01832 assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01833 const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
01834
01835 int32 value;
01836 if (!StrEmpty(str)) {
01837 value = atoi(str);
01838
01839
01840 if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
01841 } else {
01842 value = (int32)(size_t)sd->desc.def;
01843 }
01844
01845 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01846 SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
01847 } else {
01848 SetSettingValue(this->valuewindow_entry->d.entry.index, value);
01849 }
01850 this->SetDirty();
01851 }
01852
01853 virtual void OnResize()
01854 {
01855 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
01856 }
01857 };
01858
01859 GameSettings *GameSettingsWindow::settings_ptr = NULL;
01860
01861 static const NWidgetPart _nested_settings_selection_widgets[] = {
01862 NWidget(NWID_HORIZONTAL),
01863 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
01864 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
01865 EndContainer(),
01866 NWidget(NWID_HORIZONTAL),
01867 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
01868 NWidget(NWID_VERTICAL),
01869 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
01870 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
01871 EndContainer(),
01872 EndContainer(),
01873 };
01874
01875 static const WindowDesc _settings_selection_desc(
01876 WDP_CENTER, 450, 397,
01877 WC_GAME_OPTIONS, WC_NONE,
01878 0,
01879 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
01880 );
01881
01883 void ShowGameSettings()
01884 {
01885 DeleteWindowByClass(WC_GAME_OPTIONS);
01886 new GameSettingsWindow(&_settings_selection_desc);
01887 }
01888
01889
01899 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
01900 {
01901 int colour = _colour_gradient[button_colour][2];
01902
01903 DrawFrameRect(x, y + 1, x + 9, y + 9, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
01904 DrawFrameRect(x + 10, y + 1, x + 19, y + 9, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
01905 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
01906 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + 10, y + WD_IMGBTN_TOP);
01907
01908
01909 bool rtl = _current_text_dir == TD_RTL;
01910 if (rtl ? !clickable_right : !clickable_left) {
01911 GfxFillRect(x + 1, y + 1, x + 1 + 8, y + 8, colour, FILLRECT_CHECKER);
01912 }
01913 if (rtl ? !clickable_left : !clickable_right) {
01914 GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, colour, FILLRECT_CHECKER);
01915 }
01916 }
01917
01925 void DrawBoolButton(int x, int y, bool state, bool clickable)
01926 {
01927 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
01928 DrawFrameRect(x, y + 1, x + 19, y + 9, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
01929 }
01930
01931 struct CustomCurrencyWindow : Window {
01932 int query_widget;
01933
01934 CustomCurrencyWindow(const WindowDesc *desc) : Window()
01935 {
01936 this->InitNested(desc);
01937
01938 SetButtonState();
01939 }
01940
01941 void SetButtonState()
01942 {
01943 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
01944 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
01945 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
01946 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
01947 }
01948
01949 virtual void SetStringParameters(int widget) const
01950 {
01951 switch (widget) {
01952 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
01953 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
01954 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
01955 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
01956 case WID_CC_YEAR:
01957 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
01958 SetDParam(1, _custom_currency.to_euro);
01959 break;
01960
01961 case WID_CC_PREVIEW:
01962 SetDParam(0, 10000);
01963 break;
01964 }
01965 }
01966
01967 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01968 {
01969 switch (widget) {
01970
01971 case WID_CC_SEPARATOR_EDIT:
01972 case WID_CC_PREFIX_EDIT:
01973 case WID_CC_SUFFIX_EDIT:
01974 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
01975 break;
01976
01977
01978 case WID_CC_RATE:
01979 SetDParam(0, 1);
01980 SetDParam(1, INT32_MAX);
01981 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
01982 break;
01983 }
01984 }
01985
01986 virtual void OnClick(Point pt, int widget, int click_count)
01987 {
01988 int line = 0;
01989 int len = 0;
01990 StringID str = 0;
01991 CharSetFilter afilter = CS_ALPHANUMERAL;
01992
01993 switch (widget) {
01994 case WID_CC_RATE_DOWN:
01995 if (_custom_currency.rate > 1) _custom_currency.rate--;
01996 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
01997 this->EnableWidget(WID_CC_RATE_UP);
01998 break;
01999
02000 case WID_CC_RATE_UP:
02001 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
02002 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
02003 this->EnableWidget(WID_CC_RATE_DOWN);
02004 break;
02005
02006 case WID_CC_RATE:
02007 SetDParam(0, _custom_currency.rate);
02008 str = STR_JUST_INT;
02009 len = 5;
02010 line = WID_CC_RATE;
02011 afilter = CS_NUMERAL;
02012 break;
02013
02014 case WID_CC_SEPARATOR_EDIT:
02015 case WID_CC_SEPARATOR:
02016 SetDParamStr(0, _custom_currency.separator);
02017 str = STR_JUST_RAW_STRING;
02018 len = 1;
02019 line = WID_CC_SEPARATOR;
02020 break;
02021
02022 case WID_CC_PREFIX_EDIT:
02023 case WID_CC_PREFIX:
02024 SetDParamStr(0, _custom_currency.prefix);
02025 str = STR_JUST_RAW_STRING;
02026 len = 12;
02027 line = WID_CC_PREFIX;
02028 break;
02029
02030 case WID_CC_SUFFIX_EDIT:
02031 case WID_CC_SUFFIX:
02032 SetDParamStr(0, _custom_currency.suffix);
02033 str = STR_JUST_RAW_STRING;
02034 len = 12;
02035 line = WID_CC_SUFFIX;
02036 break;
02037
02038 case WID_CC_YEAR_DOWN:
02039 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
02040 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
02041 this->EnableWidget(WID_CC_YEAR_UP);
02042 break;
02043
02044 case WID_CC_YEAR_UP:
02045 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
02046 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
02047 this->EnableWidget(WID_CC_YEAR_DOWN);
02048 break;
02049
02050 case WID_CC_YEAR:
02051 SetDParam(0, _custom_currency.to_euro);
02052 str = STR_JUST_INT;
02053 len = 7;
02054 line = WID_CC_YEAR;
02055 afilter = CS_NUMERAL;
02056 break;
02057 }
02058
02059 if (len != 0) {
02060 this->query_widget = line;
02061 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
02062 }
02063
02064 this->SetTimeout();
02065 this->SetDirty();
02066 }
02067
02068 virtual void OnQueryTextFinished(char *str)
02069 {
02070 if (str == NULL) return;
02071
02072 switch (this->query_widget) {
02073 case WID_CC_RATE:
02074 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
02075 break;
02076
02077 case WID_CC_SEPARATOR:
02078 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
02079 break;
02080
02081 case WID_CC_PREFIX:
02082 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
02083 break;
02084
02085 case WID_CC_SUFFIX:
02086 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
02087 break;
02088
02089 case WID_CC_YEAR: {
02090 int val = atoi(str);
02091
02092 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
02093 break;
02094 }
02095 }
02096 MarkWholeScreenDirty();
02097 SetButtonState();
02098 }
02099
02100 virtual void OnTimeout()
02101 {
02102 this->SetDirty();
02103 }
02104 };
02105
02106 static const NWidgetPart _nested_cust_currency_widgets[] = {
02107 NWidget(NWID_HORIZONTAL),
02108 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
02109 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02110 EndContainer(),
02111 NWidget(WWT_PANEL, COLOUR_GREY),
02112 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
02113 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02114 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
02115 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
02116 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02117 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
02118 EndContainer(),
02119 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02120 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
02121 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02122 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
02123 EndContainer(),
02124 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02125 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
02126 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02127 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
02128 EndContainer(),
02129 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02130 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
02131 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02132 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
02133 EndContainer(),
02134 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02135 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02136 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02137 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02138 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
02139 EndContainer(),
02140 EndContainer(),
02141 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
02142 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
02143 EndContainer(),
02144 };
02145
02146 static const WindowDesc _cust_currency_desc(
02147 WDP_CENTER, 0, 0,
02148 WC_CUSTOM_CURRENCY, WC_NONE,
02149 WDF_UNCLICK_BUTTONS,
02150 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
02151 );
02152
02154 static void ShowCustCurrency()
02155 {
02156 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
02157 new CustomCurrencyWindow(&_cust_currency_desc);
02158 }