src/settings_gui.cpp
branchNewGRF_ports
changeset 10991 d8811e327d12
parent 10731 67db0d431d5e
child 10994 cd9968b6f96b
equal deleted inserted replaced
10731:67db0d431d5e 10991:d8811e327d12
   140 }
   140 }
   141 
   141 
   142 static void ShowCustCurrency();
   142 static void ShowCustCurrency();
   143 
   143 
   144 struct GameOptionsWindow : Window {
   144 struct GameOptionsWindow : Window {
   145 	Settings *opt;
   145 	GameSettings *opt;
   146 
   146 
   147 	GameOptionsWindow(const WindowDesc *desc) : Window(desc)
   147 	GameOptionsWindow(const WindowDesc *desc) : Window(desc)
   148 	{
   148 	{
   149 		this->opt = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings;
   149 		this->opt = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
   150 		this->FindWindowPlacementAndResize(desc);
   150 		this->FindWindowPlacementAndResize(desc);
   151 	}
   151 	}
   152 
   152 
   153 	~GameOptionsWindow()
   153 	~GameOptionsWindow()
   154 	{
   154 	{
   160 		StringID str = STR_02BE_DEFAULT;
   160 		StringID str = STR_02BE_DEFAULT;
   161 
   161 
   162 		this->SetWidgetDisabledState(GAMEOPT_VEHICLENAME_SAVE, !(_vehicle_design_names & 1));
   162 		this->SetWidgetDisabledState(GAMEOPT_VEHICLENAME_SAVE, !(_vehicle_design_names & 1));
   163 		if (!this->IsWidgetDisabled(GAMEOPT_VEHICLENAME_SAVE)) str = STR_02BF_CUSTOM;
   163 		if (!this->IsWidgetDisabled(GAMEOPT_VEHICLENAME_SAVE)) str = STR_02BF_CUSTOM;
   164 		SetDParam(0, str);
   164 		SetDParam(0, str);
   165 		SetDParam(1, _currency_specs[this->opt->gui.currency].name);
   165 		SetDParam(1, _currency_specs[this->opt->locale.currency].name);
   166 		SetDParam(2, STR_UNITS_IMPERIAL + this->opt->gui.units);
   166 		SetDParam(2, STR_UNITS_IMPERIAL + this->opt->locale.units);
   167 		SetDParam(3, STR_02E9_DRIVE_ON_LEFT + this->opt->vehicle.road_side);
   167 		SetDParam(3, STR_02E9_DRIVE_ON_LEFT + this->opt->vehicle.road_side);
   168 		SetDParam(4, TownName(this->opt->game_creation.town_name));
   168 		SetDParam(4, TownName(this->opt->game_creation.town_name));
   169 		SetDParam(5, _autosave_dropdown[this->opt->gui.autosave]);
   169 		SetDParam(5, _autosave_dropdown[_settings_client.gui.autosave]);
   170 		SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr);
   170 		SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr);
   171 		int i = GetCurRes();
   171 		int i = GetCurRes();
   172 		SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i);
   172 		SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i);
   173 		SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
   173 		SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
   174 		this->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen);
   174 		this->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen);
   179 
   179 
   180 	virtual void OnClick(Point pt, int widget)
   180 	virtual void OnClick(Point pt, int widget)
   181 	{
   181 	{
   182 		switch (widget) {
   182 		switch (widget) {
   183 			case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown
   183 			case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown
   184 				ShowDropDownMenu(this, BuildCurrencyDropdown(), this->opt->gui.currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
   184 				ShowDropDownMenu(this, BuildCurrencyDropdown(), this->opt->locale.currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
   185 				break;
   185 				break;
   186 
   186 
   187 			case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown
   187 			case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown
   188 				ShowDropDownMenu(this, _units_dropdown, this->opt->gui.units, GAMEOPT_DISTANCE_BTN, 0, 0);
   188 				ShowDropDownMenu(this, _units_dropdown, this->opt->locale.units, GAMEOPT_DISTANCE_BTN, 0, 0);
   189 				break;
   189 				break;
   190 
   190 
   191 			case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown
   191 			case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown
   192 				int i = 0;
   192 				int i = 0;
   193 				extern bool RoadVehiclesAreBuilt();
   193 				extern bool RoadVehiclesAreBuilt();
   204 			case GAMEOPT_TOWNNAME_BTN: // Setup townname dropdown
   204 			case GAMEOPT_TOWNNAME_BTN: // Setup townname dropdown
   205 				ShowTownnameDropdown(this, this->opt->game_creation.town_name);
   205 				ShowTownnameDropdown(this, this->opt->game_creation.town_name);
   206 				break;
   206 				break;
   207 
   207 
   208 			case GAMEOPT_AUTOSAVE_BTN: // Setup autosave dropdown
   208 			case GAMEOPT_AUTOSAVE_BTN: // Setup autosave dropdown
   209 				ShowDropDownMenu(this, _autosave_dropdown, this->opt->gui.autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0);
   209 				ShowDropDownMenu(this, _autosave_dropdown, _settings_client.gui.autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0);
   210 				break;
   210 				break;
   211 
   211 
   212 			case GAMEOPT_VEHICLENAME_BTN: // Setup customized vehicle-names dropdown
   212 			case GAMEOPT_VEHICLENAME_BTN: // Setup customized vehicle-names dropdown
   213 				ShowDropDownMenu(this, _designnames_dropdown, (_vehicle_design_names & 1) ? 1 : 0, GAMEOPT_VEHICLENAME_BTN, (_vehicle_design_names & 2) ? 0 : 2, 0);
   213 				ShowDropDownMenu(this, _designnames_dropdown, (_vehicle_design_names & 1) ? 1 : 0, GAMEOPT_VEHICLENAME_BTN, (_vehicle_design_names & 2) ? 0 : 2, 0);
   214 				break;
   214 				break;
   263 				}
   263 				}
   264 				break;
   264 				break;
   265 
   265 
   266 			case GAMEOPT_CURRENCY_BTN: /* Currency */
   266 			case GAMEOPT_CURRENCY_BTN: /* Currency */
   267 				if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
   267 				if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
   268 				this->opt->gui.currency = index;
   268 				this->opt->locale.currency = index;
   269 				MarkWholeScreenDirty();
   269 				MarkWholeScreenDirty();
   270 				break;
   270 				break;
   271 
   271 
   272 			case GAMEOPT_DISTANCE_BTN: // Measuring units
   272 			case GAMEOPT_DISTANCE_BTN: // Measuring units
   273 				this->opt->gui.units = index;
   273 				this->opt->locale.units = index;
   274 				MarkWholeScreenDirty();
   274 				MarkWholeScreenDirty();
   275 				break;
   275 				break;
   276 
   276 
   277 			case GAMEOPT_ROADSIDE_BTN: // Road side
   277 			case GAMEOPT_ROADSIDE_BTN: // Road side
   278 				if (this->opt->vehicle.road_side != index) { // only change if setting changed
   278 				if (this->opt->vehicle.road_side != index) { // only change if setting changed
   287 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   287 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   288 				}
   288 				}
   289 				break;
   289 				break;
   290 
   290 
   291 			case GAMEOPT_AUTOSAVE_BTN: // Autosave options
   291 			case GAMEOPT_AUTOSAVE_BTN: // Autosave options
   292 				_settings.gui.autosave = _settings_newgame.gui.autosave = index;
   292 				_settings_client.gui.autosave = index;
   293 				this->SetDirty();
   293 				this->SetDirty();
   294 				break;
   294 				break;
   295 
   295 
   296 			case GAMEOPT_LANG_BTN: // Change interface language
   296 			case GAMEOPT_LANG_BTN: // Change interface language
   297 				ReadLanguagePack(index);
   297 				ReadLanguagePack(index);
   396 	bool clicked_increase;
   396 	bool clicked_increase;
   397 	uint8 clicked_button;
   397 	uint8 clicked_button;
   398 	uint8 timeout;
   398 	uint8 timeout;
   399 
   399 
   400 	/* Temporary holding place of values in the difficulty window until 'Save' is clicked */
   400 	/* Temporary holding place of values in the difficulty window until 'Save' is clicked */
   401 	Settings opt_mod_temp;
   401 	GameSettings opt_mod_temp;
   402 
   402 
   403 	enum {
   403 	enum {
   404 		GAMEDIFF_WND_TOP_OFFSET = 45,
   404 		GAMEDIFF_WND_TOP_OFFSET = 45,
   405 		GAMEDIFF_WND_ROWSIZE    = 9,
   405 		GAMEDIFF_WND_ROWSIZE    = 9,
   406 		NO_SETTINGS_BUTTON = 0xFF,
   406 		NO_SETTINGS_BUTTON = 0xFF,
   425 public:
   425 public:
   426 	GameDifficultyWindow() : Window(&_game_difficulty_desc)
   426 	GameDifficultyWindow() : Window(&_game_difficulty_desc)
   427 	{
   427 	{
   428 		/* Copy current settings (ingame or in intro) to temporary holding place
   428 		/* Copy current settings (ingame or in intro) to temporary holding place
   429 		 * change that when setting stuff, copy back on clicking 'OK' */
   429 		 * change that when setting stuff, copy back on clicking 'OK' */
   430 		this->opt_mod_temp = (_game_mode == GM_MENU) ? _settings_newgame : _settings;
   430 		this->opt_mod_temp = (_game_mode == GM_MENU) ? _settings_newgame : _settings_game;
   431 		this->clicked_increase = false;
   431 		this->clicked_increase = false;
   432 		this->clicked_button = NO_SETTINGS_BUTTON;
   432 		this->clicked_button = NO_SETTINGS_BUTTON;
   433 		this->timeout = 0;
   433 		this->timeout = 0;
   434 		/* Hide the closebox to make sure that the user aborts or confirms his changes */
   434 		/* Hide the closebox to make sure that the user aborts or confirms his changes */
   435 		this->HideWidget(GDW_CLOSEBOX);
   435 		this->HideWidget(GDW_CLOSEBOX);
   535 			case GDW_HIGHSCORE: // Highscore Table
   535 			case GDW_HIGHSCORE: // Highscore Table
   536 				ShowHighscoreTable(this->opt_mod_temp.difficulty.diff_level, -1);
   536 				ShowHighscoreTable(this->opt_mod_temp.difficulty.diff_level, -1);
   537 				break;
   537 				break;
   538 
   538 
   539 			case GDW_ACCEPT: { // Save button - save changes
   539 			case GDW_ACCEPT: { // Save button - save changes
   540 				Settings *opt_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings;
   540 				GameSettings *opt_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
   541 
   541 
   542 				uint i;
   542 				uint i;
   543 				const SettingDesc *sd = GetPatchFromName("difficulty.max_no_competitors", &i);
   543 				const SettingDesc *sd = GetPatchFromName("difficulty.max_no_competitors", &i);
   544 				for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
   544 				for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
   545 					int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
   545 					int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
   736 	PATCHSEL_ECONOMY,
   736 	PATCHSEL_ECONOMY,
   737 	PATCHSEL_COMPETITORS
   737 	PATCHSEL_COMPETITORS
   738 };
   738 };
   739 
   739 
   740 struct PatchesSelectionWindow : Window {
   740 struct PatchesSelectionWindow : Window {
   741 	static Settings *patches_ptr;
   741 	static GameSettings *patches_ptr;
   742 	static int patches_max;
   742 	static int patches_max;
   743 
   743 
   744 	int page;
   744 	int page;
   745 	int entry;
   745 	int entry;
   746 	int click;
   746 	int click;
   747 
   747 
   748 	PatchesSelectionWindow(const WindowDesc *desc) : Window(desc)
   748 	PatchesSelectionWindow(const WindowDesc *desc) : Window(desc)
   749 	{
   749 	{
   750 		static bool first_time = true;
   750 		static bool first_time = true;
   751 
   751 
   752 		patches_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings;
   752 		patches_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
   753 
   753 
   754 		/* Build up the dynamic settings-array only once per OpenTTD session */
   754 		/* Build up the dynamic settings-array only once per OpenTTD session */
   755 		if (first_time) {
   755 		if (first_time) {
   756 			PatchPage *page;
   756 			PatchPage *page;
   757 			for (page = &_patches_page[0]; page != endof(_patches_page); page++) {
   757 			for (page = &_patches_page[0]; page != endof(_patches_page); page++) {
   910 					} break;
   910 					} break;
   911 					default: NOT_REACHED();
   911 					default: NOT_REACHED();
   912 					}
   912 					}
   913 
   913 
   914 					if (value != oldvalue) {
   914 					if (value != oldvalue) {
   915 						SetPatchValue(page->entries[btn].index, patches_ptr, value);
   915 						SetPatchValue(page->entries[btn].index, value);
   916 						this->SetDirty();
   916 						this->SetDirty();
   917 					}
   917 					}
   918 				} else {
   918 				} else {
   919 					/* only open editbox for types that its sensible for */
   919 					/* only open editbox for types that its sensible for */
   920 					if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
   920 					if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
   953 			int32 value = atoi(str);
   953 			int32 value = atoi(str);
   954 
   954 
   955 			/* Save the correct currency-translated value */
   955 			/* Save the correct currency-translated value */
   956 			if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
   956 			if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
   957 
   957 
   958 			SetPatchValue(pe->index, patches_ptr, value);
   958 			SetPatchValue(pe->index, value);
   959 			this->SetDirty();
   959 			this->SetDirty();
   960 		}
   960 		}
   961 	}
   961 	}
   962 };
   962 };
   963 
   963 
   964 Settings *PatchesSelectionWindow::patches_ptr = NULL;
   964 GameSettings *PatchesSelectionWindow::patches_ptr = NULL;
   965 int PatchesSelectionWindow::patches_max = 0;
   965 int PatchesSelectionWindow::patches_max = 0;
   966 
   966 
   967 static const Widget _patches_selection_widgets[] = {
   967 static const Widget _patches_selection_widgets[] = {
   968 {   WWT_CLOSEBOX,   RESIZE_NONE,    10,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
   968 {   WWT_CLOSEBOX,   RESIZE_NONE,    10,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
   969 {    WWT_CAPTION,   RESIZE_NONE,    10,    11,   369,     0,    13, STR_CONFIG_PATCHES_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   969 {    WWT_CAPTION,   RESIZE_NONE,    10,    11,   369,     0,    13, STR_CONFIG_PATCHES_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},