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