diff --git a/Assets/External-Assets/packages/Project/Scripts/Gameplay/Snake and Ladder/DiceView.cs b/Assets/External-Assets/packages/Project/Scripts/Gameplay/Snake and Ladder/DiceView.cs index 01129ab..584f377 100644 --- a/Assets/External-Assets/packages/Project/Scripts/Gameplay/Snake and Ladder/DiceView.cs +++ b/Assets/External-Assets/packages/Project/Scripts/Gameplay/Snake and Ladder/DiceView.cs @@ -27,6 +27,8 @@ public class DiceView : MonoBehaviour, IBase public void Roll(Action onComplete, bool isBot) { + Debug.Log($"Start rolling: {rolling}"); + if (!rolling) { Debug.Log($"isBot: {isBot}"); @@ -74,9 +76,8 @@ public class DiceView : MonoBehaviour, IBase //TODO: Use the dice value as needed Debug.Log($"Dice rolled: {value}"); - onRollingComplete?.Invoke(value); - ResetDice(); + onRollingComplete?.Invoke(value); } int GetDiceValue() @@ -98,7 +99,7 @@ public class DiceView : MonoBehaviour, IBase transform.localPosition = new Vector3(0, 20, 0); rolling = false; - Invoke(nameof(ResetEvent), 0.5f); + // Invoke(nameof(ResetEvent), 0.1f); } private void ResetEvent() diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 6ceab31..3912a2b 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -8460,8 +8460,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0483b263e22fc433caab31141efbe319, type: 3} m_Name: m_EditorClassIdentifier: + isDebugTest: 1 diceRollHandler: {fileID: 1013177415} diceValue: 6 + maxDiceSixRollCounter: 2 diceText: {fileID: 953941044} pointerDebug: {fileID: 102349503} pointerMeshRend: {fileID: 102349501} @@ -25334,6 +25336,8 @@ MonoBehaviour: m_EditorClassIdentifier: screenType: 2 shouldFade: 0 + playAgainBtn: {fileID: 5608193482985030359} + mainMenuBtn: {fileID: 5608193483181475110} --- !u!222 &5608193482210820768 CanvasRenderer: m_ObjectHideFlags: 0 @@ -27155,7 +27159,7 @@ GameObject: - component: {fileID: 5608193482985030358} - component: {fileID: 5608193482985030359} m_Layer: 5 - m_Name: Retry Button + m_Name: PlayAgainButton m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -27657,7 +27661,7 @@ GameObject: - component: {fileID: 5608193483181475113} - component: {fileID: 5608193483181475110} m_Layer: 5 - m_Name: Home Button + m_Name: MainMenuButton m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/Scripts/Gameplay/GameModeHandler.cs b/Assets/Scripts/Gameplay/GameModeHandler.cs index 0ae054a..c0a2884 100644 --- a/Assets/Scripts/Gameplay/GameModeHandler.cs +++ b/Assets/Scripts/Gameplay/GameModeHandler.cs @@ -25,7 +25,7 @@ public class BotModeData public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader { private GameplayManager gameplayManager; - + private GameManager gameManager; private PVPModeData pvpModeData; private BotModeData botModeData; @@ -41,6 +41,7 @@ public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader public void InitializeData() { + gameManager = InterfaceManager.Instance.GetInterfaceInstance(); gameplayManager = InterfaceManager.Instance.GetInterfaceInstance(); } @@ -69,6 +70,8 @@ public class GameModeHandler : MonoBehaviour, IBase, IBootLoader, IDataLoader public void OnGameRestarted() { + gameManager.OnGameStateChanged(GameState.InGame); + gameplayManager.ResetGameRestartData(); switch (CurrentGameModeType) { case GameModeType.PVP: diff --git a/Assets/Scripts/Gameplay/GameplayManager.cs b/Assets/Scripts/Gameplay/GameplayManager.cs index ac2bd47..ade3826 100644 --- a/Assets/Scripts/Gameplay/GameplayManager.cs +++ b/Assets/Scripts/Gameplay/GameplayManager.cs @@ -16,9 +16,14 @@ public enum BotMove public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { + [SerializeField] private bool isDebugTest = false; + + public bool IsDebugTest => isDebugTest; + [SerializeField] DiceRollHandler diceRollHandler; [SerializeField] private int diceValue = 0; + [SerializeField] private int maxDiceSixRollCounter = 2; [SerializeField] private TextMeshProUGUI diceText; @@ -128,9 +133,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } } - foreach (var type in allPlayerTypes) - Debug.Log($"allPlayerTypes ::: {type}"); - tilesManager.InitTilesData(); playerBaseHandler.InitPlayerTypes(allPlayerTypes); InitCurrentGamePlayerInfo(); @@ -209,6 +211,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void InitCurrentGamePlayerInfo() { currentPlayerTypeTurn = allPlayerTypes[currentPlayerTurnIndex]; + Debug.Log($"currentPlayerTypeTurn: {currentPlayerTypeTurn}"); + + SetCurrentSelectedPointer(); // initialize the board based on the player types playerGameDatasDict = new Dictionary(); @@ -268,7 +273,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader private bool CheckForMaxDiceRollAttempt() { - if (diceSixRollCounter > 2) + if (diceSixRollCounter > maxDiceSixRollCounter) // TODO :: Reset after test { CanRollDiceAgain = false; SwitchPlayer(); @@ -331,27 +336,21 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader // TODO :: Double check foreach (var key in botPawnsDictForCurrentPlayer.Keys) { - Debug.Log($"b :: botPawnsDictForCurrentPlayer[key]: {botPawnsDictForCurrentPlayer[key]}"); + Debug.Log($"b :: botPawnsDictForCurrentPlayer[key]: {key}, {botPawnsDictForCurrentPlayer[key]}"); // botPawnsDictForCurrentPlayer[key] = BotMove.NoMoves; - Debug.Log($"a :: botPawnsDictForCurrentPlayer[key]: {botPawnsDictForCurrentPlayer[key]}"); } Debug.Log($"Before Iterating"); foreach (var playerPawn in availPlayers) { - Debug.Log($"Iterating"); - var possibleLandingIndex = playerPawn.CurrentTileIndex + diceRolledValue; + int possibleSteps = 0; + Tile possibleTileData = null; - int lastIndex = tilesManager.GetGeneralTilesLength() - 1; - int index = possibleLandingIndex > lastIndex ? possibleLandingIndex - lastIndex - 1 : possibleLandingIndex; - Tile possibleTileData = tilesManager.RetrieveTileBasedOnIndex(index); + if (playerPawn.GetPlayerState() != PlayerState.InFinishingPath) + FindPossibleTileData(playerPawn, out possibleSteps, out possibleTileData); - Debug.Log($"AI playerPawn :: {playerPawn.name} :: state: {playerPawn.GetPlayerState()}, possibleLandingIndex: {possibleLandingIndex > playerGameDatasDict[currentPlayerTypeTurn].endIndex}"); - Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.IsSafeZone: {possibleTileData.IsSafeZone}"); - Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.PlayerPawn: {possibleTileData.HasPawnsAvailable}"); - - if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || possibleLandingIndex > playerGameDatasDict[currentPlayerTypeTurn].endIndex) + if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || possibleSteps > playerGameDatasDict[currentPlayerTypeTurn].endIndex) // TODO :: have a better second check { Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: inFinishingPath :: canSelectPlayer: {playerPawn.CanSelectPlayer}"); if (playerPawn.CanSelectPlayer) @@ -365,12 +364,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.NoMoves; } } - else if (possibleTileData.IsSafeZone) + else if (possibleTileData != null && possibleTileData.IsSafeZone) { Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: safeMove"); botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.SafeMove; } - else if (possibleTileData.HasPawnsAvailable) + else if (possibleTileData != null && possibleTileData.HasPawnsAvailable && possibleTileData.CurrentHoldingPlayerType != playerPawn.PlayerType) { Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: attackMove"); botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.AttackMove; @@ -417,17 +416,22 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } } - Debug.Log($"AI playerPawn :: {pawn.name} :: SelectedPawn: {pawn.name}"); if (pawn != null) + { + Debug.Log($"AI playerPawn :: {pawn.name} :: SelectedPawn: {pawn.name}"); OnPawnSelected(pawn); + } else { if (CheckForMaxDiceRollAttempt()) { return; } - - HandleDiceRoll(); + + if (CanRollDiceAgain) + HandleDiceRoll(); + else + SwitchPlayer(); } void InitPawnBasedOnState(BotMove botMove) @@ -458,6 +462,20 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } } + private void FindPossibleTileData(PlayerPawn playerPawn, out int possibleSteps, out Tile possibleTileData) + { + possibleSteps = playerGameDatasDict[playerPawn.PlayerType].playerPawnsDict[playerPawn.PlayerId].StepsTaken + diceRolledValue; + int lastStepGenTileIdx = playerGameDatasDict[playerPawn.PlayerType].endIndex; + int possibleTileIndex = playerPawn.CurrentTileIndex + diceRolledValue; + + int totalStepsInGeneralPath = tilesManager.GetGeneralTilesLength() - 1; // including the first safe zone + int lastTileIndex = tilesManager.GetGeneralTilesLength() - 1; + int index = possibleSteps > totalStepsInGeneralPath ? possibleTileIndex - lastStepGenTileIdx - 1 + : possibleTileIndex > lastTileIndex ? possibleTileIndex - lastTileIndex - 1 : possibleTileIndex; + + possibleTileData = possibleSteps > totalStepsInGeneralPath ? tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, index) : tilesManager.RetrieveTileBasedOnIndex(index); + } + public void OnDiceRolled(int rolledVal) { SetCanRollDiceForUser(false); @@ -528,7 +546,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader availPlayers[i].SetPlayerSelectionState(true); } - foreach (int i in indexesToRemove) availPlayers.RemoveAt(i); + for (int idx = indexesToRemove.Count - 1; idx >= 0; idx--) + availPlayers.RemoveAt(idx); // if (availPlayers.Count() < 1) Debug.Log($"CustomAvailablePlayers: {customAvailPlayers}"); @@ -546,11 +565,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader pawn.GetPlayerState() == PlayerState.Moving || pawn.GetPlayerState() == PlayerState.InFinishingPath).ToList(); - Debug.Log($"#### UpdatePlayerState in InitActivePlayers "); - foreach (var pawn in playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Values) - { - Debug.Log($"pawn: {pawn.name}, state: {pawn.GetPlayerState()}"); - } foreach (var player in availPlayers) // TODO :: Move from here { DisplayPlayerCountOnTile(player, true); @@ -585,7 +599,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader playerPawn.SetPlayerState(playerState); } - private void CheckDiceRollForBot(PlayerPawn playerPawn) + private void CheckDiceRollForBot() { if (CanRollDiceAgain) { @@ -595,8 +609,10 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader private void HandleDiceRoll() { - // diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal)); - diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue); + if (isDebugTest) + diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue); + else + diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal)); } public void OnPawnSelected(PlayerPawn playerPawn) @@ -625,7 +641,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } if (playerPawn.IsBotPlayer) - CheckDiceRollForBot(playerPawn); + CheckDiceRollForBot(); else SetCanRollDiceForUser(true); @@ -721,10 +737,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader InitActivePlayers(); Debug.Log($"after SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}"); - foreach (var pawn in availPlayers) - { - DisplayPlayerCountOnTile(pawn, false); - } + SetDisplayCountForAllAvailPlayers(false); if (allPlayerTypes.Count == 1) { @@ -749,16 +762,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader diceText.text = $"{0}"; InitActivePlayers(); - foreach (var pawn in availPlayers) - { - DisplayPlayerCountOnTile(pawn, true); - } + SetDisplayCountForAllAvailPlayers(true); } SetCanRollDiceForUser(!botTypesInGame.Contains(currentPlayerTypeTurn)); Debug.Log($"CurrentPlayerTurn: {currentPlayerTypeTurn}"); - var tempPos = playerBaseHandler.GetPlayerBase(currentPlayerTypeTurn).transform.position; - pointerDebug.position = new Vector3(tempPos.x, 3f, tempPos.z); + SetCurrentSelectedPointer(); pointerMeshRend.material = turnMat; // pointerMeshRend.materials[0] = turnMat; @@ -772,6 +781,20 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } } + private void SetCurrentSelectedPointer() + { + var tempPos = playerBaseHandler.GetPlayerBase(currentPlayerTypeTurn).transform.position; + pointerDebug.position = new Vector3(tempPos.x, 3f, tempPos.z); + } + + public void SetDisplayCountForAllAvailPlayers(bool state) + { + foreach (var pawn in availPlayers) + { + DisplayPlayerCountOnTile(pawn, state); + } + } + private void MoveThroughTiles(PlayerPawn playerPawn, int index, int targetIndex) { Tile nextTile = tilesManager.RetrieveTileBasedOnIndex(index); @@ -856,9 +879,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } CanRollDiceAgain = true; - if (playerPawn.IsBotPlayer) - CheckDiceRollForBot(playerPawn); - else + if (!playerPawn.IsBotPlayer) SetCanRollDiceForUser(true); } @@ -980,15 +1001,14 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader Debug.Log($"currentPlayerTypeTurn: {currentPlayerTypeTurn}"); Debug.Log($"playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn): {playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn)}"); playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn).ranking = TotalPlayersInGame - allPlayerTypes.Count; - Debug.Log($"ranking: {playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn).ranking}"); } if (allPlayerTypes.Count == 1) { // Game is over + var lastFinishingPlayerType = allPlayerTypes[0]; allPlayerTypes.RemoveAt(0); - playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn).ranking = TotalPlayersInGame - allPlayerTypes.Count; - Debug.Log($"ranking: {playerDatas.FirstOrDefault(data => data.playerType == currentPlayerTypeTurn).ranking}"); + playerDatas.FirstOrDefault(data => data.playerType == lastFinishingPlayerType).ranking = TotalPlayersInGame - allPlayerTypes.Count; // Show Game Over panel gameManager.OnGameStateChanged(GameState.GameOver); @@ -1004,7 +1024,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { CanRollDiceAgain = true; if (playerPawn.IsBotPlayer) - CheckDiceRollForBot(playerPawn); + CheckDiceRollForBot(); else SetCanRollDiceForUser(true); } @@ -1036,7 +1056,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, playerPawn.CurrentTileIndex) : tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex); - Debug.Log($"Displaycount: {playerPawn.name} on tile: {tile.name}, show: {show}"); playerPawn.ShowPlayerCountCanvas(show); if (!show) return; @@ -1055,6 +1074,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void ResetData() { + ResetGameRestartData(); + playerDatas = null; botTypesInGame = null; allPlayerTypes = null; @@ -1064,4 +1085,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader playerDatas = null; availPlayers = null; } + + public void ResetGameRestartData() + { + currentPlayerTurnIndex = 0; + } } diff --git a/Assets/Scripts/Gameplay/Player/PlayerPawn.cs b/Assets/Scripts/Gameplay/Player/PlayerPawn.cs index 9a2912d..02a6437 100644 --- a/Assets/Scripts/Gameplay/Player/PlayerPawn.cs +++ b/Assets/Scripts/Gameplay/Player/PlayerPawn.cs @@ -101,7 +101,6 @@ public class PlayerPawn : MonoBehaviour public void MoveToCustomTilePosition(Vector3 targetPoint) { - StepsTaken++; transform.DOMove(targetPoint, 1f); } diff --git a/Assets/Scripts/Input/DiceRollHandler.cs b/Assets/Scripts/Input/DiceRollHandler.cs index 10f4c7b..ce799c1 100644 --- a/Assets/Scripts/Input/DiceRollHandler.cs +++ b/Assets/Scripts/Input/DiceRollHandler.cs @@ -34,13 +34,15 @@ public class DiceRollHandler : MonoBehaviour SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance(); soundManager?.PlayGameSoundClip(SoundType.Dice); - OnUserDiceRollComplete(GetDiceTestVal()); - // diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false); + if (inputManager.GameplayManager.IsDebugTest) + OnUserDiceRollComplete(GetDiceTestVal()); + else + diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false); } public void HandleDiceViewForBot(Action onComplete) { - diceView.Roll(onComplete: (val) => onComplete?.Invoke(val), true); + diceView.Roll(onComplete: onComplete, true); } public void HandleDiceViewForBot(Action onComplete, int val) diff --git a/Assets/Scripts/State/GameManager.cs b/Assets/Scripts/State/GameManager.cs index 1ad3fa3..1379512 100644 --- a/Assets/Scripts/State/GameManager.cs +++ b/Assets/Scripts/State/GameManager.cs @@ -10,6 +10,7 @@ public enum GameState public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { private UIManager uiManager; + private TilesManager tilesManager; private GameplayManager gameplayManager; public GameState GameState @@ -25,6 +26,7 @@ public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void InitializeData() { uiManager = InterfaceManager.Instance.GetInterfaceInstance(); + tilesManager = InterfaceManager.Instance.GetInterfaceInstance(); gameplayManager = InterfaceManager.Instance.GetInterfaceInstance(); OnGameStateChanged(GameState.InMenu); @@ -37,6 +39,7 @@ public class GameManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { case GameState.InMenu: gameplayManager.ResetData(); + tilesManager.ResetData(); uiManager.OnInMenuScreen(); break; case GameState.InGame: diff --git a/Assets/Scripts/Tile/TilesManager.cs b/Assets/Scripts/Tile/TilesManager.cs index 831b61c..20fe5a2 100644 --- a/Assets/Scripts/Tile/TilesManager.cs +++ b/Assets/Scripts/Tile/TilesManager.cs @@ -32,6 +32,7 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase public void InitTilesData() { + finishingTileDataPairs = new Dictionary>(); foreach (var tileData in tileDatas) { if (gameplayManager.PlayerTypesCollection.Contains(tileData.playerType)) @@ -52,10 +53,6 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase Debug.Log($"RetrieveTileBasedOnIndex: Index: {index}"); Tile tile = index == generalTiles.Length ? generalTiles[0] : generalTiles[index]; - // if (tile.IsSafeZone) - // { - // return (SafeTile)tile; - // } return tile; } @@ -65,8 +62,8 @@ public class TilesManager : MonoBehaviour, IBootLoader, IDataLoader, IBase return finishingTileDataPairs[playerType][index]; } - public Transform RetrievePositionForFinishingTile(PlayerType playerType, int index) + public void ResetData() { - return finishingTileDataPairs[playerType][index].transform; + finishingTileDataPairs.Clear(); } } diff --git a/Assets/Scripts/UI/Pages/Bases/ScreenBase.cs b/Assets/Scripts/UI/Pages/Bases/ScreenBase.cs index ae5d71c..b894389 100644 --- a/Assets/Scripts/UI/Pages/Bases/ScreenBase.cs +++ b/Assets/Scripts/UI/Pages/Bases/ScreenBase.cs @@ -24,7 +24,7 @@ public class ScreenBase : UIBase, IUIBase public ScreenType ScreenType => screenType; - private ScreenManager screenManager; + protected ScreenManager screenManager; public void Initialize() { diff --git a/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs b/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs index c8a1eac..0ea76bd 100644 --- a/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs +++ b/Assets/Scripts/UI/Pages/PopUp/GameOverPopup.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -12,7 +13,26 @@ public class GameOverPopup : PopupBase [SerializeField] private TextMeshProUGUI[] texts; private GameModeHandler gameModeHandler; - private ScreenManager screenManager; + + public void InitData(List playerData) + { + for (int idx = 0; idx < texts.Length; idx++) + { + if (idx >= playerData.Count) + { + texts[idx].gameObject.SetActive(false); + continue; + } + + if (playerData[idx].ranking == 1) + { + texts[playerData[idx].ranking - 1].text = $"{playerData[idx].playerName} Wins"; + continue; + } + + texts[playerData[idx].ranking - 1].text = $"{playerData[idx].ranking}. {playerData[idx].playerName}"; + } + } private void OnEnable() { @@ -42,22 +62,5 @@ public class GameOverPopup : PopupBase public void OnMainMenuClicked() { HidePopup(); - - screenManager = screenManager == null ? InterfaceManager.Instance.GetInterfaceInstance() : screenManager; - screenManager.ShowScreen(ScreenType.MenuScreen); - } - - public void InitData(List playerDatas) - { - foreach (var playerData in playerDatas) - { - if (playerData.ranking == 1) - { - texts[playerData.ranking - 1].text = $"{playerData.playerName} Wins";; - continue; - } - - texts[playerData.ranking - 1].text = $"{playerData.ranking}. {playerData.playerName}"; - } } } diff --git a/Assets/Scripts/UI/Pages/Screens/GameOverScreen.cs b/Assets/Scripts/UI/Pages/Screens/GameOverScreen.cs index 642f8f6..27a0572 100644 --- a/Assets/Scripts/UI/Pages/Screens/GameOverScreen.cs +++ b/Assets/Scripts/UI/Pages/Screens/GameOverScreen.cs @@ -1,8 +1,44 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class GameOverScreen : ScreenBase { + [SerializeField] private Button playAgainBtn; + [SerializeField] private Button mainMenuBtn; + + private GameModeHandler gameModeHandler; + private void OnEnable() + { + playAgainBtn.onClick.AddListener(OnPlayAgainClicked); + mainMenuBtn.onClick.AddListener(OnMainMenuClicked); + } + + private void OnDisable() + { + playAgainBtn.onClick.RemoveAllListeners(); + mainMenuBtn.onClick.RemoveAllListeners(); + } + + public void OnPlayAgainClicked() + { + HideScreen(); + } + + private void HideScreen() + { + screenManager.HideScreen(screenType); + } + + public void OnMainMenuClicked() + { + HideScreen(); + + screenManager = screenManager == null ? InterfaceManager.Instance.GetInterfaceInstance() : screenManager; + screenManager.ShowScreen(ScreenType.MenuScreen); + screenManager.ShowScreen(ScreenType.MainMenuScreen); + } }