mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Extract and group some header drawing logic.
This commit is contained in:
parent
b00e6bd98b
commit
6f34d74752
5 changed files with 132 additions and 78 deletions
|
|
@ -67,27 +67,10 @@ public class ActorPanel
|
||||||
|
|
||||||
private void DrawHeader()
|
private void DrawHeader()
|
||||||
{
|
{
|
||||||
var frameHeight = ImGui.GetFrameHeightWithSpacing();
|
var textColor = !_identifier.IsValid ? ImGui.GetColorU32(ImGuiCol.Text) :
|
||||||
var color = !_identifier.IsValid ? ImGui.GetColorU32(ImGuiCol.Text) :
|
_data.Valid ? ColorId.ActorAvailable.Value() : ColorId.ActorUnavailable.Value();
|
||||||
_data.Valid ? ColorId.ActorAvailable.Value() : ColorId.ActorUnavailable.Value();
|
HeaderDrawer.Draw(_actorName, textColor, ImGui.GetColorU32(ImGuiCol.FrameBg), 0,
|
||||||
var buttonColor = ImGui.GetColorU32(ImGuiCol.FrameBg);
|
HeaderDrawer.Button.IncognitoButton(_selector.IncognitoMode, v => _selector.IncognitoMode = v));
|
||||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
|
|
||||||
.Push(ImGuiStyleVar.FrameRounding, 0);
|
|
||||||
ImGuiUtil.DrawTextButton($"{_actorName}##playerHeader", new Vector2(-frameHeight, ImGui.GetFrameHeight()), buttonColor, color);
|
|
||||||
ImGui.SameLine();
|
|
||||||
style.Push(ImGuiStyleVar.FrameBorderSize, ImGuiHelpers.GlobalScale);
|
|
||||||
using (var c = ImRaii.PushColor(ImGuiCol.Text, ColorId.HeaderButtons.Value())
|
|
||||||
.Push(ImGuiCol.Border, ColorId.HeaderButtons.Value()))
|
|
||||||
{
|
|
||||||
if (ImGuiUtil.DrawDisabledButton(
|
|
||||||
$"{(_selector.IncognitoMode ? FontAwesomeIcon.Eye : FontAwesomeIcon.EyeSlash).ToIconString()}###IncognitoMode",
|
|
||||||
new Vector2(frameHeight, ImGui.GetFrameHeight()), string.Empty, false, true))
|
|
||||||
_selector.IncognitoMode = !_selector.IncognitoMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
var hovered = ImGui.IsItemHovered();
|
|
||||||
if (hovered)
|
|
||||||
ImGui.SetTooltip(_selector.IncognitoMode ? "Toggle incognito mode off." : "Toggle incognito mode on.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private (string, Actor) GetHeaderName()
|
private (string, Actor) GetHeaderName()
|
||||||
|
|
|
||||||
|
|
@ -61,25 +61,8 @@ public class SetPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawHeader()
|
private void DrawHeader()
|
||||||
{
|
=> HeaderDrawer.Draw(_selector.SelectionName, 0, ImGui.GetColorU32(ImGuiCol.FrameBg), 0,
|
||||||
var buttonColor = ImGui.GetColorU32(ImGuiCol.FrameBg);
|
HeaderDrawer.Button.IncognitoButton(_selector.IncognitoMode, v => _selector.IncognitoMode = v));
|
||||||
var frameHeight = ImGui.GetFrameHeightWithSpacing();
|
|
||||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
|
|
||||||
.Push(ImGuiStyleVar.FrameRounding, 0);
|
|
||||||
ImGuiUtil.DrawTextButton(_selector.SelectionName, new Vector2(-frameHeight, ImGui.GetFrameHeight()), buttonColor);
|
|
||||||
ImGui.SameLine();
|
|
||||||
style.Push(ImGuiStyleVar.FrameBorderSize, ImGuiHelpers.GlobalScale);
|
|
||||||
using var color = ImRaii.PushColor(ImGuiCol.Text, ColorId.HeaderButtons.Value())
|
|
||||||
.Push(ImGuiCol.Border, ColorId.HeaderButtons.Value());
|
|
||||||
if (ImGuiUtil.DrawDisabledButton(
|
|
||||||
$"{(_selector.IncognitoMode ? FontAwesomeIcon.Eye : FontAwesomeIcon.EyeSlash).ToIconString()}###IncognitoMode",
|
|
||||||
new Vector2(frameHeight, ImGui.GetFrameHeight()), string.Empty, false, true))
|
|
||||||
_selector.IncognitoMode = !_selector.IncognitoMode;
|
|
||||||
var hovered = ImGui.IsItemHovered();
|
|
||||||
color.Pop(2);
|
|
||||||
if (hovered)
|
|
||||||
ImGui.SetTooltip(_selector.IncognitoMode ? "Toggle incognito mode off." : "Toggle incognito mode on.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawPanel()
|
private void DrawPanel()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -51,43 +51,30 @@ public class DesignPanel
|
||||||
_converter = converter;
|
_converter = converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HeaderDrawer.Button LockButton()
|
||||||
|
=> _selector.Selected == null
|
||||||
|
? HeaderDrawer.Button.Invisible
|
||||||
|
: _selector.Selected.WriteProtected()
|
||||||
|
? new HeaderDrawer.Button
|
||||||
|
{
|
||||||
|
BorderColor = ColorId.HeaderButtons.Value(),
|
||||||
|
TextColor = ColorId.HeaderButtons.Value(),
|
||||||
|
Description = "Make this design editable.",
|
||||||
|
Icon = FontAwesomeIcon.Lock,
|
||||||
|
OnClick = () => _manager.SetWriteProtection(_selector.Selected!, false),
|
||||||
|
}
|
||||||
|
: new HeaderDrawer.Button
|
||||||
|
{
|
||||||
|
BorderColor = ColorId.HeaderButtons.Value(),
|
||||||
|
TextColor = ColorId.HeaderButtons.Value(),
|
||||||
|
Description = "Write-protect this design.",
|
||||||
|
Icon = FontAwesomeIcon.LockOpen,
|
||||||
|
OnClick = () => _manager.SetWriteProtection(_selector.Selected!, true),
|
||||||
|
};
|
||||||
|
|
||||||
private void DrawHeader()
|
private void DrawHeader()
|
||||||
{
|
=> HeaderDrawer.Draw(SelectionName, 0, ImGui.GetColorU32(ImGuiCol.FrameBg), 0, LockButton(),
|
||||||
var selection = _selector.Selected;
|
HeaderDrawer.Button.IncognitoButton(_selector.IncognitoMode, v => _selector.IncognitoMode = v));
|
||||||
var buttonColor = ImGui.GetColorU32(ImGuiCol.FrameBg);
|
|
||||||
var frameHeight = ImGui.GetFrameHeightWithSpacing();
|
|
||||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
|
|
||||||
.Push(ImGuiStyleVar.FrameRounding, 0);
|
|
||||||
ImGuiUtil.DrawTextButton(SelectionName, new Vector2(selection != null ? -2 * frameHeight : -frameHeight, ImGui.GetFrameHeight()),
|
|
||||||
buttonColor);
|
|
||||||
|
|
||||||
ImGui.SameLine();
|
|
||||||
style.Push(ImGuiStyleVar.FrameBorderSize, ImGuiHelpers.GlobalScale);
|
|
||||||
using var color = ImRaii.PushColor(ImGuiCol.Border, ColorId.HeaderButtons.Value())
|
|
||||||
.Push(ImGuiCol.Text, ColorId.HeaderButtons.Value());
|
|
||||||
|
|
||||||
var hoverText = string.Empty;
|
|
||||||
if (selection != null)
|
|
||||||
{
|
|
||||||
if (ImGuiUtil.DrawDisabledButton(
|
|
||||||
$"{(selection.WriteProtected() ? FontAwesomeIcon.LockOpen : FontAwesomeIcon.Lock).ToIconString()}###Locked",
|
|
||||||
new Vector2(frameHeight, ImGui.GetFrameHeight()), string.Empty, false, true))
|
|
||||||
_manager.SetWriteProtection(selection, !selection.WriteProtected());
|
|
||||||
if (ImGui.IsItemHovered())
|
|
||||||
hoverText = selection.WriteProtected() ? "Make this design editable." : "Write-protect this design.";
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui.SameLine();
|
|
||||||
if (ImGuiUtil.DrawDisabledButton(
|
|
||||||
$"{(_selector.IncognitoMode ? FontAwesomeIcon.Eye : FontAwesomeIcon.EyeSlash).ToIconString()}###IncognitoMode",
|
|
||||||
new Vector2(frameHeight, ImGui.GetFrameHeight()), string.Empty, false, true))
|
|
||||||
_selector.IncognitoMode = !_selector.IncognitoMode;
|
|
||||||
if (ImGui.IsItemHovered())
|
|
||||||
hoverText = _selector.IncognitoMode ? "Toggle incognito mode off." : "Toggle incognito mode on.";
|
|
||||||
|
|
||||||
if (hoverText.Length > 0)
|
|
||||||
ImGui.SetTooltip(hoverText);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string SelectionName
|
private string SelectionName
|
||||||
=> _selector.Selected == null ? "No Selection" : _selector.IncognitoMode ? _selector.Selected.Incognito : _selector.Selected.Name.Text;
|
=> _selector.Selected == null ? "No Selection" : _selector.IncognitoMode ? _selector.Selected.Incognito : _selector.Selected.Name.Text;
|
||||||
|
|
@ -178,7 +165,9 @@ public class DesignPanel
|
||||||
{
|
{
|
||||||
var set = _customizationService.AwaitedService.GetList(_selector.Selected!.DesignData.Customize.Clan,
|
var set = _customizationService.AwaitedService.GetList(_selector.Selected!.DesignData.Customize.Clan,
|
||||||
_selector.Selected!.DesignData.Customize.Gender);
|
_selector.Selected!.DesignData.Customize.Gender);
|
||||||
var all = CustomizationExtensions.All.Where(set.IsAvailable).Select(c => c.ToFlag()).Aggregate((a, b) => a | b) | CustomizeFlag.Clan | CustomizeFlag.Gender;
|
var all = CustomizationExtensions.All.Where(set.IsAvailable).Select(c => c.ToFlag()).Aggregate((a, b) => a | b)
|
||||||
|
| CustomizeFlag.Clan
|
||||||
|
| CustomizeFlag.Gender;
|
||||||
var flags = (_selector.Selected!.ApplyCustomize & all) == 0 ? 0 : (_selector.Selected!.ApplyCustomize & all) == all ? 3 : 1;
|
var flags = (_selector.Selected!.ApplyCustomize & all) == 0 ? 0 : (_selector.Selected!.ApplyCustomize & all) == all ? 3 : 1;
|
||||||
if (ImGui.CheckboxFlags("Apply All Customizations", ref flags, 3))
|
if (ImGui.CheckboxFlags("Apply All Customizations", ref flags, 3))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
100
Glamourer/Gui/Tabs/HeaderDrawer.cs
Normal file
100
Glamourer/Gui/Tabs/HeaderDrawer.cs
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
using Dalamud.Interface;
|
||||||
|
using ImGuiNET;
|
||||||
|
using OtterGui;
|
||||||
|
using OtterGui.Raii;
|
||||||
|
|
||||||
|
namespace Glamourer.Gui.Tabs;
|
||||||
|
|
||||||
|
public static class HeaderDrawer
|
||||||
|
{
|
||||||
|
public struct Button
|
||||||
|
{
|
||||||
|
public static readonly Button Invisible = new()
|
||||||
|
{
|
||||||
|
Visible = false,
|
||||||
|
Width = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
public Action? OnClick;
|
||||||
|
public string Description = string.Empty;
|
||||||
|
public float Width;
|
||||||
|
public uint BorderColor;
|
||||||
|
public uint TextColor;
|
||||||
|
public FontAwesomeIcon Icon;
|
||||||
|
public bool Disabled;
|
||||||
|
public bool Visible;
|
||||||
|
|
||||||
|
public Button()
|
||||||
|
{
|
||||||
|
Visible = true;
|
||||||
|
Width = ImGui.GetFrameHeightWithSpacing();
|
||||||
|
Disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly void Draw()
|
||||||
|
{
|
||||||
|
if (!Visible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
using var color = ImRaii.PushColor(ImGuiCol.Border, BorderColor)
|
||||||
|
.Push(ImGuiCol.Text, TextColor, TextColor != 0);
|
||||||
|
if (ImGuiUtil.DrawDisabledButton(Icon.ToIconString(), new Vector2(Width, ImGui.GetFrameHeight()), Description, Disabled, true))
|
||||||
|
OnClick?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Button IncognitoButton(bool current, Action<bool> setter)
|
||||||
|
=> current
|
||||||
|
? new Button
|
||||||
|
{
|
||||||
|
BorderColor = ColorId.HeaderButtons.Value(),
|
||||||
|
TextColor = ColorId.HeaderButtons.Value(),
|
||||||
|
Description = "Toggle incognito mode off.",
|
||||||
|
Icon = FontAwesomeIcon.EyeSlash,
|
||||||
|
OnClick = () => setter(false),
|
||||||
|
}
|
||||||
|
: new Button
|
||||||
|
{
|
||||||
|
BorderColor = ColorId.HeaderButtons.Value(),
|
||||||
|
TextColor = ColorId.HeaderButtons.Value(),
|
||||||
|
Description = "Toggle incognito mode on.",
|
||||||
|
Icon = FontAwesomeIcon.Eye,
|
||||||
|
OnClick = () => setter(true),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Draw(string text, uint textColor, uint frameColor, int leftButtons, params Button[] buttons)
|
||||||
|
{
|
||||||
|
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, Vector2.Zero)
|
||||||
|
.Push(ImGuiStyleVar.FrameRounding, 0)
|
||||||
|
.Push(ImGuiStyleVar.FrameBorderSize, ImGuiHelpers.GlobalScale);
|
||||||
|
|
||||||
|
var leftButtonSize = 0f;
|
||||||
|
foreach (var button in buttons.Take(leftButtons).Where(b => b.Visible))
|
||||||
|
{
|
||||||
|
button.Draw();
|
||||||
|
ImGui.SameLine();
|
||||||
|
leftButtonSize += button.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rightButtonSize = buttons.Length > leftButtons ? buttons.Skip(leftButtons).Where(b => b.Visible).Select(b => b.Width).Sum() : 0f;
|
||||||
|
var midSize = ImGui.GetContentRegionAvail().X - rightButtonSize - ImGuiHelpers.GlobalScale;
|
||||||
|
|
||||||
|
style.Pop();
|
||||||
|
style.Push(ImGuiStyleVar.ButtonTextAlign, new Vector2(0.5f + (rightButtonSize - leftButtonSize) / 2 / midSize, 0.5f));
|
||||||
|
if (textColor != 0)
|
||||||
|
ImGuiUtil.DrawTextButton(text, new Vector2(midSize, ImGui.GetFrameHeight()), frameColor, textColor);
|
||||||
|
else
|
||||||
|
ImGuiUtil.DrawTextButton(text, new Vector2(midSize, ImGui.GetFrameHeight()), frameColor);
|
||||||
|
style.Pop();
|
||||||
|
style.Push(ImGuiStyleVar.FrameBorderSize, ImGuiHelpers.GlobalScale);
|
||||||
|
|
||||||
|
foreach (var button in buttons.Skip(leftButtons).Where(b => b.Visible))
|
||||||
|
{
|
||||||
|
ImGui.SameLine();
|
||||||
|
button.Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using Glamourer.Gui.Tabs.DesignTab;
|
using Glamourer.Gui.Tabs.DesignTab;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue