123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System;
- using FairyGUI;
- using FL.Data;
- using XGame;
- using XGame.Database;
- using XGame.Framework.Time;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MainHomePanelCtrl : UIController<MainHomePanelVM>
- {
- private ITimer _mapRewardTimer;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- Context.AddListener(EventDefine.PveFightEnd, RefreshMapReward);
- Context.AddListener(EventDefine.PveReceivedRewards, RefreshMapReward);
- InitView();
- RefreshPlayerInfo();
- RefreshMapReward();
- RefreshHdList();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- Context.RemoveListener(EventDefine.PveFightEnd, RefreshMapReward);
- Context.RemoveListener(EventDefine.PveReceivedRewards, RefreshMapReward);
- _mapRewardTimer?.Cancel();
- _mapRewardTimer = null;
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.SysMenuBtn.onClick.Add(OnClickSysMenuBtn);
- VM.FriendBtn.onClick.Add(OnClickFriendBtn);
- VM.MailBtn.onClick.Add(OnClickMailBtn);
- VM.NoticeBtn.onClick.Add(OnClickNoticeBtn);
- VM.SettingBtn.onClick.Add(OnClickSettingBtn);
- VM.ExchangeBtn.onClick.Add(OnClickExchangeBtn);
- VM.BagBtn.onClick.Add(OnClickBagBtn);
- VM.MapRewardBtn.onClick.Add(OnClickMapRewardBtn);
- VM.GoldNested.VM.PanelEvent.Add(OnClickGoldNested);
- VM.DiamondNested.VM.PanelEvent.Add(OnClickDiamondNested);
- }
- private void RemoveUIListenres()
- {
- VM.SysMenuBtn.onClick.Remove(OnClickSysMenuBtn);
- VM.FriendBtn.onClick.Remove(OnClickFriendBtn);
- VM.MailBtn.onClick.Remove(OnClickMailBtn);
- VM.NoticeBtn.onClick.Remove(OnClickNoticeBtn);
- VM.SettingBtn.onClick.Remove(OnClickSettingBtn);
- VM.ExchangeBtn.onClick.Remove(OnClickExchangeBtn);
- VM.BagBtn.onClick.Remove(OnClickBagBtn);
- VM.MapRewardBtn.onClick.Remove(OnClickMapRewardBtn);
- VM.GoldNested.VM.PanelEvent.Remove(OnClickGoldNested);
- VM.DiamondNested.VM.PanelEvent.Remove(OnClickDiamondNested);
- }
- private void OnClickSysMenuBtn(EventContext context)
- {
- VM.SysMenuActive = !VM.SysMenuActive;
- }
- private void OnClickFriendBtn(EventContext context)
- {
- Context.ShowTips("OnClickFriendBtn");
- VM.SysMenuActive = false;
- }
- private void OnClickMailBtn(EventContext context)
- {
- //Context.ShowTips("OnClickMailBtn");
- VM.SysMenuActive = false;
- MailService.Instance.RequestMailInto();
- }
- private void OnClickNoticeBtn(EventContext context)
- {
- Context.ShowTips("OnClickNoticeBtn");
- VM.SysMenuActive = false;
- // 临时测试GM消息按钮
- Context.UI.OpenAsync(UIKeys.GmToolSendMsgPanel);
- }
- private void OnClickSettingBtn(EventContext context)
- {
- Context.ShowTips("OnClickSettingBtn");
- VM.SysMenuActive = false;
- }
- private void OnClickExchangeBtn(EventContext context)
- {
- Context.ShowTips("OnClickExchangeBtn");
- VM.SysMenuActive = false;
- // 临时测试GM消息入口按钮
- Context.UI.OpenAsync(UIKeys.GmToolSendMsgPanel);
- }
- private void OnClickBagBtn(EventContext context)
- {
- Context.UI.OpenAsync(UIKeys.BagBackpackPanel);
- VM.SysMenuActive = false;
- }
- private void OnClickMapRewardBtn(EventContext context)
- {
- //Context.ShowTips("OnClickMapRewardBtn");
- if (FunctionService.Instance.IsUnlock((int)EFunctionUnlockType.AutoRwd))
- {
- Context.UI.OpenAsync(UIKeys.BattleRewardPreviewPanel);
- }
- else
- {
- Context.ShowTips(EStringDefine.FunctionIsLock);
- }
- }
- private void OnClickGoldNested(EventContext context)
- { // 金币商店
- ShopService.Instance.RequestShopInto();
- }
- private void OnClickDiamondNested(EventContext context)
- { // 钻石商店
- ShopService.Instance.RequestShopInto();
- }
- #endregion
- private void RefreshMapReward(int eventId, object args)
- {
- RefreshMapReward();
- }
- private bool _init = false;
- private void InitView()
- {
- if (_init)
- return;
- _init = true;
- VM.RightHdList.ListType = EGListType.Virtual;
- VM.LeftMenuBtnsList.ListType = EGListType.Virtual;
- }
- void RefreshPlayerInfo()
- {
- //TODO
- var player = PlayerData.Instance;
- VM.PlayerHead.icon = "itemicon_99"; // player.HeadIcon;
- VM.PlayerNameTxt.text = player.Name;
- VM.PlayerLvTxt.text = player.Level.ToString();
- VM.PlayerPowerIcon.icon = AddressableDefine.itemicon_power;
- VM.PlayerPowerTxt.text = player.Power.ToNumberString();
- VM.GoldNested.Ctrl.ShowUI(ItemData.GoldId, ItemData.Instance.Gold);
- VM.DiamondNested.Ctrl.ShowUI(ItemData.DiamondId, ItemData.Instance.Diamond);
- }
- void RefreshMapReward()
- {
- _mapRewardTimer?.Cancel();
- if (!FunctionService.Instance.IsUnlock((int)EFunctionUnlockType.AutoRwd))
- {
- VM.SetMapRewardState(3);
- VM.SetMapRewardUnlockTxt(FunctionService.Instance.GetUnlockText((int)EFunctionUnlockType.AutoRwd, 1));
- //VM.SetMapRewardUnlockTxt()
- return;
- }
- var pveData = PveData.Instance;
- long remainTime = KeyValue.PlaceRewardsLimit * 1000;
- var lastTime = Context.Time.GetNowTime();
- var state = 0;
- if (pveData.lastTime == 0)
- { // 没有结算过奖励
- }
- else
- {
- remainTime -= (lastTime - pveData.lastTime + pveData.overTime);
- if (remainTime <= 0)
- {
- state = 2;
- remainTime = KeyValue.PlaceRewardsLimit * 1000;
- }
- else
- {
- state = 1;
- }
- }
- VM.MapRewardBtn.title = remainTime.ToTimeString(@"hh\:mm\:ss");
- if (state < 2)
- {
- _mapRewardTimer = Context.Time.AddLooperTimer(
- 500,
- _ =>
- {
- var nowTime = Context.Time.GetNowTime();
- remainTime -= (nowTime - lastTime);
- if (remainTime <= 0)
- {
- remainTime = 0;
- _mapRewardTimer.Cancel();
- _mapRewardTimer = null;
- VM.SetMapRewardState(2);
- return;
- }
- VM.MapRewardBtn.title = remainTime.ToTimeString(@"hh\:mm\:ss");
- lastTime = nowTime;
- }
- );
- }
- VM.SetMapRewardState(state);
- }
- private void RefreshHdList()
- {
- ShowLeftMenusBtns();
- var list = hdActivityTableRepo.GetListByPos(1);
- var count = list.Count;
- if (count > 7)
- {
- count = 7;
- }
- VM.RightHdList.height =
- count * VM.RightHdList.defaultItemSize.y
- + (count - 1 * VM.RightHdList.lineGap)
- + VM.RightHdList.margin.top;
- VM.RightHdList.BindDatas(list);
- }
- private void ShowLeftMenusBtns()
- {
- var list = hdActivityTableRepo.GetListByPos(0);
- var count = list.Count;
- if (count == 0)
- {
- VM.LeftMenuBtns.visible = false;
- return;
- }
- else if (count > 7)
- {
- count = 7;
- }
- VM.LeftMenuBtns.visible = true;
- VM.LeftMenuBtnsList.height =
- count * VM.LeftMenuBtnsList.defaultItemSize.y
- + (count - 1 * VM.LeftMenuBtnsList.lineGap)
- + VM.LeftMenuBtnsList.margin.top;
- VM.LeftMenuBtnsList.BindDatas(list);
- }
- }
- }
|