qstbak/Questionable/Questionable.Windows.QuestComponents/NavigationBarComponent.cs
2026-08-17 20:29:32 +10:00

110 lines
3.7 KiB
C#

using System;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Utility.Raii;
namespace Questionable.Windows.QuestComponents;
internal sealed class NavigationBarComponent
{
private readonly ConfigWindow _configWindow;
private readonly JournalProgressWindow _journalProgressWindow;
private readonly SeasonalDutySelectionWindow _seasonalDutySelectionWindow;
private readonly FateSelectionWindow _fateSelectionWindow;
private readonly ChangelogWindow _changelogWindow;
public NavigationBarComponent(ConfigWindow configWindow, JournalProgressWindow journalProgressWindow, SeasonalDutySelectionWindow seasonalDutySelectionWindow, FateSelectionWindow fateSelectionWindow, ChangelogWindow changelogWindow)
{
_configWindow = configWindow;
_journalProgressWindow = journalProgressWindow;
_seasonalDutySelectionWindow = seasonalDutySelectionWindow;
_fateSelectionWindow = fateSelectionWindow;
_changelogWindow = changelogWindow;
}
public void Draw()
{
float x = ImGui.GetContentRegionAvail().X;
float x2 = ImGui.GetStyle().ItemSpacing.X;
float width = (x - 4f * x2) / 5f;
NavButton(FontAwesomeIcon.Cog, "Settings", delegate
{
_configWindow.IsOpenAndUncollapsed = true;
}, width, active: true);
ImGui.SameLine();
NavButton(FontAwesomeIcon.Book, "Journal Progress", delegate
{
_journalProgressWindow.IsOpenAndUncollapsed = true;
}, width);
ImGui.SameLine();
NavButton(FontAwesomeIcon.Shield, "Seasonal Duty Farming", delegate
{
_seasonalDutySelectionWindow.IsOpenAndUncollapsed = true;
}, width);
ImGui.SameLine();
NavButton(FontAwesomeIcon.Calendar, "FATE Farming", delegate
{
_fateSelectionWindow.IsOpenAndUncollapsed = true;
}, width);
ImGui.SameLine();
NavButton(FontAwesomeIcon.FileAlt, "What's New", delegate
{
_changelogWindow.IsOpenAndUncollapsed = true;
}, width);
}
private static void NavButton(FontAwesomeIcon icon, string tooltip, Action onClick, float width, bool active = false)
{
using ImRaii.ColorDisposable colorDisposable = new ImRaii.ColorDisposable();
if (active)
{
Vector4 accentColor = UiThemeUtils.AccentColor;
accentColor.W = 0.12f;
colorDisposable.Push(ImGuiCol.Button, accentColor);
accentColor = UiThemeUtils.AccentColor;
accentColor.W = 0.2f;
colorDisposable.Push(ImGuiCol.ButtonHovered, accentColor);
accentColor = UiThemeUtils.AccentColor;
accentColor.W = 0.25f;
colorDisposable.Push(ImGuiCol.ButtonActive, accentColor);
colorDisposable.Push(ImGuiCol.Text, UiThemeUtils.AccentColor);
}
float frameHeight = ImGui.GetFrameHeight();
Vector2 cursorScreenPos = ImGui.GetCursorScreenPos();
ImU8String label = new ImU8String(2, 1);
label.AppendLiteral("##");
label.AppendFormatted(tooltip);
if (ImGui.Button(label, new Vector2(width, frameHeight)))
{
onClick();
}
string text = icon.ToIconString();
Vector2 vector;
using (ImRaii.PushFont(UiBuilder.IconFont))
{
vector = ImGui.CalcTextSize(text);
}
ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList();
uint colorU = ImGui.GetColorU32(ImGuiCol.Text);
float x = cursorScreenPos.X + (width - vector.X) / 2f;
float y = cursorScreenPos.Y + (frameHeight - vector.Y) / 2f;
windowDrawList.AddText(UiBuilder.IconFont, ImGui.GetFontSize(), new Vector2(x, y), colorU, text);
if (active)
{
Vector2 itemRectMin = ImGui.GetItemRectMin();
Vector2 itemRectMax = ImGui.GetItemRectMax();
Vector4 accentColor = UiThemeUtils.AccentColor;
accentColor.W = 0.35f;
windowDrawList.AddRect(itemRectMin, itemRectMax, ImGui.ColorConvertFloat4ToU32(accentColor), 4f, ImDrawFlags.RoundCornersAll, 1f);
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(tooltip);
}
}
}