DI: Support debug items in SimpleRenderer, remove IDrawDebugItems
This commit is contained in:
parent
5419f51942
commit
adddbc452c
10
Pal.Client/Properties/Localization.Designer.cs
generated
10
Pal.Client/Properties/Localization.Designer.cs
generated
@ -1,7 +1,6 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// 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
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@ -385,15 +384,6 @@ namespace Pal.Client.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Splatoon Test:.
|
|
||||||
/// </summary>
|
|
||||||
internal static string Config_Splatoon_Test {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("Config_Splatoon_Test", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Start Export.
|
/// Looks up a localized string similar to Start Export.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -228,9 +228,6 @@ Il n'y a pas de synchronisation avec les autres joueurs ni de sauvegarde entre l
|
|||||||
<data name="Config_Renderer_Simple_Hint" xml:space="preserve">
|
<data name="Config_Renderer_Simple_Hint" xml:space="preserve">
|
||||||
<value>Expérimental</value>
|
<value>Expérimental</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Config_Splatoon_Test" xml:space="preserve">
|
|
||||||
<value>Test de Splatoon :</value>
|
|
||||||
</data>
|
|
||||||
<data name="Config_Splatoon_DrawCircles" xml:space="preserve">
|
<data name="Config_Splatoon_DrawCircles" xml:space="preserve">
|
||||||
<value>Dessiner les marqueurs des pièges et coffres autour de soi</value>
|
<value>Dessiner les marqueurs des pièges et coffres autour de soi</value>
|
||||||
<comment>To test the Splatoon integration, you can draw markers around yourself.</comment>
|
<comment>To test the Splatoon integration, you can draw markers around yourself.</comment>
|
||||||
|
@ -227,9 +227,6 @@
|
|||||||
<data name="Config_Renderer_Simple_Hint" xml:space="preserve">
|
<data name="Config_Renderer_Simple_Hint" xml:space="preserve">
|
||||||
<value>試験的機能</value>
|
<value>試験的機能</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Config_Splatoon_Test" xml:space="preserve">
|
|
||||||
<value>Splatoonのテスト:</value>
|
|
||||||
</data>
|
|
||||||
<data name="Config_Splatoon_DrawCircles" xml:space="preserve">
|
<data name="Config_Splatoon_DrawCircles" xml:space="preserve">
|
||||||
<value>自分の周りにトラップと宝箱を表示する</value>
|
<value>自分の周りにトラップと宝箱を表示する</value>
|
||||||
<comment>To test the Splatoon integration, you can draw markers around yourself.</comment>
|
<comment>To test the Splatoon integration, you can draw markers around yourself.</comment>
|
||||||
|
@ -239,9 +239,6 @@ This is not synchronized with other players and not saved between floors/runs.</
|
|||||||
<data name="Config_Renderer_Simple_Hint" xml:space="preserve">
|
<data name="Config_Renderer_Simple_Hint" xml:space="preserve">
|
||||||
<value>experimental</value>
|
<value>experimental</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Config_Splatoon_Test" xml:space="preserve">
|
|
||||||
<value>Splatoon Test:</value>
|
|
||||||
</data>
|
|
||||||
<data name="Config_Splatoon_DrawCircles" xml:space="preserve">
|
<data name="Config_Splatoon_DrawCircles" xml:space="preserve">
|
||||||
<value>Draw trap & coffer circles around self</value>
|
<value>Draw trap & coffer circles around self</value>
|
||||||
<comment>To test the Splatoon integration, you can draw markers around yourself.</comment>
|
<comment>To test the Splatoon integration, you can draw markers around yourself.</comment>
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
using System.Numerics;
|
|
||||||
|
|
||||||
namespace Pal.Client.Rendering
|
|
||||||
{
|
|
||||||
internal interface IDrawDebugItems
|
|
||||||
{
|
|
||||||
void DrawDebugItems(Vector4 trapColor, Vector4 hoardColor);
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,5 +13,7 @@ namespace Pal.Client.Rendering
|
|||||||
void ResetLayer(ELayer layer);
|
void ResetLayer(ELayer layer);
|
||||||
|
|
||||||
IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false);
|
IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false);
|
||||||
|
|
||||||
|
void DrawDebugItems(uint trapColor, uint hoardColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ namespace Pal.Client.Rendering
|
|||||||
private readonly IPalacePalConfiguration _configuration;
|
private readonly IPalacePalConfiguration _configuration;
|
||||||
|
|
||||||
private IServiceScope? _renderScope;
|
private IServiceScope? _renderScope;
|
||||||
|
private IRenderer _implementation;
|
||||||
|
|
||||||
public RenderAdapter(IServiceScopeFactory serviceScopeFactory, ILogger<RenderAdapter> logger,
|
public RenderAdapter(IServiceScopeFactory serviceScopeFactory, ILogger<RenderAdapter> logger,
|
||||||
IPalacePalConfiguration configuration)
|
IPalacePalConfiguration configuration)
|
||||||
@ -22,14 +23,14 @@ namespace Pal.Client.Rendering
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
|
||||||
Implementation = Recreate(null);
|
_implementation = Recreate(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRenderer Recreate(ERenderer? currentRenderer)
|
private IRenderer Recreate(ERenderer? currentRenderer)
|
||||||
{
|
{
|
||||||
ERenderer targetRenderer = _configuration.Renderer.SelectedRenderer;
|
ERenderer targetRenderer = _configuration.Renderer.SelectedRenderer;
|
||||||
if (targetRenderer == currentRenderer)
|
if (targetRenderer == currentRenderer)
|
||||||
return Implementation;
|
return _implementation;
|
||||||
|
|
||||||
_renderScope?.Dispose();
|
_renderScope?.Dispose();
|
||||||
|
|
||||||
@ -43,30 +44,31 @@ namespace Pal.Client.Rendering
|
|||||||
|
|
||||||
public void ConfigUpdated()
|
public void ConfigUpdated()
|
||||||
{
|
{
|
||||||
Implementation = Recreate(Implementation.GetConfigValue());
|
_implementation = Recreate(_implementation.GetConfigValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
=> _renderScope?.Dispose();
|
=> _renderScope?.Dispose();
|
||||||
|
|
||||||
public IRenderer Implementation { get; private set; }
|
|
||||||
|
|
||||||
public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements)
|
public void SetLayer(ELayer layer, IReadOnlyList<IRenderElement> elements)
|
||||||
=> Implementation.SetLayer(layer, elements);
|
=> _implementation.SetLayer(layer, elements);
|
||||||
|
|
||||||
public void ResetLayer(ELayer layer)
|
public void ResetLayer(ELayer layer)
|
||||||
=> Implementation.ResetLayer(layer);
|
=> _implementation.ResetLayer(layer);
|
||||||
|
|
||||||
public IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false)
|
public IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false)
|
||||||
=> Implementation.CreateElement(type, pos, color, fill);
|
=> _implementation.CreateElement(type, pos, color, fill);
|
||||||
|
|
||||||
public void DrawLayers()
|
|
||||||
{
|
|
||||||
if (Implementation is SimpleRenderer sr)
|
|
||||||
sr.DrawLayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ERenderer GetConfigValue()
|
public ERenderer GetConfigValue()
|
||||||
=> throw new NotImplementedException();
|
=> throw new NotImplementedException();
|
||||||
|
|
||||||
|
public void DrawDebugItems(uint trapColor, uint hoardColor)
|
||||||
|
=> _implementation.DrawDebugItems(trapColor, hoardColor);
|
||||||
|
|
||||||
|
public void DrawLayers()
|
||||||
|
{
|
||||||
|
if (_implementation is SimpleRenderer sr)
|
||||||
|
sr.DrawLayers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
internal static class RenderData
|
internal static class RenderData
|
||||||
{
|
{
|
||||||
public static readonly uint ColorInvisible = 0;
|
public static readonly uint ColorInvisible = 0;
|
||||||
|
public static readonly long TestLayerTimeout = 10_000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
{
|
||||||
|
(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()
|
public void DrawLayers()
|
||||||
{
|
{
|
||||||
if (_layers.Count == 0)
|
if (_layers.Count == 0)
|
||||||
@ -80,15 +96,14 @@ namespace Pal.Client.Rendering
|
|||||||
ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoSavedSettings |
|
ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoSavedSettings |
|
||||||
ImGuiWindowFlags.AlwaysUseWindowPadding))
|
ImGuiWindowFlags.AlwaysUseWindowPadding))
|
||||||
{
|
{
|
||||||
ushort territoryType = _clientState.TerritoryType;
|
foreach (var layer in _layers.Values.Where(l => l.IsValid(_clientState)))
|
||||||
|
|
||||||
foreach (var layer in _layers.Values.Where(l => l.TerritoryType == territoryType))
|
|
||||||
{
|
{
|
||||||
foreach (var e in layer.Elements)
|
foreach (var e in layer.Elements)
|
||||||
Draw(e);
|
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())
|
.ToList())
|
||||||
ResetLayer(key);
|
ResetLayer(key);
|
||||||
|
|
||||||
@ -159,6 +174,10 @@ namespace Pal.Client.Rendering
|
|||||||
{
|
{
|
||||||
public required ushort TerritoryType { get; init; }
|
public required ushort TerritoryType { get; init; }
|
||||||
public required IReadOnlyList<SimpleElement> Elements { get; init; }
|
public required IReadOnlyList<SimpleElement> Elements { get; init; }
|
||||||
|
public long ExpiresAt { get; init; } = long.MaxValue;
|
||||||
|
|
||||||
|
public bool IsValid(ClientState clientState) =>
|
||||||
|
TerritoryType == clientState.TerritoryType && ExpiresAt >= Environment.TickCount64;
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
using Dalamud.Logging;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin;
|
|
||||||
using ECommons;
|
using ECommons;
|
||||||
using ECommons.Reflection;
|
using ECommons.Reflection;
|
||||||
using ECommons.Schedulers;
|
using ECommons.Schedulers;
|
||||||
using ECommons.SplatoonAPI;
|
using ECommons.SplatoonAPI;
|
||||||
using ImGuiNET;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -12,15 +10,13 @@ using System.Linq;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Dalamud.Game.ClientState;
|
using Dalamud.Game.ClientState;
|
||||||
using Dalamud.Game.Gui;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Pal.Client.Configuration;
|
using Pal.Client.Configuration;
|
||||||
using Pal.Client.DependencyInjection;
|
using Pal.Client.DependencyInjection;
|
||||||
using Pal.Client.Extensions;
|
|
||||||
|
|
||||||
namespace Pal.Client.Rendering
|
namespace Pal.Client.Rendering
|
||||||
{
|
{
|
||||||
internal sealed class SplatoonRenderer : IRenderer, IDrawDebugItems, IDisposable
|
internal sealed class SplatoonRenderer : IRenderer, IDisposable
|
||||||
{
|
{
|
||||||
private const long OnTerritoryChange = -2;
|
private const long OnTerritoryChange = -2;
|
||||||
|
|
||||||
@ -102,25 +98,24 @@ namespace Pal.Client.Rendering
|
|||||||
return new SplatoonElement(this, element);
|
return new SplatoonElement(this, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO This should be handled differently
|
public void DrawDebugItems(uint trapColor, uint hoardColor)
|
||||||
// - make SimpleRenderer implement this
|
|
||||||
// - return error (if any) instead of using chat here
|
|
||||||
public void DrawDebugItems(Vector4 trapColor, Vector4 hoardColor)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Vector3? pos = _clientState.LocalPlayer?.Position;
|
Vector3? pos = _clientState.LocalPlayer?.Position;
|
||||||
if (pos != null)
|
if (pos != null)
|
||||||
{
|
{
|
||||||
|
ResetLayer(ELayer.Test);
|
||||||
|
|
||||||
var elements = new List<IRenderElement>
|
var elements = new List<IRenderElement>
|
||||||
{
|
{
|
||||||
CreateElement(Marker.EType.Trap, pos.Value, ImGui.ColorConvertFloat4ToU32(trapColor)),
|
CreateElement(Marker.EType.Trap, pos.Value, trapColor),
|
||||||
CreateElement(Marker.EType.Hoard, pos.Value, ImGui.ColorConvertFloat4ToU32(hoardColor)),
|
CreateElement(Marker.EType.Hoard, pos.Value, hoardColor),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!Splatoon.AddDynamicElements(ToLayerName(ELayer.Test),
|
if (!Splatoon.AddDynamicElements(ToLayerName(ELayer.Test),
|
||||||
elements.Cast<SplatoonElement>().Select(x => x.Delegate).ToArray(),
|
elements.Cast<SplatoonElement>().Select(x => x.Delegate).ToArray(),
|
||||||
new[] { Environment.TickCount64 + 10000 }))
|
new[] { Environment.TickCount64 + RenderData.TestLayerTimeout }))
|
||||||
{
|
{
|
||||||
_chat.Message("Could not draw markers :(");
|
_chat.Message("Could not draw markers :(");
|
||||||
}
|
}
|
||||||
|
@ -363,12 +363,9 @@ namespace Pal.Client.Windows
|
|||||||
saveAndClose = ImGui.Button(Localization.SaveAndClose);
|
saveAndClose = ImGui.Button(Localization.SaveAndClose);
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
ImGui.Text(Localization.Config_Splatoon_Test);
|
|
||||||
ImGui.BeginDisabled(!(_renderAdapter.Implementation is IDrawDebugItems));
|
|
||||||
if (ImGui.Button(Localization.Config_Splatoon_DrawCircles))
|
if (ImGui.Button(Localization.Config_Splatoon_DrawCircles))
|
||||||
(_renderAdapter.Implementation as IDrawDebugItems)?.DrawDebugItems(_trapConfig.Color,
|
_renderAdapter.DrawDebugItems(ImGui.ColorConvertFloat4ToU32(_trapConfig.Color),
|
||||||
_hoardConfig.Color);
|
ImGui.ColorConvertFloat4ToU32(_hoardConfig.Color));
|
||||||
ImGui.EndDisabled();
|
|
||||||
|
|
||||||
ImGui.EndTabItem();
|
ImGui.EndTabItem();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user