You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

135 lines
4.6 KiB

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using TMPro;
public class InGamePauseDialog : BaseDialog
{
[SerializeField] TextMeshProUGUI m_headerText;
[SerializeField] TextMeshProUGUI m_progressText;
[SerializeField] TextMeshProUGUI m_soundText;
[SerializeField] Button m_buttonToMenu;
[SerializeField] Button m_buttonResume;
[SerializeField] Button m_buttonSound;
[SerializeField] Sprite m_activeToggle;
[SerializeField] Sprite m_nonActiveToggle;
bool m_isSoundActive = true;
//-----------------------------------------------------------------------------------------
void Start ()
{
m_type = DialogType.IN_GAME_PAUSE_DIALOG;
}
//-----------------------------------------------------------------------------------------
public void Init()
{
m_isSoundActive = GlobalsVar.gNeedPlaySounds;
InitTexts();
InitButtons();
}
//-----------------------------------------------------------------------------------------
void InitButtons()
{
if (m_buttonToMenu)
{
m_buttonToMenu.onClick.AddListener(ButtonPress);
CommonFunctions.SetButtonText(m_buttonToMenu.gameObject, GlobalsVar.gGameTextMng.GetGameText(27).ToUpper());
}
if (m_buttonResume)
{
m_buttonResume.onClick.AddListener(ButtonPress);
CommonFunctions.SetButtonText(m_buttonResume.gameObject, GlobalsVar.gGameTextMng.GetGameText(28).ToUpper());
}
if (m_buttonSound)
{
m_buttonSound.onClick.AddListener(ButtonPress);
m_buttonSound.transform.Find("text_on").GetComponent<TextMeshProUGUI>().text = GlobalsVar.gGameTextMng.GetGameText(33).ToUpper();
m_buttonSound.transform.Find("text_off").GetComponent<TextMeshProUGUI>().text = GlobalsVar.gGameTextMng.GetGameText(34).ToUpper();
SetToggleState(m_buttonSound.gameObject, m_isSoundActive);
}
}
//-----------------------------------------------------------------------------------------
void SetToggleState(GameObject obj, bool active)
{
Image img = obj.GetComponent<Image>();
if (obj == m_buttonSound.gameObject)
{
m_isSoundActive = active;
if (m_isSoundActive)
{
img.sprite = m_activeToggle;
m_buttonSound.transform.Find("text_on").gameObject.SetActive(true);
m_buttonSound.transform.Find("text_off").gameObject.SetActive(false);
}
else
{
img.sprite = m_nonActiveToggle;
m_buttonSound.transform.Find("text_on").gameObject.SetActive(false);
m_buttonSound.transform.Find("text_off").gameObject.SetActive(true);
}
}
}
//-----------------------------------------------------------------------------------------
void ButtonPress()
{
GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject;
if (currentClickedObj == m_buttonResume.gameObject)
HideDialog();
else if (currentClickedObj == m_buttonToMenu.gameObject)
{
HideDialog();
Time.timeScale = 1f;
if (GlobalsVar.gBoard)
{
GameObject dlg = GlobalsVar.gBoard.StartDialog("EndRunDialog");
dlg.GetComponent<EndRunDialog>().Init();
}
}
else if (currentClickedObj == m_buttonSound.gameObject)
{
SetToggleState(m_buttonSound.gameObject, !m_isSoundActive);
if (m_isSoundActive)
GlobalsVar.gNeedPlaySounds = true;
else
GlobalsVar.gNeedPlaySounds = false;
}
}
//-----------------------------------------------------------------------------------------
void InitTexts()
{
if (m_headerText)
m_headerText.text = GlobalsVar.gGameTextMng.GetGameText(26).ToUpper();
if (m_progressText)
{
int stageId = CommonFunctions.GetStageId();
int maxRooms = GlobalsVar.gRoomByStage[stageId - 1];
string progressStr = string.Format(GlobalsVar.gGameTextMng.GetGameText(25), GlobalsVar.gCurrentRoomInRun - 1, maxRooms);
m_progressText.text = progressStr;
}
if (m_soundText)
m_soundText.text = GlobalsVar.gGameTextMng.GetGameText(30);
}
//-----------------------------------------------------------------------------------------
public override void Update ()
{
base.Update();
}
}