Files
BallCrushBest_GP/Assets/Scripts/ModuleUI/Menu/MenuUI.cs
T

239 lines
6.7 KiB
C#

using System;
using FairyGUI;
using FGUI.ZM_Setting_07;
// using FGUI.G006_menu;
using UnityEngine;
namespace BallKingdomCrush
{
public class MenuUI : BaseUI
{
private MenuUICtrl ctrl;
private MenuModel model;
private FGUI.ZM_Setting_07.com_setting ui;
private int selectIndex = -1;
private int total_item;
public MenuUI(MenuUICtrl ctrl) : base(ctrl)
{
uiName = UIConst.MenuUI;
this.ctrl = ctrl;
}
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "ZM_Setting_07";
uiInfo.assetName = "com_setting";
uiInfo.layerType = UILayerType.Popup;
uiInfo.isNeedOpenAnim = false;
uiInfo.isNeedCloseAnim = false;
uiInfo.isNeedUIMask = true;
}
#region
protected override void OnInit()
{
model = moduleManager.GetModel(ModelConst.MenuModel) as MenuModel;
}
protected override void OnClose()
{
CommonHelper.FadeOut(ui);
}
protected override void OnBind()
{
ui = baseUI as FGUI.ZM_Setting_07.com_setting;
}
protected override void OnOpenBefore(object args)
{
total_item = 8;
selectIndex = DataMgr.PlayerAvatarId.Value;
InitView();
}
protected override void OnOpen(object args)
{
CommonHelper.FadeIn(ui);
}
protected override void OnHide()
{
}
protected override void OnDisplay(object args)
{
}
#endregion
#region
protected override void AddListener()
{
HallManager.Instance.AddChangeGiftSwitch(InitView);
}
protected override void RemoveListener()
{
HallManager.Instance.RemoveChangeGiftSwitch(InitView);
}
#endregion
private void InitView()
{
var namStr = GameHelper.GetUserName();
// com_Person.edit_name.input.text = namStr;
// com_Person.btn_update.SetClick(UpdateUserInfo);
// com_Person.edit_name.btn_amend.SetClick(SaveName);
ui.btn_back.SetClick(OnCloseView);
ui.btn_music.SetClick(OnClickSetMusic);
ui.btn_sound.SetClick(OnClickSoundBtn);
ui.btn_privacy.menus.selectedIndex = btn_menu.Menus_privacy;
ui.btn_terms.menus.selectedIndex = btn_menu.Menus_terms;
ui.btn_language.menus.selectedIndex = btn_menu.Menus_delete;
ui.btn_official.menus.selectedIndex = btn_menu.Menus_official;
ui.btn_email.menus.selectedIndex = 5;
ui.btn_restore.menus.selectedIndex = 4;
ui.btn_privacy.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, 0); });
ui.btn_terms.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, 1); });
ui.btn_language.SetClick(() =>
{
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LanguageViewUI_Open);
});
ui.btn_official.SetClick(() => { Application.OpenURL("https://www.ballcrushbest.com"); });
ui.btn_restore.SetClick(Restore);
ui.btn_email.SetClick(() => {
GameHelper.OpenEmail();
});
SetUID();
SetVersion();
RefreshMusicUI();
// com_Person.list.itemRenderer = UpdateItem;
// com_Person.list.numItems = total_item;
}
private void Restore()
{
if (GameHelper.IsAdModelOfPay()) return;
// GooglePayManager.Instance.RestoreNonConsumable();
}
// private void UpdateItem(int index, GObject items)
// {
// var currentIndex = index + 1;
// var head = items as btn_item_head;
// var imgHead = head.head as btn_head;
// TextureHelper.SetAvatarToLoader(currentIndex, imgHead.load_avatar);
// head.head_select.selectedIndex = selectIndex == currentIndex
// ? btn_item_head.Head_select_select
// : btn_item_head.Head_select_none;
// head.SetClick(() =>
// {
// selectIndex = currentIndex;
// com_Person.list.numItems = total_item;
// });
// }
private void UpdateUserInfo()
{
if (selectIndex != -1)
{
DataMgr.PlayerAvatarId.Value = selectIndex;
}
SaveName();
OnCloseView();
}
private void SaveName()
{
// var name = com_Person.edit_name.input.text;
// if (string.IsNullOrEmpty(name) || name.IsNullOrWhiteSpace())
// {
// GameHelper.ShowTips("empty_input", true);
// return;
// }
// // if (name.Equals(GameHelper.GetPlayerInviteCode()))
// // {
// // return;
// // }
// if (name.Equals(PreferencesMgr.Instance.PlayerName)) return;
// GameHelper.ShowTips($"Name changed successfully");
// PreferencesMgr.Instance.PlayerName = name;
}
private void SetVersion()
{
ui.text_version.SetVar("count", Application.version).FlushVars();
}
private void SetUID()
{
ui.text_uid.SetVar("UID", GameHelper.GetLoginModel().Uid.ToString()).FlushVars();
}
public override void OnSwitchLanguage()
{
base.OnSwitchLanguage();
SetVersion();
SetUID();
}
private void CloseMenu(Action action = null)
{
CtrlCloseUI();
action?.Invoke();
}
private void OnCloseView()
{
CloseMenu();
}
private void OnClickSetMusic()
{
model.IsOpenMusic = !model.IsOpenMusic;
RefreshMusicUI();
}
private void OnClickSoundBtn()
{
model.IsOpenEffect = !model.IsOpenEffect;
RefreshMusicUI();
}
private void RefreshMusicUI()
{
ui.btn_music.music_on_off.selectedIndex =
model.IsOpenMusic ? 0 : 1;
ui.btn_sound.sound_on_off.selectedIndex =
model.IsOpenEffect ? 0 : 1;
}
}
}