mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2026-02-23 07:57:46 +01:00
Add CustomizeParameter data.
This commit is contained in:
parent
bbf460f5e0
commit
9361560350
4 changed files with 406 additions and 0 deletions
38
Glamourer/Gui/Customization/CustomizeParameterDrawData.cs
Normal file
38
Glamourer/Gui/Customization/CustomizeParameterDrawData.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.GameData;
|
||||
using Glamourer.State;
|
||||
|
||||
namespace Glamourer.Gui.Customization;
|
||||
|
||||
public ref struct CustomizeParameterDrawData(CustomizeParameterFlag flag, in DesignData data)
|
||||
{
|
||||
public readonly CustomizeParameterFlag Flag = flag;
|
||||
public bool Locked;
|
||||
public bool DisplayApplication;
|
||||
|
||||
public Action<Vector3> ValueSetter = null!;
|
||||
public Action<bool> ApplySetter = null!;
|
||||
public Vector3 CurrentValue = data.Parameters[flag];
|
||||
public bool CurrentApply;
|
||||
|
||||
public static CustomizeParameterDrawData FromDesign(DesignManager manager, Design design, CustomizeParameterFlag flag)
|
||||
=> new(flag, design.DesignData)
|
||||
{
|
||||
Locked = design.WriteProtected(),
|
||||
DisplayApplication = true,
|
||||
CurrentApply = design.DoApplyParameter(flag),
|
||||
ValueSetter = v => manager.ChangeCustomizeParameter(design, flag, v),
|
||||
ApplySetter = v => manager.ChangeApplyParameter(design, flag, v),
|
||||
};
|
||||
|
||||
public static CustomizeParameterDrawData FromState(StateManager manager, ActorState state, CustomizeParameterFlag flag)
|
||||
=> new(flag, state.ModelData)
|
||||
{
|
||||
Locked = state.IsLocked,
|
||||
DisplayApplication = false,
|
||||
ValueSetter = v => manager.ChangeCustomizeParameter(state, flag, v, StateChanged.Source.Manual),
|
||||
};
|
||||
}
|
||||
96
Glamourer/Gui/Customization/CustomizeParameterDrawer.cs
Normal file
96
Glamourer/Gui/Customization/CustomizeParameterDrawer.cs
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
using Glamourer.Designs;
|
||||
using Glamourer.GameData;
|
||||
using Glamourer.State;
|
||||
using System.Numerics;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using ImGuiNET;
|
||||
using OtterGui.Services;
|
||||
|
||||
namespace Glamourer.Gui.Customization;
|
||||
|
||||
public class CustomizeParameterDrawer(Configuration config) : IService
|
||||
{
|
||||
public void Draw(DesignManager designManager, Design design)
|
||||
{
|
||||
foreach (var flag in CustomizeParameterExtensions.TripleFlags)
|
||||
DrawColorInput(CustomizeParameterDrawData.FromDesign(designManager, design, flag));
|
||||
|
||||
foreach (var flag in CustomizeParameterExtensions.PercentageFlags)
|
||||
DrawPercentageInput(CustomizeParameterDrawData.FromDesign(designManager, design, flag));
|
||||
|
||||
foreach (var flag in CustomizeParameterExtensions.ValueFlags)
|
||||
DrawValueInput(CustomizeParameterDrawData.FromDesign(designManager, design, flag));
|
||||
}
|
||||
|
||||
public void Draw(StateManager stateManager, ActorState state)
|
||||
{
|
||||
foreach (var flag in CustomizeParameterExtensions.TripleFlags)
|
||||
DrawColorInput(CustomizeParameterDrawData.FromState(stateManager, state, flag));
|
||||
|
||||
foreach (var flag in CustomizeParameterExtensions.PercentageFlags)
|
||||
DrawPercentageInput(CustomizeParameterDrawData.FromState(stateManager, state, flag));
|
||||
|
||||
foreach (var flag in CustomizeParameterExtensions.ValueFlags)
|
||||
DrawValueInput(CustomizeParameterDrawData.FromState(stateManager, state, flag));
|
||||
}
|
||||
|
||||
private void DrawColorInput(in CustomizeParameterDrawData data)
|
||||
{
|
||||
using var id = ImRaii.PushId((int)data.Flag);
|
||||
var value = data.CurrentValue;
|
||||
using (_ = ImRaii.Disabled(data.Locked))
|
||||
{
|
||||
if (ImGui.ColorEdit3("##value", ref value, ImGuiColorEditFlags.Float))
|
||||
data.ValueSetter(value);
|
||||
}
|
||||
|
||||
DrawApplyAndLabel(data);
|
||||
}
|
||||
|
||||
private void DrawValueInput(in CustomizeParameterDrawData data)
|
||||
{
|
||||
using var id = ImRaii.PushId((int)data.Flag);
|
||||
var value = data.CurrentValue[0];
|
||||
|
||||
using (_ = ImRaii.Disabled(data.Locked))
|
||||
{
|
||||
if (ImGui.InputFloat("##value", ref value, 0.1f, 0.5f))
|
||||
data.ValueSetter(new Vector3(value));
|
||||
}
|
||||
|
||||
DrawApplyAndLabel(data);
|
||||
}
|
||||
|
||||
private void DrawPercentageInput(in CustomizeParameterDrawData data)
|
||||
{
|
||||
using var id = ImRaii.PushId((int)data.Flag);
|
||||
var value = data.CurrentValue[0] * 100f;
|
||||
|
||||
using (_ = ImRaii.Disabled(data.Locked))
|
||||
{
|
||||
if (ImGui.SliderFloat("##value", ref value, 0, 100, "%.2f", ImGuiSliderFlags.AlwaysClamp))
|
||||
data.ValueSetter(new Vector3(value / 100f));
|
||||
}
|
||||
|
||||
DrawApplyAndLabel(data);
|
||||
}
|
||||
|
||||
private static void DrawApply(in CustomizeParameterDrawData data)
|
||||
{
|
||||
if (UiHelpers.DrawCheckbox("##apply", "Apply this custom parameter when applying the Design.", data.CurrentApply, out var enabled,
|
||||
data.Locked))
|
||||
data.ApplySetter(enabled);
|
||||
}
|
||||
|
||||
private void DrawApplyAndLabel(in CustomizeParameterDrawData data)
|
||||
{
|
||||
if (data.DisplayApplication && !config.HideApplyCheckmarks)
|
||||
{
|
||||
ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X);
|
||||
DrawApply(data);
|
||||
}
|
||||
|
||||
ImGui.SameLine(0, ImGui.GetStyle().ItemInnerSpacing.X);
|
||||
ImGui.TextUnformatted(data.Flag.ToString());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue