Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src_plugin/UI/InteractiveValues/InteractiveColor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using UnityEngine;
Expand Down Expand Up @@ -32,20 +33,20 @@ private void RefreshColorUI()
{
if (this.Value is Color32 c32)
{
inputs[0].text = c32.r.ToString();
inputs[1].text = c32.g.ToString();
inputs[2].text = c32.b.ToString();
inputs[3].text = c32.a.ToString();
inputs[0].text = c32.r.ToString(CultureInfo.InvariantCulture);
inputs[1].text = c32.g.ToString(CultureInfo.InvariantCulture);
inputs[2].text = c32.b.ToString(CultureInfo.InvariantCulture);
inputs[3].text = c32.a.ToString(CultureInfo.InvariantCulture);

if (colorImage)
colorImage.color = c32;
}
else if (this.Value is Color color)
{
inputs[0].text = color.r.ToString();
inputs[1].text = color.g.ToString();
inputs[2].text = color.b.ToString();
inputs[3].text = color.a.ToString();
inputs[0].text = color.r.ToString(CultureInfo.InvariantCulture);
inputs[1].text = color.g.ToString(CultureInfo.InvariantCulture);
inputs[2].text = color.b.ToString(CultureInfo.InvariantCulture);
inputs[3].text = color.a.ToString(CultureInfo.InvariantCulture);

if (colorImage)
colorImage.color = color;
Expand Down Expand Up @@ -110,13 +111,13 @@ internal void AddEditorRow(int index, GameObject groupObj)
{
if (Value is Color)
{
float val = float.Parse(value);
float val = float.Parse(value, CultureInfo.InvariantCulture);
SetValueToColor(val);
sliders[index].value = val;
}
else
{
byte val = byte.Parse(value);
byte val = byte.Parse(value, CultureInfo.InvariantCulture);
SetValueToColor32(val);
sliders[index].value = val;
}
Expand Down Expand Up @@ -150,9 +151,9 @@ internal void AddEditorRow(int index, GameObject groupObj)
}
else
{
inputField.Text = value.ToString();
inputField.Text = value.ToString(CultureInfo.InvariantCulture);
SetValueToColor(value);
inputs[index].text = value.ToString();
inputs[index].text = value.ToString(CultureInfo.InvariantCulture);
}
}
catch (Exception ex)
Expand Down
5 changes: 3 additions & 2 deletions src_plugin/UI/InteractiveValues/InteractiveFloatStruct.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using UnityEngine;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void RefreshUI(InputField[] inputs, object instance)
{
FieldInfo field = fields[i];
float val = (float)field.GetValue(instance);
inputs[i].text = val.ToString();
inputs[i].text = val.ToString(CultureInfo.InvariantCulture);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -167,7 +168,7 @@ internal void AddEditorRow(int index, GameObject groupObj)
{
try
{
float f = float.Parse(val);
float f = float.Parse(val, CultureInfo.InvariantCulture);
Value = structInfo.SetValue(ref this.Value, index, f);
Owner.SetValueFromIValue();
}
Expand Down
41 changes: 24 additions & 17 deletions src_plugin/UI/InteractiveValues/InteractiveNumber.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Reflection;
Expand All @@ -19,8 +20,11 @@ public class InteractiveNumber : InteractiveValue
internal InputFieldRef valueInput;
private Slider slider;

public MethodInfo ParseMethod => parseMethod ??= Value.GetType().GetMethod("Parse", new Type[] { typeof(string) });
private MethodInfo parseMethod;
public MethodInfo ParseMethod => parseMethod ??= Value.GetType().GetMethod("Parse", new Type[] { typeof(string), typeof(CultureInfo) });
private MethodInfo parseMethod;

public MethodInfo ToStringMethod => toStringMethod ??= Value.GetType().GetMethod("ToString", new Type[] { typeof(IFormatProvider) });
private MethodInfo toStringMethod;

public InteractiveNumber(object value, Type valueType) : base(value, valueType) { }

Expand All @@ -29,20 +33,20 @@ public override bool SupportsType(Type type)

public override void RefreshUIForValue()
{
valueInput.Text = Value.ToString();
valueInput.Text = (string)ToStringMethod.Invoke(Value, new object[] { CultureInfo.InvariantCulture });

if (!valueInput.Component.gameObject.activeSelf)
valueInput.Component.gameObject.SetActive(true);

if (slider)
slider.value = (float)Convert.ChangeType(Value, typeof(float));
slider.value = (float)Convert.ChangeType(Value, typeof(float), CultureInfo.InvariantCulture);
}

internal void SetValueFromInput()
{
try
{
Value = ParseMethod.Invoke(null, new object[] { valueInput.Text });
Value = ParseMethod.Invoke(null, new object[] { valueInput.Text, CultureInfo.InvariantCulture });

if (Owner.RefConfig.Description?.AcceptableValues is AcceptableValueBase acceptable
&& !acceptable.IsValid(Value))
Expand Down Expand Up @@ -84,30 +88,33 @@ public override void ConstructUI(GameObject parent)
Type gtype = typeof(AcceptableValueRange<>).MakeGenericType(range.ValueType);
object minValue = AccessTools.Property(gtype, "MinValue").GetValue(range, null);
object maxValue = AccessTools.Property(gtype, "MaxValue").GetValue(range, null);
string minValueStr = (string)ToStringMethod.Invoke(minValue, new object[] { CultureInfo.InvariantCulture });
string maxValueStr = (string)ToStringMethod.Invoke(maxValue, new object[] { CultureInfo.InvariantCulture });


Owner.mainLabel.text += $" <color=grey><i>[{minValue.ToString()} - {maxValue.ToString()}]</i></color>";
Owner.mainLabel.text += $" <color=grey><i>[{minValueStr} - {maxValueStr}]</i></color>";

GameObject sliderObj = UIFactory.CreateSlider(mainContent, "ValueSlider", out slider);
UIFactory.SetLayoutElement(sliderObj, minWidth: 250, minHeight: 25);

slider.minValue = (float)Convert.ChangeType(minValue, typeof(float));
slider.maxValue = (float)Convert.ChangeType(maxValue, typeof(float));
slider.minValue = (float)Convert.ChangeType(minValue, typeof(float), CultureInfo.InvariantCulture);
slider.maxValue = (float)Convert.ChangeType(maxValue, typeof(float), CultureInfo.InvariantCulture);

slider.value = (float)Convert.ChangeType(Value, typeof(float));
slider.value = (float)Convert.ChangeType(Value, typeof(float), CultureInfo.InvariantCulture);

slider.onValueChanged.AddListener((float val) =>
{
Value = Convert.ChangeType(val, FallbackType);
Value = Convert.ChangeType(val, FallbackType, CultureInfo.InvariantCulture);
Owner.SetValueFromIValue();
valueInput.Text = Value.ToString();
});

//m_valueInput.onValueChanged.AddListener((string val) =>
//{
// SetValueFromInput
// //slider.value = (float)Convert.ChangeType(Value, typeof(float));
//});
}
}
//m_valueInput.onValueChanged.AddListener((string val) =>
//{
// SetValueFromInput
// //slider.value = (float)Convert.ChangeType(Value, typeof(float), CultureInfo.InvariantCulture);
//});
}
}
}
}