Files
back_cantanBuilding/Assets/Scripts/UI/Setting/SettingPopupPanel.cs
2026-05-26 16:15:54 +08:00

256 lines
9.0 KiB
C#

using System;
using asap.core;
using game;
using Game;
using GameCore;
using TMPro;
using UniRx;
using Unity.Notifications;
using UnityEngine;
using UnityEngine.UI;
public class SettingPopupPanel : MonoBehaviour
{
private IConfig config;
ISettingService settingService;
public Button btn_close;
public Button btn_mask;
public BtnSwitch music;
public BtnSwitch sound;
public BtnSwitch vibrate;
public BtnSwitch notification;
public Button btn_language;
public TMP_Text txt_language;
public Button btn_policy;
public Button btn_contact;
public Button btn_announcement;
public Button btn_service;
public Button btn_delete;
public Button btn_social;
public Button btn_logout;
public Button btn_support;
//new
public ToggleSwitch toggles_quality;
public ToggleSwitch toggles_weight;
public TMP_Text text_id;
public TMP_Text text_version;
protected CompositeDisposable disposables = new CompositeDisposable();
private void Awake()
{
config = GContext.container.Resolve<IConfig>();
settingService = GContext.container.Resolve<ISettingService>();
btn_close = transform.Find("btn_close").GetComponent<Button>();
btn_mask = transform.Find("mask").GetComponent<Button>();
music = transform.Find("root/normal_setting/music/btn_setting").GetComponent<BtnSwitch>();
sound = transform.Find("root/normal_setting/sound/btn_setting").GetComponent<BtnSwitch>();
vibrate = transform.Find("root/normal_setting/vibrate/btn_setting").GetComponent<BtnSwitch>();
notification = transform.Find("root/normal_setting/notice/btn_setting").GetComponent<BtnSwitch>();
btn_language = transform.Find("root/language_setting/btn_language/btn_green_c").GetComponent<Button>();
txt_language = transform.Find("root/language_setting/btn_language/btn_green_c/Ani_Container/p_text").GetComponent<TMP_Text>();
btn_policy = transform.Find("root/user_setting/btn_setting1/btn_policy").GetComponent<Button>();
btn_contact = transform.Find("root/user_setting/btn_contact/btn_green").GetComponent<Button>();
btn_announcement = transform.Find("root/user_setting/btn_announcement/btn_green").GetComponent<Button>();
btn_service = transform.Find("root/user_setting/btn_service/btn_green").GetComponent<Button>();
btn_delete = transform.Find("root/user_setting/btn_delete/btn_green").GetComponent<Button>();
btn_social = transform.Find("root/btn_social/btn_green").GetComponent<Button>();
text_id = transform.Find("root/player_info/text_id").GetComponent<TMP_Text>();
text_version = transform.Find("root/player_info/text_version").GetComponent<TMP_Text>();
toggles_quality = transform.Find("root/normal_setting/graphic/tab").GetComponent<ToggleSwitch>();
toggles_weight = transform.Find("root/normal_setting/weight/tab").GetComponent<ToggleSwitch>();
}
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);
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);
btn_policy.onClick.AddListener(OpenPrivacy);
// btn_contact.onClick.AddListener(() => { UIManager.Instance.GetUI(UITypes.ContactPopupPanel); });
btn_language.onClick.AddListener(async () =>
{
btn_language.enabled = false;
await UIManager.Instance.GetUIAsync(UITypes.SelectlanguagePopupPanel);
btn_language.enabled = true;
});
btn_announcement.onClick.AddListener(async () =>
{
btn_announcement.enabled = false;
await UIManager.Instance.GetUIAsync(UITypes.NoticePopupPanel);
btn_announcement.enabled = true;
});
btn_service.onClick.AddListener(OpenUserAgreement);
btn_delete.OnClickAsObservable().Subscribe(async x =>
{
btn_delete.enabled = false;
await UIManager.Instance.GetUIAsync(UITypes.DeleteAccountPopupPanel);
btn_delete.enabled = true;
}).AddTo(disposables);
btn_social.OnClickAsObservable().Subscribe(async x =>
{
btn_social.enabled = false;
await UIManager.Instance.GetUIAsync(UITypes.BindAccountPopupPanel);
btn_social.enabled = true;
}).AddTo(disposables);
btn_logout.OnClickAsObservable().Subscribe(async x =>
{
QuitStage.Logout = true;
DestroyUI();
await LoadingScreen.Show();
await GContext.container.Resolve<IStageService>().SwitchStageAsync("QuitStage");
}).AddTo(disposables);
btn_support.OnClickAsObservable().Subscribe(x =>
{
AIHelp.AIHelpSupport.Show("E001");
#if AGG
using (var e = GEvent.TackEvent("click_support"))
{
e.AddContent("button_position", 1);
}
#endif
}).AddTo(disposables);
GContext.OnEvent<ChangeLanguageEvent>().Subscribe(OnChangeLanguage).AddTo(disposables);
OnChangeLanguage();
//quality
if (QualityLimit.IsLimitDevice())
toggles_quality.HideFromIndex(2);
else
toggles_quality.HideFromIndex(-1);
toggles_quality.SetState(QualitySettings.GetQualityLevel());
toggles_quality.ChannalToggleChange += OnChangeQuality;
toggles_weight.SetState(settingService.UnitOfWeight);
toggles_weight.ChannalToggleChange += OnUnitOfWeight;
}
void OnChangeQuality(int level)
{
QualityManager.ChangeQuality(level);
zzwater.URPHelper.RendererFeatureSetActive(false, "FSBlur");
zzwater.URPHelper.RendererFeatureSetActive(false, "FSWave");
}
void DestroyUI()
{
UIManager.Instance.DestroyUI(UITypes.SettingPopupPanel);
UIManager.Instance.DestroyUI(UITypes.FishingMorePanel);
UIManager.Instance.DestroyUI(UITypes.HomePanel);
UIManager.Instance.DestroyUI(UITypes.CampPanel);
UIManager.Instance.DestroyUI(UITypes.GuidancePanel);
}
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);
}
private void OnToggleMusic(bool isOn)
{
settingService.Music = isOn;
}
private void OnToggleSound(bool isOn)
{
settingService.Sound = isOn;
}
private void OnUnitOfWeight(int unitOfWeight)
{
if (settingService.UnitOfWeight != unitOfWeight)
{
settingService.UnitOfWeight = unitOfWeight;
LocalizationMgr.SetUnitOfWeight();
}
}
private void OnToggleVibrate(bool isOn)
{
settingService.Vibration = isOn;
if (isOn)
{
GContext.Publish(new VibrationData(HapticTypes.LightImpact));
}
}
private void OnToggleNotification(bool isOn)
{
NotificationCenter.OpenNotificationSettings();
}
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();
}
}
}
}
}