223 lines
6.2 KiB
C#
223 lines
6.2 KiB
C#
using System;
|
|
using FairyGUI;
|
|
using FGUI.P01_Common;
|
|
using FGUI.P04_Menu;
|
|
|
|
// using FGUI.G006_menu;
|
|
|
|
using UnityEngine;
|
|
|
|
namespace FlowerPower
|
|
{
|
|
public class MenuUI : BaseUI
|
|
{
|
|
private MenuUICtrl ctrl;
|
|
private MenuModel model;
|
|
private FGUI.P04_Menu.com_setting ui;
|
|
private int selectIndex = -1;
|
|
|
|
private int total_item;
|
|
private bool is_exit_game = false;
|
|
|
|
public MenuUI(MenuUICtrl ctrl) : base(ctrl)
|
|
{
|
|
uiName = UIConst.MenuUI;
|
|
this.ctrl = ctrl;
|
|
}
|
|
|
|
protected override void SetUIInfo(UIInfo uiInfo)
|
|
{
|
|
uiInfo.packageName = "P04_Menu";
|
|
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.P04_Menu.com_setting;
|
|
}
|
|
|
|
protected override void OnOpenBefore(object args)
|
|
{
|
|
if (args != null)
|
|
{
|
|
is_exit_game = (bool)args;
|
|
}
|
|
if (Screen.safeArea.y != 0)
|
|
{
|
|
ui.com_gold.y += Screen.safeArea.y;
|
|
|
|
}
|
|
//
|
|
|
|
total_item = 8;
|
|
selectIndex = PreferencesMgr.Instance.PlayerAvatarId;
|
|
|
|
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()
|
|
{
|
|
ui.com_gold.GetChild("text_gold").text = $"{PreferencesMgr.Instance.Currency101:N0}";
|
|
|
|
|
|
|
|
var namStr = GameHelper.GetUserName();
|
|
|
|
if (is_exit_game)
|
|
{
|
|
ui.btn_quit.visible = true;
|
|
}
|
|
|
|
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_official.menus.selectedIndex = btn_menu.Menus_official;
|
|
ui.btn_record.menus.selectedIndex = btn_menu.Menus_record;
|
|
ui.btn_privacy.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open); });
|
|
ui.btn_terms.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, true); });
|
|
ui.btn_official.SetClick(() => { OpenBrowser.OpenURL("https://www.flowerlazypower.fun/"); });
|
|
ui.btn_contact_us.SetClick(() => { GameHelper.OpenEmail(); });
|
|
ui.btn_quit.SetClick(() =>
|
|
{
|
|
if (is_exit_game)
|
|
{
|
|
GameDispatcher.Instance.Dispatch(GameMsg.ExitGame);
|
|
}
|
|
OnCloseView();
|
|
});
|
|
SetUID();
|
|
SetVersion();
|
|
RefreshMusicUI();
|
|
|
|
if (GameHelper.IsGiftSwitch()) {
|
|
ui.btn_restore.visible = false;
|
|
}
|
|
ui.btn_restore.SetClick(() =>
|
|
{
|
|
PurchasingManager.Instance.IosRestore((success,message)=>{
|
|
Debug.Log("[barry] restore success message: " + message);
|
|
if (success)
|
|
{
|
|
Debug.Log("[barry] restore success: " + success);
|
|
GameHelper.ShowTips("Restore Purchases Success!");
|
|
// SaveData.GetSaveobject().is_get_packreward = success;
|
|
SaveData.GetSaveobject().have_slot = success;
|
|
}
|
|
else
|
|
{
|
|
// Debug.Log("[barry] restore failed: " + success);
|
|
GameHelper.ShowTips("There are no recoverable transactions");
|
|
}
|
|
});
|
|
CtrlCloseUI();
|
|
});
|
|
}
|
|
|
|
|
|
private void SetVersion()
|
|
{
|
|
// Debug.Log($"SetVersion====== {Application.version}");
|
|
ui.text_version.SetVar("count", Application.version.ToString()).FlushVars();
|
|
}
|
|
|
|
private void SetUID()
|
|
{
|
|
// if (GameHelper.IsGiftSwitch()) {
|
|
ui.text_uid.SetVar("UID", GameHelper.GetLoginModel().uid.ToString()).FlushVars();
|
|
// } else {
|
|
// ui.text_uid.visible = false;
|
|
// }
|
|
}
|
|
|
|
public override void OnSwitchLanguage()
|
|
{
|
|
base.OnSwitchLanguage();
|
|
|
|
SetVersion();
|
|
|
|
SetUID();
|
|
}
|
|
|
|
private void OnCloseView()
|
|
{
|
|
// CloseMenu();
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.MenuUI_Close, true);
|
|
TimerHelper.mEasy.AddTimer(0.5f, () =>
|
|
{
|
|
CtrlCloseUI();
|
|
});
|
|
|
|
}
|
|
|
|
private void OnClickSetMusic()
|
|
{
|
|
model.IsOpenMusic = !model.IsOpenMusic;
|
|
RefreshMusicUI();
|
|
}
|
|
|
|
private void OnClickSoundBtn()
|
|
{
|
|
model.IsOpenEffect = !model.IsOpenEffect;
|
|
RefreshMusicUI();
|
|
}
|
|
|
|
private void RefreshMusicUI()
|
|
{
|
|
ui.btn_music.on_off.selectedIndex =
|
|
model.IsOpenMusic ? btn_on_off.On_off_on : btn_on_off.On_off_off;
|
|
ui.btn_sound.on_off.selectedIndex =
|
|
model.IsOpenEffect ? btn_on_off.On_off_on : btn_on_off.On_off_off;
|
|
}
|
|
}
|
|
} |