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
00039
00040
00041 static const StringID _units_dropdown[] = {
00042 STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL,
00043 STR_GAME_OPTIONS_MEASURING_UNITS_METRIC,
00044 STR_GAME_OPTIONS_MEASURING_UNITS_SI,
00045 INVALID_STRING_ID
00046 };
00047
00048 static const StringID _driveside_dropdown[] = {
00049 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
00050 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
00051 INVALID_STRING_ID
00052 };
00053
00054 static const StringID _autosave_dropdown[] = {
00055 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
00056 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
00057 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
00058 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
00059 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
00060 INVALID_STRING_ID,
00061 };
00062
00063 int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1;
00064 static StringID *_grf_names = NULL;
00065 static int _nb_grf_names = 0;
00066
00068 void InitGRFTownGeneratorNames()
00069 {
00070 free(_grf_names);
00071 _grf_names = GetGRFTownNameList();
00072 _nb_grf_names = 0;
00073 for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
00074 }
00075
00081 static inline StringID TownName(int town_name)
00082 {
00083 if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
00084 town_name -= _nb_orig_names;
00085 if (town_name < _nb_grf_names) return _grf_names[town_name];
00086 return STR_UNDEFINED;
00087 }
00088
00093 static int GetCurRes()
00094 {
00095 int i;
00096
00097 for (i = 0; i != _num_resolutions; i++) {
00098 if ((int)_resolutions[i].width == _screen.width &&
00099 (int)_resolutions[i].height == _screen.height) {
00100 break;
00101 }
00102 }
00103 return i;
00104 }
00105
00106 static void ShowCustCurrency();
00107
00108 template <class T>
00109 static DropDownList *BuiltSetDropDownList(int *selected_index)
00110 {
00111 int n = T::GetNumSets();
00112 *selected_index = T::GetIndexOfUsedSet();
00113
00114 DropDownList *list = new DropDownList();
00115 for (int i = 0; i < n; i++) {
00116 list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)));
00117 }
00118
00119 return list;
00120 }
00121
00123 template <class TBaseSet>
00124 struct BaseSetTextfileWindow : public TextfileWindow {
00125 const TBaseSet* baseset;
00126 StringID content_type;
00127
00128 BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
00129 {
00130 const char *textfile = this->baseset->GetTextfile(file_type);
00131 this->LoadTextfile(textfile, BASESET_DIR);
00132 }
00133
00134 void SetStringParameters(int widget) const
00135 {
00136 if (widget == WID_TF_CAPTION) {
00137 SetDParam(0, content_type);
00138 SetDParamStr(1, this->baseset->name);
00139 }
00140 }
00141 };
00142
00149 template <class TBaseSet>
00150 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
00151 {
00152 DeleteWindowByClass(WC_TEXTFILE);
00153 new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
00154 }
00155
00156 struct GameOptionsWindow : Window {
00157 GameSettings *opt;
00158 bool reload;
00159
00160 GameOptionsWindow(const WindowDesc *desc) : Window()
00161 {
00162 this->opt = &GetGameSettings();
00163 this->reload = false;
00164
00165 this->InitNested(desc, WN_GAME_OPTIONS_GAME_OPTIONS);
00166 this->OnInvalidateData(0);
00167 }
00168
00169 ~GameOptionsWindow()
00170 {
00171 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
00172 if (this->reload) _switch_mode = SM_MENU;
00173 }
00174
00181 DropDownList *BuildDropDownList(int widget, int *selected_index) const
00182 {
00183 DropDownList *list = NULL;
00184 switch (widget) {
00185 case WID_GO_CURRENCY_DROPDOWN: {
00186 list = new DropDownList();
00187 *selected_index = this->opt->locale.currency;
00188 StringID *items = BuildCurrencyDropdown();
00189 uint disabled = _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies();
00190 int custom_index = -1;
00191
00192
00193 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00194 if (*items == STR_GAME_OPTIONS_CURRENCY_CUSTOM) {
00195 custom_index = i;
00196 } else {
00197 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00198 }
00199 }
00200 list->sort(DropDownListStringItem::NatSortFunc);
00201
00202
00203 if (custom_index >= 0) {
00204 list->push_back(new DropDownListItem(-1, false));
00205 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, custom_index, HasBit(disabled, custom_index)));
00206 }
00207 break;
00208 }
00209
00210 case WID_GO_DISTANCE_DROPDOWN: {
00211 list = new DropDownList();
00212 *selected_index = this->opt->locale.units;
00213 const StringID *items = _units_dropdown;
00214 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00215 list->push_back(new DropDownListStringItem(*items, i, false));
00216 }
00217 break;
00218 }
00219
00220 case WID_GO_ROADSIDE_DROPDOWN: {
00221 list = new DropDownList();
00222 *selected_index = this->opt->vehicle.road_side;
00223 const StringID *items = _driveside_dropdown;
00224 uint disabled = 0;
00225
00226
00227
00228 extern bool RoadVehiclesAreBuilt();
00229 if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
00230 disabled = ~(1 << this->opt->vehicle.road_side);
00231 }
00232
00233 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00234 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00235 }
00236 break;
00237 }
00238
00239 case WID_GO_TOWNNAME_DROPDOWN: {
00240 list = new DropDownList();
00241 *selected_index = this->opt->game_creation.town_name;
00242
00243 int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
00244
00245
00246 for (int i = 0; i < _nb_orig_names; i++) {
00247 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
00248 }
00249 list->sort(DropDownListStringItem::NatSortFunc);
00250
00251
00252 DropDownList newgrf_names;
00253 for (int i = 0; i < _nb_grf_names; i++) {
00254 int result = _nb_orig_names + i;
00255 newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
00256 }
00257 newgrf_names.sort(DropDownListStringItem::NatSortFunc);
00258
00259
00260 if (newgrf_names.size() > 0) {
00261 newgrf_names.push_back(new DropDownListItem(-1, false));
00262 list->splice(list->begin(), newgrf_names);
00263 }
00264 break;
00265 }
00266
00267 case WID_GO_AUTOSAVE_DROPDOWN: {
00268 list = new DropDownList();
00269 *selected_index = _settings_client.gui.autosave;
00270 const StringID *items = _autosave_dropdown;
00271 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00272 list->push_back(new DropDownListStringItem(*items, i, false));
00273 }
00274 break;
00275 }
00276
00277 case WID_GO_LANG_DROPDOWN: {
00278 list = new DropDownList();
00279 for (uint i = 0; i < _languages.Length(); i++) {
00280 if (&_languages[i] == _current_language) *selected_index = i;
00281 list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
00282 }
00283 list->sort(DropDownListStringItem::NatSortFunc);
00284 break;
00285 }
00286
00287 case WID_GO_RESOLUTION_DROPDOWN:
00288 list = new DropDownList();
00289 *selected_index = GetCurRes();
00290 for (int i = 0; i < _num_resolutions; i++) {
00291 list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
00292 }
00293 break;
00294
00295 case WID_GO_SCREENSHOT_DROPDOWN:
00296 list = new DropDownList();
00297 *selected_index = _cur_screenshot_format;
00298 for (uint i = 0; i < _num_screenshot_formats; i++) {
00299 if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
00300 list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false));
00301 }
00302 break;
00303
00304 case WID_GO_BASE_GRF_DROPDOWN:
00305 list = BuiltSetDropDownList<BaseGraphics>(selected_index);
00306 break;
00307
00308 case WID_GO_BASE_SFX_DROPDOWN:
00309 list = BuiltSetDropDownList<BaseSounds>(selected_index);
00310 break;
00311
00312 case WID_GO_BASE_MUSIC_DROPDOWN:
00313 list = BuiltSetDropDownList<BaseMusic>(selected_index);
00314 break;
00315
00316 default:
00317 return NULL;
00318 }
00319
00320 return list;
00321 }
00322
00323 virtual void SetStringParameters(int widget) const
00324 {
00325 switch (widget) {
00326 case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
00327 case WID_GO_DISTANCE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL + this->opt->locale.units); break;
00328 case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
00329 case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
00330 case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
00331 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
00332 case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
00333 case WID_GO_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
00334 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
00335 case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
00336 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
00337 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
00338 case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
00339 }
00340 }
00341
00342 virtual void DrawWidget(const Rect &r, int widget) const
00343 {
00344 switch (widget) {
00345 case WID_GO_BASE_GRF_DESCRIPTION:
00346 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00347 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00348 break;
00349
00350 case WID_GO_BASE_SFX_DESCRIPTION:
00351 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00352 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00353 break;
00354
00355 case WID_GO_BASE_MUSIC_DESCRIPTION:
00356 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00357 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00358 break;
00359 }
00360 }
00361
00362 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00363 {
00364 switch (widget) {
00365 case WID_GO_BASE_GRF_DESCRIPTION:
00366
00367 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00368 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00369 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00370 }
00371 break;
00372
00373 case WID_GO_BASE_GRF_STATUS:
00374
00375 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00376 uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
00377 if (invalid_files == 0) continue;
00378
00379 SetDParam(0, invalid_files);
00380 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
00381 }
00382 break;
00383
00384 case WID_GO_BASE_SFX_DESCRIPTION:
00385
00386 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
00387 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00388 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00389 }
00390 break;
00391
00392 case WID_GO_BASE_MUSIC_DESCRIPTION:
00393
00394 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00395 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00396 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00397 }
00398 break;
00399
00400 case WID_GO_BASE_MUSIC_STATUS:
00401
00402 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00403 uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
00404 if (invalid_files == 0) continue;
00405
00406 SetDParam(0, invalid_files);
00407 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
00408 }
00409 break;
00410
00411 default: {
00412 int selected;
00413 DropDownList *list = this->BuildDropDownList(widget, &selected);
00414 if (list != NULL) {
00415
00416 for (DropDownList::iterator it = list->begin(); it != list->end(); it++) {
00417 static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
00418 Dimension string_dim;
00419 int width = (*it)->Width();
00420 string_dim.width = width + extra.width;
00421 string_dim.height = (*it)->Height(width) + extra.height;
00422 *size = maxdim(*size, string_dim);
00423 delete *it;
00424 }
00425 delete list;
00426 }
00427 }
00428 }
00429 }
00430
00431 virtual void OnClick(Point pt, int widget, int click_count)
00432 {
00433 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
00434 if (BaseGraphics::GetUsedSet() == NULL) return;
00435
00436 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
00437 return;
00438 }
00439 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
00440 if (BaseSounds::GetUsedSet() == NULL) return;
00441
00442 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
00443 return;
00444 }
00445 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
00446 if (BaseMusic::GetUsedSet() == NULL) return;
00447
00448 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
00449 return;
00450 }
00451 switch (widget) {
00452 case WID_GO_FULLSCREEN_BUTTON:
00453
00454 if (!ToggleFullScreen(!_fullscreen)) {
00455 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
00456 }
00457 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00458 this->SetDirty();
00459 break;
00460
00461 default: {
00462 int selected;
00463 DropDownList *list = this->BuildDropDownList(widget, &selected);
00464 if (list != NULL) {
00465 ShowDropDownList(this, list, selected, widget);
00466 }
00467 break;
00468 }
00469 }
00470 }
00471
00477 template <class T>
00478 void SetMediaSet(int index)
00479 {
00480 if (_game_mode == GM_MENU) {
00481 const char *name = T::GetSet(index)->name;
00482
00483 free(T::ini_set);
00484 T::ini_set = strdup(name);
00485
00486 T::SetSet(name);
00487 this->reload = true;
00488 this->InvalidateData();
00489 }
00490 }
00491
00492 virtual void OnDropdownSelect(int widget, int index)
00493 {
00494 switch (widget) {
00495 case WID_GO_CURRENCY_DROPDOWN:
00496 if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
00497 this->opt->locale.currency = index;
00498 ReInitAllWindows();
00499 break;
00500
00501 case WID_GO_DISTANCE_DROPDOWN:
00502 this->opt->locale.units = index;
00503 MarkWholeScreenDirty();
00504 break;
00505
00506 case WID_GO_ROADSIDE_DROPDOWN:
00507 if (this->opt->vehicle.road_side != index) {
00508 uint i;
00509 if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
00510 SetSettingValue(i, index);
00511 MarkWholeScreenDirty();
00512 }
00513 break;
00514
00515 case WID_GO_TOWNNAME_DROPDOWN:
00516 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
00517 this->opt->game_creation.town_name = index;
00518 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00519 }
00520 break;
00521
00522 case WID_GO_AUTOSAVE_DROPDOWN:
00523 _settings_client.gui.autosave = index;
00524 this->SetDirty();
00525 break;
00526
00527 case WID_GO_LANG_DROPDOWN:
00528 ReadLanguagePack(&_languages[index]);
00529 DeleteWindowByClass(WC_QUERY_STRING);
00530 CheckForMissingGlyphs();
00531 UpdateAllVirtCoords();
00532 ReInitAllWindows();
00533 break;
00534
00535 case WID_GO_RESOLUTION_DROPDOWN:
00536 if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
00537 this->SetDirty();
00538 }
00539 break;
00540
00541 case WID_GO_SCREENSHOT_DROPDOWN:
00542 SetScreenshotFormat(index);
00543 this->SetDirty();
00544 break;
00545
00546 case WID_GO_BASE_GRF_DROPDOWN:
00547 this->SetMediaSet<BaseGraphics>(index);
00548 break;
00549
00550 case WID_GO_BASE_SFX_DROPDOWN:
00551 this->SetMediaSet<BaseSounds>(index);
00552 break;
00553
00554 case WID_GO_BASE_MUSIC_DROPDOWN:
00555 this->SetMediaSet<BaseMusic>(index);
00556 break;
00557 }
00558 }
00559
00565 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00566 {
00567 if (!gui_scope) return;
00568 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00569
00570 bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
00571 this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
00572
00573 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
00574 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
00575 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
00576 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
00577 }
00578
00579 missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
00580 this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
00581 }
00582 };
00583
00584 static const NWidgetPart _nested_game_options_widgets[] = {
00585 NWidget(NWID_HORIZONTAL),
00586 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00587 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00588 EndContainer(),
00589 NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
00590 NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
00591 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00592 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
00593 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),
00594 EndContainer(),
00595 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
00596 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),
00597 EndContainer(),
00598 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
00599 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),
00600 EndContainer(),
00601 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
00602 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),
00603 NWidget(NWID_HORIZONTAL),
00604 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
00605 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
00606 EndContainer(),
00607 EndContainer(),
00608 EndContainer(),
00609
00610 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00611 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_MEASURING_UNITS_FRAME, STR_NULL),
00612 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),
00613 EndContainer(),
00614 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
00615 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),
00616 EndContainer(),
00617 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
00618 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),
00619 EndContainer(),
00620 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT, STR_NULL),
00621 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),
00622 EndContainer(),
00623 NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
00624 EndContainer(),
00625 EndContainer(),
00626
00627 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
00628 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00629 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
00630 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00631 EndContainer(),
00632 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),
00633 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00634 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),
00635 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),
00636 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),
00637 EndContainer(),
00638 EndContainer(),
00639
00640 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
00641 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00642 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
00643 NWidget(NWID_SPACER), SetFill(1, 0),
00644 EndContainer(),
00645 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),
00646 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00647 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),
00648 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),
00649 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),
00650 EndContainer(),
00651 EndContainer(),
00652
00653 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
00654 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00655 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
00656 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00657 EndContainer(),
00658 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),
00659 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
00660 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),
00661 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),
00662 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),
00663 EndContainer(),
00664 EndContainer(),
00665 EndContainer(),
00666 };
00667
00668 static const WindowDesc _game_options_desc(
00669 WDP_CENTER, 0, 0,
00670 WC_GAME_OPTIONS, WC_NONE,
00671 WDF_UNCLICK_BUTTONS,
00672 _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
00673 );
00674
00676 void ShowGameOptions()
00677 {
00678 DeleteWindowByClass(WC_GAME_OPTIONS);
00679 new GameOptionsWindow(&_game_options_desc);
00680 }
00681
00682 extern void StartupEconomy();
00683
00684 void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
00685
00686 class GameDifficultyWindow : public Window {
00687 private:
00688
00689 GameSettings opt_mod_temp;
00690
00691 public:
00693 static const uint GAME_DIFFICULTY_NUM = 18;
00695 static const uint WIDGETS_PER_DIFFICULTY = 3;
00696
00697 GameDifficultyWindow(const WindowDesc *desc) : Window()
00698 {
00699 this->InitNested(desc, WN_GAME_OPTIONS_GAME_DIFFICULTY);
00700
00701
00702
00703 this->SetWidgetsDisabledState(_game_mode != GM_MENU,
00704 WID_GD_LVL_EASY,
00705 WID_GD_LVL_MEDIUM,
00706 WID_GD_LVL_HARD,
00707 WID_GD_LVL_CUSTOM,
00708 WIDGET_LIST_END);
00709 this->SetWidgetDisabledState(WID_GD_HIGHSCORE, _game_mode == GM_EDITOR || _networking);
00710 this->SetWidgetDisabledState(WID_GD_ACCEPT, _networking && !_network_server);
00711
00712
00713 this->OnInvalidateData(GOID_DIFFICULTY_CHANGED);
00714 }
00715
00716 virtual void SetStringParameters(int widget) const
00717 {
00718 widget -= WID_GD_OPTIONS_START;
00719 if (widget < 0 || (widget % 3) != 2) return;
00720
00721 widget /= 3;
00722
00723 uint i;
00724 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + widget;
00725 int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00726 SetDParam(0, sd->desc.str_val + value);
00727 }
00728
00729 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00730 {
00731
00732 int index = widget - WID_GD_OPTIONS_START;
00733 if (index < 0 || (index % 3) != 2) return;
00734
00735 index /= 3;
00736
00737 uint i;
00738 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + index;
00739 const SettingDescBase *sdb = &sd->desc;
00740
00741
00742 StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
00743 for (int32 value = sdb->min; (uint32)value <= sdb->max; value += sdb->interval) {
00744 SetDParam(0, sdb->str_val + value);
00745 *size = maxdim(*size, GetStringBoundingBox(str));
00746 }
00747 }
00748
00749 virtual void OnClick(Point pt, int widget, int click_count)
00750 {
00751 if (widget >= WID_GD_OPTIONS_START) {
00752 widget -= WID_GD_OPTIONS_START;
00753 if ((widget % 3) == 2) return;
00754
00755
00756 if (_networking && !_network_server) return;
00757
00758 uint i;
00759 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + (widget / 3);
00760 const SettingDescBase *sdb = &sd->desc;
00761
00762 int32 val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00763 if (widget % 3 == 1) {
00764
00765 val = min(val + sdb->interval, (int32)sdb->max);
00766 } else {
00767
00768 val -= sdb->interval;
00769 val = max(val, sdb->min);
00770 }
00771
00772
00773 WriteValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv, val);
00774 this->RaiseWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00775 SetDifficultyLevel(3, &this->opt_mod_temp.difficulty);
00776 this->LowerWidget(WID_GD_LVL_CUSTOM);
00777 this->InvalidateData();
00778
00779 if (widget / 3 == 0 &&
00780 AI::GetInfoList()->size() == 0 &&
00781 this->opt_mod_temp.difficulty.max_no_competitors != 0) {
00782 ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
00783 }
00784 return;
00785 }
00786
00787 switch (widget) {
00788 case WID_GD_LVL_EASY:
00789 case WID_GD_LVL_MEDIUM:
00790 case WID_GD_LVL_HARD:
00791 case WID_GD_LVL_CUSTOM:
00792
00793 this->RaiseWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00794 SetDifficultyLevel(widget - WID_GD_LVL_EASY, &this->opt_mod_temp.difficulty);
00795 this->LowerWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00796 this->InvalidateData();
00797 break;
00798
00799 case WID_GD_HIGHSCORE:
00800 ShowHighscoreTable(this->opt_mod_temp.difficulty.diff_level, -1);
00801 break;
00802
00803 case WID_GD_ACCEPT: {
00804 GameSettings *opt_ptr = &GetGameSettings();
00805
00806 uint i;
00807 GetSettingFromName("difficulty.diff_level", &i);
00808 DoCommandP(0, i, this->opt_mod_temp.difficulty.diff_level, CMD_CHANGE_SETTING);
00809
00810 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00811 for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
00812 int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00813 int32 cur_val = (int32)ReadValue(GetVariableAddress(opt_ptr, &sd->save), sd->save.conv);
00814
00815 if (new_val != cur_val) {
00816 DoCommandP(0, i + btn, new_val, CMD_CHANGE_SETTING);
00817 }
00818 }
00819 delete this;
00820
00821
00822
00823 if (_game_mode == GM_EDITOR) StartupEconomy();
00824 break;
00825 }
00826
00827 case WID_GD_CANCEL:
00828 delete this;
00829 break;
00830 }
00831 }
00832
00838 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00839 {
00840 if (!gui_scope) return;
00841
00842 if (data == GOID_DIFFICULTY_CHANGED) {
00843
00844
00845
00846
00847 this->opt_mod_temp = GetGameSettings();
00848
00849 this->LowerWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00850 }
00851
00852 uint i;
00853 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00854 for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {
00855 const SettingDescBase *sdb = &sd->desc;
00856
00857 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
00858 int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00859 bool disable = (sd->desc.flags & SGF_NEWGAME_ONLY) &&
00860 (_game_mode == GM_NORMAL ||
00861 (_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0));
00862
00863 this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 0, disable || sdb->min == value);
00864 this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 1, disable || sdb->max == (uint32)value);
00865 }
00866 }
00867 };
00868
00869 static NWidgetBase *MakeDifficultyOptionsWidgets(int *biggest_index)
00870 {
00871 NWidgetVertical *vert_desc = new NWidgetVertical;
00872
00873 int widnum = WID_GD_OPTIONS_START;
00874 uint i, j;
00875 const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00876
00877 for (i = 0, j = 0; i < GameDifficultyWindow::GAME_DIFFICULTY_NUM; i++, sd++, widnum += GameDifficultyWindow::WIDGETS_PER_DIFFICULTY) {
00878 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
00879
00880 NWidgetHorizontal *hor = new NWidgetHorizontal;
00881
00882
00883 NWidgetLeaf *leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum, AWV_DECREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
00884 hor->Add(leaf);
00885
00886
00887 leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum + 1, AWV_INCREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
00888 hor->Add(leaf);
00889
00890
00891 NWidgetSpacer *spacer = new NWidgetSpacer(5, 0);
00892 hor->Add(spacer);
00893
00894
00895 leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, widnum + 2, STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS + (j++), STR_NULL);
00896 leaf->SetFill(1, 0);
00897 hor->Add(leaf);
00898 vert_desc->Add(hor);
00899
00900
00901 vert_desc->Add(new NWidgetSpacer(0, 2));
00902 }
00903 *biggest_index = widnum - 1;
00904 return vert_desc;
00905 }
00906
00907
00909 static const NWidgetPart _nested_game_difficulty_widgets[] = {
00910 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_DIFFICULTY_LEVEL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00911 NWidget(WWT_PANEL, COLOUR_MAUVE),
00912 NWidget(NWID_VERTICAL), SetPIP(2, 0, 2),
00913 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
00914 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_EASY), SetDataTip(STR_DIFFICULTY_LEVEL_EASY, STR_NULL), SetFill(1, 0),
00915 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_MEDIUM), SetDataTip(STR_DIFFICULTY_LEVEL_MEDIUM, STR_NULL), SetFill(1, 0),
00916 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_HARD), SetDataTip(STR_DIFFICULTY_LEVEL_HARD, STR_NULL), SetFill(1, 0),
00917 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_CUSTOM), SetDataTip(STR_DIFFICULTY_LEVEL_CUSTOM, STR_NULL), SetFill(1, 0),
00918 EndContainer(),
00919 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
00920 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GD_HIGHSCORE), SetDataTip(STR_DIFFICULTY_LEVEL_HIGH_SCORE_BUTTON, STR_NULL), SetFill(1, 0),
00921 EndContainer(),
00922 EndContainer(),
00923 EndContainer(),
00924 NWidget(WWT_PANEL, COLOUR_MAUVE),
00925 NWidget(NWID_VERTICAL), SetPIP(3, 0, 1),
00926 NWidget(NWID_HORIZONTAL), SetPIP(5, 0, 5),
00927 NWidgetFunction(MakeDifficultyOptionsWidgets),
00928 EndContainer(),
00929 EndContainer(),
00930 EndContainer(),
00931 NWidget(WWT_PANEL, COLOUR_MAUVE),
00932 NWidget(NWID_VERTICAL), SetPIP(2, 0, 2),
00933 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
00934 NWidget(NWID_SPACER), SetFill(1, 0),
00935 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GD_ACCEPT), SetDataTip(STR_DIFFICULTY_LEVEL_SAVE, STR_NULL), SetFill(1, 0),
00936 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GD_CANCEL), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), SetFill(1, 0),
00937 NWidget(NWID_SPACER), SetFill(1, 0),
00938 EndContainer(),
00939 EndContainer(),
00940 EndContainer(),
00941 };
00942
00944 static const WindowDesc _game_difficulty_desc(
00945 WDP_CENTER, 0, 0,
00946 WC_GAME_OPTIONS, WC_NONE,
00947 WDF_UNCLICK_BUTTONS,
00948 _nested_game_difficulty_widgets, lengthof(_nested_game_difficulty_widgets)
00949 );
00950
00952 void ShowGameDifficulty()
00953 {
00954 DeleteWindowByClass(WC_GAME_OPTIONS);
00955 new GameDifficultyWindow(&_game_difficulty_desc);
00956 }
00957
00958 static int SETTING_HEIGHT = 11;
00959 static const int LEVEL_WIDTH = 15;
00960
00965 enum SettingEntryFlags {
00966 SEF_LEFT_DEPRESSED = 0x01,
00967 SEF_RIGHT_DEPRESSED = 0x02,
00968 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED),
00969
00970 SEF_LAST_FIELD = 0x04,
00971
00972
00973 SEF_SETTING_KIND = 0x10,
00974 SEF_SUBTREE_KIND = 0x20,
00975 SEF_KIND_MASK = (SEF_SETTING_KIND | SEF_SUBTREE_KIND),
00976 };
00977
00978 struct SettingsPage;
00979
00981 struct SettingEntrySubtree {
00982 SettingsPage *page;
00983 bool folded;
00984 StringID title;
00985 };
00986
00988 struct SettingEntrySetting {
00989 const char *name;
00990 const SettingDesc *setting;
00991 uint index;
00992 };
00993
00995 struct SettingEntry {
00996 byte flags;
00997 byte level;
00998 union {
00999 SettingEntrySetting entry;
01000 SettingEntrySubtree sub;
01001 } d;
01002
01003 SettingEntry(const char *nm);
01004 SettingEntry(SettingsPage *sub, StringID title);
01005
01006 void Init(byte level, bool last_field);
01007 void FoldAll();
01008 void SetButtons(byte new_val);
01009
01010 uint Length() const;
01011 SettingEntry *FindEntry(uint row, uint *cur_row);
01012 uint GetMaxHelpHeight(int maxw);
01013
01014 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);
01015
01020 inline StringID GetHelpText()
01021 {
01022 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01023 return this->d.entry.setting->desc.str_help;
01024 }
01025
01026 void SetValueDParams(uint first_param, int32 value);
01027
01028 private:
01029 void DrawSetting(GameSettings *settings_ptr, int x, int y, int max_x, int state, bool highlight);
01030 };
01031
01033 struct SettingsPage {
01034 SettingEntry *entries;
01035 byte num;
01036
01037 void Init(byte level = 0);
01038 void FoldAll();
01039
01040 uint Length() const;
01041 SettingEntry *FindEntry(uint row, uint *cur_row) const;
01042 uint GetMaxHelpHeight(int maxw);
01043
01044 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;
01045 };
01046
01047
01048
01049
01054 SettingEntry::SettingEntry(const char *nm)
01055 {
01056 this->flags = SEF_SETTING_KIND;
01057 this->level = 0;
01058 this->d.entry.name = nm;
01059 this->d.entry.setting = NULL;
01060 this->d.entry.index = 0;
01061 }
01062
01068 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
01069 {
01070 this->flags = SEF_SUBTREE_KIND;
01071 this->level = 0;
01072 this->d.sub.page = sub;
01073 this->d.sub.folded = true;
01074 this->d.sub.title = title;
01075 }
01076
01082 void SettingEntry::Init(byte level, bool last_field)
01083 {
01084 this->level = level;
01085 if (last_field) this->flags |= SEF_LAST_FIELD;
01086
01087 switch (this->flags & SEF_KIND_MASK) {
01088 case SEF_SETTING_KIND:
01089 this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
01090 assert(this->d.entry.setting != NULL);
01091 break;
01092 case SEF_SUBTREE_KIND:
01093 this->d.sub.page->Init(level + 1);
01094 break;
01095 default: NOT_REACHED();
01096 }
01097 }
01098
01100 void SettingEntry::FoldAll()
01101 {
01102 switch (this->flags & SEF_KIND_MASK) {
01103 case SEF_SETTING_KIND:
01104 break;
01105
01106 case SEF_SUBTREE_KIND:
01107 this->d.sub.folded = true;
01108 this->d.sub.page->FoldAll();
01109 break;
01110
01111 default: NOT_REACHED();
01112 }
01113 }
01114
01115
01121 void SettingEntry::SetButtons(byte new_val)
01122 {
01123 assert((new_val & ~SEF_BUTTONS_MASK) == 0);
01124 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
01125 }
01126
01128 uint SettingEntry::Length() const
01129 {
01130 switch (this->flags & SEF_KIND_MASK) {
01131 case SEF_SETTING_KIND:
01132 return 1;
01133 case SEF_SUBTREE_KIND:
01134 if (this->d.sub.folded) return 1;
01135
01136 return 1 + this->d.sub.page->Length();
01137 default: NOT_REACHED();
01138 }
01139 }
01140
01147 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
01148 {
01149 if (row_num == *cur_row) return this;
01150
01151 switch (this->flags & SEF_KIND_MASK) {
01152 case SEF_SETTING_KIND:
01153 (*cur_row)++;
01154 break;
01155 case SEF_SUBTREE_KIND:
01156 (*cur_row)++;
01157 if (this->d.sub.folded) {
01158 break;
01159 }
01160
01161
01162 return this->d.sub.page->FindEntry(row_num, cur_row);
01163 default: NOT_REACHED();
01164 }
01165 return NULL;
01166 }
01167
01173 uint SettingEntry::GetMaxHelpHeight(int maxw)
01174 {
01175 switch (this->flags & SEF_KIND_MASK) {
01176 case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw);
01177 case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw);
01178 default: NOT_REACHED();
01179 }
01180 }
01181
01209 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)
01210 {
01211 if (cur_row >= max_row) return cur_row;
01212
01213 bool rtl = _current_text_dir == TD_RTL;
01214 int offset = rtl ? -4 : 4;
01215 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
01216
01217 int x = rtl ? right : left;
01218 int y = base_y;
01219 if (cur_row >= first_row) {
01220 int colour = _colour_gradient[COLOUR_ORANGE][4];
01221 y = base_y + (cur_row - first_row) * SETTING_HEIGHT;
01222
01223
01224 for (uint lvl = 0; lvl < this->level; lvl++) {
01225 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
01226 x += level_width;
01227 }
01228
01229 int halfway_y = y + SETTING_HEIGHT / 2;
01230 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
01231 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
01232
01233 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
01234 x += level_width;
01235 }
01236
01237 switch (this->flags & SEF_KIND_MASK) {
01238 case SEF_SETTING_KIND:
01239 if (cur_row >= first_row) {
01240 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK,
01241 this == selected);
01242 }
01243 cur_row++;
01244 break;
01245 case SEF_SUBTREE_KIND:
01246 if (cur_row >= first_row) {
01247 DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
01248 DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
01249 }
01250 cur_row++;
01251 if (!this->d.sub.folded) {
01252 if (this->flags & SEF_LAST_FIELD) {
01253 assert(this->level < sizeof(parent_last));
01254 SetBit(parent_last, this->level);
01255 }
01256
01257 cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, selected, cur_row, parent_last);
01258 }
01259 break;
01260 default: NOT_REACHED();
01261 }
01262 return cur_row;
01263 }
01264
01265 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
01266 {
01267 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01268 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
01269 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
01270 } else {
01271 return GetVariableAddress(&_settings_client.company, &sd->save);
01272 }
01273 } else {
01274 return GetVariableAddress(settings_ptr, &sd->save);
01275 }
01276 }
01277
01283 void SettingEntry::SetValueDParams(uint first_param, int32 value)
01284 {
01285 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01286 const SettingDescBase *sdb = &this->d.entry.setting->desc;
01287 if (sdb->cmd == SDT_BOOLX) {
01288 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
01289 } else {
01290 if ((sdb->flags & SGF_MULTISTRING) != 0) {
01291 SetDParam(first_param++, sdb->str_val - sdb->min + value);
01292 } else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
01293 SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
01294 value = abs(value);
01295 } else {
01296 SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
01297 }
01298 SetDParam(first_param++, value);
01299 }
01300 }
01301
01311 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, int state, bool highlight)
01312 {
01313 const SettingDesc *sd = this->d.entry.setting;
01314 const SettingDescBase *sdb = &sd->desc;
01315 const void *var = ResolveVariableAddress(settings_ptr, sd);
01316 bool editable = true;
01317
01318 bool rtl = _current_text_dir == TD_RTL;
01319 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
01320 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
01321 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
01322 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
01323
01324
01325 if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sdb->flags & SGF_PER_COMPANY)) editable = false;
01326 if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
01327 if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
01328
01329 SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
01330 int32 value = (int32)ReadValue(var, sd->save.conv);
01331 if (sdb->cmd == SDT_BOOLX) {
01332
01333 DrawBoolButton(buttons_left, button_y, value != 0, editable);
01334 } else if ((sdb->flags & SGF_MULTISTRING) != 0) {
01335
01336 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
01337 } else {
01338
01339 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
01340 editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
01341 }
01342 this->SetValueDParams(1, value);
01343 DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
01344 }
01345
01346
01347
01348
01353 void SettingsPage::Init(byte level)
01354 {
01355 for (uint field = 0; field < this->num; field++) {
01356 this->entries[field].Init(level, field + 1 == num);
01357 }
01358 }
01359
01361 void SettingsPage::FoldAll()
01362 {
01363 for (uint field = 0; field < this->num; field++) {
01364 this->entries[field].FoldAll();
01365 }
01366 }
01367
01369 uint SettingsPage::Length() const
01370 {
01371 uint length = 0;
01372 for (uint field = 0; field < this->num; field++) {
01373 length += this->entries[field].Length();
01374 }
01375 return length;
01376 }
01377
01384 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
01385 {
01386 SettingEntry *pe = NULL;
01387
01388 for (uint field = 0; field < this->num; field++) {
01389 pe = this->entries[field].FindEntry(row_num, cur_row);
01390 if (pe != NULL) {
01391 break;
01392 }
01393 }
01394 return pe;
01395 }
01396
01402 uint SettingsPage::GetMaxHelpHeight(int maxw)
01403 {
01404 uint biggest = 0;
01405 for (uint field = 0; field < this->num; field++) {
01406 biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw));
01407 }
01408 return biggest;
01409 }
01410
01429 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
01430 {
01431 if (cur_row >= max_row) return cur_row;
01432
01433 for (uint i = 0; i < this->num; i++) {
01434 cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last, selected);
01435 if (cur_row >= max_row) {
01436 break;
01437 }
01438 }
01439 return cur_row;
01440 }
01441
01442
01443 static SettingEntry _settings_ui_display[] = {
01444 SettingEntry("gui.date_format_in_default_names"),
01445 SettingEntry("gui.population_in_label"),
01446 SettingEntry("gui.measure_tooltip"),
01447 SettingEntry("gui.loading_indicators"),
01448 SettingEntry("gui.liveries"),
01449 SettingEntry("gui.show_track_reservation"),
01450 SettingEntry("gui.expenses_layout"),
01451 SettingEntry("gui.smallmap_land_colour"),
01452 SettingEntry("gui.zoom_min"),
01453 SettingEntry("gui.zoom_max"),
01454 SettingEntry("gui.graph_line_thickness"),
01455 };
01457 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
01458
01459 static SettingEntry _settings_ui_interaction[] = {
01460 SettingEntry("gui.window_snap_radius"),
01461 SettingEntry("gui.window_soft_limit"),
01462 SettingEntry("gui.link_terraform_toolbar"),
01463 SettingEntry("gui.prefer_teamchat"),
01464 SettingEntry("gui.autoscroll"),
01465 SettingEntry("gui.reverse_scroll"),
01466 SettingEntry("gui.smooth_scroll"),
01467 SettingEntry("gui.left_mouse_btn_scrolling"),
01468
01469
01470
01471 SettingEntry("gui.scrollwheel_scrolling"),
01472 SettingEntry("gui.scrollwheel_multiplier"),
01473 #ifdef __APPLE__
01474
01475 SettingEntry("gui.right_mouse_btn_emulation"),
01476 #endif
01477 };
01479 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
01480
01481 static SettingEntry _settings_ui[] = {
01482 SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
01483 SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
01484 SettingEntry("gui.show_finances"),
01485 SettingEntry("gui.errmsg_duration"),
01486 SettingEntry("gui.hover_delay"),
01487 SettingEntry("gui.toolbar_pos"),
01488 SettingEntry("gui.statusbar_pos"),
01489 SettingEntry("gui.newgrf_default_palette"),
01490 SettingEntry("gui.pause_on_newgame"),
01491 SettingEntry("gui.advanced_vehicle_list"),
01492 SettingEntry("gui.timetable_in_ticks"),
01493 SettingEntry("gui.timetable_arrival_departure"),
01494 SettingEntry("gui.quick_goto"),
01495 SettingEntry("gui.default_rail_type"),
01496 SettingEntry("gui.disable_unsuitable_building"),
01497 SettingEntry("gui.persistent_buildingtools"),
01498 SettingEntry("gui.coloured_news_year"),
01499 };
01501 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
01502
01503 static SettingEntry _settings_construction_signals[] = {
01504 SettingEntry("construction.train_signal_side"),
01505 SettingEntry("gui.enable_signal_gui"),
01506 SettingEntry("gui.drag_signals_density"),
01507 SettingEntry("gui.drag_signals_fixed_distance"),
01508 SettingEntry("gui.semaphore_build_before"),
01509 SettingEntry("gui.default_signal_type"),
01510 SettingEntry("gui.cycle_signal_types"),
01511 };
01513 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
01514
01515 static SettingEntry _settings_construction[] = {
01516 SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
01517 SettingEntry("construction.build_on_slopes"),
01518 SettingEntry("construction.autoslope"),
01519 SettingEntry("construction.extra_dynamite"),
01520 SettingEntry("construction.max_bridge_length"),
01521 SettingEntry("construction.max_tunnel_length"),
01522 SettingEntry("station.never_expire_airports"),
01523 SettingEntry("construction.freeform_edges"),
01524 SettingEntry("construction.extra_tree_placement"),
01525 SettingEntry("construction.command_pause_level"),
01526 };
01528 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
01529
01530 static SettingEntry _settings_stations_cargo[] = {
01531 SettingEntry("order.improved_load"),
01532 SettingEntry("order.gradual_loading"),
01533 SettingEntry("order.selectgoods"),
01534 };
01536 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
01537
01538 static SettingEntry _settings_stations[] = {
01539 SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
01540 SettingEntry("station.adjacent_stations"),
01541 SettingEntry("station.distant_join_stations"),
01542 SettingEntry("station.station_spread"),
01543 SettingEntry("economy.station_noise_level"),
01544 SettingEntry("station.modified_catchment"),
01545 SettingEntry("construction.road_stop_on_town_road"),
01546 SettingEntry("construction.road_stop_on_competitor_road"),
01547 };
01549 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
01550
01551 static SettingEntry _settings_economy_towns[] = {
01552 SettingEntry("economy.bribe"),
01553 SettingEntry("economy.exclusive_rights"),
01554 SettingEntry("economy.fund_roads"),
01555 SettingEntry("economy.fund_buildings"),
01556 SettingEntry("economy.town_layout"),
01557 SettingEntry("economy.allow_town_roads"),
01558 SettingEntry("economy.allow_town_level_crossings"),
01559 SettingEntry("economy.found_town"),
01560 SettingEntry("economy.mod_road_rebuild"),
01561 SettingEntry("economy.town_growth_rate"),
01562 SettingEntry("economy.larger_towns"),
01563 SettingEntry("economy.initial_city_size"),
01564 };
01566 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
01567
01568 static SettingEntry _settings_economy_industries[] = {
01569 SettingEntry("construction.raw_industry_construction"),
01570 SettingEntry("construction.industry_platform"),
01571 SettingEntry("economy.multiple_industry_per_town"),
01572 SettingEntry("game_creation.oil_refinery_limit"),
01573 };
01575 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
01576
01577 static SettingEntry _settings_economy_scripts[] = {
01578 SettingEntry("script.script_max_opcode_till_suspend"),
01579 };
01581 static SettingsPage _settings_economy_scripts_page = {_settings_economy_scripts, lengthof(_settings_economy_scripts)};
01582
01583 static SettingEntry _settings_economy[] = {
01584 SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
01585 SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
01586 SettingEntry(&_settings_economy_scripts_page, STR_CONFIG_SETTING_ECONOMY_SCRIPTS),
01587 SettingEntry("economy.inflation"),
01588 SettingEntry("economy.smooth_economy"),
01589 SettingEntry("economy.feeder_payment_share"),
01590 SettingEntry("economy.infrastructure_maintenance"),
01591 };
01593 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
01594
01595 static SettingEntry _settings_linkgraph[] = {
01596 SettingEntry("linkgraph.recalc_interval"),
01597 SettingEntry("linkgraph.distribution_pax"),
01598 SettingEntry("linkgraph.distribution_mail"),
01599 SettingEntry("linkgraph.distribution_armoured"),
01600 SettingEntry("linkgraph.distribution_default"),
01601 SettingEntry("linkgraph.accuracy"),
01602 SettingEntry("linkgraph.demand_distance"),
01603 SettingEntry("linkgraph.demand_size"),
01604 SettingEntry("linkgraph.short_path_saturation"),
01605 };
01607 static SettingsPage _settings_linkgraph_page = {_settings_linkgraph, lengthof(_settings_linkgraph)};
01608
01609 static SettingEntry _settings_ai_npc[] = {
01610 SettingEntry("ai.ai_in_multiplayer"),
01611 SettingEntry("ai.ai_disable_veh_train"),
01612 SettingEntry("ai.ai_disable_veh_roadveh"),
01613 SettingEntry("ai.ai_disable_veh_aircraft"),
01614 SettingEntry("ai.ai_disable_veh_ship"),
01615 };
01617 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
01618
01619 static SettingEntry _settings_ai[] = {
01620 SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
01621 SettingEntry("economy.give_money"),
01622 SettingEntry("economy.allow_shares"),
01623 };
01625 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
01626
01627 static SettingEntry _settings_vehicles_routing[] = {
01628 SettingEntry("pf.pathfinder_for_trains"),
01629 SettingEntry("pf.forbid_90_deg"),
01630 SettingEntry("pf.pathfinder_for_roadvehs"),
01631 SettingEntry("pf.roadveh_queue"),
01632 SettingEntry("pf.pathfinder_for_ships"),
01633 };
01635 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
01636
01637 static SettingEntry _settings_vehicles_autorenew[] = {
01638 SettingEntry("company.engine_renew"),
01639 SettingEntry("company.engine_renew_months"),
01640 SettingEntry("company.engine_renew_money"),
01641 };
01643 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
01644
01645 static SettingEntry _settings_vehicles_servicing[] = {
01646 SettingEntry("vehicle.servint_ispercent"),
01647 SettingEntry("vehicle.servint_trains"),
01648 SettingEntry("vehicle.servint_roadveh"),
01649 SettingEntry("vehicle.servint_ships"),
01650 SettingEntry("vehicle.servint_aircraft"),
01651 SettingEntry("order.no_servicing_if_no_breakdowns"),
01652 SettingEntry("order.serviceathelipad"),
01653 };
01655 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
01656
01657 static SettingEntry _settings_vehicles_trains[] = {
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 struct GameSettingsWindow : Window {
01708 static const int SETTINGTREE_LEFT_OFFSET = 5;
01709 static const int SETTINGTREE_RIGHT_OFFSET = 5;
01710 static const int SETTINGTREE_TOP_OFFSET = 5;
01711 static const int SETTINGTREE_BOTTOM_OFFSET = 5;
01712
01713 static GameSettings *settings_ptr;
01714
01715 SettingEntry *valuewindow_entry;
01716 SettingEntry *clicked_entry;
01717 SettingEntry *last_clicked;
01718 SettingEntry *valuedropdown_entry;
01719 bool closing_dropdown;
01720
01721 Scrollbar *vscroll;
01722
01723 GameSettingsWindow(const WindowDesc *desc) : Window()
01724 {
01725 static bool first_time = true;
01726
01727 settings_ptr = &GetGameSettings();
01728
01729
01730 if (first_time) {
01731 _settings_main_page.Init();
01732 first_time = false;
01733 } else {
01734 _settings_main_page.FoldAll();
01735 }
01736
01737 this->valuewindow_entry = NULL;
01738 this->clicked_entry = NULL;
01739 this->last_clicked = NULL;
01740 this->valuedropdown_entry = NULL;
01741 this->closing_dropdown = false;
01742
01743 this->CreateNestedTree(desc);
01744 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
01745 this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
01746
01747 this->vscroll->SetCount(_settings_main_page.Length());
01748 }
01749
01750 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01751 {
01752 switch (widget) {
01753 case WID_GS_OPTIONSPANEL:
01754 resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
01755 resize->width = 1;
01756
01757 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
01758 break;
01759
01760 case WID_GS_HELP_TEXT: {
01761 static const StringID setting_types[] = {
01762 STR_CONFIG_SETTING_TYPE_CLIENT,
01763 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
01764 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
01765 };
01766 for (uint i = 0; i < lengthof(setting_types); i++) {
01767 SetDParam(0, setting_types[i]);
01768 size->width = max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width);
01769 }
01770 size->height = 2 * FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL +
01771 max(size->height, _settings_main_page.GetMaxHelpHeight(size->width));
01772 break;
01773 }
01774
01775 default:
01776 break;
01777 }
01778 }
01779
01780 virtual void OnPaint()
01781 {
01782 if (this->closing_dropdown) {
01783 this->closing_dropdown = false;
01784 assert(this->valuedropdown_entry != NULL);
01785 this->valuedropdown_entry->SetButtons(0);
01786 this->valuedropdown_entry = NULL;
01787 }
01788 this->DrawWidgets();
01789 }
01790
01791 virtual void DrawWidget(const Rect &r, int widget) const
01792 {
01793 switch (widget) {
01794 case WID_GS_OPTIONSPANEL:
01795 _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
01796 this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->last_clicked);
01797 break;
01798
01799 case WID_GS_HELP_TEXT:
01800 if (this->last_clicked != NULL) {
01801 const SettingDesc *sd = this->last_clicked->d.entry.setting;
01802
01803 int y = r.top;
01804 if (sd->desc.flags & SGF_PER_COMPANY) {
01805 SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME);
01806 } else if (sd->save.conv & SLF_NOT_IN_SAVE) {
01807 SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT);
01808 } else {
01809 SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME);
01810 }
01811 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
01812 y += FONT_HEIGHT_NORMAL;
01813
01814 int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
01815 this->last_clicked->SetValueDParams(0, default_value);
01816 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
01817 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
01818
01819 DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
01820 }
01821 break;
01822
01823 default:
01824 break;
01825 }
01826 }
01827
01832 void SetDisplayedHelpText(SettingEntry *pe)
01833 {
01834 if (this->last_clicked != pe) this->SetDirty();
01835 this->last_clicked = pe;
01836 }
01837
01838 virtual void OnClick(Point pt, int widget, int click_count)
01839 {
01840 if (widget != WID_GS_OPTIONSPANEL) return;
01841
01842 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
01843 if (btn == INT_MAX) return;
01844
01845 uint cur_row = 0;
01846 SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
01847
01848 if (pe == NULL) return;
01849
01850 int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;
01851 if (x < 0) return;
01852
01853 if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
01854 this->SetDisplayedHelpText(NULL);
01855 pe->d.sub.folded = !pe->d.sub.folded;
01856
01857 this->vscroll->SetCount(_settings_main_page.Length());
01858 this->SetDirty();
01859 return;
01860 }
01861
01862 assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01863 const SettingDesc *sd = pe->d.entry.setting;
01864
01865
01866 if ((!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sd->desc.flags & SGF_PER_COMPANY)) ||
01867 ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) || ((sd->desc.flags & SGF_NO_NETWORK) && _networking)) {
01868 this->SetDisplayedHelpText(pe);
01869 return;
01870 }
01871
01872 const void *var = ResolveVariableAddress(settings_ptr, sd);
01873 int32 value = (int32)ReadValue(var, sd->save.conv);
01874
01875
01876 if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
01877 const SettingDescBase *sdb = &sd->desc;
01878 this->SetDisplayedHelpText(pe);
01879
01880 if (this->valuedropdown_entry == pe) {
01881
01882 HideDropDownMenu(this);
01883 this->closing_dropdown = false;
01884 this->valuedropdown_entry->SetButtons(0);
01885 this->valuedropdown_entry = NULL;
01886 } else {
01887 if (this->valuedropdown_entry != NULL) this->valuedropdown_entry->SetButtons(0);
01888 this->closing_dropdown = false;
01889
01890 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
01891 int rel_y = (pt.y - (int)wid->pos_y - SETTINGTREE_TOP_OFFSET) % wid->resize_y;
01892
01893 Rect wi_rect;
01894 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
01895 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
01896 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
01897 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
01898
01899
01900 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
01901 this->valuedropdown_entry = pe;
01902 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
01903
01904 DropDownList *list = new DropDownList();
01905 for (int i = sdb->min; i <= (int)sdb->max; i++) {
01906 list->push_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
01907 }
01908
01909 ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true);
01910 }
01911 }
01912 this->SetDirty();
01913 } else if (x < SETTING_BUTTON_WIDTH) {
01914 this->SetDisplayedHelpText(pe);
01915 const SettingDescBase *sdb = &sd->desc;
01916 int32 oldvalue = value;
01917
01918 switch (sdb->cmd) {
01919 case SDT_BOOLX: value ^= 1; break;
01920 case SDT_ONEOFMANY:
01921 case SDT_NUMX: {
01922
01923
01924
01925
01926 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
01927 if (step == 0) step = 1;
01928
01929
01930 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
01931 _left_button_clicked = false;
01932 return;
01933 }
01934
01935
01936 if (x >= SETTING_BUTTON_WIDTH / 2) {
01937 value += step;
01938 if (sdb->min < 0) {
01939 assert((int32)sdb->max >= 0);
01940 if (value > (int32)sdb->max) value = (int32)sdb->max;
01941 } else {
01942 if ((uint32)value > sdb->max) value = (int32)sdb->max;
01943 }
01944 if (value < sdb->min) value = sdb->min;
01945 } else {
01946 value -= step;
01947 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
01948 }
01949
01950
01951 if (value != oldvalue) {
01952 if (this->clicked_entry != NULL) {
01953 this->clicked_entry->SetButtons(0);
01954 }
01955 this->clicked_entry = pe;
01956 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
01957 this->SetTimeout();
01958 _left_button_clicked = false;
01959 }
01960 break;
01961 }
01962
01963 default: NOT_REACHED();
01964 }
01965
01966 if (value != oldvalue) {
01967 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01968 SetCompanySetting(pe->d.entry.index, value);
01969 } else {
01970 SetSettingValue(pe->d.entry.index, value);
01971 }
01972 this->SetDirty();
01973 }
01974 } else {
01975
01976 if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
01977
01978 if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
01979
01980 this->valuewindow_entry = pe;
01981 SetDParam(0, value);
01982 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
01983 }
01984 this->SetDisplayedHelpText(pe);
01985 }
01986 }
01987
01988 virtual void OnTimeout()
01989 {
01990 if (this->clicked_entry != NULL) {
01991 this->clicked_entry->SetButtons(0);
01992 this->clicked_entry = NULL;
01993 this->SetDirty();
01994 }
01995 }
01996
01997 virtual void OnQueryTextFinished(char *str)
01998 {
01999
02000 if (str == NULL) return;
02001
02002 assert(this->valuewindow_entry != NULL);
02003 assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
02004 const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
02005
02006 int32 value;
02007 if (!StrEmpty(str)) {
02008 value = atoi(str);
02009
02010
02011 if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
02012 } else {
02013 value = (int32)(size_t)sd->desc.def;
02014 }
02015
02016 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02017 SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
02018 } else {
02019 SetSettingValue(this->valuewindow_entry->d.entry.index, value);
02020 }
02021 this->SetDirty();
02022 }
02023
02024 virtual void OnDropdownSelect(int widget, int index)
02025 {
02026 assert(this->valuedropdown_entry != NULL);
02027 const SettingDesc *sd = this->valuedropdown_entry->d.entry.setting;
02028 assert(sd->desc.flags & SGF_MULTISTRING);
02029
02030 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
02031 SetCompanySetting(this->valuedropdown_entry->d.entry.index, index);
02032 } else {
02033 SetSettingValue(this->valuedropdown_entry->d.entry.index, index);
02034 }
02035
02036 this->SetDirty();
02037 }
02038
02039 virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
02040 {
02041
02042
02043
02044
02045 assert(this->valuedropdown_entry != NULL);
02046 this->closing_dropdown = true;
02047 this->SetDirty();
02048 }
02049
02050 virtual void OnResize()
02051 {
02052 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
02053 }
02054 };
02055
02056 GameSettings *GameSettingsWindow::settings_ptr = NULL;
02057
02058 static const NWidgetPart _nested_settings_selection_widgets[] = {
02059 NWidget(NWID_HORIZONTAL),
02060 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
02061 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02062 EndContainer(),
02063 NWidget(NWID_HORIZONTAL),
02064 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
02065 NWidget(NWID_VERTICAL),
02066 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
02067 EndContainer(),
02068 EndContainer(),
02069 NWidget(WWT_PANEL, COLOUR_MAUVE), SetMinimalSize(400, 40),
02070 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
02071 SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
02072 NWidget(NWID_HORIZONTAL),
02073 NWidget(NWID_SPACER, INVALID_COLOUR), SetFill(1, 1), SetResize(1, 0),
02074 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
02075 EndContainer(),
02076 EndContainer(),
02077 };
02078
02079 static const WindowDesc _settings_selection_desc(
02080 WDP_CENTER, 510, 450,
02081 WC_GAME_OPTIONS, WC_NONE,
02082 0,
02083 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
02084 );
02085
02087 void ShowGameSettings()
02088 {
02089 DeleteWindowByClass(WC_GAME_OPTIONS);
02090 new GameSettingsWindow(&_settings_selection_desc);
02091 }
02092
02093
02103 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
02104 {
02105 int colour = _colour_gradient[button_colour][2];
02106
02107 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
02108 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);
02109 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
02110 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP);
02111
02112
02113 bool rtl = _current_text_dir == TD_RTL;
02114 if (rtl ? !clickable_right : !clickable_left) {
02115 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02116 }
02117 if (rtl ? !clickable_left : !clickable_right) {
02118 GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02119 }
02120 }
02121
02130 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
02131 {
02132 static const char *DOWNARROW = "\xEE\x8A\xAA";
02133
02134 int colour = _colour_gradient[button_colour][2];
02135
02136 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE);
02137 DrawString(x + (state ? 1 : 0), x + SETTING_BUTTON_WIDTH - (state ? 0 : 1), y + (state ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
02138
02139 if (!clickable) {
02140 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
02141 }
02142 }
02143
02151 void DrawBoolButton(int x, int y, bool state, bool clickable)
02152 {
02153 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
02154 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
02155 }
02156
02157 struct CustomCurrencyWindow : Window {
02158 int query_widget;
02159
02160 CustomCurrencyWindow(const WindowDesc *desc) : Window()
02161 {
02162 this->InitNested(desc);
02163
02164 SetButtonState();
02165 }
02166
02167 void SetButtonState()
02168 {
02169 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
02170 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
02171 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
02172 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
02173 }
02174
02175 virtual void SetStringParameters(int widget) const
02176 {
02177 switch (widget) {
02178 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
02179 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
02180 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
02181 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
02182 case WID_CC_YEAR:
02183 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
02184 SetDParam(1, _custom_currency.to_euro);
02185 break;
02186
02187 case WID_CC_PREVIEW:
02188 SetDParam(0, 10000);
02189 break;
02190 }
02191 }
02192
02193 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
02194 {
02195 switch (widget) {
02196
02197 case WID_CC_SEPARATOR_EDIT:
02198 case WID_CC_PREFIX_EDIT:
02199 case WID_CC_SUFFIX_EDIT:
02200 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
02201 break;
02202
02203
02204 case WID_CC_RATE:
02205 SetDParam(0, 1);
02206 SetDParam(1, INT32_MAX);
02207 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
02208 break;
02209 }
02210 }
02211
02212 virtual void OnClick(Point pt, int widget, int click_count)
02213 {
02214 int line = 0;
02215 int len = 0;
02216 StringID str = 0;
02217 CharSetFilter afilter = CS_ALPHANUMERAL;
02218
02219 switch (widget) {
02220 case WID_CC_RATE_DOWN:
02221 if (_custom_currency.rate > 1) _custom_currency.rate--;
02222 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
02223 this->EnableWidget(WID_CC_RATE_UP);
02224 break;
02225
02226 case WID_CC_RATE_UP:
02227 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
02228 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
02229 this->EnableWidget(WID_CC_RATE_DOWN);
02230 break;
02231
02232 case WID_CC_RATE:
02233 SetDParam(0, _custom_currency.rate);
02234 str = STR_JUST_INT;
02235 len = 5;
02236 line = WID_CC_RATE;
02237 afilter = CS_NUMERAL;
02238 break;
02239
02240 case WID_CC_SEPARATOR_EDIT:
02241 case WID_CC_SEPARATOR:
02242 SetDParamStr(0, _custom_currency.separator);
02243 str = STR_JUST_RAW_STRING;
02244 len = 1;
02245 line = WID_CC_SEPARATOR;
02246 break;
02247
02248 case WID_CC_PREFIX_EDIT:
02249 case WID_CC_PREFIX:
02250 SetDParamStr(0, _custom_currency.prefix);
02251 str = STR_JUST_RAW_STRING;
02252 len = 12;
02253 line = WID_CC_PREFIX;
02254 break;
02255
02256 case WID_CC_SUFFIX_EDIT:
02257 case WID_CC_SUFFIX:
02258 SetDParamStr(0, _custom_currency.suffix);
02259 str = STR_JUST_RAW_STRING;
02260 len = 12;
02261 line = WID_CC_SUFFIX;
02262 break;
02263
02264 case WID_CC_YEAR_DOWN:
02265 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
02266 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
02267 this->EnableWidget(WID_CC_YEAR_UP);
02268 break;
02269
02270 case WID_CC_YEAR_UP:
02271 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
02272 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
02273 this->EnableWidget(WID_CC_YEAR_DOWN);
02274 break;
02275
02276 case WID_CC_YEAR:
02277 SetDParam(0, _custom_currency.to_euro);
02278 str = STR_JUST_INT;
02279 len = 7;
02280 line = WID_CC_YEAR;
02281 afilter = CS_NUMERAL;
02282 break;
02283 }
02284
02285 if (len != 0) {
02286 this->query_widget = line;
02287 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
02288 }
02289
02290 this->SetTimeout();
02291 this->SetDirty();
02292 }
02293
02294 virtual void OnQueryTextFinished(char *str)
02295 {
02296 if (str == NULL) return;
02297
02298 switch (this->query_widget) {
02299 case WID_CC_RATE:
02300 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
02301 break;
02302
02303 case WID_CC_SEPARATOR:
02304 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
02305 break;
02306
02307 case WID_CC_PREFIX:
02308 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
02309 break;
02310
02311 case WID_CC_SUFFIX:
02312 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
02313 break;
02314
02315 case WID_CC_YEAR: {
02316 int val = atoi(str);
02317
02318 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
02319 break;
02320 }
02321 }
02322 MarkWholeScreenDirty();
02323 SetButtonState();
02324 }
02325
02326 virtual void OnTimeout()
02327 {
02328 this->SetDirty();
02329 }
02330 };
02331
02332 static const NWidgetPart _nested_cust_currency_widgets[] = {
02333 NWidget(NWID_HORIZONTAL),
02334 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
02335 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02336 EndContainer(),
02337 NWidget(WWT_PANEL, COLOUR_GREY),
02338 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
02339 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02340 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
02341 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
02342 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02343 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
02344 EndContainer(),
02345 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02346 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
02347 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02348 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
02349 EndContainer(),
02350 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02351 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
02352 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02353 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
02354 EndContainer(),
02355 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02356 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
02357 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02358 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
02359 EndContainer(),
02360 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02361 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02362 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02363 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02364 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
02365 EndContainer(),
02366 EndContainer(),
02367 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
02368 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
02369 EndContainer(),
02370 };
02371
02372 static const WindowDesc _cust_currency_desc(
02373 WDP_CENTER, 0, 0,
02374 WC_CUSTOM_CURRENCY, WC_NONE,
02375 WDF_UNCLICK_BUTTONS,
02376 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
02377 );
02378
02380 static void ShowCustCurrency()
02381 {
02382 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
02383 new CustomCurrencyWindow(&_cust_currency_desc);
02384 }