mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-13 12:14:18 +01:00
Batch some multi-design changes to skip unnecessary computations.
This commit is contained in:
parent
74674cfa0c
commit
b4485f028d
5 changed files with 75 additions and 8 deletions
|
|
@ -152,7 +152,7 @@ public class EditorHistory : IDisposable, IService
|
|||
{
|
||||
if (!_stateEntries.TryGetValue(state, out var list))
|
||||
{
|
||||
list = new Queue();
|
||||
list = [];
|
||||
_stateEntries.Add(state, list);
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ public class EditorHistory : IDisposable, IService
|
|||
{
|
||||
if (!_designEntries.TryGetValue(design, out var list))
|
||||
{
|
||||
list = new Queue();
|
||||
list = [];
|
||||
_designEntries.Add(design, list);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using OtterGui;
|
|||
using OtterGui.Classes;
|
||||
using OtterGui.Extensions;
|
||||
using OtterGui.Log;
|
||||
using OtterGui.Services;
|
||||
using OtterGui.Widgets;
|
||||
|
||||
namespace Glamourer.Gui;
|
||||
|
|
@ -21,6 +22,7 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
protected readonly DesignColors DesignColors;
|
||||
protected readonly TabSelected TabSelected;
|
||||
protected float InnerWidth;
|
||||
public bool IsListening { get; protected set; }
|
||||
private IDesignStandIn? _currentDesign;
|
||||
|
||||
protected DesignComboBase(Func<IReadOnlyList<Tuple<IDesignStandIn, string>>> generator, Logger log, DesignChanged designChanged,
|
||||
|
|
@ -32,6 +34,7 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
Config = config;
|
||||
DesignColors = designColors;
|
||||
DesignChanged.Subscribe(OnDesignChanged, DesignChanged.Priority.DesignCombo);
|
||||
IsListening = true;
|
||||
}
|
||||
|
||||
public bool Incognito
|
||||
|
|
@ -43,6 +46,25 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
if (!IsListening)
|
||||
return;
|
||||
|
||||
DesignChanged.Unsubscribe(OnDesignChanged);
|
||||
IsListening = false;
|
||||
}
|
||||
|
||||
public void StartListening()
|
||||
{
|
||||
if (IsListening)
|
||||
return;
|
||||
|
||||
DesignChanged.Subscribe(OnDesignChanged, DesignChanged.Priority.DesignCombo);
|
||||
OnDesignChanged(DesignChanged.Type.Deleted, null);
|
||||
IsListening = true;
|
||||
}
|
||||
|
||||
protected override bool DrawSelectable(int globalIdx, bool selected)
|
||||
{
|
||||
var (design, path) = Items[globalIdx];
|
||||
|
|
@ -128,7 +150,7 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
return filter.IsContained(path) || filter.IsContained(design.ResolveName(false));
|
||||
}
|
||||
|
||||
private void OnDesignChanged(DesignChanged.Type type, Design design, ITransaction? _ = null)
|
||||
private void OnDesignChanged(DesignChanged.Type type, Design? _1, ITransaction? _2 = null)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
@ -358,3 +380,29 @@ public sealed class SpecialDesignCombo(
|
|||
autoDesignManager.AddDesign(set, CurrentSelection!.Item1);
|
||||
}
|
||||
}
|
||||
|
||||
public class DesignComboWrapper(ServiceManager services)
|
||||
{
|
||||
public readonly IReadOnlyList<DesignComboBase> Combos = services.GetServicesImplementing<DesignComboBase>().ToArray();
|
||||
|
||||
internal DesignComboListener StopListening()
|
||||
{
|
||||
var list = new List<DesignComboBase>(Combos.Count);
|
||||
foreach (var combo in Combos.Where(c => c.IsListening))
|
||||
{
|
||||
combo.StopListening();
|
||||
list.Add(combo);
|
||||
}
|
||||
|
||||
return new DesignComboListener(list);
|
||||
}
|
||||
|
||||
internal readonly struct DesignComboListener(List<DesignComboBase> combos) : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var combo in combos)
|
||||
combo.StartListening();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using Dalamud.Interface.Utility;
|
|||
using Glamourer.Designs;
|
||||
using Glamourer.Interop.Material;
|
||||
using ImGuiNET;
|
||||
using OtterGui;
|
||||
using OtterGui.Extensions;
|
||||
using OtterGui.Raii;
|
||||
using OtterGui.Text;
|
||||
|
|
@ -11,7 +10,12 @@ using static Glamourer.Gui.Tabs.HeaderDrawer;
|
|||
|
||||
namespace Glamourer.Gui.Tabs.DesignTab;
|
||||
|
||||
public class MultiDesignPanel(DesignFileSystemSelector selector, DesignManager editor, DesignColors colors, Configuration config)
|
||||
public class MultiDesignPanel(
|
||||
DesignFileSystemSelector selector,
|
||||
DesignManager editor,
|
||||
DesignColors colors,
|
||||
Configuration config,
|
||||
DesignComboWrapper combos)
|
||||
{
|
||||
private readonly Button[] _leftButtons = [];
|
||||
private readonly Button[] _rightButtons = [new IncognitoButton(config)];
|
||||
|
|
@ -201,16 +205,23 @@ public class MultiDesignPanel(DesignFileSystemSelector selector, DesignManager e
|
|||
? $"All {_numDesigns} selected designs are already displayed in the quick design bar."
|
||||
: $"Display all {_numDesigns} selected designs in the quick design bar. Changes {diff} designs.";
|
||||
if (ImUtf8.ButtonEx("Display Selected Designs in QDB"u8, tt, buttonWidth, diff == 0))
|
||||
{
|
||||
using var disableListener = combos.StopListening();
|
||||
foreach (var design in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
editor.SetQuickDesign(design.Value, true);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
tt = _numQuickDesignEnabled == 0
|
||||
? $"All {_numDesigns} selected designs are already hidden in the quick design bar."
|
||||
: $"Hide all {_numDesigns} selected designs in the quick design bar. Changes {_numQuickDesignEnabled} designs.";
|
||||
if (ImUtf8.ButtonEx("Hide Selected Designs in QDB"u8, tt, buttonWidth, _numQuickDesignEnabled == 0))
|
||||
{
|
||||
using var disableListener = combos.StopListening();
|
||||
foreach (var design in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>())
|
||||
editor.SetQuickDesign(design.Value, false);
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
||||
|
|
@ -327,8 +338,11 @@ public class MultiDesignPanel(DesignFileSystemSelector selector, DesignManager e
|
|||
: $"Set the color of {_addDesigns.Count} designs to \"{_colorCombo.CurrentSelection}\"\n\n\t{string.Join("\n\t", _addDesigns.Select(m => m.Name.Text))}";
|
||||
ImGui.SameLine();
|
||||
if (ImUtf8.ButtonEx(label, tooltip, width, _addDesigns.Count == 0))
|
||||
{
|
||||
using var disableListener = combos.StopListening();
|
||||
foreach (var design in _addDesigns)
|
||||
editor.ChangeColor(design, _colorCombo.CurrentSelection!);
|
||||
}
|
||||
|
||||
label = _removeDesigns.Count > 0
|
||||
? $"Unset {_removeDesigns.Count} Designs"
|
||||
|
|
@ -338,8 +352,11 @@ public class MultiDesignPanel(DesignFileSystemSelector selector, DesignManager e
|
|||
: $"Set {_removeDesigns.Count} designs to use automatic color again:\n\n\t{string.Join("\n\t", _removeDesigns.Select(m => m.Item1.Name.Text))}";
|
||||
ImGui.SameLine();
|
||||
if (ImUtf8.ButtonEx(label, tooltip, width, _removeDesigns.Count == 0))
|
||||
{
|
||||
using var disableListener = combos.StopListening();
|
||||
foreach (var (design, _) in _removeDesigns)
|
||||
editor.ChangeColor(design, string.Empty);
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
|
@ -455,7 +472,8 @@ public class MultiDesignPanel(DesignFileSystemSelector selector, DesignManager e
|
|||
|
||||
foreach (var design in selector.SelectedPaths.OfType<DesignFileSystem.Leaf>().Select(l => l.Value))
|
||||
{
|
||||
editor.ChangeApplyMulti(design, equip, customize, equip, customize.HasValue && !customize.Value ? false : null, null, equip, equip, equip);
|
||||
editor.ChangeApplyMulti(design, equip, customize, equip, customize.HasValue && !customize.Value ? false : null, null, equip, equip,
|
||||
equip);
|
||||
if (equip.HasValue)
|
||||
{
|
||||
editor.ChangeApplyMeta(design, MetaIndex.HatState, equip.Value);
|
||||
|
|
|
|||
|
|
@ -169,5 +169,6 @@ public static class StaticServiceManager
|
|||
.AddSingleton<DesignQuickBar>()
|
||||
.AddSingleton<DesignColorUi>()
|
||||
.AddSingleton<NpcCombo>()
|
||||
.AddSingleton<TextureCache>();
|
||||
.AddSingleton<TextureCache>()
|
||||
.AddSingleton<DesignComboWrapper>();
|
||||
}
|
||||
|
|
|
|||
2
OtterGui
2
OtterGui
|
|
@ -1 +1 @@
|
|||
Subproject commit 421874a12540b7f8c1279dcc6a92e895a94d2fbc
|
||||
Subproject commit cee50c3fe97a03ca7445c81de651b609620da526
|
||||
Loading…
Add table
Add a link
Reference in a new issue