mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2026-02-20 14:37:46 +01:00
Add Revert-Design for automated designs.
This commit is contained in:
parent
c909510edc
commit
d70d6ff1b3
6 changed files with 98 additions and 66 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using Glamourer.Automation;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.Services;
|
||||
using ImGuiNET;
|
||||
using OtterGui;
|
||||
using OtterGui.Raii;
|
||||
|
|
@ -11,30 +12,34 @@ namespace Glamourer.Gui.Tabs.AutomationTab;
|
|||
|
||||
public sealed class DesignCombo : FilterComboCache<Design>
|
||||
{
|
||||
public const int RevertDesignIndex = -1228;
|
||||
public readonly Design RevertDesign;
|
||||
|
||||
private readonly AutoDesignManager _manager;
|
||||
private readonly DesignFileSystem _fileSystem;
|
||||
private readonly TabSelected _tabSelected;
|
||||
|
||||
public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected)
|
||||
: base(() => designs.Designs.OrderBy(d => d.Name).ToList())
|
||||
public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected,
|
||||
ItemManager items)
|
||||
: base(() => designs.Designs.OrderBy(d => d.Name).Prepend(CreateRevertDesign(items)).ToList())
|
||||
{
|
||||
_manager = manager;
|
||||
_fileSystem = fileSystem;
|
||||
_tabSelected = tabSelected;
|
||||
RevertDesign = Items[0];
|
||||
}
|
||||
|
||||
protected override bool DrawSelectable(int globalIdx, bool selected)
|
||||
{
|
||||
var ret = base.DrawSelectable(globalIdx, selected);
|
||||
|
||||
if (_fileSystem.FindLeaf(Items[globalIdx], out var leaf))
|
||||
if (ImGui.IsItemHovered() && _fileSystem.FindLeaf(Items[globalIdx], out var leaf))
|
||||
{
|
||||
var fullName = leaf.FullName();
|
||||
if (!fullName.StartsWith(Items[globalIdx].Name))
|
||||
{
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Text, ImGui.GetColorU32(ImGuiCol.TextDisabled));
|
||||
ImGui.SameLine();
|
||||
ImGuiUtil.RightAlign(fullName);
|
||||
using var tt = ImRaii.Tooltip();
|
||||
ImGui.TextUnformatted(fullName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,20 +48,20 @@ public sealed class DesignCombo : FilterComboCache<Design>
|
|||
|
||||
public void Draw(AutoDesignSet set, AutoDesign? design, int autoDesignIndex, bool incognito)
|
||||
{
|
||||
CurrentSelection = design?.Design ?? (Items.Count > 0 ? Items[0] : null);
|
||||
CurrentSelectionIdx = design?.Design.Index ?? (Items.Count > 0 ? 0 : -1);
|
||||
var name = (incognito ? CurrentSelection?.Incognito : CurrentSelection?.Name.Text) ?? string.Empty;
|
||||
CurrentSelection = design?.Design ?? RevertDesign;
|
||||
CurrentSelectionIdx = (design?.Design?.Index ?? -1) + 1;
|
||||
var name = design?.Name(incognito) ?? string.Empty;
|
||||
if (Draw("##design", name, string.Empty, ImGui.GetContentRegionAvail().X,
|
||||
ImGui.GetTextLineHeight())
|
||||
&& CurrentSelection != null)
|
||||
{
|
||||
if (autoDesignIndex >= 0)
|
||||
_manager.ChangeDesign(set, autoDesignIndex, CurrentSelection);
|
||||
_manager.ChangeDesign(set, autoDesignIndex, CurrentSelection == RevertDesign ? null : CurrentSelection);
|
||||
else
|
||||
_manager.AddDesign(set, CurrentSelection);
|
||||
_manager.AddDesign(set, CurrentSelection == RevertDesign ? null : CurrentSelection);
|
||||
}
|
||||
|
||||
if (design != null)
|
||||
if (design?.Design != null)
|
||||
{
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right) && ImGui.GetIO().KeyCtrl)
|
||||
_tabSelected.Invoke(MainWindow.TabType.Designs, design.Design);
|
||||
|
|
@ -66,4 +71,11 @@ public sealed class DesignCombo : FilterComboCache<Design>
|
|||
|
||||
protected override string ToString(Design obj)
|
||||
=> obj.Name.Text;
|
||||
|
||||
private static Design CreateRevertDesign(ItemManager items)
|
||||
=> new(items)
|
||||
{
|
||||
Index = RevertDesignIndex,
|
||||
Name = AutoDesign.RevertName,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1362,7 +1362,7 @@ public unsafe class DebugTab : ITab
|
|||
|
||||
foreach (var (design, designIdx) in set.Designs.WithIndex())
|
||||
{
|
||||
ImGuiUtil.DrawTableColumn($"{design.Design.Name} ({designIdx})");
|
||||
ImGuiUtil.DrawTableColumn($"{design.Name(false)} ({designIdx})");
|
||||
ImGuiUtil.DrawTableColumn($"{design.ApplicationType} {design.Jobs.Name}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue