proper esc

This commit is contained in:
LadyEbony 2020-08-22 13:39:53 -07:00
parent 0e365b3d23
commit d7deb5d8c4
5 changed files with 220 additions and 1407 deletions

View File

@ -10,6 +10,7 @@ public class GameBoardInstance : MonoBehaviour {
public static GameBoardInstance instance { get; private set; } public static GameBoardInstance instance { get; private set; }
public GameBoard player1, player2; public GameBoard player1, player2;
public bool gameActive;
[Header("Text")] [Header("Text")]
public TextMeshProUGUI headerTextMesh; public TextMeshProUGUI headerTextMesh;
@ -33,7 +34,7 @@ public class GameBoardInstance : MonoBehaviour {
if (GameTransition.Instance == null) return; if (GameTransition.Instance == null) return;
var state = GameTransition.Instance.state; 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; var over = player1.delayState == GameBoard.DelayState.Loss || player2.delayState == GameBoard.DelayState.Loss;
if (over){ if (over){
@ -57,14 +58,7 @@ public class GameBoardInstance : MonoBehaviour {
switch(response){ switch(response){
// leave room // leave room
case 0: case 0:
if (NetworkManager.inRoom){ ExitGame(true);
NetworkManager.net.OpLeaveRoom();
GameTransition.Instance.state = GameState.Multiplayer;
} else {
GameTransition.Instance.state = GameState.Menu;
}
player1.Clear();
player2.Clear();
break; break;
// return to lobby or not enough players // return to lobby or not enough players
case 1: case 1:
@ -124,15 +118,15 @@ public class GameBoardInstance : MonoBehaviour {
PlayerProperties.CreatePlayerHashtable(); PlayerProperties.CreatePlayerHashtable();
callback(); callback();
gameActive = true;
yield return new WaitForSeconds(2f); yield return new WaitForSeconds(2f);
headerTextMesh.text = ""; headerTextMesh.text = "";
} }
private bool endGameCoroutine;
private IEnumerator EndGameTimer(float timer){ private IEnumerator EndGameTimer(float timer){
endGameCoroutine = true; gameActive = false;
headerTextMesh.text = Localization.GetString(gameSetKey); headerTextMesh.text = Localization.GetString(gameSetKey);
yield return new WaitForSeconds(timer); yield return new WaitForSeconds(timer);
@ -140,8 +134,6 @@ public class GameBoardInstance : MonoBehaviour {
GameTransition.Instance.state = GameState.Continue; GameTransition.Instance.state = GameState.Continue;
Rematch.Instance.Setup(); Rematch.Instance.Setup();
endGameCoroutine = false;
} }
private void StartSinglePlayer(){ private void StartSinglePlayer(){
@ -155,4 +147,23 @@ public class GameBoardInstance : MonoBehaviour {
player2.Setup(); 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

View File

@ -2,48 +2,21 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Linq; using System.Linq;
public enum GameState { Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits, Help } public enum GameState { Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits, Help }
public class GameTransition : MonoBehaviour { public class GameTransition : MonoBehaviour {
#region Escape [Header("Escape")]
public static void Escape() { public RectTransform escapeButton;
// Menu, SinglePlayer, Multiplayer, Lobby, SelectingRegion, ConnectionInProgress, InGame, Continue, Credits public Vector2 selectedEscapePosition = Vector2.zero;
switch (Instance.state){ private Vector2 baseEscapePosition;
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
public static GameTransition Instance { get; private set; } public static GameTransition Instance { get; private set; }
[Header("Main")]
[SerializeField] [SerializeField]
private GameState _state; private GameState _state;
public GameState state { public GameState state {
@ -121,7 +94,8 @@ public class GameTransition : MonoBehaviour {
} }
private void Start() { private void Start() {
if (EscapeButton) EscapeButton.onClick.AddListener(Escape); escapeButton.GetComponent<Button>().onClick.AddListener(Escape);
baseEscapePosition = escapeButton.anchoredPosition;
baseCamera = Camera.main; baseCamera = Camera.main;
baseCameraOrthoSize = baseCamera.orthographicSize; 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(); 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() { 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 // Escape handling
if (state != GameState.Menu) { if (Input.GetKeyDown(KeyCode.Escape)) {
if (Input.GetKey(KeyCode.Escape)) { if (prevState && !curState) return;
Escape(); Escape();
}
} }
if (EscapeButton) // in case the player disconnects during any weird times
EscapeButton.gameObject.SetActive(ShowEscape());
if (inMultiplayer){ if (inMultiplayer){
switch(NetworkManager.net.State){ switch(NetworkManager.net.State){
case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected: 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); 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;
}
} }
} }

View File

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: -20
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:

View File

@ -170,24 +170,6 @@ MonoBehaviour:
speed: 0.25 speed: 0.25
one: {fileID: 456349643} one: {fileID: 456349643}
two: {fileID: 1386837618} two: {fileID: 1386837618}
--- !u!1 &130187149 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1736330633655152094, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
m_PrefabInstance: {fileID: 1736330635466942931}
m_PrefabAsset: {fileID: 0}
--- !u!114 &130187155
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 130187149}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62d2a91b62e06c04cb0f877e535b187e, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &456349642 --- !u!1 &456349642
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1421,6 +1403,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
player1: {fileID: 647195263} player1: {fileID: 647195263}
player2: {fileID: 2143326256} player2: {fileID: 2143326256}
gameActive: 0
headerTextMesh: {fileID: 2013137395} headerTextMesh: {fileID: 2013137395}
startKey: GAME_START startKey: GAME_START
gameSetKey: GAME_GAMESET gameSetKey: GAME_GAMESET
@ -1559,17 +1542,9 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 380521610, guid: adba91609cb1e5448b76682be198fc9b, type: 3} - target: {fileID: 482421870, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 380521610, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 380521610, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: 49.99994
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 610498694, guid: adba91609cb1e5448b76682be198fc9b, type: 3} - target: {fileID: 610498694, guid: adba91609cb1e5448b76682be198fc9b, type: 3}
propertyPath: m_AnchorMin.y propertyPath: m_AnchorMin.y
@ -1651,185 +1626,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1736330633638169071, guid: adba91609cb1e5448b76682be198fc9b, - target: {fileID: 1736330633687387551, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633638169071, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633638169071, guid: adba91609cb1e5448b76682be198fc9b,
type: 3} type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: 49.99994
objectReference: {fileID: 0}
- target: {fileID: 1736330633760980512, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633760980512, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633760980512, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633775482130, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633775482130, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633775482130, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633916843623, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633916843623, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330633916843623, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634003904156, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634003904156, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634003904156, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634159991433, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634159991433, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634159991433, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634177679782, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634177679782, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634177679782, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634248025819, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634248025819, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634248025819, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634454597124, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634454597124, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634454597124, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634653605562, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634653605562, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634653605562, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634900042864, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634900042864, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330634900042864, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330635014798853, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330635014798853, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330635014798853, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1736330635070797285, guid: adba91609cb1e5448b76682be198fc9b, - target: {fileID: 1736330635070797285, guid: adba91609cb1e5448b76682be198fc9b,
type: 3} type: 3}
@ -1941,21 +1741,6 @@ PrefabInstance:
propertyPath: m_Pivot.y propertyPath: m_Pivot.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1736330635428427867, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330635428427867, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330635428427867, guid: adba91609cb1e5448b76682be198fc9b,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1736330635485585598, guid: adba91609cb1e5448b76682be198fc9b, - target: {fileID: 1736330635485585598, guid: adba91609cb1e5448b76682be198fc9b,
type: 3} type: 3}
propertyPath: tDisplays.Array.data[0].target propertyPath: tDisplays.Array.data[0].target