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

File diff suppressed because it is too large Load diff

View file

@ -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;
}
}
}

View file

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