Game UI ready
This commit is contained in:
@@ -1,34 +1,48 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
public class DeathScreenController
|
||||
public class DeathScreenController:IDeathScreenController
|
||||
{
|
||||
private DeathScreenView deathScreenView;
|
||||
public event Action OnRestartPressed;
|
||||
public event Action OnExitPressed;
|
||||
|
||||
[Inject] private ScoreService scoreService;
|
||||
[Inject] private IScoreService IscoreService;
|
||||
[Inject] private IInputReader IinputReader;
|
||||
[Inject] private IAudioController IaudioController;
|
||||
[Inject] private IGameSession IgameSession;
|
||||
public DeathScreenController(DeathScreenView _deathScreenView)
|
||||
{
|
||||
deathScreenView = _deathScreenView;
|
||||
deathScreenView.restartBtn.onClick.AddListener(() => OnRestartPressed?.Invoke());
|
||||
deathScreenView.exitBtn.onClick.AddListener(()=>OnExitPressed?.Invoke());
|
||||
deathScreenView.restartBtn.onClick.AddListener(OnRestartButtonClicked);
|
||||
deathScreenView.exitBtn.onClick.AddListener(OnExitButtonClicked);
|
||||
}
|
||||
|
||||
public void ShowDeathScreen()
|
||||
{
|
||||
deathScreenView.Show(scoreService.score,scoreService.highScore);
|
||||
deathScreenView.Show(IscoreService.score,IscoreService.highScore);
|
||||
}
|
||||
|
||||
private void OnExitButtonClicked()
|
||||
{
|
||||
Debug.Log("Exit Button Clicked");
|
||||
IinputReader.UnlockInput();
|
||||
IaudioController.PlayBtnPressedSound();
|
||||
IgameSession.showStartScreen = true;
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
|
||||
private void OnRestartButtonClicked()
|
||||
{
|
||||
Debug.Log("Restart Button Clicked");
|
||||
IinputReader.UnlockInput();
|
||||
IaudioController.PlayBtnPressedSound();
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IDeathScreenController
|
||||
{
|
||||
void ShowDeathScreen();
|
||||
}
|
||||
@@ -1,16 +1,31 @@
|
||||
using System;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
public class GameScreenController
|
||||
public class GameScreenController: IGameScreenController
|
||||
{
|
||||
GameScreenView gameScreenView;
|
||||
public event Action OnPausePressed;
|
||||
public GameScreenController(GameScreenView _gameScreenView)
|
||||
[Inject] private IScoreService IscoreService;
|
||||
[Inject] private IPauseScreenController IpauseScreenController;
|
||||
[Inject] private IInputReader IinputReader;
|
||||
[Inject] private IAudioController IaudioController;
|
||||
public GameScreenController(GameScreenView _gameScreenView,IScoreService _IscoreService,IPauseScreenController _IpauseScreenController)
|
||||
{
|
||||
this.gameScreenView = _gameScreenView;
|
||||
gameScreenView.pauseBtn.onClick.AddListener(()=>OnPausePressed?.Invoke());
|
||||
IscoreService = _IscoreService;
|
||||
IpauseScreenController=_IpauseScreenController;
|
||||
IscoreService.OnScoreChange += UpdateScore;
|
||||
gameScreenView.pauseBtn.onClick.AddListener(OnPauseButtonClicked);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UpdateScore(int score)
|
||||
{
|
||||
Debug.Log("calling Score");
|
||||
gameScreenView.UpdateScore(score);
|
||||
}
|
||||
|
||||
public void ShowGameScreen()
|
||||
@@ -20,6 +35,14 @@ public class GameScreenController
|
||||
|
||||
public void OnPauseButtonClicked()
|
||||
{
|
||||
Debug.Log("Paused Btn Clicked");
|
||||
IaudioController.PlayBtnPressedSound();
|
||||
Time.timeScale = 0f;
|
||||
IinputReader.LockInput();
|
||||
IpauseScreenController.ShowPauseScreen();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IGameScreenController {
|
||||
void ShowGameScreen();
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ public class GameScreenView : MonoBehaviour
|
||||
public Button pauseBtn;
|
||||
[SerializeField] private TextMeshProUGUI scoreText;
|
||||
|
||||
private void Start()
|
||||
public void UpdateScore(int score)
|
||||
{
|
||||
gameScreen.SetActive(false);
|
||||
scoreText.text = score.ToString();
|
||||
}
|
||||
|
||||
public void Show()
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VContainer;
|
||||
|
||||
public class PauseScreenController
|
||||
public class PauseScreenController:IPauseScreenController
|
||||
{
|
||||
private PauseScreenView pauseScreenView;
|
||||
public event Action OnResumePressed;
|
||||
public event Action OnRestartPressed;
|
||||
[Inject] private IInputReader IinputReader;
|
||||
[Inject] private IAudioController IaudioController;
|
||||
|
||||
public PauseScreenController(PauseScreenView _pauseScreenView)
|
||||
{
|
||||
pauseScreenView = _pauseScreenView;
|
||||
pauseScreenView.resumeBtn.onClick.AddListener(()=>OnRestartPressed?.Invoke());
|
||||
pauseScreenView.restartBtn.onClick.AddListener(()=>OnRestartPressed?.Invoke());
|
||||
pauseScreenView.resumeBtn.onClick.AddListener(OnResumeButtonClicked);
|
||||
pauseScreenView.restartBtn.onClick.AddListener(OnRestartButtonClicked);
|
||||
}
|
||||
|
||||
public void ShowPauseScreen()
|
||||
@@ -21,11 +23,23 @@ public class PauseScreenController
|
||||
|
||||
private void OnRestartButtonClicked()
|
||||
{
|
||||
Debug.Log("Restart Button Clicked");
|
||||
Time.timeScale = 1.0f;
|
||||
IinputReader.UnlockInput();
|
||||
IaudioController.PlayBtnPressedSound();
|
||||
SceneManager.LoadScene(0); //Restart This Scene
|
||||
}
|
||||
|
||||
private void OnResumeButtonClicked()
|
||||
{
|
||||
Debug.Log("Resume Button Clicked");
|
||||
Time.timeScale = 1.0f;
|
||||
pauseScreenView.Hide();
|
||||
IinputReader.UnlockInput();
|
||||
IaudioController.PlayBtnPressedSound();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPauseScreenController
|
||||
{
|
||||
void ShowPauseScreen();
|
||||
}
|
||||
|
||||
@@ -1,24 +1,45 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
public class StartScreenController
|
||||
public class StartScreenController:IStartable
|
||||
{
|
||||
private StartScreenView startScreenView;
|
||||
public event Action OnStartPressed;
|
||||
public StartScreenController(StartScreenView _startScreenView)
|
||||
[Inject] IGameScreenController gameScreenController;
|
||||
[Inject] IInputReader IinputReader;
|
||||
[Inject] private IAudioController IaudioController;
|
||||
[Inject] private IGameSession IgameSession;
|
||||
public StartScreenController(StartScreenView _startScreenView, IGameScreenController _gameScreenController)
|
||||
{
|
||||
Debug.Log("StartScreenController Constructor Called");
|
||||
startScreenView = _startScreenView;
|
||||
startScreenView.tapToStartButton.onClick.AddListener(() => OnStartPressed?.Invoke());
|
||||
gameScreenController = _gameScreenController;
|
||||
startScreenView.tapToStartButton.onClick.AddListener(OnTapToStartButtonClicked);
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
if(IgameSession.showStartScreen)
|
||||
{
|
||||
startScreenView.Show();
|
||||
IinputReader.LockInput();
|
||||
IgameSession.showStartScreen = false;
|
||||
IgameSession.hasGameStarted = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
gameScreenController.ShowGameScreen();
|
||||
IgameSession.hasGameStarted = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnTapToStartButtonClicked()
|
||||
{
|
||||
IaudioController.PlayBtnPressedSound();
|
||||
startScreenView.Hide();
|
||||
}
|
||||
public void ShowStartScreen()
|
||||
{
|
||||
startScreenView.Show();
|
||||
IinputReader.UnlockInput();
|
||||
gameScreenController.ShowGameScreen();
|
||||
IgameSession.hasGameStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,6 @@ public class StartScreenView : MonoBehaviour
|
||||
[SerializeField] private GameObject startScreen;
|
||||
public Button tapToStartButton;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//startScreen.SetActive(true);
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
startScreen.SetActive(true);
|
||||
|
||||
Reference in New Issue
Block a user