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