using System.Collections;
using AibisDream.Utility;
using TMPro;
using UnityEngine;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
namespace AibisDream.MiniGame.Language
{
///
/// Drives the full-frame Huoshan expression screen while keeping readable text in TMP.
/// The sprite sheet uses the original 384x216 Aseprite timing and the existing world-space
/// Canvas remains the source of truth for interaction and dynamic language particles.
///
public sealed class ExpressionScreenPresentationController : MonoBehaviour
{
public enum ScreenState
{
Reset,
Deep,
Panel,
Output,
Floating,
Click,
FocusHidden
}
private const int DeepFirst = 0;
private const int DeepLast = 14;
private const int UiFlashFirst = 15;
private const int UiFlashLast = 29;
private const int StatusRevealFrame = 21;
private const int RingFirst = 30;
private const int RingLast = 40;
private const int OutputFirst = 41;
private const int OutputLast = 47;
private const int OutputTextRevealFrame = 45;
private const int FloatingFrame = 48;
private const int ClickFirst = 49;
private const int ClickLast = 52;
private const string ObjectiveLocalizationKey = "huoshan_expression_objective";
private const string OutputLocalizationKey = "huoshan_expression_output";
[Header("Frame Animation")]
[SerializeField] private SpriteRenderer screenRenderer;
[SerializeField] private Sprite[] frames = new Sprite[53];
[Header("Existing TMP / Interaction")]
[SerializeField] private TMP_Text integrationProgressText;
[SerializeField] private TMP_Text interferenceCountText;
[SerializeField] private Button outputButton;
[SerializeField] private TMP_FontAsset screenFont;
[Header("Objective TMP (384x216 reference)")]
[SerializeField] private Vector2 objectivePosition = new Vector2(-8.18f, -4.08f);
[SerializeField] private Vector2 objectiveSize = new Vector2(7.4f, 0.95f);
[SerializeField] private float objectiveFontSize = 0.28f;
[SerializeField] private Color objectiveColor = new Color(0.78f, 0.91f, 1f, 1f);
private int playbackGeneration;
private TMP_Text objectiveText;
private TMP_Text outputText;
private LocalizeStringEvent objectiveLocalization;
private LocalizeStringEvent outputLocalization;
private Material objectiveMaterial;
private ScreenState state = ScreenState.Reset;
public ScreenState State => state;
private void Awake()
{
ResolveSceneReferences();
ConfigureExistingUiAsTextOnly();
CreateObjectiveText();
BindStaticLocalization();
ResetImmediate();
}
private void ResolveSceneReferences()
{
if (screenRenderer == null)
{
SpriteRenderer[] renderers = GetComponentsInChildren(true);
foreach (SpriteRenderer candidate in renderers)
{
if (candidate != null && candidate.gameObject.name == "火山释放log界面")
{
screenRenderer = candidate;
break;
}
}
}
if (outputButton != null)
{
outputText = outputButton.GetComponentInChildren(true);
}
}
private void ConfigureExistingUiAsTextOnly()
{
MakeParentImageTransparent(integrationProgressText);
MakeParentImageTransparent(interferenceCountText);
if (integrationProgressText != null)
integrationProgressText.raycastTarget = false;
if (interferenceCountText != null)
interferenceCountText.raycastTarget = false;
if (outputButton != null && outputButton.targetGraphic != null)
{
Color color = outputButton.targetGraphic.color;
color.a = 0f;
outputButton.targetGraphic.color = color;
outputButton.targetGraphic.raycastTarget = true;
}
}
private static void MakeParentImageTransparent(TMP_Text text)
{
if (text == null || text.transform.parent == null)
return;
Image image = text.transform.parent.GetComponent();
if (image == null)
return;
Color color = image.color;
color.a = 0f;
image.color = color;
image.raycastTarget = false;
}
private void CreateObjectiveText()
{
Canvas canvas = integrationProgressText != null
? integrationProgressText.GetComponentInParent