Implemented end of game screen
This commit is contained in:
parent
ac10c8a2fc
commit
3651adbef8
23 changed files with 20035 additions and 19365 deletions
83
PuzzleGameProject/Assets/Scripts/UI/EndGameController.cs
Normal file
83
PuzzleGameProject/Assets/Scripts/UI/EndGameController.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using DungeonSelection;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class EndGameController : MonoBehaviour
|
||||
{
|
||||
public static event Action LeaveDungeonClicked;
|
||||
public static event Action<string, int> SaveScoreClicked;
|
||||
|
||||
private const string WIN_MESSAGE = "You Won";
|
||||
private const string DIE_MESSAGE = "You Died";
|
||||
[SerializeField] private Sprite diamondSprite;
|
||||
[SerializeField] private Sprite healthSprite;
|
||||
private Label _title;
|
||||
private Label _message;
|
||||
private Label _diamondPoints;
|
||||
private Label _pointsFromHealth;
|
||||
private Label _scoreSum;
|
||||
private VisualElement _diamondImageBox;
|
||||
private VisualElement _healthImageBox;
|
||||
private TextField _nameField;
|
||||
|
||||
private int _score;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
VisualElement root = GetComponent<UIDocument>().rootVisualElement;
|
||||
|
||||
Button save = root.Q<Button>("Save");
|
||||
save.clicked += HandleSaveClicked;
|
||||
Button close = root.Q<Button>("Close");
|
||||
close.clicked += HandleCloseClicked;
|
||||
_diamondPoints = root.Q<Label>("PointsFromDiamond");
|
||||
_pointsFromHealth = root.Q<Label>("PointsFromHealth");
|
||||
_scoreSum = root.Q<Label>("ScoreSum");
|
||||
_diamondImageBox = root.Q<VisualElement>("DiamondImageBox");
|
||||
_healthImageBox = root.Q<VisualElement>("HealthImageBox");
|
||||
_title = root.Q<Label>("Title");
|
||||
_message = root.Q<Label>("Message");
|
||||
_nameField = root.Q<TextField>("NameField");
|
||||
|
||||
Image diamondImage = new Image();
|
||||
diamondImage.image = diamondSprite.texture;
|
||||
diamondImage.scaleMode = ScaleMode.ScaleToFit;
|
||||
_diamondImageBox.Add(diamondImage);
|
||||
|
||||
Image healthImage = new Image();
|
||||
healthImage.image = healthSprite.texture;
|
||||
healthImage.scaleMode = ScaleMode.ScaleToFit;
|
||||
_healthImageBox.Add(healthImage);
|
||||
}
|
||||
|
||||
public void PopulateEndOfGamePopUp(EndOfGameEventArgs args)
|
||||
{
|
||||
if (args.Died)
|
||||
{
|
||||
_title.text = DIE_MESSAGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
_title.text = WIN_MESSAGE;
|
||||
}
|
||||
|
||||
_message.text = args.Message;
|
||||
_diamondPoints.text = $"{args.Diamonds} X {args.DiamondsMultiplier}";
|
||||
_pointsFromHealth.text = args.PointsFromHealth.ToString();
|
||||
_score = args.FinalScore;
|
||||
_scoreSum.text = _score.ToString();
|
||||
}
|
||||
|
||||
private void HandleCloseClicked()
|
||||
{
|
||||
LeaveDungeonClicked?.Invoke();
|
||||
}
|
||||
|
||||
private void HandleSaveClicked()
|
||||
{
|
||||
SaveScoreClicked?.Invoke(_nameField.value, _score);
|
||||
LeaveDungeonClicked?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad2e64e6a9233f54a90f666bbbc029d8
|
||||
|
|
@ -12,6 +12,7 @@ namespace UI
|
|||
[SerializeField] private GameObject canvas;
|
||||
[FormerlySerializedAs("hud")] [SerializeField] private InGameHUDController hudController;
|
||||
[SerializeField] private GameObject chestPopUpControllerGO;
|
||||
[SerializeField] private GameObject endOfGamePupUpGO;
|
||||
[SerializeField] private ChestPopUpController chestPopUpController;
|
||||
[SerializeField] private GameObject diceGO;
|
||||
[SerializeField] private DiceRoller diceRoller;
|
||||
|
|
@ -45,6 +46,8 @@ namespace UI
|
|||
|
||||
RoomRewards.ChestRewarded += HandleChestRewarded;
|
||||
|
||||
GameManager.EndOfGame += HandleEndOfGame;
|
||||
|
||||
chestPopUpController.BlackDieSelected += chestRewardSelection.HandleBlackDiceSelected;
|
||||
chestPopUpController.KeySelected += chestRewardSelection.HandleTorchSelected;
|
||||
chestPopUpController.ArmorAndDiamondSelected += chestRewardSelection.HandleDiamondAndLifeSelected;
|
||||
|
|
@ -136,5 +139,11 @@ namespace UI
|
|||
{
|
||||
chestPopUpControllerGO.SetActive(true);
|
||||
}
|
||||
|
||||
private void HandleEndOfGame(object sender, EndOfGameEventArgs args)
|
||||
{
|
||||
endOfGamePupUpGO.SetActive(true);
|
||||
endOfGamePupUpGO.GetComponent<EndGameController>().PopulateEndOfGamePopUp(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue