--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using Dalamud.Interface;
+using Dalamud.Interface.Components;
+using Dalamud.Plugin;
+using Humanizer;
+using Humanizer.Localisation;
+using ImGuiNET;
+using Questionable.Controller;
+using Questionable.Data;
+using Questionable.Functions;
+using Questionable.Model;
+using Questionable.Model.Questing;
+
+namespace Questionable.Windows.QuestComponents;
+
+internal sealed class EventInfoComponent
+{
+ private readonly List<EventQuest> _eventQuests =
+ [
+ new EventQuest("Moonfire Faire", [new(5182), new(5183)],
+ new DateTime(new DateOnly(2024, 8, 26), new TimeOnly(14, 59), DateTimeKind.Utc)),
+ ];
+
+ private readonly QuestData _questData;
+ private readonly QuestRegistry _questRegistry;
+ private readonly QuestFunctions _questFunctions;
+ private readonly UiUtils _uiUtils;
+ private readonly QuestController _questController;
+ private readonly QuestTooltipComponent _questTooltipComponent;
+ private readonly Configuration _configuration;
+ private readonly IDalamudPluginInterface _pluginInterface;
+
+ public EventInfoComponent(QuestData questData, QuestRegistry questRegistry, QuestFunctions questFunctions,
+ UiUtils uiUtils, QuestController questController, QuestTooltipComponent questTooltipComponent,
+ Configuration configuration, IDalamudPluginInterface pluginInterface)
+ {
+ _questData = questData;
+ _questRegistry = questRegistry;
+ _questFunctions = questFunctions;
+ _uiUtils = uiUtils;
+ _questController = questController;
+ _questTooltipComponent = questTooltipComponent;
+ _configuration = configuration;
+ _pluginInterface = pluginInterface;
+ }
+
+ public bool ShouldDraw => _configuration.General.ShowIncompleteSeasonalEvents && _eventQuests.Any(IsIncomplete);
+
+ public void Draw()
+ {
+ foreach (var eventQuest in _eventQuests)
+ {
+ if (IsIncomplete(eventQuest))
+ DrawEventQuest(eventQuest);
+ }
+ }
+
+ private void DrawEventQuest(EventQuest eventQuest)
+ {
+ string time = (eventQuest.EndsAtUtc - DateTime.UtcNow).Humanize(
+ precision: 1,
+ culture: CultureInfo.InvariantCulture,
+ minUnit: TimeUnit.Minute,
+ maxUnit: TimeUnit.Day);
+ ImGui.Text($"{eventQuest.Name} ({time})");
+
+ float width;
+ using (var _ = _pluginInterface.UiBuilder.IconFontHandle.Push())
+ width = ImGui.CalcTextSize(FontAwesomeIcon.Play.ToIconString()).X + ImGui.GetStyle().FramePadding.X;
+
+ using (var _ = _pluginInterface.UiBuilder.IconFontFixedWidthHandle.Push())
+ width -= ImGui.CalcTextSize(FontAwesomeIcon.Check.ToIconString()).X;
+
+ List<QuestId> startableQuests = eventQuest.QuestIds.Where(x =>
+ _questRegistry.IsKnownQuest(x) &&
+ _questFunctions.IsReadyToAcceptQuest(x) &&
+ x != _questController.StartedQuest?.Quest.Id &&
+ x != _questController.NextQuest?.Quest.Id)
+ .ToList();
+ if (startableQuests.Count == 0)
+ width = 0;
+
+ foreach (var questId in eventQuest.QuestIds)
+ {
+ if (_questFunctions.IsQuestComplete(questId))
+ continue;
+
+ string questName = _questData.GetQuestInfo(questId).Name;
+ if (startableQuests.Contains(questId) &&
+ _questRegistry.TryGetQuest(questId, out Quest? quest))
+ {
+ ImGuiComponents.IconButton(FontAwesomeIcon.Play);
+ if (ImGui.IsItemClicked())
+ {
+ _questController.SetNextQuest(quest);
+ _questController.Start("SeasonalEventSelection");
+ }
+
+ bool hovered = ImGui.IsItemHovered();
+
+ ImGui.SameLine();
+ ImGui.AlignTextToFramePadding();
+ ImGui.Text(questName);
+ hovered |= ImGui.IsItemHovered();
+
+ if (hovered)
+ _questTooltipComponent.Draw(quest.Info);
+ }
+ else
+ {
+ if (width > 0)
+ ImGui.SetCursorPosX(ImGui.GetCursorPosX() + width);
+
+ var style = _uiUtils.GetQuestStyle(questId);
+ if (_uiUtils.ChecklistItem(questName, style.Color, style.Icon, ImGui.GetStyle().FramePadding.X))
+ _questTooltipComponent.Draw(_questData.GetQuestInfo(questId));
+ }
+ }
+ }
+
+ private bool IsIncomplete(EventQuest eventQuest)
+ {
+ if (eventQuest.EndsAtUtc <= DateTime.UtcNow)
+ return false;
+
+ return !eventQuest.QuestIds.All(x => _questFunctions.IsQuestComplete(x));
+ }
+
+ private sealed record EventQuest(string Name, List<QuestId> QuestIds, DateTime EndsAtUtc);
+}
private readonly ActiveQuestComponent _activeQuestComponent;
private readonly ARealmRebornComponent _aRealmRebornComponent;
private readonly CreationUtilsComponent _creationUtilsComponent;
+ private readonly EventInfoComponent _eventInfoComponent;
private readonly QuickAccessButtonsComponent _quickAccessButtonsComponent;
private readonly RemainingTasksComponent _remainingTasksComponent;
private readonly IFramework _framework;
TerritoryData territoryData,
ActiveQuestComponent activeQuestComponent,
ARealmRebornComponent aRealmRebornComponent,
+ EventInfoComponent eventInfoComponent,
CreationUtilsComponent creationUtilsComponent,
QuickAccessButtonsComponent quickAccessButtonsComponent,
RemainingTasksComponent remainingTasksComponent,
_territoryData = territoryData;
_activeQuestComponent = activeQuestComponent;
_aRealmRebornComponent = aRealmRebornComponent;
+ _eventInfoComponent = eventInfoComponent;
_creationUtilsComponent = creationUtilsComponent;
_quickAccessButtonsComponent = quickAccessButtonsComponent;
_remainingTasksComponent = remainingTasksComponent;
ImGui.Separator();
}
+ if (_eventInfoComponent.ShouldDraw)
+ {
+ _eventInfoComponent.Draw();
+ ImGui.Separator();
+ }
+
_creationUtilsComponent.Draw();
ImGui.Separator();
_pluginInterface = pluginInterface;
}
- public (Vector4 color, FontAwesomeIcon icon, string status) GetQuestStyle(ElementId elementId)
+ public (Vector4 Color, FontAwesomeIcon Icon, string Status) GetQuestStyle(ElementId elementId)
{
if (_questFunctions.IsQuestAccepted(elementId))
return (ImGuiColors.DalamudYellow, FontAwesomeIcon.PersonWalkingArrowRight, "Active");
return (ImGuiColors.DalamudRed, FontAwesomeIcon.Times);
}
- public bool ChecklistItem(string text, Vector4 color, FontAwesomeIcon icon)
+ public bool ChecklistItem(string text, Vector4 color, FontAwesomeIcon icon, float extraPadding = 0)
{
// ReSharper disable once UnusedVariable
using (var font = _pluginInterface.UiBuilder.IconFontFixedWidthHandle.Push())
bool hover = ImGui.IsItemHovered();
ImGui.SameLine();
+ if (extraPadding > 0)
+ ImGui.SetCursorPosX(ImGui.GetCursorPosX() + extraPadding);
ImGui.TextUnformatted(text);
return hover;
}