mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Add quick selection design and saving last quick selected design in config.
This commit is contained in:
parent
f35c20ed4d
commit
6696d539d3
5 changed files with 203 additions and 59 deletions
|
|
@ -28,6 +28,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
|
|||
private readonly AutomationChanged _event;
|
||||
private readonly DesignChanged _designEvent;
|
||||
private readonly RandomDesignGenerator _randomDesigns;
|
||||
private readonly QuickSelectedDesign _quickSelectedDesign;
|
||||
|
||||
private readonly List<AutoDesignSet> _data = [];
|
||||
private readonly Dictionary<ActorIdentifier, AutoDesignSet> _enabled = [];
|
||||
|
|
@ -36,15 +37,17 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
|
|||
=> _enabled;
|
||||
|
||||
public AutoDesignManager(JobService jobs, ActorManager actors, SaveService saveService, DesignManager designs, AutomationChanged @event,
|
||||
FixedDesignMigrator migrator, DesignFileSystem fileSystem, DesignChanged designEvent, RandomDesignGenerator randomDesigns)
|
||||
FixedDesignMigrator migrator, DesignFileSystem fileSystem, DesignChanged designEvent, RandomDesignGenerator randomDesigns,
|
||||
QuickSelectedDesign quickSelectedDesign)
|
||||
{
|
||||
_jobs = jobs;
|
||||
_actors = actors;
|
||||
_saveService = saveService;
|
||||
_designs = designs;
|
||||
_event = @event;
|
||||
_designEvent = designEvent;
|
||||
_randomDesigns = randomDesigns;
|
||||
_jobs = jobs;
|
||||
_actors = actors;
|
||||
_saveService = saveService;
|
||||
_designs = designs;
|
||||
_event = @event;
|
||||
_designEvent = designEvent;
|
||||
_randomDesigns = randomDesigns;
|
||||
_quickSelectedDesign = quickSelectedDesign;
|
||||
_designEvent.Subscribe(OnDesignChange, DesignChanged.Priority.AutoDesignManager);
|
||||
Load();
|
||||
migrator.ConsumeMigratedData(_actors, fileSystem, this);
|
||||
|
|
@ -486,6 +489,10 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
|
|||
{
|
||||
design = new RandomDesign(_randomDesigns);
|
||||
}
|
||||
else if (designIdentifier is QuickSelectedDesign.SerializedName)
|
||||
{
|
||||
design = _quickSelectedDesign;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (designIdentifier.Length == 0)
|
||||
|
|
|
|||
52
Glamourer/Designs/Special/QuickSelectedDesign.cs
Normal file
52
Glamourer/Designs/Special/QuickSelectedDesign.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using Glamourer.Automation;
|
||||
using Glamourer.Gui;
|
||||
using Glamourer.Interop.Material;
|
||||
using Glamourer.State;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OtterGui.Services;
|
||||
|
||||
namespace Glamourer.Designs.Special;
|
||||
|
||||
public class QuickSelectedDesign(QuickDesignCombo combo) : IDesignStandIn, IService
|
||||
{
|
||||
public const string SerializedName = "//QuickSelection";
|
||||
public const string ResolvedName = "Quick Design Bar Selection";
|
||||
|
||||
public bool Equals(IDesignStandIn? other)
|
||||
=> other is QuickSelectedDesign;
|
||||
|
||||
public string ResolveName(bool incognito)
|
||||
=> ResolvedName;
|
||||
|
||||
public Design? CurrentDesign
|
||||
=> combo.Design as Design;
|
||||
|
||||
public ref readonly DesignData GetDesignData(in DesignData baseRef)
|
||||
{
|
||||
if (combo.Design != null)
|
||||
return ref combo.Design.GetDesignData(baseRef);
|
||||
|
||||
return ref baseRef;
|
||||
}
|
||||
|
||||
public IReadOnlyList<(uint, MaterialValueDesign)> GetMaterialData()
|
||||
=> combo.Design?.GetMaterialData() ?? [];
|
||||
|
||||
public string SerializeName()
|
||||
=> SerializedName;
|
||||
|
||||
public StateSource AssociatedSource()
|
||||
=> StateSource.Manual;
|
||||
|
||||
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags)> AllLinks
|
||||
=> combo.Design?.AllLinks ?? [];
|
||||
|
||||
public void AddData(JObject jObj)
|
||||
{ }
|
||||
|
||||
public void ParseData(JObject jObj)
|
||||
{ }
|
||||
|
||||
public bool ChangeData(object data)
|
||||
=> false;
|
||||
}
|
||||
|
|
@ -9,15 +9,16 @@ namespace Glamourer;
|
|||
|
||||
public class EphemeralConfig : ISavable
|
||||
{
|
||||
public int Version { get; set; } = Configuration.Constants.CurrentVersion;
|
||||
public bool IncognitoMode { get; set; } = false;
|
||||
public bool UnlockDetailMode { get; set; } = true;
|
||||
public bool ShowDesignQuickBar { get; set; } = false;
|
||||
public bool LockDesignQuickBar { get; set; } = false;
|
||||
public bool LockMainWindow { get; set; } = false;
|
||||
public MainWindow.TabType SelectedTab { get; set; } = MainWindow.TabType.Settings;
|
||||
public Guid SelectedDesign { get; set; } = Guid.Empty;
|
||||
public int LastSeenVersion { get; set; } = GlamourerChangelog.LastChangelogVersion;
|
||||
public int Version { get; set; } = Configuration.Constants.CurrentVersion;
|
||||
public bool IncognitoMode { get; set; } = false;
|
||||
public bool UnlockDetailMode { get; set; } = true;
|
||||
public bool ShowDesignQuickBar { get; set; } = false;
|
||||
public bool LockDesignQuickBar { get; set; } = false;
|
||||
public bool LockMainWindow { get; set; } = false;
|
||||
public MainWindow.TabType SelectedTab { get; set; } = MainWindow.TabType.Settings;
|
||||
public Guid SelectedDesign { get; set; } = Guid.Empty;
|
||||
public Guid SelectedQuickDesign { get; set; } = Guid.Empty;
|
||||
public int LastSeenVersion { get; set; } = GlamourerChangelog.LastChangelogVersion;
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ namespace Glamourer.Gui;
|
|||
|
||||
public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, string>>, IDisposable
|
||||
{
|
||||
private readonly EphemeralConfig _config;
|
||||
private readonly DesignChanged _designChanged;
|
||||
private readonly DesignColors _designColors;
|
||||
protected readonly EphemeralConfig Config;
|
||||
protected readonly DesignChanged DesignChanged;
|
||||
protected readonly DesignColors DesignColors;
|
||||
protected readonly TabSelected TabSelected;
|
||||
protected float InnerWidth;
|
||||
private IDesignStandIn? _currentDesign;
|
||||
|
|
@ -25,19 +25,19 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
TabSelected tabSelected, EphemeralConfig config, DesignColors designColors)
|
||||
: base(generator, MouseWheelType.Control, log)
|
||||
{
|
||||
_designChanged = designChanged;
|
||||
TabSelected = tabSelected;
|
||||
_config = config;
|
||||
_designColors = designColors;
|
||||
_designChanged.Subscribe(OnDesignChange, DesignChanged.Priority.DesignCombo);
|
||||
DesignChanged = designChanged;
|
||||
TabSelected = tabSelected;
|
||||
Config = config;
|
||||
DesignColors = designColors;
|
||||
DesignChanged.Subscribe(OnDesignChange, DesignChanged.Priority.DesignCombo);
|
||||
}
|
||||
|
||||
public bool Incognito
|
||||
=> _config.IncognitoMode;
|
||||
=> Config.IncognitoMode;
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
_designChanged.Unsubscribe(OnDesignChange);
|
||||
DesignChanged.Unsubscribe(OnDesignChange);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
|
@ -45,42 +45,47 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
{
|
||||
var (design, path) = Items[globalIdx];
|
||||
bool ret;
|
||||
if (design is Design realDesign)
|
||||
switch (design)
|
||||
{
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Text, _designColors.GetColor(realDesign));
|
||||
ret = base.DrawSelectable(globalIdx, selected);
|
||||
case Design realDesign:
|
||||
|
||||
if (path.Length > 0 && realDesign.Name != path)
|
||||
{
|
||||
var start = ImGui.GetItemRectMin();
|
||||
var pos = start.X + ImGui.CalcTextSize(realDesign.Name).X;
|
||||
var maxSize = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
|
||||
var remainingSpace = maxSize - pos;
|
||||
var requiredSize = ImGui.CalcTextSize(path).X + ImGui.GetStyle().ItemInnerSpacing.X;
|
||||
var offset = remainingSpace - requiredSize;
|
||||
if (ImGui.GetScrollMaxY() == 0)
|
||||
offset -= ImGui.GetStyle().ItemInnerSpacing.X;
|
||||
|
||||
if (offset < ImGui.GetStyle().ItemSpacing.X)
|
||||
ImGuiUtil.HoverTooltip(path);
|
||||
else
|
||||
ImGui.GetWindowDrawList().AddText(start with { X = pos + offset },
|
||||
ImGui.GetColorU32(ImGuiCol.TextDisabled), path);
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Text, DesignColors.GetColor(realDesign));
|
||||
ret = base.DrawSelectable(globalIdx, selected);
|
||||
DrawPath(path, realDesign);
|
||||
return ret;
|
||||
}
|
||||
case QuickSelectedDesign quickDesign:
|
||||
{
|
||||
ret = base.DrawSelectable(globalIdx, selected);
|
||||
DrawResolvedDesign(quickDesign);
|
||||
return ret;
|
||||
}
|
||||
default: return base.DrawSelectable(globalIdx, selected);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawPath(string path, Design realDesign)
|
||||
{
|
||||
if (path.Length <= 0 || realDesign.Name == path)
|
||||
return;
|
||||
|
||||
DrawRightAligned(realDesign.Name, path, ImGui.GetColorU32(ImGuiCol.TextDisabled));
|
||||
}
|
||||
|
||||
private void DrawResolvedDesign(QuickSelectedDesign quickDesign)
|
||||
{
|
||||
var linkedDesign = quickDesign.CurrentDesign;
|
||||
if (linkedDesign != null)
|
||||
DrawRightAligned(quickDesign.ResolveName(false), linkedDesign.Name.Text, DesignColors.GetColor(linkedDesign));
|
||||
else
|
||||
{
|
||||
ret = base.DrawSelectable(globalIdx, selected);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
DrawRightAligned(quickDesign.ResolveName(false), "[Nothing]", DesignColors.MissingColor);
|
||||
}
|
||||
|
||||
protected override int UpdateCurrentSelected(int currentSelected)
|
||||
{
|
||||
CurrentSelectionIdx = Items.IndexOf(p => _currentDesign == p.Item1);
|
||||
CurrentSelection = CurrentSelectionIdx >= 0 ? Items[CurrentSelectionIdx] : null;
|
||||
UpdateSelection(CurrentSelectionIdx >= 0 ? Items[CurrentSelectionIdx] : null);
|
||||
return CurrentSelectionIdx;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +95,7 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
InnerWidth = 400 * ImGuiHelpers.GlobalScale;
|
||||
var name = label ?? "Select Design Here...";
|
||||
bool ret;
|
||||
using (_ = currentDesign != null ? ImRaii.PushColor(ImGuiCol.Text, _designColors.GetColor(currentDesign as Design)) : null)
|
||||
using (_ = currentDesign != null ? ImRaii.PushColor(ImGuiCol.Text, DesignColors.GetColor(currentDesign as Design)) : null)
|
||||
{
|
||||
ret = Draw("##design", name, string.Empty, width, ImGui.GetTextLineHeightWithSpacing())
|
||||
&& CurrentSelection != null;
|
||||
|
|
@ -103,6 +108,8 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
ImGuiUtil.HoverTooltip("Control + Right-Click to move to design.");
|
||||
}
|
||||
|
||||
QuickSelectedDesignTooltip(currentDesign);
|
||||
|
||||
_currentDesign = null;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -134,16 +141,16 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
CurrentSelectionIdx = Items.IndexOf(s => ReferenceEquals(s.Item1, CurrentSelection?.Item1));
|
||||
if (CurrentSelectionIdx >= 0)
|
||||
{
|
||||
CurrentSelection = Items[CurrentSelectionIdx];
|
||||
UpdateSelection(Items[CurrentSelectionIdx]);
|
||||
}
|
||||
else if (Items.Count > 0)
|
||||
{
|
||||
CurrentSelectionIdx = 0;
|
||||
CurrentSelection = Items[0];
|
||||
UpdateSelection(Items[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSelection = null;
|
||||
UpdateSelection(null);
|
||||
}
|
||||
|
||||
if (!priorState)
|
||||
|
|
@ -151,6 +158,47 @@ public abstract class DesignComboBase : FilterComboCache<Tuple<IDesignStandIn, s
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void QuickSelectedDesignTooltip(IDesignStandIn? design)
|
||||
{
|
||||
if (!ImGui.IsItemHovered())
|
||||
return;
|
||||
|
||||
if (design is not QuickSelectedDesign q)
|
||||
return;
|
||||
|
||||
using var tt = ImRaii.Tooltip();
|
||||
var linkedDesign = q.CurrentDesign;
|
||||
if (linkedDesign != null)
|
||||
{
|
||||
ImGui.TextUnformatted("Currently resolving to ");
|
||||
using var color = ImRaii.PushColor(ImGuiCol.Text, DesignColors.GetColor(linkedDesign));
|
||||
ImGui.SameLine(0, 0);
|
||||
ImGui.TextUnformatted(linkedDesign.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.TextUnformatted("No design selected in the Quick Design Bar.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawRightAligned(string leftText, string text, uint color)
|
||||
{
|
||||
var start = ImGui.GetItemRectMin();
|
||||
var pos = start.X + ImGui.CalcTextSize(leftText).X;
|
||||
var maxSize = ImGui.GetWindowPos().X + ImGui.GetWindowContentRegionMax().X;
|
||||
var remainingSpace = maxSize - pos;
|
||||
var requiredSize = ImGui.CalcTextSize(text).X + ImGui.GetStyle().ItemInnerSpacing.X;
|
||||
var offset = remainingSpace - requiredSize;
|
||||
if (ImGui.GetScrollMaxY() == 0)
|
||||
offset -= ImGui.GetStyle().ItemInnerSpacing.X;
|
||||
|
||||
if (offset < ImGui.GetStyle().ItemSpacing.X)
|
||||
ImGuiUtil.HoverTooltip(text);
|
||||
else
|
||||
ImGui.GetWindowDrawList().AddText(start with { X = pos + offset },
|
||||
color, text);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class DesignCombo : DesignComboBase
|
||||
|
|
@ -190,7 +238,41 @@ public sealed class QuickDesignCombo : DesignCombo
|
|||
.Select(d => new Tuple<IDesignStandIn, string>(d, fileSystem.FindLeaf(d, out var l) ? l.FullName() : string.Empty))
|
||||
.OrderBy(d => d.Item2),
|
||||
])
|
||||
=> AllowMouseWheel = MouseWheelType.Unmodified;
|
||||
{
|
||||
if (config.SelectedQuickDesign != Guid.Empty)
|
||||
{
|
||||
CurrentSelectionIdx = Items.IndexOf(t => t.Item1 is Design d && d.Identifier == config.SelectedQuickDesign);
|
||||
if (CurrentSelectionIdx >= 0)
|
||||
CurrentSelection = Items[CurrentSelectionIdx];
|
||||
else if (Items.Count > 0)
|
||||
CurrentSelectionIdx = 0;
|
||||
}
|
||||
|
||||
AllowMouseWheel = MouseWheelType.Unmodified;
|
||||
SelectionChanged += OnSelectionChange;
|
||||
}
|
||||
|
||||
private void OnSelectionChange(Tuple<IDesignStandIn, string>? old, Tuple<IDesignStandIn, string>? @new)
|
||||
{
|
||||
if (old == null)
|
||||
{
|
||||
if (@new?.Item1 is not Design d)
|
||||
return;
|
||||
|
||||
Config.SelectedQuickDesign = d.Identifier;
|
||||
Config.Save();
|
||||
}
|
||||
else if (@new?.Item1 is not Design d)
|
||||
{
|
||||
Config.SelectedQuickDesign = Guid.Empty;
|
||||
Config.Save();
|
||||
}
|
||||
else if (!old.Item1.Equals(@new.Item1))
|
||||
{
|
||||
Config.SelectedQuickDesign = d.Identifier;
|
||||
Config.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LinkDesignCombo(
|
||||
|
|
@ -253,11 +335,13 @@ public sealed class SpecialDesignCombo(
|
|||
DesignChanged designChanged,
|
||||
AutoDesignManager autoDesignManager,
|
||||
EphemeralConfig config,
|
||||
RandomDesignGenerator rng)
|
||||
RandomDesignGenerator rng,
|
||||
QuickSelectedDesign quickSelectedDesign)
|
||||
: DesignComboBase(() => designs.Designs
|
||||
.Select(d => new Tuple<IDesignStandIn, string>(d, fileSystem.FindLeaf(d, out var l) ? l.FullName() : string.Empty))
|
||||
.OrderBy(d => d.Item2)
|
||||
.Prepend(new Tuple<IDesignStandIn, string>(new RandomDesign(rng), string.Empty))
|
||||
.Prepend(new Tuple<IDesignStandIn, string>(quickSelectedDesign, string.Empty))
|
||||
.Prepend(new Tuple<IDesignStandIn, string>(new RevertDesign(), string.Empty))
|
||||
.ToList(), log, designChanged, tabSelected, config, designColors)
|
||||
{
|
||||
|
|
|
|||
2
OtterGui
2
OtterGui
|
|
@ -1 +1 @@
|
|||
Subproject commit 9d68a487610266058fbec853efed9a35c9df6fbe
|
||||
Subproject commit d71f8540a2c2efb4f2cb96e4706bb056397daf0a
|
||||
Loading…
Add table
Add a link
Reference in a new issue