ResultScreen.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Globalization;
  2. using DevilLink2.Gameplay;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace DevilLink2.UI
  6. {
  7. /// <summary>Reads a settled immutable result only. Never credits currency or advances progress.</summary>
  8. public sealed class ResultScreen : UIScreen
  9. {
  10. private readonly ScoreFeedbackVisuals visuals = new ScoreFeedbackVisuals();
  11. public int RewardEmphasisCount { get; private set; }
  12. public Text Heading { get; private set; }
  13. public Text ScoreLabel { get; private set; }
  14. public Text RewardsLabel { get; private set; }
  15. public Button NextButton { get; private set; }
  16. public Button RetryButton { get; private set; }
  17. public Button LobbyButton { get; private set; }
  18. public GameResult Data { get; private set; }
  19. public int PresentationCount { get; private set; }
  20. public void Configure(Text heading, Text score, Text rewards, Button next, Button retry, Button lobby)
  21. { Heading = heading; ScoreLabel = score; RewardsLabel = rewards; NextButton = next; RetryButton = retry; LobbyButton = lobby; Clear(); }
  22. public void Present(GameResult result)
  23. {
  24. if (result == null || !result.IsSettled || Data?.SessionId == result.SessionId) return;
  25. Data = result; PresentationCount++;
  26. bool victory = result.Outcome == GameOutcome.Victory;
  27. Heading.text = (victory ? "LEVEL CLEARED" : "TIME UP") + "\n" + UIManager.ModeName(result.GameMode) + " / " + result.LevelNumber;
  28. Heading.color = victory ? UIBuilder.LightGold : UIBuilder.Hex("FF8EA0");
  29. ScoreLabel.text = "FINAL SCORE\n" + result.FinalScore.ToString("N0", CultureInfo.InvariantCulture);
  30. RewardsLabel.text = victory ? "+" + result.CoinReward.ToString("N0", CultureInfo.InvariantCulture) + " COINS / +" + result.SpinTicketReward + " SPIN TICKET" : "";
  31. if (result.RewardCapacityExceeded) RewardsLabel.text = "RESOURCE LIMIT · REWARDS NOT ADDED";
  32. RewardsLabel.gameObject.SetActive(victory); NextButton.gameObject.SetActive(victory);
  33. NextButton.GetComponentInChildren<Text>(true).text = result.LevelNumber == LevelCatalog.LevelsPerMode ? "REPLAY LEVEL 20" : "NEXT LEVEL";
  34. transform.SetAsLastSibling(); SetVisible(true);
  35. if (victory) { visuals.Emphasize(ScoreLabel, .055f); visuals.Emphasize(RewardsLabel, .04f); RewardEmphasisCount++; }
  36. }
  37. public void Clear() { visuals.Clear(); Data = null; SetVisible(false); }
  38. private void OnDisable() { visuals.Clear(); }
  39. private void OnDestroy() { visuals.Dispose(); }
  40. }
  41. }