Some more reworking

This commit is contained in:
Ottermandias 2022-10-19 15:24:27 +02:00
parent 6a4b5fc3b2
commit dad146d043
41 changed files with 1714 additions and 1320 deletions

View file

@ -9,10 +9,10 @@ internal partial class CustomizationDrawer
{
private const string ColorPickerPopupName = "ColorPicker";
private void DrawColorPicker(CustomizationId id)
private void DrawColorPicker(CustomizeIndex index)
{
using var _ = SetId(id);
var (current, custom) = GetCurrentCustomization(id);
using var _ = SetId(index);
var (current, custom) = GetCurrentCustomization(index);
var color = ImGui.ColorConvertU32ToFloat4(custom.Color);
// Print 1-based index instead of 0.
@ -40,7 +40,7 @@ internal partial class CustomizationDrawer
.Push(ImGuiStyleVar.FrameRounding, 0);
for (var i = 0; i < _currentCount; ++i)
{
var custom = _set.Data(_currentId, i, _customize[CustomizationId.Face]);
var custom = _set.Data(_currentIndex, i, _customize[CustomizeIndex.Face]);
if (ImGui.ColorButton((i + 1).ToString(), ImGui.ColorConvertU32ToFloat4(custom.Color)))
{
UpdateValue(custom.Value);
@ -53,13 +53,13 @@ internal partial class CustomizationDrawer
}
// Obtain the current customization and print a warning if it is not known.
private (int, CustomizationData) GetCurrentCustomization(CustomizationId id)
private (int, CustomizeData) GetCurrentCustomization(CustomizeIndex index)
{
var current = _set.DataByValue(id, _customize[id], out var custom);
if (!_set.IsAvailable(id) || current >= 0)
var current = _set.DataByValue(index, _customize[index], out var custom, _customize.Face);
if (!_set.IsAvailable(index) || current >= 0)
return (current, custom!.Value);
Glamourer.Log.Warning($"Read invalid customization value {_customize[id]} for {id}.");
return (0, _set.Data(id, 0));
Glamourer.Log.Warning($"Read invalid customization value {_customize[index]} for {index}.");
return (0, _set.Data(index, 0));
}
}

View file

@ -6,6 +6,7 @@ using Glamourer.Util;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.Api.Enums;
using Penumbra.GameData.Enums;
namespace Glamourer.Gui.Customization;
@ -39,7 +40,7 @@ internal partial class CustomizationDrawer
return;
foreach (var actor in _actors.Where(a => a))
Glamourer.Penumbra.RedrawObject(actor.Character, RedrawType.Redraw, false);
Glamourer.Penumbra.RedrawObject(actor.Character, RedrawType.Redraw);
}
private void DrawRaceCombo()
@ -56,7 +57,7 @@ internal partial class CustomizationDrawer
continue;
foreach (var actor in _actors.Where(a => a && a.DrawObject))
Glamourer.Penumbra.RedrawObject(actor.Character, RedrawType.Redraw, false);
Glamourer.Penumbra.RedrawObject(actor.Character, RedrawType.Redraw);
}
}
}

View file

@ -5,6 +5,7 @@ using Glamourer.Customization;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using Penumbra.Api.Enums;
using Penumbra.GameData.Enums;
namespace Glamourer.Gui.Customization;
@ -13,18 +14,18 @@ internal partial class CustomizationDrawer
{
private const string IconSelectorPopup = "Style Picker";
private void DrawIconSelector(CustomizationId id)
private void DrawIconSelector(CustomizeIndex index)
{
using var _ = SetId(id);
using var _ = SetId(index);
using var bigGroup = ImRaii.Group();
var label = _currentOption;
var current = _set.DataByValue(id, _currentByte, out var custom);
var current = _set.DataByValue(index, _currentByte, out var custom, _customize.Face);
if (current < 0)
{
label = $"{_currentOption} (Custom #{_customize[id]})";
label = $"{_currentOption} (Custom #{_customize[index]})";
current = 0;
custom = _set.Data(id, 0);
custom = _set.Data(index, 0);
}
var icon = Glamourer.Customization.GetIcon(custom!.Value.IconId);
@ -35,7 +36,7 @@ internal partial class CustomizationDrawer
ImGui.SameLine();
using (var group = ImRaii.Group())
{
if (_currentId == CustomizationId.Face)
if (_currentIndex == CustomizeIndex.Face)
FaceInputInt(current);
else
DataInputInt(current);
@ -45,7 +46,7 @@ internal partial class CustomizationDrawer
DrawIconPickerPopup();
}
private void UpdateFace(CustomizationData data)
private void UpdateFace(CustomizeData data)
{
// Hrothgar Hack
var value = _set.Race == Race.Hrothgar ? data.Value + 4 : data.Value;
@ -54,7 +55,7 @@ internal partial class CustomizationDrawer
_customize.Face = value;
foreach (var actor in _actors)
Glamourer.Penumbra.RedrawObject(actor.Character, RedrawType.Redraw, false);
Glamourer.Penumbra.RedrawObject(actor.Character, RedrawType.Redraw);
}
private void FaceInputInt(int currentIndex)
@ -64,7 +65,7 @@ internal partial class CustomizationDrawer
if (ImGui.InputInt("##text", ref currentIndex, 1, 1))
{
currentIndex = Math.Clamp(currentIndex - 1, 0, _currentCount - 1);
var data = _set.Data(_currentId, currentIndex, _customize.Face);
var data = _set.Data(_currentIndex, currentIndex, _customize.Face);
UpdateFace(data);
}
@ -81,13 +82,13 @@ internal partial class CustomizationDrawer
.Push(ImGuiStyleVar.FrameRounding, 0);
for (var i = 0; i < _currentCount; ++i)
{
var custom = _set.Data(_currentId, i, _customize.Face);
var custom = _set.Data(_currentIndex, i, _customize.Face);
var icon = Glamourer.Customization.GetIcon(custom.IconId);
using (var _ = ImRaii.Group())
{
if (ImGui.ImageButton(icon.ImGuiHandle, _iconSize))
{
if (_currentId == CustomizationId.Face)
if (_currentIndex == CustomizeIndex.Face)
UpdateFace(custom);
else
UpdateValue(custom.Value);

View file

@ -88,19 +88,8 @@ internal partial class CustomizationDrawer
Functions.IteratePairwise(d._set.Order[CharaMakeParams.MenuType.ColorPicker], d.DrawColorPicker, ImGui.SameLine);
d.Checkbox(d._set.Option(CustomizationId.HighlightsOnFlag), customize.HighlightsOn, b => customize.HighlightsOn = b);
var xPos = d._inputIntSize + d._framedIconSize.X + 3 * ImGui.GetStyle().ItemSpacing.X;
ImGui.SameLine(xPos);
d.Checkbox($"{Glamourer.Customization.GetName(CustomName.Reverse)} {d._set.Option(CustomizationId.FacePaint)}",
customize.FacePaintReversed, b => customize.FacePaintReversed = b);
d.Checkbox($"{Glamourer.Customization.GetName(CustomName.IrisSmall)} {Glamourer.Customization.GetName(CustomName.IrisSize)}",
customize.SmallIris, b => customize.SmallIris = b);
if (customize.Race != Race.Hrothgar)
{
ImGui.SameLine(xPos);
d.Checkbox(d._set.Option(CustomizationId.LipColor), customize.Lipstick, b => customize.Lipstick = b);
}
Functions.IteratePairwise(d._set.Order[CharaMakeParams.MenuType.Checkmark], d.DrawCheckbox,
() => ImGui.SameLine(d._inputIntSize + d._framedIconSize.X + 3 * ImGui.GetStyle().ItemSpacing.X));
}
public static void Draw(Customize customize, IReadOnlyCollection<Actor> actors, bool locked = false)
@ -113,29 +102,29 @@ internal partial class CustomizationDrawer
=> Draw(customize, CharacterEquip.Null, Array.Empty<Actor>(), locked);
// Set state for drawing of current customization.
private CustomizationId _currentId;
private CustomizationByteValue _currentByte = CustomizationByteValue.Zero;
private int _currentCount;
private string _currentOption = string.Empty;
private CustomizeIndex _currentIndex;
private CustomizeValue _currentByte = CustomizeValue.Zero;
private int _currentCount;
private string _currentOption = string.Empty;
// Prepare a new customization option.
private ImRaii.Id SetId(CustomizationId id)
private ImRaii.Id SetId(CustomizeIndex index)
{
_currentId = id;
_currentByte = _customize[id];
_currentCount = _set.Count(id, _customize.Face);
_currentOption = _set.Option(id);
return ImRaii.PushId((int)id);
_currentIndex = index;
_currentByte = _customize[index];
_currentCount = _set.Count(index, _customize.Face);
_currentOption = _set.Option(index);
return ImRaii.PushId((int)index);
}
// Update the current id with a value,
// also update actors if any.
private void UpdateValue(CustomizationByteValue value)
private void UpdateValue(CustomizeValue value)
{
if (_customize[_currentId] == value)
if (_customize[_currentIndex] == value)
return;
_customize[_currentId] = value;
_customize[_currentIndex] = value;
UpdateActors();
}

View file

@ -1,5 +1,4 @@
using System.Linq;
using System.Numerics;
using System.Numerics;
using Glamourer.Customization;
using ImGuiNET;
using OtterGui;
@ -12,9 +11,7 @@ internal partial class CustomizationDrawer
// Only used for facial features, so fixed ID.
private void DrawMultiIconSelector()
{
using var _ = SetId(CustomizationId.FacialFeaturesTattoos);
using var bigGroup = ImRaii.Group();
DrawMultiIcons();
ImGui.SameLine();
using var group = ImRaii.Group();
@ -23,28 +20,30 @@ internal partial class CustomizationDrawer
_currentCount = 256;
PercentageInputInt();
ImGui.TextUnformatted(_set.Option(CustomizationId.FacialFeaturesTattoos));
ImGui.TextUnformatted(_set.Option(CustomizeIndex.LegacyTattoo));
}
private void DrawMultiIcons()
{
using var _ = ImRaii.Group();
for (var i = 0; i < _currentCount; ++i)
var options = _set.Order[CharaMakeParams.MenuType.IconCheckmark];
using var _ = ImRaii.Group();
foreach (var (featureIdx, idx) in options.WithIndex())
{
var enabled = _customize.FacialFeatures[i];
var feature = _set.FacialFeature(_customize.Face, i);
var icon = i == _currentCount - 1
using var id = SetId(featureIdx);
var enabled = _customize.Get(featureIdx) != CustomizeValue.Zero;
var feature = _set.Data(featureIdx, 0, _customize.Face);
var icon = featureIdx == CustomizeIndex.LegacyTattoo
? LegacyTattoo ?? Glamourer.Customization.GetIcon(feature.IconId)
: Glamourer.Customization.GetIcon(feature.IconId);
if (ImGui.ImageButton(icon.ImGuiHandle, _iconSize, Vector2.Zero, Vector2.One, (int)ImGui.GetStyle().FramePadding.X,
Vector4.Zero, enabled ? Vector4.One : RedTint))
{
_customize.FacialFeatures.Set(i, !enabled);
_customize.Set(featureIdx, enabled ? CustomizeValue.Zero : CustomizeValue.Max);
UpdateActors();
}
ImGuiUtil.HoverIconTooltip(icon, _iconSize);
if (i % 4 != 3)
if (idx % 4 != 3)
ImGui.SameLine();
}
}

View file

@ -1,8 +1,8 @@
using System;
using System.Linq;
using System.Security.AccessControl;
using Glamourer.Customization;
using ImGuiNET;
using Newtonsoft.Json.Linq;
using OtterGui;
using OtterGui.Raii;
@ -10,9 +10,9 @@ namespace Glamourer.Gui.Customization;
internal partial class CustomizationDrawer
{
private void DrawListSelector(CustomizationId id)
private void DrawListSelector(CustomizeIndex index)
{
using var _ = SetId(id);
using var _ = SetId(index);
using var bigGroup = ImRaii.Group();
ListCombo();
@ -33,22 +33,22 @@ internal partial class CustomizationDrawer
for (var i = 0; i < _currentCount; ++i)
{
if (ImGui.Selectable($"{_currentOption} #{i + 1}##combo", i == _currentByte.Value))
UpdateValue((CustomizationByteValue)i);
UpdateValue((CustomizeValue)i);
}
}
private void ListInputInt()
{
var tmp = _currentByte.Value + 1;
ImGui.SetNextItemWidth(_inputIntSize);
if (ImGui.InputInt("##text", ref tmp, 1, 1) && tmp > 0 && tmp <= _currentCount)
UpdateValue((CustomizationByteValue)Math.Clamp(tmp - 1, 0, _currentCount - 1));
UpdateValue((CustomizeValue)Math.Clamp(tmp - 1, 0, _currentCount - 1));
ImGuiUtil.HoverTooltip($"Input Range: [1, {_currentCount}]");
}
private void PercentageSelector(CustomizationId id)
private void PercentageSelector(CustomizeIndex index)
{
using var _ = SetId(id);
using var _ = SetId(index);
using var bigGroup = ImRaii.Group();
DrawPercentageSlider();
@ -63,7 +63,7 @@ internal partial class CustomizationDrawer
var tmp = (int)_currentByte.Value;
ImGui.SetNextItemWidth(_comboSelectorSize);
if (ImGui.SliderInt("##slider", ref tmp, 0, _currentCount - 1, "%i", ImGuiSliderFlags.AlwaysClamp))
UpdateValue((CustomizationByteValue)tmp);
UpdateValue((CustomizeValue)tmp);
}
private void PercentageInputInt()
@ -71,7 +71,7 @@ internal partial class CustomizationDrawer
var tmp = (int)_currentByte.Value;
ImGui.SetNextItemWidth(_inputIntSize);
if (ImGui.InputInt("##text", ref tmp, 1, 1))
UpdateValue((CustomizationByteValue)Math.Clamp(tmp, 0, _currentCount - 1));
UpdateValue((CustomizeValue)Math.Clamp(tmp, 0, _currentCount - 1));
ImGuiUtil.HoverTooltip($"Input Range: [0, {_currentCount - 1}]");
}
@ -87,6 +87,14 @@ internal partial class CustomizationDrawer
}
}
// Draw a customize checkbox.
private void DrawCheckbox(CustomizeIndex idx)
{
using var id = SetId(idx);
Checkbox(_set.Option(idx), _customize.Get(idx) != CustomizeValue.Zero,
b => _customize.Set(idx, b ? CustomizeValue.Max : CustomizeValue.Zero));
}
// Integral input for an icon- or color based item.
private void DataInputInt(int currentIndex)
{
@ -95,7 +103,7 @@ internal partial class CustomizationDrawer
if (ImGui.InputInt("##text", ref currentIndex, 1, 1))
{
currentIndex = Math.Clamp(currentIndex - 1, 0, _currentCount - 1);
var data = _set.Data(_currentId, currentIndex, _customize.Face);
var data = _set.Data(_currentIndex, currentIndex, _customize.Face);
UpdateValue(data.Value);
}

View file

@ -6,6 +6,7 @@ using Lumina.Excel.GeneratedSheets;
using Lumina.Text;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
using OtterGui.Widgets;
using Penumbra.GameData;
using Penumbra.GameData.Enums;
@ -141,6 +142,12 @@ public partial class EquipmentDrawer
return Draw(Label, _lastPreview, ref newIdx, ItemComboWidth * ImGuiHelpers.GlobalScale, ImGui.GetTextLineHeight());
}
//protected override bool DrawSelectable(int globalIdx, bool selected)
//{
// using var _ = ImRaii.Group();
//
//}
protected override bool IsVisible(int globalIndex, LowerString filter)
{
var item = Items[globalIndex];

View file

@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
@ -10,6 +12,8 @@ using ImGuiNET;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
using Penumbra.GameData.Enums;
using ImGui = ImGuiNET.ImGui;
namespace Glamourer.Gui;
@ -59,6 +63,7 @@ internal partial class Interface
if (_currentData.Valid)
_currentSave.Update(_currentData.Objects[0]);
RevertButton();
CustomizationDrawer.Draw(_currentSave.Data.Customize, _currentSave.Data.Equipment, _currentData.Objects,
_identifier is Actor.SpecialIdentifier);
@ -68,6 +73,52 @@ internal partial class Interface
private const uint RedHeaderColor = 0xFF1818C0;
private const uint GreenHeaderColor = 0xFF18C018;
private void RevertButton()
{
if (ImGui.Button("Revert"))
{
_manipulations.DeleteSave(_identifier);
foreach (var actor in _currentData.Objects)
_currentSave!.ApplyToActor(actor);
if (_currentData.Objects.Count > 0)
_currentSave = _manipulations.GetOrCreateSave(_currentData.Objects[0]);
_currentSave!.Reset();
}
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 DrawPanelHeader()
{
var color = _currentData.Valid ? GreenHeaderColor : RedHeaderColor;

View file

@ -0,0 +1,51 @@
using System;
using Glamourer.Customization;
using Glamourer.Util;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
namespace Glamourer.Gui;
internal partial class Interface
{
private class DebugDataTab
{
private readonly ICustomizationManager _mg;
public DebugDataTab(ICustomizationManager manager)
=> _mg = manager;
public void Draw()
{
using var tab = ImRaii.TabItem("Debug");
if (!tab)
return;
foreach (var clan in _mg.Clans)
{
foreach (var gender in _mg.Genders)
DrawCustomizationInfo(_mg.GetList(clan, gender));
}
}
public static void DrawCustomizationInfo(CustomizationSet set)
{
if (!ImGui.CollapsingHeader($"{CustomizeExtensions.ClanName(set.Clan, set.Gender)} {set.Gender}"))
return;
using var table = ImRaii.Table("data", 5);
if (!table)
return;
foreach (var index in Enum.GetValues<CustomizeIndex>())
{
ImGuiUtil.DrawTableColumn(index.ToString());
ImGuiUtil.DrawTableColumn(set.Option(index));
ImGuiUtil.DrawTableColumn(set.IsAvailable(index) ? "Available" : "Unavailable");
ImGuiUtil.DrawTableColumn(set.Type(index).ToString());
ImGuiUtil.DrawTableColumn(set.Count(index).ToString());
}
}
}
}

View file

@ -15,6 +15,7 @@ internal partial class Interface : Window, IDisposable
private readonly ActorTab _actorTab;
private readonly DebugStateTab _debugStateTab;
private readonly DebugDataTab _debugDataTab;
public Interface(Glamourer plugin)
: base(GetLabel())
@ -29,6 +30,7 @@ internal partial class Interface : Window, IDisposable
};
_actorTab = new ActorTab(_plugin.CurrentManipulations);
_debugStateTab = new DebugStateTab(_plugin.CurrentManipulations);
_debugDataTab = new DebugDataTab(Glamourer.Customization);
}
public override void Draw()
@ -44,6 +46,7 @@ internal partial class Interface : Window, IDisposable
_actorTab.Draw();
DrawSettingsTab();
_debugStateTab.Draw();
_debugDataTab.Draw();
// DrawSaves();
// DrawFixedDesignsTab();
// DrawRevertablesTab();