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.
154 lines
5.5 KiB
154 lines
5.5 KiB
using UnityEngine; |
|
using UnityEngine.UI; |
|
using UnityEngine.EventSystems; |
|
|
|
using TMPro; |
|
|
|
public class SettingsDialog : BaseDialog |
|
{ |
|
[SerializeField] TextMeshProUGUI m_headerText; |
|
[SerializeField] TextMeshProUGUI m_soundText; |
|
[SerializeField] TextMeshProUGUI m_musicText; |
|
|
|
[SerializeField] Button m_buttonSound; |
|
[SerializeField] Button m_buttonMusic; |
|
[SerializeField] Button m_buttonExit; |
|
[SerializeField] Button m_buttonContactUs; |
|
|
|
[SerializeField] Sprite m_activeToggle; |
|
[SerializeField] Sprite m_nonActiveToggle; |
|
|
|
bool m_isSoundActive = true; |
|
bool m_isMusicActive = true; |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void Start () |
|
{ |
|
m_type = DialogType.SETTINGS_DIALOG; |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
public void Init() |
|
{ |
|
m_isSoundActive = GlobalsVar.gNeedPlaySounds; |
|
m_isMusicActive = GlobalsVar.gNeedPlayMusic; |
|
|
|
InitButtons(); |
|
InitTexts(); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitTexts() |
|
{ |
|
if (m_headerText) |
|
m_headerText.text = GlobalsVar.gGameTextMng.GetGameText(29).ToUpper(); |
|
|
|
if (m_soundText) |
|
m_soundText.text = GlobalsVar.gGameTextMng.GetGameText(30); |
|
|
|
if (m_musicText) |
|
m_musicText.text = GlobalsVar.gGameTextMng.GetGameText(31); |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void InitButtons() |
|
{ |
|
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); |
|
} |
|
|
|
if (m_buttonMusic) |
|
{ |
|
m_buttonMusic.onClick.AddListener(ButtonPress); |
|
m_buttonMusic.transform.Find("text_on").GetComponent<TextMeshProUGUI>().text = GlobalsVar.gGameTextMng.GetGameText(33).ToUpper(); |
|
m_buttonMusic.transform.Find("text_off").GetComponent<TextMeshProUGUI>().text = GlobalsVar.gGameTextMng.GetGameText(34).ToUpper(); |
|
SetToggleState(m_buttonMusic.gameObject, m_isMusicActive); |
|
} |
|
|
|
if (m_buttonExit) |
|
m_buttonExit.onClick.AddListener(ButtonPress); |
|
|
|
if (m_buttonContactUs) |
|
{ |
|
m_buttonContactUs.onClick.AddListener(ButtonPress); |
|
CommonFunctions.SetButtonText(m_buttonContactUs.gameObject, GlobalsVar.gGameTextMng.GetGameText(32)); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
void ButtonPress() |
|
{ |
|
GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject; |
|
if (currentClickedObj == m_buttonExit.gameObject) |
|
HideDialog(); |
|
else if (currentClickedObj == m_buttonSound.gameObject) |
|
{ |
|
SetToggleState(m_buttonSound.gameObject, !m_isSoundActive); |
|
if (m_isSoundActive) |
|
GlobalsVar.gNeedPlaySounds = true; |
|
else |
|
GlobalsVar.gNeedPlaySounds = false; |
|
} |
|
else if (currentClickedObj == m_buttonMusic.gameObject) |
|
{ |
|
SetToggleState(m_buttonMusic.gameObject, !m_isMusicActive); |
|
if (m_isMusicActive) |
|
{ |
|
GlobalsVar.gNeedPlayMusic = true; |
|
MusicManager.Instance.StartMusic(); |
|
} |
|
else |
|
{ |
|
GlobalsVar.gNeedPlayMusic = false; |
|
MusicManager.Instance.FadeDownMusicVolume(); |
|
} |
|
} |
|
else if (currentClickedObj == m_buttonContactUs.gameObject) |
|
{ |
|
Application.OpenURL("https://apelsingames.com/"); |
|
} |
|
} |
|
|
|
//----------------------------------------------------------------------------------------- |
|
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); |
|
} |
|
} |
|
else if (obj == m_buttonMusic.gameObject) |
|
{ |
|
m_isMusicActive = active; |
|
if (m_isMusicActive) |
|
{ |
|
img.sprite = m_activeToggle; |
|
m_buttonMusic.transform.Find("text_on").gameObject.SetActive(true); |
|
m_buttonMusic.transform.Find("text_off").gameObject.SetActive(false); |
|
} |
|
else |
|
{ |
|
img.sprite = m_nonActiveToggle; |
|
m_buttonMusic.transform.Find("text_on").gameObject.SetActive(false); |
|
m_buttonMusic.transform.Find("text_off").gameObject.SetActive(true); |
|
} |
|
} |
|
} |
|
}
|
|
|