From 87cb90ec8ac5da8f6f4728113bbd25017c128b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Mon, 3 Jul 2023 14:06:13 +0800 Subject: [PATCH] fix: add downloading failed warning. --- RotationSolver/Helpers/RotationHelper.cs | 5 +- RotationSolver/Helpers/RotationLoadContext.cs | 1 - RotationSolver/Helpers/UIHelper.cs | 47 +++++++++++++++++++ RotationSolver/Localization/Strings.cs | 2 + RotationSolver/RotationSolverPlugin.cs | 20 +++++--- .../UI/RotationConfigWindow_Debug.cs | 26 +++------- RotationSolver/Updaters/RotationUpdater.cs | 1 - RotationSolver/Updaters/SocialUpdater.cs | 26 +--------- 8 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 RotationSolver/Helpers/UIHelper.cs diff --git a/RotationSolver/Helpers/RotationHelper.cs b/RotationSolver/Helpers/RotationHelper.cs index a93dba863..ea2d8ae36 100644 --- a/RotationSolver/Helpers/RotationHelper.cs +++ b/RotationSolver/Helpers/RotationHelper.cs @@ -1,6 +1,7 @@ using Dalamud.Interface.Colors; using Dalamud.Logging; using RotationSolver.Data; +using RotationSolver.Localization; using System.Diagnostics; namespace RotationSolver.Helpers; @@ -25,7 +26,9 @@ public static async Task LoadListAsync() } catch (Exception ex) { - PluginLog.Log(ex, "Failed to load white List."); + var failed = LocalizationManager.RightLang.WhiteListDownloadingFailed; + failed.ShowWarning(1, RotationSolverPlugin.DownloadLinkPayload); + PluginLog.Log(ex, failed); } } diff --git a/RotationSolver/Helpers/RotationLoadContext.cs b/RotationSolver/Helpers/RotationLoadContext.cs index 53665bc58..5499c6851 100644 --- a/RotationSolver/Helpers/RotationLoadContext.cs +++ b/RotationSolver/Helpers/RotationLoadContext.cs @@ -81,6 +81,5 @@ internal Assembly LoadFromFile(string filePath) return LoadFromStream(file); } } - } } diff --git a/RotationSolver/Helpers/UIHelper.cs b/RotationSolver/Helpers/UIHelper.cs new file mode 100644 index 000000000..fb4889177 --- /dev/null +++ b/RotationSolver/Helpers/UIHelper.cs @@ -0,0 +1,47 @@ +using Dalamud.Game.Text.SeStringHandling; +using Dalamud.Game.Text.SeStringHandling.Payloads; +using ECommons.DalamudServices; + +namespace RotationSolver.Basic.Helpers; + +public static class UIHelper +{ + public static void ShowWarning(this string message, int times = 3, DalamudLinkPayload link = null) + { + var seString = link == null + ? new SeString( + new IconPayload(BitmapFontIcon.DPS), + RotationSolverPlugin.OpenLinkPayload, + new UIForegroundPayload(31), + new TextPayload("Rotation Solver"), + UIForegroundPayload.UIForegroundOff, + RawPayload.LinkTerminator, + new TextPayload(": " + message)) + + : new SeString( + new IconPayload(BitmapFontIcon.DPS), + RotationSolverPlugin.OpenLinkPayload, + new UIForegroundPayload(31), + new TextPayload("Rotation Solver"), + UIForegroundPayload.UIForegroundOff, + RawPayload.LinkTerminator, + link, + new TextPayload(": " + message), + RawPayload.LinkTerminator); + + Svc.Chat.PrintChat(new Dalamud.Game.Text.XivChatEntry() + { + Message = seString, + Type = Dalamud.Game.Text.XivChatType.ErrorMessage, + }); + + Task.Run(async () => + { + for (int i = 0; i < times; i++) + { + await Task.Delay(3000); + Svc.Toasts.ShowError(message); + } + }); + } +} diff --git a/RotationSolver/Localization/Strings.cs b/RotationSolver/Localization/Strings.cs index f7257f036..6efbfee0e 100644 --- a/RotationSolver/Localization/Strings.cs +++ b/RotationSolver/Localization/Strings.cs @@ -617,4 +617,6 @@ internal partial class Strings public string HighEndWarning { get; set; } = "Please separately keybind damage reduction / shield cooldowns in case RS fails at a crucial moment in {0}!"; public string HighEndBan { get; set; } = "{0} can not be used in High-end Duty!"; public string TextToTalkWarning { get; set; } = "You didn't install TextToTalk, please install it to make Rotation Solver say something for you!"; + + public string WhiteListDownloadingFailed { get; set; } = "Failed to load white List. Click to retry."; } diff --git a/RotationSolver/RotationSolverPlugin.cs b/RotationSolver/RotationSolverPlugin.cs index dd95fdde2..2dbe966d4 100644 --- a/RotationSolver/RotationSolverPlugin.cs +++ b/RotationSolver/RotationSolverPlugin.cs @@ -30,7 +30,8 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable static readonly List _dis = new(); public string Name => "Rotation Solver"; - public static DalamudLinkPayload LinkPayload { get; private set; } + public static DalamudLinkPayload OpenLinkPayload { get; private set; } + public static DalamudLinkPayload DownloadLinkPayload { get; private set; } public RotationSolverPlugin(DalamudPluginInterface pluginInterface) { ECommonsMain.Init(pluginInterface, this, Module.DalamudReflector, Module.ObjectFunctions); @@ -74,15 +75,22 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface) #endif ChangeUITranslation(); - Task.Run(async () => + OpenLinkPayload = pluginInterface.AddChatLinkHandler(0, (id, str) => { - await RotationUpdater.GetAllCustomRotationsAsync(DownloadOption.Download); - await RotationHelper.LoadListAsync(); + if (id == 0) OpenConfigWindow(); + }); + DownloadLinkPayload = pluginInterface.AddChatLinkHandler(1, (id, str) => + { + if (id == 1) Task.Run(async () => + { + await RotationHelper.LoadListAsync(); + }); }); - LinkPayload = pluginInterface.AddChatLinkHandler(0, (id, str) => + Task.Run(async () => { - if(id == 0) OpenConfigWindow(); + await RotationUpdater.GetAllCustomRotationsAsync(DownloadOption.Download); + await RotationHelper.LoadListAsync(); }); } diff --git a/RotationSolver/UI/RotationConfigWindow_Debug.cs b/RotationSolver/UI/RotationConfigWindow_Debug.cs index e72542cea..13fd687f2 100644 --- a/RotationSolver/UI/RotationConfigWindow_Debug.cs +++ b/RotationSolver/UI/RotationConfigWindow_Debug.cs @@ -2,6 +2,7 @@ using ECommons.GameFunctions; using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game.Fate; +using FFXIVClientStructs.FFXIV.Client.UI.Agent; using RotationSolver.Updaters; namespace RotationSolver.UI; @@ -161,25 +162,12 @@ private void DrawLastAction() private unsafe void DrawIcon() { - //var pointer = (AddonActionCross*) Service.GetAddon(); - //if (pointer != null) - //{ - // ImGui.Text($"LTRT: {pointer->ExpandedHoldControlsLTRT}"); - // ImGui.Text($"RTLT: {pointer->ExpandedHoldControlsRTLT}"); - //} - //var pointer2 = (AddonActionDoubleCrossBase*)Service.GetAddon(); - //if (pointer2 != null) - //{ - // ImGui.Text($"ShowDPadSlots: {pointer2->ShowDPadSlots}"); - // ImGui.Text($"BarTarget: {pointer2->BarTarget}"); - // ImGui.Text($"UseLeftSide: {pointer2->UseLeftSide}"); - // ImGui.Text($"MergedPositioning: {pointer2->MergedPositioning}"); - //} - - var a = new int[]{ 0,1,3,4, 6, 6, 7}; - var index = Array.BinarySearch(a, -1); - if (index < 0) index = - 1 - index; - ImGui.Text(index.ToString()); + var ptr = AgentMap.Instance(); + for (var i = 23064; i < 23079; i++) + { + var value = *(byte*)(ptr + i); + ImGui.Text($"{i}: {value}"); + } } private static void DrawAction(ActionID id, string type) diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index 01a6d890a..a7e25fd7c 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -28,7 +28,6 @@ internal static class RotationUpdater public static async Task GetAllCustomRotationsAsync(DownloadOption option) { if (_isLoading) return; - _isLoading = true; try diff --git a/RotationSolver/Updaters/SocialUpdater.cs b/RotationSolver/Updaters/SocialUpdater.cs index 0190bbd1e..b19cc8462 100644 --- a/RotationSolver/Updaters/SocialUpdater.cs +++ b/RotationSolver/Updaters/SocialUpdater.cs @@ -123,29 +123,7 @@ static void DutyState_DutyStarted(object sender, ushort e) var territory = Service.GetSheet().GetRow(e); if (HighEndDuties.Any(t => t.RowId == territory.RowId)) { - var message = string.Format(LocalizationManager.RightLang.HighEndWarning, GetDutyName(territory)); - - Svc.Chat.PrintChat(new Dalamud.Game.Text.XivChatEntry() - { - Message = new SeString( - new IconPayload(BitmapFontIcon.DPS), - RotationSolverPlugin.LinkPayload, - new UIForegroundPayload(31), - new TextPayload("Rotation Solver"), - UIForegroundPayload.UIForegroundOff, - RawPayload.LinkTerminator, - new TextPayload(": " + message)), - Type = Dalamud.Game.Text.XivChatType.ErrorMessage, - }); - - Task.Run(async() => - { - for (int i = 0; i < 3; i++) - { - await Task.Delay(3000); - Svc.Toasts.ShowError(message); - } - }); + string.Format(LocalizationManager.RightLang.HighEndWarning, GetDutyName(territory)).ShowWarning(); } } @@ -214,7 +192,7 @@ private static async void SayHelloToAuthor() new TextPayload($"({nameDesc}) is one of the authors of "), new IconPayload(BitmapFontIcon.DPS), - RotationSolverPlugin.LinkPayload, + RotationSolverPlugin.OpenLinkPayload, new UIForegroundPayload(31), new TextPayload("Rotation Solver"), UIForegroundPayload.UIForegroundOff,