Skip to content

Commit

Permalink
More editor work.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed May 13, 2024
1 parent b9de572 commit 7cde086
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 36 deletions.
66 changes: 44 additions & 22 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/BluePrintsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public abstract class BluePrintsUI
private protected string[] _cargoTypes;
private protected string[] _techCatTypes;
private protected string[] _techTypes;
private protected string[] _industryTypes;
protected BluePrintsUI(ModDataStore modDataStore)
{
_modDataStore = modDataStore;
_cargoTypes = modDataStore.CargoTypes.Keys.ToArray();
_techCatTypes = modDataStore.TechCategories.Keys.ToArray();
_techTypes = modDataStore.Techs.Keys.ToArray();
_industryTypes = modDataStore.IndustryTypes.Keys.ToArray();
}

public abstract void Display();
Expand Down Expand Up @@ -291,68 +293,88 @@ public void DisplayEditorWindow(int selectedIndex)
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))
if (TextEditWidget.Display("##cmpt" + 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 editIndex))
editIndex = Array.IndexOf(_cargoTypes, selectedItem.CargoTypeID);
if (SelectFromListWiget.Display("##cgot" + selectedItem.CargoTypeID, _cargoTypes, ref editIndex))
{
selectedItem.Name = _cargoTypes[editIndex];
}

ImGui.NextColumn();


ImGui.Text("Fomula: ");
ImGui.NextColumn();
var editDicf = selectedItem.Formulas;
if (DictEditWidget.Display("##fmula", ref editDicf))
{
selectedItem.Formulas = editDicf;
}
ImGui.NextColumn();


ImGui.Text("ResourceCosts: ");
ImGui.NextColumn();
var editDic = selectedItem.ResourceCost;
if (DictEditWidget.Display("##cgt", ref editDic))
if (DictEditWidget.Display("##resc", ref editDic))
{
selectedItem.ResourceCost = editDic;
}
ImGui.NextColumn();


ImGui.Text("IndustryType: ");
ImGui.NextColumn();
editIndex = Array.IndexOf(_industryTypes, selectedItem.IndustryTypeID);
if (SelectFromListWiget.Display("##indt" + selectedItem.IndustryTypeID, _industryTypes, ref editIndex))
{
selectedItem.IndustryTypeID = _industryTypes[editIndex];
}
ImGui.NextColumn();


ImGui.Text("MountType: ");
ImGui.NextColumn();
string[] mountTypes = Enum.GetNames(typeof(ComponentMountType));
editIndex = Array.IndexOf(_industryTypes, selectedItem.MountType);
if (SelectFromListWiget.Display("##mntt" + selectedItem.IndustryTypeID, mountTypes, ref editIndex))
{

if(Enum.TryParse(typeof(ComponentMountType), mountTypes[editIndex], out var mtype))
selectedItem.MountType = (ComponentMountType)mtype;
}
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());
*/
ImGui.End();
}
}
}
30 changes: 16 additions & 14 deletions Pulsar4X/Pulsar4X.Client/ModFileEditing/EditorWidgets.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Numerics;
using ImGuiNET;
using ImGuiSDL2CS;

Expand Down Expand Up @@ -83,13 +84,13 @@ 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;
public static bool Display(string label, ref Dictionary<int, List<string>> dict, string[] techs)
{
ImGui.BeginChild("##dic");
ImGui.Columns(2);
bool isChanged = false;
int addnum = -1;
_addnum = -1;
foreach (var kvp in dict)
{
_editInt = kvp.Key;
Expand Down Expand Up @@ -133,45 +134,46 @@ public static bool Display(string label, ref Dictionary<int, List<string>> dict,
}
else
{
addnum = dict.Keys.Count;
while (dict.ContainsKey(addnum))
addnum++;
_addnum = dict.Keys.Count;
while (dict.ContainsKey(_addnum))
_addnum++;
_editingID = null;
}
}
if(addnum > -1) //do this here so we don't add in the middle of foreach
dict.Add(addnum, new List<string>());
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;
}

public static bool Display(string label, ref Dictionary<string, string> dict)
{
ImGui.BeginChild("##dic");
ImGui.BeginChild("##dic" + label, new Vector2(400,160), true);
ImGui.Columns(2);
bool isChanged = false;
_addnum = -1;
foreach (var kvp in dict)
{
_editStr = kvp.Key;
if (TextEditWidget.Display(label + _editInt, ref _editStr))
if (TextEditWidget.Display(label + kvp.Key + "k", ref _editStr))
{
isChanged = true;
if(!dict.ContainsKey(_editStr))
dict.Add(_editStr,kvp.Value);
}
ImGui.NextColumn();
//values list


//values
_editStr = kvp.Value;
if(TextEditWidget.Display(label+kvp.Value, ref _editStr))
if(TextEditWidget.Display(label+kvp.Key + "v", ref _editStr))
{
dict[kvp.Key] = _editStr;
}

ImGui.NextColumn();
}

ImGui.Columns(0);
ImGui.NewLine();
ImGui.EndChild();

return isChanged;
Expand Down

0 comments on commit 7cde086

Please sign in to comment.