/// <summary> /// Performs initial setup /// </summary> /// <param name="parentTransform">Parent transform</param> /// <param name="targetPrefabInfo">Currently selected target prefab</param> internal override void Setup(Transform parentTransform, PrefabInfo targetPrefabInfo) { try { // Perform basic panel setup. base.Setup(parentTransform, targetPrefabInfo); Logging.Message("commencing InfoPanel setup"); // Replace all button. replaceAllButton = AddIconButton(this, MidControlX + replaceButton.width, ReplaceY, BigIconSize, ReplaceAllTooltipKey, ReplaceAllAtlas); replaceAllButton.eventClicked += ReplaceAll; // Probability. UIPanel probabilityPanel = Sliderpanel(this, MidControlX, ProbabilityY, SliderHeight); probabilitySlider = AddBOBSlider(probabilityPanel, 0f, "BOB_PNL_PRB", 0, 100, 1); probabilitySlider.TrueValue = 100f; probabilitySlider.LimitToVisible = true; // Angle. UIPanel anglePanel = Sliderpanel(this, MidControlX, AngleY, SliderHeight); angleSlider = AddBOBSlider(anglePanel, 0f, "BOB_PNL_ANG", -180, 180, 1); Logging.Message("Creating offset panel"); // Offset panel. UIPanel offsetPanel = Sliderpanel(this, MidControlX, OffsetPanelY, OffsetPanelHeight); UILabel offsetLabel = UIControls.AddLabel(offsetPanel, 0f, OffsetLabelY, Translations.Translate("BOB_PNL_OFF")); offsetLabel.textAlignment = UIHorizontalAlignment.Center; while (offsetLabel.width > MidControlWidth) { offsetLabel.textScale -= 0.05f; offsetLabel.PerformLayout(); } offsetLabel.relativePosition = new Vector2((offsetPanel.width - offsetLabel.width) / 2f, OffsetLabelY); // Offset sliders. xSlider = AddBOBSlider(offsetPanel, XOffsetY, "BOB_PNL_XOF", -8f, 8f, 0.01f); ySlider = AddBOBSlider(offsetPanel, YOffsetY, "BOB_PNL_YOF", -8f, 8f, 0.01f); zSlider = AddBOBSlider(offsetPanel, ZOffsetY, "BOB_PNL_ZOF", -8f, 8f, 0.01f); // Set initial button states. UpdateButtonStates(); // Normal/random toggle. randomCheck = UIControls.LabelledCheckBox((UIComponent)(object)this, hideVanilla.relativePosition.x, hideVanilla.relativePosition.y + hideVanilla.height + (Margin / 2f), Translations.Translate("BOB_PNL_RSW"), 12f, 0.7f); randomCheck.eventCheckChanged += RandomCheckChanged; // Random settings button. UIButton randomButton = UIControls.EvenSmallerButton(this, RightX - 200f, TitleHeight + Margin + 20f, Translations.Translate("BOB_PNL_RST")); randomButton.eventClicked += (control, clickEvent) => BOBRandomPanel.Create(); Logging.Message("InfoPanel setup completed"); } catch (Exception e) { Logging.LogException(e, "exception setting up InfoPanel"); } }
/// <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> /// 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(); }