private void SetupControls() { // Title Bar m_title = AddUIComponent <UITitleBar>(); m_title.title = "RICO Settings"; m_title.iconSprite = "ToolbarIconZoomOutCity"; // Filter m_filter = AddUIComponent <UIBuildingFilter>(); m_filter.width = width - SPACING * 2; m_filter.height = 40; m_filter.relativePosition = new Vector3(SPACING, TITLE_HEIGHT); m_filter.eventFilteringChanged += (c, i) => { if (i == -1) { return; } int listCount = m_buildingSelection.rowsData.m_size; float pos = m_buildingSelection.listPosition; m_buildingSelection.selectedIndex = -1; m_buildingSelection.rowsData = Filter(); }; UIPanel left = AddUIComponent <UIPanel>(); left.width = LEFT_WIDTH; left.height = HEIGHT - m_filter.height; left.relativePosition = new Vector3(SPACING, TITLE_HEIGHT + m_filter.height + SPACING); UIPanel middle = AddUIComponent <UIPanel>(); middle.width = MIDDLE_WIDTH; middle.height = HEIGHT - m_filter.height; middle.relativePosition = new Vector3(LEFT_WIDTH + (SPACING * 2), TITLE_HEIGHT + m_filter.height + SPACING); UIPanel right = AddUIComponent <UIPanel>(); right.width = RIGHT_WIDTH; right.height = HEIGHT - m_filter.height; right.relativePosition = new Vector3(LEFT_WIDTH + MIDDLE_WIDTH + (SPACING * 3), TITLE_HEIGHT + m_filter.height + SPACING); m_buildingPreview = middle.AddUIComponent <UIBuildingPreview>(); m_buildingPreview.width = middle.width; m_buildingPreview.height = (middle.height - SPACING) / 2; m_buildingPreview.relativePosition = Vector3.zero; m_savePanel = middle.AddUIComponent <UISavePanel>(); m_savePanel.width = middle.width; m_savePanel.height = ((middle.height - SPACING) / 2) - 40; m_savePanel.relativePosition = new Vector3(0, m_buildingPreview.height + SPACING); m_buildingSelection = UIFastList.Create <UIBuildingItem>(left); m_buildingSelection.backgroundSprite = "UnlockingPanel"; m_buildingSelection.width = left.width; m_buildingSelection.height = left.height - 40; m_buildingSelection.canSelect = true; m_buildingSelection.rowHeight = 40; m_buildingSelection.autoHideScrollbar = true; m_buildingSelection.relativePosition = Vector3.zero; m_buildingSelection.rowsData = new FastList <object>(); m_buildingSelection.selectedIndex = -1; // Building Options m_buildingOptions = right.AddUIComponent <UIBuildingOptions>(); m_buildingOptions.width = RIGHT_WIDTH; m_buildingOptions.height = right.height - 40; m_buildingOptions.relativePosition = Vector3.zero; try { m_buildingSelection.rowsData = GenerateFastList(); } catch { } }
/// <summary> /// Performs initial setup for the panel; we no longer use Start() as that's not sufficiently reliable (race conditions), and is no longer needed, with the new create/destroy process. /// </summary> internal void Setup() { try { // Hide while we're setting up. isVisible = false; // Basic setup. canFocus = true; isInteractive = true; width = LeftWidth + MiddleWidth + RightWidth + (Spacing * 4); height = PanelHeight + TitleHeight + FilterHeight + (Spacing * 2) + BottomMargin; relativePosition = new Vector3(Mathf.Floor((GetUIView().fixedWidth - width) / 2), Mathf.Floor((GetUIView().fixedHeight - height) / 2)); backgroundSprite = "UnlockingPanel2"; // Titlebar. titleBar = AddUIComponent <UITitleBar>(); titleBar.Setup(); // Filter. filterBar = AddUIComponent <UIBuildingFilter>(); filterBar.width = width - (Spacing * 2); filterBar.height = FilterHeight; filterBar.relativePosition = new Vector3(Spacing, TitleHeight); // Event handler to dealth with changes to filtering. filterBar.EventFilteringChanged += (component, value) => { if (value == -1) { return; } int listCount = buildingSelection.rowsData.m_size; float position = buildingSelection.listPosition; buildingSelection.selectedIndex = -1; buildingSelection.rowsData = GenerateFastList(); }; // Set up panels. // Left panel - list of buildings. UIPanel leftPanel = AddUIComponent <UIPanel>(); leftPanel.width = LeftWidth; leftPanel.height = PanelHeight - CheckFilterHeight; leftPanel.relativePosition = new Vector3(Spacing, TitleHeight + FilterHeight + CheckFilterHeight + Spacing); // Middle panel - building preview and edit panels. UIPanel middlePanel = AddUIComponent <UIPanel>(); middlePanel.width = MiddleWidth; middlePanel.height = PanelHeight; middlePanel.relativePosition = new Vector3(LeftWidth + (Spacing * 2), TitleHeight + FilterHeight + Spacing); previewPanel = middlePanel.AddUIComponent <UIPreviewPanel>(); previewPanel.width = middlePanel.width; previewPanel.height = (PanelHeight - Spacing) / 2; previewPanel.relativePosition = Vector3.zero; previewPanel.Setup(); savePanel = middlePanel.AddUIComponent <UISavePanel>(); savePanel.width = middlePanel.width; savePanel.height = (PanelHeight - Spacing) / 2; savePanel.relativePosition = new Vector3(0, previewPanel.height + Spacing); savePanel.Setup(); // Right panel - mod calculations. UIPanel rightPanel = AddUIComponent <UIPanel>(); rightPanel.width = RightWidth; rightPanel.height = PanelHeight; rightPanel.relativePosition = new Vector3(LeftWidth + MiddleWidth + (Spacing * 3), TitleHeight + FilterHeight + Spacing); buildingOptionsPanel = rightPanel.AddUIComponent <UIBuildingOptions>(); buildingOptionsPanel.width = RightWidth; buildingOptionsPanel.height = PanelHeight; buildingOptionsPanel.relativePosition = Vector3.zero; buildingOptionsPanel.Setup(); // Building selection list. buildingSelection = UIFastList.Create <UIBuildingRow>(leftPanel); buildingSelection.backgroundSprite = "UnlockingPanel"; buildingSelection.width = leftPanel.width; buildingSelection.height = leftPanel.height; buildingSelection.canSelect = true; buildingSelection.rowHeight = 40; buildingSelection.autoHideScrollbar = true; buildingSelection.relativePosition = Vector3.zero; buildingSelection.rowsData = new FastList <object>(); // Set up filterBar to make sure selection filters are properly initialised before calling GenerateFastList. filterBar.Setup(); // Populate the list. buildingSelection.rowsData = GenerateFastList(); } catch (Exception e) { Logging.LogException(e, "exception setting up settings panel"); } }