/*public override void OnDestroy() * { * base.OnDestroy(); * * DebugUtils.Log("Destroying UIMainPanel"); * * if (m_button != null) GameObject.Destroy(m_button.gameObject); * GameObject.Destroy(m_optionPanel.gameObject); * }*/ private void SetupControls() { float offset = 40f; // Title Bar m_title = AddUIComponent <UITitleBar>(); m_title.iconSprite = "InfoIconTrafficCongestion"; m_title.title = "Advanced Vehicle Options " + ModInfo.version; // Category DropDown UILabel label = AddUIComponent <UILabel>(); label.textScale = 0.8f; label.padding = new RectOffset(0, 0, 8, 0); label.relativePosition = new Vector3(10f, offset); label.text = "Category :"; m_category = UIUtils.CreateDropDown(this); m_category.width = 150; for (int i = 0; i < categoryList.Length; i++) { m_category.AddItem(categoryList[i]); } m_category.selectedIndex = 0; m_category.tooltip = "Select a category to display\nTip: Use the mouse wheel to switch between categories faster"; m_category.relativePosition = label.relativePosition + new Vector3(75f, 0f); m_category.eventSelectedIndexChanged += (c, t) => { m_category.enabled = false; PopulateList(); m_category.enabled = true; }; // Search m_search = UIUtils.CreateTextField(this); m_search.width = 145f; m_search.height = 30f; m_search.padding = new RectOffset(6, 6, 6, 6); m_search.tooltip = "Type the name of a vehicle type"; m_search.relativePosition = new Vector3(WIDTHLEFT - m_search.width, offset); m_search.eventTextChanged += (c, t) => PopulateList(); label = AddUIComponent <UILabel>(); label.textScale = 0.8f; label.padding = new RectOffset(0, 0, 8, 0); label.relativePosition = m_search.relativePosition - new Vector3(60f, 0f); label.text = "Search :"; // FastList m_fastList = UIFastList.Create <UIVehicleItem>(this); m_fastList.backgroundSprite = "UnlockingPanel"; m_fastList.width = WIDTHLEFT - 5; m_fastList.height = height - offset - 110; m_fastList.canSelect = true; m_fastList.relativePosition = new Vector3(5, offset + 35); // Configuration file buttons UILabel configLabel = this.AddUIComponent <UILabel>(); configLabel.text = "Configuration file:"; configLabel.textScale = 0.8f; configLabel.relativePosition = new Vector3(10, height - 60); m_import = UIUtils.CreateButton(this); m_import.text = "Import"; m_import.tooltip = "Import the configuration"; m_import.relativePosition = new Vector3(10, height - 40); m_export = UIUtils.CreateButton(this); m_export.text = "Export"; m_export.tooltip = "Export the configuration"; m_export.relativePosition = new Vector3(105, height - 40); // Preview UIPanel panel = AddUIComponent <UIPanel>(); panel.backgroundSprite = "GenericPanel"; panel.width = WIDTHRIGHT - 10; panel.height = HEIGHT - 420; panel.relativePosition = new Vector3(WIDTHLEFT + 5, offset); m_preview = panel.AddUIComponent <UITextureSprite>(); m_preview.size = panel.size; m_preview.relativePosition = Vector3.zero; m_previewRenderer = gameObject.AddComponent <PreviewRenderer>(); m_previewRenderer.size = m_preview.size * 2; // Twice the size for anti-aliasing m_preview.texture = m_previewRenderer.texture; // Follow if (m_cameraController != null) { m_followVehicle = AddUIComponent <UISprite>(); m_followVehicle.spriteName = "LocationMarkerFocused"; m_followVehicle.width = m_followVehicle.spriteInfo.width; m_followVehicle.height = m_followVehicle.spriteInfo.height; m_followVehicle.tooltip = "Click here to cycle through the existing vehicles of that type"; m_followVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_followVehicle.width - 5, panel.relativePosition.y + 5); m_followVehicle.eventClick += (c, p) => FollowNextVehicle(); } // Option panel m_optionPanel = AddUIComponent <UIOptionPanel>(); m_optionPanel.relativePosition = new Vector3(WIDTHLEFT, height - 370); // Event handlers m_fastList.eventSelectedIndexChanged += OnSelectedItemChanged; m_optionPanel.eventEnableCheckChanged += OnEnableStateChanged; m_import.eventClick += (c, t) => { DefaultOptions.RestoreAll(); AdvancedVehicleOptionsUID.ImportConfig(); optionList = AdvancedVehicleOptionsUID.config.options; }; m_export.eventClick += (c, t) => AdvancedVehicleOptionsUID.ExportConfig(); panel.eventMouseDown += (c, p) => { eventMouseMove += RotateCamera; if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations) { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor); } else { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab); } }; panel.eventMouseUp += (c, p) => { eventMouseMove -= RotateCamera; if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations) { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor); } else { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab); } }; panel.eventMouseWheel += (c, p) => { m_previewRenderer.zoom -= Mathf.Sign(p.wheelDelta) * 0.25f; if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations) { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor); } else { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab); } }; }
private void SetupControls() { float offset = 40f; //Beta Testing Timestamp //DateTime now = DateTime.Now; //m_title.title = "Advanced Vehicle Options " + ModInfo.version + " " + now; // Title Bar m_title = AddUIComponent <UITitleBar>(); m_title.iconSprite = "InfoIconTrafficCongestion"; m_title.title = "Advanced Vehicle Options " + ModInfo.version; // Category DropDown UILabel label = AddUIComponent <UILabel>(); label.textScale = 0.8f; label.padding = new RectOffset(0, 0, 8, 0); label.relativePosition = new Vector3(10f, offset); label.text = "Category :"; m_category = UIUtils.CreateDropDown(this); m_category.width = 175; for (int i = 0; i < categoryList.Length; i++) { m_category.AddItem(categoryList[i]); } m_category.selectedIndex = 0; m_category.tooltip = "Select a category to display\nTip: Use the mouse wheel to switch between categories faster"; m_category.relativePosition = label.relativePosition + new Vector3(75f, 0f); m_category.eventSelectedIndexChanged += (c, t) => { m_category.enabled = false; PopulateList(); m_category.enabled = true; }; // Search m_search = UIUtils.CreateTextField(this); m_search.width = 145f; m_search.height = 30f; m_search.padding = new RectOffset(6, 6, 6, 6); m_search.tooltip = "Type the name of a vehicle type"; m_search.relativePosition = new Vector3(WIDTHLEFT - m_search.width, offset); m_search.eventTextChanged += (c, t) => PopulateList(); label = AddUIComponent <UILabel>(); label.textScale = 0.8f; label.padding = new RectOffset(0, 0, 8, 0); label.relativePosition = m_search.relativePosition - new Vector3(60f, 0f); label.text = "Search :"; // FastList m_fastList = UIFastList.Create <UIVehicleItem>(this); m_fastList.backgroundSprite = "UnlockingPanel"; m_fastList.width = WIDTHLEFT - 5; m_fastList.height = height - offset - 110; m_fastList.canSelect = true; m_fastList.relativePosition = new Vector3(5, offset + 35); // Configuration file buttons UILabel configLabel = this.AddUIComponent <UILabel>(); configLabel.text = "Actions for Vehicle Configuration:"; configLabel.textScale = 0.8f; configLabel.relativePosition = new Vector3(16, height - 65); m_import = UIUtils.CreateButton(this); m_import.text = "Import"; m_import.width = 80; m_import.tooltip = "Import the configuration"; m_import.relativePosition = new Vector3(10, height - 45); m_export = UIUtils.CreateButton(this); m_export.text = "Export"; m_export.width = 80; m_export.tooltip = "Export the configuration"; m_export.relativePosition = new Vector3(95, height - 45); m_resetall = UIUtils.CreateButton(this); m_resetall.text = "Reset all"; m_resetall.width = 80; m_resetall.tooltip = "Reset full configuration"; m_resetall.relativePosition = new Vector3(180, height - 45); // Preview UIPanel panel = AddUIComponent <UIPanel>(); panel.backgroundSprite = "GenericPanel"; panel.width = WIDTHRIGHT - 10; panel.height = HEIGHT - 420; panel.relativePosition = new Vector3(WIDTHLEFT + 5, offset); m_preview = panel.AddUIComponent <UITextureSprite>(); m_preview.size = panel.size; m_preview.relativePosition = Vector3.zero; m_previewRenderer = gameObject.AddComponent <PreviewRenderer>(); m_previewRenderer.size = m_preview.size * 2; // Twice the size for anti-aliasing m_preview.texture = m_previewRenderer.texture; // Follow a vehicle if (m_cameraController != null) { m_followVehicle = AddUIComponent <UISprite>(); m_followVehicle.spriteName = "LocationMarkerFocused"; m_followVehicle.width = m_followVehicle.spriteInfo.width; m_followVehicle.height = m_followVehicle.spriteInfo.height; m_followVehicle.tooltip = "Click here to cycle through the existing vehicles of that type.\nHold Shift Key down for zooming directly to vehicle."; m_followVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_followVehicle.width - 5, panel.relativePosition.y + 5); m_followVehicle.eventClick += (c, p) => FollowNextVehicle(); } //Remove the followed vehicle { m_removeVehicle = AddUIComponent <UISprite>(); m_removeVehicle.Hide(); m_removeVehicle.spriteName = "IconPolicyOldTown"; m_removeVehicle.width = m_removeVehicle.spriteInfo.width - 12; m_removeVehicle.height = m_removeVehicle.spriteInfo.height - 12; m_removeVehicle.tooltip = "Click here to remove the selected vehicle."; m_removeVehicle.relativePosition = new Vector3(panel.relativePosition.x + panel.width - m_removeVehicle.width - 33, panel.relativePosition.y + 7); m_removeVehicle.eventClick += (c, p) => RemoveThisVehicle(); } // Option panel m_optionPanel = AddUIComponent <UIOptionPanel>(); m_optionPanel.relativePosition = new Vector3(WIDTHLEFT, height - 370); // Event handlers m_fastList.eventSelectedIndexChanged += OnSelectedItemChanged; m_optionPanel.eventEnableCheckChanged += OnEnableStateChanged; m_import.eventClick += (c, t) => { DefaultOptions.RestoreAll(); AdvancedVehicleOptionsUID.ImportConfig(); optionList = AdvancedVehicleOptionsUID.config.options; }; m_export.eventClick += (c, t) => AdvancedVehicleOptionsUID.ExportConfig(); m_resetall.eventClick += (c, t) => { ConfirmPanel.ShowModal("Confirm Reset Configuration", "Customized settings for all vehicles will be reset.\n\n" + "Proceed with Configuration reset ?", (comp, ret) => { if (ret != 1) { return; } DefaultOptions.RestoreAll(); AdvancedVehicleOptionsUID.ResetConfig(); optionList = AdvancedVehicleOptionsUID.config.options; ExceptionPanel resetpanel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel"); resetpanel.SetMessage("Advanced Vehicle Options", "All vehicle configuration and customized settings\n" + "have been reset to the Game Defaults.", false); }); }; panel.eventMouseDown += (c, p) => { eventMouseMove += RotateCamera; if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations) { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor); } else { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab); } }; panel.eventMouseUp += (c, p) => { eventMouseMove -= RotateCamera; if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations) { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor); } else { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab); } }; panel.eventMouseWheel += (c, p) => { m_previewRenderer.zoom -= Mathf.Sign(p.wheelDelta) * 0.25f; if (m_optionPanel.m_options != null && m_optionPanel.m_options.useColorVariations) { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab, m_previewColor); } else { m_previewRenderer.RenderVehicle(m_optionPanel.m_options.prefab); } }; }