00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "currency.h"
00014 #include "error.h"
00015 #include "settings_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 #include "stringfilter_type.h"
00039 #include "querystring_gui.h"
00040
00041
00042 static const StringID _units_dropdown[] = {
00043 STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL,
00044 STR_GAME_OPTIONS_MEASURING_UNITS_METRIC,
00045 STR_GAME_OPTIONS_MEASURING_UNITS_SI,
00046 INVALID_STRING_ID
00047 };
00048
00049 static const StringID _driveside_dropdown[] = {
00050 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
00051 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
00052 INVALID_STRING_ID
00053 };
00054
00055 static const StringID _autosave_dropdown[] = {
00056 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
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
00068 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
00069
00071 void InitGRFTownGeneratorNames()
00072 {
00073 free(_grf_names);
00074 _grf_names = GetGRFTownNameList();
00075 _nb_grf_names = 0;
00076 for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
00077 }
00078
00084 static inline StringID TownName(int town_name)
00085 {
00086 if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
00087 town_name -= _nb_orig_names;
00088 if (town_name < _nb_grf_names) return _grf_names[town_name];
00089 return STR_UNDEFINED;
00090 }
00091
00096 static int GetCurRes()
00097 {
00098 int i;
00099
00100 for (i = 0; i != _num_resolutions; i++) {
00101 if ((int)_resolutions[i].width == _screen.width &&
00102 (int)_resolutions[i].height == _screen.height) {
00103 break;
00104 }
00105 }
00106 return i;
00107 }
00108
00109 static void ShowCustCurrency();
00110
00111 template <class T>
00112 static DropDownList *BuiltSetDropDownList(int *selected_index)
00113 {
00114 int n = T::GetNumSets();
00115 *selected_index = T::GetIndexOfUsedSet();
00116
00117 DropDownList *list = new DropDownList();
00118 for (int i = 0; i < n; i++) {
00119 list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)));
00120 }
00121
00122 return list;
00123 }
00124
00126 template <class TBaseSet>
00127 struct BaseSetTextfileWindow : public TextfileWindow {
00128 const TBaseSet* baseset;
00129 StringID content_type;
00130
00131 BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
00132 {
00133 const char *textfile = this->baseset->GetTextfile(file_type);
00134 this->LoadTextfile(textfile, BASESET_DIR);
00135 }
00136
00137 void SetStringParameters(int widget) const
00138 {
00139 if (widget == WID_TF_CAPTION) {
00140 SetDParam(0, content_type);
00141 SetDParamStr(1, this->baseset->name);
00142 }
00143 }
00144 };
00145
00152 template <class TBaseSet>
00153 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
00154 {
00155 DeleteWindowByClass(WC_TEXTFILE);
00156 new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
00157 }
00158
00159 struct GameOptionsWindow : Window {
00160 GameSettings *opt;
00161 bool reload;
00162
00163 GameOptionsWindow(const WindowDesc *desc) : Window()
00164 {
00165 this->opt = &GetGameSettings();
00166 this->reload = false;
00167
00168 this->InitNested(desc, WN_GAME_OPTIONS_GAME_OPTIONS);
00169 this->OnInvalidateData(0);
00170 }
00171
00172 ~GameOptionsWindow()
00173 {
00174 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
00175 if (this->reload) _switch_mode = SM_MENU;
00176 }
00177
00184 DropDownList *BuildDropDownList(int widget, int *selected_index) const
00185 {
00186 DropDownList *list = NULL;
00187 switch (widget) {
00188 case WID_GO_CURRENCY_DROPDOWN: {
00189 list = new DropDownList();
00190 *selected_index = this->opt->locale.currency;
00191 StringID *items = BuildCurrencyDropdown();
00192 uint disabled = _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies();
00193 int custom_index = -1;
00194
00195
00196 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00197 if (*items == STR_GAME_OPTIONS_CURRENCY_CUSTOM) {
00198 custom_index = i;
00199 } else {
00200 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00201 }
00202 }
00203 list->sort(DropDownListStringItem::NatSortFunc);
00204
00205
00206 if (custom_index >= 0) {
00207 list->push_back(new DropDownListItem(-1, false));
00208 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, custom_index, HasBit(disabled, custom_index)));
00209 }
00210 break;
00211 }
00212
00213 case WID_GO_DISTANCE_DROPDOWN: {
00214 list = new DropDownList();
00215 *selected_index = this->opt->locale.units;
00216 const StringID *items = _units_dropdown;
00217 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00218 list->push_back(new DropDownListStringItem(*items, i, false));
00219 }
00220 break;
00221 }
00222
00223 case WID_GO_ROADSIDE_DROPDOWN: {
00224 list = new DropDownList();
00225 *selected_index = this->opt->vehicle.road_side;
00226 const StringID *items = _driveside_dropdown;
00227 uint disabled = 0;
00228
00229
00230
00231 extern bool RoadVehiclesAreBuilt();
00232 if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
00233 disabled = ~(1 << this->opt->vehicle.road_side);
00234 }
00235
00236 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00237 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00238 }
00239 break;
00240 }
00241
00242 case WID_GO_TOWNNAME_DROPDOWN: {
00243 list = new DropDownList();
00244 *selected_index = this->opt->game_creation.town_name;
00245
00246 int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
00247
00248
00249 for (int i = 0; i < _nb_orig_names; i++) {
00250 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
00251 }
00252 list->sort(DropDownListStringItem::NatSortFunc);
00253
00254
00255 DropDownList newgrf_names;
00256 for (int i = 0; i < _nb_grf_names; i++) {
00257 int result = _nb_orig_names + i;
00258 newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
00259 }
00260 newgrf_names.sort(DropDownListStringItem::NatSortFunc);
00261
00262
00263 if (newgrf_names.size() > 0) {
00264 newgrf_names.push_back(new DropDownListItem(-1, false));
00265 list->splice(list->begin(), newgrf_names);
00266 }
00267 break;
00268 }
00269
00270 case WID_GO_AUTOSAVE_DROPDOWN: {
00271 list = new DropDownList();
00272 *selected_index = _settings_client.gui.autosave;
00273 const StringID *items = _autosave_dropdown;
00274 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00275 list->push_back(new DropDownListStringItem(*items, i, false));
00276 }
00277 break;
00278 }
00279
00280 case WID_GO_LANG_DROPDOWN: {
00281 list = new DropDownList();
00282 for (uint i = 0; i < _languages.Length(); i++) {
00283 if (&_languages[i] == _current_language) *selected_index = i;
00284 list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
00285 }
00286 list->sort(DropDownListStringItem::NatSortFunc);
00287 break;
00288 }
00289
00290 case WID_GO_RESOLUTION_DROPDOWN:
00291 list = new DropDownList();
00292 *selected_index = GetCurRes();
00293 for (int i = 0; i < _num_resolutions; i++) {
00294 list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
00295 }
00296 break;
00297
00298 case WID_GO_SCREENSHOT_DROPDOWN:
00299 list = new DropDownList();
00300 *selected_index = _cur_screenshot_format;
00301 for (uint i = 0; i < _num_screenshot_formats; i++) {
00302 if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
00303 list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false));
00304 }
00305 break;
00306
00307 case WID_GO_BASE_GRF_DROPDOWN:
00308 list = BuiltSetDropDownList<BaseGraphics>(selected_index);
00309 break;
00310
00311 case WID_GO_BASE_SFX_DROPDOWN:
00312 list = BuiltSetDropDownList<BaseSounds>(selected_index);
00313 break;
00314
00315 case WID_GO_BASE_MUSIC_DROPDOWN:
00316 list = BuiltSetDropDownList<BaseMusic>(selected_index);
00317 break;
00318
00319 default:
00320 return NULL;
00321 }
00322
00323 return list;
00324 }
00325
00326 virtual void SetStringParameters(int widget) const
00327 {
00328 switch (widget) {
00329 case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
00330 case WID_GO_DISTANCE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL + this->opt->locale.units); break;
00331 case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
00332 case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
00333 case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
00334 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
00335 case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
00336 case WID_GO_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
00337 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
00338 case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
00339 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
00340 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
00341 case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
00342 }
00343 }
00344
00345 virtual void DrawWidget(const Rect &r, int widget) const
00346 {
00347 switch (widget) {
00348 case WID_GO_BASE_GRF_DESCRIPTION:
00349 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00350 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00351 break;
00352
00353 case WID_GO_BASE_SFX_DESCRIPTION:
00354 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00355 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00356 break;
00357
00358 case WID_GO_BASE_MUSIC_DESCRIPTION:
00359 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00360 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00361 break;
00362 }
00363 }
00364
00365 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00366 {
00367 switch (widget) {
00368 case WID_GO_BASE_GRF_DESCRIPTION:
00369
00370 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00371 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00372 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00373 }
00374 break;
00375
00376 case WID_GO_BASE_GRF_STATUS:
00377
00378 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00379 uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
00380 if (invalid_files == 0) continue;
00381
00382 SetDParam(0, invalid_files);
00383 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
00384 }
00385 break;
00386
00387 case WID_GO_BASE_SFX_DESCRIPTION:
00388
00389 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
00390 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00391 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00392 }
00393 break;
00394
00395 case WID_GO_BASE_MUSIC_DESCRIPTION:
00396
00397 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00398 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00399 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00400 }
00401 break;
00402
00403 case WID_GO_BASE_MUSIC_STATUS:
00404
00405 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00406 uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
00407 if (invalid_files == 0) continue;
00408
00409 SetDParam(0, invalid_files);
00410 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
00411 }
00412 break;
00413
00414 default: {
00415 int selected;
00416 DropDownList *list = this->BuildDropDownList(widget, &selected);
00417 if (list != NULL) {
00418
00419 for (DropDownList::iterator it = list->begin(); it != list->end(); it++) {
00420 static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
00421 Dimension string_dim;
00422 int width = (*it)->Width();
00423 string_dim.width = width + extra.width;
00424 string_dim.height = (*it)->Height(width) + extra.height;
00425 *size = maxdim(*size, string_dim);
00426 delete *it;
00427 }
00428 delete list;
00429 }
00430 }
00431 }
00432 }
00433
00434 virtual void OnClick(Point pt, int widget, int click_count)
00435 {
00436 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
00437 if (BaseGraphics::GetUsedSet() == NULL) return;
00438
00439 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
00440 return;
00441 }
00442 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
00443 if (BaseSounds::GetUsedSet() == NULL) return;
00444
00445 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
00446 return;
00447 }
00448 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
00449 if (BaseMusic::GetUsedSet() == NULL) return;
00450
00451 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
00452 return;
00453 }
00454 switch (widget) {
00455 case WID_GO_FULLSCREEN_BUTTON:
00456
00457 if (!ToggleFullScreen(!_fullscreen)) {
00458 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
00459 }
00460 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00461 this->SetDirty();
00462 break;
00463
00464 default: {
00465 int selected;
00466 DropDownList *list = this->BuildDropDownList(widget, &selected);
00467 if (list != NULL) {
00468 ShowDropDownList(this, list, selected, widget);
00469 }
00470 break;
00471 }
00472 }
00473 }
00474
00480 template <class T>
00481 void SetMediaSet(int index)
00482 {
00483 if (_game_mode == GM_MENU) {
00484 const char *name = T::GetSet(index)->name;
00485
00486 free(T::ini_set);
00487 T::ini_set = strdup(name);
00488
00489 T::SetSet(name);
00490 this->reload = true;
00491 this->InvalidateData();
00492 }
00493 }
00494
00495 virtual void OnDropdownSelect(int widget, int index)
00496 {
00497 switch (widget) {
00498 case WID_GO_CURRENCY_DROPDOWN:
00499 if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
00500 this->opt->locale.currency = index;
00501 ReInitAllWindows();
00502 break;
00503
00504 case WID_GO_DISTANCE_DROPDOWN:
00505 this->opt->locale.units = index;
00506 MarkWholeScreenDirty();
00507 break;
00508
00509 case WID_GO_ROADSIDE_DROPDOWN:
00510 if (this->opt->vehicle.road_side != index) {
00511 uint i;
00512 if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
00513 SetSettingValue(i, index);
00514 MarkWholeScreenDirty();
00515 }
00516 break;
00517
00518 case WID_GO_TOWNNAME_DROPDOWN:
00519 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
00520 this->opt->game_creation.town_name = index;
00521 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00522 }
00523 break;
00524
00525 case WID_GO_AUTOSAVE_DROPDOWN:
00526 _settings_client.gui.autosave = index;
00527 this->SetDirty();
00528 break;
00529
00530 case WID_GO_LANG_DROPDOWN:
00531 ReadLanguagePack(&_languages[index]);
00532 DeleteWindowByClass(WC_QUERY_STRING);
00533 CheckForMissingGlyphs();
00534 UpdateAllVirtCoords();
00535 ReInitAllWindows();
00536 break;
00537
00538 case WID_GO_RESOLUTION_DROPDOWN:
00539 if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
00540 this->SetDirty();
00541 }
00542 break;
00543
00544 case WID_GO_SCREENSHOT_DROPDOWN:
00545 SetScreenshotFormat(index);
00546 this->SetDirty();
00547 break;
00548
00549 case WID_GO_BASE_GRF_DROPDOWN:
00550 this->SetMediaSet<BaseGraphics>(index);
00551 break;
00552
00553 case WID_GO_BASE_SFX_DROPDOWN:
00554 this->SetMediaSet<BaseSounds>(index);
00555 break;
00556
00557 case WID_GO_BASE_MUSIC_DROPDOWN:
00558 this->SetMediaSet<BaseMusic>(index);
00559 break;
00560 }
00561 }
00562
00568 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00569 {
00570 if (!gui_scope) return;
00571 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00572
00573 bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
00574 this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
00575
00576 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
00577 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
00578 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
00579 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
00580 }
00581
00582 missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
00583 this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
00584 }
00585 };
00586
00587 static const NWidgetPart _nested_game_options_widgets[] = {
00588 NWidget(NWID_HORIZONTAL),
00589 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00590 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00591 EndContainer(),
00592 NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
00593 NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
00594 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00595 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
00596 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),
00597 EndContainer(),
00598 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
00599 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),
00600 EndContainer(),
00601 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
00602 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),
00603 EndContainer(),
00604 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
00605 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),
00606 NWidget(NWID_HORIZONTAL),
00607 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
00608 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
00609 EndContainer(),
00610 EndContainer(),
00611 EndContainer(),
00612
00613 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00614 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_MEASURING_UNITS_FRAME, STR_NULL),
00615 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),
00616 EndContainer(),
00617 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
00618 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),
00619 EndContainer(),
00620 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
00621 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),
00622 EndContainer(),
00623 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT, STR_NULL),
00624 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),
00625 EndContainer(),
00626 NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
00627 EndContainer(),
00628 EndContainer(),
00629
00630 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
00631 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00632 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
00633 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00634 EndContainer(),
00635 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),
00636 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00637 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),
00638 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),
00639 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),
00640 EndContainer(),
00641 EndContainer(),
00642
00643 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
00644 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00645 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
00646 NWidget(NWID_SPACER), SetFill(1, 0),
00647 EndContainer(),
00648 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),
00649 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00650 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),
00651 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),
00652 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),
00653 EndContainer(),
00654 EndContainer(),
00655
00656 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
00657 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00658 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
00659 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00660 EndContainer(),
00661 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),
00662 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00663 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),
00664 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),
00665 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),
00666 EndContainer(),
00667 EndContainer(),
00668 EndContainer(),
00669 };
00670
00671 static const WindowDesc _game_options_desc(
00672 WDP_CENTER, 0, 0,
00673 WC_GAME_OPTIONS, WC_NONE,
00674 0,
00675 _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
00676 );
00677
00679 void ShowGameOptions()
00680 {
00681 DeleteWindowByClass(WC_GAME_OPTIONS);
00682 new GameOptionsWindow(&_game_options_desc);
00683 }
00684
00685 static int SETTING_HEIGHT = 11;
00686 static const int LEVEL_WIDTH = 15;
00687
00692 enum SettingEntryFlags {
00693 SEF_LEFT_DEPRESSED = 0x01,
00694 SEF_RIGHT_DEPRESSED = 0x02,
00695 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED),
00696
00697 SEF_LAST_FIELD = 0x04,
00698 SEF_FILTERED = 0x08,
00699
00700
00701 SEF_SETTING_KIND = 0x10,
00702 SEF_SUBTREE_KIND = 0x20,
00703 SEF_KIND_MASK = (SEF_SETTING_KIND | SEF_SUBTREE_KIND),
00704 };
00705
00706 struct SettingsPage;
00707
00709 struct SettingEntrySubtree {
00710 SettingsPage *page;
00711 bool folded;
00712 StringID title;
00713 };
00714
00716 struct SettingEntrySetting {
00717 const char *name;
00718 const SettingDesc *setting;
00719 uint index;
00720 };
00721
00723 enum RestrictionMode {
00724 RM_BASIC,
00725 RM_ADVANCED,
00726 RM_ALL,
00727 RM_CHANGED_AGAINST_DEFAULT,
00728 RM_CHANGED_AGAINST_NEW,
00729 RM_END,
00730 };
00731
00733 struct SettingFilter {
00734 StringFilter string;
00735 RestrictionMode mode;
00736 SettingType type;
00737 };
00738
00740 struct SettingEntry {
00741 byte flags;
00742 byte level;
00743 union {
00744 SettingEntrySetting entry;
00745 SettingEntrySubtree sub;
00746 } d;
00747
00748 SettingEntry(const char *nm);
00749 SettingEntry(SettingsPage *sub, StringID title);
00750
00751 void Init(byte level);
00752 void FoldAll();
00753 void UnFoldAll();
00754 void SetButtons(byte new_val);
00755
00760 void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
00761
00762 uint Length() const;
00763 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
00764 bool IsVisible(const SettingEntry *item) const;
00765 SettingEntry *FindEntry(uint row, uint *cur_row);
00766 uint GetMaxHelpHeight(int maxw);
00767
00768 bool IsFiltered() const;
00769 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
00770
00771 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, SettingEntry *selected);
00772
00777 inline StringID GetHelpText()
00778 {
00779 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
00780 return this->d.entry.setting->desc.str_help;
00781 }
00782
00783 void SetValueDParams(uint first_param, int32 value);
00784
00785 private:
00786 void DrawSetting(GameSettings *settings_ptr, int x, int y, int max_x, int state, bool highlight);
00787 bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
00788 };
00789
00791 struct SettingsPage {
00792 SettingEntry *entries;
00793 byte num;
00794
00795 void Init(byte level = 0);
00796 void FoldAll();
00797 void UnFoldAll();
00798
00799 uint Length() const;
00800 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
00801 bool IsVisible(const SettingEntry *item) const;
00802 SettingEntry *FindEntry(uint row, uint *cur_row) const;
00803 uint GetMaxHelpHeight(int maxw);
00804
00805 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
00806
00807 uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, SettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
00808 };
00809
00810
00811
00812
00817 SettingEntry::SettingEntry(const char *nm)
00818 {
00819 this->flags = SEF_SETTING_KIND;
00820 this->level = 0;
00821 this->d.entry.name = nm;
00822 this->d.entry.setting = NULL;
00823 this->d.entry.index = 0;
00824 }
00825
00831 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
00832 {
00833 this->flags = SEF_SUBTREE_KIND;
00834 this->level = 0;
00835 this->d.sub.page = sub;
00836 this->d.sub.folded = true;
00837 this->d.sub.title = title;
00838 }
00839
00844 void SettingEntry::Init(byte level)
00845 {
00846 this->level = level;
00847
00848 switch (this->flags & SEF_KIND_MASK) {
00849 case SEF_SETTING_KIND:
00850 this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
00851 assert(this->d.entry.setting != NULL);
00852 break;
00853 case SEF_SUBTREE_KIND:
00854 this->d.sub.page->Init(level + 1);
00855 break;
00856 default: NOT_REACHED();
00857 }
00858 }
00859
00861 void SettingEntry::FoldAll()
00862 {
00863 if (this->IsFiltered()) return;
00864 switch (this->flags & SEF_KIND_MASK) {
00865 case SEF_SETTING_KIND:
00866 break;
00867
00868 case SEF_SUBTREE_KIND:
00869 this->d.sub.folded = true;
00870 this->d.sub.page->FoldAll();
00871 break;
00872
00873 default: NOT_REACHED();
00874 }
00875 }
00876
00878 void SettingEntry::UnFoldAll()
00879 {
00880 if (this->IsFiltered()) return;
00881 switch (this->flags & SEF_KIND_MASK) {
00882 case SEF_SETTING_KIND:
00883 break;
00884
00885 case SEF_SUBTREE_KIND:
00886 this->d.sub.folded = false;
00887 this->d.sub.page->UnFoldAll();
00888 break;
00889
00890 default: NOT_REACHED();
00891 }
00892 }
00893
00899 void SettingEntry::GetFoldingState(bool &all_folded, bool &all_unfolded) const
00900 {
00901 if (this->IsFiltered()) return;
00902 switch (this->flags & SEF_KIND_MASK) {
00903 case SEF_SETTING_KIND:
00904 break;
00905
00906 case SEF_SUBTREE_KIND:
00907 if (this->d.sub.folded) {
00908 all_unfolded = false;
00909 } else {
00910 all_folded = false;
00911 }
00912 this->d.sub.page->GetFoldingState(all_folded, all_unfolded);
00913 break;
00914
00915 default: NOT_REACHED();
00916 }
00917 }
00918
00925 bool SettingEntry::IsVisible(const SettingEntry *item) const
00926 {
00927 if (this->IsFiltered()) return false;
00928 if (this == item) return true;
00929
00930 switch (this->flags & SEF_KIND_MASK) {
00931 case SEF_SETTING_KIND:
00932 return false;
00933
00934 case SEF_SUBTREE_KIND:
00935 return !this->d.sub.folded && this->d.sub.page->IsVisible(item);
00936
00937 default: NOT_REACHED();
00938 }
00939 }
00940
00946 void SettingEntry::SetButtons(byte new_val)
00947 {
00948 assert((new_val & ~SEF_BUTTONS_MASK) == 0);
00949 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
00950 }
00951
00953 uint SettingEntry::Length() const
00954 {
00955 if (this->IsFiltered()) return 0;
00956 switch (this->flags & SEF_KIND_MASK) {
00957 case SEF_SETTING_KIND:
00958 return 1;
00959 case SEF_SUBTREE_KIND:
00960 if (this->d.sub.folded) return 1;
00961
00962 return 1 + this->d.sub.page->Length();
00963 default: NOT_REACHED();
00964 }
00965 }
00966
00973 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
00974 {
00975 if (this->IsFiltered()) return NULL;
00976 if (row_num == *cur_row) return this;
00977
00978 switch (this->flags & SEF_KIND_MASK) {
00979 case SEF_SETTING_KIND:
00980 (*cur_row)++;
00981 break;
00982 case SEF_SUBTREE_KIND:
00983 (*cur_row)++;
00984 if (this->d.sub.folded) {
00985 break;
00986 }
00987
00988
00989 return this->d.sub.page->FindEntry(row_num, cur_row);
00990 default: NOT_REACHED();
00991 }
00992 return NULL;
00993 }
00994
01000 uint SettingEntry::GetMaxHelpHeight(int maxw)
01001 {
01002 switch (this->flags & SEF_KIND_MASK) {
01003 case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw);
01004 case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw);
01005 default: NOT_REACHED();
01006 }
01007 }
01008
01013 bool SettingEntry::IsFiltered() const
01014 {
01015 return (this->flags & SEF_FILTERED) != 0;
01016 }
01017
01023 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
01024 {
01025
01026 if (mode == RM_ALL) return true;
01027
01028 GameSettings *settings_ptr = &GetGameSettings();
01029 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01030 const SettingDesc *sd = this->d.entry.setting;
01031
01032 if (mode == RM_BASIC) return (this->d.entry.setting->desc.cat & SC_BASIC_LIST) != 0;
01033 if (mode == RM_ADVANCED) return (this->d.entry.setting->desc.cat & SC_ADVANCED_LIST) != 0;
01034
01035
01036 const void *var = ResolveVariableAddress(settings_ptr, sd);
01037 int64 current_value = ReadValue(var, sd->save.conv);
01038
01039 int64 filter_value;
01040
01041 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
01042
01043
01044
01045 filter_value = ReadValue(&sd->desc.def, sd->save.conv);
01046 } else {
01047 assert(mode == RM_CHANGED_AGAINST_NEW);
01048
01049
01050
01051
01052 assert(settings_ptr != &_settings_newgame);
01053
01054
01055 var = ResolveVariableAddress(&_settings_newgame, sd);
01056 filter_value = ReadValue(var, sd->save.conv);
01057 }
01058
01059 return current_value != filter_value;
01060 }
01061
01068 bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
01069 {
01070 CLRBITS(this->flags, SEF_FILTERED);
01071
01072 bool visible = true;
01073 switch (this->flags & SEF_KIND_MASK) {
01074 case SEF_SETTING_KIND: {
01075 const SettingDesc *sd = this->d.entry.setting;
01076 if (!force_visible && !filter.string.IsEmpty()) {
01077
01078 filter.string.ResetState();
01079
01080 const SettingDescBase *sdb = &sd->desc;
01081
01082 SetDParam(0, STR_EMPTY);
01083 filter.string.AddLine(sdb->str);
01084 filter.string.AddLine(this->GetHelpText());
01085
01086 visible = filter.string.GetState();
01087 }
01088 if (filter.type != ST_ALL) visible = visible && sd->GetType() == filter.type;
01089 visible = visible && this->IsVisibleByRestrictionMode(filter.mode);
01090 break;
01091 }
01092 case SEF_SUBTREE_KIND: {
01093 if (!force_visible && !filter.string.IsEmpty()) {
01094 filter.string.ResetState();
01095 filter.string.AddLine(this->d.sub.title);
01096 force_visible = filter.string.GetState();
01097 }
01098 visible = this->d.sub.page->UpdateFilterState(filter, force_visible);
01099 break;
01100 }
01101 default: NOT_REACHED();
01102 }
01103
01104 if (!visible) SETBITS(this->flags, SEF_FILTERED);
01105 return visible;
01106 }
01107
01108
01109
01137 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, SettingEntry *selected)
01138 {
01139 if (this->IsFiltered()) return cur_row;
01140 if (cur_row >= max_row) return cur_row;
01141
01142 bool rtl = _current_text_dir == TD_RTL;
01143 int offset = rtl ? -4 : 4;
01144 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
01145
01146 int x = rtl ? right : left;
01147 int y = base_y;
01148 if (cur_row >= first_row) {
01149 int colour = _colour_gradient[COLOUR_ORANGE][4];
01150 y = base_y + (cur_row - first_row) * SETTING_HEIGHT;
01151
01152
01153 for (uint lvl = 0; lvl < this->level; lvl++) {
01154 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
01155 x += level_width;
01156 }
01157
01158 int halfway_y = y + SETTING_HEIGHT / 2;
01159 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
01160 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
01161
01162 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
01163 x += level_width;
01164 }
01165
01166 switch (this->flags & SEF_KIND_MASK) {
01167 case SEF_SETTING_KIND:
01168 if (cur_row >= first_row) {
01169 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK,
01170 this == selected);
01171 }
01172 cur_row++;
01173 break;
01174 case SEF_SUBTREE_KIND:
01175 if (cur_row >= first_row) {
01176 DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
01177 DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
01178 }
01179 cur_row++;
01180 if (!this->d.sub.folded) {
01181 if (this->flags & SEF_LAST_FIELD) {
01182 assert(this->level < sizeof(parent_last));
01183 SetBit(parent_last, this->level);
01184 }
01185
01186 cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, selected, cur_row, parent_last);
01187 }
01188 break;
01189 default: NOT_REACHED();
01190 }
01191 return cur_row;
01192 }
01193
01194 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
01195 {
01196 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01197 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
01198 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
01199 } else {
01200 return GetVariableAddress(&_settings_client.company, &sd->save);
01201 }
01202 } else {
01203 return GetVariableAddress(settings_ptr, &sd->save);
01204 }
01205 }
01206
01212 void SettingEntry::SetValueDParams(uint first_param, int32 value)
01213 {
01214 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01215 const SettingDescBase *sdb = &this->d.entry.setting->desc;
01216 if (sdb->cmd == SDT_BOOLX) {
01217 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
01218 } else {
01219 if ((sdb->flags & SGF_MULTISTRING) != 0) {
01220 SetDParam(first_param++, sdb->str_val - sdb->min + value);
01221 } else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
01222 SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
01223 value = abs(value);
01224 } else {
01225 SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
01226 }
01227 SetDParam(first_param++, value);
01228 }
01229 }
01230
01240 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, int state, bool highlight)
01241 {
01242 const SettingDesc *sd = this->d.entry.setting;
01243 const SettingDescBase *sdb = &sd->desc;
01244 const void *var = ResolveVariableAddress(settings_ptr, sd);
01245
01246 bool rtl = _current_text_dir == TD_RTL;
01247 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
01248 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
01249 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
01250 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
01251
01252
01253 bool editable = sd->IsEditable();
01254
01255 SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
01256 int32 value = (int32)ReadValue(var, sd->save.conv);
01257 if (sdb->cmd == SDT_BOOLX) {
01258
01259 DrawBoolButton(buttons_left, button_y, value != 0, editable);
01260 } else if ((sdb->flags & SGF_MULTISTRING) != 0) {
01261
01262 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
01263 } else {
01264
01265 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
01266 editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
01267 }
01268 this->SetValueDParams(1, value);
01269 DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
01270 }
01271
01272
01273
01274
01279 void SettingsPage::Init(byte level)
01280 {
01281 for (uint field = 0; field < this->num; field++) {
01282 this->entries[field].Init(level);
01283 }
01284 }
01285
01287 void SettingsPage::FoldAll()
01288 {
01289 for (uint field = 0; field < this->num; field++) {
01290 this->entries[field].FoldAll();
01291 }
01292 }
01293
01295 void SettingsPage::UnFoldAll()
01296 {
01297 for (uint field = 0; field < this->num; field++) {
01298 this->entries[field].UnFoldAll();
01299 }
01300 }
01301
01307 void SettingsPage::GetFoldingState(bool &all_folded, bool &all_unfolded) const
01308 {
01309 for (uint field = 0; field < this->num; field++) {
01310 this->entries[field].GetFoldingState(all_folded, all_unfolded);
01311 }
01312 }
01313
01320 bool SettingsPage::UpdateFilterState(SettingFilter &filter, bool force_visible)
01321 {
01322 bool visible = false;
01323 bool first_visible = true;
01324 for (int field = this->num - 1; field >= 0; field--) {
01325 visible |= this->entries[field].UpdateFilterState(filter, force_visible);
01326 this->entries[field].SetLastField(first_visible);
01327 if (visible && first_visible) first_visible = false;
01328 }
01329 return visible;
01330 }
01331
01332
01339 bool SettingsPage::IsVisible(const SettingEntry *item) const
01340 {
01341 for (uint field = 0; field < this->num; field++) {
01342 if (this->entries[field].IsVisible(item)) return true;
01343 }
01344 return false;
01345 }
01346
01348 uint SettingsPage::Length() const
01349 {
01350 uint length = 0;
01351 for (uint field = 0; field < this->num; field++) {
01352 length += this->entries[field].Length();
01353 }
01354 return length;
01355 }
01356
01363 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
01364 {
01365 SettingEntry *pe = NULL;
01366
01367 for (uint field = 0; field < this->num; field++) {
01368 pe = this->entries[field].FindEntry(row_num, cur_row);
01369 if (pe != NULL) {
01370 break;
01371 }
01372 }
01373 return pe;
01374 }
01375
01381 uint SettingsPage::GetMaxHelpHeight(int maxw)
01382 {
01383 uint biggest = 0;
01384 for (uint field = 0; field < this->num; field++) {
01385 biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw));
01386 }
01387 return biggest;
01388 }
01389
01408 uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, SettingEntry *selected, uint cur_row, uint parent_last) const
01409 {
01410 if (cur_row >= max_row) return cur_row;
01411
01412 for (uint i = 0; i < this->num; i++) {
01413 cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last, selected);
01414 if (cur_row >= max_row) {
01415 break;
01416 }
01417 }
01418 return cur_row;
01419 }
01420
01421
01422 static SettingEntry _settings_ui_display[] = {
01423 SettingEntry("gui.date_format_in_default_names"),
01424 SettingEntry("gui.population_in_label"),
01425 SettingEntry("gui.measure_tooltip"),
01426 SettingEntry("gui.loading_indicators"),
01427 SettingEntry("gui.liveries"),
01428 SettingEntry("gui.show_track_reservation"),
01429 SettingEntry("gui.expenses_layout"),
01430 SettingEntry("gui.smallmap_land_colour"),
01431 SettingEntry("gui.zoom_min"),
01432 SettingEntry("gui.zoom_max"),
01433 SettingEntry("gui.graph_line_thickness"),
01434 };
01436 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
01437
01438 static SettingEntry _settings_ui_interaction[] = {
01439 SettingEntry("gui.window_snap_radius"),
01440 SettingEntry("gui.window_soft_limit"),
01441 SettingEntry("gui.link_terraform_toolbar"),
01442 SettingEntry("gui.prefer_teamchat"),
01443 SettingEntry("gui.auto_scrolling"),
01444 SettingEntry("gui.reverse_scroll"),
01445 SettingEntry("gui.smooth_scroll"),
01446 SettingEntry("gui.left_mouse_btn_scrolling"),
01447
01448
01449
01450 SettingEntry("gui.scrollwheel_scrolling"),
01451 SettingEntry("gui.scrollwheel_multiplier"),
01452 SettingEntry("gui.osk_activation"),
01453 #ifdef __APPLE__
01454
01455 SettingEntry("gui.right_mouse_btn_emulation"),
01456 #endif
01457 };
01459 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
01460
01461 static SettingEntry _settings_ui_sound[] = {
01462 SettingEntry("sound.click_beep"),
01463 SettingEntry("sound.confirm"),
01464 SettingEntry("sound.news_ticker"),
01465 SettingEntry("sound.news_full"),
01466 SettingEntry("sound.new_year"),
01467 SettingEntry("sound.disaster"),
01468 SettingEntry("sound.vehicle"),
01469 SettingEntry("sound.ambient"),
01470 };
01472 static SettingsPage _settings_ui_sound_page = {_settings_ui_sound, lengthof(_settings_ui_sound)};
01473
01474 static SettingEntry _settings_ui_news[] = {
01475 SettingEntry("news_display.arrival_player"),
01476 SettingEntry("news_display.arrival_other"),
01477 SettingEntry("news_display.accident"),
01478 SettingEntry("news_display.company_info"),
01479 SettingEntry("news_display.open"),
01480 SettingEntry("news_display.close"),
01481 SettingEntry("news_display.economy"),
01482 SettingEntry("news_display.production_player"),
01483 SettingEntry("news_display.production_other"),
01484 SettingEntry("news_display.production_nobody"),
01485 SettingEntry("news_display.advice"),
01486 SettingEntry("news_display.new_vehicles"),
01487 SettingEntry("news_display.acceptance"),
01488 SettingEntry("news_display.subsidies"),
01489 SettingEntry("news_display.general"),
01490 SettingEntry("gui.coloured_news_year"),
01491 };
01493 static SettingsPage _settings_ui_news_page = {_settings_ui_news, lengthof(_settings_ui_news)};
01494
01495 static SettingEntry _settings_ui[] = {
01496 SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
01497 SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
01498 SettingEntry(&_settings_ui_sound_page, STR_CONFIG_SETTING_SOUND),
01499 SettingEntry(&_settings_ui_news_page, STR_CONFIG_SETTING_NEWS),
01500 SettingEntry("gui.show_finances"),
01501 SettingEntry("gui.errmsg_duration"),
01502 SettingEntry("gui.hover_delay"),
01503 SettingEntry("gui.toolbar_pos"),
01504 SettingEntry("gui.statusbar_pos"),
01505 SettingEntry("gui.newgrf_default_palette"),
01506 SettingEntry("gui.pause_on_newgame"),
01507 SettingEntry("gui.advanced_vehicle_list"),
01508 SettingEntry("gui.timetable_in_ticks"),
01509 SettingEntry("gui.timetable_arrival_departure"),
01510 SettingEntry("gui.quick_goto"),
01511 SettingEntry("gui.default_rail_type"),
01512 SettingEntry("gui.disable_unsuitable_building"),
01513 SettingEntry("gui.persistent_buildingtools"),
01514 };
01516 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
01517
01518 static SettingEntry _settings_construction_signals[] = {
01519 SettingEntry("construction.train_signal_side"),
01520 SettingEntry("gui.enable_signal_gui"),
01521 SettingEntry("gui.drag_signals_fixed_distance"),
01522 SettingEntry("gui.semaphore_build_before"),
01523 SettingEntry("gui.default_signal_type"),
01524 SettingEntry("gui.cycle_signal_types"),
01525 };
01527 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
01528
01529 static SettingEntry _settings_construction[] = {
01530 SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
01531 SettingEntry("construction.build_on_slopes"),
01532 SettingEntry("construction.autoslope"),
01533 SettingEntry("construction.extra_dynamite"),
01534 SettingEntry("construction.max_bridge_length"),
01535 SettingEntry("construction.max_tunnel_length"),
01536 SettingEntry("station.never_expire_airports"),
01537 SettingEntry("construction.freeform_edges"),
01538 SettingEntry("construction.extra_tree_placement"),
01539 SettingEntry("construction.command_pause_level"),
01540 };
01542 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
01543
01544 static SettingEntry _settings_stations_cargo[] = {
01545 SettingEntry("order.improved_load"),
01546 SettingEntry("order.gradual_loading"),
01547 SettingEntry("order.selectgoods"),
01548 };
01550 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
01551
01552 static SettingEntry _settings_stations[] = {
01553 SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
01554 SettingEntry("station.adjacent_stations"),
01555 SettingEntry("station.distant_join_stations"),
01556 SettingEntry("station.station_spread"),
01557 SettingEntry("economy.station_noise_level"),
01558 SettingEntry("station.modified_catchment"),
01559 SettingEntry("construction.road_stop_on_town_road"),
01560 SettingEntry("construction.road_stop_on_competitor_road"),
01561 };
01563 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
01564
01565 static SettingEntry _settings_economy_towns[] = {
01566 SettingEntry("difficulty.town_council_tolerance"),
01567 SettingEntry("economy.bribe"),
01568 SettingEntry("economy.exclusive_rights"),
01569 SettingEntry("economy.fund_roads"),
01570 SettingEntry("economy.fund_buildings"),
01571 SettingEntry("economy.town_layout"),
01572 SettingEntry("economy.allow_town_roads"),
01573 SettingEntry("economy.allow_town_level_crossings"),
01574 SettingEntry("economy.found_town"),
01575 SettingEntry("economy.mod_road_rebuild"),
01576 SettingEntry("economy.town_growth_rate"),
01577 SettingEntry("economy.larger_towns"),
01578 SettingEntry("economy.initial_city_size"),
01579 };
01581 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
01582
01583 static SettingEntry _settings_economy_industries[] = {
01584 SettingEntry("construction.raw_industry_construction"),
01585 SettingEntry("construction.industry_platform"),
01586 SettingEntry("economy.multiple_industry_per_town"),
01587 SettingEntry("game_creation.oil_refinery_limit"),
01588 };
01590 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
01591
01592
01593 static SettingEntry _settings_economy[] = {
01594 SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
01595 SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
01596 SettingEntry("economy.inflation"),
01597 SettingEntry("difficulty.initial_interest"),
01598 SettingEntry("difficulty.max_loan"),
01599 SettingEntry("difficulty.subsidy_multiplier"),
01600 SettingEntry("difficulty.economy"),
01601 SettingEntry("economy.smooth_economy"),
01602 SettingEntry("economy.feeder_payment_share"),
01603 SettingEntry("economy.infrastructure_maintenance"),
01604 SettingEntry("difficulty.vehicle_costs"),
01605 SettingEntry("difficulty.construction_cost"),
01606 SettingEntry("difficulty.disasters"),
01607 };
01609 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
01610
01611 static SettingEntry _settings_linkgraph[] = {
01612 SettingEntry("linkgraph.recalc_interval"),
01613 SettingEntry("linkgraph.distribution_pax"),
01614 SettingEntry("linkgraph.distribution_mail"),
01615 SettingEntry("linkgraph.distribution_armoured"),
01616 SettingEntry("linkgraph.distribution_default"),
01617 SettingEntry("linkgraph.accuracy"),
01618 SettingEntry("linkgraph.demand_distance"),
01619 SettingEntry("linkgraph.demand_size"),
01620 SettingEntry("linkgraph.short_path_saturation"),
01621 };
01623 static SettingsPage _settings_linkgraph_page = {_settings_linkgraph, lengthof(_settings_linkgraph)};
01624
01625 static SettingEntry _settings_ai_npc[] = {
01626 SettingEntry("script.settings_profile"),
01627 SettingEntry("script.script_max_opcode_till_suspend"),
01628 SettingEntry("difficulty.competitor_speed"),
01629 SettingEntry("ai.ai_in_multiplayer"),
01630 SettingEntry("ai.ai_disable_veh_train"),
01631 SettingEntry("ai.ai_disable_veh_roadveh"),
01632 SettingEntry("ai.ai_disable_veh_aircraft"),
01633 SettingEntry("ai.ai_disable_veh_ship"),
01634 };
01636 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
01637
01638 static SettingEntry _settings_ai[] = {
01639 SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
01640 SettingEntry("economy.give_money"),
01641 SettingEntry("economy.allow_shares"),
01642 };
01644 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
01645
01646 static SettingEntry _settings_vehicles_routing[] = {
01647 SettingEntry("pf.pathfinder_for_trains"),
01648 SettingEntry("pf.forbid_90_deg"),
01649 SettingEntry("pf.pathfinder_for_roadvehs"),
01650 SettingEntry("pf.roadveh_queue"),
01651 SettingEntry("pf.pathfinder_for_ships"),
01652 };
01654 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
01655
01656 static SettingEntry _settings_vehicles_autorenew[] = {
01657 SettingEntry("company.engine_renew"),
01658 SettingEntry("company.engine_renew_months"),
01659 SettingEntry("company.engine_renew_money"),
01660 };
01662 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
01663
01664 static SettingEntry _settings_vehicles_servicing[] = {
01665 SettingEntry("vehicle.servint_ispercent"),
01666 SettingEntry("vehicle.servint_trains"),
01667 SettingEntry("vehicle.servint_roadveh"),
01668 SettingEntry("vehicle.servint_ships"),
01669 SettingEntry("vehicle.servint_aircraft"),
01670 SettingEntry("difficulty.vehicle_breakdowns"),
01671 SettingEntry("order.no_servicing_if_no_breakdowns"),
01672 SettingEntry("order.serviceathelipad"),
01673 };
01675 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
01676
01677 static SettingEntry _settings_vehicles_trains[] = {
01678 SettingEntry("difficulty.line_reverse_mode"),
01679 SettingEntry("pf.reverse_at_signals"),
01680 SettingEntry("vehicle.train_acceleration_model"),
01681 SettingEntry("vehicle.train_slope_steepness"),
01682 SettingEntry("vehicle.max_train_length"),
01683 SettingEntry("vehicle.wagon_speed_limits"),
01684 SettingEntry("vehicle.disable_elrails"),
01685 SettingEntry("vehicle.freight_trains"),
01686 SettingEntry("gui.stop_location"),
01687 };
01689 static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
01690
01691 static SettingEntry _settings_vehicles[] = {
01692 SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
01693 SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
01694 SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
01695 SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
01696 SettingEntry("gui.new_nonstop"),
01697 SettingEntry("gui.order_review_system"),
01698 SettingEntry("gui.vehicle_income_warn"),
01699 SettingEntry("gui.lost_vehicle_warn"),
01700 SettingEntry("vehicle.never_expire_vehicles"),
01701 SettingEntry("vehicle.max_trains"),
01702 SettingEntry("vehicle.max_roadveh"),
01703 SettingEntry("vehicle.max_aircraft"),
01704 SettingEntry("vehicle.max_ships"),
01705 SettingEntry("vehicle.plane_speed"),
01706 SettingEntry("vehicle.plane_crashes"),
01707 SettingEntry("vehicle.dynamic_engines"),
01708 SettingEntry("vehicle.roadveh_acceleration_model"),
01709 SettingEntry("vehicle.roadveh_slope_steepness"),
01710 SettingEntry("vehicle.smoke_amount"),
01711 };
01713 static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
01714
01715 static SettingEntry _settings_main[] = {
01716 SettingEntry(&_settings_ui_page, STR_CONFIG_SETTING_GUI),
01717 SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
01718 SettingEntry(&_settings_vehicles_page, STR_CONFIG_SETTING_VEHICLES),
01719 SettingEntry(&_settings_stations_page, STR_CONFIG_SETTING_STATIONS),
01720 SettingEntry(&_settings_economy_page, STR_CONFIG_SETTING_ECONOMY),
01721 SettingEntry(&_settings_linkgraph_page, STR_CONFIG_SETTING_LINKGRAPH),
01722 SettingEntry(&_settings_ai_page, STR_CONFIG_SETTING_AI),
01723 };
01724
01726 static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
01727
01728 static const StringID _game_settings_restrict_dropdown[] = {
01729 STR_CONFIG_SETTING_RESTRICT_BASIC,
01730 STR_CONFIG_SETTING_RESTRICT_ADVANCED,
01731 STR_CONFIG_SETTING_RESTRICT_ALL,
01732 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT,
01733 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW,
01734 };
01735 assert_compile(lengthof(_game_settings_restrict_dropdown) == RM_END);
01736
01737 struct GameSettingsWindow : Window {
01738 static const int SETTINGTREE_LEFT_OFFSET = 5;
01739 static const int SETTINGTREE_RIGHT_OFFSET = 5;
01740 static const int SETTINGTREE_TOP_OFFSET = 5;
01741 static const int SETTINGTREE_BOTTOM_OFFSET = 5;
01742
01743 static GameSettings *settings_ptr;
01744
01745 SettingEntry *valuewindow_entry;
01746 SettingEntry *clicked_entry;
01747 SettingEntry *last_clicked;
01748 SettingEntry *valuedropdown_entry;
01749 bool closing_dropdown;
01750
01751 SettingFilter filter;
01752 QueryString filter_editbox;
01753 bool manually_changed_folding;
01754
01755 Scrollbar *vscroll;
01756
01757 GameSettingsWindow(const WindowDesc *desc) : filter_editbox(50)
01758 {
01759 static bool first_time = true;
01760
01761 filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
01762 filter.type = ST_ALL;
01763 settings_ptr = &GetGameSettings();
01764
01765
01766 if (first_time) {
01767 _settings_main_page.Init();
01768 first_time = false;
01769 } else {
01770 _settings_main_page.FoldAll();
01771 }
01772
01773 this->valuewindow_entry = NULL;
01774 this->clicked_entry = NULL;
01775 this->last_clicked = NULL;
01776 this->valuedropdown_entry = NULL;
01777 this->closing_dropdown = false;
01778 this->manually_changed_folding = false;
01779
01780 this->CreateNestedTree(desc);
01781 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
01782 this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
01783
01784 this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
01785 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
01786 this->SetFocusedWidget(WID_GS_FILTER);
01787
01788 this->InvalidateData();
01789 }
01790
01791 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01792 {
01793 switch (widget) {
01794 case WID_GS_OPTIONSPANEL:
01795 resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
01796 resize->width = 1;
01797
01798 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
01799 break;
01800
01801 case WID_GS_HELP_TEXT: {
01802 static const StringID setting_types[] = {
01803 STR_CONFIG_SETTING_TYPE_CLIENT,
01804 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
01805 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
01806 };
01807 for (uint i = 0; i < lengthof(setting_types); i++) {
01808 SetDParam(0, setting_types[i]);
01809 size->width = max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width);
01810 }
01811 size->height = 2 * FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL +
01812 max(size->height, _settings_main_page.GetMaxHelpHeight(size->width));
01813 break;
01814 }
01815
01816 default:
01817 break;
01818 }
01819 }
01820
01821 virtual void OnPaint()
01822 {
01823 if (this->closing_dropdown) {
01824 this->closing_dropdown = false;
01825 assert(this->valuedropdown_entry != NULL);
01826 this->valuedropdown_entry->SetButtons(0);
01827 this->valuedropdown_entry = NULL;
01828 }
01829 this->DrawWidgets();
01830 }
01831
01832 virtual void SetStringParameters(int widget) const
01833 {
01834 switch (widget) {
01835 case WID_GS_RESTRICT_DROPDOWN:
01836 SetDParam(0, _game_settings_restrict_dropdown[this->filter.mode]);
01837 break;
01838
01839 case WID_GS_TYPE_DROPDOWN:
01840 switch (this->filter.type) {
01841 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME); break;
01842 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME); break;
01843 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT); break;
01844 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL); break;
01845 }
01846 break;
01847 }
01848 }
01849
01850 DropDownList *BuildDropDownList(int widget) const
01851 {
01852 DropDownList *list = NULL;
01853 switch (widget) {
01854 case WID_GS_RESTRICT_DROPDOWN:
01855 list = new DropDownList();
01856
01857 for (int mode = 0; mode != RM_END; mode++) {
01858
01859
01860 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
01861
01862 list->push_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
01863 }
01864 break;
01865
01866 case WID_GS_TYPE_DROPDOWN:
01867 list = new DropDownList();
01868 list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false));
01869 list->push_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false));
01870 list->push_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false));
01871 list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false));
01872 break;
01873 }
01874 return list;
01875 }
01876
01877 virtual void DrawWidget(const Rect &r, int widget) const
01878 {
01879 switch (widget) {
01880 case WID_GS_OPTIONSPANEL:
01881 _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
01882 this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->last_clicked);
01883 break;
01884
01885 case WID_GS_HELP_TEXT:
01886 if (this->last_clicked != NULL) {
01887 const SettingDesc *sd = this->last_clicked->d.entry.setting;
01888
01889 int y = r.top;
01890 switch (sd->GetType()) {
01891 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
01892 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
01893 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
01894 default: NOT_REACHED();
01895 }
01896 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
01897 y += FONT_HEIGHT_NORMAL;
01898
01899 int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
01900 this->last_clicked->SetValueDParams(0, default_value);
01901 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
01902 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
01903
01904 DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
01905 }
01906 break;
01907
01908 default:
01909 break;
01910 }
01911 }
01912
01917 void SetDisplayedHelpText(SettingEntry *pe)
01918 {
01919 if (this->last_clicked != pe) this->SetDirty();
01920 this->last_clicked = pe;
01921 }
01922
01923 virtual void OnClick(Point pt, int widget, int click_count)
01924 {
01925 switch (widget) {
01926 case WID_GS_EXPAND_ALL:
01927 this->manually_changed_folding = true;
01928 _settings_main_page.UnFoldAll();
01929 this->InvalidateData();
01930 break;
01931
01932 case WID_GS_COLLAPSE_ALL:
01933 this->manually_changed_folding = true;
01934 _settings_main_page.FoldAll();
01935 this->InvalidateData();
01936 break;
01937
01938 case WID_GS_RESTRICT_DROPDOWN: {
01939 DropDownList *list = this->BuildDropDownList(widget);
01940 if (list != NULL) {
01941 ShowDropDownList(this, list, this->filter.mode, widget);
01942 }
01943 break;
01944 }
01945
01946 case WID_GS_TYPE_DROPDOWN: {
01947 DropDownList *list = this->BuildDropDownList(widget);
01948 if (list != NULL) {
01949 ShowDropDownList(this, list, this->filter.type, widget);
01950 }
01951 break;
01952 }
01953 }
01954
01955 if (widget != WID_GS_OPTIONSPANEL) return;
01956
01957 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
01958 if (btn == INT_MAX) return;
01959
01960 uint cur_row = 0;
01961 SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
01962
01963 if (pe == NULL) return;
01964
01965 int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;
01966 if (x < 0) return;
01967
01968 if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
01969 this->SetDisplayedHelpText(NULL);
01970 pe->d.sub.folded = !pe->d.sub.folded;
01971
01972 this->manually_changed_folding = true;
01973
01974 this->InvalidateData();
01975 return;
01976 }
01977
01978 assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01979 const SettingDesc *sd = pe->d.entry.setting;
01980
01981
01982 if (!sd->IsEditable()) {
01983 this->SetDisplayedHelpText(pe);
01984 return;
01985 }
01986
01987 const void *var = ResolveVariableAddress(settings_ptr, sd);
01988 int32 value = (int32)ReadValue(var, sd->save.conv);
01989
01990
01991 if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
01992 const SettingDescBase *sdb = &sd->desc;
01993 this->SetDisplayedHelpText(pe);
01994
01995 if (this->valuedropdown_entry == pe) {
01996
01997 HideDropDownMenu(this);
01998 this->closing_dropdown = false;
01999 this->valuedropdown_entry->SetButtons(0);
02000 this->valuedropdown_entry = NULL;
02001 } else {
02002 if (this->valuedropdown_entry != NULL) this->valuedropdown_entry->SetButtons(0);
02003 this->closing_dropdown = false;
02004
02005 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
02006 int rel_y = (pt.y - (int)wid->pos_y - SETTINGTREE_TOP_OFFSET) % wid->resize_y;
02007
02008 Rect wi_rect;
02009 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
02010 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
02011 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
02012 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
02013
02014
02015 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
02016 this->valuedropdown_entry = pe;
02017 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
02018
02019 DropDownList *list = new DropDownList();
02020 for (int i = sdb->min; i <= (int)sdb->max; i++) {
02021 list->push_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
02022 }
02023
02024 ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true);
02025 }
02026 }
02027 this->SetDirty();
02028 } else if (x < SETTING_BUTTON_WIDTH) {
02029 this->SetDisplayedHelpText(pe);
02030 const SettingDescBase *sdb = &sd->desc;
02031 int32 oldvalue = value;
02032
02033 switch (sdb->cmd) {
02034 case SDT_BOOLX: value ^= 1; break;
02035 case SDT_ONEOFMANY:
02036 case SDT_NUMX: {
02037
02038
02039
02040
02041 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
02042 if (step == 0) step = 1;
02043
02044
02045 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
02046 _left_button_clicked = false;
02047 return;
02048 }
02049
02050
02051 if (x >= SETTING_BUTTON_WIDTH / 2) {
02052 value += step;
02053 if (sdb->min < 0) {
02054 assert((int32)sdb->max >= 0);
02055 if (value > (int32)sdb->max) value = (int32)sdb->max;
02056 } else {
02057 if ((uint32)value > sdb->max) value = (int32)sdb->max;
02058 }
02059 if (value < sdb->min) value = sdb->min;
02060 } else {
02061 value -= step;
02062 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
02063 }
02064
02065
02066 if (value != oldvalue) {
02067 if (this->clicked_entry != NULL) {
02068 this->clicked_entry->SetButtons(0);
02069 }
02070 this->clicked_entry = pe;
02071 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
02072 this->SetTimeout();
02073 _left_button_clicked = false;
02074 }
02075 break;
02076 }
02077
02078 default: NOT_REACHED();
02079 }
02080
02081 if (value != oldvalue) {
02082 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02083 SetCompanySetting(pe->d.entry.index, value);
02084 } else {
02085 SetSettingValue(pe->d.entry.index, value);
02086 }
02087 this->SetDirty();
02088 }
02089 } else {
02090
02091 if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
02092
02093 if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
02094
02095 this->valuewindow_entry = pe;
02096 SetDParam(0, value);
02097 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
02098 }
02099 this->SetDisplayedHelpText(pe);
02100 }
02101 }
02102
02103 virtual void OnTimeout()
02104 {
02105 if (this->clicked_entry != NULL) {
02106 this->clicked_entry->SetButtons(0);
02107 this->clicked_entry = NULL;
02108 this->SetDirty();
02109 }
02110 }
02111
02112 virtual void OnQueryTextFinished(char *str)
02113 {
02114
02115 if (str == NULL) return;
02116
02117 assert(this->valuewindow_entry != NULL);
02118 assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
02119 const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
02120
02121 int32 value;
02122 if (!StrEmpty(str)) {
02123 value = atoi(str);
02124
02125
02126 if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
02127 } else {
02128 value = (int32)(size_t)sd->desc.def;
02129 }
02130
02131 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02132 SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
02133 } else {
02134 SetSettingValue(this->valuewindow_entry->d.entry.index, value);
02135 }
02136 this->SetDirty();
02137 }
02138
02139 virtual void OnDropdownSelect(int widget, int index)
02140 {
02141 switch (widget) {
02142 case WID_GS_RESTRICT_DROPDOWN:
02143 this->filter.mode = (RestrictionMode)index;
02144 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
02145 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
02146
02147 if (!this->manually_changed_folding) {
02148
02149 _settings_main_page.UpdateFilterState(this->filter, false);
02150 _settings_main_page.UnFoldAll();
02151 }
02152 } else {
02153
02154 _settings_client.gui.settings_restriction_mode = this->filter.mode;
02155 }
02156 this->InvalidateData();
02157 break;
02158
02159 case WID_GS_TYPE_DROPDOWN:
02160 this->filter.type = (SettingType)index;
02161 this->InvalidateData();
02162 break;
02163
02164 default:
02165 if (widget < 0) {
02166
02167 assert(this->valuedropdown_entry != NULL);
02168 const SettingDesc *sd = this->valuedropdown_entry->d.entry.setting;
02169 assert(sd->desc.flags & SGF_MULTISTRING);
02170
02171 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02172 SetCompanySetting(this->valuedropdown_entry->d.entry.index, index);
02173 } else {
02174 SetSettingValue(this->valuedropdown_entry->d.entry.index, index);
02175 }
02176
02177 this->SetDirty();
02178 }
02179 break;
02180 }
02181 }
02182
02183 virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
02184 {
02185 if (widget >= 0) {
02186
02187
02188
02189
02190 Window::OnDropdownClose(pt, widget, index, instant_close);
02191 } else {
02192
02193
02194
02195
02196 assert(this->valuedropdown_entry != NULL);
02197 this->closing_dropdown = true;
02198 this->SetDirty();
02199 }
02200 }
02201
02202 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
02203 {
02204 if (!gui_scope) return;
02205
02206 _settings_main_page.UpdateFilterState(this->filter, false);
02207
02208 this->vscroll->SetCount(_settings_main_page.Length());
02209
02210 if (this->last_clicked != NULL && !_settings_main_page.IsVisible(this->last_clicked)) {
02211 this->SetDisplayedHelpText(NULL);
02212 }
02213
02214 bool all_folded = true;
02215 bool all_unfolded = true;
02216 _settings_main_page.GetFoldingState(all_folded, all_unfolded);
02217 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
02218 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
02219 }
02220
02221 virtual void OnEditboxChanged(int wid)
02222 {
02223 if (wid == WID_GS_FILTER) {
02224 this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
02225 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
02226
02227
02228 _settings_main_page.UnFoldAll();
02229 }
02230 this->InvalidateData();
02231 }
02232 }
02233
02234 virtual void OnResize()
02235 {
02236 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
02237 }
02238 };
02239
02240 GameSettings *GameSettingsWindow::settings_ptr = NULL;
02241
02242 static const NWidgetPart _nested_settings_selection_widgets[] = {
02243 NWidget(NWID_HORIZONTAL),
02244 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
02245 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02246 EndContainer(),
02247 NWidget(WWT_PANEL, COLOUR_MAUVE),
02248 NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
02249 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
02250 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_LABEL), SetDataTip(STR_CONFIG_SETTING_RESTRICT_LABEL, STR_NULL),
02251 NWidget(NWID_VERTICAL), SetPIP(0, WD_PAR_VSEP_NORMAL, 0),
02252 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_RESTRICT_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_CONFIG_SETTING_RESTRICT_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
02253 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_TYPE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_CONFIG_SETTING_TYPE_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
02254 EndContainer(),
02255 EndContainer(),
02256 NWidget(NWID_HORIZONTAL), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM, 0),
02257 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
02258 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE, STR_NULL),
02259 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_GS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
02260 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
02261 EndContainer(),
02262 EndContainer(),
02263 NWidget(NWID_HORIZONTAL),
02264 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
02265 NWidget(NWID_VERTICAL),
02266 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
02267 EndContainer(),
02268 EndContainer(),
02269 NWidget(WWT_PANEL, COLOUR_MAUVE), SetMinimalSize(400, 40),
02270 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
02271 SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
02272 NWidget(NWID_HORIZONTAL),
02273 NWidget(WWT_PANEL, COLOUR_MAUVE),
02274 NWidget(NWID_HORIZONTAL),
02275 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
02276 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
02277 NWidget(NWID_SPACER, INVALID_COLOUR), SetFill(1, 1), SetResize(1, 0),
02278 EndContainer(),
02279 EndContainer(),
02280 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
02281 EndContainer(),
02282 EndContainer(),
02283 };
02284
02285 static const WindowDesc _settings_selection_desc(
02286 WDP_CENTER, 510, 450,
02287 WC_GAME_OPTIONS, WC_NONE,
02288 0,
02289 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
02290 );
02291
02293 void ShowGameSettings()
02294 {
02295 DeleteWindowByClass(WC_GAME_OPTIONS);
02296 new GameSettingsWindow(&_settings_selection_desc);
02297 }
02298
02299
02309 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
02310 {
02311 int colour = _colour_gradient[button_colour][2];
02312
02313 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
02314 DrawFrameRect(x + SETTING_BUTTON_WIDTH / 2, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
02315 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
02316 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP);
02317
02318
02319 bool rtl = _current_text_dir == TD_RTL;
02320 if (rtl ? !clickable_right : !clickable_left) {
02321 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02322 }
02323 if (rtl ? !clickable_left : !clickable_right) {
02324 GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02325 }
02326 }
02327
02336 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
02337 {
02338 static const char *DOWNARROW = "\xEE\x8A\xAA";
02339
02340 int colour = _colour_gradient[button_colour][2];
02341
02342 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE);
02343 DrawString(x + (state ? 1 : 0), x + SETTING_BUTTON_WIDTH - (state ? 0 : 1), y + (state ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
02344
02345 if (!clickable) {
02346 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02347 }
02348 }
02349
02357 void DrawBoolButton(int x, int y, bool state, bool clickable)
02358 {
02359 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
02360 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
02361 }
02362
02363 struct CustomCurrencyWindow : Window {
02364 int query_widget;
02365
02366 CustomCurrencyWindow(const WindowDesc *desc) : Window()
02367 {
02368 this->InitNested(desc);
02369
02370 SetButtonState();
02371 }
02372
02373 void SetButtonState()
02374 {
02375 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
02376 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
02377 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
02378 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
02379 }
02380
02381 virtual void SetStringParameters(int widget) const
02382 {
02383 switch (widget) {
02384 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
02385 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
02386 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
02387 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
02388 case WID_CC_YEAR:
02389 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
02390 SetDParam(1, _custom_currency.to_euro);
02391 break;
02392
02393 case WID_CC_PREVIEW:
02394 SetDParam(0, 10000);
02395 break;
02396 }
02397 }
02398
02399 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
02400 {
02401 switch (widget) {
02402
02403 case WID_CC_SEPARATOR_EDIT:
02404 case WID_CC_PREFIX_EDIT:
02405 case WID_CC_SUFFIX_EDIT:
02406 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
02407 break;
02408
02409
02410 case WID_CC_RATE:
02411 SetDParam(0, 1);
02412 SetDParam(1, INT32_MAX);
02413 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
02414 break;
02415 }
02416 }
02417
02418 virtual void OnClick(Point pt, int widget, int click_count)
02419 {
02420 int line = 0;
02421 int len = 0;
02422 StringID str = 0;
02423 CharSetFilter afilter = CS_ALPHANUMERAL;
02424
02425 switch (widget) {
02426 case WID_CC_RATE_DOWN:
02427 if (_custom_currency.rate > 1) _custom_currency.rate--;
02428 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
02429 this->EnableWidget(WID_CC_RATE_UP);
02430 break;
02431
02432 case WID_CC_RATE_UP:
02433 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
02434 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
02435 this->EnableWidget(WID_CC_RATE_DOWN);
02436 break;
02437
02438 case WID_CC_RATE:
02439 SetDParam(0, _custom_currency.rate);
02440 str = STR_JUST_INT;
02441 len = 5;
02442 line = WID_CC_RATE;
02443 afilter = CS_NUMERAL;
02444 break;
02445
02446 case WID_CC_SEPARATOR_EDIT:
02447 case WID_CC_SEPARATOR:
02448 SetDParamStr(0, _custom_currency.separator);
02449 str = STR_JUST_RAW_STRING;
02450 len = 1;
02451 line = WID_CC_SEPARATOR;
02452 break;
02453
02454 case WID_CC_PREFIX_EDIT:
02455 case WID_CC_PREFIX:
02456 SetDParamStr(0, _custom_currency.prefix);
02457 str = STR_JUST_RAW_STRING;
02458 len = 12;
02459 line = WID_CC_PREFIX;
02460 break;
02461
02462 case WID_CC_SUFFIX_EDIT:
02463 case WID_CC_SUFFIX:
02464 SetDParamStr(0, _custom_currency.suffix);
02465 str = STR_JUST_RAW_STRING;
02466 len = 12;
02467 line = WID_CC_SUFFIX;
02468 break;
02469
02470 case WID_CC_YEAR_DOWN:
02471 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
02472 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
02473 this->EnableWidget(WID_CC_YEAR_UP);
02474 break;
02475
02476 case WID_CC_YEAR_UP:
02477 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
02478 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
02479 this->EnableWidget(WID_CC_YEAR_DOWN);
02480 break;
02481
02482 case WID_CC_YEAR:
02483 SetDParam(0, _custom_currency.to_euro);
02484 str = STR_JUST_INT;
02485 len = 7;
02486 line = WID_CC_YEAR;
02487 afilter = CS_NUMERAL;
02488 break;
02489 }
02490
02491 if (len != 0) {
02492 this->query_widget = line;
02493 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
02494 }
02495
02496 this->SetTimeout();
02497 this->SetDirty();
02498 }
02499
02500 virtual void OnQueryTextFinished(char *str)
02501 {
02502 if (str == NULL) return;
02503
02504 switch (this->query_widget) {
02505 case WID_CC_RATE:
02506 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
02507 break;
02508
02509 case WID_CC_SEPARATOR:
02510 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
02511 break;
02512
02513 case WID_CC_PREFIX:
02514 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
02515 break;
02516
02517 case WID_CC_SUFFIX:
02518 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
02519 break;
02520
02521 case WID_CC_YEAR: {
02522 int val = atoi(str);
02523
02524 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
02525 break;
02526 }
02527 }
02528 MarkWholeScreenDirty();
02529 SetButtonState();
02530 }
02531
02532 virtual void OnTimeout()
02533 {
02534 this->SetDirty();
02535 }
02536 };
02537
02538 static const NWidgetPart _nested_cust_currency_widgets[] = {
02539 NWidget(NWID_HORIZONTAL),
02540 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
02541 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02542 EndContainer(),
02543 NWidget(WWT_PANEL, COLOUR_GREY),
02544 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
02545 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02546 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
02547 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
02548 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02549 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
02550 EndContainer(),
02551 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02552 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
02553 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02554 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
02555 EndContainer(),
02556 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02557 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
02558 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02559 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
02560 EndContainer(),
02561 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02562 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
02563 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02564 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
02565 EndContainer(),
02566 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02567 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02568 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02569 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02570 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
02571 EndContainer(),
02572 EndContainer(),
02573 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
02574 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
02575 EndContainer(),
02576 };
02577
02578 static const WindowDesc _cust_currency_desc(
02579 WDP_CENTER, 0, 0,
02580 WC_CUSTOM_CURRENCY, WC_NONE,
02581 0,
02582 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
02583 );
02584
02586 static void ShowCustCurrency()
02587 {
02588 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
02589 new CustomCurrencyWindow(&_cust_currency_desc);
02590 }