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