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
00699 struct SettingFilter {
00700 StringFilter string;
00701 RestrictionMode mode;
00702 SettingType type;
00703 };
00704
00706 struct SettingEntry {
00707 byte flags;
00708 byte level;
00709 union {
00710 SettingEntrySetting entry;
00711 SettingEntrySubtree sub;
00712 } d;
00713
00714 SettingEntry(const char *nm);
00715 SettingEntry(SettingsPage *sub, StringID title);
00716
00717 void Init(byte level);
00718 void FoldAll();
00719 void UnFoldAll();
00720 void SetButtons(byte new_val);
00721
00726 void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
00727
00728 uint Length() const;
00729 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
00730 bool IsVisible(const SettingEntry *item) const;
00731 SettingEntry *FindEntry(uint row, uint *cur_row);
00732 uint GetMaxHelpHeight(int maxw);
00733
00734 bool IsFiltered() const;
00735 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
00736
00737 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);
00738
00743 inline StringID GetHelpText()
00744 {
00745 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
00746 return this->d.entry.setting->desc.str_help;
00747 }
00748
00749 void SetValueDParams(uint first_param, int32 value);
00750
00751 private:
00752 void DrawSetting(GameSettings *settings_ptr, int x, int y, int max_x, int state, bool highlight);
00753 bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
00754 };
00755
00757 struct SettingsPage {
00758 SettingEntry *entries;
00759 byte num;
00760
00761 void Init(byte level = 0);
00762 void FoldAll();
00763 void UnFoldAll();
00764
00765 uint Length() const;
00766 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
00767 bool IsVisible(const SettingEntry *item) const;
00768 SettingEntry *FindEntry(uint row, uint *cur_row) const;
00769 uint GetMaxHelpHeight(int maxw);
00770
00771 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
00772
00773 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;
00774 };
00775
00776
00777
00778
00783 SettingEntry::SettingEntry(const char *nm)
00784 {
00785 this->flags = SEF_SETTING_KIND;
00786 this->level = 0;
00787 this->d.entry.name = nm;
00788 this->d.entry.setting = NULL;
00789 this->d.entry.index = 0;
00790 }
00791
00797 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
00798 {
00799 this->flags = SEF_SUBTREE_KIND;
00800 this->level = 0;
00801 this->d.sub.page = sub;
00802 this->d.sub.folded = true;
00803 this->d.sub.title = title;
00804 }
00805
00810 void SettingEntry::Init(byte level)
00811 {
00812 this->level = level;
00813
00814 switch (this->flags & SEF_KIND_MASK) {
00815 case SEF_SETTING_KIND:
00816 this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
00817 assert(this->d.entry.setting != NULL);
00818 break;
00819 case SEF_SUBTREE_KIND:
00820 this->d.sub.page->Init(level + 1);
00821 break;
00822 default: NOT_REACHED();
00823 }
00824 }
00825
00827 void SettingEntry::FoldAll()
00828 {
00829 if (this->IsFiltered()) return;
00830 switch (this->flags & SEF_KIND_MASK) {
00831 case SEF_SETTING_KIND:
00832 break;
00833
00834 case SEF_SUBTREE_KIND:
00835 this->d.sub.folded = true;
00836 this->d.sub.page->FoldAll();
00837 break;
00838
00839 default: NOT_REACHED();
00840 }
00841 }
00842
00844 void SettingEntry::UnFoldAll()
00845 {
00846 if (this->IsFiltered()) return;
00847 switch (this->flags & SEF_KIND_MASK) {
00848 case SEF_SETTING_KIND:
00849 break;
00850
00851 case SEF_SUBTREE_KIND:
00852 this->d.sub.folded = false;
00853 this->d.sub.page->UnFoldAll();
00854 break;
00855
00856 default: NOT_REACHED();
00857 }
00858 }
00859
00865 void SettingEntry::GetFoldingState(bool &all_folded, bool &all_unfolded) const
00866 {
00867 if (this->IsFiltered()) return;
00868 switch (this->flags & SEF_KIND_MASK) {
00869 case SEF_SETTING_KIND:
00870 break;
00871
00872 case SEF_SUBTREE_KIND:
00873 if (this->d.sub.folded) {
00874 all_unfolded = false;
00875 } else {
00876 all_folded = false;
00877 }
00878 this->d.sub.page->GetFoldingState(all_folded, all_unfolded);
00879 break;
00880
00881 default: NOT_REACHED();
00882 }
00883 }
00884
00891 bool SettingEntry::IsVisible(const SettingEntry *item) const
00892 {
00893 if (this->IsFiltered()) return false;
00894 if (this == item) return true;
00895
00896 switch (this->flags & SEF_KIND_MASK) {
00897 case SEF_SETTING_KIND:
00898 return false;
00899
00900 case SEF_SUBTREE_KIND:
00901 return !this->d.sub.folded && this->d.sub.page->IsVisible(item);
00902
00903 default: NOT_REACHED();
00904 }
00905 }
00906
00912 void SettingEntry::SetButtons(byte new_val)
00913 {
00914 assert((new_val & ~SEF_BUTTONS_MASK) == 0);
00915 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
00916 }
00917
00919 uint SettingEntry::Length() const
00920 {
00921 if (this->IsFiltered()) return 0;
00922 switch (this->flags & SEF_KIND_MASK) {
00923 case SEF_SETTING_KIND:
00924 return 1;
00925 case SEF_SUBTREE_KIND:
00926 if (this->d.sub.folded) return 1;
00927
00928 return 1 + this->d.sub.page->Length();
00929 default: NOT_REACHED();
00930 }
00931 }
00932
00939 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
00940 {
00941 if (this->IsFiltered()) return NULL;
00942 if (row_num == *cur_row) return this;
00943
00944 switch (this->flags & SEF_KIND_MASK) {
00945 case SEF_SETTING_KIND:
00946 (*cur_row)++;
00947 break;
00948 case SEF_SUBTREE_KIND:
00949 (*cur_row)++;
00950 if (this->d.sub.folded) {
00951 break;
00952 }
00953
00954
00955 return this->d.sub.page->FindEntry(row_num, cur_row);
00956 default: NOT_REACHED();
00957 }
00958 return NULL;
00959 }
00960
00966 uint SettingEntry::GetMaxHelpHeight(int maxw)
00967 {
00968 switch (this->flags & SEF_KIND_MASK) {
00969 case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw);
00970 case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw);
00971 default: NOT_REACHED();
00972 }
00973 }
00974
00979 bool SettingEntry::IsFiltered() const
00980 {
00981 return (this->flags & SEF_FILTERED) != 0;
00982 }
00983
00989 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
00990 {
00991
00992 if (mode == RM_ALL) return true;
00993
00994 GameSettings *settings_ptr = &GetGameSettings();
00995 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
00996 const SettingDesc *sd = this->d.entry.setting;
00997
00998 if (mode == RM_BASIC) return (this->d.entry.setting->desc.cat & SC_BASIC_LIST) != 0;
00999 if (mode == RM_ADVANCED) return (this->d.entry.setting->desc.cat & SC_ADVANCED_LIST) != 0;
01000
01001
01002 const void *var = ResolveVariableAddress(settings_ptr, sd);
01003 int64 current_value = ReadValue(var, sd->save.conv);
01004
01005 int64 filter_value;
01006
01007 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
01008
01009
01010
01011 filter_value = ReadValue(&sd->desc.def, sd->save.conv);
01012 } else {
01013 assert(mode == RM_CHANGED_AGAINST_NEW);
01014
01015
01016
01017
01018 assert(settings_ptr != &_settings_newgame);
01019
01020
01021 var = ResolveVariableAddress(&_settings_newgame, sd);
01022 filter_value = ReadValue(var, sd->save.conv);
01023 }
01024
01025 return current_value != filter_value;
01026 }
01027
01034 bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
01035 {
01036 CLRBITS(this->flags, SEF_FILTERED);
01037
01038 bool visible = true;
01039 switch (this->flags & SEF_KIND_MASK) {
01040 case SEF_SETTING_KIND: {
01041 const SettingDesc *sd = this->d.entry.setting;
01042 if (!force_visible && !filter.string.IsEmpty()) {
01043
01044 filter.string.ResetState();
01045
01046 const SettingDescBase *sdb = &sd->desc;
01047
01048 SetDParam(0, STR_EMPTY);
01049 filter.string.AddLine(sdb->str);
01050 filter.string.AddLine(this->GetHelpText());
01051
01052 visible = filter.string.GetState();
01053 }
01054 if (filter.type != ST_ALL) visible = visible && sd->GetType() == filter.type;
01055 visible = visible && this->IsVisibleByRestrictionMode(filter.mode);
01056 break;
01057 }
01058 case SEF_SUBTREE_KIND: {
01059 if (!force_visible && !filter.string.IsEmpty()) {
01060 filter.string.ResetState();
01061 filter.string.AddLine(this->d.sub.title);
01062 force_visible = filter.string.GetState();
01063 }
01064 visible = this->d.sub.page->UpdateFilterState(filter, force_visible);
01065 break;
01066 }
01067 default: NOT_REACHED();
01068 }
01069
01070 if (!visible) SETBITS(this->flags, SEF_FILTERED);
01071 return visible;
01072 }
01073
01074
01075
01103 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)
01104 {
01105 if (this->IsFiltered()) return cur_row;
01106 if (cur_row >= max_row) return cur_row;
01107
01108 bool rtl = _current_text_dir == TD_RTL;
01109 int offset = rtl ? -4 : 4;
01110 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
01111
01112 int x = rtl ? right : left;
01113 int y = base_y;
01114 if (cur_row >= first_row) {
01115 int colour = _colour_gradient[COLOUR_ORANGE][4];
01116 y = base_y + (cur_row - first_row) * SETTING_HEIGHT;
01117
01118
01119 for (uint lvl = 0; lvl < this->level; lvl++) {
01120 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
01121 x += level_width;
01122 }
01123
01124 int halfway_y = y + SETTING_HEIGHT / 2;
01125 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
01126 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
01127
01128 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
01129 x += level_width;
01130 }
01131
01132 switch (this->flags & SEF_KIND_MASK) {
01133 case SEF_SETTING_KIND:
01134 if (cur_row >= first_row) {
01135 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK,
01136 this == selected);
01137 }
01138 cur_row++;
01139 break;
01140 case SEF_SUBTREE_KIND:
01141 if (cur_row >= first_row) {
01142 DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
01143 DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
01144 }
01145 cur_row++;
01146 if (!this->d.sub.folded) {
01147 if (this->flags & SEF_LAST_FIELD) {
01148 assert(this->level < sizeof(parent_last));
01149 SetBit(parent_last, this->level);
01150 }
01151
01152 cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, selected, cur_row, parent_last);
01153 }
01154 break;
01155 default: NOT_REACHED();
01156 }
01157 return cur_row;
01158 }
01159
01160 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
01161 {
01162 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01163 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
01164 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
01165 } else {
01166 return GetVariableAddress(&_settings_client.company, &sd->save);
01167 }
01168 } else {
01169 return GetVariableAddress(settings_ptr, &sd->save);
01170 }
01171 }
01172
01178 void SettingEntry::SetValueDParams(uint first_param, int32 value)
01179 {
01180 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01181 const SettingDescBase *sdb = &this->d.entry.setting->desc;
01182 if (sdb->cmd == SDT_BOOLX) {
01183 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
01184 } else {
01185 if ((sdb->flags & SGF_MULTISTRING) != 0) {
01186 SetDParam(first_param++, sdb->str_val - sdb->min + value);
01187 } else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
01188 SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
01189 value = abs(value);
01190 } else {
01191 SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
01192 }
01193 SetDParam(first_param++, value);
01194 }
01195 }
01196
01206 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, int state, bool highlight)
01207 {
01208 const SettingDesc *sd = this->d.entry.setting;
01209 const SettingDescBase *sdb = &sd->desc;
01210 const void *var = ResolveVariableAddress(settings_ptr, sd);
01211
01212 bool rtl = _current_text_dir == TD_RTL;
01213 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
01214 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
01215 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
01216 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
01217
01218
01219 bool editable = sd->IsEditable();
01220
01221 SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
01222 int32 value = (int32)ReadValue(var, sd->save.conv);
01223 if (sdb->cmd == SDT_BOOLX) {
01224
01225 DrawBoolButton(buttons_left, button_y, value != 0, editable);
01226 } else if ((sdb->flags & SGF_MULTISTRING) != 0) {
01227
01228 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
01229 } else {
01230
01231 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
01232 editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
01233 }
01234 this->SetValueDParams(1, value);
01235 DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
01236 }
01237
01238
01239
01240
01245 void SettingsPage::Init(byte level)
01246 {
01247 for (uint field = 0; field < this->num; field++) {
01248 this->entries[field].Init(level);
01249 }
01250 }
01251
01253 void SettingsPage::FoldAll()
01254 {
01255 for (uint field = 0; field < this->num; field++) {
01256 this->entries[field].FoldAll();
01257 }
01258 }
01259
01261 void SettingsPage::UnFoldAll()
01262 {
01263 for (uint field = 0; field < this->num; field++) {
01264 this->entries[field].UnFoldAll();
01265 }
01266 }
01267
01273 void SettingsPage::GetFoldingState(bool &all_folded, bool &all_unfolded) const
01274 {
01275 for (uint field = 0; field < this->num; field++) {
01276 this->entries[field].GetFoldingState(all_folded, all_unfolded);
01277 }
01278 }
01279
01286 bool SettingsPage::UpdateFilterState(SettingFilter &filter, bool force_visible)
01287 {
01288 bool visible = false;
01289 bool first_visible = true;
01290 for (int field = this->num - 1; field >= 0; field--) {
01291 visible |= this->entries[field].UpdateFilterState(filter, force_visible);
01292 this->entries[field].SetLastField(first_visible);
01293 if (visible && first_visible) first_visible = false;
01294 }
01295 return visible;
01296 }
01297
01298
01305 bool SettingsPage::IsVisible(const SettingEntry *item) const
01306 {
01307 for (uint field = 0; field < this->num; field++) {
01308 if (this->entries[field].IsVisible(item)) return true;
01309 }
01310 return false;
01311 }
01312
01314 uint SettingsPage::Length() const
01315 {
01316 uint length = 0;
01317 for (uint field = 0; field < this->num; field++) {
01318 length += this->entries[field].Length();
01319 }
01320 return length;
01321 }
01322
01329 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
01330 {
01331 SettingEntry *pe = NULL;
01332
01333 for (uint field = 0; field < this->num; field++) {
01334 pe = this->entries[field].FindEntry(row_num, cur_row);
01335 if (pe != NULL) {
01336 break;
01337 }
01338 }
01339 return pe;
01340 }
01341
01347 uint SettingsPage::GetMaxHelpHeight(int maxw)
01348 {
01349 uint biggest = 0;
01350 for (uint field = 0; field < this->num; field++) {
01351 biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw));
01352 }
01353 return biggest;
01354 }
01355
01374 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
01375 {
01376 if (cur_row >= max_row) return cur_row;
01377
01378 for (uint i = 0; i < this->num; i++) {
01379 cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last, selected);
01380 if (cur_row >= max_row) {
01381 break;
01382 }
01383 }
01384 return cur_row;
01385 }
01386
01387
01388 static SettingEntry _settings_ui_localisation[] = {
01389 SettingEntry("locale.units_velocity"),
01390 SettingEntry("locale.units_power"),
01391 SettingEntry("locale.units_weight"),
01392 SettingEntry("locale.units_volume"),
01393 SettingEntry("locale.units_force"),
01394 SettingEntry("locale.units_height"),
01395 };
01397 static SettingsPage _settings_ui_localisation_page = {_settings_ui_localisation, lengthof(_settings_ui_localisation)};
01398
01399 static SettingEntry _settings_ui_display[] = {
01400 SettingEntry("gui.date_format_in_default_names"),
01401 SettingEntry("gui.population_in_label"),
01402 SettingEntry("gui.measure_tooltip"),
01403 SettingEntry("gui.loading_indicators"),
01404 SettingEntry("gui.liveries"),
01405 SettingEntry("gui.show_track_reservation"),
01406 SettingEntry("gui.expenses_layout"),
01407 SettingEntry("gui.smallmap_land_colour"),
01408 SettingEntry("gui.zoom_min"),
01409 SettingEntry("gui.zoom_max"),
01410 SettingEntry("gui.graph_line_thickness"),
01411 };
01413 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
01414
01415 static SettingEntry _settings_ui_interaction[] = {
01416 SettingEntry("gui.window_snap_radius"),
01417 SettingEntry("gui.window_soft_limit"),
01418 SettingEntry("gui.link_terraform_toolbar"),
01419 SettingEntry("gui.prefer_teamchat"),
01420 SettingEntry("gui.auto_scrolling"),
01421 SettingEntry("gui.reverse_scroll"),
01422 SettingEntry("gui.smooth_scroll"),
01423 SettingEntry("gui.left_mouse_btn_scrolling"),
01424
01425
01426
01427 SettingEntry("gui.scrollwheel_scrolling"),
01428 SettingEntry("gui.scrollwheel_multiplier"),
01429 SettingEntry("gui.osk_activation"),
01430 #ifdef __APPLE__
01431
01432 SettingEntry("gui.right_mouse_btn_emulation"),
01433 #endif
01434 };
01436 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
01437
01438 static SettingEntry _settings_ui_sound[] = {
01439 SettingEntry("sound.click_beep"),
01440 SettingEntry("sound.confirm"),
01441 SettingEntry("sound.news_ticker"),
01442 SettingEntry("sound.news_full"),
01443 SettingEntry("sound.new_year"),
01444 SettingEntry("sound.disaster"),
01445 SettingEntry("sound.vehicle"),
01446 SettingEntry("sound.ambient"),
01447 };
01449 static SettingsPage _settings_ui_sound_page = {_settings_ui_sound, lengthof(_settings_ui_sound)};
01450
01451 static SettingEntry _settings_ui_news[] = {
01452 SettingEntry("news_display.arrival_player"),
01453 SettingEntry("news_display.arrival_other"),
01454 SettingEntry("news_display.accident"),
01455 SettingEntry("news_display.company_info"),
01456 SettingEntry("news_display.open"),
01457 SettingEntry("news_display.close"),
01458 SettingEntry("news_display.economy"),
01459 SettingEntry("news_display.production_player"),
01460 SettingEntry("news_display.production_other"),
01461 SettingEntry("news_display.production_nobody"),
01462 SettingEntry("news_display.advice"),
01463 SettingEntry("news_display.new_vehicles"),
01464 SettingEntry("news_display.acceptance"),
01465 SettingEntry("news_display.subsidies"),
01466 SettingEntry("news_display.general"),
01467 SettingEntry("gui.coloured_news_year"),
01468 };
01470 static SettingsPage _settings_ui_news_page = {_settings_ui_news, lengthof(_settings_ui_news)};
01471
01472 static SettingEntry _settings_ui[] = {
01473 SettingEntry(&_settings_ui_localisation_page, STR_CONFIG_SETTING_LOCALISATION),
01474 SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
01475 SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
01476 SettingEntry(&_settings_ui_sound_page, STR_CONFIG_SETTING_SOUND),
01477 SettingEntry(&_settings_ui_news_page, STR_CONFIG_SETTING_NEWS),
01478 SettingEntry("gui.show_finances"),
01479 SettingEntry("gui.errmsg_duration"),
01480 SettingEntry("gui.hover_delay"),
01481 SettingEntry("gui.toolbar_pos"),
01482 SettingEntry("gui.statusbar_pos"),
01483 SettingEntry("gui.newgrf_default_palette"),
01484 SettingEntry("gui.pause_on_newgame"),
01485 SettingEntry("gui.advanced_vehicle_list"),
01486 SettingEntry("gui.timetable_in_ticks"),
01487 SettingEntry("gui.timetable_arrival_departure"),
01488 SettingEntry("gui.quick_goto"),
01489 SettingEntry("gui.default_rail_type"),
01490 SettingEntry("gui.disable_unsuitable_building"),
01491 SettingEntry("gui.persistent_buildingtools"),
01492 };
01494 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
01495
01496 static SettingEntry _settings_construction_signals[] = {
01497 SettingEntry("construction.train_signal_side"),
01498 SettingEntry("gui.enable_signal_gui"),
01499 SettingEntry("gui.drag_signals_fixed_distance"),
01500 SettingEntry("gui.semaphore_build_before"),
01501 SettingEntry("gui.default_signal_type"),
01502 SettingEntry("gui.cycle_signal_types"),
01503 };
01505 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
01506
01507 static SettingEntry _settings_construction[] = {
01508 SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
01509 SettingEntry("construction.build_on_slopes"),
01510 SettingEntry("construction.autoslope"),
01511 SettingEntry("construction.extra_dynamite"),
01512 SettingEntry("construction.max_bridge_length"),
01513 SettingEntry("construction.max_tunnel_length"),
01514 SettingEntry("station.never_expire_airports"),
01515 SettingEntry("construction.freeform_edges"),
01516 SettingEntry("construction.extra_tree_placement"),
01517 SettingEntry("construction.command_pause_level"),
01518 };
01520 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
01521
01522 static SettingEntry _settings_stations_cargo[] = {
01523 SettingEntry("order.improved_load"),
01524 SettingEntry("order.gradual_loading"),
01525 SettingEntry("order.selectgoods"),
01526 };
01528 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
01529
01530 static SettingEntry _settings_stations[] = {
01531 SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
01532 SettingEntry("station.adjacent_stations"),
01533 SettingEntry("station.distant_join_stations"),
01534 SettingEntry("station.station_spread"),
01535 SettingEntry("economy.station_noise_level"),
01536 SettingEntry("station.modified_catchment"),
01537 SettingEntry("construction.road_stop_on_town_road"),
01538 SettingEntry("construction.road_stop_on_competitor_road"),
01539 };
01541 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
01542
01543 static SettingEntry _settings_economy_towns[] = {
01544 SettingEntry("difficulty.town_council_tolerance"),
01545 SettingEntry("economy.bribe"),
01546 SettingEntry("economy.exclusive_rights"),
01547 SettingEntry("economy.fund_roads"),
01548 SettingEntry("economy.fund_buildings"),
01549 SettingEntry("economy.town_layout"),
01550 SettingEntry("economy.allow_town_roads"),
01551 SettingEntry("economy.allow_town_level_crossings"),
01552 SettingEntry("economy.found_town"),
01553 SettingEntry("economy.mod_road_rebuild"),
01554 SettingEntry("economy.town_growth_rate"),
01555 SettingEntry("economy.larger_towns"),
01556 SettingEntry("economy.initial_city_size"),
01557 };
01559 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
01560
01561 static SettingEntry _settings_economy_industries[] = {
01562 SettingEntry("construction.raw_industry_construction"),
01563 SettingEntry("construction.industry_platform"),
01564 SettingEntry("economy.multiple_industry_per_town"),
01565 SettingEntry("game_creation.oil_refinery_limit"),
01566 };
01568 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
01569
01570
01571 static SettingEntry _settings_economy[] = {
01572 SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
01573 SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
01574 SettingEntry("economy.inflation"),
01575 SettingEntry("difficulty.initial_interest"),
01576 SettingEntry("difficulty.max_loan"),
01577 SettingEntry("difficulty.subsidy_multiplier"),
01578 SettingEntry("difficulty.economy"),
01579 SettingEntry("economy.smooth_economy"),
01580 SettingEntry("economy.feeder_payment_share"),
01581 SettingEntry("economy.infrastructure_maintenance"),
01582 SettingEntry("difficulty.vehicle_costs"),
01583 SettingEntry("difficulty.construction_cost"),
01584 SettingEntry("difficulty.disasters"),
01585 };
01587 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
01588
01589 static SettingEntry _settings_linkgraph[] = {
01590 SettingEntry("linkgraph.recalc_time"),
01591 SettingEntry("linkgraph.recalc_interval"),
01592 SettingEntry("linkgraph.distribution_pax"),
01593 SettingEntry("linkgraph.distribution_mail"),
01594 SettingEntry("linkgraph.distribution_armoured"),
01595 SettingEntry("linkgraph.distribution_default"),
01596 SettingEntry("linkgraph.accuracy"),
01597 SettingEntry("linkgraph.demand_distance"),
01598 SettingEntry("linkgraph.demand_size"),
01599 SettingEntry("linkgraph.short_path_saturation"),
01600 };
01602 static SettingsPage _settings_linkgraph_page = {_settings_linkgraph, lengthof(_settings_linkgraph)};
01603
01604 static SettingEntry _settings_ai_npc[] = {
01605 SettingEntry("script.settings_profile"),
01606 SettingEntry("script.script_max_opcode_till_suspend"),
01607 SettingEntry("difficulty.competitor_speed"),
01608 SettingEntry("ai.ai_in_multiplayer"),
01609 SettingEntry("ai.ai_disable_veh_train"),
01610 SettingEntry("ai.ai_disable_veh_roadveh"),
01611 SettingEntry("ai.ai_disable_veh_aircraft"),
01612 SettingEntry("ai.ai_disable_veh_ship"),
01613 };
01615 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
01616
01617 static SettingEntry _settings_ai[] = {
01618 SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
01619 SettingEntry("economy.give_money"),
01620 SettingEntry("economy.allow_shares"),
01621 };
01623 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
01624
01625 static SettingEntry _settings_vehicles_routing[] = {
01626 SettingEntry("pf.pathfinder_for_trains"),
01627 SettingEntry("pf.forbid_90_deg"),
01628 SettingEntry("pf.pathfinder_for_roadvehs"),
01629 SettingEntry("pf.roadveh_queue"),
01630 SettingEntry("pf.pathfinder_for_ships"),
01631 };
01633 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
01634
01635 static SettingEntry _settings_vehicles_autorenew[] = {
01636 SettingEntry("company.engine_renew"),
01637 SettingEntry("company.engine_renew_months"),
01638 SettingEntry("company.engine_renew_money"),
01639 };
01641 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
01642
01643 static SettingEntry _settings_vehicles_servicing[] = {
01644 SettingEntry("vehicle.servint_ispercent"),
01645 SettingEntry("vehicle.servint_trains"),
01646 SettingEntry("vehicle.servint_roadveh"),
01647 SettingEntry("vehicle.servint_ships"),
01648 SettingEntry("vehicle.servint_aircraft"),
01649 SettingEntry("difficulty.vehicle_breakdowns"),
01650 SettingEntry("order.no_servicing_if_no_breakdowns"),
01651 SettingEntry("order.serviceathelipad"),
01652 };
01654 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
01655
01656 static SettingEntry _settings_vehicles_trains[] = {
01657 SettingEntry("difficulty.line_reverse_mode"),
01658 SettingEntry("pf.reverse_at_signals"),
01659 SettingEntry("vehicle.train_acceleration_model"),
01660 SettingEntry("vehicle.train_slope_steepness"),
01661 SettingEntry("vehicle.max_train_length"),
01662 SettingEntry("vehicle.wagon_speed_limits"),
01663 SettingEntry("vehicle.disable_elrails"),
01664 SettingEntry("vehicle.freight_trains"),
01665 SettingEntry("gui.stop_location"),
01666 };
01668 static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
01669
01670 static SettingEntry _settings_vehicles[] = {
01671 SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
01672 SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
01673 SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
01674 SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
01675 SettingEntry("gui.new_nonstop"),
01676 SettingEntry("gui.order_review_system"),
01677 SettingEntry("gui.vehicle_income_warn"),
01678 SettingEntry("gui.lost_vehicle_warn"),
01679 SettingEntry("vehicle.never_expire_vehicles"),
01680 SettingEntry("vehicle.max_trains"),
01681 SettingEntry("vehicle.max_roadveh"),
01682 SettingEntry("vehicle.max_aircraft"),
01683 SettingEntry("vehicle.max_ships"),
01684 SettingEntry("vehicle.plane_speed"),
01685 SettingEntry("vehicle.plane_crashes"),
01686 SettingEntry("vehicle.dynamic_engines"),
01687 SettingEntry("vehicle.roadveh_acceleration_model"),
01688 SettingEntry("vehicle.roadveh_slope_steepness"),
01689 SettingEntry("vehicle.smoke_amount"),
01690 };
01692 static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
01693
01694 static SettingEntry _settings_main[] = {
01695 SettingEntry(&_settings_ui_page, STR_CONFIG_SETTING_GUI),
01696 SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
01697 SettingEntry(&_settings_vehicles_page, STR_CONFIG_SETTING_VEHICLES),
01698 SettingEntry(&_settings_stations_page, STR_CONFIG_SETTING_STATIONS),
01699 SettingEntry(&_settings_economy_page, STR_CONFIG_SETTING_ECONOMY),
01700 SettingEntry(&_settings_linkgraph_page, STR_CONFIG_SETTING_LINKGRAPH),
01701 SettingEntry(&_settings_ai_page, STR_CONFIG_SETTING_AI),
01702 };
01703
01705 static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
01706
01707 static const StringID _game_settings_restrict_dropdown[] = {
01708 STR_CONFIG_SETTING_RESTRICT_BASIC,
01709 STR_CONFIG_SETTING_RESTRICT_ADVANCED,
01710 STR_CONFIG_SETTING_RESTRICT_ALL,
01711 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT,
01712 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW,
01713 };
01714 assert_compile(lengthof(_game_settings_restrict_dropdown) == RM_END);
01715
01716 struct GameSettingsWindow : Window {
01717 static const int SETTINGTREE_LEFT_OFFSET = 5;
01718 static const int SETTINGTREE_RIGHT_OFFSET = 5;
01719 static const int SETTINGTREE_TOP_OFFSET = 5;
01720 static const int SETTINGTREE_BOTTOM_OFFSET = 5;
01721
01722 static GameSettings *settings_ptr;
01723
01724 SettingEntry *valuewindow_entry;
01725 SettingEntry *clicked_entry;
01726 SettingEntry *last_clicked;
01727 SettingEntry *valuedropdown_entry;
01728 bool closing_dropdown;
01729
01730 SettingFilter filter;
01731 QueryString filter_editbox;
01732 bool manually_changed_folding;
01733
01734 Scrollbar *vscroll;
01735
01736 GameSettingsWindow(WindowDesc *desc) : Window(desc), filter_editbox(50)
01737 {
01738 static bool first_time = true;
01739
01740 filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
01741 filter.type = ST_ALL;
01742 settings_ptr = &GetGameSettings();
01743
01744
01745 if (first_time) {
01746 _settings_main_page.Init();
01747 first_time = false;
01748 } else {
01749 _settings_main_page.FoldAll();
01750 }
01751
01752 this->valuewindow_entry = NULL;
01753 this->clicked_entry = NULL;
01754 this->last_clicked = NULL;
01755 this->valuedropdown_entry = NULL;
01756 this->closing_dropdown = false;
01757 this->manually_changed_folding = false;
01758
01759 this->CreateNestedTree();
01760 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
01761 this->FinishInitNested(WN_GAME_OPTIONS_GAME_SETTINGS);
01762
01763 this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
01764 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
01765 this->SetFocusedWidget(WID_GS_FILTER);
01766
01767 this->InvalidateData();
01768 }
01769
01770 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01771 {
01772 switch (widget) {
01773 case WID_GS_OPTIONSPANEL:
01774 resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
01775 resize->width = 1;
01776
01777 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
01778 break;
01779
01780 case WID_GS_HELP_TEXT: {
01781 static const StringID setting_types[] = {
01782 STR_CONFIG_SETTING_TYPE_CLIENT,
01783 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
01784 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
01785 };
01786 for (uint i = 0; i < lengthof(setting_types); i++) {
01787 SetDParam(0, setting_types[i]);
01788 size->width = max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width);
01789 }
01790 size->height = 2 * FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL +
01791 max(size->height, _settings_main_page.GetMaxHelpHeight(size->width));
01792 break;
01793 }
01794
01795 default:
01796 break;
01797 }
01798 }
01799
01800 virtual void OnPaint()
01801 {
01802 if (this->closing_dropdown) {
01803 this->closing_dropdown = false;
01804 assert(this->valuedropdown_entry != NULL);
01805 this->valuedropdown_entry->SetButtons(0);
01806 this->valuedropdown_entry = NULL;
01807 }
01808 this->DrawWidgets();
01809 }
01810
01811 virtual void SetStringParameters(int widget) const
01812 {
01813 switch (widget) {
01814 case WID_GS_RESTRICT_DROPDOWN:
01815 SetDParam(0, _game_settings_restrict_dropdown[this->filter.mode]);
01816 break;
01817
01818 case WID_GS_TYPE_DROPDOWN:
01819 switch (this->filter.type) {
01820 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME); break;
01821 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME); break;
01822 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT); break;
01823 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL); break;
01824 }
01825 break;
01826 }
01827 }
01828
01829 DropDownList *BuildDropDownList(int widget) const
01830 {
01831 DropDownList *list = NULL;
01832 switch (widget) {
01833 case WID_GS_RESTRICT_DROPDOWN:
01834 list = new DropDownList();
01835
01836 for (int mode = 0; mode != RM_END; mode++) {
01837
01838
01839 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
01840
01841 *list->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled);
01842 }
01843 break;
01844
01845 case WID_GS_TYPE_DROPDOWN:
01846 list = new DropDownList();
01847 *list->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false);
01848 *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);
01849 *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);
01850 *list->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false);
01851 break;
01852 }
01853 return list;
01854 }
01855
01856 virtual void DrawWidget(const Rect &r, int widget) const
01857 {
01858 switch (widget) {
01859 case WID_GS_OPTIONSPANEL:
01860 _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
01861 this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->last_clicked);
01862 break;
01863
01864 case WID_GS_HELP_TEXT:
01865 if (this->last_clicked != NULL) {
01866 const SettingDesc *sd = this->last_clicked->d.entry.setting;
01867
01868 int y = r.top;
01869 switch (sd->GetType()) {
01870 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
01871 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
01872 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
01873 default: NOT_REACHED();
01874 }
01875 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
01876 y += FONT_HEIGHT_NORMAL;
01877
01878 int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
01879 this->last_clicked->SetValueDParams(0, default_value);
01880 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
01881 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
01882
01883 DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
01884 }
01885 break;
01886
01887 default:
01888 break;
01889 }
01890 }
01891
01896 void SetDisplayedHelpText(SettingEntry *pe)
01897 {
01898 if (this->last_clicked != pe) this->SetDirty();
01899 this->last_clicked = pe;
01900 }
01901
01902 virtual void OnClick(Point pt, int widget, int click_count)
01903 {
01904 switch (widget) {
01905 case WID_GS_EXPAND_ALL:
01906 this->manually_changed_folding = true;
01907 _settings_main_page.UnFoldAll();
01908 this->InvalidateData();
01909 break;
01910
01911 case WID_GS_COLLAPSE_ALL:
01912 this->manually_changed_folding = true;
01913 _settings_main_page.FoldAll();
01914 this->InvalidateData();
01915 break;
01916
01917 case WID_GS_RESTRICT_DROPDOWN: {
01918 DropDownList *list = this->BuildDropDownList(widget);
01919 if (list != NULL) {
01920 ShowDropDownList(this, list, this->filter.mode, widget);
01921 }
01922 break;
01923 }
01924
01925 case WID_GS_TYPE_DROPDOWN: {
01926 DropDownList *list = this->BuildDropDownList(widget);
01927 if (list != NULL) {
01928 ShowDropDownList(this, list, this->filter.type, widget);
01929 }
01930 break;
01931 }
01932 }
01933
01934 if (widget != WID_GS_OPTIONSPANEL) return;
01935
01936 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
01937 if (btn == INT_MAX) return;
01938
01939 uint cur_row = 0;
01940 SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
01941
01942 if (pe == NULL) return;
01943
01944 int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;
01945 if (x < 0) return;
01946
01947 if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
01948 this->SetDisplayedHelpText(NULL);
01949 pe->d.sub.folded = !pe->d.sub.folded;
01950
01951 this->manually_changed_folding = true;
01952
01953 this->InvalidateData();
01954 return;
01955 }
01956
01957 assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01958 const SettingDesc *sd = pe->d.entry.setting;
01959
01960
01961 if (!sd->IsEditable()) {
01962 this->SetDisplayedHelpText(pe);
01963 return;
01964 }
01965
01966 const void *var = ResolveVariableAddress(settings_ptr, sd);
01967 int32 value = (int32)ReadValue(var, sd->save.conv);
01968
01969
01970 if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
01971 const SettingDescBase *sdb = &sd->desc;
01972 this->SetDisplayedHelpText(pe);
01973
01974 if (this->valuedropdown_entry == pe) {
01975
01976 HideDropDownMenu(this);
01977 this->closing_dropdown = false;
01978 this->valuedropdown_entry->SetButtons(0);
01979 this->valuedropdown_entry = NULL;
01980 } else {
01981 if (this->valuedropdown_entry != NULL) this->valuedropdown_entry->SetButtons(0);
01982 this->closing_dropdown = false;
01983
01984 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
01985 int rel_y = (pt.y - (int)wid->pos_y - SETTINGTREE_TOP_OFFSET) % wid->resize_y;
01986
01987 Rect wi_rect;
01988 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
01989 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
01990 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
01991 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
01992
01993
01994 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
01995 this->valuedropdown_entry = pe;
01996 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
01997
01998 DropDownList *list = new DropDownList();
01999 for (int i = sdb->min; i <= (int)sdb->max; i++) {
02000 *list->Append() = new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false);
02001 }
02002
02003 ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true);
02004 }
02005 }
02006 this->SetDirty();
02007 } else if (x < SETTING_BUTTON_WIDTH) {
02008 this->SetDisplayedHelpText(pe);
02009 const SettingDescBase *sdb = &sd->desc;
02010 int32 oldvalue = value;
02011
02012 switch (sdb->cmd) {
02013 case SDT_BOOLX: value ^= 1; break;
02014 case SDT_ONEOFMANY:
02015 case SDT_NUMX: {
02016
02017
02018
02019
02020 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
02021 if (step == 0) step = 1;
02022
02023
02024 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
02025 _left_button_clicked = false;
02026 return;
02027 }
02028
02029
02030 if (x >= SETTING_BUTTON_WIDTH / 2) {
02031 value += step;
02032 if (sdb->min < 0) {
02033 assert((int32)sdb->max >= 0);
02034 if (value > (int32)sdb->max) value = (int32)sdb->max;
02035 } else {
02036 if ((uint32)value > sdb->max) value = (int32)sdb->max;
02037 }
02038 if (value < sdb->min) value = sdb->min;
02039 } else {
02040 value -= step;
02041 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
02042 }
02043
02044
02045 if (value != oldvalue) {
02046 if (this->clicked_entry != NULL) {
02047 this->clicked_entry->SetButtons(0);
02048 }
02049 this->clicked_entry = pe;
02050 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
02051 this->SetTimeout();
02052 _left_button_clicked = false;
02053 }
02054 break;
02055 }
02056
02057 default: NOT_REACHED();
02058 }
02059
02060 if (value != oldvalue) {
02061 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02062 SetCompanySetting(pe->d.entry.index, value);
02063 } else {
02064 SetSettingValue(pe->d.entry.index, value);
02065 }
02066 this->SetDirty();
02067 }
02068 } else {
02069
02070 if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
02071
02072 if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
02073
02074 this->valuewindow_entry = pe;
02075 SetDParam(0, value);
02076 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
02077 }
02078 this->SetDisplayedHelpText(pe);
02079 }
02080 }
02081
02082 virtual void OnTimeout()
02083 {
02084 if (this->clicked_entry != NULL) {
02085 this->clicked_entry->SetButtons(0);
02086 this->clicked_entry = NULL;
02087 this->SetDirty();
02088 }
02089 }
02090
02091 virtual void OnQueryTextFinished(char *str)
02092 {
02093
02094 if (str == NULL) return;
02095
02096 assert(this->valuewindow_entry != NULL);
02097 assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
02098 const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
02099
02100 int32 value;
02101 if (!StrEmpty(str)) {
02102 value = atoi(str);
02103
02104
02105 if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
02106 } else {
02107 value = (int32)(size_t)sd->desc.def;
02108 }
02109
02110 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02111 SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
02112 } else {
02113 SetSettingValue(this->valuewindow_entry->d.entry.index, value);
02114 }
02115 this->SetDirty();
02116 }
02117
02118 virtual void OnDropdownSelect(int widget, int index)
02119 {
02120 switch (widget) {
02121 case WID_GS_RESTRICT_DROPDOWN:
02122 this->filter.mode = (RestrictionMode)index;
02123 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
02124 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
02125
02126 if (!this->manually_changed_folding) {
02127
02128 _settings_main_page.UpdateFilterState(this->filter, false);
02129 _settings_main_page.UnFoldAll();
02130 }
02131 } else {
02132
02133 _settings_client.gui.settings_restriction_mode = this->filter.mode;
02134 }
02135 this->InvalidateData();
02136 break;
02137
02138 case WID_GS_TYPE_DROPDOWN:
02139 this->filter.type = (SettingType)index;
02140 this->InvalidateData();
02141 break;
02142
02143 default:
02144 if (widget < 0) {
02145
02146 assert(this->valuedropdown_entry != NULL);
02147 const SettingDesc *sd = this->valuedropdown_entry->d.entry.setting;
02148 assert(sd->desc.flags & SGF_MULTISTRING);
02149
02150 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02151 SetCompanySetting(this->valuedropdown_entry->d.entry.index, index);
02152 } else {
02153 SetSettingValue(this->valuedropdown_entry->d.entry.index, index);
02154 }
02155
02156 this->SetDirty();
02157 }
02158 break;
02159 }
02160 }
02161
02162 virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
02163 {
02164 if (widget >= 0) {
02165
02166
02167
02168
02169 Window::OnDropdownClose(pt, widget, index, instant_close);
02170 } else {
02171
02172
02173
02174
02175 assert(this->valuedropdown_entry != NULL);
02176 this->closing_dropdown = true;
02177 this->SetDirty();
02178 }
02179 }
02180
02181 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
02182 {
02183 if (!gui_scope) return;
02184
02185 _settings_main_page.UpdateFilterState(this->filter, false);
02186
02187 this->vscroll->SetCount(_settings_main_page.Length());
02188
02189 if (this->last_clicked != NULL && !_settings_main_page.IsVisible(this->last_clicked)) {
02190 this->SetDisplayedHelpText(NULL);
02191 }
02192
02193 bool all_folded = true;
02194 bool all_unfolded = true;
02195 _settings_main_page.GetFoldingState(all_folded, all_unfolded);
02196 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
02197 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
02198 }
02199
02200 virtual void OnEditboxChanged(int wid)
02201 {
02202 if (wid == WID_GS_FILTER) {
02203 this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
02204 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
02205
02206
02207 _settings_main_page.UnFoldAll();
02208 }
02209 this->InvalidateData();
02210 }
02211 }
02212
02213 virtual void OnResize()
02214 {
02215 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
02216 }
02217 };
02218
02219 GameSettings *GameSettingsWindow::settings_ptr = NULL;
02220
02221 static const NWidgetPart _nested_settings_selection_widgets[] = {
02222 NWidget(NWID_HORIZONTAL),
02223 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
02224 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02225 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
02226 EndContainer(),
02227 NWidget(WWT_PANEL, COLOUR_MAUVE),
02228 NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
02229 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
02230 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_LABEL), SetDataTip(STR_CONFIG_SETTING_RESTRICT_LABEL, STR_NULL),
02231 NWidget(NWID_VERTICAL), SetPIP(0, WD_PAR_VSEP_NORMAL, 0),
02232 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),
02233 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),
02234 EndContainer(),
02235 EndContainer(),
02236 NWidget(NWID_HORIZONTAL), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM, 0),
02237 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
02238 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE, STR_NULL),
02239 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_GS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
02240 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
02241 EndContainer(),
02242 EndContainer(),
02243 NWidget(NWID_HORIZONTAL),
02244 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
02245 NWidget(NWID_VERTICAL),
02246 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
02247 EndContainer(),
02248 EndContainer(),
02249 NWidget(WWT_PANEL, COLOUR_MAUVE), SetMinimalSize(400, 40),
02250 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
02251 SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
02252 NWidget(NWID_HORIZONTAL),
02253 NWidget(WWT_PANEL, COLOUR_MAUVE),
02254 NWidget(NWID_HORIZONTAL),
02255 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
02256 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
02257 NWidget(NWID_SPACER, INVALID_COLOUR), SetFill(1, 1), SetResize(1, 0),
02258 EndContainer(),
02259 EndContainer(),
02260 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
02261 EndContainer(),
02262 EndContainer(),
02263 };
02264
02265 static WindowDesc _settings_selection_desc(
02266 WDP_CENTER, "settings", 510, 450,
02267 WC_GAME_OPTIONS, WC_NONE,
02268 0,
02269 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
02270 );
02271
02273 void ShowGameSettings()
02274 {
02275 DeleteWindowByClass(WC_GAME_OPTIONS);
02276 new GameSettingsWindow(&_settings_selection_desc);
02277 }
02278
02279
02289 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
02290 {
02291 int colour = _colour_gradient[button_colour][2];
02292
02293 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
02294 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);
02295 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
02296 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP);
02297
02298
02299 bool rtl = _current_text_dir == TD_RTL;
02300 if (rtl ? !clickable_right : !clickable_left) {
02301 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02302 }
02303 if (rtl ? !clickable_left : !clickable_right) {
02304 GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02305 }
02306 }
02307
02316 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
02317 {
02318 static const char *DOWNARROW = "\xEE\x8A\xAA";
02319
02320 int colour = _colour_gradient[button_colour][2];
02321
02322 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE);
02323 DrawString(x + (state ? 1 : 0), x + SETTING_BUTTON_WIDTH - (state ? 0 : 1), y + (state ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
02324
02325 if (!clickable) {
02326 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02327 }
02328 }
02329
02337 void DrawBoolButton(int x, int y, bool state, bool clickable)
02338 {
02339 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
02340 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
02341 }
02342
02343 struct CustomCurrencyWindow : Window {
02344 int query_widget;
02345
02346 CustomCurrencyWindow(WindowDesc *desc) : Window(desc)
02347 {
02348 this->InitNested();
02349
02350 SetButtonState();
02351 }
02352
02353 void SetButtonState()
02354 {
02355 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
02356 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
02357 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
02358 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
02359 }
02360
02361 virtual void SetStringParameters(int widget) const
02362 {
02363 switch (widget) {
02364 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
02365 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
02366 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
02367 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
02368 case WID_CC_YEAR:
02369 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
02370 SetDParam(1, _custom_currency.to_euro);
02371 break;
02372
02373 case WID_CC_PREVIEW:
02374 SetDParam(0, 10000);
02375 break;
02376 }
02377 }
02378
02379 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
02380 {
02381 switch (widget) {
02382
02383 case WID_CC_SEPARATOR_EDIT:
02384 case WID_CC_PREFIX_EDIT:
02385 case WID_CC_SUFFIX_EDIT:
02386 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
02387 break;
02388
02389
02390 case WID_CC_RATE:
02391 SetDParam(0, 1);
02392 SetDParam(1, INT32_MAX);
02393 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
02394 break;
02395 }
02396 }
02397
02398 virtual void OnClick(Point pt, int widget, int click_count)
02399 {
02400 int line = 0;
02401 int len = 0;
02402 StringID str = 0;
02403 CharSetFilter afilter = CS_ALPHANUMERAL;
02404
02405 switch (widget) {
02406 case WID_CC_RATE_DOWN:
02407 if (_custom_currency.rate > 1) _custom_currency.rate--;
02408 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
02409 this->EnableWidget(WID_CC_RATE_UP);
02410 break;
02411
02412 case WID_CC_RATE_UP:
02413 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
02414 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
02415 this->EnableWidget(WID_CC_RATE_DOWN);
02416 break;
02417
02418 case WID_CC_RATE:
02419 SetDParam(0, _custom_currency.rate);
02420 str = STR_JUST_INT;
02421 len = 5;
02422 line = WID_CC_RATE;
02423 afilter = CS_NUMERAL;
02424 break;
02425
02426 case WID_CC_SEPARATOR_EDIT:
02427 case WID_CC_SEPARATOR:
02428 SetDParamStr(0, _custom_currency.separator);
02429 str = STR_JUST_RAW_STRING;
02430 len = 1;
02431 line = WID_CC_SEPARATOR;
02432 break;
02433
02434 case WID_CC_PREFIX_EDIT:
02435 case WID_CC_PREFIX:
02436 SetDParamStr(0, _custom_currency.prefix);
02437 str = STR_JUST_RAW_STRING;
02438 len = 12;
02439 line = WID_CC_PREFIX;
02440 break;
02441
02442 case WID_CC_SUFFIX_EDIT:
02443 case WID_CC_SUFFIX:
02444 SetDParamStr(0, _custom_currency.suffix);
02445 str = STR_JUST_RAW_STRING;
02446 len = 12;
02447 line = WID_CC_SUFFIX;
02448 break;
02449
02450 case WID_CC_YEAR_DOWN:
02451 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
02452 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
02453 this->EnableWidget(WID_CC_YEAR_UP);
02454 break;
02455
02456 case WID_CC_YEAR_UP:
02457 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
02458 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
02459 this->EnableWidget(WID_CC_YEAR_DOWN);
02460 break;
02461
02462 case WID_CC_YEAR:
02463 SetDParam(0, _custom_currency.to_euro);
02464 str = STR_JUST_INT;
02465 len = 7;
02466 line = WID_CC_YEAR;
02467 afilter = CS_NUMERAL;
02468 break;
02469 }
02470
02471 if (len != 0) {
02472 this->query_widget = line;
02473 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
02474 }
02475
02476 this->SetTimeout();
02477 this->SetDirty();
02478 }
02479
02480 virtual void OnQueryTextFinished(char *str)
02481 {
02482 if (str == NULL) return;
02483
02484 switch (this->query_widget) {
02485 case WID_CC_RATE:
02486 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
02487 break;
02488
02489 case WID_CC_SEPARATOR:
02490 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
02491 break;
02492
02493 case WID_CC_PREFIX:
02494 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
02495 break;
02496
02497 case WID_CC_SUFFIX:
02498 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
02499 break;
02500
02501 case WID_CC_YEAR: {
02502 int val = atoi(str);
02503
02504 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
02505 break;
02506 }
02507 }
02508 MarkWholeScreenDirty();
02509 SetButtonState();
02510 }
02511
02512 virtual void OnTimeout()
02513 {
02514 this->SetDirty();
02515 }
02516 };
02517
02518 static const NWidgetPart _nested_cust_currency_widgets[] = {
02519 NWidget(NWID_HORIZONTAL),
02520 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
02521 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02522 EndContainer(),
02523 NWidget(WWT_PANEL, COLOUR_GREY),
02524 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
02525 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02526 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
02527 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
02528 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02529 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
02530 EndContainer(),
02531 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02532 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
02533 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02534 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
02535 EndContainer(),
02536 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02537 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
02538 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02539 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
02540 EndContainer(),
02541 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02542 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
02543 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02544 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
02545 EndContainer(),
02546 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02547 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02548 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02549 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02550 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
02551 EndContainer(),
02552 EndContainer(),
02553 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
02554 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
02555 EndContainer(),
02556 };
02557
02558 static WindowDesc _cust_currency_desc(
02559 WDP_CENTER, NULL, 0, 0,
02560 WC_CUSTOM_CURRENCY, WC_NONE,
02561 0,
02562 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
02563 );
02564
02566 static void ShowCustCurrency()
02567 {
02568 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
02569 new CustomCurrencyWindow(&_cust_currency_desc);
02570 }