mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
ScriptCore: Add Entry for dictionaries
This commit is contained in:
@@ -12,6 +12,7 @@ namespace GlitchyEngine.Editor;
|
||||
public class DictionaryEditor
|
||||
{
|
||||
private static object? dictionaryForNewValue = null;
|
||||
private static DictionaryEntry newDictionaryValue = new();
|
||||
|
||||
public static object? ShowEditor(object? reference, Type fieldType, string fieldName)
|
||||
{
|
||||
@@ -53,9 +54,11 @@ public class DictionaryEditor
|
||||
|
||||
//if (newKey != null)
|
||||
// dictionary!.Add(newKey, newValue);
|
||||
|
||||
newDictionaryValue = new DictionaryEntry();
|
||||
}
|
||||
|
||||
ImGuiExtension.AttachTooltip("Add a new Element to the dictionary.");
|
||||
ImGuiExtension.AttachTooltip("Add a new Entry to the dictionary.");
|
||||
|
||||
if (listOpen)
|
||||
{
|
||||
@@ -102,7 +105,49 @@ public class DictionaryEditor
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
|
||||
if (ReferenceEquals(dictionaryForNewValue, dictionary))
|
||||
{
|
||||
ImGui.PushID("NewEntry");
|
||||
|
||||
ImGui.SetNextItemOpen(true);
|
||||
bool isEntryOpen = ImGui.TreeNode("");
|
||||
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMax().X - removeButtonWidth);
|
||||
|
||||
if (ImGui.SmallButton("-"))
|
||||
{
|
||||
dictionaryForNewValue = null;
|
||||
newDictionaryValue = new();
|
||||
}
|
||||
|
||||
ImGuiExtension.AttachTooltip("Remove the Entry from the dictionary");
|
||||
|
||||
if (isEntryOpen)
|
||||
{
|
||||
object newKey = EntityEditor.ShowFieldEditor(newDictionaryValue.Key, keyType, "Key");
|
||||
|
||||
if (newKey != EntityEditor.DidNotChange)
|
||||
{
|
||||
newEntries.Add(new DictionaryEntry(newKey, newDictionaryValue.Value));
|
||||
dictionaryForNewValue = null;
|
||||
newDictionaryValue = new();
|
||||
}
|
||||
|
||||
object newValue = EntityEditor.ShowFieldEditor(newDictionaryValue.Value, newDictionaryValue.Value?.GetType() ?? valueType, "Value");
|
||||
|
||||
if (newValue != EntityEditor.DidNotChange)
|
||||
{
|
||||
newDictionaryValue.Value = newValue;
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ internal class EntityEditor
|
||||
return (T?)attributes?.FirstOrDefault(a => a is T);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -230,6 +230,10 @@ internal class EntityEditor
|
||||
ImGui.TextColored(new Vector4(1, 0, 0, 1), $"{fieldName}: Type {fieldType} is not implemented.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ActivatorExtension.CreateInstanceSafe(fieldType);
|
||||
}
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user