Changeset - r10667:5badb3a35c7b
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-01-10 17:14:59
rubidium@openttd.org
(svn r14970) -Change: move all (patch) settings to a single "page" (Alberth)
1 file changed with 35 insertions and 55 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -996,12 +996,14 @@ static PatchEntry _patches_ui[] = {
 
	PatchEntry("gui.default_rail_type"),
 
	PatchEntry("gui.always_build_infrastructure"),
 
	PatchEntry("gui.persistent_buildingtools"),
 
	PatchEntry("gui.show_track_reservation"),
 
	PatchEntry("gui.left_mouse_btn_scrolling"),
 
};
 
/** Interface subpage */
 
static PatchPage _patches_ui_page = {_patches_ui, lengthof(_patches_ui)};
 

	
 
static PatchEntry _patches_construction[] = {
 
	PatchEntry("construction.build_on_slopes"),
 
	PatchEntry("construction.autoslope"),
 
	PatchEntry("construction.extra_dynamite"),
 
	PatchEntry("construction.longbridges"),
 
@@ -1011,12 +1013,14 @@ static PatchEntry _patches_construction[
 
	PatchEntry("gui.drag_signals_density"),
 
	PatchEntry("game_creation.oil_refinery_limit"),
 
	PatchEntry("gui.semaphore_build_before"),
 
	PatchEntry("gui.default_signal_type"),
 
	PatchEntry("gui.cycle_signal_types"),
 
};
 
/** Construction sub-page */
 
static PatchPage _patches_construction_page = {_patches_construction, lengthof(_patches_construction)};
 

	
 
static PatchEntry _patches_stations[] = {
 
	PatchEntry("station.join_stations"),
 
	PatchEntry("order.improved_load"),
 
	PatchEntry("order.selectgoods"),
 
	PatchEntry("gui.new_nonstop"),
 
@@ -1027,12 +1031,14 @@ static PatchEntry _patches_stations[] = 
 
	PatchEntry("order.gradual_loading"),
 
	PatchEntry("construction.road_stop_on_town_road"),
 
	PatchEntry("station.adjacent_stations"),
 
	PatchEntry("station.distant_join_stations"),
 
	PatchEntry("economy.station_noise_level"),
 
};
 
/** Stations sub-page */
 
static PatchPage _patches_stations_page = {_patches_stations, lengthof(_patches_stations)};
 

	
 
static PatchEntry _patches_economy[] = {
 
	PatchEntry("economy.inflation"),
 
	PatchEntry("construction.raw_industry_construction"),
 
	PatchEntry("economy.multiple_industry_per_town"),
 
	PatchEntry("economy.same_industry_close"),
 
@@ -1045,21 +1051,25 @@ static PatchEntry _patches_economy[] = {
 
	PatchEntry("economy.town_layout"),
 
	PatchEntry("economy.mod_road_rebuild"),
 
	PatchEntry("economy.town_growth_rate"),
 
	PatchEntry("economy.larger_towns"),
 
	PatchEntry("economy.initial_city_size"),
 
};
 
/** Economy sub-page */
 
static PatchPage _patches_economy_page = {_patches_economy, lengthof(_patches_economy)};
 

	
 
static PatchEntry _patches_ai[] = {
 
	PatchEntry("ai.ainew_active"),
 
	PatchEntry("ai.ai_in_multiplayer"),
 
	PatchEntry("ai.ai_disable_veh_train"),
 
	PatchEntry("ai.ai_disable_veh_roadveh"),
 
	PatchEntry("ai.ai_disable_veh_aircraft"),
 
	PatchEntry("ai.ai_disable_veh_ship"),
 
};
 
/** AI sub-page */
 
static PatchPage _patches_ai_page = {_patches_ai, lengthof(_patches_ai)};
 

	
 
static PatchEntry _patches_vehicles[] = {
 
	PatchEntry("vehicle.realistic_acceleration"),
 
	PatchEntry("pf.forbid_90_deg"),
 
	PatchEntry("vehicle.mammoth_trains"),
 
	PatchEntry("order.gotodepot"),
 
@@ -1088,43 +1098,40 @@ static PatchEntry _patches_vehicles[] = 
 
	PatchEntry("vehicle.disable_elrails"),
 
	PatchEntry("vehicle.freight_trains"),
 
	PatchEntry("vehicle.plane_speed"),
 
	PatchEntry("order.timetabling"),
 
	PatchEntry("vehicle.dynamic_engines"),
 
};
 
/** Vehicles sub-page */
 
static PatchPage _patches_vehicles_page = {_patches_vehicles, lengthof(_patches_vehicles)};
 

	
 
/** Array of pages (tabs), where each page holds a number of advanced settings. */
 
static PatchPage _patches_page[] = {
 
	{_patches_ui,           lengthof(_patches_ui)},
 
	{_patches_construction, lengthof(_patches_construction)},
 
	{_patches_vehicles,     lengthof(_patches_vehicles)},
 
	{_patches_stations,     lengthof(_patches_stations)},
 
	{_patches_economy,      lengthof(_patches_economy)},
 
	{_patches_ai,           lengthof(_patches_ai)},
 
static PatchEntry _patches_main[] = {
 
	PatchEntry(&_patches_ui_page,           STR_CONFIG_PATCHES_GUI),
 
	PatchEntry(&_patches_construction_page, STR_CONFIG_PATCHES_CONSTRUCTION),
 
	PatchEntry(&_patches_vehicles_page,     STR_CONFIG_PATCHES_VEHICLES),
 
	PatchEntry(&_patches_stations_page,     STR_CONFIG_PATCHES_STATIONS),
 
	PatchEntry(&_patches_economy_page,      STR_CONFIG_PATCHES_ECONOMY),
 
	PatchEntry(&_patches_ai_page,           STR_CONFIG_PATCHES_AI),
 
};
 

	
 
/** Main page, holding all advanced settings */
 
static PatchPage _patches_main_page = {_patches_main, lengthof(_patches_main)};
 

	
 
/** Widget numbers of config patches window */
 
enum PatchesSelectionWidgets {
 
	PATCHSEL_OPTIONSPANEL = 3, ///< Panel widget containing the option lists
 
	PATCHSEL_OPTIONSPANEL = 2, ///< Panel widget containing the option lists
 
	PATCHSEL_SCROLLBAR,        ///< Scrollbar
 
	PATCHSEL_RESIZE,           ///< Resize button
 
	PATCHSEL_INTERFACE,        ///< Button 'Interface'
 
	PATCHSEL_CONSTRUCTION,     ///< Button 'Construction'
 
	PATCHSEL_VEHICLES,         ///< Button 'Vehicles'
 
	PATCHSEL_STATIONS,         ///< Button 'Stations'
 
	PATCHSEL_ECONOMY,          ///< Button 'Economy'
 
	PATCHSEL_COMPETITORS       ///< Button 'Competitors'
 
};
 

	
 
struct PatchesSelectionWindow : Window {
 
	static const int SETTINGTREE_LEFT_OFFSET; ///< Position of left edge of patch values
 
	static const int SETTINGTREE_TOP_OFFSET;  ///< Position of top edge of patch values
 

	
 
	static GameSettings *patches_ptr;  ///< Pointer to the game settings being displayed and modified
 

	
 
	int page;
 
	PatchEntry *valuewindow_entry; ///< If non-NULL, pointer to patch setting for which a value-entering window has been opened
 
	PatchEntry *clicked_entry; ///< If non-NULL, pointer to a clicked numeric patch setting (with a depressed left or right button)
 

	
 
	PatchesSelectionWindow(const WindowDesc *desc) : Window(desc)
 
	{
 
		/* Check that the widget doesn't get moved without adapting the constant as well.
 
@@ -1137,42 +1144,34 @@ struct PatchesSelectionWindow : Window {
 
		static bool first_time = true;
 

	
 
		patches_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
 

	
 
		/* Build up the dynamic settings-array only once per OpenTTD session */
 
		if (first_time) {
 
			for (PatchPage *page = &_patches_page[0]; page != endof(_patches_page); page++) {
 
				page->Init();
 
			}
 
			_patches_main_page.Init();
 
			first_time = false;
 
		}
 

	
 
		this->page = 0;
 
		this->valuewindow_entry = NULL; // No patch entry for which a entry window is opened
 
		this->clicked_entry = NULL; // No numeric patch setting buttons are depressed
 
		this->vscroll.pos = 0;
 
		this->vscroll.cap = (this->widget[PATCHSEL_OPTIONSPANEL].bottom - this->widget[PATCHSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT;
 
		SetVScrollCount(this, _patches_page[this->page].Length());
 
		SetVScrollCount(this, _patches_main_page.Length());
 

	
 
		this->resize.step_height = SETTING_HEIGHT;
 
		this->resize.height = this->height;
 
		this->resize.step_width = 1;
 
		this->resize.width = this->width;
 

	
 
		this->LowerWidget(this->page + PATCHSEL_INTERFACE); // Depress button of currently selected page
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		const PatchPage *page = &_patches_page[this->page];
 

	
 
		/* Set up selected category */
 
		this->DrawWidgets();
 
		page->Draw(patches_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
 
		_patches_main_page.Draw(patches_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
 
						this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
@@ -1180,25 +1179,24 @@ struct PatchesSelectionWindow : Window {
 
				int y = pt.y - SETTINGTREE_TOP_OFFSET;  // Shift y coordinate
 
				if (y < 0) return;  // Clicked above first entry
 

	
 
				byte btn = this->vscroll.pos + y / SETTING_HEIGHT;  // Compute which setting is selected
 
				if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return;  // Clicked too low at the setting
 

	
 
				const PatchPage *page = &_patches_page[this->page];
 
				uint cur_row = 0;
 
				PatchEntry *pe = page->FindEntry(btn, &cur_row);
 
				PatchEntry *pe = _patches_main_page.FindEntry(btn, &cur_row);
 

	
 
				if (pe == NULL) return;  // Clicked below the last setting of the page
 

	
 
				int x = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;  // Shift x coordinate
 
				if (x < 0) return;  // Clicked left of the entry
 

	
 
				if ((pe->flags & PEF_KIND_MASK) == PEF_SUBTREE_KIND) {
 
					pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
 

	
 
					SetVScrollCount(this, _patches_page[this->page].Length());
 
					SetVScrollCount(this, _patches_main_page.Length());
 
					this->SetDirty();
 
					return;
 
				}
 

	
 
				assert((pe->flags & PEF_KIND_MASK) == PEF_SETTING_KIND);
 
				const SettingDesc *sd = pe->d.entry.setting;
 
@@ -1270,22 +1268,12 @@ struct PatchesSelectionWindow : Window {
 
						this->valuewindow_entry = pe;
 
						SetDParam(0, value);
 
						ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, this, CS_NUMERAL, QSF_NONE);
 
					}
 
				}
 
			} break;
 

	
 
			case PATCHSEL_INTERFACE: case PATCHSEL_CONSTRUCTION: case PATCHSEL_VEHICLES:
 
			case PATCHSEL_STATIONS:  case PATCHSEL_ECONOMY:      case PATCHSEL_COMPETITORS:
 
				this->RaiseWidget(this->page + PATCHSEL_INTERFACE);
 
				this->page = widget - PATCHSEL_INTERFACE;
 
				this->LowerWidget(this->page + PATCHSEL_INTERFACE);
 
				SetVScrollCount(this, _patches_page[this->page].Length());
 
				DeleteWindowById(WC_QUERY_STRING, 0);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTimeout()
 
	{
 
		if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
 
@@ -1311,39 +1299,31 @@ struct PatchesSelectionWindow : Window {
 
		}
 
	}
 

	
 
	virtual void OnResize(Point new_size, Point delta)
 
	{
 
		this->vscroll.cap += delta.y / SETTING_HEIGHT;
 
		SetVScrollCount(this, _patches_page[this->page].Length());
 
		SetVScrollCount(this, _patches_main_page.Length());
 
	}
 
};
 

	
 
GameSettings *PatchesSelectionWindow::patches_ptr = NULL;
 
const int PatchesSelectionWindow::SETTINGTREE_LEFT_OFFSET = 5;
 
const int PatchesSelectionWindow::SETTINGTREE_TOP_OFFSET = 47;
 
const int PatchesSelectionWindow::SETTINGTREE_TOP_OFFSET = 19;
 

	
 
static const Widget _patches_selection_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_MAUVE,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_MAUVE,    11,   396,     0,    13, STR_CONFIG_PATCHES_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,  RESIZE_RIGHT,  COLOUR_MAUVE,     0,   396,    14,    41, 0x0,                             STR_NULL},
 
{      WWT_PANEL,     RESIZE_RB,  COLOUR_MAUVE,     0,   384,    42,   215, 0x0,                             STR_NULL}, // PATCHSEL_OPTIONSPANEL
 
{  WWT_SCROLLBAR,    RESIZE_LRB,  COLOUR_MAUVE,   385,   396,    42,   203, 0x0,                             STR_0190_SCROLL_BAR_SCROLLS_LIST}, // PATCHSEL_SCROLLBAR
 
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_MAUVE,   385,   396,   204,   215, 0x0,                             STR_RESIZE_BUTTON}, // PATCHSEL_RESIZE
 

	
 
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,   10,   100,    16,    27, STR_CONFIG_PATCHES_GUI,          STR_NULL}, // PATCHSEL_INTERFACE
 
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,  101,   191,    16,    27, STR_CONFIG_PATCHES_CONSTRUCTION, STR_NULL}, // PATCHSEL_CONSTRUCTION
 
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,  192,   283,    16,    27, STR_CONFIG_PATCHES_VEHICLES,     STR_NULL}, // PATCHSEL_VEHICLES
 
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,  284,   375,    16,    27, STR_CONFIG_PATCHES_STATIONS,     STR_NULL}, // PATCHSEL_STATIONS
 
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,   10,   100,    28,    39, STR_CONFIG_PATCHES_ECONOMY,      STR_NULL}, // PATCHSEL_ECONOMY
 
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_YELLOW,  101,   191,    28,    39, STR_CONFIG_PATCHES_AI,           STR_NULL}, // PATCHSEL_COMPETITORS
 
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_MAUVE,    11,   411,     0,    13, STR_CONFIG_PATCHES_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,     RESIZE_RB,  COLOUR_MAUVE,     0,   399,    14,   187, 0x0,                             STR_NULL}, // PATCHSEL_OPTIONSPANEL
 
{  WWT_SCROLLBAR,    RESIZE_LRB,  COLOUR_MAUVE,   400,   411,    14,   175, 0x0,                             STR_0190_SCROLL_BAR_SCROLLS_LIST}, // PATCHSEL_SCROLLBAR
 
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_MAUVE,   400,   411,   176,   187, 0x0,                             STR_RESIZE_BUTTON}, // PATCHSEL_RESIZE
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _patches_selection_desc = {
 
	WDP_CENTER, WDP_CENTER, 397, 216, 397, 425,
 
	WDP_CENTER, WDP_CENTER, 412, 188, 412, 397,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
 
	_patches_selection_widgets,
 
};
 

	
 
void ShowPatchesSelection()
0 comments (0 inline, 0 general)