SHA256
Add Hide Failed Decorations Option
This commit is contained in:
1 parent
d1ba5d5c18
commit
b66d774cb9
6 files changed
+123
No files matched your search
@@ -0,0 +1,93 @@
|
||||
using ADOFAIRenderer.Core;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Patch.Game;
|
||||
|
||||
/// <summary>
|
||||
/// Patches decoration rendering to hide decorations that failed to load (or are empty) and fell back to the default
|
||||
/// placeholder sprite (tree inside a circle) during a render when <c>AdvancedConfig.HideFailedDecorations</c> is enabled.
|
||||
/// </summary>
|
||||
public static class DecorationPatch
|
||||
{
|
||||
/// <summary>
|
||||
/// True while a render is loading or active and <c>HideFailedDecorations</c> is enabled in the configuration.
|
||||
/// </summary>
|
||||
public static bool IsEnabled =>
|
||||
RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration?.AdvancedConfig?.HideFailedDecorations == true;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given sprite is the default placeholder or not-found sprite of the decoration manager.
|
||||
/// </summary>
|
||||
public static bool IsPlaceholderSprite(Sprite? sprite, scrDecorationManager? manager = null)
|
||||
{
|
||||
if (!sprite) return false;
|
||||
manager ??= scrDecorationManager.instance;
|
||||
if (!manager) return false;
|
||||
|
||||
return sprite == manager.defaultSprite || (manager.notFoundSprite && sprite == manager.notFoundSprite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sweeps all visual decorations in <c>scrDecorationManager.instance.allDecorations</c> and clears any placeholder sprites.
|
||||
/// Called from <see cref="scnGamePatch.ProcessFloors"/> when <c>scnGame.Play</c> runs.
|
||||
/// </summary>
|
||||
public static void ProcessDecorations()
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
var manager = scrDecorationManager.instance;
|
||||
if (!manager || manager.allDecorations == null) return;
|
||||
|
||||
foreach (var dec in manager.allDecorations)
|
||||
{
|
||||
if (dec is scrVisualDecoration visualDec && visualDec.spriteRenderer)
|
||||
{
|
||||
if (IsPlaceholderSprite(visualDec.spriteRenderer.sprite, manager))
|
||||
{
|
||||
visualDec.SetSprite((Sprite)null!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prefix of <c>scrVisualDecoration.SetSprite(Sprite)</c>: replaces placeholder default/not-found sprites with null
|
||||
/// when <see cref="IsEnabled"/> is true.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(scrVisualDecoration), nameof(scrVisualDecoration.SetSprite), typeof(Sprite))]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static class VisualDecorationSetSpritePatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static void Prefix(scrVisualDecoration __instance, ref Sprite? sprite)
|
||||
{
|
||||
if (!IsEnabled || !sprite) return;
|
||||
|
||||
if (IsPlaceholderSprite(sprite, __instance.manager))
|
||||
{
|
||||
sprite = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prefix of <c>scrDecorationManager.ShowEmptyDecorations(bool)</c>: suppresses showing placeholder default sprites
|
||||
/// during render when <see cref="IsEnabled"/> is true.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(scrDecorationManager), nameof(scrDecorationManager.ShowEmptyDecorations))]
|
||||
public static class ShowEmptyDecorationsPatch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
public static bool Prefix(bool show)
|
||||
{
|
||||
if (show && IsEnabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ public static class scnGamePatch
|
||||
}
|
||||
}
|
||||
|
||||
DecorationPatch.ProcessDecorations();
|
||||
|
||||
var nonTile = RenderManager.Instance &&
|
||||
RenderManager.Instance.stage >= RenderStage.Load &&
|
||||
RenderManager.Instance.Configuration?.AdvancedConfig?.NonTile == true;
|
||||
|
||||
Reference in new issue
Block a user