Skip to content

Commit

Permalink
fix: work around dalamud's unwieldiness
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Mar 21, 2024
1 parent 6f228f7 commit 4d6abc8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Ui/NotificationProgressManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Heliosphere.Ui;
internal class NotificationProgressManager : IDisposable {
private Plugin Plugin { get; }
private Dictionary<Guid, IActiveNotification> Notifications { get; } = [];
private Dictionary<Guid, State> LastSeenState { get; } = [];
private Dictionary<State, IDalamudTextureWrap> Icons { get; } = [];

internal NotificationProgressManager(Plugin plugin) {
Expand All @@ -30,6 +31,17 @@ internal NotificationProgressManager(Plugin plugin) {
}
}

private IDalamudTextureWrap? GetStateIcon(State state) {
try {
using var stream = state.GetIconStream();
using var memory = new MemoryStream();
stream.CopyTo(memory);
return this.Plugin.Interface.UiBuilder.LoadImage(memory.ToArray());
} catch {
return null;
}
}

public void Dispose() {
this.Plugin.Framework.Update -= this.FrameworkUpdate;

Expand Down Expand Up @@ -92,8 +104,10 @@ internal void Update() {
}

var state = this.UpdateNotif(notif, task);
this.LastSeenState[task.TaskId] = state;
if (state.IsDone()) {
this.Notifications.Remove(task.TaskId);
this.LastSeenState.Remove(task.TaskId);
}
}
}
Expand All @@ -103,7 +117,12 @@ private State UpdateNotif(IActiveNotification notif, DownloadTask task) {
var sData = task.StateData;
var sMax = task.StateDataMax;

if (this.Icons.TryGetValue(state, out var icon)) {
var setIcon = true;
if (this.LastSeenState.TryGetValue(task.TaskId, out var lastState) && lastState == state) {
setIcon = false;
}

if (setIcon && this.GetStateIcon(state) is { } icon) {
notif.SetIconTexture(icon);
}

Expand Down

0 comments on commit 4d6abc8

Please sign in to comment.