using System.Globalization;
using DevilLink2.Gameplay;
using UnityEngine;
using UnityEngine.UI;
namespace DevilLink2.UI
{
/// Reads a settled immutable result only. Never credits currency or advances progress.
public sealed class ResultScreen : UIScreen
{
private readonly ScoreFeedbackVisuals visuals = new ScoreFeedbackVisuals();
public int RewardEmphasisCount { get; private set; }
public Text Heading { get; private set; }
public Text ScoreLabel { get; private set; }
public Text RewardsLabel { get; private set; }
public Button NextButton { get; private set; }
public Button RetryButton { get; private set; }
public Button LobbyButton { get; private set; }
public GameResult Data { get; private set; }
public int PresentationCount { get; private set; }
public void Configure(Text heading, Text score, Text rewards, Button next, Button retry, Button lobby)
{ Heading = heading; ScoreLabel = score; RewardsLabel = rewards; NextButton = next; RetryButton = retry; LobbyButton = lobby; Clear(); }
public void Present(GameResult result)
{
if (result == null || !result.IsSettled || Data?.SessionId == result.SessionId) return;
Data = result; PresentationCount++;
bool victory = result.Outcome == GameOutcome.Victory;
Heading.text = (victory ? "LEVEL CLEARED" : "TIME UP") + "\n" + UIManager.ModeName(result.GameMode) + " / " + result.LevelNumber;
Heading.color = victory ? UIBuilder.LightGold : UIBuilder.Hex("FF8EA0");
ScoreLabel.text = "FINAL SCORE\n" + result.FinalScore.ToString("N0", CultureInfo.InvariantCulture);
RewardsLabel.text = victory ? "+" + result.CoinReward.ToString("N0", CultureInfo.InvariantCulture) + " COINS / +" + result.SpinTicketReward + " SPIN TICKET" : "";
if (result.RewardCapacityExceeded) RewardsLabel.text = "RESOURCE LIMIT ยท REWARDS NOT ADDED";
RewardsLabel.gameObject.SetActive(victory); NextButton.gameObject.SetActive(victory);
NextButton.GetComponentInChildren(true).text = result.LevelNumber == LevelCatalog.LevelsPerMode ? "REPLAY LEVEL 20" : "NEXT LEVEL";
transform.SetAsLastSibling(); SetVisible(true);
if (victory) { visuals.Emphasize(ScoreLabel, .055f); visuals.Emphasize(RewardsLabel, .04f); RewardEmphasisCount++; }
}
public void Clear() { visuals.Clear(); Data = null; SetVisible(false); }
private void OnDisable() { visuals.Clear(); }
private void OnDestroy() { visuals.Dispose(); }
}
}