| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using UI.FieldGuide;
- using FairyGUI;
- using UnityEngine;
- using System.Collections.Generic;
- using cfg.GfgCfg;
- using ET;
- namespace GFGGame
- {
- public class SuitShowView : BaseWindow
- {
- private UI_SuitShowUI _ui;
- private int _suitTypeId;
- private int _suitId;
- private DressUpObjUI _dressUpObjUI;
- private bool _actionIsPic;
- private List<int> _suitIds;
- private bool touchClick = true;
- public override void Dispose()
- {
- Timers.inst.Remove(OnTimerUpDate);
- if (_dressUpObjUI != null)
- {
- _dressUpObjUI.Dispose();
- _dressUpObjUI = null;
- }
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_SuitShowUI.PACKAGE_NAME;
- _ui = UI_SuitShowUI.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- //isReturnView = true;
- this.clickBlankToClose = false;
- //_dressUpObjUI = new DressUpObjUI("SceneDressUp");
- _ui.m_btnBack.onClick.Add(OnClickBtnBack);
- _ui.m_imgBonusBox.target.onClick.Add(OnClickImgBonusBox);
- _ui.m_btnChangeAction.visible = false;
- _ui.m_btnLeft.onClick.Add(OnClickBtnLeft);
- _ui.m_btnRight.onClick.Add(OnClickBtnRight);
- }
- protected override void OnShown()
- {
- base.OnShown();
- object[] datas = this.viewData as object[];
- _suitTypeId = (int)datas[0];
- _suitId = (int)datas[1];
- List<int> suitIds = datas[2] as List<int>;
- _ui.m_imgBonusBox.target.visible = datas.Length >= 4 ? (bool)datas[3] : true;
- _suitIds = new List<int>();
- foreach (int suitId in suitIds)
- {
- if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId))
- {
- _suitIds.Add(suitId);
- }
- }
- SuitGuideMenuCfg cfg = CommonDataManager.Tables.TblSuitGuideMenuCfg.GetOrDefault(_suitTypeId);
- if (cfg == null)
- {
- SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_suitId);
- _ui.m_txtSuitName.text = suitCfg.Name;
- }
- else
- {
- _ui.m_txtTypeName.text = cfg.Name;
- }
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjtj_bjbj");
- UpdateArrows();
- UpdateSuitView();
- UpdateSuitBoxStatus();
- }
- protected override void AddEventListener()
- {
- base.AddEventListener();
- EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
- }
- private void OnClickBtnBack()
- {
- this.Hide();
- }
- private void OnClickImgBonusBox()
- {
- SuitUtil.ShowSuitGuideBonus(_suitId);
- }
- private void OnTimerUpDate(object param = null)
- {
- touchClick = true;
- _dressUpObjUI.UpdateWrapper(_ui.m_holder);
- }
- private async void UpdateSuitView(bool isPic = true)
- {
- _actionIsPic = isPic;
- SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_suitId);
- _ui.m_txtSuitName.text = suitCfg.Name;
- if (_dressUpObjUI != null)
- {
- _dressUpObjUI.Dispose();
- _dressUpObjUI = null;
- }
- _dressUpObjUI = new DressUpObjUI("SceneDressUp");
- // 使用异步方式重置场景对象
- _dressUpObjUI.ResetSceneObjAsync(100, false, true, null, false, (sceneObj) =>
- {
- if (sceneObj != null)
- {
- //_dressUpObjUI.dressUpObj.SetOnSuitPutOnCompleteCallback(() =>
- //{
- //_dressUpObjUI.UpdateWrapper(_ui.m_holder);
- //UpdateSuitBoxStatus();
- //});
- // 场景对象加载完成后穿上套装
- _dressUpObjUI.dressUpObj.PutOnSuitCfg(
- _suitId,
- isPic,
- new int[] { ConstDressUpItemType.BEI_JING },
- true,
- false,
- false,
- (needYooAsseetDown) =>
- {
- if(needYooAsseetDown)
- Timers.inst.Add(4f, 1, OnTimerUpDate);
- else
- Timers.inst.Add(0.3f, 1, OnTimerUpDate);
- }
- );
- UpdateSuitBoxStatus();
- }
- else
- {
- Debug.LogError("Failed to load scene object for suit view");
- }
- });
- }
- private void UpdateArrows()
- {
- int index = _suitIds.IndexOf(_suitId);
- int count = _suitIds.Count;
- _ui.m_btnRight.visible = (index + 1 < count);
- _ui.m_btnLeft.visible = (index - 1 >= 0);
- }
- private void OnClickBtnLeft()
- {
- if (!touchClick) return;
- touchClick = false;
- int index = _suitIds.IndexOf(_suitId);
- int targetIndex = index - 1;
- if (targetIndex >= 0)
- {
- _suitId = _suitIds[targetIndex];
- UpdateArrows();
- UpdateSuitView();
- }
- UpdateSuitBoxStatus();
- }
- private void OnClickBtnRight()
- {
- if (!touchClick) return;
- touchClick = false;
- int index = _suitIds.IndexOf(_suitId);
- int targetIndex = index + 1;
- if (targetIndex < _suitIds.Count)
- {
- _suitId = _suitIds[targetIndex];
- UpdateArrows();
- UpdateSuitView();
- }
- UpdateSuitBoxStatus();
- }
- private void UpdateSuitBoxStatus(EventContext eventContext = null)
- {
- if (eventContext == null || _suitId == (int)eventContext.data)
- {
- int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(_suitId);
- RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, false);
- RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, status == ConstBonusStatus.CAN_GET);
- if (status == ConstBonusStatus.CAN_GET)
- {
- _ui.m_imgBonusBox.m_c1.selectedIndex = 1;
- }
- else
- {
- _ui.m_imgBonusBox.m_c1.selectedIndex = 0;
- }
- }
- }
- }
- }
|