Skip to content

Commit

Permalink
Add multiple FMG refs, conditional FMG refs (soulsmods#662)
Browse files Browse the repository at this point in the history
* Add multiple fmg refs. Add conditional fmg refs. Bonus toys.

* Add some refs

* Cache the correct thing
  • Loading branch information
Philiquaz authored Sep 13, 2023
1 parent 1d1ac00 commit 01107e5
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 40 deletions.
16 changes: 8 additions & 8 deletions StudioCore/Assets/Paramdex/ER/Meta/WorldMapPointParam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,28 @@
<posX AltName="Map Coordinate: X" Wiki="X coordinate" />
<posY AltName="Map Coordinate: Y" Wiki="Y coordinate (not used)" />
<posZ AltName="Map Coordinate: Z" Wiki="Z coordinate" />
<textId1 AltName="Text ID [1]" Wiki="The text ID to display. If the value is invalid (-1), nothing is displayed." />
<textId1 FmgRef="TitleLocations(textType1=0),TitleCharacters(textType1=1)" AltName="Text ID [1]" Wiki="The text ID to display. If the value is invalid (-1), nothing is displayed." />
<textEnableFlagId1 AltName="Text Enable Flag [1]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (0) is invalid, it will be treated as On." />
<textDisableFlagId1 AltName="Text Disable Flag [1]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (0) is invalid, it will be treated as Off." />
<textId2 AltName="Text ID [2]" Wiki="The text ID to display. If it is an invalid value (-2), nothing is displayed." />
<textId2 FmgRef="TitleLocations(textType2=0),TitleCharacters(textType2=1)" AltName="Text ID [2]" Wiki="The text ID to display. If it is an invalid value (-2), nothing is displayed." />
<textEnableFlagId2 AltName="Text Enable Flag [2]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (1) is invalid, it will be treated as On." />
<textDisableFlagId2 AltName="Text Disable Flag [2]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (1) is invalid, it will be treated as Off." />
<textId3 AltName="Text ID [3]" Wiki="The text ID to display. If it is an invalid value (-3), nothing is displayed." />
<textId3 FmgRef="TitleLocations(textType3=0),TitleCharacters(textType3=1)" AltName="Text ID [3]" Wiki="The text ID to display. If it is an invalid value (-3), nothing is displayed." />
<textEnableFlagId3 AltName="Text Enable Flag [3]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (2) is invalid, it will be treated as On." />
<textDisableFlagId3 AltName="Text Disable Flag [3]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (2) is invalid, it will be treated as Off." />
<textId4 AltName="Text ID [4]" Wiki="The text ID to display. If it is an invalid value (-4), nothing is displayed." />
<textId4 FmgRef="TitleLocations(textType4=0),TitleCharacters(textType4=1)" AltName="Text ID [4]" Wiki="The text ID to display. If it is an invalid value (-4), nothing is displayed." />
<textEnableFlagId4 AltName="Text Enable Flag [4]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (3) is invalid, it will be treated as On." />
<textDisableFlagId4 AltName="Text Disable Flag [4]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (3) is invalid, it will be treated as Off." />
<textId5 AltName="Text ID [5]" Wiki="The text ID to display. If it is an invalid value (-5), nothing is displayed." />
<textId5 FmgRef="TitleLocations(textType5=0),TitleCharacters(textType5=1)" AltName="Text ID [5]" Wiki="The text ID to display. If it is an invalid value (-5), nothing is displayed." />
<textEnableFlagId5 AltName="Text Enable Flag [5]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (4) is invalid, it will be treated as On." />
<textDisableFlagId5 AltName="Text Disable Flag [5]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (4) is invalid, it will be treated as Off." />
<textId6 AltName="Text ID [6]" Wiki="The text ID to display. If it is an invalid value (-6), nothing is displayed." />
<textId6 FmgRef="TitleLocations(textType6=0),TitleCharacters(textType6=1)" AltName="Text ID [6]" Wiki="The text ID to display. If it is an invalid value (-6), nothing is displayed." />
<textEnableFlagId6 AltName="Text Enable Flag [6]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (5) is invalid, it will be treated as On." />
<textDisableFlagId6 AltName="Text Disable Flag [6]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (5) is invalid, it will be treated as Off." />
<textId7 AltName="Text ID [7]" Wiki="The text ID to display. If it is an invalid value (-7), nothing is displayed." />
<textId7 FmgRef="TitleLocations(textType7=0),TitleCharacters(textType7=1)" AltName="Text ID [7]" Wiki="The text ID to display. If it is an invalid value (-7), nothing is displayed." />
<textEnableFlagId7 AltName="Text Enable Flag [7]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (6) is invalid, it will be treated as On." />
<textDisableFlagId7 AltName="Text Disable Flag [7]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (6) is invalid, it will be treated as Off." />
<textId8 AltName="Text ID [8]" Wiki="The text ID to display. If it is an invalid value (-8), nothing is displayed." />
<textId8 FmgRef="TitleLocations(textType8=0),TitleCharacters(textType8=1)" AltName="Text ID [8]" Wiki="The text ID to display. If it is an invalid value (-8), nothing is displayed." />
<textEnableFlagId8 AltName="Text Enable Flag [8]" Wiki="Display text Event flag ID. Display if the event flag is On. If the event flag ID (7) is invalid, it will be treated as On." />
<textDisableFlagId8 AltName="Text Disable Flag [8]" Wiki="Hidden event flag ID of the text. If the event flag is On, it will not be displayed. It takes precedence over the display event flag ID. If the event flag ID (7) is invalid, it will be treated as Off." />
<textType1 AltName="Text Type [1]" Wiki="Text type (place name, NPC name, ...)" Enum="WORLD_MAP_POINT_TEXT_TYPE" />
Expand Down
138 changes: 116 additions & 22 deletions StudioCore/Editor/EditorDecorations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void ParamRefText(List<ParamRef> paramRefs, Param.Row context)
ImGui.PopStyleVar();
}
}
public static void FmgRefText(string fmgRef)
public static void FmgRefText(List<FMGRef> fmgRef, Param.Row context)
{
if (fmgRef == null)
return;
Expand All @@ -94,8 +94,47 @@ public static void FmgRefText(string fmgRef)
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1.0f, 1.0f, 0.0f, 1.0f));
ImGui.TextUnformatted($@" [");
ImGui.SameLine();
ImGui.TextUnformatted(fmgRef);
List<string> inactiveRefs = new List<string>();
bool first = true;
foreach (FMGRef r in fmgRef)
{
Param.Cell? c = context?[r.conditionField];
bool inactiveRef = context != null && c != null && Convert.ToInt32(c.Value.Value) != r.conditionValue;
if (inactiveRef)
{
inactiveRefs.Add(r.fmg);
}
else
{
if (first)
{
ImGui.SameLine();
ImGui.TextUnformatted(r.fmg);
}
else
{
ImGui.TextUnformatted(" " + r.fmg);
}
first = false;
}
}

ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.7f, 0.7f, 0.7f, 1.0f));
foreach (string inactive in inactiveRefs)
{
ImGui.SameLine();
if (first)
{
ImGui.TextUnformatted("!" + inactive);
}
else
{
ImGui.TextUnformatted("!"+ inactive);
}
first = false;
}
ImGui.PopStyleColor();

ImGui.SameLine();
ImGui.TextUnformatted("]");
ImGui.PopStyleColor();
Expand Down Expand Up @@ -179,19 +218,48 @@ public static void ParamRefsSelectables(ParamBank bank, List<ParamRef> paramRefs
}
return rows;
}
public static void FmgRefSelectable(string fmgName, dynamic oldval)
private static List<(string, FMGBank.EntryGroup)> resolveFMGRefs(List<FMGRef> fmgRefs, Param.Row context, dynamic oldval)
{
if (fmgName == null || !FMGBank.IsLoaded)
return;
FMGBank.FMGInfo fmgInfo = FMGBank.FmgInfoBank.Find((x) => x.Name == fmgName);
if (fmgInfo == null)
return;
FMG.Entry entry = fmgInfo.GetPatchedEntries().Find((x) => x.ID == (int)oldval);
if (!FMGBank.IsLoaded)
return new List<(string, FMGBank.EntryGroup)>();
return fmgRefs.Where((rf) => {
Param.Cell? c = context?[rf.conditionField];
return context == null || c == null || Convert.ToInt32(c.Value.Value) == rf.conditionValue;
}).Select(rf => FMGBank.FmgInfoBank.Find((x) => x.Name == rf.fmg))
.Where((fmgi) => fmgi != null)
.Select((fmgi) => (fmgi.Name, FMGBank.GenerateEntryGroup((int)oldval, fmgi)))
.ToList();
}
public static void FmgRefSelectable(EditorScreen ownerScreen, List<FMGRef> fmgNames, Param.Row context, dynamic oldval)
{
List<string> textsToPrint = CacheBank.GetCached(ownerScreen, (int)oldval, () => {
List<(string, FMGBank.EntryGroup)> refs = resolveFMGRefs(fmgNames, context, oldval);
return refs.Where((x) => x.Item2 != null)
.Select((x) => {
var group = x.Item2;
string toPrint = "";
if (!string.IsNullOrWhiteSpace(group.Title?.Text))
toPrint += '\n'+group.Title.Text;
if (!string.IsNullOrWhiteSpace(group.Summary?.Text))
toPrint += '\n'+group.Summary.Text;
if (!string.IsNullOrWhiteSpace(group.Description?.Text))
toPrint += '\n'+group.Description.Text;
if (!string.IsNullOrWhiteSpace(group.TextBody?.Text))
toPrint += '\n'+group.TextBody.Text;
if (!string.IsNullOrWhiteSpace(group.ExtraText?.Text))
toPrint += '\n'+group.ExtraText.Text;
return toPrint.TrimStart();
}).ToList();
});
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1.0f, 0.5f, 0.5f, 1.0f));
if (entry == null || entry.Text == null || entry.Text.Trim().Equals(""))
ImGui.TextUnformatted("%null%");
else
ImGui.TextUnformatted(entry.Text);
foreach(string text in textsToPrint)
{
if (string.IsNullOrWhiteSpace(text))
ImGui.TextUnformatted("%null%");
else
ImGui.TextUnformatted(text);
}

ImGui.PopStyleColor();
}
public static void EnumNameText(string enumName)
Expand Down Expand Up @@ -231,9 +299,9 @@ public static void VirtualParamRefSelectables(ParamBank bank, string virtualRefN
}
}

public static bool ParamRefEnumContextMenu(ParamBank bank, object oldval, ref object newval, List<ParamRef> RefTypes, Param.Row context, FMGBank.FMGInfo fmgInfo, ParamEnum Enum, ActionManager executor)
public static bool ParamRefEnumContextMenu(ParamBank bank, object oldval, ref object newval, List<ParamRef> RefTypes, Param.Row context, List<FMGRef> fmgRefs, ParamEnum Enum, ActionManager executor)
{
if ((CFG.Current.Param_HideReferenceRows || RefTypes == null) && (CFG.Current.Param_HideEnums || Enum == null) && (CFG.Current.Param_HideReferenceRows || fmgInfo == null))
if ((CFG.Current.Param_HideReferenceRows || RefTypes == null) && (CFG.Current.Param_HideEnums || Enum == null) && (CFG.Current.Param_HideReferenceRows || fmgRefs == null))
return false;
if (ImGui.IsItemClicked(ImGuiMouseButton.Left) && (InputTracker.GetKey(Veldrid.Key.ControlLeft) || InputTracker.GetKey(Veldrid.Key.ControlRight)))
{
Expand All @@ -248,9 +316,13 @@ public static bool ParamRefEnumContextMenu(ParamBank bank, object oldval, ref ob
EditorCommandQueue.AddCommand($@"param/select/-1/{primaryRef?.Item1}/{primaryRef?.Item2.ID}");
}
}
if (fmgInfo != null)
else if (fmgRefs != null)
{
EditorCommandQueue.AddCommand($@"text/select/{fmgInfo.Name}/{(int)oldval}");
var primaryRef = resolveFMGRefs(fmgRefs, context, oldval)?.First();
if (primaryRef != null)
{
EditorCommandQueue.AddCommand($@"text/select/{primaryRef?.Item1}/{primaryRef?.Item2.ID}");
}
}
}
bool result = false;
Expand All @@ -260,8 +332,8 @@ public static bool ParamRefEnumContextMenu(ParamBank bank, object oldval, ref ob
result |= PropertyRowRefsContextItems(bank, RefTypes, context, oldval, ref newval, executor);
if (Enum != null)
result |= PropertyRowEnumContextItems(Enum, oldval, ref newval);
if (fmgInfo != null && ImGui.Selectable($@"Goto {fmgInfo.Name} Text"))
EditorCommandQueue.AddCommand($@"text/select/{fmgInfo.Name}/{(int)oldval}");
if (fmgRefs != null)
PropertyRowFMGRefsContextItems(fmgRefs, context, oldval, executor);
ImGui.EndPopup();
}
return result;
Expand All @@ -273,6 +345,7 @@ public static bool PropertyRowRefsContextItems(ParamBank bank, List<ParamRef> re
return false;
// Add Goto statements
List<(string, Param.Row, string)> refs = resolveRefs(bank, reftypes, context, oldval);
bool ctrlDown = InputTracker.GetKey(Veldrid.Key.ControlLeft) || InputTracker.GetKey(Veldrid.Key.ControlRight);
foreach (var rf in refs)
{
if (ImGui.Selectable($@"Go to {rf.Item3}"))
Expand All @@ -281,11 +354,11 @@ public static bool PropertyRowRefsContextItems(ParamBank bank, List<ParamRef> re
EditorCommandQueue.AddCommand($@"param/select/new/{rf.Item1}/{rf.Item2.ID}");
if (context == null || executor == null)
continue;
if (!string.IsNullOrWhiteSpace(rf.Item2.Name) && string.IsNullOrWhiteSpace(context.Name) && ImGui.Selectable($@"Inherit referenced row's name ({rf.Item2.Name})"))
if (!string.IsNullOrWhiteSpace(rf.Item2.Name) && (ctrlDown || string.IsNullOrWhiteSpace(context.Name)) && ImGui.Selectable($@"Inherit referenced row's name ({rf.Item2.Name})"))
{
executor.ExecuteAction(new PropertiesChangedAction(context.GetType().GetProperty("Name"), context, rf.Item2.Name));
}
else if (string.IsNullOrWhiteSpace(rf.Item2.Name) && !string.IsNullOrWhiteSpace(context.Name) && ImGui.Selectable($@"Proliferate name to referenced row ({rf.Item1})"))
else if ((ctrlDown || string.IsNullOrWhiteSpace(rf.Item2.Name)) && !string.IsNullOrWhiteSpace(context.Name) && ImGui.Selectable($@"Proliferate name to referenced row ({rf.Item1})"))
{
executor.ExecuteAction(new PropertiesChangedAction(rf.Item2.GetType().GetProperty("Name"), rf.Item2, context.Name));
}
Expand Down Expand Up @@ -322,6 +395,27 @@ public static bool PropertyRowRefsContextItems(ParamBank bank, List<ParamRef> re
}
return false;
}
public static void PropertyRowFMGRefsContextItems(List<FMGRef> reftypes, Param.Row context, dynamic oldval, ActionManager executor)
{
// Add Goto statements
List<(string, FMGBank.EntryGroup)> refs = resolveFMGRefs(reftypes, context, oldval);
bool ctrlDown = InputTracker.GetKey(Veldrid.Key.ControlLeft) || InputTracker.GetKey(Veldrid.Key.ControlRight);
foreach (var (name, group) in refs)
{
if (ImGui.Selectable($@"Goto {name} Text"))
EditorCommandQueue.AddCommand($@"text/select/{name}/{group.ID}");
if (context == null || executor == null)
continue;
foreach(var field in group.GetType().GetFields().Where((propinfo) => propinfo.FieldType == typeof(FMG.Entry)))
{
FMG.Entry entry = (FMG.Entry)field.GetValue(group);
if (!string.IsNullOrWhiteSpace(entry?.Text) && (ctrlDown || string.IsNullOrWhiteSpace(context.Name)) && ImGui.Selectable($@"Inherit referenced fmg {field.Name} ({entry?.Text})"))
executor.ExecuteAction(new PropertiesChangedAction(context.GetType().GetProperty("Name"), context, entry?.Text));
if (entry != null && (ctrlDown || string.IsNullOrWhiteSpace(entry?.Text)) && !string.IsNullOrWhiteSpace(context.Name) && ImGui.Selectable($@"Proliferate name to referenced fmg {field.Name} ({name})"))
executor.ExecuteAction(new PropertiesChangedAction(entry.GetType().GetProperty("Text"), entry, context.Name));
}
}
}
public static bool PropertyRowEnumContextItems(ParamEnum en, object oldval, ref object newval)
{
try
Expand Down
Loading

0 comments on commit 01107e5

Please sign in to comment.