From 5769d431dfbb61abcf42aa42b532e2a4722ae151 Mon Sep 17 00:00:00 2001 From: se5a Date: Mon, 20 May 2024 12:29:40 +1200 Subject: [PATCH] Fixed some issues with techBlueprints and DictEditWidget. --- .../ModFileEditing/BluePrintsUI.cs | 12 ++-- .../ModFileEditing/EditorWidgets.cs | 61 +++++++++---------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs index 9f505c3b6..03c39b8aa 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs @@ -694,10 +694,10 @@ public AttributeBlueprintUI(ModDataStore modDataStore, ComponentTemplateBlueprin public sealed override void Refresh() { - _itemNames = new string[_itemBlueprints.Length]; - _isActive = new bool[_itemBlueprints.Length]; + _itemNames = new string[_blueprints.Length]; + _isActive = new bool[_blueprints.Length]; int i = 0; - foreach (TechCategoryBlueprint item in _itemBlueprints) + foreach (ComponentTemplateAttributeBlueprint item in _blueprints) { if (item is null) _itemNames[i] = "?"; @@ -706,9 +706,9 @@ public sealed override void Refresh() _isActive[i] = false; i++; } - var newEmpty = new TechCategoryBlueprint(); - newEmpty.Name = "New Blueprint"; - _newEmpty = newEmpty; + //var newEmpty = new ComponentTemplateAttributeBlueprint(); + //newEmpty.Name = "New Blueprint"; + //_newEmpty = newEmpty; var type = typeof(IComponentDesignAttribute); var attributeTypes = AppDomain.CurrentDomain.GetAssemblies() diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs index 371c37b4b..dc737d651 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Linq; using System.Numerics; using ImGuiNET; using ImGuiSDL2CS; @@ -114,35 +116,44 @@ public static class DictEditWidget private static uint _buffSize = 128; private static byte[] _strInputBuffer = new byte[128]; private static int _techIndex = 0; - private static int _addnum = -1; + private static int _addKey = -1; + private static int _addVal = -1; public static bool Display(string label, ref Dictionary> dict, string[] techs) { ImGui.BeginChild("##dic"); ImGui.Columns(2); + ImGui.SetColumnWidth(0, 64); bool isChanged = false; - _addnum = -1; - foreach (var kvp in dict) + _addKey = -1; + foreach (var kvp in dict.ToArray()) { _editInt = kvp.Key; + int oldVal = kvp.Key; if (IntEditWidget.Display(label + _editInt, ref _editInt)) { isChanged = true; if(!dict.ContainsKey(_editInt)) - dict.Add(_editInt,kvp.Value); + { + dict.Add(_editInt, kvp.Value); + dict.Remove(oldVal); + } } ImGui.NextColumn(); //values list - foreach (var item in kvp.Value) + int valIndex = 0; + foreach (var item in kvp.Value.ToArray()) { - _editStr = item; - if(TextEditWidget.Display(label+_editInt+item, ref _editStr)) + _techIndex = Array.IndexOf(techs, item); + if(SelectFromListWiget.Display(label+"chValue", techs, ref _techIndex)) { - + dict[kvp.Key][valIndex] = techs[_techIndex]; } + valIndex++; } + if(_editingID != label+"addValue") { - if (ImGui.Button("+")) + if (ImGui.Button("+##addval" + label)) { _editingID = label+"addValue"; } @@ -152,26 +163,14 @@ public static bool Display(string label, ref Dictionary> dict, if (SelectFromListWiget.Display(label+"addValue", techs, ref _techIndex)) { dict[kvp.Key].Add(techs[_techIndex]); + _editingID = null; } } ImGui.NextColumn(); - if(_editingID != label+"addKey") - { - if (ImGui.Button("+")) - { - _editingID = label+"addKey"; - } - } - else - { - _addnum = dict.Keys.Count; - while (dict.ContainsKey(_addnum)) - _addnum++; - _editingID = null; - } + ImGui.Separator(); } - if (dict.Count == 0) + //if (dict.Count == 0) { if(_editingID != label+"addKey") { @@ -182,16 +181,14 @@ public static bool Display(string label, ref Dictionary> dict, } else { - _addnum = dict.Keys.Count; - while (dict.ContainsKey(_addnum)) - _addnum++; + _addKey = dict.Keys.Count; + while (dict.ContainsKey(_addKey)) + _addKey++; + dict.Add(_addKey, new List()); _editingID = null; } } - if(_addnum > -1) //do this here so we don't add in the middle of foreach - dict.Add(_addnum, new List()); - ImGui.EndChild(); return isChanged; } @@ -203,7 +200,7 @@ public static bool Display(string label, ref Dictionary dict) bool isChanged = false; if (dict is null) dict = new Dictionary(); - _addnum = -1; + _addKey = -1; foreach (var kvp in dict) { _editStr = kvp.Key; @@ -243,7 +240,7 @@ public static bool Display(string label, ref Dictionary dict) bool isChanged = false; if (dict is null) dict = new Dictionary(); - _addnum = -1; + _addKey = -1; foreach (var kvp in dict) { _editStr = kvp.Key;