-
-
Save Syjgin/34c83f77e41000b9d0500c0aa141089c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using Zenject; | |
using Components; | |
using UnityEngine.Localization; | |
using Constants; | |
using Data; | |
using Dialogues; | |
using Dialogues.PopupQueue; | |
namespace UI | |
{ | |
public class GameOverUI : BaseDialogue | |
{ | |
[SerializeField] private LocalizedString _localizedCause; | |
[SerializeField] private Text _causeText; | |
[Inject] private SceneLoadHandler _sceneLoadHandler; | |
protected override void OnEnable() | |
{ | |
_closeButton.onClick.AddListener(OpenMenu); | |
InputHandler.PopupStateChanged += OnPopupStateChanged; | |
} | |
private void OnDestroy() | |
{ | |
_closeButton.onClick.RemoveListener(OpenMenu); | |
} | |
protected override void UpdateContent(IPopupQueueElement popupQueueElement) | |
{ | |
base.UpdateContent(popupQueueElement); | |
var gameOverCause = ((GameOverPopupDefinition)popupQueueElement).Cause; | |
OnGameOverReached(gameOverCause); | |
} | |
private void OnGameOverReached(GameOverCause cause) | |
{ | |
var tableEntry = cause switch | |
{ | |
GameOverCause.NoFuel => LocalizationKeys.NoFuel, | |
GameOverCause.FreeFall => LocalizationKeys.FreeFall, | |
GameOverCause.HeightTooHigh => LocalizationKeys.HeightHigh, | |
GameOverCause.HeightTooLow => LocalizationKeys.HeightLow, | |
_ => "" | |
}; | |
LocalizationUtils.LoadLocalizedString(_localizedCause, LocalizationTables.UiTable, tableEntry, this, result => | |
{ | |
_causeText.text = result; | |
}); | |
} | |
private void OpenMenu() | |
{ | |
_sceneLoadHandler.LoadScene(GameScene.Menu, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment