public void OnPrevious() { if (matchIndex > 0) { matchIndex -= 1; var jsonStr = JsonStore.Load(JsonStore.SaveTag.Score, matchIDs[matchIndex]); board = MatchScoreboard.FromJson(jsonStr); ShowBoard(); } }
public void OnNext() { if (matchIndex < matchIDs.Length - 1) { matchIndex += 1; var jsonStr = JsonStore.Load(JsonStore.SaveTag.Score, matchIDs[matchIndex]); board = MatchScoreboard.FromJson(jsonStr); ShowBoard(); } }
public void Start() { // load match info matchIDs = JsonStore.ListByTag(JsonStore.SaveTag.Score); matchIndex = 0; if (matchIDs.Length > 0) { var jsonStr = JsonStore.Load(JsonStore.SaveTag.Score, matchIDs[matchIndex]); board = MatchScoreboard.FromJson(jsonStr); ShowBoard(); } else { prevButton.gameObject.SetActive(false); nextButton.gameObject.SetActive(false); } // set back button callback prevButton.onClick.AddListener(OnPrevious); backButton.onClick.AddListener(OnBack); nextButton.onClick.AddListener(OnNext); }
IEnumerator StatePlayerSelect() { if (debug) { Debug.Log("StatePlayerSelect"); } // load panel var panelGo = Instantiate(playerSelectPanelPrefab, GetCanvas().gameObject.transform); yield return(null); // wait a frame for panel initialization string selectedPlayer = ""; bool cancelled = false; // create string event listener to listen for callback event from player select modal var listener = panelGo.AddComponent <StringEventListener>(); listener.SetEvent(playerSelected); listener.Response.AddListener((msg) => { selectedPlayer = msg; }); var geListener = panelGo.AddComponent <GameEventListener>(); geListener.SetEvent(cancelSelected); geListener.Response.AddListener(() => { cancelled = true; }); // get list of player save files, then serialize to a single string var savedPlayerNames = JsonStore.ListByTag(JsonStore.SaveTag.Player); string serializedPlayerNames = ""; if (savedPlayerNames.Length > 0) { serializedPlayerNames = string.Join(":", savedPlayerNames); } // trigger event to ask for player to be selected wantPlayerSelect.Raise(serializedPlayerNames); // wait for player to be selected yield return(new WaitUntil(() => selectedPlayer != "" || cancelled)); // clean up Destroy(panelGo); // go back to main menu if cancelled if (cancelled) { StartCoroutine(StateMainMenu()); // otherwise, advance, based on game state } else { // if player is selected from existing saved players... load that player if (System.Array.Exists(savedPlayerNames, element => element == selectedPlayer)) { var json = JsonStore.Load(JsonStore.SaveTag.Player, selectedPlayer); playerInfo = PlayerInfo.FromJson(json); // otherwise create and save new player record } else { playerInfo = new PlayerInfo(); playerInfo.name = selectedPlayer; JsonStore.Save(JsonStore.SaveTag.Player, selectedPlayer, playerInfo.ToJson()); } // transition to match select StartCoroutine(StateMatchSelect()); } }
IEnumerator StateFinish() { if (debug) { Debug.Log("StateFinish"); } // notify channel if (gameEventChannel != null) { gameEventChannel.Raise(GameRecord.GameFinished()); } // declare game over if (bannerMessage != null) { bannerMessage.Raise("Game Over!!!"); } yield return(null); // disable bots for (var i = allBots.Items.Count - 1; i >= 0; i--) { allBots.Items[i].GetComponent <BotBrain>().DisableControls(); } // stop match music if (gameInfo.matchInfo.matchMusicTrack != null) { gameInfo.matchInfo.matchMusicTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, gameInfo.matchInfo.matchMusicTrack)); } // add win/loss for player if (winningBot == spawnedPlayer) { // create score for win var scoreInfo = new MatchScoreInfo(); scoreInfo.matchID = gameInfo.matchInfo.id; scoreInfo.time = timerTick; scoreInfo.score = scoreKeeper.GetScore(); gameInfo.playerInfo.AddWin(scoreInfo); // update scoreboard var json = JsonStore.Load(JsonStore.SaveTag.Score, gameInfo.matchInfo.id); var scoreboard = MatchScoreboard.FromJson(json); if (scoreboard == null) { scoreboard = new MatchScoreboard(gameInfo.matchInfo.id); } scoreboard.AddScore(gameInfo.playerInfo.name, scoreInfo.score, scoreInfo.time); } else { gameInfo.playerInfo.AddLoss(); } // start win/loss music if (winLossTrack != null) { winLossTrack.Play(AudioManager.GetInstance().GetEmitter(gameObject, winLossTrack)); } // setup listener for doneConfirmed event var confirmed = false; var listener = gameObject.AddComponent <GameEventListener>(); listener.SetEvent(doneConfirmed); listener.Response.AddListener(() => { confirmed = true; }); // instantiate modal for confirmation var panelGo = Instantiate(donePanelPrefab, GetCanvas().gameObject.transform); yield return(null); // wait a frame for panel initialization // trigger event to notify player that match is complete, // causes confirmation modal to display message and wait for player to click ok var msg = System.String.Format("{0}:{1}", (winningBot == spawnedPlayer) ? "win" : "loss", gameInfo.playerInfo.name); wantDoneConfirm.Raise(msg); // wait for match info to be selected yield return(new WaitUntil(() => confirmed)); if (winLossTrack != null) { winLossTrack.Stop(AudioManager.GetInstance().GetEmitter(gameObject, winLossTrack)); } // clean up, remove listener Destroy(panelGo); Destroy(listener); // signal that the match is done if (matchFinished != null) { matchFinished.Raise(); } }