Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Menu peformance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Taurenkey committed Aug 25, 2024
1 parent 6e5b600 commit 22aaaf7
Showing 1 changed file with 100 additions and 64 deletions.
164 changes: 100 additions & 64 deletions XIVSlothCombo/Window/Functions/Presets.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,84 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility;
using ECommons.DalamudServices;
using ECommons.ImGuiMethods;
using ImGuiNET;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection.Emit;
using System.Text;
using XIVSlothCombo.Attributes;
using XIVSlothCombo.Combos;
using XIVSlothCombo.Core;
using XIVSlothCombo.Data;
using XIVSlothCombo.Extensions;
using XIVSlothCombo.Services;

namespace XIVSlothCombo.Window.Functions
{
internal class Presets : ConfigWindow
{
internal static Dictionary<CustomComboPreset, PresetAttributes> Attributes = new();
internal class PresetAttributes
{
public bool IsPvP;
public CustomComboPreset[] Conflicts;
public CustomComboPreset? Parent;
public BlueInactiveAttribute? BlueInactive;
public VariantParentAttribute? VariantParent;
public BozjaParentAttribute? BozjaParent;
public EurekaParentAttribute? EurekaParent;
public HoverInfoAttribute? HoverInfo;
public ReplaceSkillAttribute? ReplaceSkill;
public CustomComboInfoAttribute? CustomComboInfo;

public PresetAttributes(CustomComboPreset preset)
{
IsPvP = PresetStorage.IsPvP(preset);
Conflicts = PresetStorage.GetConflicts(preset);
Parent = PresetStorage.GetParent(preset);
BlueInactive = preset.GetAttribute<BlueInactiveAttribute>();
VariantParent = preset.GetAttribute<VariantParentAttribute>();
BozjaParent = preset.GetAttribute<BozjaParentAttribute>();
EurekaParent = preset.GetAttribute<EurekaParentAttribute>();
HoverInfo = preset.GetAttribute<HoverInfoAttribute>();
ReplaceSkill = preset.GetAttribute<ReplaceSkillAttribute>();
CustomComboInfo = preset.GetAttribute<CustomComboInfoAttribute>();
}
}

internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfoAttribute info, ref int i)
{
if (!Attributes.ContainsKey(preset))
{
PresetAttributes attributes = new(preset);
Attributes[preset] = attributes;
}
var enabled = PresetStorage.IsEnabled(preset);
var secret = PresetStorage.IsPvP(preset);
var conflicts = PresetStorage.GetConflicts(preset);
var parent = PresetStorage.GetParent(preset);
var blueAttr = preset.GetAttribute<BlueInactiveAttribute>();
var secret = Attributes[preset].IsPvP;
var conflicts = Attributes[preset].Conflicts;
var parent = Attributes[preset].Parent;
var blueAttr = Attributes[preset].BlueInactive;
var variantParents = Attributes[preset].VariantParent;
var bozjaParents = Attributes[preset].BozjaParent;
var eurekaParents = Attributes[preset].EurekaParent;

ImGui.Spacing();

if (ImGui.Checkbox($"{info.FancyName}###{info.FancyName}{i}", ref enabled))
if (ImGui.Checkbox($"{info.FancyName}###{i}", ref enabled))
{
if (enabled)
{

EnableParentPresets(preset);
Service.Configuration.EnabledActions.Add(preset);
foreach (var conflict in conflicts)
{
Service.Configuration.EnabledActions.Remove(conflict);
}
}

else
{
Service.Configuration.EnabledActions.Remove(preset);
Expand All @@ -49,34 +87,33 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo
Service.Configuration.Save();
}

ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudGrey);

DrawReplaceAttribute(preset);

Vector2 length = new();

if (i != -1)
using (var styleCol = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudGrey))
{
ImGui.Text($"#{i}: ");
length = ImGui.CalcTextSize($"#{i}: ");
ImGui.SameLine();
ImGui.PushItemWidth(length.Length());
}
if (i != -1)
{
ImGui.Text($"#{i}: ");
length = ImGui.CalcTextSize($"#{i}: ");
ImGui.SameLine();
ImGui.PushItemWidth(length.Length());
}

ImGui.TextWrapped($"{info.Description}");
ImGui.TextWrapped($"{info.Description}");

if (preset.GetHoverAttribute() != null)
{
if (ImGui.IsItemHovered())
if (Attributes[preset].HoverInfo != null)
{
ImGui.BeginTooltip();
ImGui.TextUnformatted(preset.GetHoverAttribute().HoverText);
ImGui.EndTooltip();
if (ImGui.IsItemHovered())
{
ImGui.BeginTooltip();
ImGui.TextUnformatted(Attributes[preset].HoverInfo.HoverText);
ImGui.EndTooltip();
}
}
}


ImGui.PopStyleColor();
ImGui.Spacing();

if (conflicts.Length > 0)
Expand All @@ -86,15 +123,18 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo
ImGui.Indent();
foreach (var conflict in conflicts)
{
var comboInfo = conflict.GetAttribute<CustomComboInfoAttribute>();
var comboInfo = Attributes.ContainsKey(conflict) ? Attributes[conflict].CustomComboInfo : conflict.GetAttribute<CustomComboInfoAttribute>();
conflictBuilder.Insert(0, $"{comboInfo.FancyName}");
var par2 = conflict;

while (PresetStorage.GetParent(par2) != null)
{
var subpar = PresetStorage.GetParent(par2);
conflictBuilder.Insert(0, $"{subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName} -> ");
par2 = subpar!.Value;
if (subpar != null)
{
conflictBuilder.Insert(0, $"{(Attributes.ContainsKey(subpar.Value) ? Attributes[subpar.Value].CustomComboInfo : subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName)} -> ");
par2 = subpar!.Value;
}

}

Expand Down Expand Up @@ -125,21 +165,23 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo
}
}

VariantParentAttribute? varientparents = preset.GetAttribute<VariantParentAttribute>();
if (varientparents is not null)
if (variantParents is not null)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
ImGui.TextWrapped($"Part of normal combo{(varientparents.ParentPresets.Length > 1 ? "s" : "")}:");
ImGui.TextWrapped($"Part of normal combo{(variantParents.ParentPresets.Length > 1 ? "s" : "")}:");
StringBuilder builder = new();
foreach (var par in varientparents.ParentPresets)
foreach (var par in variantParents.ParentPresets)
{
builder.Insert(0, $"{par.GetAttribute<CustomComboInfoAttribute>().FancyName}");
builder.Insert(0, $"{(Attributes.ContainsKey(par) ? Attributes[par].CustomComboInfo.FancyName : par.GetAttribute<CustomComboInfoAttribute>().FancyName)}");
var par2 = par;
while (PresetStorage.GetParent(par2) != null)
{
var subpar = PresetStorage.GetParent(par2);
builder.Insert(0, $"{subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName} -> ");
par2 = subpar!.Value;
if (subpar != null)
{
builder.Insert(0, $"{(Attributes.ContainsKey(subpar.Value) ? Attributes[subpar.Value].CustomComboInfo.FancyName : subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName)} -> ");
par2 = subpar!.Value;
}

}

Expand All @@ -149,21 +191,23 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo
ImGui.PopStyleColor();
}

BozjaParentAttribute? bozjaparents = preset.GetAttribute<BozjaParentAttribute>();
if (bozjaparents is not null)
if (bozjaParents is not null)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
ImGui.TextWrapped($"Part of normal combo{(varientparents.ParentPresets.Length > 1 ? "s" : "")}:");
ImGui.TextWrapped($"Part of normal combo{(variantParents.ParentPresets.Length > 1 ? "s" : "")}:");
StringBuilder builder = new();
foreach (var par in bozjaparents.ParentPresets)
foreach (var par in bozjaParents.ParentPresets)
{
builder.Insert(0, $"{par.GetAttribute<CustomComboInfoAttribute>().FancyName}");
builder.Insert(0, $"{(Attributes.ContainsKey(par) ? Attributes[par].CustomComboInfo.FancyName : par.GetAttribute<CustomComboInfoAttribute>().FancyName)}");
var par2 = par;
while (PresetStorage.GetParent(par2) != null)
{
var subpar = PresetStorage.GetParent(par2);
builder.Insert(0, $"{subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName} -> ");
par2 = subpar!.Value;
if (subpar != null)
{
builder.Insert(0, $"{(Attributes.ContainsKey(subpar.Value) ? Attributes[subpar.Value].CustomComboInfo.FancyName : subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName)} -> ");
par2 = subpar!.Value;
}

}

Expand All @@ -173,21 +217,23 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo
ImGui.PopStyleColor();
}

EurekaParentAttribute? eurekaparents = preset.GetAttribute<EurekaParentAttribute>();
if (eurekaparents is not null)
if (eurekaParents is not null)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
ImGui.TextWrapped($"Part of normal combo{(varientparents.ParentPresets.Length > 1 ? "s" : "")}:");
ImGui.TextWrapped($"Part of normal combo{(variantParents.ParentPresets.Length > 1 ? "s" : "")}:");
StringBuilder builder = new();
foreach (var par in eurekaparents.ParentPresets)
foreach (var par in eurekaParents.ParentPresets)
{
builder.Insert(0, $"{par.GetAttribute<CustomComboInfoAttribute>().FancyName}");
builder.Insert(0, $"{(Attributes.ContainsKey(par) ? Attributes[par].CustomComboInfo.FancyName : par.GetAttribute<CustomComboInfoAttribute>().FancyName)}");
var par2 = par;
while (PresetStorage.GetParent(par2) != null)
{
var subpar = PresetStorage.GetParent(par2);
builder.Insert(0, $"{subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName} -> ");
par2 = subpar!.Value;
if (subpar != null)
{
builder.Insert(0, $"{(Attributes.ContainsKey(subpar.Value) ? Attributes[subpar.Value].CustomComboInfo.FancyName : subpar?.GetAttribute<CustomComboInfoAttribute>().FancyName)} -> ");
par2 = subpar!.Value;
}

}

Expand All @@ -199,23 +245,13 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo

UserConfigItems.Draw(preset, enabled);

if (preset == CustomComboPreset.NIN_ST_SimpleMode_BalanceOpener || preset == CustomComboPreset.NIN_ST_AdvancedMode_BalanceOpener)
{
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + length.Length());
if (ImGui.Button($"Image of rotation###ninrtn{i}"))
{
Util.OpenLink("https://i.imgur.com/IeP27KF.png");
}
}

i++;

var hideChildren = Service.Configuration.HideChildren;
var children = presetChildren[preset];
var children = presetChildren.ContainsKey(preset) ? presetChildren[preset] : null;

if (children.Length > 0)
if (children != null)
{
if (enabled || !hideChildren)
if (enabled || !Service.Configuration.HideChildren)
{
ImGui.Indent();

Expand Down Expand Up @@ -244,10 +280,10 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo
continue;
}
}

else
{
DrawPreset(childPreset, childInfo, ref i);
continue;
}
}

Expand All @@ -263,7 +299,7 @@ internal unsafe static void DrawPreset(CustomComboPreset preset, CustomComboInfo

private static void DrawReplaceAttribute(CustomComboPreset preset)
{
var att = preset.GetReplaceAttribute();
var att = Attributes[preset].ReplaceSkill;
if (att != null)
{
string skills = string.Join(", ", att.ActionNames);
Expand Down

0 comments on commit 22aaaf7

Please sign in to comment.