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