1
0
Fork 0
forked from aly/qstbak
qstbak/Questionable/Questionable.Windows.JournalComponents/JournalUiShared.cs
2026-08-17 20:29:32 +10:00

65 lines
2.3 KiB
C#

using System;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility.Raii;
using Questionable.Controller.Utils;
namespace Questionable.Windows.JournalComponents;
internal static class JournalUiShared
{
public static void DrawAllowanceHeader(int used, int limit, string unit, TimeSpan untilReset, string? tooltip = null)
{
int num = limit - used;
float fraction = ((limit > 0) ? ((float)num / (float)limit) : 0f);
string text = ExpiryUtils.FormatTimeSpan(untilReset);
Vector4 col = ((num > 0) ? UiThemeUtils.StatusComplete : UiThemeUtils.StatusLocked);
ImU8String text2 = new ImU8String(0, 1);
text2.AppendFormatted(num);
ImGui.TextColored(in col, text2);
ImGui.SameLine(0f, 4f);
ImU8String text3 = new ImU8String(13, 2);
text3.AppendLiteral("/ ");
text3.AppendFormatted(limit);
text3.AppendLiteral(" ");
text3.AppendFormatted(unit);
text3.AppendLiteral(" remaining");
ImGui.TextColored(in UiThemeUtils.MutedTextColor, text3);
string text4 = "Resets in " + text;
float y = ImGui.GetContentRegionMax().X - ImGui.CalcTextSize(text4).X;
ImGui.SameLine(0f, 0f);
ImGui.SameLine(MathF.Max(ImGui.GetCursorPosX() + ImGui.GetStyle().ItemSpacing.X, y));
ImGui.TextColored(in UiThemeUtils.DimTextColor, text4);
ImGui.Spacing();
using (UiThemeUtils.PushProgressBarColors())
{
Vector2 sizeArg = new Vector2(-1E-45f, 0f);
ImU8String overlay = new ImU8String(3, 2);
overlay.AppendFormatted(num);
overlay.AppendLiteral(" / ");
overlay.AppendFormatted(limit);
ImGui.ProgressBar(fraction, sizeArg, overlay);
}
if (tooltip != null && ImGui.IsItemHovered())
{
using ImRaii.TooltipDisposable tooltipDisposable = ImRaii.Tooltip();
if (tooltipDisposable.Alive)
{
DateTime value = (DateTime.UtcNow + untilReset).ToLocalTime();
ImGui.TextUnformatted(tooltip);
ImGui.Spacing();
ImGui.Separator();
ImGui.Spacing();
ImU8String text5 = new ImU8String(12, 1);
text5.AppendLiteral("Next reset: ");
text5.AppendFormatted(value, "g");
ImGui.TextColored(in UiThemeUtils.DimTextColor, text5);
ImU8String text6 = new ImU8String(18, 1);
text6.AppendLiteral("Time until reset: ");
text6.AppendFormatted(text);
ImGui.TextColored(in UiThemeUtils.DimTextColor, text6);
}
}
ImGui.Spacing();
}
}