private void CreateComponents() { m_label = AddUIComponent <UILabel>(); m_label.text = "Select an effect"; m_label.relativePosition = new Vector3(WIDTH / 2 - m_label.width / 2, 10); // Drag handle UIDragHandle handle = AddUIComponent <UIDragHandle>(); handle.target = this; handle.constrainToScreen = true; handle.width = WIDTH; handle.height = 40; handle.relativePosition = Vector3.zero; // Name field UILabel label = AddUIComponent <UILabel>(); label.text = "Name:"; m_searchField = UIUtils.CreateTextField(this); m_searchField.width = 250; label.relativePosition = new Vector3((WIDTH - (label.width + m_searchField.width + 10)) / 2, 55); m_searchField.relativePosition = new Vector3((WIDTH - m_searchField.width + label.width + 10) / 2, 50); m_searchField.text = ""; m_searchField.eventTextChanged += (c, s) => { PopulateList(); }; m_searchField.tooltip = "Search for an effect by name"; // Buttons UIButton confirmButton = UIUtils.CreateButton(this); confirmButton.text = "Select"; confirmButton.relativePosition = new Vector3(WIDTH / 2 - confirmButton.width - 10, HEIGHT - confirmButton.height - 10); confirmButton.eventClicked += (c, p) => { SelectEffect(); }; UIButton cancelButton = UIUtils.CreateButton(this); cancelButton.text = "Cancel"; cancelButton.relativePosition = new Vector3(WIDTH / 2 + 10, HEIGHT - cancelButton.height - 10); cancelButton.eventClicked += (c, p) => { isVisible = false; }; // Effect list m_effectList = UIFastList.Create <UIEffectRow>(this); m_effectList.backgroundSprite = "UnlockingPanel"; m_effectList.relativePosition = new Vector3(10, 90); m_effectList.height = HEIGHT - 90 - 10 - cancelButton.height; m_effectList.width = WIDTH - 20; m_effectList.canSelect = true; }
/// <summary> /// Use this to create the UIFastList. /// Do NOT use AddUIComponent. /// I had to do that way because MonoBehaviors classes cannot be generic /// </summary> /// <typeparam name="T">The type of the row UI component</typeparam> /// <param name="parent"></param> /// <returns></returns> public static UIFastList Create <T>(UIComponent parent) where T : UIPanel, IUIFastListRow { UIFastList list = parent.AddUIComponent <UIFastList>(); list.m_rowType = typeof(T); return(list); }
private void CreateComponents() { int headerHeight = 40; // Label UILabel label = AddUIComponent <UILabel>(); label.text = "Effects"; label.relativePosition = new Vector3(WIDTH / 2 - label.width / 2, 10); // Drag handle UIDragHandle handle = AddUIComponent <UIDragHandle>(); handle.target = this; handle.constrainToScreen = true; handle.width = WIDTH; handle.height = headerHeight; handle.relativePosition = Vector3.zero; // close button UIButton closeButton = UIUtils.CreateButton(this); closeButton.size = new Vector2(30, 30); closeButton.normalBgSprite = "buttonclose"; closeButton.hoveredBgSprite = "buttonclosehover"; closeButton.pressedBgSprite = "buttonclosepressed"; closeButton.relativePosition = new Vector3(WIDTH - 35, 5); closeButton.eventClicked += (c, p) => { isVisible = false; }; // Dropdown m_vehicleDropdown = UIUtils.CreateDropDown(this); m_vehicleDropdown.width = 400; m_vehicleDropdown.relativePosition = new Vector3(10, headerHeight + 10); m_vehicleDropdown.eventSelectedIndexChanged += OnDropdownIndexChanged; m_vehicleDropdown.selectedIndex = -1; float listHeight = HEIGHT - headerHeight - m_vehicleDropdown.height - 30 - 50; float listWidth = 300; float padding = 10; float optionsWidth = WIDTH - (listWidth - 3 * padding); float listTop = headerHeight + 20 + m_vehicleDropdown.height; // Fastlist for Vehicle Effects definitions m_veEffectList = UIFastList.Create <UIEffectDefinitionRow>(this); m_veEffectList.backgroundSprite = "UnlockingPanel"; m_veEffectList.width = listWidth; m_veEffectList.height = listHeight; m_veEffectList.relativePosition = new Vector3(padding, listTop); m_veEffectList.canSelect = true; m_veEffectList.eventSelectedIndexChanged += OnVEEffectSelectionChanged; // Create options panel m_optionsPanel = AddUIComponent <UIEffectOptionsPanel>(); m_optionsPanel.width = optionsWidth; m_optionsPanel.height = listHeight; m_optionsPanel.relativePosition = new Vector3(listWidth + padding * 2, listTop); m_optionsPanel.m_mainPanel = this; m_optionsPanel.CreateComponents(); float footerX = 10; // Button to add effects (footer) m_addEffectButton = UIUtils.CreateButton(this); m_addEffectButton.text = "Add effect"; m_addEffectButton.width = 120; m_addEffectButton.relativePosition = new Vector3(footerX, HEIGHT - 40); m_addEffectButton.eventClicked += (c, b) => { if (!m_effectListPanel.isVisible) { m_effectListPanel.Show((info) => { VehicleEffectsDefinition.Effect effect = new VehicleEffectsDefinition.Effect(); effect.Name = info.name; AddEffect(effect); }); } }; footerX += m_addEffectButton.width + 10; // Button to save definition (footer) m_saveDefinitionButton = UIUtils.CreateButton(this); m_saveDefinitionButton.text = "Save XML"; m_saveDefinitionButton.width = 120; m_saveDefinitionButton.relativePosition = new Vector3(footerX, HEIGHT - 40); m_saveDefinitionButton.eventClicked += (c, b) => { if (!m_savePanel.isVisible) { m_savePanel.Show(Util.GetPackageName(m_vehicles[0]), GetCleanedDefinition()); } }; footerX += m_saveDefinitionButton.width + 10; // Button to load definition (footer) m_loadDefinitionButton = UIUtils.CreateButton(this); m_loadDefinitionButton.text = "Load XML"; m_loadDefinitionButton.width = 120; m_loadDefinitionButton.relativePosition = new Vector3(footerX, HEIGHT - 40); m_loadDefinitionButton.eventClicked += (c, b) => { if (!m_loadPanel.isVisible) { m_loadPanel.Show((definition) => { if (definition != null) { m_definition = definition; AddMissingSceneVehicles(); PopulateVEList(); } }); } }; footerX += m_loadDefinitionButton.width + 10; // Button to preview definition (footer) m_previewButton = UIUtils.CreateButton(this); m_previewButton.text = "Enable Preview"; m_previewButton.width = 180; m_previewButton.relativePosition = new Vector3(WIDTH - 10 - m_previewButton.width, HEIGHT - 40); m_previewButton.eventClicked += (c, b) => { if (m_previewer.IsPreviewing) { m_previewButton.text = "Enable Preview"; m_previewer.RevertPreview(); } else { if (m_previewer.ApplyPreview(GetCleanedDefinition(), "Vehicle Effects Previewer")) { m_previewButton.text = "Disable Preview"; } } }; }