Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add downloading failed warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 3, 2023
1 parent eff495d commit 87cb90e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 52 deletions.
5 changes: 4 additions & 1 deletion RotationSolver/Helpers/RotationHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Interface.Colors;
using Dalamud.Logging;
using RotationSolver.Data;
using RotationSolver.Localization;
using System.Diagnostics;

namespace RotationSolver.Helpers;
Expand All @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion RotationSolver/Helpers/RotationLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,5 @@ internal Assembly LoadFromFile(string filePath)
return LoadFromStream(file);
}
}

}
}
47 changes: 47 additions & 0 deletions RotationSolver/Helpers/UIHelper.cs
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
}
2 changes: 2 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
20 changes: 14 additions & 6 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable
static readonly List<IDisposable> _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);
Expand Down Expand Up @@ -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();
});
}

Expand Down
26 changes: 7 additions & 19 deletions RotationSolver/UI/RotationConfigWindow_Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,25 +162,12 @@ private void DrawLastAction()

private unsafe void DrawIcon()
{
//var pointer = (AddonActionCross*) Service.GetAddon<AddonActionCross>();
//if (pointer != null)
//{
// ImGui.Text($"LTRT: {pointer->ExpandedHoldControlsLTRT}");
// ImGui.Text($"RTLT: {pointer->ExpandedHoldControlsRTLT}");
//}
//var pointer2 = (AddonActionDoubleCrossBase*)Service.GetAddon<AddonActionDoubleCrossBase>();
//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<int>(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)
Expand Down
1 change: 0 additions & 1 deletion RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ internal static class RotationUpdater
public static async Task GetAllCustomRotationsAsync(DownloadOption option)
{
if (_isLoading) return;

_isLoading = true;

try
Expand Down
26 changes: 2 additions & 24 deletions RotationSolver/Updaters/SocialUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,7 @@ static void DutyState_DutyStarted(object sender, ushort e)
var territory = Service.GetSheet<TerritoryType>().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();
}
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 87cb90e

Please sign in to comment.