449 lines
15 KiB
C#
449 lines
15 KiB
C#
using System;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using Spine.Unity;
|
|
using FairyGUI;
|
|
using FGUI.ZM_Common_01;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using Random = UnityEngine.Random;
|
|
using IgnoreOPS;
|
|
using Unity.VisualScripting;
|
|
using Newtonsoft.Json;
|
|
using System.IO;
|
|
using FGUI.LG_Common;
|
|
using SGModule.Common.Extensions;
|
|
using SGModule.Common.Helper;
|
|
using SGModule.Net;
|
|
using FGUI.ZM_Lobby_03;
|
|
|
|
|
|
namespace TowerClimberChronicles
|
|
{
|
|
public class HallUI : BaseUI
|
|
{
|
|
private HallUICtrl ctrl;
|
|
private HallModel model;
|
|
public FGUI.ZM_Lobby_03.com_hall ui;
|
|
|
|
public static bool isClosed = false;
|
|
|
|
private long userUid;
|
|
public int active_cd = 10;
|
|
private Tweener tweener;
|
|
|
|
private SkeletonAnimation anim_ad;
|
|
private SkeletonAnimation anim_banma = null;
|
|
|
|
public HallUI(HallUICtrl ctrl) : base(ctrl)
|
|
{
|
|
uiName = UIConst.HallUI;
|
|
this.ctrl = ctrl;
|
|
}
|
|
private string jsonstr;
|
|
List<int[]> levelShowList = new List<int[]>()
|
|
{
|
|
new int [1]{1},
|
|
new int [2]{2,3},
|
|
new int [1]{4},
|
|
};
|
|
|
|
private List<GLoader> loader_list = new List<GLoader>();
|
|
|
|
protected override void SetUIInfo(UIInfo uiInfo)
|
|
{
|
|
uiInfo.packageName = "ZM_Lobby_03";
|
|
uiInfo.assetName = "com_hall";
|
|
uiInfo.layerType = UILayerType.Normal;
|
|
uiInfo.isNeedOpenAnim = false;
|
|
uiInfo.isNeedCloseAnim = false;
|
|
uiInfo.isNeedUIMask = false;
|
|
}
|
|
|
|
#region 生命周期
|
|
|
|
protected override void OnInit()
|
|
{
|
|
model = moduleManager.GetModel(ModelConst.HallModel) as HallModel;
|
|
InitData();
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
|
|
HallManager.Instance.UpdateSecondEvent -= UpBtnCoin;
|
|
isClosed = true;
|
|
//关闭时保存cd数据
|
|
PlayerPrefs.SetInt($"active_cd_num_{userUid}", active_cd);
|
|
// HallManager.Instance.countTimes = (int)Time.time;
|
|
|
|
CommonHelper.FadeOut(ui);
|
|
tweener?.Kill();
|
|
closeCallback?.Invoke();
|
|
|
|
foreach (var t in loader_list)
|
|
{
|
|
if (t != null && !t.isDisposed && t.texture != null)
|
|
{
|
|
t.texture.Dispose();
|
|
t.texture = null;
|
|
}
|
|
}
|
|
loader_list.Clear();
|
|
}
|
|
|
|
protected override void OnBind()
|
|
{
|
|
ui = baseUI as FGUI.ZM_Lobby_03.com_hall;
|
|
}
|
|
|
|
protected override void OnOpenBefore(object args)
|
|
{
|
|
//测试代码
|
|
// ui.top_bg.visible = false;
|
|
// ui.bg.visible = false;
|
|
Debug.Log("Cache path: " + Application.temporaryCachePath);
|
|
|
|
if (Screen.safeArea.y != 0)
|
|
{
|
|
ui.btn_gold.y += 68;
|
|
}
|
|
// ui.com_panel.scrollPane.ScrollRight(12,false);
|
|
// if(GameHelper.IsGiftSwitch())
|
|
// {
|
|
// ui.com_panel.scrollPane.touchEffect = false;
|
|
// }
|
|
|
|
|
|
CreateGoldtimeList();
|
|
|
|
var isNew = DataMgr.NoviceGuide.Value;
|
|
|
|
if (!GameHelper.IsGiftSwitch() && !isNew)
|
|
{
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.GuideViewUI_Open);
|
|
}
|
|
GameHelper.IsShowFirstReward();
|
|
|
|
isClosed = false;
|
|
|
|
var loginModel = GameHelper.GetLoginModel();
|
|
userUid = loginModel.Uid;
|
|
|
|
|
|
InitView();
|
|
UpBtnCoin();
|
|
|
|
HallManager.Instance.UpdateSecondEvent += UpBtnCoin;
|
|
ui.level_list.SetVirtual();
|
|
ui.level_list.itemRenderer = RendererList;
|
|
ui.level_list.numItems = levelShowList.Count;
|
|
// int random_ = Random.Range(0, 100);
|
|
// if (GameHelper.IsGiftSwitch() && random_ < GameHelper.GetCommonModel().HomeGuideRate)
|
|
// {
|
|
// List<int> unlocklist = new List<int>();
|
|
// if ((GameHelper.GetCommonModel().Live == 1) && (GameHelper.GetLevel() >= GameHelper.GetCommonModel().LivePreview) && (GameHelper.GetLevel() < GameHelper.GetCommonModel().UnlockLive[1]))
|
|
// {
|
|
// if (DataMgr.IsUnlockLive.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockLive.As<int>()))//未解锁。
|
|
// {
|
|
// unlocklist.Add(0);
|
|
// }
|
|
// }
|
|
// if ((GameHelper.GetCommonModel().Secret == 1) && (GameHelper.GetLevel() >= GameHelper.GetCommonModel().SecretPreview) && (GameHelper.GetLevel() < GameHelper.GetCommonModel().UnlockSecret[1]))
|
|
// {
|
|
// if (DataMgr.IsUnlockSecret.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockSecret.As<int>()))//未解锁。
|
|
// {
|
|
// unlocklist.Add(1);
|
|
// }
|
|
// }
|
|
// if (unlocklist.Count > 0)
|
|
// {
|
|
// int random_index = Random.Range(0, unlocklist.Count);
|
|
// if (unlocklist[random_index] == 0)
|
|
// {
|
|
// uiCtrlDispatcher.Dispatch(UICtrlMsg.LiveUnlockUI_Open);
|
|
// }
|
|
// else if (unlocklist[random_index] == 1)
|
|
// {
|
|
// uiCtrlDispatcher.Dispatch(UICtrlMsg.ScAlbumLockUI_Open);
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
}
|
|
void RendererList(int index, GObject item_)
|
|
{
|
|
item_level item = (item_level)item_;
|
|
if (levelShowList[index].Length == 1)
|
|
{
|
|
item.type.selectedIndex = 0;
|
|
item.btn_big.text_level.text = "LEVEL " + levelShowList[index][0];
|
|
item.btn_big.loader_0.url = $"ui://ZM_Lobby_03/{levelShowList[index][0]}";
|
|
item.btn_big.SetClick(() =>
|
|
{
|
|
uiCtrlDispatcher.Dispatch(UICtrlMsg.GamePlayUI_Open);
|
|
GameHelper.now_level = levelShowList[index][0];
|
|
CtrlCloseUI();
|
|
GameHelper.LoadSceneAsync("scene_" + levelShowList[index][0]);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.TabUI_Close);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.MainUI_Close);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
item.type.selectedIndex = 1;
|
|
item.btn_small0.text_level_0.text = "LEVEL " + levelShowList[index][0];
|
|
item.btn_small0.loader_0.url = $"ui://ZM_Lobby_03/{levelShowList[index][0]}";
|
|
item.btn_small0.SetClick(() =>
|
|
{
|
|
uiCtrlDispatcher.Dispatch(UICtrlMsg.GamePlayUI_Open);
|
|
GameHelper.now_level = levelShowList[index][0];
|
|
CtrlCloseUI();
|
|
GameHelper.LoadSceneAsync("scene_" + levelShowList[index][0]);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.TabUI_Close);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.MainUI_Close);
|
|
});
|
|
|
|
item.btn_small1.text_level_1.text = "LEVEL " + levelShowList[index][1];
|
|
item.btn_small1.loader_1.url = $"ui://ZM_Lobby_03/{levelShowList[index][1]}";
|
|
item.btn_small1.SetClick(() =>
|
|
{
|
|
uiCtrlDispatcher.Dispatch(UICtrlMsg.GamePlayUI_Open);
|
|
GameHelper.now_level = levelShowList[index][1];
|
|
CtrlCloseUI();
|
|
GameHelper.LoadSceneAsync("scene_" + levelShowList[index][1]);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.TabUI_Close);
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.MainUI_Close);
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
private void getJsonData()
|
|
{
|
|
var json = DataMgr.LevelData.Value;
|
|
if (!string.IsNullOrEmpty(json))
|
|
{
|
|
jsonstr = json;
|
|
}
|
|
}
|
|
protected override void OnOpen(object args)
|
|
{
|
|
// CommonHelper.FadeIn(ui);
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
}
|
|
|
|
protected override void OnDisplay(object args)
|
|
{
|
|
}
|
|
|
|
public override void OnSwitchLanguage()
|
|
{
|
|
base.OnSwitchLanguage();
|
|
ui.btn_play.text_lv.text = Language.GetContent("Level") + " " + GameHelper.GetLevel();
|
|
// InitView();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 消息
|
|
|
|
protected override void AddListener()
|
|
{
|
|
HallManager.Instance.AddChangeGiftSwitch(InitView);
|
|
|
|
GameDispatcher.Instance.AddListener(GameMsg.updateAvatar, UpdataAvatar);
|
|
PreferencesDispatcher<string>.Instance.AddListener(DataMsg.playerName, OnChangeName);
|
|
GameDispatcher.Instance.AddListener(GameMsg.Gold_refresh, Chang101);
|
|
GameDispatcher.Instance.AddListener(GameMsg.Update101, Chang101);
|
|
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, UpdataAvatar);//VIP订阅后更新头像的vip图标
|
|
}
|
|
|
|
protected override void RemoveListener()
|
|
{
|
|
HallManager.Instance.RemoveChangeGiftSwitch(InitView);
|
|
GameDispatcher.Instance.RemoveListener(GameMsg.updateAvatar, UpdataAvatar);
|
|
PreferencesDispatcher<string>.Instance.RemoveListener(DataMsg.playerName, OnChangeName);
|
|
GameDispatcher.Instance.RemoveListener(GameMsg.Gold_refresh, Chang101);
|
|
GameDispatcher.Instance.RemoveListener(GameMsg.Update101, Chang101);
|
|
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, UpdataAvatar);//VIP订阅后更新头像的vip图标
|
|
}
|
|
#endregion
|
|
private List<Paidcoins> Paidcoins_list = ConfigSystem.GetConfig<Paidcoins>();
|
|
|
|
private int time_count = 11;
|
|
|
|
void CreateGoldtimeList()
|
|
{
|
|
// 获取保存对象
|
|
var saveObject = SaveData.GetSaveObject();
|
|
|
|
// 检查_goldtime是否为null或者长度与Paidcoins_list.Count不相等
|
|
if (saveObject._goldtime == null || saveObject._goldtime.Length != Paidcoins_list.Count)
|
|
{
|
|
// 重置_goldtime,并创建一个新的数组,长度为Paidcoins_list.Count
|
|
saveObject._goldtime = new int[Paidcoins_list.Count];
|
|
}
|
|
}
|
|
|
|
|
|
private void UpBtnCoin()
|
|
{
|
|
com_gold btn_gold = ui.btn_gold as com_gold;
|
|
btn_gold.state.selectedIndex = 1;
|
|
for (int i = 0; i < Paidcoins_list.Count; i++)
|
|
{
|
|
if (!Paidcoins_list[i].is_paid)
|
|
{
|
|
int time = SaveData.GetSaveObject()._goldtime[i];
|
|
if (time + Paidcoins_list[i].receive_CD < GameHelper.GetNowTime())
|
|
{
|
|
btn_gold.state.selectedIndex = 2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void InitData()
|
|
{
|
|
model.showCoin = DataMgr.Coin.Value;
|
|
model.showDollar = DataMgr.Ticket.Value;
|
|
}
|
|
|
|
private Action closeCallback;
|
|
|
|
private void InitView()
|
|
{
|
|
|
|
Set101();
|
|
|
|
SetName(ui.text_name);
|
|
|
|
ui.btn_play.text_lv.text = Language.GetContent("Level") + " " + GameHelper.GetLevel();
|
|
ui.btn_play.SetClick(OnClickPlay);
|
|
ui.btn_setting.SetClick(OnClickSetting);
|
|
|
|
var btnCoin = ui.btn_gold as com_gold;
|
|
btnCoin.text_gold.text = $"{DataMgr.Coin.Value:N0}";
|
|
btnCoin.SetClick(OnClickShop);
|
|
|
|
ui.btn_head.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PersonViewUI_Open); });
|
|
UpdataAvatar();
|
|
|
|
ui.state.selectedIndex = GameHelper.IsGiftSwitch() ? 1 : 0;
|
|
ui.btn_puzzle.SetClick(OnClickPuzzle);
|
|
ui.btn_flower.SetClick(OnClickflower);
|
|
|
|
}
|
|
|
|
|
|
private void OnClickShop()
|
|
{
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open, true);
|
|
}
|
|
private void OnClickSetting()
|
|
{
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.MenuUI_Open, 1);
|
|
}
|
|
|
|
|
|
private void OnClickPlay()
|
|
{
|
|
|
|
|
|
if (GameHelper.GetLevel() < GameHelper.GetCommonModel().MultiModal)
|
|
{
|
|
GameHelper.gameType = 0;
|
|
GameDispatcher.Instance.Dispatch(GameMsg.OpenGame);
|
|
}
|
|
else
|
|
{
|
|
|
|
GameHelper.gameType = 0;
|
|
GameDispatcher.Instance.Dispatch(GameMsg.OpenGame);
|
|
|
|
}
|
|
}
|
|
private void OnClickPuzzle()
|
|
{
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
|
DOVirtual.DelayedCall(0.1f, () =>
|
|
{
|
|
GameDispatcher.Instance.Dispatch(GameMsg.OpenPuzzleGame);
|
|
});
|
|
}
|
|
|
|
private void OnClickflower()
|
|
{
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
|
DOVirtual.DelayedCall(0.1f, () =>
|
|
{
|
|
GameDispatcher.Instance.Dispatch(GameMsg.OpenFlowerGame);
|
|
});
|
|
}
|
|
public void OnUpdate101(object obj = null)
|
|
{
|
|
if (obj != null)
|
|
{
|
|
var changeValue = (decimal)obj;
|
|
model.showCoin += changeValue;
|
|
Set101(model.showCoin);
|
|
}
|
|
}
|
|
|
|
public void OnUpdate102(object obj = null)
|
|
{
|
|
if (obj != null)
|
|
{
|
|
var changeValue = (decimal)obj;
|
|
model.showDollar += changeValue;
|
|
}
|
|
}
|
|
private void UpdataAvatar(object obj = null)
|
|
{
|
|
var headId = DataMgr.PlayerAvatarId.Value;
|
|
}
|
|
|
|
public void Set101(decimal coin = -1)
|
|
{
|
|
if (coin < 0)
|
|
{
|
|
coin = DataMgr.Coin.Value;
|
|
}
|
|
|
|
var btnCoin = ui.btn_gold as com_gold;
|
|
btnCoin.text_gold.text = $"{coin:N0}";
|
|
}
|
|
public void Chang101(object a = null)
|
|
{
|
|
|
|
int coin = DataMgr.Coin.Value;
|
|
|
|
|
|
var btnCoin = ui.btn_gold as com_gold;
|
|
btnCoin.text_gold.text = $"{coin:N0}";
|
|
}
|
|
private void OnChangeName(ChangeValue<string> obj)
|
|
{
|
|
var name = obj.newValue;
|
|
GameHelper.SetName(ui.text_name, name);
|
|
}
|
|
|
|
private void SetName(GTextField gTextField)
|
|
{
|
|
var name = DataMgr.PlayerName.Value;
|
|
|
|
GameHelper.SetName(gTextField, name);
|
|
}
|
|
}
|
|
} |