Skip to content

Commit

Permalink
Use new INotificationManager instead of pluginInterface.UiBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurochi51 committed Mar 17, 2024
1 parent 01f3787 commit ff50582
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
8 changes: 5 additions & 3 deletions PetScale/PetScale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace PetScale;
public sealed class PetScale : IDalamudPlugin
{
private const string CommandName = "/pscale";
public const string PluginName = "Pet Scale";

private readonly DalamudPluginInterface pluginInterface;
private readonly Configuration config;
Expand Down Expand Up @@ -70,7 +71,8 @@ public PetScale(DalamudPluginInterface _pluginInterface,
IFramework _framework,
IPluginLog _log,
IClientState _clientState,
IDataManager _dataManger)
IDataManager _dataManger,
INotificationManager _notificationManager)

Check failure on line 75 in PetScale/PetScale.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'INotificationManager' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 75 in PetScale/PetScale.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'INotificationManager' could not be found (are you missing a using directive or an assembly reference?)
{
pluginInterface = _pluginInterface;
commandManager = _commandManager;
Expand All @@ -80,7 +82,7 @@ public PetScale(DalamudPluginInterface _pluginInterface,
config = pluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
utilities = new Utilities(_dataManger, log);

ConfigWindow = new ConfigWindow(this, config, pluginInterface, log);
ConfigWindow = new ConfigWindow(this, config, pluginInterface, log, _notificationManager);
#if DEBUG
DevWindow = new DevWindow(log, pluginInterface);
WindowSystem.AddWindow(DevWindow);
Expand Down Expand Up @@ -336,7 +338,7 @@ private void RefreshCache(string playerName, uint playerObjectId)
utilities.CachePlayerList(playerObjectId, players, BattleCharaSpan);
}

private unsafe void SetScale(BattleChara* pet, PetStruct userData, string petName)
private unsafe void SetScale(BattleChara* pet, in PetStruct userData, string petName)
{
var scale = userData.PetSize switch
{
Expand Down
2 changes: 2 additions & 0 deletions PetScale/PetScale.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
</ContentWithTargetPath>
</ItemGroup>

<!--D:\yes\Dalamud\bin\Release\-->
<!--$(appdata)\XIVLauncher\addon\Hooks\dev\-->
<PropertyGroup>
<DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
<DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('Linux'))">$(HOME)/.xlcore/dalamud/Hooks/dev/</DalamudLibPath>
Expand Down
29 changes: 22 additions & 7 deletions PetScale/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Dalamud.Interface.Windowing;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.ImGuiNotification;

Check failure on line 19 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ImGuiNotification' does not exist in the namespace 'Dalamud.Interface' (are you missing an assembly reference?)

Check failure on line 19 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ImGuiNotification' does not exist in the namespace 'Dalamud.Interface' (are you missing an assembly reference?)
using Dalamud.Interface.Internal.Notifications;
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
using PetScale.Structs;
Expand All @@ -29,6 +30,7 @@ public sealed class ConfigWindow : Window, IDisposable
private readonly Configuration config;
private readonly PetScale plugin;
private readonly IPluginLog log;
private readonly INotificationManager notificationManager;

Check failure on line 33 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'INotificationManager' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 33 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'INotificationManager' could not be found (are you missing a using directive or an assembly reference?)
private readonly Dictionary<PetSize, string> sizeMap = new()
{
{ PetSize.SmallModelScale, "Small" },
Expand All @@ -38,6 +40,7 @@ public sealed class ConfigWindow : Window, IDisposable
private readonly string buttonIcon;
private readonly CancellationTokenSource cts;
private readonly CancellationToken cToken;
private readonly Notification notification = new();

Check failure on line 43 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Notification' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Notification' could not be found (are you missing a using directive or an assembly reference?)
private const string DefaultPetSelection = "Pet";
private const string LongestCharaName = "WWWWWWWWWWWWWWW WWWWW";
private const string LongestSize = "Medium";
Expand All @@ -53,12 +56,14 @@ public sealed class ConfigWindow : Window, IDisposable
public unsafe ConfigWindow(PetScale _plugin,
Configuration _config,
DalamudPluginInterface _pluginInterface,
IPluginLog _pluginLog) : base($"{nameof(PetScale)} Config")
IPluginLog _pluginLog,
INotificationManager _notificationManager) : base($"{nameof(PetScale)} Config")

Check failure on line 60 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'INotificationManager' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 60 in PetScale/Windows/ConfigWindow.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'INotificationManager' could not be found (are you missing a using directive or an assembly reference?)
{
plugin = _plugin;
config = _config;
pluginInterface = _pluginInterface;
log = _pluginLog;
notificationManager = _notificationManager;
SizeConstraints = new WindowSizeConstraints()
{
MinimumSize = new Vector2(470, 365),
Expand Down Expand Up @@ -106,17 +111,17 @@ public override void Draw()
var error = false;
if (charaName.IsNullOrWhitespace() || charaName.Equals("Characters", StringComparison.Ordinal))
{
pluginInterface.UiBuilder.AddNotification("Invalid Character selected", "Pet Scale", NotificationType.Error);
CreateNotification("Invalid Character selected", PetScale.PluginName, NotificationType.Error);
error = true;
}
if (petSelection.Equals(DefaultPetSelection, StringComparison.Ordinal))
{
pluginInterface.UiBuilder.AddNotification("Invalid Pet selected", "Pet Scale", NotificationType.Error);
CreateNotification("Invalid Pet selected", PetScale.PluginName, NotificationType.Error);
error = true;
}
if (sizeSelection.Equals("Size", StringComparison.Ordinal))
{
pluginInterface.UiBuilder.AddNotification("Invalid Pet Size selected", "Pet Scale", NotificationType.Error);
CreateNotification("Invalid Pet Size selected", PetScale.PluginName, NotificationType.Error);
error = true;
}
if (!error)
Expand Down Expand Up @@ -179,7 +184,7 @@ private unsafe void DisplayEntries()
if (DrawIconButton(fontHandle: null, buttonIcon, buttonId + buttonIcon))
{
petData.RemoveAt(i);
pluginInterface.UiBuilder.AddNotification("Entry " + item.CharacterName + ", " + petSelection + ", " + sizeMap[item.PetSize] + " was removed.");
CreateNotification("Entry " + item.CharacterName + ", " + petSelection + ", " + sizeMap[item.PetSize] + " was removed.", PetScale.PluginName);
itemRemoved = true;
}
}
Expand Down Expand Up @@ -324,7 +329,9 @@ private void CheckPossibleEntry()
if (checkPet.IsDefault())
{
petData.Add(currentPetData);
pluginInterface.UiBuilder.AddNotification("Entry " + currentPetData.CharacterName + ", " + petSelection + ", " + sizeMap[currentPetSize.Key] + " was added.");
CreateNotification(
"Entry " + currentPetData.CharacterName + ", " + petSelection + ", " + sizeMap[currentPetSize.Key] + " was added.",
PetScale.PluginName);
}
else if (!checkPet.PetSize.Equals(currentPetData.PetSize))
{
Expand All @@ -333,7 +340,7 @@ private void CheckPossibleEntry()
checkPet.PetSize = currentPetSize.Key;
petData[index] = checkPet;
log.Debug("Entry {name} with {pet} at {size} got changed.", checkPet.CharacterName, petSelection, checkPet.PetSize);
pluginInterface.UiBuilder.AddNotification(entry + sizeMap[petData[index].PetSize]);
CreateNotification(entry + sizeMap[petData[index].PetSize], PetScale.PluginName);
}
Save(save: true);
}
Expand Down Expand Up @@ -451,6 +458,14 @@ private async void QueueColumnWidthChange(IFontHandle handle, ILockedImFont lock
fontChange = true;
}

private void CreateNotification(string content, string title, NotificationType type = NotificationType.None)
{
notification.Content = content;
notification.Title = title;
notification.Type = type;
notificationManager.AddNotification(notification);
}

public void Dispose()
{
pluginInterface.UiBuilder.DefaultFontHandle.ImFontChanged -= QueueColumnWidthChange;
Expand Down

0 comments on commit ff50582

Please sign in to comment.