You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.6 KiB
C#
137 lines
4.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using SiegeSong;
|
|
|
|
namespace SiegeSong
|
|
{
|
|
public class GlobalPauseMenu : MonoBehaviour
|
|
{
|
|
public GameObject PauseMenu;
|
|
public GameObject OptionsContainer;
|
|
|
|
private string pauseGamepadInput = "Start";
|
|
private string menuVerticalGamepadInput = "D-Pad Vertical";
|
|
private string menuHorizontalGamepadInput = "D-Pad Horizontal";
|
|
private string menuConfirmGamepadInput = "A";
|
|
private string menuRejectGamepadInput = "B";
|
|
|
|
private bool oldConfirmState;
|
|
private bool oldRejectState;
|
|
private float oldVerticalState;
|
|
private float oldHorizontalState;
|
|
|
|
private bool open;
|
|
private int selectedIndex;
|
|
|
|
private Color activeColor = Color.white;
|
|
private Color inactiveColor = Color.grey;
|
|
|
|
private int activeFontSize;
|
|
private int inactiveFontSize;
|
|
|
|
private bool loadingSubmenuOpen;
|
|
private bool savingSubmenuOpen;
|
|
private bool settingsSubmenuOpen;
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!open && Input.GetButton(pauseGamepadInput))
|
|
{
|
|
open = true;
|
|
Time.timeScale = 0.0f;
|
|
PauseMenu.active = true;
|
|
}
|
|
|
|
if (open)
|
|
{
|
|
for (var i = 0; i < OptionsContainer.transform.childCount; i++)
|
|
{
|
|
var childObject = OptionsContainer.transform.GetChild(i);
|
|
childObject.GetComponent<Text>().text = selectedIndex == i ? $"- {childObject.name} -" : childObject.name;
|
|
childObject.GetComponent<Text>().color = selectedIndex == i ? activeColor : inactiveColor;
|
|
childObject.GetComponent<Text>().fontSize = selectedIndex == i ? activeFontSize : inactiveFontSize;
|
|
}
|
|
var newConfirmState = Input.GetButton(menuConfirmGamepadInput);
|
|
var newRejectState = Input.GetButton(menuRejectGamepadInput);
|
|
var newMenuVerticalState = Input.GetAxis(menuVerticalGamepadInput);
|
|
var newMenuHorizontalState = Input.GetAxis(menuHorizontalGamepadInput);
|
|
if (oldVerticalState == 0 && newMenuVerticalState < 0)
|
|
{
|
|
if (selectedIndex == OptionsContainer.transform.childCount - 1)
|
|
selectedIndex = 0;
|
|
else
|
|
selectedIndex++;
|
|
}
|
|
if (oldVerticalState == 0 && newMenuVerticalState > 0)
|
|
{
|
|
if (selectedIndex == 0)
|
|
selectedIndex = OptionsContainer.transform.childCount - 1;
|
|
else
|
|
selectedIndex--;
|
|
}
|
|
if (!loadingSubmenuOpen && !savingSubmenuOpen && !settingsSubmenuOpen)
|
|
{
|
|
if ((!oldConfirmState && newConfirmState) || (oldHorizontalState == 0 && newMenuHorizontalState > 0))
|
|
{
|
|
switch (selectedIndex)
|
|
{
|
|
case 0:
|
|
ResumeGame();
|
|
break;
|
|
case 1:
|
|
OpenLoadingSubmenu();
|
|
break;
|
|
case 2:
|
|
OpenSavingSubmenu();
|
|
break;
|
|
case 3:
|
|
OpenSettingsSubmenu();
|
|
break;
|
|
case 4:
|
|
ExitGame();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
oldConfirmState = newConfirmState;
|
|
oldRejectState = newRejectState;
|
|
oldHorizontalState = newMenuHorizontalState;
|
|
oldVerticalState = newMenuVerticalState;
|
|
}
|
|
}
|
|
|
|
void ResumeGame()
|
|
{
|
|
open = false;
|
|
PauseMenu.active = false;
|
|
Time.timeScale = 1.0f;
|
|
}
|
|
|
|
void OpenLoadingSubmenu()
|
|
{
|
|
loadingSubmenuOpen = true;
|
|
}
|
|
|
|
void OpenSavingSubmenu()
|
|
{
|
|
savingSubmenuOpen = true;
|
|
}
|
|
|
|
void OpenSettingsSubmenu()
|
|
{
|
|
settingsSubmenuOpen = true;
|
|
}
|
|
|
|
void ExitGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|
|
} |