Skip to content

Commit

Permalink
Fixed some issues with techBlueprints and DictEditWidget.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed May 20, 2024
1 parent c2e5edd commit 5769d43
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
12 changes: 6 additions & 6 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "?";
Expand All @@ -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()
Expand Down
61 changes: 29 additions & 32 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using ImGuiNET;
using ImGuiSDL2CS;
Expand Down Expand Up @@ -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<int, List<string>> 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";
}
Expand All @@ -152,26 +163,14 @@ public static bool Display(string label, ref Dictionary<int, List<string>> 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")
{
Expand All @@ -182,16 +181,14 @@ public static bool Display(string label, ref Dictionary<int, List<string>> 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<string>());
_editingID = null;
}
}

if(_addnum > -1) //do this here so we don't add in the middle of foreach
dict.Add(_addnum, new List<string>());

ImGui.EndChild();
return isChanged;
}
Expand All @@ -203,7 +200,7 @@ public static bool Display(string label, ref Dictionary<string, string> dict)
bool isChanged = false;
if (dict is null)
dict = new Dictionary<string, string>();
_addnum = -1;
_addKey = -1;
foreach (var kvp in dict)
{
_editStr = kvp.Key;
Expand Down Expand Up @@ -243,7 +240,7 @@ public static bool Display(string label, ref Dictionary<string, long> dict)
bool isChanged = false;
if (dict is null)
dict = new Dictionary<string, long>();
_addnum = -1;
_addKey = -1;
foreach (var kvp in dict)
{
_editStr = kvp.Key;
Expand Down

0 comments on commit 5769d43

Please sign in to comment.