/// <summary> /// Adds mod options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> internal GeneralOptionsPanel(UITabstrip tabStrip, int tabIndex) { // Add tab and helper. UIPanel panel = PanelUtils.AddTab(tabStrip, Translations.Translate("BOB_OPT_GEN"), tabIndex); UIHelper helper = new UIHelper(panel); panel.autoLayout = true; // Language dropdown. UIDropDown languageDrop = UIControls.AddPlainDropDown(panel, Translations.Translate("TRN_CHOICE"), Translations.LanguageList, Translations.Index); languageDrop.eventSelectedIndexChanged += (control, index) => Translations.Index = index; // Hotkey control. panel.gameObject.AddComponent <OptionsKeymapping>(); // Default grouping behaviour. string[] groupItems = new string[] { Translations.Translate("BOB_PER_LST"), Translations.Translate("BOB_PER_SIN"), Translations.Translate("BOB_PER_GRP") }; UIDropDown groupDropDown = UIControls.AddPlainDropDown(panel, Translations.Translate("BOB_PER_IND"), groupItems, ModSettings.indDefault, 350f); groupDropDown.eventSelectedIndexChanged += (control, index) => ModSettings.indDefault = index; // Rember last position. UICheckBox rememberPosCheck = UIControls.AddPlainCheckBox(panel, Translations.Translate("BOB_OPT_POS")); rememberPosCheck.isChecked = ModSettings.rememberPosition; rememberPosCheck.eventCheckChanged += (control, isChecked) => ModSettings.rememberPosition = isChecked; }
/// <summary> /// Adds a BOB slider to the specified component. /// </summary> /// <param name="parent">Parent component</param> /// <param name="xPos">Relative X position</param /// <param name="yPos">Relative Y position</param /// <param name="width">Slider width</param> /// <param name="labelKey">Text label translation key</param> /// <param name="minValue">Minimum displayed value</param /// <param name="maxValue">Maximum displayed value</param> /// <param name="stepSize">Minimum slider step size</param> /// <param name="name">Slider name</param> /// <returns>New BOBSlider</returns> protected BOBSlider AddBOBSlider(UIComponent parent, float xPos, float yPos, float width, string labelKey, float minValue, float maxValue, float stepSize, string name) { const float SliderY = 18f; const float ValueY = 3f; const float LabelY = -13f; const float SliderHeight = 18f; const float FloatTextFieldWidth = 45f; const float IntTextFieldWidth = 38f; // Slider control. BOBSlider newSlider = parent.AddUIComponent <BOBSlider>(); newSlider.size = new Vector2(width, SliderHeight); newSlider.relativePosition = new Vector2(xPos, yPos + SliderY); newSlider.name = name; // Value field - added to parent, not to slider, otherwise slider catches all input attempts. Integer textfields (stepsize == 1) have shorter widths. float textFieldWidth = stepSize == 1 ? IntTextFieldWidth : FloatTextFieldWidth; UITextField valueField = UIControls.TinyTextField(parent, xPos + Margin + newSlider.width - textFieldWidth, yPos + ValueY, textFieldWidth); // Title label. UILabel titleLabel = UIControls.AddLabel(newSlider, 0f, LabelY, Translations.Translate(labelKey), textScale: 0.7f); // Autoscale tile label text, with minimum size 0.35. while (titleLabel.width > newSlider.width - textFieldWidth && titleLabel.textScale > 0.35f) { titleLabel.textScale -= 0.05f; } // Slider track. UISlicedSprite sliderSprite = newSlider.AddUIComponent <UISlicedSprite>(); sliderSprite.atlas = TextureUtils.InGameAtlas; sliderSprite.spriteName = "BudgetSlider"; sliderSprite.size = new Vector2(newSlider.width, 9f); sliderSprite.relativePosition = new Vector2(0f, 4f); // Slider thumb. UISlicedSprite sliderThumb = newSlider.AddUIComponent <UISlicedSprite>(); sliderThumb.atlas = TextureUtils.InGameAtlas; sliderThumb.spriteName = "SliderBudget"; newSlider.thumbObject = sliderThumb; // Set references. newSlider.ValueField = valueField; // Event handler for textfield. newSlider.ValueField.eventTextSubmitted += newSlider.OnTextSubmitted; // Set initial values. newSlider.StepSize = stepSize; newSlider.maxValue = maxValue; newSlider.minValue = minValue; newSlider.TrueValue = 0f; return(newSlider); }
/// <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); }