This commit is contained in:
Ottermandias 2023-06-19 23:59:22 +02:00
parent 80ab57e96d
commit d1d369a56b
31 changed files with 1637 additions and 80 deletions

View file

@ -0,0 +1,218 @@
using System.Numerics;
using Glamourer.Gui.Customization;
using Glamourer.Interop.Structs;
using Glamourer.State;
using ImGuiNET;
using OtterGui.Raii;
using Penumbra.GameData.Actors;
using Penumbra.GameData.Enums;
namespace Glamourer.Gui.Tabs.ActorTab;
public class ActorPanel
{
private readonly ActorSelector _selector;
private readonly StateManager _stateManager;
private readonly CustomizationDrawer _customizationDrawer;
private ActorIdentifier _identifier;
private string _actorName = string.Empty;
private Actor _actor = Actor.Null;
private ActorData _data;
private ActorState? _state;
public ActorPanel(ActorSelector selector, StateManager stateManager, CustomizationDrawer customizationDrawer)
{
_selector = selector;
_stateManager = stateManager;
_customizationDrawer = customizationDrawer;
}
public void Draw()
{
if (!_selector.HasSelection)
return;
(_identifier, _data) = _selector.Selection;
if (_data.Valid)
{
_actorName = _data.Label;
_actor = _data.Objects[0];
}
else
{
_actorName = _identifier.ToString();
_actor = Actor.Null;
}
if (!_stateManager.GetOrCreate(_identifier, _actor, out _state))
return;
//if (_state != null)
// _stateManager.Update(ref _state.Data, _actor);
using var group = ImRaii.Group();
DrawHeader();
DrawPanel();
}
private void DrawHeader()
{
var color = _data.Valid ? ColorId.ActorAvailable.Value() : ColorId.ActorUnavailable.Value();
var buttonColor = ImGui.GetColorU32(ImGuiCol.FrameBg);
using var c = ImRaii.PushColor(ImGuiCol.Text, color)
.Push(ImGuiCol.Button, buttonColor)
.Push(ImGuiCol.ButtonHovered, buttonColor)
.Push(ImGuiCol.ButtonActive, buttonColor);
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
.Push(ImGuiStyleVar.FrameRounding, 0);
ImGui.Button($"{(_data.Valid ? _data.Label : _identifier.ToString())}##playerHeader", -Vector2.UnitX);
}
private unsafe void DrawPanel()
{
using var child = ImRaii.Child("##ActorPanel", -Vector2.One, true);
if (!child || _state == null)
return;
if (_customizationDrawer.Draw(_state.Data.Customize, false))
{
}
// if (_currentData.Valid)
// _currentSave.Initialize(_items, _currentData.Objects[0]);
//
// RevertButton();
// ActorDebug.Draw(_currentSave.ModelData);
// return;
//
// if (_main._customizationDrawer.Draw(_currentSave.ModelData.Customize, _identifier.Type == IdentifierType.Special))
// _activeDesigns.ChangeCustomize(_currentSave, _main._customizationDrawer.Changed, _main._customizationDrawer.Customize.Data,
// false);
//
// foreach (var slot in EquipSlotExtensions.EqdpSlots)
// {
// var current = _currentSave.Armor(slot);
// if (_main._equipmentDrawer.DrawStain(current.Stain, slot, out var stain))
// _activeDesigns.ChangeStain(_currentSave, slot, stain.RowIndex, false);
// ImGui.SameLine();
// if (_main._equipmentDrawer.DrawArmor(current, slot, out var armor, _currentSave.ModelData.Customize.Gender,
// _currentSave.ModelData.Customize.Race))
// _activeDesigns.ChangeEquipment(_currentSave, slot, armor, false);
// }
//
// var currentMain = _currentSave.WeaponMain;
// if (_main._equipmentDrawer.DrawStain(currentMain.Stain, EquipSlot.MainHand, out var stainMain))
// _activeDesigns.ChangeStain(_currentSave, EquipSlot.MainHand, stainMain.RowIndex, false);
// ImGui.SameLine();
// _main._equipmentDrawer.DrawMainhand(currentMain, true, out var main);
// if (currentMain.Type.Offhand() != FullEquipType.Unknown)
// {
// var currentOff = _currentSave.WeaponOff;
// if (_main._equipmentDrawer.DrawStain(currentOff.Stain, EquipSlot.OffHand, out var stainOff))
// _activeDesigns.ChangeStain(_currentSave, EquipSlot.OffHand, stainOff.RowIndex, false);
// ImGui.SameLine();
// _main._equipmentDrawer.DrawOffhand(currentOff, main.Type, out var off);
// }
//
// if (_main._equipmentDrawer.DrawVisor(_currentSave, out var value))
// _activeDesigns.ChangeVisor(_currentSave, value, false);
}
private unsafe void RevertButton()
{
//if (ImGui.Button("Revert"))
// _activeDesigns.RevertDesign(_currentSave!);
//foreach (var actor in _currentData.Objects)
// _currentSave!.ApplyToActor(actor);
//
//if (_currentData.Objects.Count > 0)
// _currentSave = _manipulations.GetOrCreateSave(_currentData.Objects[0]);
//
//_currentSave!.Reset();
//if (_currentData.Objects.Count > 0)
// ImGui.TextUnformatted(_currentData.Objects[0].Pointer->GameObject.DataID.ToString());
//VisorBox();
}
//private unsafe void VisorBox()
//{
// var (flags, mask) = (_currentSave!.Data.Flags & (ApplicationFlags.SetVisor | ApplicationFlags.Visor)) switch
// {
// ApplicationFlags.SetVisor => (0u, 3u),
// ApplicationFlags.Visor => (1u, 3u),
// ApplicationFlags.SetVisor | ApplicationFlags.Visor => (3u, 3u),
// _ => (2u, 3u),
// };
// var tmp = flags;
// if (ImGui.CheckboxFlags("Visor Toggled", ref tmp, mask))
// {
// _currentSave.Data.Flags = flags switch
// {
// 0 => (_currentSave.Data.Flags | ApplicationFlags.Visor) & ~ApplicationFlags.SetVisor,
// 1 => _currentSave.Data.Flags | ApplicationFlags.SetVisor,
// 2 => _currentSave.Data.Flags | ApplicationFlags.SetVisor,
// _ => _currentSave.Data.Flags & ~(ApplicationFlags.SetVisor | ApplicationFlags.Visor),
// };
// if (_currentSave.Data.Flags.HasFlag(ApplicationFlags.SetVisor))
// {
// var on = _currentSave.Data.Flags.HasFlag(ApplicationFlags.Visor);
// foreach (var actor in _currentData.Objects.Where(a => a.IsHuman && a.DrawObject))
// RedrawManager.SetVisor(actor.DrawObject.Pointer, on);
// }
// }
//}
//private void DrawActorPanel()
//{
// using var group = ImRaii.Group();
// if (!_data.Identifier.IsValid)
// return;
//
// if (DrawCustomization(_currentSave.Customize, _currentSave.Equipment, !_data.Modifiable))
// //Glamourer.RedrawManager.Set(_data.Actor.Address, _character);
// Glamourer.Penumbra.RedrawObject(_data.Actor.Character, RedrawType.Redraw, true);
//
// if (ImGui.Button("Set Machinist Goggles"))
// Glamourer.RedrawManager.ChangeEquip(_data.Actor, EquipSlot.Head, new CharacterArmor(265, 1, 0));
//
// if (ImGui.Button("Set Weapon"))
// Glamourer.RedrawManager.LoadWeapon(_data.Actor.Address, new CharacterWeapon(0x00C9, 0x004E, 0x0001, 0x00),
// new CharacterWeapon(0x0065, 0x003D, 0x0001, 0x00));
//
// if (ImGui.Button("Set Customize"))
// {
// unsafe
// {
// var data = _data.Actor.Customize.Data->Clone();
// Glamourer.RedrawManager.UpdateCustomize(_data.Actor.DrawObject, new Customize(&data)
// {
// SkinColor = 154,
// });
// }
// }
//}
//
//private void DrawMonsterPanel()
//{
// using var group = ImRaii.Group();
// var currentModel = (uint)_data.Actor.ModelId;
// var models = GameData.Models(Dalamud.GameData);
// var currentData = models.Models.TryGetValue(currentModel, out var c) ? c.FirstName : $"#{currentModel}";
// using var combo = ImRaii.Combo("Model Id", currentData);
// if (!combo)
// return;
//
// foreach (var (id, data) in models.Models)
// {
// if (ImGui.Selectable(data.FirstName, id == currentModel) && id != currentModel)
// {
// _data.Actor.SetModelId((int)id);
// Glamourer.Penumbra.RedrawObject(_data.Actor.Character, RedrawType.Redraw, true);
// }
//
// ImGuiUtil.HoverTooltip(data.AllNames);
// }
//}
}

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Interface;
using Glamourer.Interop;
using Glamourer.Interop.Structs;
using Glamourer.Services;
using ImGuiNET;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
using Penumbra.GameData.Actors;
namespace Glamourer.Gui.Tabs.ActorTab;
public class ActorSelector
{
private readonly ObjectManager _objects;
private readonly ActorService _actors;
private readonly TargetManager _targets;
private ActorIdentifier _identifier = ActorIdentifier.Invalid;
public ActorSelector(ObjectManager objects, TargetManager targets, ActorService actors)
{
_objects = objects;
_targets = targets;
_actors = actors;
}
private LowerString _actorFilter = LowerString.Empty;
private Vector2 _defaultItemSpacing;
private float _width;
public (ActorIdentifier Identifier, ActorData Data) Selection
=> _objects.TryGetValue(_identifier, out var data) ? (_identifier, data) : (_identifier, ActorData.Invalid);
public bool HasSelection
=> _identifier.IsValid;
public void Draw(float width)
{
_width = width;
using var group = ImRaii.Group();
_defaultItemSpacing = ImGui.GetStyle().ItemSpacing;
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
.Push(ImGuiStyleVar.FrameRounding, 0);
ImGui.SetNextItemWidth(_width);
LowerString.InputWithHint("##actorFilter", "Filter...", ref _actorFilter, 64);
DrawSelector();
DrawSelectionButtons();
}
private void DrawSelector()
{
using var child = ImRaii.Child("##actorSelector", new Vector2(_width, -ImGui.GetFrameHeight()), true);
if (!child)
return;
_objects.Update();
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, _defaultItemSpacing);
var skips = ImGuiClip.GetNecessarySkips(ImGui.GetTextLineHeight());
var remainder = ImGuiClip.FilteredClippedDraw(_objects, skips, CheckFilter, DrawSelectable);
ImGuiClip.DrawEndDummy(remainder, ImGui.GetTextLineHeight());
}
private bool CheckFilter(KeyValuePair<ActorIdentifier, ActorData> pair)
=> _actorFilter.IsEmpty || pair.Value.Label.Contains(_actorFilter.Lower, StringComparison.OrdinalIgnoreCase);
private void DrawSelectable(KeyValuePair<ActorIdentifier, ActorData> pair)
{
var equals = pair.Key.Equals(_identifier);
if (ImGui.Selectable(pair.Value.Label, equals) && !equals)
_identifier = pair.Key.CreatePermanent();
}
private void DrawSelectionButtons()
{
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
.Push(ImGuiStyleVar.FrameRounding, 0);
var buttonWidth = new Vector2(_width / 2, 0);
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.UserCircle.ToIconString(), buttonWidth
, "Select the local player character.", !_objects.Player, true))
_identifier = _objects.Player.GetIdentifier(_actors.AwaitedService);
ImGui.SameLine();
Actor targetActor = _targets.Target?.Address;
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.HandPointer.ToIconString(), buttonWidth,
"Select the current target, if it is in the list.", _objects.IsInGPose || !targetActor, true))
_identifier = targetActor.GetIdentifier(_actors.AwaitedService);
}
}

View file

@ -0,0 +1,28 @@
using System;
using Dalamud.Interface;
using ImGuiNET;
using OtterGui.Widgets;
namespace Glamourer.Gui.Tabs.ActorTab;
public class ActorTab : ITab
{
private readonly ActorSelector _selector;
private readonly ActorPanel _panel;
public ReadOnlySpan<byte> Label
=> "Actors"u8;
public void DrawContent()
{
_selector.Draw(200 * ImGuiHelpers.GlobalScale);
ImGui.SameLine();
_panel.Draw();
}
public ActorTab(ActorSelector selector, ActorPanel panel)
{
_selector = selector;
_panel = panel;
}
}

View file

@ -66,7 +66,7 @@ public unsafe class DebugTab : ITab
_designFileSystem = designFileSystem;
_designManager = designManager;
_state = state;
_config = config;
_config = config;
}
public ReadOnlySpan<byte> Label
@ -74,6 +74,10 @@ public unsafe class DebugTab : ITab
public void DrawContent()
{
using var child = ImRaii.Child("MainWindowChild");
if (!child)
return;
DrawInteropHeader();
DrawGameDataHeader();
DrawPenumbraHeader();
@ -829,7 +833,7 @@ public unsafe class DebugTab : ITab
}
}
private static void DrawDesignData(in DesignData data)
public static void DrawDesignData(in DesignData data)
{
if (data.ModelId == 0)
{

View file

@ -0,0 +1,66 @@
using System.Numerics;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Interface;
using Glamourer.Designs;
using Glamourer.Events;
using OtterGui;
using OtterGui.Filesystem;
using OtterGui.FileSystem.Selector;
namespace Glamourer.Gui.Tabs.DesignTab;
public sealed class DesignFileSystemSelector : FileSystemSelector<Design, DesignFileSystemSelector.DesignState>
{
private readonly DesignManager _designManager;
private readonly DesignChanged _event;
private readonly Configuration _config;
public struct DesignState
{ }
public DesignFileSystemSelector(DesignManager designManager, DesignFileSystem fileSystem, KeyState keyState, DesignChanged @event,
Configuration config)
: base(fileSystem, keyState)
{
_designManager = designManager;
_event = @event;
_config = config;
_event.Subscribe(OnDesignChange, DesignChanged.Priority.DesignFileSystemSelector);
AddButton(DeleteButton, 1000);
}
public override void Dispose()
{
base.Dispose();
_event.Unsubscribe(OnDesignChange);
}
private void OnDesignChange(DesignChanged.Type type, Design design, object? oldData)
{
switch (type)
{
case DesignChanged.Type.ReloadedAll:
case DesignChanged.Type.Renamed:
case DesignChanged.Type.AddedTag:
case DesignChanged.Type.ChangedTag:
case DesignChanged.Type.RemovedTag:
SetFilterDirty();
break;
}
}
private void DeleteButton(Vector2 size)
{
var keys = _config.DeleteDesignModifier.IsActive();
var tt = SelectedLeaf == null
? "No design selected."
: "Delete the currently selected design entirely from your drive.\n"
+ "This can not be undone.";
if (!keys)
tt += $"\nHold {_config.DeleteDesignModifier} while clicking to delete the mod.";
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), size, tt, SelectedLeaf == null || !keys, true)
&& Selected != null)
_designManager.Delete(Selected);
}
}

View file

@ -0,0 +1,33 @@
using System.Numerics;
using Glamourer.Designs;
using Glamourer.Gui.Customization;
using OtterGui.Raii;
namespace Glamourer.Gui.Tabs.DesignTab;
public class DesignPanel
{
private readonly DesignFileSystemSelector _selector;
private readonly DesignManager _manager;
private readonly CustomizationDrawer _customizationDrawer;
public DesignPanel(DesignFileSystemSelector selector, CustomizationDrawer customizationDrawer, DesignManager manager)
{
_selector = selector;
_customizationDrawer = customizationDrawer;
_manager = manager;
}
public void Draw()
{
var design = _selector.Selected;
if (design == null)
return;
using var child = ImRaii.Child("##panel", -Vector2.One, true);
if (!child)
return;
_customizationDrawer.Draw(design.DesignData.Customize, design.WriteProtected());
}
}

View file

@ -0,0 +1,39 @@
using System;
using Dalamud.Interface;
using Glamourer.Designs;
using Glamourer.Interop;
using ImGuiNET;
using OtterGui.Widgets;
namespace Glamourer.Gui.Tabs.DesignTab;
public class DesignTab : ITab
{
public readonly DesignFileSystemSelector Selector;
private readonly DesignFileSystem _fileSystem;
private readonly DesignManager _designManager;
private readonly DesignPanel _panel;
private readonly ObjectManager _objects;
public DesignTab(DesignFileSystemSelector selector, DesignFileSystem fileSystem, DesignManager designManager, ObjectManager objects, DesignPanel panel)
{
Selector = selector;
_fileSystem = fileSystem;
_designManager = designManager;
_objects = objects;
_panel = panel;
}
public ReadOnlySpan<byte> Label
=> "Designs"u8;
public void DrawContent()
{
Selector.Draw(GetDesignSelectorSize());
ImGui.SameLine();
_panel.Draw();
}
public float GetDesignSelectorSize()
=> 200f * ImGuiHelpers.GlobalScale;
}

View file

@ -1,8 +1,10 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using Dalamud.Interface;
using ImGuiNET;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
using OtterGui.Widgets;
@ -20,20 +22,23 @@ public class SettingsTab : ITab
public void DrawContent()
{
using var child = ImRaii.Child("##SettingsTab", -Vector2.One, false);
using var child = ImRaii.Child("MainWindowChild");
if (!child)
return;
Checkbox("Restricted Gear Protection",
"Use gender- and race-appropriate models when detecting certain items not available for a characters current gender and race.",
_config.UseRestrictedGearProtection, v => _config.UseRestrictedGearProtection = v);
if (Widget.DoubleModifierSelector("Design Deletion Modifier",
"A modifier you need to hold while clicking the Delete Design button for it to take effect.", 100 * ImGuiHelpers.GlobalScale,
_config.DeleteDesignModifier, v => _config.DeleteDesignModifier = v))
_config.Save();
Checkbox("Debug Mode", "Show the debug tab. Only useful for debugging or advanced use.", _config.DebugMode, v => _config.DebugMode = v);
DrawColorSettings();
MainWindow.DrawSupportButtons();
}
/// <summary> Draw the entire Color subsection. </summary>
private void DrawColorSettings()
{