From fd3a066aee423a43b5b16fba92640ae26010c635 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 22 Apr 2023 21:55:31 +0200 Subject: [PATCH] Some more touches. --- OtterGui | 2 +- .../Manager/IndividualCollections.Files.cs | 1 + .../Manager/ModCollectionMigration.cs | 1 + Penumbra/Collections/ModCollection.cs | 5 +- Penumbra/Configuration.cs | 1 - .../PathResolving/AnimationHookService.cs | 11 +- Penumbra/Mods/Editor/DuplicateManager.cs | 1 + Penumbra/Mods/Manager/ModMigration.cs | 1 + Penumbra/Mods/ModCreator.cs | 1 + Penumbra/Mods/TemporaryMod.cs | 1 + Penumbra/Services/ChatService.cs | 47 ++++++++ Penumbra/{Util => Services}/SaveService.cs | 3 +- Penumbra/Services/ServiceManager.cs | 1 - Penumbra/Services/ServiceWrapper.cs | 11 +- Penumbra/Services/StainService.cs | 1 - Penumbra/UI/ModsTab/ModFileSystemSelector.cs | 2 +- Penumbra/UI/ModsTab/ModPanelEditTab.cs | 1 - Penumbra/Util/ChatService.cs | 109 ------------------ 18 files changed, 64 insertions(+), 136 deletions(-) create mode 100644 Penumbra/Services/ChatService.cs rename Penumbra/{Util => Services}/SaveService.cs (95%) delete mode 100644 Penumbra/Util/ChatService.cs diff --git a/OtterGui b/OtterGui index ee7815a4..99bd0a88 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit ee7815a4f4c91ec04a240c9e52733f2f5ffa15d0 +Subproject commit 99bd0a889806f0560109686ca3b29a4edfa48f76 diff --git a/Penumbra/Collections/Manager/IndividualCollections.Files.cs b/Penumbra/Collections/Manager/IndividualCollections.Files.cs index b720c35c..97e22bb2 100644 --- a/Penumbra/Collections/Manager/IndividualCollections.Files.cs +++ b/Penumbra/Collections/Manager/IndividualCollections.Files.cs @@ -5,6 +5,7 @@ using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Interface.Internal.Notifications; using Newtonsoft.Json.Linq; using Penumbra.GameData.Actors; +using Penumbra.Services; using Penumbra.String; using Penumbra.Util; diff --git a/Penumbra/Collections/Manager/ModCollectionMigration.cs b/Penumbra/Collections/Manager/ModCollectionMigration.cs index c0ddd0e4..c1f158ea 100644 --- a/Penumbra/Collections/Manager/ModCollectionMigration.cs +++ b/Penumbra/Collections/Manager/ModCollectionMigration.cs @@ -2,6 +2,7 @@ using Penumbra.Mods; using System.Collections.Generic; using System.Linq; using Penumbra.Mods.Manager; +using Penumbra.Services; using Penumbra.Util; namespace Penumbra.Collections.Manager; diff --git a/Penumbra/Collections/ModCollection.cs b/Penumbra/Collections/ModCollection.cs index a2b201cd..32e7b0b3 100644 --- a/Penumbra/Collections/ModCollection.cs +++ b/Penumbra/Collections/ModCollection.cs @@ -5,8 +5,9 @@ using System.Diagnostics; using System.Linq; using Penumbra.Mods.Manager; using Penumbra.Util; -using Penumbra.Collections.Manager; - +using Penumbra.Collections.Manager; +using Penumbra.Services; + namespace Penumbra.Collections; /// diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index 3799d9db..cc10e3a7 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -16,7 +16,6 @@ using Penumbra.Services; using Penumbra.UI; using Penumbra.UI.Classes; using Penumbra.UI.Tabs; -using Penumbra.Util; using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs; namespace Penumbra; diff --git a/Penumbra/Interop/PathResolving/AnimationHookService.cs b/Penumbra/Interop/PathResolving/AnimationHookService.cs index e3b06de3..2add5771 100644 --- a/Penumbra/Interop/PathResolving/AnimationHookService.cs +++ b/Penumbra/Interop/PathResolving/AnimationHookService.cs @@ -225,12 +225,9 @@ public unsafe class AnimationHookService : IDisposable } var ret = _loadCharacterVfxHook.Original(vfxPath, vfxParams, unk1, unk2, unk3, unk4); -#if DEBUG - var path = new ByteString(vfxPath); - Penumbra.Log.Verbose( - $"Load Character VFX: {path} 0x{vfxParams->GameObjectId:X} {vfxParams->TargetCount} {unk1} {unk2} {unk3} {unk4} -> " + Penumbra.Log.Excessive( + $"Load Character VFX: {new ByteString(vfxPath)} 0x{vfxParams->GameObjectId:X} {vfxParams->TargetCount} {unk1} {unk2} {unk3} {unk4} -> " + $"0x{ret:X} {_animationLoadData.Value.ModCollection.Name} {_animationLoadData.Value.AssociatedGameObject} {last.ModCollection.Name} {last.AssociatedGameObject}"); -#endif _animationLoadData.Value = last; return ret; } @@ -250,11 +247,9 @@ public unsafe class AnimationHookService : IDisposable : ResolveData.Invalid; var ret = _loadAreaVfxHook.Original(vfxId, pos, caster, unk1, unk2, unk3); -#if DEBUG - Penumbra.Log.Verbose( + Penumbra.Log.Excessive( $"Load Area VFX: {vfxId}, {pos[0]} {pos[1]} {pos[2]} {(caster != null ? new ByteString(caster->GetName()).ToString() : "Unknown")} {unk1} {unk2} {unk3}" + $" -> {ret:X} {_animationLoadData.Value.ModCollection.Name} {_animationLoadData.Value.AssociatedGameObject} {last.ModCollection.Name} {last.AssociatedGameObject}"); -#endif _animationLoadData.Value = last; return ret; } diff --git a/Penumbra/Mods/Editor/DuplicateManager.cs b/Penumbra/Mods/Editor/DuplicateManager.cs index b2ec750f..62edb9fb 100644 --- a/Penumbra/Mods/Editor/DuplicateManager.cs +++ b/Penumbra/Mods/Editor/DuplicateManager.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Security.Cryptography; using System.Threading.Tasks; using Penumbra.Mods.Manager; +using Penumbra.Services; using Penumbra.String.Classes; using Penumbra.Util; diff --git a/Penumbra/Mods/Manager/ModMigration.cs b/Penumbra/Mods/Manager/ModMigration.cs index c41c40dc..28c37175 100644 --- a/Penumbra/Mods/Manager/ModMigration.cs +++ b/Penumbra/Mods/Manager/ModMigration.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OtterGui; using Penumbra.Api.Enums; +using Penumbra.Services; using Penumbra.String.Classes; using Penumbra.Util; diff --git a/Penumbra/Mods/ModCreator.cs b/Penumbra/Mods/ModCreator.cs index 806d1a1b..8801e433 100644 --- a/Penumbra/Mods/ModCreator.cs +++ b/Penumbra/Mods/ModCreator.cs @@ -15,6 +15,7 @@ using Penumbra.Import; using Penumbra.Import.Structs; using Penumbra.Meta; using Penumbra.Mods.Manager; +using Penumbra.Services; using Penumbra.String.Classes; using Penumbra.Util; diff --git a/Penumbra/Mods/TemporaryMod.cs b/Penumbra/Mods/TemporaryMod.cs index 1f408b15..6959194f 100644 --- a/Penumbra/Mods/TemporaryMod.cs +++ b/Penumbra/Mods/TemporaryMod.cs @@ -6,6 +6,7 @@ using OtterGui.Classes; using Penumbra.Collections; using Penumbra.Meta.Manipulations; using Penumbra.Mods.Manager; +using Penumbra.Services; using Penumbra.String.Classes; using Penumbra.Util; diff --git a/Penumbra/Services/ChatService.cs b/Penumbra/Services/ChatService.cs new file mode 100644 index 00000000..f4d4ead0 --- /dev/null +++ b/Penumbra/Services/ChatService.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using Dalamud.Game.Gui; +using Dalamud.Game.Text; +using Dalamud.Game.Text.SeStringHandling; +using Dalamud.Game.Text.SeStringHandling.Payloads; +using Dalamud.Interface; +using Dalamud.Plugin; +using Lumina.Excel.GeneratedSheets; +using OtterGui.Log; + +namespace Penumbra.Services; + +public class ChatService : OtterGui.Classes.ChatService +{ + private readonly ChatGui _chat; + + public ChatService(Logger log, DalamudPluginInterface pi, ChatGui chat, UiBuilder uiBuilder) + : base(log, pi) + => _chat = chat; + + public void LinkItem(Item item) + { + // @formatter:off + var payloadList = new List + { + new UIForegroundPayload((ushort)(0x223 + item.Rarity * 2)), + new UIGlowPayload((ushort)(0x224 + item.Rarity * 2)), + new ItemPayload(item.RowId, false), + new UIForegroundPayload(500), + new UIGlowPayload(501), + new TextPayload($"{(char)SeIconChar.LinkMarker}"), + new UIForegroundPayload(0), + new UIGlowPayload(0), + new TextPayload(item.Name), + new RawPayload(new byte[] { 0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03 }), + new RawPayload(new byte[] { 0x02, 0x13, 0x02, 0xEC, 0x03 }), + }; + // @formatter:on + + var payload = new SeString(payloadList); + + _chat.PrintChat(new XivChatEntry + { + Message = payload, + }); + } +} diff --git a/Penumbra/Util/SaveService.cs b/Penumbra/Services/SaveService.cs similarity index 95% rename from Penumbra/Util/SaveService.cs rename to Penumbra/Services/SaveService.cs index f8bdd848..ff4ec151 100644 --- a/Penumbra/Util/SaveService.cs +++ b/Penumbra/Services/SaveService.cs @@ -4,9 +4,8 @@ using System.Text; using OtterGui.Classes; using OtterGui.Log; using Penumbra.Mods; -using Penumbra.Services; -namespace Penumbra.Util; +namespace Penumbra.Services; /// /// Any file type that we want to save via SaveService. diff --git a/Penumbra/Services/ServiceManager.cs b/Penumbra/Services/ServiceManager.cs index e973c784..b55a820f 100644 --- a/Penumbra/Services/ServiceManager.cs +++ b/Penumbra/Services/ServiceManager.cs @@ -18,7 +18,6 @@ using Penumbra.UI; using Penumbra.UI.AdvancedWindow; using Penumbra.UI.ModsTab; using Penumbra.UI.Tabs; -using Penumbra.Util; namespace Penumbra.Services; diff --git a/Penumbra/Services/ServiceWrapper.cs b/Penumbra/Services/ServiceWrapper.cs index 5da7cd07..cb4c86e8 100644 --- a/Penumbra/Services/ServiceWrapper.cs +++ b/Penumbra/Services/ServiceWrapper.cs @@ -4,14 +4,7 @@ using Penumbra.Util; namespace Penumbra.Services; -public interface IServiceWrapper : IDisposable -{ - public string Name { get; } - public T? Service { get; } - public bool Valid { get; } -} - -public abstract class SyncServiceWrapper : IServiceWrapper +public abstract class SyncServiceWrapper { public string Name { get; } public T Service { get; } @@ -40,7 +33,7 @@ public abstract class SyncServiceWrapper : IServiceWrapper } } -public abstract class AsyncServiceWrapper : IServiceWrapper +public abstract class AsyncServiceWrapper { public string Name { get; } public T? Service { get; private set; } diff --git a/Penumbra/Services/StainService.cs b/Penumbra/Services/StainService.cs index cf493716..d795062c 100644 --- a/Penumbra/Services/StainService.cs +++ b/Penumbra/Services/StainService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using Dalamud.Data; using Dalamud.Plugin; -using OtterGui.Classes; using OtterGui.Widgets; using Penumbra.GameData.Data; using Penumbra.GameData.Files; diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index e151faa8..2b5b50ba 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -18,7 +18,7 @@ using Penumbra.Mods; using Penumbra.Mods.Manager; using Penumbra.Services; using Penumbra.UI.Classes; -using Penumbra.Util; +using ChatService = Penumbra.Services.ChatService; namespace Penumbra.UI.ModsTab; diff --git a/Penumbra/UI/ModsTab/ModPanelEditTab.cs b/Penumbra/UI/ModsTab/ModPanelEditTab.cs index 68f9707d..294f8041 100644 --- a/Penumbra/UI/ModsTab/ModPanelEditTab.cs +++ b/Penumbra/UI/ModsTab/ModPanelEditTab.cs @@ -15,7 +15,6 @@ using Penumbra.Mods; using Penumbra.Mods.Manager; using Penumbra.Services; using Penumbra.UI.AdvancedWindow; -using Penumbra.Util; namespace Penumbra.UI.ModsTab; diff --git a/Penumbra/Util/ChatService.cs b/Penumbra/Util/ChatService.cs deleted file mode 100644 index 92cf0560..00000000 --- a/Penumbra/Util/ChatService.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System.Collections.Generic; -using Dalamud.Game.Gui; -using Dalamud.Game.Text; -using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Game.Text.SeStringHandling.Payloads; -using Dalamud.Interface; -using Dalamud.Interface.Internal.Notifications; -using Dalamud.Plugin; -using Dalamud.Utility; -using Lumina.Excel.GeneratedSheets; -using OtterGui.Log; - -namespace Penumbra.Util; - -public class ChatService -{ - private readonly Logger _log; - private readonly UiBuilder _uiBuilder; - private readonly ChatGui _chat; - - public ChatService(Logger log, DalamudPluginInterface pi, ChatGui chat) - { - _log = log; - _uiBuilder = pi.UiBuilder; - _chat = chat; - } - - public void LinkItem(Item item) - { - // @formatter:off - var payloadList = new List - { - new UIForegroundPayload((ushort)(0x223 + item.Rarity * 2)), - new UIGlowPayload((ushort)(0x224 + item.Rarity * 2)), - new ItemPayload(item.RowId, false), - new UIForegroundPayload(500), - new UIGlowPayload(501), - new TextPayload($"{(char)SeIconChar.LinkMarker}"), - new UIForegroundPayload(0), - new UIGlowPayload(0), - new TextPayload(item.Name), - new RawPayload(new byte[] { 0x02, 0x27, 0x07, 0xCF, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03 }), - new RawPayload(new byte[] { 0x02, 0x13, 0x02, 0xEC, 0x03 }), - }; - // @formatter:on - - var payload = new SeString(payloadList); - - _chat.PrintChat(new XivChatEntry - { - Message = payload, - }); - } - - public void NotificationMessage(string content, string? title = null, NotificationType type = NotificationType.None) - { - var logLevel = type switch - { - NotificationType.None => Logger.LogLevel.Information, - NotificationType.Success => Logger.LogLevel.Information, - NotificationType.Warning => Logger.LogLevel.Warning, - NotificationType.Error => Logger.LogLevel.Error, - NotificationType.Info => Logger.LogLevel.Information, - _ => Logger.LogLevel.Debug, - }; - _uiBuilder.AddNotification(content, title, type); - _log.Message(logLevel, title.IsNullOrEmpty() ? content : $"[{title}] {content}"); - } -} - -public static class SeStringBuilderExtensions -{ - public const ushort Green = 504; - public const ushort Yellow = 31; - public const ushort Red = 534; - public const ushort Blue = 517; - public const ushort White = 1; - public const ushort Purple = 541; - - public static SeStringBuilder AddText(this SeStringBuilder sb, string text, int color, bool brackets = false) - => sb.AddUiForeground((ushort)color).AddText(brackets ? $"[{text}]" : text).AddUiForegroundOff(); - - public static SeStringBuilder AddGreen(this SeStringBuilder sb, string text, bool brackets = false) - => AddText(sb, text, Green, brackets); - - public static SeStringBuilder AddYellow(this SeStringBuilder sb, string text, bool brackets = false) - => AddText(sb, text, Yellow, brackets); - - public static SeStringBuilder AddRed(this SeStringBuilder sb, string text, bool brackets = false) - => AddText(sb, text, Red, brackets); - - public static SeStringBuilder AddBlue(this SeStringBuilder sb, string text, bool brackets = false) - => AddText(sb, text, Blue, brackets); - - public static SeStringBuilder AddWhite(this SeStringBuilder sb, string text, bool brackets = false) - => AddText(sb, text, White, brackets); - - public static SeStringBuilder AddPurple(this SeStringBuilder sb, string text, bool brackets = false) - => AddText(sb, text, Purple, brackets); - - public static SeStringBuilder AddCommand(this SeStringBuilder sb, string command, string description) - => sb.AddText(" 》 ") - .AddBlue(command) - .AddText($" - {description}"); - - public static SeStringBuilder AddInitialPurple(this SeStringBuilder sb, string word, bool withComma = true) - => sb.AddPurple($"[{word[0]}]") - .AddText(withComma ? $"{word[1..]}, " : word[1..]); -}