using UI.FieldGuide; using FairyGUI; using UnityEngine; using System.Collections.Generic; namespace GFGGame { public class SuitShowView : BaseWindow { private UI_SuitShowUI _ui; private int _suitTypeId; private int _suitId; private GameObject _scenePrefab; private GameObject _sceneObject; private GoWrapper _wrapper; private DressUpObjDataCache _dressUpObjDataCache; private bool _actionIsPic; private List _suitIds; public override void Dispose() { if (_scenePrefab != null) { GameObject.Destroy(_scenePrefab); _scenePrefab = null; } if (_dressUpObjDataCache != null) { _dressUpObjDataCache.Dispose(); _dressUpObjDataCache = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); _ui = UI_SuitShowUI.Create(); this.viewCom = _ui.target; isfullScreen = true; this.clickBlankToClose = false; _scenePrefab = GFGAsset.Load(ResPathUtil.GetPrefabPath("SceneDressUp")); _dressUpObjDataCache = new DressUpObjDataCache(); _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_imgBonusBox.target.onClick.Add(OnClickImgBonusBox); _ui.m_btnChangeAction.onClick.Add(OnClickBtnChangeAction); _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 suitIds = datas[2] as List; _suitIds = new List(); foreach (int suitId in suitIds) { if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId)) { _suitIds.Add(suitId); } } SuitGuideMenuCfg cfg = SuitGuideMenuCfgArray.Instance.GetCfg(_suitTypeId); _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(); if (_sceneObject != null) { GameObject.Destroy(_sceneObject); _sceneObject = null; } } 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 OnClickBtnChangeAction() { if (!_ui.m_btnChangeAction.grayed) { _actionIsPic = !_actionIsPic; UpdateSuitView(_actionIsPic); } } private void UpdateSuitView(bool isPic = true) { _actionIsPic = isPic; SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId); _ui.m_txtSuitName.text = suitCfg.name; if (_sceneObject != null) { GameObject.Destroy(_sceneObject); _sceneObject = null; } _sceneObject = GameObject.Instantiate(_scenePrefab); int scale = 100; _sceneObject.transform.localScale = new Vector3(scale, scale, scale); _dressUpObjDataCache.setSceneObj(_sceneObject); _dressUpObjDataCache.PutOnDefaultSuitSaved(false); _dressUpObjDataCache.PutOnSuitCfg(_suitId, isPic, false, new int[] { ConstDressUpItemType.BEI_JING }); if (_wrapper == null) { _wrapper = new GoWrapper(_sceneObject); _ui.m_holder.SetNativeObject(_wrapper); } else { _wrapper.wrapTarget = _sceneObject; } _ui.m_btnChangeAction.grayed = !_dressUpObjDataCache.HasSuitPicRes; UpdateSuitBoxStatus(); } 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() { int index = _suitIds.IndexOf(_suitId); int targetIndex = index - 1; if (targetIndex >= 0) { _suitId = _suitIds[targetIndex]; UpdateArrows(); UpdateSuitView(); } UpdateSuitBoxStatus(); } private void OnClickBtnRight() { 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; } } } } }