mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Added basic decimal editor
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -100,8 +101,9 @@ internal class EntityEditor
|
|||||||
{
|
{
|
||||||
// TODO: Call custom editors here!
|
// TODO: Call custom editors here!
|
||||||
|
|
||||||
ScriptGlue.Entity_GetScriptInstance(entityId, out object instance);
|
ScriptGlue.Entity_GetScriptInstance(entityId, out object? instance);
|
||||||
|
|
||||||
|
if (instance != null)
|
||||||
ShowEditor(entityType, instance);
|
ShowEditor(entityType, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +112,34 @@ internal class EntityEditor
|
|||||||
return (T?)attributes?.FirstOrDefault(a => a is T);
|
return (T?)attributes?.FirstOrDefault(a => a is T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static object ShowDecimalEditor(object? reference, Type fieldType, string fieldName, IEnumerable<Attribute>? attributes)
|
||||||
|
{
|
||||||
|
if (reference is not decimal value)
|
||||||
|
return DidNotChange;
|
||||||
|
|
||||||
|
string stringValue = value.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
|
byte[] bytes = new byte[30 * 4];
|
||||||
|
|
||||||
|
Encoding.UTF8.GetBytes(stringValue, 0, stringValue.Length, bytes, 0);
|
||||||
|
|
||||||
|
ImGui.PushID("Decimal");
|
||||||
|
|
||||||
|
if (ImGui.InputText(fieldName, bytes, (uint)bytes.Length, ImGuiInputTextFlags.EnterReturnsTrue | ImGuiInputTextFlags.CharsDecimal))
|
||||||
|
{
|
||||||
|
string text = Encoding.UTF8.GetString(bytes);
|
||||||
|
|
||||||
|
if (decimal.TryParse(text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal newValue))
|
||||||
|
{
|
||||||
|
ImGui.PopID();
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.PopID();
|
||||||
|
|
||||||
|
return DidNotChange;
|
||||||
|
}
|
||||||
|
|
||||||
private static object? ShowPrimitiveEditor(object? reference, Type fieldType, string fieldName, IEnumerable<Attribute>? attributes)
|
private static object? ShowPrimitiveEditor(object? reference, Type fieldType, string fieldName, IEnumerable<Attribute>? attributes)
|
||||||
{
|
{
|
||||||
object newValue = DidNotChange;
|
object newValue = DidNotChange;
|
||||||
@@ -184,7 +214,6 @@ internal class EntityEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: allow editing in edit-mode
|
|
||||||
if (reference != null)
|
if (reference != null)
|
||||||
{
|
{
|
||||||
if (fieldType == typeof(bool))
|
if (fieldType == typeof(bool))
|
||||||
@@ -361,7 +390,11 @@ internal class EntityEditor
|
|||||||
}
|
}
|
||||||
else if (fieldType.IsValueType)
|
else if (fieldType.IsValueType)
|
||||||
{
|
{
|
||||||
if (fieldType == typeof(bool2))
|
if (fieldType == typeof(decimal))
|
||||||
|
{
|
||||||
|
newValue = ShowDecimalEditor(reference, fieldType, fieldName, attributes);
|
||||||
|
}
|
||||||
|
else if (fieldType == typeof(bool2))
|
||||||
{
|
{
|
||||||
bool2 value = (bool2)reference;
|
bool2 value = (bool2)reference;
|
||||||
|
|
||||||
@@ -377,7 +410,8 @@ internal class EntityEditor
|
|||||||
if (ImGui.Checkbox($"##{fieldName}Y", ref value.Y))
|
if (ImGui.Checkbox($"##{fieldName}Y", ref value.Y))
|
||||||
newValue = value;
|
newValue = value;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
// Struct
|
// Struct
|
||||||
@@ -396,6 +430,7 @@ internal class EntityEditor
|
|||||||
ImGui.BeginDisabled(readonlyAttribute != null);
|
ImGui.BeginDisabled(readonlyAttribute != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (fieldType.IsSubclassOf(typeof(Entity)) || fieldType == typeof(Entity))
|
else if (fieldType.IsSubclassOf(typeof(Entity)) || fieldType == typeof(Entity))
|
||||||
{
|
{
|
||||||
newValue = ShowEntityDropTarget(fieldName, fieldType, reference);
|
newValue = ShowEntityDropTarget(fieldName, fieldType, reference);
|
||||||
|
|||||||
Reference in New Issue
Block a user