add NotificationService, cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using Dalamud.Logging;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using MareSynchronos.API.Data;
|
||||
using MareSynchronos.API.Data.Enum;
|
||||
@@ -143,11 +144,12 @@ public class CachedPlayer : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
List<string> missingPluginsForData = new();
|
||||
if (characterData.HeelsOffset != default)
|
||||
{
|
||||
if (!warning.ShownHeelsWarning && !_ipcManager.CheckHeelsApi())
|
||||
{
|
||||
_dalamudUtil.PrintWarnChat("Received Heels data for player " + PlayerName + ", but Heels is not installed. Install Heels to experience their character fully.");
|
||||
missingPluginsForData.Add("Heels");
|
||||
warning.ShownHeelsWarning = true;
|
||||
}
|
||||
}
|
||||
@@ -155,7 +157,7 @@ public class CachedPlayer : IDisposable
|
||||
{
|
||||
if (!warning.ShownCustomizePlusWarning && !_ipcManager.CheckCustomizePlusApi())
|
||||
{
|
||||
_dalamudUtil.PrintWarnChat("Received Customize+ data for player " + PlayerName + ", but Customize+ is not installed. Install Customize+ to experience their character fully.");
|
||||
missingPluginsForData.Add("Customize+");
|
||||
warning.ShownCustomizePlusWarning = true;
|
||||
}
|
||||
}
|
||||
@@ -164,11 +166,18 @@ public class CachedPlayer : IDisposable
|
||||
{
|
||||
if (!warning.ShownPalettePlusWarning && !_ipcManager.CheckPalettePlusApi())
|
||||
{
|
||||
_dalamudUtil.PrintWarnChat("Received Palette+ data for player " + PlayerName + ", but Palette+ is not installed. Install Palette+ to experience their character fully.");
|
||||
missingPluginsForData.Add("Palette+");
|
||||
warning.ShownPalettePlusWarning = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (missingPluginsForData.Any())
|
||||
{
|
||||
_mediator.Publish(new NotificationMessage("Missing plugins for " + PlayerName,
|
||||
$"Received data for {PlayerName} that contained information for plugins you have not installed. Install {string.Join(", ", missingPluginsForData)} to experience their character fully.",
|
||||
NotificationType.Warning, 10000));
|
||||
}
|
||||
|
||||
_cachedData = characterData;
|
||||
|
||||
DownloadAndApplyCharacter(charaDataToUpdate, updateModdedPaths);
|
||||
|
||||
@@ -177,7 +177,7 @@ public class IpcManager : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public bool Initialized => CheckPenumbraApi();
|
||||
public bool Initialized => CheckPenumbraApi() && CheckGlamourerApi();
|
||||
public bool CheckGlamourerApi()
|
||||
{
|
||||
try
|
||||
|
||||
103
MareSynchronos/Managers/NotificationService.cs
Normal file
103
MareSynchronos/Managers/NotificationService.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using Dalamud.Game.Gui;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Mediator;
|
||||
using MareSynchronos.Utils;
|
||||
|
||||
namespace MareSynchronos.Managers;
|
||||
public class NotificationService
|
||||
{
|
||||
private readonly UiBuilder _uiBuilder;
|
||||
private readonly ChatGui _chatGui;
|
||||
private readonly ConfigurationService _configurationService;
|
||||
|
||||
public NotificationService(MareMediator mediator, UiBuilder uiBuilder, ChatGui chatGui, ConfigurationService configurationService)
|
||||
{
|
||||
_uiBuilder = uiBuilder;
|
||||
_chatGui = chatGui;
|
||||
_configurationService = configurationService;
|
||||
mediator.Subscribe<NotificationMessage>(this, (msg) => ShowNotification((NotificationMessage)msg));
|
||||
}
|
||||
|
||||
private void ShowNotification(NotificationMessage msg)
|
||||
{
|
||||
Logger.Info(msg.ToString());
|
||||
|
||||
switch (msg.Type)
|
||||
{
|
||||
case NotificationType.Info:
|
||||
case NotificationType.Success:
|
||||
case NotificationType.None:
|
||||
ShowNotificationLocationBased(msg, _configurationService.Current.InfoNotification);
|
||||
break;
|
||||
case NotificationType.Warning:
|
||||
ShowNotificationLocationBased(msg, _configurationService.Current.WarningNotification);
|
||||
break;
|
||||
case NotificationType.Error:
|
||||
ShowNotificationLocationBased(msg, _configurationService.Current.ErrorNotification);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowNotificationLocationBased(NotificationMessage msg, NotificationLocation location)
|
||||
{
|
||||
switch (location)
|
||||
{
|
||||
case NotificationLocation.Toast:
|
||||
ShowToast(msg);
|
||||
break;
|
||||
case NotificationLocation.Chat:
|
||||
ShowChat(msg);
|
||||
break;
|
||||
case NotificationLocation.Both:
|
||||
ShowToast(msg);
|
||||
ShowChat(msg);
|
||||
break;
|
||||
case NotificationLocation.Nowhere:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowToast(NotificationMessage msg)
|
||||
{
|
||||
_uiBuilder.AddNotification(msg.Message ?? string.Empty, "[Mare Synchronos] " + msg.Title, msg.Type, msg.TimeShownOnScreen);
|
||||
}
|
||||
|
||||
private void ShowChat(NotificationMessage msg)
|
||||
{
|
||||
switch (msg.Type)
|
||||
{
|
||||
case NotificationType.Info:
|
||||
case NotificationType.Success:
|
||||
case NotificationType.None:
|
||||
PrintInfoChat(msg.Message);
|
||||
break;
|
||||
case NotificationType.Warning:
|
||||
PrintWarnChat(msg.Message);
|
||||
break;
|
||||
case NotificationType.Error:
|
||||
PrintErrorChat(msg.Message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void PrintInfoChat(string? message)
|
||||
{
|
||||
SeStringBuilder se = new SeStringBuilder().AddText("[Mare Synchronos] Info: ").AddItalics(message ?? string.Empty);
|
||||
_chatGui.Print(se.BuiltString);
|
||||
}
|
||||
|
||||
private void PrintWarnChat(string? message)
|
||||
{
|
||||
SeStringBuilder se = new SeStringBuilder().AddText("[Mare Synchronos] ").AddUiForeground("Warning: " + (message ?? string.Empty), 31).AddUiForegroundOff();
|
||||
_chatGui.Print(se.BuiltString);
|
||||
}
|
||||
|
||||
private void PrintErrorChat(string? message)
|
||||
{
|
||||
SeStringBuilder se = new SeStringBuilder().AddText("[Mare Synchronos] ").AddUiForeground("Error: ", 534).AddItalicsOn().AddUiForeground(message ?? string.Empty, 534).AddUiForegroundOff().AddItalicsOff();
|
||||
_chatGui.Print(se.BuiltString);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Internal.Notifications;
|
||||
using Dalamud.Utility;
|
||||
using MareSynchronos.API.Data;
|
||||
using MareSynchronos.API.Data.Comparer;
|
||||
@@ -21,16 +22,14 @@ public class PairManager : IDisposable
|
||||
private readonly ConcurrentDictionary<UserData, Pair> _allClientPairs = new(UserDataComparer.Instance);
|
||||
private readonly ConcurrentDictionary<GroupData, GroupFullInfoDto> _allGroups = new(GroupDataComparer.Instance);
|
||||
private readonly CachedPlayerFactory _cachedPlayerFactory;
|
||||
private readonly DalamudUtil _dalamudUtil;
|
||||
private readonly PairFactory _pairFactory;
|
||||
private readonly UiBuilder _uiBuilder;
|
||||
private readonly ConfigurationService _configurationService;
|
||||
private readonly MareMediator _mediator;
|
||||
|
||||
public PairManager(CachedPlayerFactory cachedPlayerFactory, DalamudUtil dalamudUtil, PairFactory pairFactory, UiBuilder uiBuilder, ConfigurationService configurationService, MareMediator mediator)
|
||||
public PairManager(CachedPlayerFactory cachedPlayerFactory, PairFactory pairFactory, UiBuilder uiBuilder, ConfigurationService configurationService, MareMediator mediator)
|
||||
{
|
||||
_cachedPlayerFactory = cachedPlayerFactory;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_pairFactory = pairFactory;
|
||||
_uiBuilder = uiBuilder;
|
||||
_configurationService = configurationService;
|
||||
@@ -172,20 +171,24 @@ public class PairManager : IDisposable
|
||||
public void MarkPairOnline(OnlineUserIdentDto dto, ApiController controller)
|
||||
{
|
||||
if (!_allClientPairs.ContainsKey(dto.User)) throw new InvalidOperationException("No user found for " + dto);
|
||||
var pair = _allClientPairs[dto.User];
|
||||
if (pair.CachedPlayer != null) return;
|
||||
|
||||
if (_allClientPairs[dto.User].CachedPlayer != null) return;
|
||||
|
||||
if (_configurationService.Current.ShowOnlineNotifications)
|
||||
if (_configurationService.Current.ShowOnlineNotifications
|
||||
&& ((_configurationService.Current.ShowOnlineNotificationsOnlyForIndividualPairs && pair.UserPair != null)
|
||||
|| !_configurationService.Current.ShowOnlineNotificationsOnlyForIndividualPairs)
|
||||
&& (_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs && !string.IsNullOrEmpty(pair.GetNote())
|
||||
|| !_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs))
|
||||
{
|
||||
var pair = _allClientPairs[dto.User];
|
||||
if (_configurationService.Current.ShowOnlineNotificationsOnlyForIndividualPairs && pair.UserPair != null || !_configurationService.Current.ShowOnlineNotificationsOnlyForIndividualPairs)
|
||||
{
|
||||
_uiBuilder.AddNotification(string.Empty, "[Mare Synchronos] " + (pair.GetNote() ?? pair.UserData.AliasOrUID) + " is now online", Dalamud.Interface.Internal.Notifications.NotificationType.Info, 5000);
|
||||
}
|
||||
string note = pair.GetNote();
|
||||
var msg = string.IsNullOrEmpty(note)
|
||||
? $"{note} ({pair.UserData.AliasOrUID}) is now online"
|
||||
: $"{pair.UserData.AliasOrUID} is now online";
|
||||
_mediator.Publish(new NotificationMessage("User online", msg, NotificationType.Info, 5000));
|
||||
}
|
||||
|
||||
_allClientPairs[dto.User].CachedPlayer?.Dispose();
|
||||
_allClientPairs[dto.User].CachedPlayer = _cachedPlayerFactory.Create(dto, controller);
|
||||
pair.CachedPlayer?.Dispose();
|
||||
pair.CachedPlayer = _cachedPlayerFactory.Create(dto, controller);
|
||||
RecreateLazy();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using MareSynchronos.Utils;
|
||||
using MareSynchronos.WebAPI;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using MareSynchronos.Models;
|
||||
using MareSynchronos.UI;
|
||||
using MareSynchronos.API.Data.Enum;
|
||||
using MareSynchronos.Mediator;
|
||||
#if DEBUG
|
||||
@@ -55,10 +54,10 @@ public class PlayerManager : MediatorSubscriberBase, IDisposable
|
||||
|
||||
_playerRelatedObjects = new List<PlayerRelatedObject>()
|
||||
{
|
||||
new PlayerRelatedObject(ObjectKind.Player, IntPtr.Zero, IntPtr.Zero, () => _dalamudUtil.PlayerPointer),
|
||||
new PlayerRelatedObject(ObjectKind.MinionOrMount, IntPtr.Zero, IntPtr.Zero, () => (IntPtr)((Character*)_dalamudUtil.PlayerPointer)->CompanionObject),
|
||||
new PlayerRelatedObject(ObjectKind.Pet, IntPtr.Zero, IntPtr.Zero, () => _dalamudUtil.GetPet()),
|
||||
new PlayerRelatedObject(ObjectKind.Companion, IntPtr.Zero, IntPtr.Zero, () => _dalamudUtil.GetCompanion()),
|
||||
new(ObjectKind.Player, IntPtr.Zero, IntPtr.Zero, () => _dalamudUtil.PlayerPointer),
|
||||
new(ObjectKind.MinionOrMount, IntPtr.Zero, IntPtr.Zero, () => (IntPtr)((Character*)_dalamudUtil.PlayerPointer)->CompanionObject),
|
||||
new(ObjectKind.Pet, IntPtr.Zero, IntPtr.Zero, () => _dalamudUtil.GetPet()),
|
||||
new(ObjectKind.Companion, IntPtr.Zero, IntPtr.Zero, () => _dalamudUtil.GetCompanion()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user