diff --git a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs index 9dfe2ecb4..f89897b81 100644 --- a/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs +++ b/Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs @@ -38,14 +38,16 @@ public abstract class BluePrintsUI private protected bool _showFileDialog = false; private protected string _fileDialogPath = ""; private protected string _fileName = ""; + private protected ModInstruction.DataType _dataType; - protected BluePrintsUI(ModDataStore modDataStore) + protected BluePrintsUI(ModDataStore modDataStore, ModInstruction.DataType dataType) { _modDataStore = modDataStore; _cargoTypes = modDataStore.CargoTypes.Keys.ToArray(); _techCatTypes = modDataStore.TechCategories.Keys.ToArray(); _techTypes = modDataStore.Techs.Keys.ToArray(); _industryTypes = modDataStore.IndustryTypes.Keys.ToArray(); + _dataType = dataType; _units = new string[9]; _units[0] = ""; @@ -61,14 +63,31 @@ protected BluePrintsUI(ModDataStore modDataStore) _mountTypes = Enum.GetNames(typeof(ComponentMountType)); _constrGuiHints = Enum.GetNames(typeof(ConstructableGuiHints)); _guiHints = Enum.GetNames(typeof(GuiHint)); - - - } public abstract void Refresh(); - protected abstract void Save(); + private void Save() + { + using (StreamWriter outputFile = new StreamWriter(Path.Combine(_fileDialogPath, _fileName))) + { + JArray output = new JArray(); + foreach (var bpt in _itemBlueprints) + { + ModInstruction modInstruction = new ModInstruction(); + modInstruction.Type = _dataType; + modInstruction.Data = bpt; + + JObject jObject = new JObject + { + { "Type", modInstruction.Type.ToString() }, + { "Payload", JObject.FromObject(modInstruction.Data) } + }; + output.Add(jObject); + } + outputFile.Write(output); + }; + } public void Display(string label) { @@ -161,7 +180,7 @@ void removeAtIndex(int index) public class TechCatBlueprintUI : BluePrintsUI { - public TechCatBlueprintUI(ModDataStore modDataStore) : base(modDataStore) + public TechCatBlueprintUI(ModDataStore modDataStore) : base(modDataStore, ModInstruction.DataType.TechCategory) { Dictionary blueprints = _modDataStore.TechCategories; _itemBlueprints = blueprints.Values.ToArray(); @@ -183,47 +202,8 @@ public sealed override void Refresh() newEmpty.Name = "New Blueprint"; _newEmpty = newEmpty; } - - protected override void Save() - { - using (StreamWriter outputFile = new StreamWriter(Path.Combine(_fileDialogPath, _fileName))) - { - JArray output = new JArray(); - foreach (TechCategoryBlueprint bpt in _itemBlueprints) - { - ModInstruction modInstruction = new ModInstruction(); - modInstruction.Type = ModInstruction.DataType.TechCategory; - modInstruction.Data = bpt; - - var json = JsonConvert.SerializeObject( - modInstruction, - Formatting.Indented, - new JsonSerializerSettings { Converters = new List { new ModInstructionJsonConverter() } }); - output.Add(json); - } - - outputFile.Write(output); - - /* - Dictionary> dic = new Dictionary>(); - dic.Add(ModInstruction.DataType.TechCategory, new List()); - foreach (TechCategoryBlueprint bpt in _itemBlueprints) - { - dic[ModInstruction.DataType.TechCategory].Add(bpt); - } - var json = JsonConvert.SerializeObject(dic, Formatting.Indented); - outputFile.WriteLine(json); - */ - } - } - - class Tcb - { - [JsonConverter(typeof(StringEnumConverter))] - public ModInstruction.DataType Type = ModInstruction.DataType.TechCategory; - public List Payload; - } - + + public override void DisplayEditorWindow(int selectedIndex) { if(!_isActive[selectedIndex]) @@ -258,7 +238,7 @@ public override void DisplayEditorWindow(int selectedIndex) public class TechBlueprintUI : BluePrintsUI { private int _selectedIndex = -1; - public TechBlueprintUI(ModDataStore modDataStore) : base(modDataStore) + public TechBlueprintUI(ModDataStore modDataStore) : base(modDataStore, ModInstruction.DataType.Tech) { var blueprints = modDataStore.Techs; _itemBlueprints = blueprints.Values.ToArray(); @@ -280,11 +260,7 @@ public override void Refresh() newEmpty.Name = "New Blueprint"; _newEmpty = newEmpty; } - - protected override void Save() - { - throw new NotImplementedException(); - } + public override void DisplayEditorWindow(int selectedIndex) { @@ -380,7 +356,7 @@ public class ComponentBluprintUI : BluePrintsUI { private AttributeBlueprintUI? _attributeBlueprintUI; private List _selectedAttributes; - public ComponentBluprintUI(ModDataStore modDataStore) : base(modDataStore) + public ComponentBluprintUI(ModDataStore modDataStore) : base(modDataStore, ModInstruction.DataType.ComponentTemplate) { Dictionary blueprints = modDataStore.ComponentTemplates; _itemBlueprints = blueprints.Values.ToArray(); @@ -401,12 +377,7 @@ public sealed override void Refresh() newEmpty.Name = "New Blueprint"; _newEmpty = newEmpty; } - - protected override void Save() - { - throw new NotImplementedException(); - } - + public override void DisplayEditorWindow(int selectedIndex) { @@ -508,7 +479,7 @@ public override void DisplayEditorWindow(int selectedIndex) public class ArmorBlueprintUI : BluePrintsUI { - public ArmorBlueprintUI(ModDataStore modDataStore) : base(modDataStore) + public ArmorBlueprintUI(ModDataStore modDataStore) : base(modDataStore, ModInstruction.DataType.Armor) { Dictionary blueprints = _modDataStore.Armor; _itemBlueprints = blueprints.Values.ToArray(); @@ -530,12 +501,7 @@ public sealed override void Refresh() newEmpty.UniqueID = "New Blueprint"; _newEmpty = newEmpty; } - - protected override void Save() - { - throw new NotImplementedException(); - } - + public override void DisplayEditorWindow(int selectedIndex) { @@ -584,7 +550,7 @@ public override void DisplayEditorWindow(int selectedIndex) public class ProcessedMateralsUI : BluePrintsUI { private int _selectedIndex = -1; - public ProcessedMateralsUI(ModDataStore modDataStore) : base(modDataStore) + public ProcessedMateralsUI(ModDataStore modDataStore) : base(modDataStore, ModInstruction.DataType.ProcessedMaterial) { var blueprints = modDataStore.ProcessedMaterials; _itemBlueprints = blueprints.Values.ToArray(); @@ -606,12 +572,7 @@ public sealed override void Refresh() newEmpty.Name = "New Blueprint"; _newEmpty = newEmpty; } - - protected override void Save() - { - throw new NotImplementedException(); - } - + public override void DisplayEditorWindow(int selectedIndex) { @@ -749,7 +710,7 @@ public override void DisplayEditorWindow(int selectedIndex) public class MineralBlueprintUI : BluePrintsUI { - public MineralBlueprintUI(ModDataStore modDataStore) : base(modDataStore) + public MineralBlueprintUI(ModDataStore modDataStore) : base(modDataStore, ModInstruction.DataType.Mineral) { var blueprints = modDataStore.Minerals; _itemBlueprints = blueprints.Values.ToArray(); @@ -772,11 +733,6 @@ public override void Refresh() _newEmpty = newEmpty; } - protected override void Save() - { - throw new NotImplementedException(); - } - public override void DisplayEditorWindow(int selectedIndex) { @@ -861,7 +817,7 @@ public class AttributeBlueprintUI : BluePrintsUI private ComponentTemplateAttributeBlueprint[] _blueprints; private string[] _attributeTypeNames; private string[] _attributeFullNames; - public AttributeBlueprintUI(ModDataStore modDataStore, ComponentTemplateBlueprint componentBlueprint) : base(modDataStore) + public AttributeBlueprintUI(ModDataStore modDataStore, ComponentTemplateBlueprint componentBlueprint) : base(modDataStore, ModInstruction.DataType.ComponentTemplate ) { _parentID = componentBlueprint.UniqueID; if(componentBlueprint.Attributes != null) @@ -909,12 +865,6 @@ public sealed override void Refresh() } } - protected override void Save() - { - throw new NotImplementedException(); - } - - public void Display() { ImGui.Columns(2);