From 6a76b259bb16246b3104a3ce8182e010aec354e7 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Thu, 9 May 2024 01:08:01 +0200 Subject: [PATCH] Add chat message when turn in is finished --- Deliveroo/Configuration.cs | 1 + Deliveroo/Deliveroo.csproj | 2 +- Deliveroo/DeliverooPlugin.cs | 76 ++++++++++++++++++++++------- Deliveroo/DeliveryResult.cs | 9 ++++ Deliveroo/Handlers/SupplyHandler.cs | 19 ++++---- Deliveroo/Windows/ConfigWindow.cs | 16 ++++++ 6 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 Deliveroo/DeliveryResult.cs diff --git a/Deliveroo/Configuration.cs b/Deliveroo/Configuration.cs index 1a680f2..39e22dd 100644 --- a/Deliveroo/Configuration.cs +++ b/Deliveroo/Configuration.cs @@ -15,6 +15,7 @@ internal sealed class Configuration : IPluginConfiguration public int ReservedSealCount { get; set; } public bool ReserveDifferentSealCountAtMaxRank { get; set; } public int ReservedSealCountAtMaxRank { get; set; } + public XivChatType ChatType { get; set; } = XivChatType.Debug; public int PauseAtRank { get; set; } public EBehaviorOnOtherWorld BehaviorOnOtherWorld { get; set; } = EBehaviorOnOtherWorld.Warning; public bool DisableFrameLimiter { get; set; } = true; diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 827b45b..33c3e24 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,7 +1,7 @@ net8.0-windows - 4.6 + 4.7 12 enable true diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index 7cb063c..0274276 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -82,7 +82,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin var itemCache = new ItemCache(dataManager); _exchangeHandler = new ExchangeHandler(this, _gameFunctions, targetManager, _gameGui, _chatGui, _pluginLog); - _supplyHandler = new SupplyHandler(this, _gameFunctions, targetManager, _gameGui, _chatGui, itemCache, + _supplyHandler = new SupplyHandler(this, _gameFunctions, targetManager, _gameGui, itemCache, _pluginLog); _configWindow = new ConfigWindow(_pluginInterface, this, _configuration, _gcRewardsCache, _clientState, @@ -132,7 +132,12 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin { _turnInWindow.State = false; _pluginLog.Information($"Pausing GC delivery, FC reached rank {rank}"); - _chatGui.Print($"Pausing Deliveroo, your FC reached rank {rank}."); + DeliveryResult = new DeliveryResult + { + Message = new SeStringBuilder() + .Append($"Pausing Deliveroo, your FC reached rank {rank}.") + .Build(), + }; return; } } @@ -155,8 +160,9 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin } internal DateTime ContinueAt { private get; set; } = DateTime.MinValue; - internal List ItemsToPurchaseNow { get; set; } = new(); + internal List ItemsToPurchaseNow { get; private set; } = new(); internal int LastTurnInListSize { get; set; } = int.MaxValue; + internal DeliveryResult? DeliveryResult { get; set; } internal bool TurnInState { @@ -234,11 +240,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin { _turnInWindow.IsOpen = false; _turnInWindow.State = false; - if (CurrentStage != Stage.Stopped) - { - _externalPluginHandler.Restore(); - CurrentStage = Stage.Stopped; - } + StopTurnIn(); } else if (DateTime.Now > ContinueAt) { @@ -247,18 +249,14 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin if (!_turnInWindow.State) { - if (CurrentStage != Stage.Stopped) - { - _externalPluginHandler.Restore(); - CurrentStage = Stage.Stopped; - } - + StopTurnIn(); return; } else if (_turnInWindow.State && CurrentStage == Stage.Stopped) { CurrentStage = Stage.TargetPersonnelOfficer; ItemsToPurchaseNow = _turnInWindow.SelectedItems; + DeliveryResult = new(); _supplyHandler.ResetTurnInErrorHandling(); if (ItemsToPurchaseNow.Count > 0) { @@ -351,10 +349,9 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin break; case Stage.RequestStop: - _externalPluginHandler.Restore(); - CurrentStage = Stage.Stopped; - + StopTurnIn(); break; + case Stage.Stopped: break; @@ -365,6 +362,51 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin } } + private void StopTurnIn() + { + if (CurrentStage != Stage.Stopped) + { + _externalPluginHandler.Restore(); + CurrentStage = Stage.Stopped; + + var text = DeliveryResult?.Message ?? "Delivery completed."; + var message = _configuration.ChatType switch + { + XivChatType.Say + or XivChatType.Shout + or XivChatType.TellOutgoing + or XivChatType.TellIncoming + or XivChatType.Party + or XivChatType.Alliance + or (>= XivChatType.Ls1 and <= XivChatType.Ls8) + or XivChatType.FreeCompany + or XivChatType.NoviceNetwork + or XivChatType.Yell + or XivChatType.CrossParty + or XivChatType.PvPTeam + or XivChatType.CrossLinkShell1 + or XivChatType.NPCDialogue + or XivChatType.NPCDialogueAnnouncements + or (>= XivChatType.CrossLinkShell2 and <= XivChatType.CrossLinkShell8) + => new XivChatEntry + { + Message = text, + Type = _configuration.ChatType, + Name = new SeStringBuilder().AddUiForeground("Deliveroo", 52).Build(), + }, + _ => new XivChatEntry + { + Message = new SeStringBuilder().AddUiForeground("[Deliveroo] ", 52) + .Append(text) + .Build(), + Type = _configuration.ChatType, + } + }; + _chatGui.Print(message); + + DeliveryResult = null; + } + } public void Dispose() { diff --git a/Deliveroo/DeliveryResult.cs b/Deliveroo/DeliveryResult.cs new file mode 100644 index 0000000..79af2a0 --- /dev/null +++ b/Deliveroo/DeliveryResult.cs @@ -0,0 +1,9 @@ +using Dalamud.Game.Text.SeStringHandling; + +namespace Deliveroo +{ + internal sealed class DeliveryResult + { + public SeString? Message { get; init; } + } +} diff --git a/Deliveroo/Handlers/SupplyHandler.cs b/Deliveroo/Handlers/SupplyHandler.cs index c8e43ab..6cd8892 100644 --- a/Deliveroo/Handlers/SupplyHandler.cs +++ b/Deliveroo/Handlers/SupplyHandler.cs @@ -9,11 +9,10 @@ using Deliveroo.GameData; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Component.GUI; -using LLib; using LLib.GameUI; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; -namespace Deliveroo; +namespace Deliveroo.Handlers; internal sealed class SupplyHandler { @@ -21,20 +20,18 @@ internal sealed class SupplyHandler private readonly GameFunctions _gameFunctions; private readonly ITargetManager _targetManager; private readonly IGameGui _gameGui; - private readonly IChatGui _chatGui; private readonly ItemCache _itemCache; private readonly IPluginLog _pluginLog; private uint _turnInErrors; public SupplyHandler(DeliverooPlugin plugin, GameFunctions gameFunctions, ITargetManager targetManager, - IGameGui gameGui, IChatGui chatGui, ItemCache itemCache, IPluginLog pluginLog) + IGameGui gameGui, ItemCache itemCache, IPluginLog pluginLog) { _plugin = plugin; _gameFunctions = gameFunctions; _targetManager = targetManager; _gameGui = gameGui; - _chatGui = chatGui; _itemCache = itemCache; _pluginLog = pluginLog; } @@ -210,10 +207,14 @@ internal sealed class SupplyHandler if (itemName != null && _itemCache.GetItemIdFromItemName(itemName) .Any(itemId => InternalConfiguration.QuickVentureExclusiveItems.Contains(itemId))) { - _chatGui.Print(new SeStringBuilder().Append("Won't turn in ") - .AddItemLink(_itemCache.GetItemIdFromItemName(itemName).First()) - .Append(", as it can only be obtained through Quick Ventures.") - .Build()); + _plugin.DeliveryResult = new DeliveryResult + { + Message = new SeStringBuilder() + .Append("Won't turn in ") + .AddItemLink(_itemCache.GetItemIdFromItemName(itemName).First()) + .Append(", as it can only be obtained through Quick Ventures.") + .Build(), + }; addonSupplyReward->AtkUnitBase.FireCallbackInt(1); _plugin.CurrentStage = Stage.CloseGcSupplyWindowThenStop; diff --git a/Deliveroo/Windows/ConfigWindow.cs b/Deliveroo/Windows/ConfigWindow.cs index a936f9a..8722d58 100644 --- a/Deliveroo/Windows/ConfigWindow.cs +++ b/Deliveroo/Windows/ConfigWindow.cs @@ -9,6 +9,7 @@ using Dalamud.Interface.Internal; using Dalamud.Interface.Utility; using Dalamud.Plugin; using Dalamud.Plugin.Services; +using Dalamud.Utility; using Deliveroo.GameData; using ImGuiNET; using LLib; @@ -359,6 +360,21 @@ internal sealed class ConfigWindow : LWindow ImGui.EndDisabled(); + ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 120); + var xivChatTypes = Enum.GetValues() + .Where(x => x != XivChatType.StandardEmote) + .ToArray(); + var selectedChatType = Array.IndexOf(xivChatTypes, _configuration.ChatType); + string[] chatTypeNames = xivChatTypes + .Select(t => t.GetAttribute()?.FancyName ?? t.ToString()) + .ToArray(); + if (ImGui.Combo("Chat channel for status updates", ref selectedChatType, chatTypeNames, + chatTypeNames.Length)) + { + _configuration.ChatType = xivChatTypes[selectedChatType]; + Save(); + } + ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 120); List<(int Rank, string Name)> rankUpComboValues = Enumerable.Range(1, 30) .Select(x => x == 1 ? (0, "---") : (x, $"Rank {x}"))