/// <summary> /// Adds crime options tab to tabstrip. /// </summary> /// <param name="tabStrip">Tab strip to add to</param> /// <param name="tabIndex">Index number of tab</param> internal CrimePanel(UITabstrip tabStrip, int tabIndex) { // Add tab and helper. UIPanel panel = PanelUtils.AddTextTab(tabStrip, Translations.Translate("RPR_OPT_CRI"), tabIndex, out UIButton _); UIHelper helper = new UIHelper(panel); panel.autoLayout = true; // Add slider component. UISlider newSlider = UIControls.AddSlider(panel, Translations.Translate("RPR_OPT_CML"), 1f, 200f, 1f, ModSettings.crimeMultiplier); newSlider.tooltipBox = TooltipUtils.TooltipBox; newSlider.tooltip = Translations.Translate("RPR_OPT_CML_TIP"); // Value label. UIPanel sliderPanel = (UIPanel)newSlider.parent; UILabel valueLabel = sliderPanel.AddUIComponent <UILabel>(); valueLabel.name = "ValueLabel"; valueLabel.relativePosition = UIControls.PositionRightOf(newSlider, 8f, 1f); // Set initial text. PercentSliderText(newSlider, newSlider.value); // Slider change event. newSlider.eventValueChanged += (control, value) => { // Update value label. PercentSliderText(control, value); // Update setting. ModSettings.crimeMultiplier = value; }; }
/// <summary> /// Adds a slider with a multiplier label below. /// </summary> /// <param name="parent">Panel to add the control to</param> /// <param name="text">Descriptive label text</param> /// <param name="min">Slider minimum value</param> /// <param name="max">Slider maximum value</param> /// <param name="step">Slider minimum step</param> /// <param name="defaultValue">Slider initial value</param> /// <param name="eventCallback">Slider event handler</param> /// <param name="width">Slider width (excluding value label to right) (default 600)</param> /// <returns>New UI slider with attached labels</returns> private UISlider AddSliderWithMultipler(UIComponent parent, string text, float min, float max, float step, float defaultValue, OnValueChanged eventCallback, float width = 600f) { // Add slider component. UISlider newSlider = UIControls.AddSlider(parent, text, min, max, step, defaultValue, width); UIPanel sliderPanel = (UIPanel)newSlider.parent; // Value label. UILabel valueLabel = sliderPanel.AddUIComponent <UILabel>(); valueLabel.name = "ValueLabel"; valueLabel.relativePosition = UIControls.PositionUnder(newSlider, 2, 0f); valueLabel.text = "x" + newSlider.value.ToString(); // Event handler to update value label. newSlider.eventValueChanged += (component, value) => { valueLabel.text = "x" + value.ToString(); // Execute provided callback. eventCallback(value); }; return(newSlider); }