New settings handling

This commit is contained in:
amevarashi 2023-03-24 20:22:54 +05:00
parent fed4b54915
commit 8d49addd63
24 changed files with 309 additions and 233 deletions

View file

@ -7,30 +7,39 @@ namespace RJWSexperience.Settings
{
public const float lineHeight = 24f;
public static void LabelwithTextfield(Rect rect, string label, string tooltip, ref float value, float min, float max)
public static void LabelwithTextfield(Rect rect, string label, string tooltip, ref float value, FloatRange range)
{
Rect textfieldRect = new Rect(rect.xMax - 100f, rect.y, 100f, rect.height);
string valuestr = value.ToString();
Widgets.Label(rect, label);
Widgets.TextFieldNumeric(textfieldRect, ref value, ref valuestr, min, max);
Widgets.TextFieldNumeric(textfieldRect, ref value, ref valuestr, range.TrueMin, range.TrueMax);
Widgets.DrawHighlightIfMouseover(rect);
TooltipHandler.TipRegion(rect, tooltip);
}
public static void SliderOption(Rect doublerect, string label, string tooltip, ref float value, float min, float max, float roundTo)
public static void SliderOption(this Listing_Standard outList, string label, string tooltip, SettingHandle<float> handle, FloatRange range, float roundTo)
{
// Slider was fighting with textfield for "correct" decimals. Causes a repeating slider move sound
float fieldValue = value;
float sliderValue = value;
float fieldValue = handle.Value;
float sliderValue = handle.Value;
float minChange = roundTo / 10f;
LabelwithTextfield(doublerect.TopHalf(), label, tooltip, ref fieldValue, min, max);
sliderValue = Widgets.HorizontalSlider(doublerect.BottomHalf(), sliderValue, min, max, roundTo: roundTo);
string formattedLabel = string.Format(label, handle.Value);
if (Mathf.Abs(fieldValue - value) > minChange)
value = fieldValue;
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
value = sliderValue;
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;
}
}
}