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

This commit is contained in:
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
.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() })
.OrderBy(m => m.distance)
.Take(5)

View File

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

View File

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

View File

@ -13,7 +13,7 @@ internal interface IRenderer
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);
}

View File

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

View File

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

View File

@ -52,13 +52,15 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
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);
return new SimpleElement
{
Type = type,
Position = pos + new Vector3(0, config.OffsetY, 0),
Enabled = enabled,
Color = color,
Radius = config.Radius,
Fill = fill,
@ -75,10 +77,12 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
(SimpleElement)CreateElement(
MemoryLocation.EType.Trap,
_clientState.LocalPlayer?.Position ?? default,
true,
trapColor),
(SimpleElement)CreateElement(
MemoryLocation.EType.Hoard,
_clientState.LocalPlayer?.Position ?? default,
true,
hoardColor)
},
ExpiresAt = Environment.TickCount64 + RenderData.TestLayerTimeout
@ -118,7 +122,7 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
private void Draw(SimpleElement e)
{
if (e.Color == RenderData.ColorInvisible)
if (!e.Enabled)
return;
switch (e.Type)
@ -194,6 +198,7 @@ internal sealed class SimpleRenderer : IRenderer, IDisposable
public bool IsValid { get; set; } = true;
public required MemoryLocation.EType Type { get; init; }
public required Vector3 Position { get; init; }
public required bool Enabled { get; set; }
public required uint Color { get; set; }
public required float Radius { 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)
=> $"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);
Element element = new Element(ElementType.CircleAtFixedCoordinates)
@ -96,6 +96,7 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
FillStep = 1,
color = color,
thicc = 2,
Enabled = enabled,
};
return new SplatoonElement(this, element);
}
@ -111,8 +112,8 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
var elements = new List<IRenderElement>
{
CreateElement(MemoryLocation.EType.Trap, pos.Value, trapColor),
CreateElement(MemoryLocation.EType.Hoard, pos.Value, hoardColor),
CreateElement(MemoryLocation.EType.Trap, pos.Value, true, trapColor),
CreateElement(MemoryLocation.EType.Hoard, pos.Value, true, hoardColor),
};
if (!Splatoon.AddDynamicElements(ToLayerName(ELayer.Test),
@ -186,10 +187,10 @@ internal sealed class SplatoonRenderer : IRenderer, IDisposable
public bool IsValid => !_renderer.IsDisposed && Delegate.IsValid();
public uint Color
public bool Enabled
{
get => Delegate.color;
set => Delegate.color = value;
get => Delegate.Enabled;
set => Delegate.Enabled = value;
}
}
}