From adddbc452c55ffd204adbbabce2d6eaff6a2edd4 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Fri, 17 Feb 2023 19:31:43 +0100 Subject: [PATCH] DI: Support debug items in SimpleRenderer, remove IDrawDebugItems --- .../Properties/Localization.Designer.cs | 10 ------- Pal.Client/Properties/Localization.fr.resx | 3 -- Pal.Client/Properties/Localization.ja.resx | 3 -- Pal.Client/Properties/Localization.resx | 3 -- Pal.Client/Rendering/IDrawDebugItems.cs | 9 ------ Pal.Client/Rendering/IRenderer.cs | 2 ++ Pal.Client/Rendering/RenderAdapter.cs | 30 ++++++++++--------- Pal.Client/Rendering/RenderData.cs | 1 + Pal.Client/Rendering/SimpleRenderer.cs | 27 ++++++++++++++--- Pal.Client/Rendering/SplatoonRenderer.cs | 21 +++++-------- Pal.Client/Windows/ConfigWindow.cs | 7 ++--- 11 files changed, 52 insertions(+), 64 deletions(-) delete mode 100644 Pal.Client/Rendering/IDrawDebugItems.cs diff --git a/Pal.Client/Properties/Localization.Designer.cs b/Pal.Client/Properties/Localization.Designer.cs index f123400..d15a42c 100644 --- a/Pal.Client/Properties/Localization.Designer.cs +++ b/Pal.Client/Properties/Localization.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -385,15 +384,6 @@ namespace Pal.Client.Properties { } } - /// - /// Looks up a localized string similar to Splatoon Test:. - /// - internal static string Config_Splatoon_Test { - get { - return ResourceManager.GetString("Config_Splatoon_Test", resourceCulture); - } - } - /// /// Looks up a localized string similar to Start Export. /// diff --git a/Pal.Client/Properties/Localization.fr.resx b/Pal.Client/Properties/Localization.fr.resx index a213ab4..0712d94 100644 --- a/Pal.Client/Properties/Localization.fr.resx +++ b/Pal.Client/Properties/Localization.fr.resx @@ -228,9 +228,6 @@ Il n'y a pas de synchronisation avec les autres joueurs ni de sauvegarde entre l Expérimental - - Test de Splatoon : - Dessiner les marqueurs des pièges et coffres autour de soi To test the Splatoon integration, you can draw markers around yourself. diff --git a/Pal.Client/Properties/Localization.ja.resx b/Pal.Client/Properties/Localization.ja.resx index 051b929..4dd5bbf 100644 --- a/Pal.Client/Properties/Localization.ja.resx +++ b/Pal.Client/Properties/Localization.ja.resx @@ -227,9 +227,6 @@ 試験的機能 - - Splatoonのテスト: - 自分の周りにトラップと宝箱を表示する To test the Splatoon integration, you can draw markers around yourself. diff --git a/Pal.Client/Properties/Localization.resx b/Pal.Client/Properties/Localization.resx index 76cf1da..f9e3625 100644 --- a/Pal.Client/Properties/Localization.resx +++ b/Pal.Client/Properties/Localization.resx @@ -239,9 +239,6 @@ This is not synchronized with other players and not saved between floors/runs. experimental - - Splatoon Test: - Draw trap & coffer circles around self To test the Splatoon integration, you can draw markers around yourself. diff --git a/Pal.Client/Rendering/IDrawDebugItems.cs b/Pal.Client/Rendering/IDrawDebugItems.cs deleted file mode 100644 index e584545..0000000 --- a/Pal.Client/Rendering/IDrawDebugItems.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Numerics; - -namespace Pal.Client.Rendering -{ - internal interface IDrawDebugItems - { - void DrawDebugItems(Vector4 trapColor, Vector4 hoardColor); - } -} diff --git a/Pal.Client/Rendering/IRenderer.cs b/Pal.Client/Rendering/IRenderer.cs index 68ecf00..0ac7fd3 100644 --- a/Pal.Client/Rendering/IRenderer.cs +++ b/Pal.Client/Rendering/IRenderer.cs @@ -13,5 +13,7 @@ namespace Pal.Client.Rendering void ResetLayer(ELayer layer); IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false); + + void DrawDebugItems(uint trapColor, uint hoardColor); } } diff --git a/Pal.Client/Rendering/RenderAdapter.cs b/Pal.Client/Rendering/RenderAdapter.cs index 338bb51..5ccb1a1 100644 --- a/Pal.Client/Rendering/RenderAdapter.cs +++ b/Pal.Client/Rendering/RenderAdapter.cs @@ -14,6 +14,7 @@ namespace Pal.Client.Rendering private readonly IPalacePalConfiguration _configuration; private IServiceScope? _renderScope; + private IRenderer _implementation; public RenderAdapter(IServiceScopeFactory serviceScopeFactory, ILogger logger, IPalacePalConfiguration configuration) @@ -22,14 +23,14 @@ namespace Pal.Client.Rendering _logger = logger; _configuration = configuration; - Implementation = Recreate(null); + _implementation = Recreate(null); } private IRenderer Recreate(ERenderer? currentRenderer) { ERenderer targetRenderer = _configuration.Renderer.SelectedRenderer; if (targetRenderer == currentRenderer) - return Implementation; + return _implementation; _renderScope?.Dispose(); @@ -43,30 +44,31 @@ namespace Pal.Client.Rendering public void ConfigUpdated() { - Implementation = Recreate(Implementation.GetConfigValue()); + _implementation = Recreate(_implementation.GetConfigValue()); } public void Dispose() => _renderScope?.Dispose(); - public IRenderer Implementation { get; private set; } - public void SetLayer(ELayer layer, IReadOnlyList elements) - => Implementation.SetLayer(layer, elements); + => _implementation.SetLayer(layer, elements); public void ResetLayer(ELayer layer) - => Implementation.ResetLayer(layer); + => _implementation.ResetLayer(layer); public IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false) - => Implementation.CreateElement(type, pos, color, fill); - - public void DrawLayers() - { - if (Implementation is SimpleRenderer sr) - sr.DrawLayers(); - } + => _implementation.CreateElement(type, pos, color, fill); public ERenderer GetConfigValue() => throw new NotImplementedException(); + + public void DrawDebugItems(uint trapColor, uint hoardColor) + => _implementation.DrawDebugItems(trapColor, hoardColor); + + public void DrawLayers() + { + if (_implementation is SimpleRenderer sr) + sr.DrawLayers(); + } } } diff --git a/Pal.Client/Rendering/RenderData.cs b/Pal.Client/Rendering/RenderData.cs index 2c4b802..41c64ed 100644 --- a/Pal.Client/Rendering/RenderData.cs +++ b/Pal.Client/Rendering/RenderData.cs @@ -3,5 +3,6 @@ internal static class RenderData { public static readonly uint ColorInvisible = 0; + public static readonly long TestLayerTimeout = 10_000; } } diff --git a/Pal.Client/Rendering/SimpleRenderer.cs b/Pal.Client/Rendering/SimpleRenderer.cs index 14fd0bc..d7724f5 100644 --- a/Pal.Client/Rendering/SimpleRenderer.cs +++ b/Pal.Client/Rendering/SimpleRenderer.cs @@ -66,6 +66,22 @@ namespace Pal.Client.Rendering }; } + public void DrawDebugItems(uint trapColor, uint hoardColor) + { + _layers[ELayer.Test] = new SimpleLayer + { + TerritoryType = _clientState.TerritoryType, + Elements = new List + { + (SimpleElement)CreateElement(Marker.EType.Trap, _clientState.LocalPlayer?.Position ?? default, + trapColor), + (SimpleElement)CreateElement(Marker.EType.Hoard, _clientState.LocalPlayer?.Position ?? default, + hoardColor) + }, + ExpiresAt = Environment.TickCount64 + RenderData.TestLayerTimeout + }; + } + public void DrawLayers() { if (_layers.Count == 0) @@ -80,15 +96,14 @@ namespace Pal.Client.Rendering ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.AlwaysUseWindowPadding)) { - ushort territoryType = _clientState.TerritoryType; - - foreach (var layer in _layers.Values.Where(l => l.TerritoryType == territoryType)) + foreach (var layer in _layers.Values.Where(l => l.IsValid(_clientState))) { foreach (var e in layer.Elements) Draw(e); } - foreach (var key in _layers.Where(l => l.Value.TerritoryType != territoryType).Select(l => l.Key) + foreach (var key in _layers.Where(l => !l.Value.IsValid(_clientState)) + .Select(l => l.Key) .ToList()) ResetLayer(key); @@ -159,6 +174,10 @@ namespace Pal.Client.Rendering { public required ushort TerritoryType { get; init; } public required IReadOnlyList Elements { get; init; } + public long ExpiresAt { get; init; } = long.MaxValue; + + public bool IsValid(ClientState clientState) => + TerritoryType == clientState.TerritoryType && ExpiresAt >= Environment.TickCount64; public void Dispose() { diff --git a/Pal.Client/Rendering/SplatoonRenderer.cs b/Pal.Client/Rendering/SplatoonRenderer.cs index a07d2f5..82dd7f2 100644 --- a/Pal.Client/Rendering/SplatoonRenderer.cs +++ b/Pal.Client/Rendering/SplatoonRenderer.cs @@ -1,10 +1,8 @@ -using Dalamud.Logging; -using Dalamud.Plugin; +using Dalamud.Plugin; using ECommons; using ECommons.Reflection; using ECommons.Schedulers; using ECommons.SplatoonAPI; -using ImGuiNET; using System; using System.Collections; using System.Collections.Generic; @@ -12,15 +10,13 @@ using System.Linq; using System.Numerics; using System.Reflection; using Dalamud.Game.ClientState; -using Dalamud.Game.Gui; using Microsoft.Extensions.Logging; using Pal.Client.Configuration; using Pal.Client.DependencyInjection; -using Pal.Client.Extensions; namespace Pal.Client.Rendering { - internal sealed class SplatoonRenderer : IRenderer, IDrawDebugItems, IDisposable + internal sealed class SplatoonRenderer : IRenderer, IDisposable { private const long OnTerritoryChange = -2; @@ -102,25 +98,24 @@ namespace Pal.Client.Rendering return new SplatoonElement(this, element); } - // TODO This should be handled differently - // - make SimpleRenderer implement this - // - return error (if any) instead of using chat here - public void DrawDebugItems(Vector4 trapColor, Vector4 hoardColor) + public void DrawDebugItems(uint trapColor, uint hoardColor) { try { Vector3? pos = _clientState.LocalPlayer?.Position; if (pos != null) { + ResetLayer(ELayer.Test); + var elements = new List { - CreateElement(Marker.EType.Trap, pos.Value, ImGui.ColorConvertFloat4ToU32(trapColor)), - CreateElement(Marker.EType.Hoard, pos.Value, ImGui.ColorConvertFloat4ToU32(hoardColor)), + CreateElement(Marker.EType.Trap, pos.Value, trapColor), + CreateElement(Marker.EType.Hoard, pos.Value, hoardColor), }; if (!Splatoon.AddDynamicElements(ToLayerName(ELayer.Test), elements.Cast().Select(x => x.Delegate).ToArray(), - new[] { Environment.TickCount64 + 10000 })) + new[] { Environment.TickCount64 + RenderData.TestLayerTimeout })) { _chat.Message("Could not draw markers :("); } diff --git a/Pal.Client/Windows/ConfigWindow.cs b/Pal.Client/Windows/ConfigWindow.cs index 17368c0..fed5212 100644 --- a/Pal.Client/Windows/ConfigWindow.cs +++ b/Pal.Client/Windows/ConfigWindow.cs @@ -363,12 +363,9 @@ namespace Pal.Client.Windows saveAndClose = ImGui.Button(Localization.SaveAndClose); ImGui.Separator(); - ImGui.Text(Localization.Config_Splatoon_Test); - ImGui.BeginDisabled(!(_renderAdapter.Implementation is IDrawDebugItems)); if (ImGui.Button(Localization.Config_Splatoon_DrawCircles)) - (_renderAdapter.Implementation as IDrawDebugItems)?.DrawDebugItems(_trapConfig.Color, - _hoardConfig.Color); - ImGui.EndDisabled(); + _renderAdapter.DrawDebugItems(ImGui.ColorConvertFloat4ToU32(_trapConfig.Color), + ImGui.ColorConvertFloat4ToU32(_hoardConfig.Color)); ImGui.EndTabItem(); }