163 lines
5.2 KiB
C#
163 lines
5.2 KiB
C#
using BrewMonster.Network;
|
|
using BrewMonster.UI;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class DlgSetting : AUIDialog
|
|
{
|
|
[Header("Box Button")]
|
|
[SerializeField] private Button btn_system;
|
|
[SerializeField] private Button btn_interface;
|
|
[SerializeField] private Button btn_setting;
|
|
[SerializeField] private Button btn_sound;
|
|
[SerializeField] private Button btn_default;
|
|
[SerializeField] private Button btn_confirm;
|
|
[SerializeField] private Button btn_close;
|
|
|
|
[Header("Content")]
|
|
[SerializeField] private GameObject content_interface;
|
|
[SerializeField] private GameObject content_sound;
|
|
|
|
[Header("Sprite")]
|
|
[SerializeField] private Sprite tab_active;
|
|
[SerializeField] private Sprite tab_unactive;
|
|
|
|
[Header("Tab Text Color")]
|
|
[SerializeField] private Color activeTextColor = Color.white;
|
|
[SerializeField] private Color inactiveTextColor = Color.white;
|
|
|
|
private Button[] tabButtons;
|
|
|
|
[SerializeField] private SettingSound settingSoundCtrl;
|
|
[SerializeField] private SettingInterface settingGraphicCtrl;
|
|
|
|
int curTab = 1;
|
|
|
|
public override void Awake()
|
|
{
|
|
tabButtons = new[]
|
|
{
|
|
btn_system,
|
|
btn_interface,
|
|
btn_setting,
|
|
btn_sound
|
|
};
|
|
}
|
|
|
|
public override void OnEnable()
|
|
{
|
|
btn_system.onClick.AddListener(OnBtnSystem);
|
|
btn_interface.onClick.AddListener(OnBtnInterface);
|
|
btn_setting.onClick.AddListener(OnBtnSetting);
|
|
btn_sound.onClick.AddListener(OnBtnSound);
|
|
btn_close.onClick.AddListener(OnBtnClose);
|
|
btn_confirm.onClick.AddListener(OnClickBtnConfirm);
|
|
|
|
curTab = 1;
|
|
UpdateUITabs();
|
|
OnBtnInterface();
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
btn_system.onClick.RemoveListener(OnBtnSystem);
|
|
btn_interface.onClick.RemoveListener(OnBtnInterface);
|
|
btn_setting.onClick.RemoveListener(OnBtnSetting);
|
|
btn_sound.onClick.RemoveListener(OnBtnSound);
|
|
btn_close.onClick.RemoveListener(OnBtnClose);
|
|
btn_confirm.onClick.RemoveListener(OnClickBtnConfirm);
|
|
}
|
|
|
|
private void OnBtnSystem()
|
|
{
|
|
SetActiveTab(btn_system);
|
|
curTab = 0;
|
|
UpdateUITabs();
|
|
}
|
|
|
|
private void OnBtnInterface()
|
|
{
|
|
SetActiveTab(btn_interface);
|
|
content_interface.SetActive(true);
|
|
content_sound.SetActive(false);
|
|
curTab = 1;
|
|
UpdateUITabs();
|
|
}
|
|
|
|
private void OnBtnSetting()
|
|
{
|
|
SetActiveTab(btn_setting);
|
|
curTab = 2;
|
|
UpdateUITabs();
|
|
}
|
|
|
|
private void OnBtnSound()
|
|
{
|
|
SetActiveTab(btn_sound);
|
|
content_interface.SetActive(false);
|
|
content_sound.SetActive(true);
|
|
curTab = 3;
|
|
UpdateUITabs();
|
|
}
|
|
|
|
private void SetActiveTab(Button activeButton)
|
|
{
|
|
foreach(Button button in tabButtons)
|
|
{
|
|
if (button == null)
|
|
continue;
|
|
|
|
Image image = button.GetComponent<Image>();
|
|
if(image != null)
|
|
{
|
|
image.sprite = button == activeButton ? tab_active : tab_unactive;
|
|
}
|
|
|
|
TMP_Text text = button.GetComponentInChildren<TMP_Text>();
|
|
if(text != null)
|
|
{
|
|
text.color = button == activeButton ? activeTextColor : inactiveTextColor;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnBtnClose()
|
|
{
|
|
CECUIManager.Instance.HideCurrentUIInStack();
|
|
}
|
|
|
|
private void OnClickBtnConfirm()
|
|
{
|
|
EC_Game.SetActiveSoundMaster(settingSoundCtrl.GetActiveSoundMaster());
|
|
EC_Game.SetActiveSoundSFX(settingSoundCtrl.GetActiveSFX());
|
|
EC_Game.SetActiveBgrMusic(settingSoundCtrl.GetActiveBgrMusic());
|
|
|
|
EC_Game.SetSettingActiveShadow(settingGraphicCtrl.GetValueToggleShadow());
|
|
EC_Game.SetSettingActiveFullResolution(settingGraphicCtrl.GetValueToggleFullResolution());
|
|
EC_Game.SetSettingActiveFog(settingGraphicCtrl.GetValueToggleFog());
|
|
|
|
EC_Game.SetVolumeBgrMusic(settingSoundCtrl.GetVolumeBgrMusic());
|
|
EC_Game.SetVolumeSoundMaster(settingSoundCtrl.GetVolumeMaster());
|
|
EC_Game.SetVolumeSoundSFX(settingSoundCtrl.GetVolumeSFX());
|
|
|
|
EC_Game.SetSettingViewDistance(settingGraphicCtrl.GetValueViewDistance());
|
|
EC_Game.SetSettingViewDistanceEP(settingGraphicCtrl.GetValueViewDistanceEP());
|
|
EC_Game.SetSettingViewDistanceNPC(settingGraphicCtrl.GetValueViewDistanceNPC());
|
|
|
|
OnBtnClose();
|
|
}
|
|
|
|
private void UpdateUITabs()
|
|
{
|
|
for(int i = 0; i < tabButtons.Length; i++)
|
|
{
|
|
tabButtons[i].image.sprite = (curTab == i) ? tab_active: tab_unactive;
|
|
}
|
|
}
|
|
}
|
|
}
|