using System.Collections; using System.Collections.Generic; using FairyGUI; using UI.ClothingFoster; using UI.CommonGame; using UnityEngine; namespace GFGGame { public class SuitView : BaseWindow { private UI_SuitUI _ui; private GameObject _scenePrefab; private GameObject _sceneObject; private GoWrapper _wrapper; private DressUpObjDataCache _dressUpObjDataCache; private bool _actionIsPic; private List _suitIds;//已解锁套装列表 private SortedList _propertyList; private int _suitId; private int _index; public override void Dispose() { base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_SuitUI.PACKAGE_NAME; _ui = UI_SuitUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); isfullScreen = true; this.clickBlankToClose = false; _scenePrefab = GFGAsset.Load(ResPathUtil.GetPrefabPath("SceneDressUp")); _dressUpObjDataCache = new DressUpObjDataCache(); _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_btnLeft.onClick.Add(() => { OnClickBtnDirection(-1); }); _ui.m_btnRight.onClick.Add(() => { OnClickBtnDirection(1); }); _ui.m_btnReward.target.onClick.Add(OnClickBtnReward); _ui.m_btnPropertyShow.onClick.Add(OnClickBtnPropertyShow); _ui.m_listFoster.itemRenderer = ListFosterItemRender; _ui.m_listFoster.onClickItem.Add(OnClickListFosterItem); _ui.m_listProperty.itemRenderer = ListPropertyItemRender; } protected override void OnShown() { base.OnShown(); object[] datas = this.viewData as object[]; _suitId = (int)datas[0]; List suitIds = datas[1] as List; _suitIds = new List(); foreach (int suitId in suitIds) { if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId)) { _suitIds.Add(suitId); } } UpdateView(); } protected override void OnHide() { base.OnHide(); } private void OnClickBtnBack() { ViewManager.GoBackFrom(typeof(SuitView).FullName); } private void UpdateView() { UpdateArrows(); UpdateSuitView(); _ui.m_listFoster.numItems = SuitFosterCfgArray.Instance.GetCfgs(_suitId).Length; _propertyList = SuitFosterDataManager.Instance.GetPropertyData(_suitId, _index); _ui.m_listProperty.numItems = _propertyList.Count; } 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 OnClickBtnDirection(int direction) { int index = _suitIds.IndexOf(_suitId); int targetIndex = index + direction; if (targetIndex >= 0 && direction == -1 || targetIndex < _suitIds.Count && direction == 1) { _suitId = _suitIds[targetIndex]; UpdateView(); } } private void UpdateSuitView(bool isPic = true) { _actionIsPic = isPic; SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId); _ui.m_txtName.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; } } private void ListFosterItemRender(int index, GObject obj) { UI_ListFosterItem item = UI_ListFosterItem.Proxy(obj); item.target.data = index; item.m_finish.selectedIndex = SuitFosterDataManager.Instance.GetFosterState(_suitId, index); if (SuitFosterDataManager.Instance.GetSuitFosterData(_suitId).maintainStep == index) { _index = index; } } private void ListPropertyItemRender(int index, GObject obj) { UI_ListPropertyItem item = UI_ListPropertyItem.Proxy(obj); int score = index + 1; item.m_txtProperty.text = _propertyList[score].ToString(); item.m_loaIcon.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (score)); } private void OnClickListFosterItem(EventContext context) { int index = (int)(context.data as GObject).data; if (index == _index) { ViewManager.Show(new object[] { _suitId, index }); } } private void OnClickBtnReward() { ViewManager.Show(_suitId); } private void OnClickBtnPropertyShow() { ViewManager.Show(new object[] { _suitId, _index }); } } }