Add Revert-Design for automated designs.

This commit is contained in:
Ottermandias 2023-07-19 18:02:40 +02:00
parent c909510edc
commit d70d6ff1b3
6 changed files with 98 additions and 66 deletions

View file

@ -2,6 +2,7 @@
using Glamourer.Customization; using Glamourer.Customization;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Interop.Structs; using Glamourer.Interop.Structs;
using Glamourer.State;
using Glamourer.Structs; using Glamourer.Structs;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@ -9,6 +10,8 @@ namespace Glamourer.Automation;
public class AutoDesign public class AutoDesign
{ {
public const string RevertName = "Revert";
[Flags] [Flags]
public enum Type : byte public enum Type : byte
{ {
@ -21,10 +24,19 @@ public class AutoDesign
All = Armor | Accessories | Customizations | Weapons | Stains, All = Armor | Accessories | Customizations | Weapons | Stains,
} }
public Design Design = null!; public Design? Design;
public JobGroup Jobs; public JobGroup Jobs;
public Type ApplicationType; public Type ApplicationType;
public string Name(bool incognito)
=> Revert ? RevertName : incognito ? Design!.Incognito : Design!.Name.Text;
public ref DesignData GetDesignData(ActorState state)
=> ref Design == null ? ref state.BaseData : ref Design.DesignData;
public bool Revert
=> Design == null;
public AutoDesign Clone() public AutoDesign Clone()
=> new() => new()
{ {
@ -39,7 +51,7 @@ public class AutoDesign
public JObject Serialize() public JObject Serialize()
=> new() => new()
{ {
["Design"] = Design.Identifier.ToString(), ["Design"] = Design?.Identifier.ToString(),
["ApplicationType"] = (uint)ApplicationType, ["ApplicationType"] = (uint)ApplicationType,
["Conditions"] = CreateConditionObject(), ["Conditions"] = CreateConditionObject(),
}; };
@ -59,7 +71,12 @@ public class AutoDesign
| (ApplicationType.HasFlag(Type.Accessories) ? AccessoryFlags : 0) | (ApplicationType.HasFlag(Type.Accessories) ? AccessoryFlags : 0)
| (ApplicationType.HasFlag(Type.Stains) ? StainFlags : 0); | (ApplicationType.HasFlag(Type.Stains) ? StainFlags : 0);
var customizeFlags = ApplicationType.HasFlag(Type.Customizations) ? CustomizeFlagExtensions.All : 0; var customizeFlags = ApplicationType.HasFlag(Type.Customizations) ? CustomizeFlagExtensions.All : 0;
return (equipFlags & Design.ApplyEquip, customizeFlags & Design.ApplyCustomize,
if (Revert)
return (equipFlags, customizeFlags, ApplicationType.HasFlag(Type.Armor), ApplicationType.HasFlag(Type.Armor),
ApplicationType.HasFlag(Type.Weapons), ApplicationType.HasFlag(Type.Customizations));
return (equipFlags & Design!.ApplyEquip, customizeFlags & Design.ApplyCustomize,
ApplicationType.HasFlag(Type.Armor) && Design.DoApplyHatVisible(), ApplicationType.HasFlag(Type.Armor) && Design.DoApplyHatVisible(),
ApplicationType.HasFlag(Type.Armor) && Design.DoApplyVisorToggle(), ApplicationType.HasFlag(Type.Armor) && Design.DoApplyVisorToggle(),
ApplicationType.HasFlag(Type.Weapons) && Design.DoApplyWeaponVisible(), ApplicationType.HasFlag(Type.Weapons) && Design.DoApplyWeaponVisible(),

View file

@ -11,7 +11,6 @@ using Glamourer.Structs;
using Glamourer.Unlocks; using Glamourer.Unlocks;
using Penumbra.GameData.Actors; using Penumbra.GameData.Actors;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Glamourer.Automation; namespace Glamourer.Automation;
@ -206,13 +205,16 @@ public class AutoDesignApplier : IDisposable
if (design.ApplicationType is 0) if (design.ApplicationType is 0)
continue; continue;
if (actor.AsCharacter->CharacterData.ModelCharaId != design.Design.DesignData.ModelId) ref var data = ref design.GetDesignData(state);
var source = design.Revert ? StateChanged.Source.Game : StateChanged.Source.Fixed;
if (actor.AsCharacter->CharacterData.ModelCharaId != data.ModelId)
continue; continue;
var (equipFlags, customizeFlags, applyHat, applyVisor, applyWeapon, applyWet) = design.ApplyWhat(); var (equipFlags, customizeFlags, applyHat, applyVisor, applyWeapon, applyWet) = design.ApplyWhat();
Reduce(state, in design.Design.DesignData, applyHat, applyVisor, applyWeapon, applyWet, ref totalMetaFlags, respectManual); Reduce(state, data, applyHat, applyVisor, applyWeapon, applyWet, ref totalMetaFlags, respectManual, source);
Reduce(state, in design.Design.DesignData, customizeFlags, ref totalCustomizeFlags, respectManual); Reduce(state, data, customizeFlags, ref totalCustomizeFlags, respectManual, source);
Reduce(state, in design.Design.DesignData, equipFlags, ref totalEquipFlags, respectManual); Reduce(state, data, equipFlags, ref totalEquipFlags, respectManual, source);
} }
} }
@ -229,7 +231,7 @@ public class AutoDesignApplier : IDisposable
return _manager.EnabledSets.TryGetValue(identifier, out set); return _manager.EnabledSets.TryGetValue(identifier, out set);
} }
private void Reduce(ActorState state, in DesignData design, EquipFlag equipFlags, ref EquipFlag totalEquipFlags, bool respectManual) private void Reduce(ActorState state, in DesignData design, EquipFlag equipFlags, ref EquipFlag totalEquipFlags, bool respectManual, StateChanged.Source source)
{ {
equipFlags &= ~totalEquipFlags; equipFlags &= ~totalEquipFlags;
if (equipFlags == 0) if (equipFlags == 0)
@ -244,7 +246,7 @@ public class AutoDesignApplier : IDisposable
if (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _)) if (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _))
{ {
if (!respectManual || state[slot, false] is not StateChanged.Source.Manual) if (!respectManual || state[slot, false] is not StateChanged.Source.Manual)
_state.ChangeItem(state, slot, item, StateChanged.Source.Fixed); _state.ChangeItem(state, slot, item, source);
totalEquipFlags |= flag; totalEquipFlags |= flag;
} }
} }
@ -253,7 +255,7 @@ public class AutoDesignApplier : IDisposable
if (equipFlags.HasFlag(stainFlag)) if (equipFlags.HasFlag(stainFlag))
{ {
if (!respectManual || state[slot, true] is not StateChanged.Source.Manual) if (!respectManual || state[slot, true] is not StateChanged.Source.Manual)
_state.ChangeStain(state, slot, design.Stain(slot), StateChanged.Source.Fixed); _state.ChangeStain(state, slot, design.Stain(slot), source);
totalEquipFlags |= stainFlag; totalEquipFlags |= stainFlag;
} }
} }
@ -265,7 +267,7 @@ public class AutoDesignApplier : IDisposable
&& (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _))) && (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _)))
{ {
if (!respectManual || state[EquipSlot.MainHand, false] is not StateChanged.Source.Manual) if (!respectManual || state[EquipSlot.MainHand, false] is not StateChanged.Source.Manual)
_state.ChangeItem(state, EquipSlot.MainHand, item, StateChanged.Source.Fixed); _state.ChangeItem(state, EquipSlot.MainHand, item, source);
totalEquipFlags |= EquipFlag.Mainhand; totalEquipFlags |= EquipFlag.Mainhand;
} }
} }
@ -277,7 +279,7 @@ public class AutoDesignApplier : IDisposable
&& (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _))) && (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _)))
{ {
if (!respectManual || state[EquipSlot.OffHand, false] is not StateChanged.Source.Manual) if (!respectManual || state[EquipSlot.OffHand, false] is not StateChanged.Source.Manual)
_state.ChangeItem(state, EquipSlot.OffHand, item, StateChanged.Source.Fixed); _state.ChangeItem(state, EquipSlot.OffHand, item, source);
totalEquipFlags |= EquipFlag.Offhand; totalEquipFlags |= EquipFlag.Offhand;
} }
} }
@ -285,20 +287,20 @@ public class AutoDesignApplier : IDisposable
if (equipFlags.HasFlag(EquipFlag.MainhandStain)) if (equipFlags.HasFlag(EquipFlag.MainhandStain))
{ {
if (!respectManual || state[EquipSlot.MainHand, true] is not StateChanged.Source.Manual) if (!respectManual || state[EquipSlot.MainHand, true] is not StateChanged.Source.Manual)
_state.ChangeStain(state, EquipSlot.MainHand, design.Stain(EquipSlot.MainHand), StateChanged.Source.Fixed); _state.ChangeStain(state, EquipSlot.MainHand, design.Stain(EquipSlot.MainHand), source);
totalEquipFlags |= EquipFlag.MainhandStain; totalEquipFlags |= EquipFlag.MainhandStain;
} }
if (equipFlags.HasFlag(EquipFlag.OffhandStain)) if (equipFlags.HasFlag(EquipFlag.OffhandStain))
{ {
if (!respectManual || state[EquipSlot.OffHand, true] is not StateChanged.Source.Manual) if (!respectManual || state[EquipSlot.OffHand, true] is not StateChanged.Source.Manual)
_state.ChangeStain(state, EquipSlot.OffHand, design.Stain(EquipSlot.OffHand), StateChanged.Source.Fixed); _state.ChangeStain(state, EquipSlot.OffHand, design.Stain(EquipSlot.OffHand), source);
totalEquipFlags |= EquipFlag.OffhandStain; totalEquipFlags |= EquipFlag.OffhandStain;
} }
} }
private void Reduce(ActorState state, in DesignData design, CustomizeFlag customizeFlags, ref CustomizeFlag totalCustomizeFlags, private void Reduce(ActorState state, in DesignData design, CustomizeFlag customizeFlags, ref CustomizeFlag totalCustomizeFlags,
bool respectManual) bool respectManual, StateChanged.Source source)
{ {
customizeFlags &= ~totalCustomizeFlags; customizeFlags &= ~totalCustomizeFlags;
if (customizeFlags == 0) if (customizeFlags == 0)
@ -328,12 +330,12 @@ public class AutoDesignApplier : IDisposable
} }
if (fixFlags != 0) if (fixFlags != 0)
_state.ChangeCustomize(state, customize, fixFlags, StateChanged.Source.Fixed); _state.ChangeCustomize(state, customize, fixFlags, source);
if (customizeFlags.HasFlag(CustomizeFlag.Face)) if (customizeFlags.HasFlag(CustomizeFlag.Face))
{ {
if (!respectManual || state[CustomizeIndex.Face] is not StateChanged.Source.Manual) if (!respectManual || state[CustomizeIndex.Face] is not StateChanged.Source.Manual)
_state.ChangeCustomize(state, CustomizeIndex.Face, design.Customize.Face, StateChanged.Source.Fixed); _state.ChangeCustomize(state, CustomizeIndex.Face, design.Customize.Face, source);
customizeFlags &= ~CustomizeFlag.Face; customizeFlags &= ~CustomizeFlag.Face;
totalCustomizeFlags |= CustomizeFlag.Face; totalCustomizeFlags |= CustomizeFlag.Face;
} }
@ -351,40 +353,40 @@ public class AutoDesignApplier : IDisposable
&& (!_config.UnlockedItemMode || _customizeUnlocks.IsUnlocked(data.Value, out _))) && (!_config.UnlockedItemMode || _customizeUnlocks.IsUnlocked(data.Value, out _)))
{ {
if (!respectManual || state[index] is not StateChanged.Source.Manual) if (!respectManual || state[index] is not StateChanged.Source.Manual)
_state.ChangeCustomize(state, index, value, StateChanged.Source.Fixed); _state.ChangeCustomize(state, index, value, source);
totalCustomizeFlags |= flag; totalCustomizeFlags |= flag;
} }
} }
} }
private void Reduce(ActorState state, in DesignData design, bool applyHat, bool applyVisor, bool applyWeapon, bool applyWet, private void Reduce(ActorState state, in DesignData design, bool applyHat, bool applyVisor, bool applyWeapon, bool applyWet,
ref byte totalMetaFlags, bool respectManual) ref byte totalMetaFlags, bool respectManual, StateChanged.Source source)
{ {
if (applyHat && (totalMetaFlags & 0x01) == 0) if (applyHat && (totalMetaFlags & 0x01) == 0)
{ {
if (!respectManual || state[ActorState.MetaIndex.HatState] is not StateChanged.Source.Manual) if (!respectManual || state[ActorState.MetaIndex.HatState] is not StateChanged.Source.Manual)
_state.ChangeHatState(state, design.IsHatVisible(), StateChanged.Source.Fixed); _state.ChangeHatState(state, design.IsHatVisible(), source);
totalMetaFlags |= 0x01; totalMetaFlags |= 0x01;
} }
if (applyVisor && (totalMetaFlags & 0x02) == 0) if (applyVisor && (totalMetaFlags & 0x02) == 0)
{ {
if (!respectManual || state[ActorState.MetaIndex.VisorState] is not StateChanged.Source.Manual) if (!respectManual || state[ActorState.MetaIndex.VisorState] is not StateChanged.Source.Manual)
_state.ChangeVisorState(state, design.IsVisorToggled(), StateChanged.Source.Fixed); _state.ChangeVisorState(state, design.IsVisorToggled(), source);
totalMetaFlags |= 0x02; totalMetaFlags |= 0x02;
} }
if (applyWeapon && (totalMetaFlags & 0x04) == 0) if (applyWeapon && (totalMetaFlags & 0x04) == 0)
{ {
if (!respectManual || state[ActorState.MetaIndex.WeaponState] is not StateChanged.Source.Manual) if (!respectManual || state[ActorState.MetaIndex.WeaponState] is not StateChanged.Source.Manual)
_state.ChangeWeaponState(state, design.IsWeaponVisible(), StateChanged.Source.Fixed); _state.ChangeWeaponState(state, design.IsWeaponVisible(), source);
totalMetaFlags |= 0x04; totalMetaFlags |= 0x04;
} }
if (applyWet && (totalMetaFlags & 0x08) == 0) if (applyWet && (totalMetaFlags & 0x08) == 0)
{ {
if (!respectManual || state[ActorState.MetaIndex.Wetness] is not StateChanged.Source.Manual) if (!respectManual || state[ActorState.MetaIndex.Wetness] is not StateChanged.Source.Manual)
_state.ChangeWetness(state, design.IsWet(), StateChanged.Source.Fixed); _state.ChangeWetness(state, design.IsWet(), source);
totalMetaFlags |= 0x08; totalMetaFlags |= 0x08;
} }
} }

View file

@ -6,7 +6,6 @@ using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Internal.Notifications;
using Dalamud.Utility;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events; using Glamourer.Events;
using Glamourer.Interop; using Glamourer.Interop;
@ -185,7 +184,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
return; return;
set.Enabled = value; set.Enabled = value;
AutoDesignSet? oldEnabled = null; AutoDesignSet? oldEnabled;
if (value) if (value)
{ {
if (_enabled.Remove(set.Identifiers[0], out oldEnabled)) if (_enabled.Remove(set.Identifiers[0], out oldEnabled))
@ -225,7 +224,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
_event.Invoke(AutomationChanged.Type.ChangedBase, set, (old, newBase)); _event.Invoke(AutomationChanged.Type.ChangedBase, set, (old, newBase));
} }
public void AddDesign(AutoDesignSet set, Design design) public void AddDesign(AutoDesignSet set, Design? design)
{ {
var newDesign = new AutoDesign() var newDesign = new AutoDesign()
{ {
@ -235,7 +234,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
}; };
set.Designs.Add(newDesign); set.Designs.Add(newDesign);
Save(); Save();
Glamourer.Log.Debug($"Added new associated design {design.Identifier} as design {set.Designs.Count} to design set."); Glamourer.Log.Debug($"Added new associated design {design?.Identifier.ToString() ?? "Reverter"} as design {set.Designs.Count} to design set.");
_event.Invoke(AutomationChanged.Type.AddedDesign, set, set.Designs.Count - 1); _event.Invoke(AutomationChanged.Type.AddedDesign, set, set.Designs.Count - 1);
} }
@ -260,20 +259,20 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
_event.Invoke(AutomationChanged.Type.MovedDesign, set, (from, to)); _event.Invoke(AutomationChanged.Type.MovedDesign, set, (from, to));
} }
public void ChangeDesign(AutoDesignSet set, int which, Design newDesign) public void ChangeDesign(AutoDesignSet set, int which, Design? newDesign)
{ {
if (which >= set.Designs.Count || which < 0) if (which >= set.Designs.Count || which < 0)
return; return;
var design = set.Designs[which]; var design = set.Designs[which];
if (design.Design.Identifier == newDesign.Identifier) if (design.Design?.Identifier == newDesign?.Identifier)
return; return;
var old = design.Design; var old = design.Design;
design.Design = newDesign; design.Design = newDesign;
Save(); Save();
Glamourer.Log.Debug( Glamourer.Log.Debug(
$"Changed linked design from {old.Identifier} to {newDesign.Identifier} for associated design {which + 1} in design set."); $"Changed linked design from {old?.Identifier.ToString() ?? "Reverter"} to {newDesign?.Identifier.ToString() ?? "Reverter"} for associated design {which + 1} in design set.");
_event.Invoke(AutomationChanged.Type.ChangedDesign, set, (which, old, newDesign)); _event.Invoke(AutomationChanged.Type.ChangedDesign, set, (which, old, newDesign));
} }
@ -390,7 +389,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
var set = new AutoDesignSet(name, id) var set = new AutoDesignSet(name, id)
{ {
Enabled = obj["Enabled"]?.ToObject<bool>() ?? false, Enabled = obj["Enabled"]?.ToObject<bool>() ?? false,
BaseState = obj["BaseState"]?.ToObject<AutoDesignSet.Base>() ?? AutoDesignSet.Base.Current, BaseState = obj["BaseState"]?.ToObject<AutoDesignSet.Base>() ?? AutoDesignSet.Base.Current,
}; };
@ -425,30 +424,33 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>
private AutoDesign? ToDesignObject(JObject jObj) private AutoDesign? ToDesignObject(JObject jObj)
{ {
var designIdentifier = jObj["Design"]?.ToObject<string>(); var designIdentifier = jObj["Design"]?.ToObject<string?>();
if (designIdentifier.IsNullOrEmpty()) Design? design = null;
// designIdentifier == null means Revert-Design.
if (designIdentifier != null)
{ {
Glamourer.Chat.NotificationMessage("Error parsing automatically applied design: No design specified."); if (designIdentifier.Length == 0)
return null; {
Glamourer.Chat.NotificationMessage("Error parsing automatically applied design: No design specified.");
return null;
}
if (!Guid.TryParse(designIdentifier, out var guid))
{
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: {designIdentifier} is not a valid GUID.");
return null;
}
design = _designs.Designs.FirstOrDefault(d => d.Identifier == guid);
if (design == null)
{
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: The specified design {guid} does not exist.");
return null;
}
} }
if (!Guid.TryParse(designIdentifier, out var guid))
{
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: {designIdentifier} is not a valid GUID.");
return null;
}
var design = _designs.Designs.FirstOrDefault(d => d.Identifier == guid);
if (design == null)
{
Glamourer.Chat.NotificationMessage($"Error parsing automatically applied design: The specified design {guid} does not exist.");
return null;
}
var applicationType = (AutoDesign.Type)(jObj["ApplicationType"]?.ToObject<uint>() ?? 0); var applicationType = (AutoDesign.Type)(jObj["ApplicationType"]?.ToObject<uint>() ?? 0);
var ret = new AutoDesign() var ret = new AutoDesign()
{ {
Design = design, Design = design,

View file

@ -14,7 +14,6 @@ namespace Glamourer.Designs;
public sealed class Design : DesignBase, ISavable public sealed class Design : DesignBase, ISavable
{ {
#region Data #region Data
internal Design(ItemManager items) internal Design(ItemManager items)
: base(items) : base(items)
{ } { }

View file

@ -2,6 +2,7 @@
using Glamourer.Automation; using Glamourer.Automation;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events; using Glamourer.Events;
using Glamourer.Services;
using ImGuiNET; using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
@ -11,30 +12,34 @@ namespace Glamourer.Gui.Tabs.AutomationTab;
public sealed class DesignCombo : FilterComboCache<Design> public sealed class DesignCombo : FilterComboCache<Design>
{ {
public const int RevertDesignIndex = -1228;
public readonly Design RevertDesign;
private readonly AutoDesignManager _manager; private readonly AutoDesignManager _manager;
private readonly DesignFileSystem _fileSystem; private readonly DesignFileSystem _fileSystem;
private readonly TabSelected _tabSelected; private readonly TabSelected _tabSelected;
public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected) public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected,
: base(() => designs.Designs.OrderBy(d => d.Name).ToList()) ItemManager items)
: base(() => designs.Designs.OrderBy(d => d.Name).Prepend(CreateRevertDesign(items)).ToList())
{ {
_manager = manager; _manager = manager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_tabSelected = tabSelected; _tabSelected = tabSelected;
RevertDesign = Items[0];
} }
protected override bool DrawSelectable(int globalIdx, bool selected) protected override bool DrawSelectable(int globalIdx, bool selected)
{ {
var ret = base.DrawSelectable(globalIdx, 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(); var fullName = leaf.FullName();
if (!fullName.StartsWith(Items[globalIdx].Name)) if (!fullName.StartsWith(Items[globalIdx].Name))
{ {
using var color = ImRaii.PushColor(ImGuiCol.Text, ImGui.GetColorU32(ImGuiCol.TextDisabled)); using var tt = ImRaii.Tooltip();
ImGui.SameLine(); ImGui.TextUnformatted(fullName);
ImGuiUtil.RightAlign(fullName);
} }
} }
@ -43,20 +48,20 @@ public sealed class DesignCombo : FilterComboCache<Design>
public void Draw(AutoDesignSet set, AutoDesign? design, int autoDesignIndex, bool incognito) public void Draw(AutoDesignSet set, AutoDesign? design, int autoDesignIndex, bool incognito)
{ {
CurrentSelection = design?.Design ?? (Items.Count > 0 ? Items[0] : null); CurrentSelection = design?.Design ?? RevertDesign;
CurrentSelectionIdx = design?.Design.Index ?? (Items.Count > 0 ? 0 : -1); CurrentSelectionIdx = (design?.Design?.Index ?? -1) + 1;
var name = (incognito ? CurrentSelection?.Incognito : CurrentSelection?.Name.Text) ?? string.Empty; var name = design?.Name(incognito) ?? string.Empty;
if (Draw("##design", name, string.Empty, ImGui.GetContentRegionAvail().X, if (Draw("##design", name, string.Empty, ImGui.GetContentRegionAvail().X,
ImGui.GetTextLineHeight()) ImGui.GetTextLineHeight())
&& CurrentSelection != null) && CurrentSelection != null)
{ {
if (autoDesignIndex >= 0) if (autoDesignIndex >= 0)
_manager.ChangeDesign(set, autoDesignIndex, CurrentSelection); _manager.ChangeDesign(set, autoDesignIndex, CurrentSelection == RevertDesign ? null : CurrentSelection);
else 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) if (ImGui.IsItemClicked(ImGuiMouseButton.Right) && ImGui.GetIO().KeyCtrl)
_tabSelected.Invoke(MainWindow.TabType.Designs, design.Design); _tabSelected.Invoke(MainWindow.TabType.Designs, design.Design);
@ -66,4 +71,11 @@ public sealed class DesignCombo : FilterComboCache<Design>
protected override string ToString(Design obj) protected override string ToString(Design obj)
=> obj.Name.Text; => obj.Name.Text;
private static Design CreateRevertDesign(ItemManager items)
=> new(items)
{
Index = RevertDesignIndex,
Name = AutoDesign.RevertName,
};
} }

View file

@ -1362,7 +1362,7 @@ public unsafe class DebugTab : ITab
foreach (var (design, designIdx) in set.Designs.WithIndex()) 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}"); ImGuiUtil.DrawTableColumn($"{design.ApplicationType} {design.Jobs.Name}");
} }
} }