API 4 updates

This commit is contained in:
Ottermandias 2021-08-27 15:06:58 +02:00
parent 86417ed74f
commit f10280d15d
31 changed files with 359 additions and 367 deletions

View file

@ -20,12 +20,12 @@ namespace Glamourer.Gui
private readonly IReadOnlyList<string> _itemNamesLower;
private readonly Func<T, string> _itemToName;
public Action? PrePreview = null;
public Action? PostPreview = null;
public Func<T, bool>? CreateSelectable = null;
public Action? PreList = null;
public Action? PostList = null;
public float? HeightPerItem = null;
public Action? PrePreview;
public Action? PostPreview;
public Func<T, bool>? CreateSelectable;
public Action? PreList;
public Action? PostList;
public float? HeightPerItem;
private float _heightPerItem;
@ -99,7 +99,7 @@ namespace Glamourer.Gui
{
nodeIdx = i;
var item = _items[i]!;
var success = false;
bool success;
if (CreateSelectable != null)
{
success = CreateSelectable(item);
@ -151,7 +151,7 @@ namespace Glamourer.Gui
_heightPerItem = HeightPerItem ?? ImGui.GetTextLineHeightWithSpacing();
var ret = false;
bool ret;
try
{
ImGui.SetNextItemWidth(-1);

View file

@ -7,15 +7,12 @@ namespace Glamourer.Gui
{
public sealed class ImGuiRaii : IDisposable
{
private int _colorStack = 0;
private int _fontStack = 0;
private int _styleStack = 0;
private float _indentation = 0f;
private int _colorStack;
private int _fontStack;
private int _styleStack;
private float _indentation;
private Stack<Action>? _onDispose = null;
public ImGuiRaii()
{ }
private Stack<Action>? _onDispose;
public static ImGuiRaii NewGroup()
=> new ImGuiRaii().Group();
@ -51,6 +48,7 @@ namespace Glamourer.Gui
ImGui.PopStyleColor(actualN);
_colorStack -= actualN;
}
return this;
}
@ -76,6 +74,7 @@ namespace Glamourer.Gui
ImGui.PopStyleVar(actualN);
_styleStack -= actualN;
}
return this;
}
@ -95,6 +94,7 @@ namespace Glamourer.Gui
ImGui.PopFont();
--_fontStack;
}
return this;
}
@ -105,6 +105,7 @@ namespace Glamourer.Gui
ImGui.Indent(width);
_indentation += width;
}
return this;
}
@ -134,7 +135,7 @@ namespace Glamourer.Gui
public void End(int n = 1)
{
var actualN = Math.Min(n, _onDispose?.Count ?? 0);
while(actualN-- > 0)
while (actualN-- > 0)
_onDispose!.Pop()();
}

View file

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Game.ClientState.Actors;
using Glamourer.Designs;
using ImGuiNET;
using Penumbra.GameData;
@ -19,7 +18,6 @@ namespace Glamourer.Gui
private readonly string _glamourerHeader;
private readonly IReadOnlyDictionary<byte, Stain> _stains;
private readonly ActorTable _actors;
private readonly IObjectIdentifier _identifier;
private readonly Dictionary<EquipSlot, (ComboWithFilter<Item>, ComboWithFilter<Stain>)> _combos;
private readonly ImGuiScene.TextureWrap? _legacyTattooIcon;
@ -27,8 +25,8 @@ namespace Glamourer.Gui
private readonly DesignManager _designs;
private readonly Glamourer _plugin;
private bool _visible = false;
private bool _inGPose = false;
private bool _visible;
private bool _inGPose;
public Interface(Glamourer plugin)
{
@ -37,31 +35,30 @@ namespace Glamourer.Gui
_glamourerHeader = Glamourer.Version.Length > 0
? $"{PluginName} v{Glamourer.Version}###{PluginName}Main"
: $"{PluginName}###{PluginName}Main";
Glamourer.PluginInterface.UiBuilder.DisableGposeUiHide = true;
Glamourer.PluginInterface.UiBuilder.OnBuildUi += Draw;
Glamourer.PluginInterface.UiBuilder.OnOpenConfigUi += ToggleVisibility;
Dalamud.PluginInterface.UiBuilder.DisableGposeUiHide = true;
Dalamud.PluginInterface.UiBuilder.Draw += Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi += ToggleVisibility;
_equipSlotNames = GetEquipSlotNames();
_stains = GameData.Stains(Glamourer.PluginInterface);
_identifier = Penumbra.GameData.GameData.GetIdentifier(Glamourer.PluginInterface);
_actors = Glamourer.PluginInterface.ClientState.Actors;
_stains = GameData.Stains(Dalamud.GameData);
_identifier = Penumbra.GameData.GameData.GetIdentifier(Dalamud.GameData, Dalamud.ClientState.ClientLanguage);
var stainCombo = CreateDefaultStainCombo(_stains.Values.ToArray());
var equip = GameData.ItemsBySlot(Glamourer.PluginInterface);
var equip = GameData.ItemsBySlot(Dalamud.GameData);
_combos = equip.ToDictionary(kvp => kvp.Key, kvp => CreateCombos(kvp.Key, kvp.Value, stainCombo));
_legacyTattooIcon = GetLegacyTattooIcon();
}
public void ToggleVisibility(object _, object _2)
public void ToggleVisibility()
=> _visible = !_visible;
public void Dispose()
{
_legacyTattooIcon?.Dispose();
Glamourer.PluginInterface.UiBuilder.OnBuildUi -= Draw;
Glamourer.PluginInterface.UiBuilder.OnOpenConfigUi -= ToggleVisibility;
Dalamud.PluginInterface.UiBuilder.Draw -= Draw;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= ToggleVisibility;
}
private void Draw()
@ -80,7 +77,7 @@ namespace Glamourer.Gui
if (!raii.Begin(() => ImGui.BeginTabBar("##tabBar"), ImGui.EndTabBar))
return;
_inGPose = _actors[GPoseActorId] != null;
_inGPose = Dalamud.Objects[GPoseActorId] != null;
_iconSize = Vector2.One * ImGui.GetTextLineHeightWithSpacing() * 2;
_actualIconSize = _iconSize + 2 * ImGui.GetStyle().FramePadding;
_comboSelectorSize = 4 * _actualIconSize.X + 3 * ImGui.GetStyle().ItemSpacing.X;

View file

@ -1,9 +1,9 @@
using System;
using System.Linq;
using System.Numerics;
using System.Windows.Forms;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Interface;
using Dalamud.Plugin;
using Dalamud.Logging;
using Glamourer.Designs;
using Glamourer.FileSystem;
using ImGuiNET;
@ -12,9 +12,9 @@ namespace Glamourer.Gui
{
internal partial class Interface
{
private readonly CharacterSave _currentSave = new();
private string _newDesignName = string.Empty;
private bool _keyboardFocus = false;
private readonly CharacterSave _currentSave = new();
private string _newDesignName = string.Empty;
private bool _keyboardFocus;
private const string DesignNamePopupLabel = "Save Design As...";
private const uint RedHeaderColor = 0xFF1818C0;
private const uint GreenHeaderColor = 0xFF18C018;
@ -37,7 +37,7 @@ namespace Glamourer.Gui
{
ImGui.PushFont(UiBuilder.IconFont);
if (ImGui.Button(FontAwesomeIcon.Clipboard.ToIconString()))
Clipboard.SetText(save.ToBase64());
ImGui.SetClipboardText(save.ToBase64());
ImGui.PopFont();
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Copy customization code to clipboard.");
@ -54,7 +54,7 @@ namespace Glamourer.Gui
if (!applyButton)
return false;
var text = Clipboard.GetText();
var text = ImGui.GetClipboardText();
if (!text.Any())
return false;
@ -88,41 +88,41 @@ namespace Glamourer.Gui
private void DrawTargetPlayerButton()
{
if (ImGui.Button("Target Player"))
Glamourer.PluginInterface.ClientState.Targets.SetCurrentTarget(_player);
Dalamud.Targets.SetTarget(_player);
}
private void DrawApplyToPlayerButton(CharacterSave save)
{
if (ImGui.Button("Apply to Self"))
{
var player = _inGPose
? Glamourer.PluginInterface.ClientState.Actors[GPoseActorId]
: Glamourer.PluginInterface.ClientState.LocalPlayer;
var fallback = _inGPose ? Glamourer.PluginInterface.ClientState.LocalPlayer : null;
if (player != null)
{
save.Apply(player);
if (_inGPose)
save.Apply(fallback!);
_plugin.UpdateActors(player, fallback);
}
}
if (!ImGui.Button("Apply to Self"))
return;
var player = _inGPose
? (Character?) Dalamud.Objects[GPoseActorId]
: Dalamud.ClientState.LocalPlayer;
var fallback = _inGPose ? Dalamud.ClientState.LocalPlayer : null;
if (player == null)
return;
save.Apply(player);
if (_inGPose)
save.Apply(fallback!);
_plugin.UpdateActors(player, fallback);
}
private void DrawApplyToTargetButton(CharacterSave save)
{
if (ImGui.Button("Apply to Target"))
{
var player = Glamourer.PluginInterface.ClientState.Targets.CurrentTarget;
if (player != null)
{
var fallBackActor = _playerNames[player.Name];
save.Apply(player);
if (fallBackActor != null)
save.Apply(fallBackActor);
_plugin.UpdateActors(player, fallBackActor);
}
}
if (!ImGui.Button("Apply to Target"))
return;
var player = Dalamud.Targets.Target as Character;
if (player == null)
return;
var fallBackActor = _playerNames[player.Name.ToString()];
save.Apply(player);
if (fallBackActor != null)
save.Apply(fallBackActor);
_plugin.UpdateActors(player, fallBackActor);
}
private void SaveNewDesign(CharacterSave save)
@ -130,13 +130,13 @@ namespace Glamourer.Gui
try
{
var (folder, name) = _designs.FileSystem.CreateAllFolders(_newDesignName);
if (name.Any())
{
var newDesign = new Design(folder, name) { Data = save };
folder.AddChild(newDesign);
_designs.Designs[newDesign.FullName()] = save;
_designs.SaveToFile();
}
if (!name.Any())
return;
var newDesign = new Design(folder, name) { Data = save };
folder.AddChild(newDesign);
_designs.Designs[newDesign.FullName()] = save;
_designs.SaveToFile();
}
catch (Exception e)
{

View file

@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Game.ClientState.Actors;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Interface;
using ImGuiNET;
@ -10,11 +10,11 @@ namespace Glamourer.Gui
{
internal partial class Interface
{
private Actor? _player;
private Character? _player;
private string _currentActorName = string.Empty;
private string _actorFilter = string.Empty;
private string _actorFilterLower = string.Empty;
private readonly Dictionary<string, Actor?> _playerNames = new(400);
private readonly Dictionary<string, Character?> _playerNames = new(400);
private void DrawActorFilter()
{
@ -26,9 +26,9 @@ namespace Glamourer.Gui
_actorFilterLower = _actorFilter.ToLowerInvariant();
}
private void DrawActorSelectable(Actor actor, bool gPose)
private void DrawActorSelectable(Character actor, bool gPose)
{
var actorName = actor.Name;
var actorName = actor.Name.ToString();
if (!actorName.Any())
return;
@ -50,7 +50,7 @@ namespace Glamourer.Gui
return;
}
if (_currentActorName == actor.Name)
if (_currentActorName == actorName)
{
_currentSave.LoadActor(actor);
_player = actor;
@ -63,10 +63,10 @@ namespace Glamourer.Gui
.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
.PushStyle(ImGuiStyleVar.FrameRounding, 0)
.PushFont(UiBuilder.IconFont);
Actor? select = null;
Character? select = null;
var buttonWidth = Vector2.UnitX * SelectorWidth / 2;
if (ImGui.Button(FontAwesomeIcon.UserCircle.ToIconString(), buttonWidth))
select = Glamourer.PluginInterface.ClientState.LocalPlayer;
select = Dalamud.ClientState.LocalPlayer;
raii.PopFonts();
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Select the local player character.");
@ -81,7 +81,7 @@ namespace Glamourer.Gui
else
{
if (ImGui.Button(FontAwesomeIcon.HandPointer.ToIconString(), buttonWidth))
select = Glamourer.PluginInterface.ClientState.Targets.CurrentTarget;
select = Dalamud.Targets.Target as Character;
}
raii.PopFonts();
@ -92,7 +92,7 @@ namespace Glamourer.Gui
return;
_player = select;
_currentActorName = _player.Name;
_currentActorName = _player.Name.ToString();
_currentSave.LoadActor(_player);
}
@ -107,7 +107,7 @@ namespace Glamourer.Gui
_playerNames.Clear();
for (var i = GPoseActorId; i < GPoseActorId + 48; ++i)
{
var actor = _actors[i];
var actor = Dalamud.Objects[i] as Character;
if (actor == null)
break;
@ -117,13 +117,13 @@ namespace Glamourer.Gui
for (var i = 0; i < GPoseActorId; i += 2)
{
var actor = _actors[i];
var actor = Dalamud.Objects[i] as Character;
if (actor != null && actor.ObjectKind == ObjectKind.Player)
DrawActorSelectable(actor, false);
}
using (var raii = new ImGuiRaii().PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
using (var _ = new ImGuiRaii().PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero))
{
ImGui.EndChild();
}

View file

@ -53,7 +53,7 @@ namespace Glamourer.Gui
return;
}
if (ImGui.Button(buttonLabel) && _plugin.GetPenumbra())
if (ImGui.Button(buttonLabel) && Glamourer.GetPenumbra())
{
_plugin.UnregisterFunctions();
_plugin.RegisterFunctions();
@ -88,7 +88,7 @@ namespace Glamourer.Gui
cfg.AttachToPenumbra = v;
if (v)
{
if (_plugin.GetPenumbra())
if (Glamourer.GetPenumbra())
_plugin.RegisterFunctions();
}
else

View file

@ -2,7 +2,7 @@
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Plugin;
using Dalamud.Logging;
using Glamourer.Customization;
using ImGuiNET;
using Penumbra.GameData.Enums;
@ -39,13 +39,13 @@ namespace Glamourer.Gui
return ret;
}
private Vector2 _iconSize = Vector2.Zero;
private Vector2 _actualIconSize = Vector2.Zero;
private float _raceSelectorWidth = 0;
private float _inputIntSize = 0;
private float _comboSelectorSize = 0;
private float _percentageSize = 0;
private float _itemComboWidth = 0;
private Vector2 _iconSize = Vector2.Zero;
private Vector2 _actualIconSize = Vector2.Zero;
private float _raceSelectorWidth;
private float _inputIntSize;
private float _comboSelectorSize;
private float _percentageSize;
private float _itemComboWidth;
private bool InputInt(string label, ref int value, int minValue, int maxValue)
{
@ -93,7 +93,7 @@ namespace Glamourer.Gui
ImGui.SameLine();
using (var group = ImGuiRaii.NewGroup())
using (var _ = ImGuiRaii.NewGroup())
{
if (InputInt($"##text_{id}", ref current, 1, count))
{

View file

@ -1,9 +1,8 @@
using System;
using System.Linq;
using System.Numerics;
using System.Windows.Forms;
using Dalamud.Interface;
using Dalamud.Plugin;
using Dalamud.Logging;
using Glamourer.Designs;
using Glamourer.FileSystem;
using ImGuiNET;
@ -12,9 +11,9 @@ namespace Glamourer.Gui
{
internal partial class Interface
{
private int _totalObject = 0;
private int _totalObject;
private Design? _selection = null;
private Design? _selection;
private string _newChildName = string.Empty;
private void DrawDesignSelector()
@ -50,7 +49,7 @@ namespace Glamourer.Gui
if (_selection!.Data.WriteProtected || !applyButton)
return;
var text = Clipboard.GetText();
var text = ImGui.GetClipboardText();
if (!text.Any())
return;
@ -280,7 +279,6 @@ namespace Glamourer.Gui
private void ContextMenu(IFileSystemBase child)
{
var label = $"##fsPopup{child.FullName()}";
var renameLabel = $"{label}_rename";
if (ImGui.BeginPopup(label))
{
if (ImGui.MenuItem("Delete"))
@ -289,7 +287,7 @@ namespace Glamourer.Gui
RenameChildInput(child);
if (child is Design d && ImGui.MenuItem("Copy to Clipboard"))
Clipboard.SetText(d.Data.ToBase64());
ImGui.SetClipboardText(d.Data.ToBase64());
ImGui.EndPopup();
}

View file

@ -1,11 +1,8 @@
using System;
using System.Linq;
using System.Windows.Forms;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Plugin;
using Dalamud.Logging;
using Glamourer.Customization;
using ImGuiNET;
using Penumbra.Api;
using Penumbra.GameData.Enums;
namespace Glamourer.Gui
@ -46,7 +43,7 @@ namespace Glamourer.Gui
break;
default:
var count = set.Count(id);
if (set.DataByValue(id, customization[id], out var value) < 0)
if (set.DataByValue(id, customization[id], out _) < 0)
if (count == 0)
customization[id] = 0;
else
@ -173,7 +170,7 @@ namespace Glamourer.Gui
case DesignNameUse.FromClipboard:
try
{
var text = Clipboard.GetText();
var text = ImGui.GetClipboardText();
var save = CharacterSave.FromString(text);
SaveNewDesign(save);
}

View file

@ -53,7 +53,7 @@ namespace Glamourer.Gui
{
var rawImage = new byte[resource.Length];
resource.Read(rawImage, 0, (int) resource.Length);
return Glamourer.PluginInterface.UiBuilder.LoadImageRaw(rawImage, 192, 192, 4);
return Dalamud.PluginInterface.UiBuilder.LoadImageRaw(rawImage, 192, 192, 4);
}
return null;
@ -61,7 +61,7 @@ namespace Glamourer.Gui
private static Dictionary<EquipSlot, string> GetEquipSlotNames()
{
var sheet = Glamourer.PluginInterface.Data.GetExcelSheet<Addon>();
var sheet = Dalamud.GameData.GetExcelSheet<Addon>()!;
var ret = new Dictionary<EquipSlot, string>(12)
{
[EquipSlot.MainHand] = sheet.GetRow(738)?.Text.ToString() ?? "Main Hand",

View file

@ -1,5 +1,5 @@
using System;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Objects.Types;
using ImGuiNET;
namespace Glamourer.Gui
@ -18,7 +18,7 @@ namespace Glamourer.Gui
return false;
}
private static bool DrawMiscellaneous(CharacterSave save, Actor? player)
private static bool DrawMiscellaneous(CharacterSave save, Character? player)
{
var ret = false;
if (!ImGui.CollapsingHeader("Miscellaneous"))