/// <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); }
/// <summary> /// Constructor - creates panel. /// </summary> internal BOBScalePanel() { // Default position - centre in screen. relativePosition = new Vector2(Mathf.Floor((GetUIView().fixedWidth - width) / 2), Mathf.Floor((GetUIView().fixedHeight - height) / 2)); // Title label. SetTitle(Translations.Translate("BOB_NAM") + " : " + Translations.Translate("BOB_SCA_TIT")); // Minimum scale slider. minScaleSlider = AddBOBSlider(this, ControlX, MinOffsetY, ControlWidth - (Margin * 2f), "BOB_SCA_MIN", 0.5f, 2f, 0.5f, "MinScale"); minScaleSlider.eventValueChanged += MinScaleValue; minScaleSlider.value = 1f; maxScaleSlider = AddBOBSlider(this, ControlX, MaxOffsetY + 40f, ControlWidth - (Margin * 2f), "BOB_SCA_MAX", 0.5f, 2f, 0.5f, "MaxScale"); maxScaleSlider.eventValueChanged += MaxScaleValue; maxScaleSlider.value = 1f; // Revert button. revertButton = UIControls.AddSmallerButton(this, ControlX, RevertY, Translations.Translate("BOB_PNL_REV"), ControlWidth); revertButton.eventClicked += Revert; revertButton.Disable(); // Loaded prop list. UIPanel loadedPanel = AddUIComponent <UIPanel>(); loadedPanel.width = LoadedWidth; loadedPanel.height = ListHeight; loadedPanel.relativePosition = new Vector2(LoadedX, ListY); loadedList = UIFastList.Create <UILoadedScalingPropRow>(loadedPanel); ListSetup(loadedList); // Order button. loadedNameButton = ArrowButton(this, LoadedX + 10f, ListY - 20f); loadedNameButton.eventClicked += SortLoaded; loadedCreatorButton = ArrowButton(this, LoadedX + UILoadedScalingPropRow.CreatorX + 10f, ListY - 20f); loadedCreatorButton.eventClicked += SortLoaded; // Default is name ascending. SetFgSprites(loadedNameButton, "IconUpArrow2"); // Populate loaded list. LoadedList(); // Bring to front. BringToFront(); }
/// <summary> /// Performs initial fastlist setup. /// </summary> /// <param name="fastList">Fastlist to set up</param> protected void ListSetup(UIFastList fastList) { // Apperance, size and position. fastList.backgroundSprite = "UnlockingPanel"; fastList.width = fastList.parent.width; fastList.height = fastList.parent.height; fastList.relativePosition = Vector2.zero; fastList.rowHeight = UIPropRow.RowHeight; // Behaviour. fastList.canSelect = true; fastList.autoHideScrollbar = true; // Data. fastList.rowsData = new FastList <object>(); fastList.selectedIndex = -1; }
/// <summary> /// Adds configurations panel tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> internal ConfigurationsPanel(UITabstrip tabStrip, int tabIndex) { // Set reference. instance = this; // Determine if we're in-game or not; use status of replacer managers to determine. inGame = BuildingReplacement.Instance != null && NetworkReplacement.Instance != null; // Add tab and helper. UIPanel panel = PanelUtils.AddTab(tabStrip, Translations.Translate("BOB_OPT_CFG"), tabIndex); UIHelper helper = new UIHelper(panel); panel.autoLayout = false; // Config list panel. UIPanel configListPanel = panel.AddUIComponent <UIPanel>(); configListPanel.width = ListWidth; configListPanel.height = ListHeight; configListPanel.relativePosition = new Vector2(Margin, ListY); // Config selection list. configList = UIFastList.Create <UIConfigRow>(configListPanel); configList.backgroundSprite = "UnlockingPanel"; configList.width = configListPanel.width; configList.height = configListPanel.height; configList.canSelect = true; configList.rowHeight = RowHeight; configList.autoHideScrollbar = true; configList.relativePosition = Vector2.zero; configList.rowsData = new FastList <object>(); // File name textfield. UILabel fileTextLabel = UIControls.AddLabel(panel, ControlPanelX, ListY, "New configuration name:"); fileNameField = UIControls.AddTextField(panel, ControlPanelX, ListY + fileTextLabel.height); fileNameField.eventTextChanged += (control, text) => UpdateButtonStates(); // Buttons. activeCopyButton = UIControls.AddButton(panel, ControlPanelX, ListY + 70f, Translations.Translate("BOB_CFG_SAC"), 300f, scale: 0.8f); activeCopyButton.eventClicked += NewCurrent; selectedCopyButton = UIControls.AddButton(panel, ControlPanelX, ListY + 105f, Translations.Translate("BOB_CFG_SSC"), 300f, scale: 0.8f); selectedCopyButton.eventClicked += CopySelected; newCleanButton = UIControls.AddButton(panel, ControlPanelX, ListY + 140f, Translations.Translate("BOB_CFG_SEC"), 300f, scale: 0.8f); newCleanButton.eventClicked += NewClean; deleteButton = UIControls.AddButton(panel, ControlPanelX, ListY + 210f, Translations.Translate("BOB_CFG_DEL"), 300f, scale: 0.8f); deleteButton.eventClicked += Delete; // Ingame buttons - 'use custom' check and apply and nuke buttons. if (inGame) { // Use custom check box. customCheck = UIControls.LabelledCheckBox(panel, Margin, ToolBarY, Translations.Translate("BOB_CFG_UCS")); customCheck.eventCheckChanged += (control, isChecked) => { // If we've got a valid selection, set the current config name to this. if (isChecked && !string.IsNullOrEmpty(selectedConfig)) { ConfigurationUtils.CurrentSavedConfigName = selectedConfig; } }; // Apply button. UIButton applyButton = UIControls.AddButton(panel, Margin, FooterY, Translations.Translate("BOB_CFG_LAA"), 400f, scale: 0.8f); applyButton.eventClicked += Apply; // Use global configuration button. UIButton globalButton = UIControls.AddButton(panel, Margin, FooterY + 50f, Translations.Translate("BOB_CFG_LGL"), 400f, scale: 0.8f); globalButton.eventClicked += UseGlobal; // Clean up config button. UIButton cleanUpButton = UIControls.AddButton(panel, Margin + 50f, FooterY + 150f, Translations.Translate("BOB_CFG_CLE"), 300f); cleanUpButton.tooltip = Translations.Translate("BOB_CFG_CLE_TIP"); cleanUpButton.eventClicked += (control, clickEvent) => ConfigurationUtils.Cleanup(); // Nuke all settings button. UIButton nukeButton = UIControls.AddButton(panel, Margin + 50f, FooterY + 200f, Translations.Translate("BOB_NUKE"), 300f); nukeButton.eventClicked += (control, clickEvent) => { // Revert all-building and building settings. ReplacementUtils.NukeSettings(); // Save clean configuration. //ConfigurationUtils.SaveConfig(ConfigurationUtils.CurrentSavedConfigName, true); }; } // Populate selection list and set initial button states. RefreshList(); // Select current pack if we've got one. if (customCheck != null && customCheck.isChecked) { // Try to select current config name. selectedConfig = configList.FindItem(ConfigurationUtils.CurrentSavedConfigName); // Did we find it? if (selectedConfig == null) { // Not found; uncheck the use custom check. customCheck.isChecked = false; } } // Set initial button states. UpdateButtonStates(); }
/// <summary> /// Sets the target prefab. /// </summary> /// <param name="targetPrefabInfo">Target prefab to set</param> internal override void SetTarget(PrefabInfo targetPrefabInfo) { // Don't do anything if invalid target, or target hasn't changed. if (!(targetPrefabInfo is BuildingInfo) || selectedPrefab == targetPrefabInfo) { return; } // Base setup. base.SetTarget(targetPrefabInfo); // Set target reference. currentBuilding = SelectedBuilding; // Does this building have sub-buildings? if (currentBuilding.m_subBuildings != null && currentBuilding.m_subBuildings.Length > 0) { // Yes - create lists of sub-buildings (names and infos). int numSubs = currentBuilding.m_subBuildings.Length; int numChoices = numSubs + 1; SubBuildingNames = new string[numChoices]; subBuildings = new BuildingInfo[numChoices]; SubBuildingNames[0] = PrefabLists.GetDisplayName(currentBuilding); subBuildings[0] = currentBuilding; object[] subBuildingIndexes = new object[numChoices]; subBuildingIndexes[0] = 0; for (int i = 0; i < numSubs; ++i) { SubBuildingNames[i + 1] = PrefabLists.GetDisplayName(currentBuilding.m_subBuildings[i].m_buildingInfo); subBuildings[i + 1] = currentBuilding.m_subBuildings[i].m_buildingInfo; subBuildingIndexes[i + 1] = i + 1; } // Add sub-building menu, if it doesn't already exist. if (subBuildingPanel == null) { subBuildingPanel = this.AddUIComponent <UIPanel>(); // Basic behaviour. subBuildingPanel.autoLayout = false; subBuildingPanel.canFocus = true; subBuildingPanel.isInteractive = true; // Appearance. subBuildingPanel.backgroundSprite = "MenuPanel2"; subBuildingPanel.opacity = PanelOpacity; // Size and position. subBuildingPanel.size = new Vector2(200f, PanelHeight - TitleHeight); subBuildingPanel.relativePosition = new Vector2(-205f, TitleHeight); // Heading. UILabel subTitleLabel = UIControls.AddLabel(subBuildingPanel, 5f, 5f, Translations.Translate("BOB_PNL_SUB"), 190f); subTitleLabel.textAlignment = UIHorizontalAlignment.Center; subTitleLabel.relativePosition = new Vector2(5f, (TitleHeight - subTitleLabel.height) / 2f); // List panel. UIPanel subBuildingListPanel = subBuildingPanel.AddUIComponent <UIPanel>(); subBuildingListPanel.relativePosition = new Vector2(Margin, TitleHeight); subBuildingListPanel.width = subBuildingPanel.width - (Margin * 2f); subBuildingListPanel.height = subBuildingPanel.height - TitleHeight - (Margin * 2f); subBuildingList = UIFastList.Create <UISubBuildingRow>(subBuildingListPanel); ListSetup(subBuildingList); // Create return fastlist from our filtered list. subBuildingList.rowsData = new FastList <object> { m_buffer = subBuildingIndexes, m_size = subBuildingIndexes.Length }; } else { // If the sub-building panel has already been created. just make sure it's visible. subBuildingPanel.Show(); } } else { // Otherwise, hide the sub-building panel (if it exists). subBuildingPanel?.Hide(); } // Populate target list and select target item. TargetList(); // Apply Harmony rendering patches. RenderOverlays.CurrentBuilding = selectedPrefab as BuildingInfo; Patcher.PatchBuildingOverlays(true); }