Render: Use enabled instead of color for showing/hiding elements

rendering
Liza 2023-11-26 20:13:17 +01:00
parent 309edfcd17
commit 964119cfd2
Signed by: liza
GPG Key ID: 7199F8D727D55F67
8 changed files with 34 additions and 39 deletions

View File

@ -50,7 +50,7 @@ internal sealed class PalNearCommand : ISubCommand
var nearbyMarkers = state.Locations var nearbyMarkers = state.Locations
.Where(m => predicate(m)) .Where(m => predicate(m))
.Where(m => m.RenderElement != null && m.RenderElement.Color != RenderData.ColorInvisible) .Where(m => m.RenderElement != null && m.RenderElement.Enabled)
.Select(m => new { m, distance = (playerPosition.Value - m.Position).Length() }) .Select(m => new { m, distance = (playerPosition.Value - m.Position).Length() })
.OrderBy(m => m.distance) .OrderBy(m => m.distance)
.Take(5) .Take(5)

View File

@ -175,12 +175,12 @@ internal sealed class FrameworkService : IDisposable
{ {
foreach (var location in memoryTerritory.Locations) foreach (var location in memoryTerritory.Locations)
{ {
uint desiredColor = DetermineColor(location, visibleLocations); bool isEnabled = DetermineVisibility(location, visibleLocations);
if (location.RenderElement == null || !location.RenderElement.IsValid) if (location.RenderElement == null || !location.RenderElement.IsValid)
return true; return true;
if (location.RenderElement.Color != desiredColor) if (location.RenderElement.Enabled != isEnabled)
location.RenderElement.Color = desiredColor; location.RenderElement.Enabled = isEnabled;
} }
} }
catch (Exception e) catch (Exception e)
@ -225,12 +225,12 @@ internal sealed class FrameworkService : IDisposable
{ {
if (location.Type == MemoryLocation.EType.Trap) if (location.Type == MemoryLocation.EType.Trap)
{ {
CreateRenderElement(location, elements, DetermineColor(location, visibleMarkers), CreateRenderElement(location, elements, DetermineVisibility(location, visibleMarkers),
_configuration.DeepDungeons.Traps); _configuration.DeepDungeons.Traps);
} }
else if (location.Type == MemoryLocation.EType.Hoard) else if (location.Type == MemoryLocation.EType.Hoard)
{ {
CreateRenderElement(location, elements, DetermineColor(location, visibleMarkers), CreateRenderElement(location, elements, DetermineVisibility(location, visibleMarkers),
_configuration.DeepDungeons.HoardCoffers); _configuration.DeepDungeons.HoardCoffers);
} }
} }
@ -251,14 +251,12 @@ internal sealed class FrameworkService : IDisposable
if (location.Type == MemoryLocation.EType.SilverCoffer && if (location.Type == MemoryLocation.EType.SilverCoffer &&
_configuration.DeepDungeons.SilverCoffers.Show) _configuration.DeepDungeons.SilverCoffers.Show)
{ {
CreateRenderElement(location, elements, DetermineColor(location), CreateRenderElement(location, elements, true, _configuration.DeepDungeons.SilverCoffers);
_configuration.DeepDungeons.SilverCoffers);
} }
else if (location.Type == MemoryLocation.EType.GoldCoffer && else if (location.Type == MemoryLocation.EType.GoldCoffer &&
_configuration.DeepDungeons.GoldCoffers.Show) _configuration.DeepDungeons.GoldCoffers.Show)
{ {
CreateRenderElement(location, elements, DetermineColor(location), CreateRenderElement(location, elements, true, _configuration.DeepDungeons.GoldCoffers);
_configuration.DeepDungeons.GoldCoffers);
} }
} }
@ -268,7 +266,7 @@ internal sealed class FrameworkService : IDisposable
_renderAdapter.SetLayer(ELayer.RegularCoffers, elements); _renderAdapter.SetLayer(ELayer.RegularCoffers, elements);
} }
private uint DetermineColor(PersistentLocation location, IReadOnlyList<PersistentLocation> visibleLocations) private bool DetermineVisibility(PersistentLocation location, IReadOnlyList<PersistentLocation> visibleLocations)
{ {
switch (location.Type) switch (location.Type)
{ {
@ -276,34 +274,25 @@ internal sealed class FrameworkService : IDisposable
when _territoryState.PomanderOfSight == PomanderState.Inactive || when _territoryState.PomanderOfSight == PomanderState.Inactive ||
!_configuration.DeepDungeons.Traps.OnlyVisibleAfterPomander || !_configuration.DeepDungeons.Traps.OnlyVisibleAfterPomander ||
visibleLocations.Any(x => x == location): visibleLocations.Any(x => x == location):
return _configuration.DeepDungeons.Traps.Color; return true;
case MemoryLocation.EType.Hoard case MemoryLocation.EType.Hoard
when _territoryState.PomanderOfIntuition == PomanderState.Inactive || when _territoryState.PomanderOfIntuition == PomanderState.Inactive ||
!_configuration.DeepDungeons.HoardCoffers.OnlyVisibleAfterPomander || !_configuration.DeepDungeons.HoardCoffers.OnlyVisibleAfterPomander ||
visibleLocations.Any(x => x == location): visibleLocations.Any(x => x == location):
return _configuration.DeepDungeons.HoardCoffers.Color; return true;
default: default:
return RenderData.ColorInvisible; return false;
} }
} }
private uint DetermineColor(EphemeralLocation location) private void CreateRenderElement(MemoryLocation location, List<IRenderElement> elements, bool enabled,
{
return location.Type switch
{
MemoryLocation.EType.SilverCoffer => _configuration.DeepDungeons.SilverCoffers.Color,
MemoryLocation.EType.GoldCoffer => _configuration.DeepDungeons.GoldCoffers.Color,
_ => RenderData.ColorInvisible
};
}
private void CreateRenderElement(MemoryLocation location, List<IRenderElement> elements, uint color,
MarkerConfiguration config) MarkerConfiguration config)
{ {
if (!config.Show) if (!config.Show)
return; return;
var element = _renderAdapter.CreateElement(location.Type, location.Position, color, config.Fill); var element =
_renderAdapter.CreateElement(location.Type, location.Position, enabled, config.Color, config.Fill);
location.RenderElement = element; location.RenderElement = element;
elements.Add(element); elements.Add(element);
} }

View File

@ -4,5 +4,5 @@ public interface IRenderElement
{ {
bool IsValid { get; } bool IsValid { get; }
uint Color { get; set; } bool Enabled { get; set; }
} }

View File

@ -13,7 +13,7 @@ internal interface IRenderer
void ResetLayer(ELayer layer); void ResetLayer(ELayer layer);
IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, uint color, bool fill = false); IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, bool enabled, uint color, bool fill = false);
void DrawDebugItems(uint trapColor, uint hoardColor); void DrawDebugItems(uint trapColor, uint hoardColor);
} }

View File

@ -60,8 +60,9 @@ internal sealed class RenderAdapter : IRenderer, IDisposable
public void ResetLayer(ELayer layer) public void ResetLayer(ELayer layer)
=> _implementation.ResetLayer(layer); => _implementation.ResetLayer(layer);
public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, uint color, bool fill = false) public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, bool enabled, uint color,
=> _implementation.CreateElement(type, pos, color, fill); bool fill = false)
=> _implementation.CreateElement(type, pos, enabled, color, fill);
public ERenderer GetConfigValue() public ERenderer GetConfigValue()
=> throw new NotImplementedException(); => throw new NotImplementedException();

View File

@ -2,6 +2,5 @@
internal static class RenderData internal static class RenderData
{ {
public static readonly uint ColorInvisible = 0;
public static readonly long TestLayerTimeout = 10_000; public static readonly long TestLayerTimeout = 10_000;
} }

View File

@ -52,13 +52,15 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
l.Dispose(); l.Dispose();
} }
public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, uint color, bool fill = false) public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, bool enabled, uint color,
bool fill = false)
{ {
var config = MarkerConfig.ForType(type); var config = MarkerConfig.ForType(type);
return new SimpleElement return new SimpleElement
{ {
Type = type, Type = type,
Position = pos + new Vector3(0, config.OffsetY, 0), Position = pos + new Vector3(0, config.OffsetY, 0),
Enabled = enabled,
Color = color, Color = color,
Radius = config.Radius, Radius = config.Radius,
Fill = fill, Fill = fill,
@ -75,10 +77,12 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
(SimpleElement)CreateElement( (SimpleElement)CreateElement(
MemoryLocation.EType.Trap, MemoryLocation.EType.Trap,
_clientState.LocalPlayer?.Position ?? default, _clientState.LocalPlayer?.Position ?? default,
true,
trapColor), trapColor),
(SimpleElement)CreateElement( (SimpleElement)CreateElement(
MemoryLocation.EType.Hoard, MemoryLocation.EType.Hoard,
_clientState.LocalPlayer?.Position ?? default, _clientState.LocalPlayer?.Position ?? default,
true,
hoardColor) hoardColor)
}, },
ExpiresAt = Environment.TickCount64 + RenderData.TestLayerTimeout ExpiresAt = Environment.TickCount64 + RenderData.TestLayerTimeout
@ -118,7 +122,7 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
private void Draw(SimpleElement e) private void Draw(SimpleElement e)
{ {
if (e.Color == RenderData.ColorInvisible) if (!e.Enabled)
return; return;
switch (e.Type) switch (e.Type)
@ -194,6 +198,7 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
public bool IsValid { get; set; } = true; public bool IsValid { get; set; } = true;
public required MemoryLocation.EType Type { get; init; } public required MemoryLocation.EType Type { get; init; }
public required Vector3 Position { get; init; } public required Vector3 Position { get; init; }
public required bool Enabled { get; set; }
public required uint Color { get; set; } public required uint Color { get; set; }
public required float Radius { get; init; } public required float Radius { get; init; }
public required bool Fill { get; init; } public required bool Fill { get; init; }

View File

@ -80,7 +80,7 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
private string ToLayerName(ELayer layer) private string ToLayerName(ELayer layer)
=> $"PalacePal.{layer}"; => $"PalacePal.{layer}";
public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, uint color, bool fill = false) public IRenderElement CreateElement(MemoryLocation.EType type, Vector3 pos, bool enabled, uint color, bool fill = false)
{ {
MarkerConfig config = MarkerConfig.ForType(type); MarkerConfig config = MarkerConfig.ForType(type);
Element element = new Element(ElementType.CircleAtFixedCoordinates) Element element = new Element(ElementType.CircleAtFixedCoordinates)
@ -96,6 +96,7 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
FillStep = 1, FillStep = 1,
color = color, color = color,
thicc = 2, thicc = 2,
Enabled = enabled,
}; };
return new SplatoonElement(this, element); return new SplatoonElement(this, element);
} }
@ -111,8 +112,8 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
var elements = new List<IRenderElement> var elements = new List<IRenderElement>
{ {
CreateElement(MemoryLocation.EType.Trap, pos.Value, trapColor), CreateElement(MemoryLocation.EType.Trap, pos.Value, true, trapColor),
CreateElement(MemoryLocation.EType.Hoard, pos.Value, hoardColor), CreateElement(MemoryLocation.EType.Hoard, pos.Value, true, hoardColor),
}; };
if (!Splatoon.AddDynamicElements(ToLayerName(ELayer.Test), if (!Splatoon.AddDynamicElements(ToLayerName(ELayer.Test),
@ -186,10 +187,10 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
public bool IsValid => !_renderer.IsDisposed && Delegate.IsValid(); public bool IsValid => !_renderer.IsDisposed && Delegate.IsValid();
public uint Color public bool Enabled
{ {
get => Delegate.color; get => Delegate.Enabled;
set => Delegate.color = value; set => Delegate.Enabled = value;
} }
} }
} }