111 lines
3.3 KiB
C#
111 lines
3.3 KiB
C#
using System.Text;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WarGame.Managers;
|
|
|
|
namespace WarGame.UI
|
|
{
|
|
public class BattleResultUI : MonoBehaviour
|
|
{
|
|
[Header("UI Panels")]
|
|
[SerializeField] private GameObject resultPanel;
|
|
|
|
[Header("Text Displays")]
|
|
[SerializeField] private TMP_Text resultTitleText;
|
|
[SerializeField] private TMP_Text goldRewardText;
|
|
[SerializeField] private TMP_Text casualtiesText;
|
|
[SerializeField] private TMP_Text levelUpReportText;
|
|
|
|
[Header("Buttons")]
|
|
[SerializeField] private Button continueButton;
|
|
|
|
private void Start()
|
|
{
|
|
if (resultPanel != null)
|
|
{
|
|
resultPanel.SetActive(false);
|
|
}
|
|
|
|
if (BattleManager.Instance != null)
|
|
{
|
|
BattleManager.Instance.OnBattleCompleted += ShowBattleResults;
|
|
}
|
|
|
|
if (continueButton != null)
|
|
{
|
|
continueButton.onClick.AddListener(OnContinueClicked);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (BattleManager.Instance != null)
|
|
{
|
|
BattleManager.Instance.OnBattleCompleted -= ShowBattleResults;
|
|
}
|
|
}
|
|
|
|
public void ShowBattleResults(BattleResultData results)
|
|
{
|
|
if (resultPanel == null) return;
|
|
resultPanel.SetActive(true);
|
|
|
|
if (resultTitleText != null)
|
|
{
|
|
if (results.isVictory)
|
|
{
|
|
resultTitleText.text = "VICTORY!";
|
|
resultTitleText.color = new Color(0.2f, 1f, 0.4f);
|
|
}
|
|
else
|
|
{
|
|
resultTitleText.text = "DEFEATED IN BATTLE";
|
|
resultTitleText.color = new Color(1f, 0.25f, 0.25f);
|
|
}
|
|
}
|
|
|
|
if (goldRewardText != null)
|
|
{
|
|
goldRewardText.text = $"Gold Earned: +{results.goldEarned}";
|
|
}
|
|
|
|
if (casualtiesText != null)
|
|
{
|
|
casualtiesText.text = $"Surviving Units: {results.survivingPlayerUnits} / {results.totalPlayerUnits}\nEnemies Defeated: {results.enemyCasualties}";
|
|
}
|
|
|
|
if (levelUpReportText != null)
|
|
{
|
|
if (results.levelUpReports != null && results.levelUpReports.Count > 0)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("<b>UNIT LEVEL UPS & TACTICS:</b>");
|
|
foreach (var report in results.levelUpReports)
|
|
{
|
|
sb.AppendLine($"• {report.unitName}: Reached Level {report.newLevel}!");
|
|
}
|
|
levelUpReportText.text = sb.ToString();
|
|
}
|
|
else
|
|
{
|
|
levelUpReportText.text = "All surviving units gained experience.";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnContinueClicked()
|
|
{
|
|
if (resultPanel != null)
|
|
{
|
|
resultPanel.SetActive(false);
|
|
}
|
|
|
|
if (BattleManager.Instance != null)
|
|
{
|
|
BattleManager.Instance.ContinueToNextRound();
|
|
}
|
|
}
|
|
}
|
|
}
|