proper esc
This commit is contained in:
parent
0e365b3d23
commit
d7deb5d8c4
5 changed files with 220 additions and 1407 deletions
|
@ -10,6 +10,7 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
public static GameBoardInstance instance { get; private set; }
|
||||
|
||||
public GameBoard player1, player2;
|
||||
public bool gameActive;
|
||||
|
||||
[Header("Text")]
|
||||
public TextMeshProUGUI headerTextMesh;
|
||||
|
@ -33,7 +34,7 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
if (GameTransition.Instance == null) return;
|
||||
|
||||
var state = GameTransition.Instance.state;
|
||||
if (state == GameState.InGame && !endGameCoroutine){
|
||||
if (state == GameState.InGame && gameActive){
|
||||
var over = player1.delayState == GameBoard.DelayState.Loss || player2.delayState == GameBoard.DelayState.Loss;
|
||||
|
||||
if (over){
|
||||
|
@ -57,14 +58,7 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
switch(response){
|
||||
// leave room
|
||||
case 0:
|
||||
if (NetworkManager.inRoom){
|
||||
NetworkManager.net.OpLeaveRoom();
|
||||
GameTransition.Instance.state = GameState.Multiplayer;
|
||||
} else {
|
||||
GameTransition.Instance.state = GameState.Menu;
|
||||
}
|
||||
player1.Clear();
|
||||
player2.Clear();
|
||||
ExitGame(true);
|
||||
break;
|
||||
// return to lobby or not enough players
|
||||
case 1:
|
||||
|
@ -124,15 +118,15 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
|
||||
PlayerProperties.CreatePlayerHashtable();
|
||||
callback();
|
||||
gameActive = true;
|
||||
|
||||
yield return new WaitForSeconds(2f);
|
||||
headerTextMesh.text = "";
|
||||
}
|
||||
|
||||
private bool endGameCoroutine;
|
||||
|
||||
private IEnumerator EndGameTimer(float timer){
|
||||
endGameCoroutine = true;
|
||||
gameActive = false;
|
||||
|
||||
headerTextMesh.text = Localization.GetString(gameSetKey);
|
||||
yield return new WaitForSeconds(timer);
|
||||
|
@ -140,8 +134,6 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
|
||||
GameTransition.Instance.state = GameState.Continue;
|
||||
Rematch.Instance.Setup();
|
||||
|
||||
endGameCoroutine = false;
|
||||
}
|
||||
|
||||
private void StartSinglePlayer(){
|
||||
|
@ -155,4 +147,23 @@ public class GameBoardInstance : MonoBehaviour {
|
|||
player2.Setup();
|
||||
}
|
||||
|
||||
public void ExitGame(bool force = false){
|
||||
if (gameActive || force){
|
||||
gameActive = false;
|
||||
|
||||
player1.Stop();
|
||||
player2.Stop();
|
||||
|
||||
player1.Clear();
|
||||
player2.Clear();
|
||||
|
||||
if (NetworkManager.inRoom){
|
||||
NetworkManager.net.OpLeaveRoom();
|
||||
GameTransition.Instance.state = GameState.Multiplayer;
|
||||
} else {
|
||||
GameTransition.Instance.state = GameState.Menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,48 +2,21 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using System.Linq;
|
||||
|
||||
public enum GameState { Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits, Help }
|
||||
|
||||
public class GameTransition : MonoBehaviour {
|
||||
|
||||
#region Escape
|
||||
public static void Escape() {
|
||||
// Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits
|
||||
switch (Instance.state){
|
||||
case GameState.SinglePlayer:
|
||||
case GameState.Multiplayer:
|
||||
case GameState.SelectingRegion:
|
||||
case GameState.Continue:
|
||||
case GameState.InGame:
|
||||
case GameState.Help:
|
||||
// Hard reset states
|
||||
// Blah blah deprecated still works
|
||||
Application.LoadLevel(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
Instance.state = GameState.Menu;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ShowEscape() {
|
||||
switch(Instance.state) {
|
||||
case GameState.Menu:
|
||||
case GameState.Lobby:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public UnityEngine.UI.Button EscapeButton;
|
||||
#endregion
|
||||
[Header("Escape")]
|
||||
public RectTransform escapeButton;
|
||||
public Vector2 selectedEscapePosition = Vector2.zero;
|
||||
private Vector2 baseEscapePosition;
|
||||
|
||||
public static GameTransition Instance { get; private set; }
|
||||
|
||||
[Header("Main")]
|
||||
[SerializeField]
|
||||
private GameState _state;
|
||||
public GameState state {
|
||||
|
@ -121,7 +94,8 @@ public class GameTransition : MonoBehaviour {
|
|||
}
|
||||
|
||||
private void Start() {
|
||||
if (EscapeButton) EscapeButton.onClick.AddListener(Escape);
|
||||
escapeButton.GetComponent<Button>().onClick.AddListener(Escape);
|
||||
baseEscapePosition = escapeButton.anchoredPosition;
|
||||
|
||||
baseCamera = Camera.main;
|
||||
baseCameraOrthoSize = baseCamera.orthographicSize;
|
||||
|
@ -133,17 +107,28 @@ public class GameTransition : MonoBehaviour {
|
|||
tDefault = tDisplays.Select(t => t.target).Distinct().Select(t => new TransformDefault(t, t.localPosition, t.localEulerAngles, t.localScale)).ToArray();
|
||||
}
|
||||
|
||||
private bool prevState;
|
||||
private bool curState;
|
||||
|
||||
private void Update() {
|
||||
|
||||
// obscure fix to input field + esc
|
||||
prevState = curState;
|
||||
var sinputfield = EventSystem.current.currentSelectedGameObject;
|
||||
if (sinputfield){
|
||||
var comp = sinputfield.GetComponent<TMPro.TMP_InputField>();
|
||||
curState = comp ? comp.isFocused : false;
|
||||
} else {
|
||||
curState = false;
|
||||
}
|
||||
|
||||
// Escape handling
|
||||
if (state != GameState.Menu) {
|
||||
if (Input.GetKey(KeyCode.Escape)) {
|
||||
Escape();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Escape)) {
|
||||
if (prevState && !curState) return;
|
||||
Escape();
|
||||
}
|
||||
|
||||
if (EscapeButton)
|
||||
EscapeButton.gameObject.SetActive(ShowEscape());
|
||||
|
||||
// in case the player disconnects during any weird times
|
||||
if (inMultiplayer){
|
||||
switch(NetworkManager.net.State){
|
||||
case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected:
|
||||
|
@ -198,5 +183,43 @@ public class GameTransition : MonoBehaviour {
|
|||
|
||||
baseCamera.orthographicSize = Mathf.Lerp(baseCamera.orthographicSize, selectedOrthoStates.Contains(state) ? selectedCameraOrthoSize : baseCameraOrthoSize, dist);
|
||||
|
||||
escapeButton.anchoredPosition = Vector2.Lerp(escapeButton.anchoredPosition, ShowEscapeButton() ? selectedEscapePosition : baseEscapePosition, dist);
|
||||
|
||||
}
|
||||
|
||||
bool ShowEscapeButton(){
|
||||
return state != GameState.Menu;
|
||||
}
|
||||
|
||||
void Escape(){
|
||||
if (!ShowEscapeButton()) return;
|
||||
|
||||
switch (state){
|
||||
case GameState.Help:
|
||||
case GameState.Credits:
|
||||
state = GameState.Menu;
|
||||
break;
|
||||
// must disconnect
|
||||
case GameState.Multiplayer:
|
||||
case GameState.SelectingRegion:
|
||||
state = GameState.ConnectionInProgress;
|
||||
NetworkManager.net.Service();
|
||||
NetworkManager.net.Disconnect();
|
||||
break;
|
||||
|
||||
// special case, leave room
|
||||
case GameState.Lobby:
|
||||
state = GameState.ConnectionInProgress;
|
||||
NetworkManager.net.OpLeaveRoom();
|
||||
break;
|
||||
|
||||
// close game
|
||||
case GameState.InGame:
|
||||
GameBoardInstance.instance.ExitGame();
|
||||
break;
|
||||
case GameState.Continue:
|
||||
GameBoardInstance.instance.ExitGame(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ MonoImporter:
|
|||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -20
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue