265 lines
8.4 KiB
C#
265 lines
8.4 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using Unity.Notifications;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SettingPopupPanel : MonoBehaviour
|
|
{
|
|
ISettingService settingService;
|
|
public Button btn_close;
|
|
public Button btn_mask;
|
|
public BtnSwitch music;
|
|
public BtnSwitch sound;
|
|
public BtnSwitch vibrate;
|
|
public BtnSwitch notification;
|
|
public BtnSwitch weight;
|
|
public GameObject bg_light;
|
|
public TMP_Text text_graphic;
|
|
public Button btn_arrow_left;
|
|
public Button btn_arrow_right;
|
|
public Button btn_language;
|
|
public TMP_Text txt_language;
|
|
|
|
public Button btn_policy;
|
|
public Button btn_service;
|
|
public Button btn_delete;
|
|
public Button btn_clearcache;
|
|
//new
|
|
|
|
public TMP_Text text_id;
|
|
public TMP_Text text_version;
|
|
protected CompositeDisposable disposables = new CompositeDisposable();
|
|
/* 低 Low",
|
|
中 Medium",
|
|
高 High",
|
|
超高 Ultra"
|
|
*/
|
|
|
|
string[] qualityLevels = new string[]
|
|
{
|
|
"UI_SettingPopupPanel_17",
|
|
"UI_SettingPopupPanel_18",
|
|
"UI_SettingPopupPanel_19",
|
|
"UI_SettingPopupPanel_20",
|
|
};
|
|
int level;
|
|
|
|
private IConfig config;
|
|
|
|
private void Awake()
|
|
{
|
|
settingService = GContext.container.Resolve<ISettingService>();
|
|
config = GContext.container.Resolve<IConfig>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
btn_close.onClick.AddListener(() => { UIManager.Instance.DestroyUI(UITypes.SettingPopupPanel); });
|
|
btn_mask.onClick.AddListener(() => { UIManager.Instance.DestroyUI(UITypes.SettingPopupPanel); });
|
|
music.onToggle.AddListener(OnToggleMusic);
|
|
sound.onToggle.AddListener(OnToggleSound);
|
|
vibrate.onToggle.AddListener(OnToggleVibrate);
|
|
notification.OverrideListener(OnToggleNotification);
|
|
weight.onToggle.AddListener(OnToggleWeight);
|
|
text_id.text = $"ID: {GContext.container.Resolve<IUserService>().CustomId}";
|
|
text_version.text = $"Ver. {VersionTool.FromLocal().ToVerString()}";
|
|
music.SetState(settingService.Music);
|
|
sound.SetState(settingService.Sound);
|
|
vibrate.SetState(settingService.Vibration);
|
|
notification.SetState(settingService.Notice);
|
|
weight.SetState(settingService.UnitOfWeight == 1);
|
|
bg_light.SetActive(settingService.UnitOfWeight == 1);
|
|
btn_language.onClick.AddListener(async () =>
|
|
{
|
|
btn_language.enabled = false;
|
|
await UIManager.Instance.GetUIAsync(UITypes.SelectlanguagePopupPanel);
|
|
btn_language.enabled = true;
|
|
});
|
|
|
|
|
|
btn_policy.onClick.AddListener(OpenPrivacy);
|
|
btn_service.onClick.AddListener(OpenUserAgreement);
|
|
btn_delete.onClick.AddListener(OnBtnDelete);
|
|
|
|
btn_clearcache.onClick.AddListener(OnClearcache);
|
|
|
|
GContext.OnEvent<ChangeLanguageEvent>().Subscribe(OnChangeLanguage).AddTo(disposables);
|
|
OnChangeLanguage();
|
|
|
|
//quality
|
|
SetQualityState();
|
|
}
|
|
private void OnBtnDelete()
|
|
{
|
|
UIManager.Instance.ShowUI(new UIType("DeleteAccountPopupPanel"));
|
|
}
|
|
|
|
void OpenPrivacy()
|
|
{
|
|
#if UNITY_IOS
|
|
var k = GConstant.K_IOS_Privacy_Policy_URL;
|
|
var v = GConstant.V_IOS_Privacy_Policy_URL;
|
|
#else
|
|
var k = GConstant.K_Android_Privacy_Policy_URL;
|
|
var v = GConstant.V_Android_Privacy_Policy_URL;
|
|
#endif
|
|
string privacy = config.Get(k, v);
|
|
Application.OpenURL(privacy);
|
|
}
|
|
|
|
void OpenUserAgreement()
|
|
{
|
|
string agreement = config.Get(GConstant.K_User_Agreement_URL, GConstant.V_User_Agreement_URL);
|
|
Application.OpenURL(agreement);
|
|
}
|
|
async void OnClearcache()
|
|
{
|
|
string title = LocalizationMgr.GetText("UI_SettingPopupPanel_26");
|
|
string info = LocalizationMgr.GetText("UI_ClearCachePopupPanel_1");
|
|
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
|
string l_Label = LocalizationMgr.GetText("UI_COMMON_cancel");
|
|
string r_label = LocalizationMgr.GetText("UI_COMMON_confirm");
|
|
var noticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
|
noticeConfirmPopupPanel.Init(2, title, info, onClickRight: OnClearcacheConfirm, btn_left_text: l_Label, btn_right_text: r_label);
|
|
}
|
|
|
|
async void OnClearcacheConfirm()
|
|
{
|
|
PlayerPrefs.DeleteAll();
|
|
string title = LocalizationMgr.GetText("UI_ClearCachePopupPanel_2");
|
|
string info = LocalizationMgr.GetText("UI_ClearCachePopupPanel_3");
|
|
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
|
|
|
var noticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
|
noticeConfirmPopupPanel.Init(1, title, info, onClickLeft: Restart, onClose: Restart);
|
|
}
|
|
private async void Restart()
|
|
{
|
|
QuitStage.Logout = true;
|
|
await LoadingScreen.Show();
|
|
await GContext.container.Resolve<IStageService>().SwitchStageAsync("QuitStage");
|
|
}
|
|
void SetQualityState()
|
|
{
|
|
if (QualityLimit.IsLimitDevice())
|
|
{
|
|
qualityLevels = new string[] { "UI_SettingPopupPanel_17", "UI_SettingPopupPanel_18", };
|
|
}
|
|
else
|
|
{
|
|
qualityLevels = new string[] { "UI_SettingPopupPanel_17", "UI_SettingPopupPanel_18", "UI_SettingPopupPanel_19", "UI_SettingPopupPanel_20", };
|
|
}
|
|
level = QualitySettings.GetQualityLevel();
|
|
if (level >= qualityLevels.Length)
|
|
{
|
|
level = qualityLevels.Length - 1;
|
|
}
|
|
text_graphic.text = LocalizationMgr.GetText(qualityLevels[level]);
|
|
btn_arrow_left.onClick.AddListener(() =>
|
|
{
|
|
level--;
|
|
if (level < 0)
|
|
{
|
|
level = qualityLevels.Length - 1;
|
|
}
|
|
OnChangeQuality(level);
|
|
});
|
|
btn_arrow_right.onClick.AddListener(() =>
|
|
{
|
|
level++;
|
|
if (level >= qualityLevels.Length)
|
|
{
|
|
level = 0;
|
|
}
|
|
OnChangeQuality(level);
|
|
});
|
|
}
|
|
void OnChangeQuality(int level)
|
|
{
|
|
QualityManager.ChangeQuality(level);
|
|
zzwater.URPHelper.RendererFeatureSetActive(false, "FSBlur");
|
|
zzwater.URPHelper.RendererFeatureSetActive(false, "FSWave");
|
|
text_graphic.text = LocalizationMgr.GetText(qualityLevels[level]);
|
|
}
|
|
|
|
private void OnToggleMusic(bool isOn)
|
|
{
|
|
settingService.Music = isOn;
|
|
}
|
|
|
|
private void OnToggleSound(bool isOn)
|
|
{
|
|
settingService.Sound = isOn;
|
|
}
|
|
|
|
private void OnToggleVibrate(bool isOn)
|
|
{
|
|
settingService.Vibration = isOn;
|
|
if (isOn)
|
|
{
|
|
GContext.Publish(new VibrationData(HapticTypes.LightImpact));
|
|
}
|
|
}
|
|
void OnToggleWeight(bool isOn)
|
|
{
|
|
bg_light.SetActive(isOn);
|
|
settingService.UnitOfWeight = isOn ? 1 : 0;
|
|
LocalizationMgr.SetUnitOfWeight();
|
|
}
|
|
private void OnToggleNotification(bool isOn)
|
|
{
|
|
if (isOn)
|
|
{
|
|
GContext.container.Resolve<ILocalNotificationService>().OpenSettings();
|
|
// NotificationCenter.OpenNotificationSettings();
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.ShowUI(new UIType("SettingNotificationsPopupPanel"));
|
|
}
|
|
}
|
|
|
|
private void OnChangeLanguage(ChangeLanguageEvent changeLanguageEvent = null)
|
|
{
|
|
txt_language.text = LocalizationMgr.LanguageLanguages[LocalizationMgr.LanguageIndex];
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
disposables.Dispose();
|
|
disposables = null;
|
|
}
|
|
|
|
bool isNoticeOpen;
|
|
private void OnApplicationFocus(bool hasFocus)
|
|
{
|
|
if (!hasFocus)
|
|
{
|
|
isNoticeOpen = settingService.Notice;
|
|
}
|
|
else
|
|
{
|
|
var isNoticeOn_now = settingService.Notice;
|
|
if (isNoticeOpen != isNoticeOn_now)
|
|
{
|
|
isNoticeOpen = isNoticeOn_now;
|
|
Debug.Log($"SettingPopupPanel OnApplicationFocus Notice enable {isNoticeOpen}");
|
|
notification.SetStateSmooth(isNoticeOpen);
|
|
if (isNoticeOpen)
|
|
{
|
|
GContext.container.Resolve<ILocalNotificationService>().ScheduleDefaultNotification();
|
|
}
|
|
else
|
|
{
|
|
GContext.container.Resolve<ILocalNotificationService>().ClearAllNotification();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|