using ImGuiNET; using SzCore; using SzCore.DataObjects; namespace SzGui.Windows; public class SzTemplateCreatorWindow : SzGuiWindowBase { private string _name = ""; private string _type = ""; private List _fields = new(); private string _newFieldId = ""; private int _selectedTypeIndex = 0; public SzTemplateCreatorWindow() => WindowName = "Template Creator"; protected override void RenderContent() { ImGui.InputText("Template Name", ref _name, 64); ImGui.InputText("Object Type", ref _type, 64); ImGui.SeparatorText("Fields"); for (int i = 0; i < _fields.Count; i++) { ImGui.BulletText($"{_fields[i].Id} ({_fields[i].FieldType})"); ImGui.SameLine(); if (ImGui.Button($"Remove##{i}")) _fields.RemoveAt(i); } ImGui.Separator(); ImGui.InputText("Field ID", ref _newFieldId, 64); string[] typeNames = Enum.GetNames(); ImGui.Combo("Type", ref _selectedTypeIndex, typeNames, typeNames.Length); if (ImGui.Button("Add Field")) { var result = SZ.DataHandler.CreateTemplateField(_newFieldId, (SzFieldType)_selectedTypeIndex); if (result.IsSuccess) { _fields.Add(result.Value!); _newFieldId = ""; // Reset } } ImGui.Separator(); if (ImGui.Button("Save Template", new System.Numerics.Vector2(0, 30))) { Save(); } } private async void Save() { var result = SZ.DataHandler.CreateDataObjectTemplate(_name, _type, fields: _fields); if (result.IsSuccess) { await SZ.DataHandler.SaveTemplateAsync(result.Value!); IsOpen = false; } } }