RJW-Sexperience/Source/RJWSexperience/Settings/SettingsWidgets.cs

46 lines
1.6 KiB
C#
Raw Normal View History

2022-05-09 03:16:51 +00:00
using UnityEngine;
using Verse;
namespace RJWSexperience.Settings
{
public static class SettingsWidgets
{
public const float lineHeight = 24f;
2023-03-24 15:22:54 +00:00
public static void LabelwithTextfield(Rect rect, string label, string tooltip, ref float value, FloatRange range)
2022-05-09 03:16:51 +00:00
{
Rect textfieldRect = new Rect(rect.xMax - 100f, rect.y, 100f, rect.height);
string valuestr = value.ToString();
Widgets.Label(rect, label);
2023-03-24 15:22:54 +00:00
Widgets.TextFieldNumeric(textfieldRect, ref value, ref valuestr, range.TrueMin, range.TrueMax);
2022-05-09 03:16:51 +00:00
Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, tooltip);
}
2023-03-24 15:22:54 +00:00
public static void SliderOption(this Listing_Standard outList, string label, string tooltip, SettingHandle<float> handle, FloatRange range, float roundTo)
2022-05-09 03:16:51 +00:00
{
// Slider was fighting with textfield for "correct" decimals. Causes a repeating slider move sound
2023-03-24 15:22:54 +00:00
float fieldValue = handle.Value;
float sliderValue = handle.Value;
2022-05-09 03:16:51 +00:00
float minChange = roundTo / 10f;
2023-03-24 15:22:54 +00:00
string formattedLabel = string.Format(label, handle.Value);
2022-05-09 03:16:51 +00:00
2023-03-24 15:22:54 +00:00
LabelwithTextfield(outList.GetRect(lineHeight), formattedLabel, tooltip, ref fieldValue, range);
sliderValue = Widgets.HorizontalSlider_NewTemp(outList.GetRect(lineHeight), sliderValue, range.TrueMin, range.TrueMax, roundTo: roundTo);
if (Mathf.Abs(fieldValue - handle.Value) > minChange)
handle.Value = fieldValue;
else
2023-03-24 15:22:54 +00:00
handle.Value = sliderValue;
}
public static void CheckboxLabeled(this Listing_Standard outList, string label, SettingHandle<bool> handle, string tooltip)
{
bool value = handle.Value;
outList.CheckboxLabeled(label, ref value, tooltip);
handle.Value = value;
2022-05-09 03:16:51 +00:00
}
}
}