mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Add color preview for dye template selection.
This commit is contained in:
parent
7e8cd719fd
commit
c88f1a7b1c
2 changed files with 52 additions and 5 deletions
|
|
@ -1,5 +1,8 @@
|
|||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using ImGuiNET;
|
||||
using OtterGui.Widgets;
|
||||
using Penumbra.GameData.Data;
|
||||
using Penumbra.GameData.Files;
|
||||
|
|
@ -11,9 +14,54 @@ public class StainService : IDisposable
|
|||
{
|
||||
public sealed class StainTemplateCombo : FilterComboCache<ushort>
|
||||
{
|
||||
public StainTemplateCombo(IEnumerable<ushort> items)
|
||||
: base(items, Penumbra.Log)
|
||||
{ }
|
||||
private readonly StmFile _stmFile;
|
||||
private readonly FilterComboColors _stainCombo;
|
||||
|
||||
private float _rightOffset;
|
||||
|
||||
public StainTemplateCombo(FilterComboColors stainCombo, StmFile stmFile)
|
||||
: base(stmFile.Entries.Keys.Prepend((ushort)0), Penumbra.Log)
|
||||
{
|
||||
_stainCombo = stainCombo;
|
||||
_stmFile = stmFile;
|
||||
}
|
||||
|
||||
protected override float GetFilterWidth()
|
||||
{
|
||||
using var font = ImRaii.PushFont(UiBuilder.MonoFont);
|
||||
var baseSize = ImGui.CalcTextSize("0000").X + ImGui.GetStyle().ScrollbarSize + ImGui.GetStyle().ItemInnerSpacing.X;
|
||||
if (_stainCombo.CurrentSelection.Key == 0)
|
||||
return baseSize;
|
||||
return baseSize + ImGui.GetTextLineHeight() * 3 + ImGui.GetStyle().ItemInnerSpacing.X * 3;
|
||||
}
|
||||
|
||||
protected override string ToString(ushort obj)
|
||||
=> $"{obj,4}";
|
||||
|
||||
protected override void DrawList(float width, float itemHeight)
|
||||
{
|
||||
using var font = ImRaii.PushFont(UiBuilder.MonoFont);
|
||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing,
|
||||
ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemInnerSpacing.X });
|
||||
base.DrawList(width, itemHeight);
|
||||
}
|
||||
|
||||
protected override bool DrawSelectable(int globalIdx, bool selected)
|
||||
{
|
||||
var ret = base.DrawSelectable(globalIdx, selected);
|
||||
var selection = _stainCombo.CurrentSelection.Key;
|
||||
if (selection == 0 || !_stmFile.TryGetValue(Items[globalIdx], selection, out var colors))
|
||||
return ret;
|
||||
|
||||
ImGui.SameLine();
|
||||
var frame = new Vector2(ImGui.GetTextLineHeight());
|
||||
ImGui.ColorButton("D", new Vector4(colors.Diffuse, 1), 0, frame);
|
||||
ImGui.SameLine();
|
||||
ImGui.ColorButton("E", new Vector4(colors.Emissive, 1), 0, frame);
|
||||
ImGui.SameLine();
|
||||
ImGui.ColorButton("S", new Vector4(colors.Specular, 1), 0, frame);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly StainData StainData;
|
||||
|
|
@ -29,7 +77,7 @@ public class StainService : IDisposable
|
|||
() => StainData.Data.Prepend(new KeyValuePair<byte, (string Name, uint Dye, bool Gloss)>(0, ("None", 0, false))).ToList(),
|
||||
Penumbra.Log);
|
||||
StmFile = new StmFile(dataManager);
|
||||
TemplateCombo = new StainTemplateCombo(StmFile.Entries.Keys.Prepend((ushort)0));
|
||||
TemplateCombo = new StainTemplateCombo(StainCombo, StmFile);
|
||||
Penumbra.Log.Verbose($"[{nameof(StainService)}] Created.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
|
||||
using ImGuiNET;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OtterGui;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue