src/settings_gui.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6704 1d7e67bc3f7c
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file settings_gui.cpp */
     2 
     4 
     3 #include "stdafx.h"
     5 #include "stdafx.h"
     4 #include "openttd.h"
     6 #include "openttd.h"
     5 #include "currency.h"
     7 #include "currency.h"
     6 #include "functions.h"
     8 #include "functions.h"
   111 		SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
   113 		SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
   112 		SetWindowWidgetLoweredState(w, 28, _fullscreen);
   114 		SetWindowWidgetLoweredState(w, 28, _fullscreen);
   113 
   115 
   114 		DrawWindowWidgets(w);
   116 		DrawWindowWidgets(w);
   115 		DrawString(20, 175, STR_OPTIONS_FULLSCREEN, 0); // fullscreen
   117 		DrawString(20, 175, STR_OPTIONS_FULLSCREEN, 0); // fullscreen
   116 	}	break;
   118 	} break;
   117 
   119 
   118 	case WE_CLICK:
   120 	case WE_CLICK:
   119 		switch (e->we.click.widget) {
   121 		switch (e->we.click.widget) {
   120 		case 4: case 5: /* Setup currencies dropdown */
   122 		case 4: case 5: /* Setup currencies dropdown */
   121 			ShowDropDownMenu(w, BuildCurrencyDropdown(), _opt_ptr->currency, 5, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);;
   123 			ShowDropDownMenu(w, BuildCurrencyDropdown(), _opt_ptr->currency, 5, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);;
   199 			_opt.autosave = _opt_newgame.autosave = e->we.dropdown.index;
   201 			_opt.autosave = _opt_newgame.autosave = e->we.dropdown.index;
   200 			SetWindowDirty(w);
   202 			SetWindowDirty(w);
   201 			break;
   203 			break;
   202 		case 24: /* Change interface language */
   204 		case 24: /* Change interface language */
   203 			ReadLanguagePack(e->we.dropdown.index);
   205 			ReadLanguagePack(e->we.dropdown.index);
       
   206 			UpdateAllStationVirtCoord();
   204 			MarkWholeScreenDirty();
   207 			MarkWholeScreenDirty();
   205 			break;
   208 			break;
   206 		case 27: /* Change resolution */
   209 		case 27: /* Change resolution */
   207 			if (e->we.dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->we.dropdown.index][0],_resolutions[e->we.dropdown.index][1]))
   210 			if (e->we.dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->we.dropdown.index][0],_resolutions[e->we.dropdown.index][1]))
   208 				SetWindowDirty(w);
   211 				SetWindowDirty(w);
   221 
   224 
   222 }
   225 }
   223 
   226 
   224 /** Change the side of the road vehicles drive on (server only).
   227 /** Change the side of the road vehicles drive on (server only).
   225  * @param tile unused
   228  * @param tile unused
       
   229  * @param flags operation to perform
   226  * @param p1 the side of the road; 0 = left side and 1 = right side
   230  * @param p1 the side of the road; 0 = left side and 1 = right side
   227  * @param p2 unused
   231  * @param p2 unused
   228  */
   232  */
   229 int32 CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   233 int32 CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   230 {
   234 {
   303 };
   307 };
   304 
   308 
   305 static const GameSettingData _game_setting_info[] = {
   309 static const GameSettingData _game_setting_info[] = {
   306 	{  0,   7,  1, STR_NULL},
   310 	{  0,   7,  1, STR_NULL},
   307 	{  0,   3,  1, STR_6830_IMMEDIATE},
   311 	{  0,   3,  1, STR_6830_IMMEDIATE},
   308 	{  0,   2,  1, STR_6816_LOW},
   312 	{  0,   3,  1, STR_NUM_VERY_LOW},
   309 	{  0,   3,  1, STR_26816_NONE},
   313 	{  0,   4,  1, STR_26816_NONE},
   310 	{100, 500, 50, STR_NULL},
   314 	{100, 500, 50, STR_NULL},
   311 	{  2,   4,  1, STR_NULL},
   315 	{  2,   4,  1, STR_NULL},
   312 	{  0,   2,  1, STR_6820_LOW},
   316 	{  0,   2,  1, STR_6820_LOW},
   313 	{  0,   4,  1, STR_681B_VERY_SLOW},
   317 	{  0,   4,  1, STR_681B_VERY_SLOW},
   314 	{  0,   2,  1, STR_6820_LOW},
   318 	{  0,   2,  1, STR_6820_LOW},
   321 	{  0,   1,  1, STR_6834_AT_END_OF_LINE_AND_AT_STATIONS},
   325 	{  0,   1,  1, STR_6834_AT_END_OF_LINE_AND_AT_STATIONS},
   322 	{  0,   1,  1, STR_6836_OFF},
   326 	{  0,   1,  1, STR_6836_OFF},
   323 	{  0,   2,  1, STR_6839_PERMISSIVE},
   327 	{  0,   2,  1, STR_6839_PERMISSIVE},
   324 };
   328 };
   325 
   329 
   326 static inline bool GetBitAndShift(uint32 *b)
       
   327 {
       
   328 	uint32 x = *b;
       
   329 	*b >>= 1;
       
   330 	return HASBIT(x, 0);
       
   331 }
       
   332 
       
   333 /*
   330 /*
   334  * A: competitors
   331  * A: competitors
   335  * B: start time in months / 3
   332  * B: start time in months / 3
   336  * C: town count (2 = high, 0 = low)
   333  * C: town count (2 = high, 0 = very low)
   337  * D: industry count (3 = high, 0 = none)
   334  * D: industry count (4 = high, 0 = none)
   338  * E: inital loan / 1000 (in GBP)
   335  * E: inital loan / 1000 (in GBP)
   339  * F: interest rate
   336  * F: interest rate
   340  * G: running costs (0 = low, 2 = high)
   337  * G: running costs (0 = low, 2 = high)
   341  * H: construction speed of competitors (0 = very slow, 4 = very fast)
   338  * H: construction speed of competitors (0 = very slow, 4 = very fast)
   342  * I: intelligence (0-2)
   339  * I: intelligence (0-2)
   350  * Q: disasters
   347  * Q: disasters
   351  * R: area restructuring (0 = permissive, 2 = hostile)
   348  * R: area restructuring (0 = permissive, 2 = hostile)
   352  */
   349  */
   353 static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = { /*
   350 static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = { /*
   354 	 A, B, C, D,   E, F, G, H, I, J, K, L, M, N, O, P, Q, R*/
   351 	 A, B, C, D,   E, F, G, H, I, J, K, L, M, N, O, P, Q, R*/
   355 	{2, 2, 1, 3, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, //easy
   352 	{2, 2, 1, 4, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, ///< easy
   356 	{4, 1, 1, 2, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, //medium
   353 	{4, 1, 1, 3, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, ///< medium
   357 	{7, 0, 2, 2, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2}, //hard
   354 	{7, 0, 0, 2, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2}, ///< hard
   358 };
   355 };
   359 
   356 
   360 void SetDifficultyLevel(int mode, GameOptions *gm_opt)
   357 void SetDifficultyLevel(int mode, GameOptions *gm_opt)
   361 {
   358 {
   362 	int i;
   359 	int i;
   391 enum {
   388 enum {
   392 	GAMEDIFF_WND_TOP_OFFSET = 45,
   389 	GAMEDIFF_WND_TOP_OFFSET = 45,
   393 	GAMEDIFF_WND_ROWSIZE    = 9
   390 	GAMEDIFF_WND_ROWSIZE    = 9
   394 };
   391 };
   395 
   392 
   396 // Temporary holding place of values in the difficulty window until 'Save' is clicked
   393 /* Temporary holding place of values in the difficulty window until 'Save' is clicked */
   397 static GameOptions _opt_mod_temp;
   394 static GameOptions _opt_mod_temp;
   398 // 0x383E = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1)
   395 // 0x383E = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1)
   399 #define DIFF_INGAME_DISABLED_BUTTONS 0x383E
   396 #define DIFF_INGAME_DISABLED_BUTTONS 0x383E
   400 
   397 
   401 static void GameDifficultyWndProc(Window *w, WindowEvent *e)
   398 static void GameDifficultyWndProc(Window *w, WindowEvent *e)
   426 		 * that bit is set. If it is set, the button is disabled */
   423 		 * that bit is set. If it is set, the button is disabled */
   427 		disabled = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0;
   424 		disabled = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0;
   428 
   425 
   429 		y = GAMEDIFF_WND_TOP_OFFSET;
   426 		y = GAMEDIFF_WND_TOP_OFFSET;
   430 		for (i = 0; i != GAME_DIFFICULTY_NUM; i++) {
   427 		for (i = 0; i != GAME_DIFFICULTY_NUM; i++) {
   431 			DrawFrameRect( 5, y,  5 + 8, y + 8, 3, GetBitAndShift(&click_a) ? FR_LOWERED : FR_NONE);
   428 			DrawFrameRect( 5, y,  5 + 8, y + 8, 3, HASBIT(click_a, i) ? FR_LOWERED : FR_NONE);
   432 			DrawFrameRect(15, y, 15 + 8, y + 8, 3, GetBitAndShift(&click_b) ? FR_LOWERED : FR_NONE);
   429 			DrawFrameRect(15, y, 15 + 8, y + 8, 3, HASBIT(click_b, i) ? FR_LOWERED : FR_NONE);
   433 			if (GetBitAndShift(&disabled) || (_networking && !_network_server)) {
   430 			if (HASBIT(disabled, i) || (_networking && !_network_server)) {
   434 				int color = (1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[COLOUR_YELLOW][2];
   431 				int color = (1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[COLOUR_YELLOW][2];
   435 				GfxFillRect( 6, y + 1,  6 + 8, y + 8, color);
   432 				GfxFillRect( 6, y + 1,  6 + 8, y + 8, color);
   436 				GfxFillRect(16, y + 1, 16 + 8, y + 8, color);
   433 				GfxFillRect(16, y + 1, 16 + 8, y + 8, color);
   437 			}
   434 			}
   438 
   435 
   455 			const GameSettingData *info;
   452 			const GameSettingData *info;
   456 			int x, y;
   453 			int x, y;
   457 			uint btn, dis;
   454 			uint btn, dis;
   458 			int16 val;
   455 			int16 val;
   459 
   456 
   460 			// Don't allow clients to make any changes
   457 			/* Don't allow clients to make any changes */
   461 			if  (_networking && !_network_server)
   458 			if  (_networking && !_network_server)
   462 				return;
   459 				return;
   463 
   460 
   464 			x = e->we.click.pt.x - 5;
   461 			x = e->we.click.pt.x - 5;
   465 			if (!IS_INT_INSIDE(x, 0, 21)) // Button area
   462 			if (!IS_INT_INSIDE(x, 0, 21)) // Button area
   467 
   464 
   468 			y = e->we.click.pt.y - GAMEDIFF_WND_TOP_OFFSET;
   465 			y = e->we.click.pt.y - GAMEDIFF_WND_TOP_OFFSET;
   469 			if (y < 0)
   466 			if (y < 0)
   470 				return;
   467 				return;
   471 
   468 
   472 			// Get button from Y coord.
   469 			/* Get button from Y coord. */
   473 			btn = y / (GAMEDIFF_WND_ROWSIZE + 2);
   470 			btn = y / (GAMEDIFF_WND_ROWSIZE + 2);
   474 			if (btn >= GAME_DIFFICULTY_NUM || y % (GAMEDIFF_WND_ROWSIZE + 2) >= 9)
   471 			if (btn >= GAME_DIFFICULTY_NUM || y % (GAMEDIFF_WND_ROWSIZE + 2) >= 9)
   475 				return;
   472 				return;
   476 
   473 
   477 			// Clicked disabled button?
   474 			/* Clicked disabled button? */
   478 			dis = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0;
   475 			dis = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0;
   479 
   476 
   480 			if (HASBIT(dis, btn))
   477 			if (HASBIT(dis, btn))
   481 				return;
   478 				return;
   482 
   479 
   496 				SETBIT(_difficulty_click_a, btn);
   493 				SETBIT(_difficulty_click_a, btn);
   497 			}
   494 			}
   498 
   495 
   499 			// save value in temporary variable
   496 			// save value in temporary variable
   500 			((int*)&_opt_mod_temp.diff)[btn] = val;
   497 			((int*)&_opt_mod_temp.diff)[btn] = val;
       
   498 			RaiseWindowWidget(w, _opt_mod_temp.diff_level + 3);
   501 			SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom
   499 			SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom
       
   500 			LowerWindowWidget(w, _opt_mod_temp.diff_level + 3);
   502 			SetWindowDirty(w);
   501 			SetWindowDirty(w);
   503 		}	break;
   502 		} break;
   504 		case 3: case 4: case 5: case 6: /* Easy / Medium / Hard / Custom */
   503 		case 3: case 4: case 5: case 6: /* Easy / Medium / Hard / Custom */
   505 			// temporarily change difficulty level
   504 			// temporarily change difficulty level
   506 			RaiseWindowWidget(w, _opt_mod_temp.diff_level + 3);
   505 			RaiseWindowWidget(w, _opt_mod_temp.diff_level + 3);
   507 			SetDifficultyLevel(e->we.click.widget - 3, &_opt_mod_temp);
   506 			SetDifficultyLevel(e->we.click.widget - 3, &_opt_mod_temp);
   508 			LowerWindowWidget(w, _opt_mod_temp.diff_level + 3);
   507 			LowerWindowWidget(w, _opt_mod_temp.diff_level + 3);
   582 	"vehicle_speed",
   581 	"vehicle_speed",
   583 	"status_long_date",
   582 	"status_long_date",
   584 	"show_finances",
   583 	"show_finances",
   585 	"autoscroll",
   584 	"autoscroll",
   586 	"reverse_scroll",
   585 	"reverse_scroll",
       
   586 	"smooth_scroll",
   587 	"errmsg_duration",
   587 	"errmsg_duration",
   588 	"toolbar_pos",
   588 	"toolbar_pos",
   589 	"measure_tooltip",
   589 	"measure_tooltip",
   590 	"window_snap_radius",
   590 	"window_snap_radius",
   591 	"invisible_trees",
   591 	"invisible_trees",
   596 	/* While the horizontal scrollwheel scrolling is written as general code, only
   596 	/* While the horizontal scrollwheel scrolling is written as general code, only
   597 	 *  the cocoa (OSX) driver generates input for it.
   597 	 *  the cocoa (OSX) driver generates input for it.
   598 	 *  Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
   598 	 *  Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
   599 	"scrollwheel_scrolling",
   599 	"scrollwheel_scrolling",
   600 	"scrollwheel_multiplier",
   600 	"scrollwheel_multiplier",
       
   601 	"pause_on_newgame",
       
   602 	"advanced_vehicle_list",
   601 };
   603 };
   602 
   604 
   603 static const char *_patches_construction[] = {
   605 static const char *_patches_construction[] = {
   604 	"build_on_slopes",
   606 	"build_on_slopes",
   605 	"extra_dynamite",
   607 	"extra_dynamite",
   607 	"signal_side",
   609 	"signal_side",
   608 	"always_small_airport",
   610 	"always_small_airport",
   609 	"drag_signals_density",
   611 	"drag_signals_density",
   610 	"oil_refinery_limit",
   612 	"oil_refinery_limit",
   611 	"semaphore_build_before",
   613 	"semaphore_build_before",
       
   614 	"town_layout",
   612 };
   615 };
   613 
   616 
   614 static const char *_patches_stations[] = {
   617 static const char *_patches_stations[] = {
   615 	"join_stations",
   618 	"join_stations",
   616 	"full_load_any",
   619 	"full_load_any",
   621 	"station_spread",
   624 	"station_spread",
   622 	"serviceathelipad",
   625 	"serviceathelipad",
   623 	"modified_catchment",
   626 	"modified_catchment",
   624 	"gradual_loading",
   627 	"gradual_loading",
   625 	"road_stop_on_town_road",
   628 	"road_stop_on_town_road",
       
   629 	"adjacent_stations",
   626 };
   630 };
   627 
   631 
   628 static const char *_patches_economy[] = {
   632 static const char *_patches_economy[] = {
   629 	"inflation",
   633 	"inflation",
   630 	"build_rawmaterial_ind",
   634 	"build_rawmaterial_ind",
   633 	"bribe",
   637 	"bribe",
   634 	"colored_news_year",
   638 	"colored_news_year",
   635 	"ending_year",
   639 	"ending_year",
   636 	"smooth_economy",
   640 	"smooth_economy",
   637 	"allow_shares",
   641 	"allow_shares",
       
   642 	"town_growth_rate",
       
   643 	"larger_towns",
       
   644 	"initial_city_size",
   638 };
   645 };
   639 
   646 
   640 static const char *_patches_ai[] = {
   647 static const char *_patches_ai[] = {
   641 	"ainew_active",
   648 	"ainew_active",
   642 	"ai_in_multiplayer",
   649 	"ai_in_multiplayer",