diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs index 45ed90b0d..edcf34523 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs @@ -4,6 +4,7 @@ using ImGuiSDL2CS; using Pulsar4X.Blueprints; using Pulsar4X.DataStructures; +using Pulsar4X.Engine; namespace Pulsar4X.SDL2UI.ModFileEditing; @@ -21,7 +22,7 @@ public class TechCatBlueprintUI : BluePrintsUI { - public TechCatBlueprintUI(SafeDictionary blueprints) + public TechCatBlueprintUI(Dictionary blueprints) { _itemNames = new string[blueprints.Count]; _itemBlueprints = new Blueprint[blueprints.Count]; @@ -93,49 +94,6 @@ private void DisplayEditorWindow(int selectedIndex) } } -public static class TextEditWidget -{ - private static uint _buffSize = 128; - private static byte[] _strInputBuffer = new byte[128]; - private static string? _editingID; - - public static uint BufferSize - { - get { return _buffSize ;} - set - { - _buffSize = value; - _strInputBuffer = new byte[value]; - } - } - - public static bool Display(string label, ref string text) - { - bool hasChanged = false; - if(label != _editingID) - { - ImGui.Text(text); - if(ImGui.IsItemClicked()) - { - _editingID = label; - _strInputBuffer = ImGuiSDL2CSHelper.BytesFromString(text); - - } - } - else - { - if (ImGui.InputText(label, _strInputBuffer, _buffSize, ImGuiInputTextFlags.EnterReturnsTrue)) - { - text = ImGuiSDL2CSHelper.StringFromBytes(_strInputBuffer); - _editingID = null; - hasChanged = true; - } - } - - return hasChanged; - } -} - public class TechBlueprintUI : BluePrintsUI { public TechBlueprintUI(IDictionary blueprints) @@ -230,7 +188,7 @@ public void DisplayEditorWindow(int selectedIndex) ImGui.Text("DataFormula: "); ImGui.NextColumn(); editStr = selectedItem.DataFormula; - if (TextEditWidget.Display("##cf" + selectedItem.DataFormula, ref editStr)) + if (TextEditWidget.Display("##df" + selectedItem.DataFormula, ref editStr)) { selectedItem.DataFormula = editStr; } @@ -238,17 +196,21 @@ public void DisplayEditorWindow(int selectedIndex) ImGui.Text("MaxLevel: "); - ImGui.NextColumn(); - ImGui.Text("MaxLevel: "); - ImGui.SameLine(); - ImGui.Text(selectedItem.MaxLevel.ToString()); + ImGui.NextColumn(); + int editInt = selectedItem.MaxLevel; + if (IntEditWidget.Display("##ml" + selectedItem.MaxLevel.ToString(), ref editInt)) + { + selectedItem.MaxLevel = editInt; + } ImGui.NextColumn(); ImGui.Text("Unlocks: "); ImGui.NextColumn(); - ImGui.Text("Unlocks: "); - ImGui.SameLine(); - ImGui.Text(selectedItem.Unlocks.ToString()); + var editDic = selectedItem.Unlocks; + if (DictEditWidget.Display("##ul" + selectedItem.Name, ref editDic)) + { + + } ImGui.End(); @@ -259,56 +221,118 @@ public void DisplayEditorWindow(int selectedIndex) public class ComponentBluprintUI : BluePrintsUI { - public ComponentBluprintUI(Dictionary blueprints) + private string[] _cargoTypes; + public ComponentBluprintUI(Dictionary blueprints, string[] cargoTypes ) { _itemNames = new string[blueprints.Count]; _itemBlueprints = new Blueprint[blueprints.Count]; + _cargoTypes = cargoTypes; + _isActive = new bool[blueprints.Count]; int i = 0; foreach (var kvp in blueprints) { _itemNames[i] = kvp.Key; _itemBlueprints[i] = kvp.Value; + _isActive[i] = false; i++; } } public override void Display() { - //BorderListOptions.Begin("Tech Blueprints", _itemNames, ref _selecteditem, 200); + ImGui.Columns(2); + ImGui.SetColumnWidth(0,200); + ImGui.SetColumnWidth(1,100); - var selected = (ComponentTemplateBlueprint)_itemBlueprints[_selecteditem]; - ImGui.Text("Name: "); - ImGui.SameLine(); - ImGui.Text(selected.Name); + int i = 0; + foreach (ComponentTemplateBlueprint item in _itemBlueprints) + { + ImGui.Text(item.Name); + ImGui.NextColumn(); + if(ImGui.Checkbox("Edit##"+_itemNames[i], ref _isActive[i])); + { + } + DisplayEditorWindow(i); + ImGui.NextColumn(); + i++; + } + } - ImGui.Text("ComponentType: "); - ImGui.SameLine(); - ImGui.Text(selected.ComponentType); - - ImGui.Text("CargoType: "); - ImGui.SameLine(); - ImGui.Text(selected.CargoTypeID); - - ImGui.Text("ResourceCosts: "); - ImGui.SameLine(); - ImGui.Text(selected.ResourceCost.ToString()); - - ImGui.Text("IndustryType: "); - ImGui.SameLine(); - ImGui.Text(selected.IndustryTypeID); - - ImGui.Text("Attributes: "); - ImGui.SameLine(); - ImGui.Text(selected.Attributes.ToString()); - - ImGui.Text("Formulas: "); - ImGui.SameLine(); - ImGui.Text(selected.Formulas.ToString()); - - ImGui.Text("MountType: "); - ImGui.SameLine(); - ImGui.Text(selected.MountType.ToString()); - - //BorderListOptions.End(new Vector2(400, 600)); + public void DisplayEditorWindow(int selectedIndex) + { + + if (!_isActive[selectedIndex]) + return; + var selectedItem = (ComponentTemplateBlueprint)_itemBlueprints[selectedIndex]; + string name = selectedItem.Name; + string editStr; + if (ImGui.Begin("Tech Category Editor: " + name)) + { + ImGui.Columns(2); + ImGui.SetColumnWidth(0, 100); + ImGui.SetColumnWidth(1, 300); + ImGui.Text("Name: "); + ImGui.NextColumn(); + + editStr = selectedItem.Name; + if (TextEditWidget.Display("##name" + selectedItem.Name, ref editStr)) + { + selectedItem.Name = editStr; + } + + ImGui.NextColumn(); + + + ImGui.Text("ComponentType: "); + ImGui.NextColumn(); + editStr = selectedItem.ComponentType; + if (TextEditWidget.Display("##ct" + selectedItem.ComponentType, ref editStr)) + { + selectedItem.Name = editStr; + } + + ImGui.NextColumn(); + + ImGui.Text("CargoType: "); + ImGui.NextColumn(); + editStr = selectedItem.CargoTypeID; + if (SelectFromListWiget.Display("##cgt" + selectedItem.CargoTypeID, _cargoTypes, ref editStr)) + { + selectedItem.Name = editStr; + } + + ImGui.NextColumn(); + + ImGui.Text("ResourceCosts: "); + ImGui.NextColumn(); + var editDic = selectedItem.ResourceCost; + if (DictEditWidget.Display("##cgt", ref editDic)) + { + selectedItem.ResourceCost = editDic; + } + + ImGui.NextColumn(); + /* + ImGui.Text("ResourceCosts: "); + ImGui.SameLine(); + ImGui.Text(selected.ResourceCost.ToString()); + + ImGui.Text("IndustryType: "); + ImGui.SameLine(); + ImGui.Text(selected.IndustryTypeID); + + ImGui.Text("Attributes: "); + ImGui.SameLine(); + ImGui.Text(selected.Attributes.ToString()); + + ImGui.Text("Formulas: "); + ImGui.SameLine(); + ImGui.Text(selected.Formulas.ToString()); + + ImGui.Text("MountType: "); + ImGui.SameLine(); + ImGui.Text(selected.MountType.ToString()); + */ + } } } \ No newline at end of file diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs new file mode 100644 index 000000000..040994605 --- /dev/null +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs @@ -0,0 +1,179 @@ +using System.Collections.Generic; +using ImGuiNET; +using ImGuiSDL2CS; + +namespace Pulsar4X.SDL2UI.ModFileEditing; + +public static class TextEditWidget +{ + private static uint _buffSize = 128; + private static byte[] _strInputBuffer = new byte[128]; + private static string? _editingID; + + public static uint BufferSize + { + get { return _buffSize ;} + set + { + _buffSize = value; + _strInputBuffer = new byte[value]; + } + } + + public static bool Display(string label, ref string text) + { + bool hasChanged = false; + if(label != _editingID) + { + ImGui.Text(text); + if(ImGui.IsItemClicked()) + { + _editingID = label; + _strInputBuffer = ImGuiSDL2CSHelper.BytesFromString(text); + + } + } + else + { + if (ImGui.InputText(label, _strInputBuffer, _buffSize, ImGuiInputTextFlags.EnterReturnsTrue)) + { + text = ImGuiSDL2CSHelper.StringFromBytes(_strInputBuffer); + _editingID = null; + hasChanged = true; + } + } + + return hasChanged; + } +} +public static class IntEditWidget +{ + private static string? _editingID; + + public static bool Display(string label, ref int num) + { + bool hasChanged = false; + if(label != _editingID) + { + ImGui.Text(num.ToString()); + if(ImGui.IsItemClicked()) + { + _editingID = label; + } + } + else + { + if (ImGui.InputInt(label, ref num, 1, 1, ImGuiInputTextFlags.EnterReturnsTrue)) + { + _editingID = null; + hasChanged = true; + } + } + + return hasChanged; + } +} + +public static class DictEditWidget +{ + private static string _editingID; + private static int _editInt; + private static string _editStr; + + public static bool Display(string label, ref Dictionary> dict) + { + ImGui.BeginChild("##dic"); + ImGui.Columns(2); + bool isChanged = false; + foreach (var kvp in dict) + { + _editInt = kvp.Key; + if (IntEditWidget.Display(label + _editInt, ref _editInt)) + { + isChanged = true; + if(!dict.ContainsKey(_editInt)) + dict.Add(_editInt,kvp.Value); + } + ImGui.NextColumn(); + //values list + foreach (var item in kvp.Value) + { + _editStr = item; + if(TextEditWidget.Display(label+_editInt+item, ref _editStr)) + { + + } + } + ImGui.NextColumn(); + } + + ImGui.EndChild(); + + return isChanged; + } + + public static bool Display(string label, ref Dictionary dict) + { + ImGui.BeginChild("##dic"); + ImGui.Columns(2); + bool isChanged = false; + foreach (var kvp in dict) + { + _editStr = kvp.Key; + if (TextEditWidget.Display(label + _editInt, ref _editStr)) + { + isChanged = true; + if(!dict.ContainsKey(_editStr)) + dict.Add(_editStr,kvp.Value); + } + ImGui.NextColumn(); + //values list + + _editStr = kvp.Value; + if(TextEditWidget.Display(label+kvp.Value, ref _editStr)) + { + dict[kvp.Key] = _editStr; + } + + ImGui.NextColumn(); + } + + ImGui.EndChild(); + + return isChanged; + } +} + +public static class SelectFromListWiget +{ + private static string _editingID; + private static int _currentItem; + private static string[] _items; + private static int _itemCount; + + public static bool Display(string label, string[] selectFrom, ref string selected) + { + bool hasChanged = false; + if (label != _editingID) + { + ImGui.Text(selected); + if(ImGui.IsItemClicked()) + { + _editingID = label; + _items = selectFrom; + _itemCount = _items.Length; + } + } + else + { + ImGui.Text(selected); + ImGui.SameLine(); + if (ImGui.ListBox(label, ref _currentItem, _items, _itemCount)) + { + selected = _items[_currentItem]; + } + } + + return hasChanged; + } +} \ No newline at end of file diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs index eeb166700..aeefbdf7f 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/ModFileEditor.cs @@ -1,10 +1,13 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Numerics; using ImGuiNET; using Pulsar4X.Blueprints; using Pulsar4X.DataStructures; +using Pulsar4X.Engine; +using Pulsar4X.Modding; namespace Pulsar4X.SDL2UI.ModFileEditing; @@ -14,6 +17,11 @@ public class ModFileEditor : PulsarGuiWindow private TechBlueprintUI _techBlueprintUI; private TechCatBlueprintUI _techCatBlueprintUI; private ComponentBluprintUI _componentBluprintUI; + //private CargoTypeBlueprint _cargoTypeBlueprintUI; + + + + private ModFileEditor() { @@ -35,10 +43,15 @@ internal static ModFileEditor GetInstance() void refresh() { - - _techCatBlueprintUI = new TechCatBlueprintUI(_uiState.Game.TechCategories); - _techBlueprintUI = new TechBlueprintUI(_uiState.Game.StartingGameData.Techs); - _componentBluprintUI = new ComponentBluprintUI(_uiState.Game.StartingGameData.ComponentTemplates); + ModLoader modLoader = new ModLoader(); + ModDataStore modDataStore = new ModDataStore(); + modLoader.LoadModManifest("Data/basemod/modInfo.json", modDataStore); + + _techCatBlueprintUI = new TechCatBlueprintUI(modDataStore.TechCategories); + _techBlueprintUI = new TechBlueprintUI(modDataStore.Techs); + + string[] cargoTypes = modDataStore.CargoTypes.Keys.ToArray(); + _componentBluprintUI = new ComponentBluprintUI(_uiState.Game.StartingGameData.ComponentTemplates, cargoTypes); }