ClothingShopView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using UI.ClothingShop;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class ClothingShopView : BaseWindow
  10. {
  11. private const int SHOES_Y = 105;
  12. private const int HEAD_Y = 609;
  13. private const int BODY_Y = 412;
  14. private const float SCALE_MAX = 1.5f;
  15. private const float DURATION = 0.6f;
  16. private readonly int[] HEAD_Y_ARR = new int[] { ConstDressUpItemType.FA_XING, ConstDressUpItemType.NEI_DA, ConstDressUpItemType.SHANG_YI, ConstDressUpItemType.TOU_SHI, ConstDressUpItemType.ER_SHI, ConstDressUpItemType.JING_SHI };
  17. private readonly int[] SHOES_Y_ARR = new int[] { ConstDressUpItemType.XIA_ZHUANG, ConstDressUpItemType.WA_ZI, ConstDressUpItemType.XIE_ZI, ConstDressUpItemType.SHOU_SHI, ConstDressUpItemType.YAO_SHI };
  18. private UI_ClothingShopUI _ui;
  19. private GameObject _scenePrefab;
  20. private GameObject _sceneObject;
  21. private GoWrapper _wrapper;
  22. private DressUpObjDataCache _dressUpObjDataCache;
  23. private ValueBarController _valueBarController;
  24. private List<ClothingShopCfg> _dataList;
  25. private GLoader _imgSelected;
  26. private ClothingShopCfg _cfgSelected;
  27. private const int MAX_COUNT = 99;
  28. private const int INIT_COUNT = 1;
  29. private int _scoreType;
  30. private int _storeId = 1;
  31. private GObject _selectedListItem;
  32. private int _selectedItemId;//打开界面时选中的物品id
  33. private int _selectedType = 0;//打开界面时选中的物品类型
  34. private int _selectedItemClothingId;
  35. public override void Dispose()
  36. {
  37. _valueBarController.Dispose();
  38. _valueBarController = null;
  39. if (_scenePrefab != null)
  40. {
  41. GameObject.Destroy(_scenePrefab);
  42. _scenePrefab = null;
  43. }
  44. if (_imgSelected != null)
  45. {
  46. _imgSelected.RemoveFromParent();
  47. _imgSelected.Dispose();
  48. }
  49. if (_dressUpObjDataCache != null)
  50. {
  51. _dressUpObjDataCache.Dispose();
  52. _dressUpObjDataCache = null;
  53. }
  54. _cfgSelected = null;
  55. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  56. base.Dispose();
  57. }
  58. protected override void OnInit()
  59. {
  60. base.OnInit();
  61. packageName = UI_ClothingShopUI.PACKAGE_NAME;
  62. _ui = UI_ClothingShopUI.Create();
  63. this.viewCom = _ui.target;
  64. isfullScreen = true;
  65. _valueBarController = new ValueBarController(_ui.m_valueBar);
  66. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  67. _dressUpObjDataCache = new DressUpObjDataCache();
  68. _imgSelected = new GLoader();
  69. _imgSelected.x = -5;
  70. _imgSelected.y = -3;
  71. _imgSelected.url = "ui://ClothingShop/fzd_fzxzhong";
  72. _ui.m_listShop.itemRenderer = ListShopItemRender;
  73. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  74. _ui.m_compItemInfo.m_btnBuy.onClick.Add(OnclickBtnBuy);
  75. _ui.m_listType.onClickItem.Add(OnClickListTypeItem);
  76. _ui.m_listShop.onClickItem.Add(OnClickListShopItem);
  77. _ui.m_compItemInfo.m_listTag.itemRenderer = RenderListTagItem;
  78. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  79. }
  80. protected override void OnShown()
  81. {
  82. base.OnShown();
  83. _storeId = ConstStoreId.CLOTHING_STORE_ID;
  84. _scoreType = 0;
  85. _selectedItemId = -1;
  86. _selectedType = 0;
  87. if (this.viewData != null)
  88. {
  89. //this.viewData[0]=storeId(商店Id)
  90. //this.viewData[1]=_scoreType(服装属性:风花雪月)
  91. //this.viewData[2]=_selectedItemId
  92. object[] objs = this.viewData as object[];
  93. if (objs.Length > 0 && objs[0] != null)
  94. {
  95. _storeId = (int)objs[0];//从抽奖跳转到商店会区分商店Id
  96. }
  97. if (objs.Length > 1 && objs[1] != null)
  98. {
  99. _scoreType = (int)objs[1];//从战斗跳转到商店需要服装突出属性用来服装排序
  100. }
  101. if (objs.Length > 2 && objs[2] != null)
  102. {
  103. _selectedItemId = (int)objs[2];//从物品来源面板跳转到商店,需要物品id方便打开界面时做选中处理
  104. ClothingShopCfg[] dataArray = ClothingShopCfgArray.Instance.dataArray;
  105. for (int i = 0; i < dataArray.Length; i++)
  106. {
  107. if (dataArray[i].itemID == _selectedItemId)
  108. {
  109. _selectedType = dataArray[i].typeIndex;
  110. _selectedItemClothingId = dataArray[i].id;
  111. break;
  112. }
  113. }
  114. }
  115. }
  116. _ui.m_c1.selectedIndex = _storeId;
  117. _ui.m_compItemInfo.m_c1.selectedIndex = _storeId;
  118. _ui.m_listType.selectedIndex = _selectedType;
  119. _ui.m_listType.ScrollToView(_selectedType);
  120. UpdateList(false);
  121. _ui.m_listShop.height = _ui.target.height - _ui.m_listShop.y;
  122. _ui.m_bgList.height = _ui.target.height - _ui.m_bgList.y;
  123. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  124. UpdateCJGoodsCount();
  125. _valueBarController.OnShown();
  126. _valueBarController.Controller(1);
  127. if (_storeId == ConstStoreId.CLOTHING_STORE_ID)
  128. {
  129. _valueBarController.Controller(1);
  130. }
  131. else if (_storeId == ConstStoreId.LUCKY_BOX_STORE_ID)
  132. {
  133. _valueBarController.Controller(2);
  134. }
  135. else if (_storeId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  136. {
  137. _valueBarController.Controller(3);
  138. }
  139. GuideController.TryGuideClothingShopViewBtnBug(_ui.m_compItemInfo.m_btnBuy);
  140. }
  141. protected override void OnHide()
  142. {
  143. base.OnHide();
  144. _valueBarController.OnHide();
  145. if (_sceneObject != null)
  146. {
  147. GameObject.Destroy(_sceneObject);
  148. _sceneObject = null;
  149. }
  150. if (_wrapper != null)
  151. {
  152. _wrapper.wrapTarget = null;
  153. }
  154. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  155. }
  156. private void OnClickBtnBack()
  157. {
  158. GuideController.HideGuide();
  159. ViewManager.GoBackFrom(ViewName.CLOTHING_SHOP_VIEW);
  160. this.Hide();
  161. GuideController.TryGuideDressUpFightViewMenuType1();
  162. }
  163. private void OnclickBtnBuy()
  164. {
  165. BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, INIT_COUNT, null, true, false, MAX_COUNT);
  166. }
  167. private void UpdateItemChange()
  168. {
  169. GuideController.TryGuideClothingShopViewBtnBack(_ui.m_btnBack);
  170. UpdateCJGoodsCount();
  171. }
  172. private void UpdateCJGoodsCount()
  173. {
  174. int luckyBoxId1 = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  175. LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1);
  176. _ui.m_txtCount0.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.drop);
  177. _ui.m_loaIcon0.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.drop).res);
  178. int luckyBoxId2 = LuckyBoxDataManager.Instance.luckyBoxIds[1];
  179. LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2);
  180. _ui.m_txtCount1.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.drop);
  181. _ui.m_loaIcon1.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.drop).res);
  182. }
  183. private void UpdateRole(bool tween)
  184. {
  185. if (_sceneObject != null)
  186. {
  187. GameObject.Destroy(_sceneObject);
  188. _sceneObject = null;
  189. }
  190. _sceneObject = GameObject.Instantiate(_scenePrefab);
  191. int scale = 70;
  192. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  193. _dressUpObjDataCache.setSceneObj(_sceneObject);
  194. _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
  195. _dressUpObjDataCache.AddOrRemove(_cfgSelected.itemID, true);
  196. if (_wrapper == null)
  197. {
  198. _wrapper = new GoWrapper(_sceneObject);
  199. _ui.m_compHolder.m_compMover.m_holder.SetNativeObject(_wrapper);
  200. }
  201. else
  202. {
  203. _wrapper.wrapTarget = _sceneObject;
  204. }
  205. int type = ItemUtil.GetItemSubType(_cfgSelected.itemID);
  206. float duration = DURATION;
  207. if (!tween)
  208. {
  209. duration = 0;
  210. }
  211. if (Array.IndexOf(HEAD_Y_ARR, type) >= 0)
  212. {
  213. _ui.m_compHolder.m_compMover.target.TweenMoveY(HEAD_Y, duration);
  214. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SCALE_MAX, SCALE_MAX), duration);
  215. }
  216. else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)
  217. {
  218. _ui.m_compHolder.m_compMover.target.TweenMoveY(SHOES_Y, duration);
  219. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SCALE_MAX, SCALE_MAX), duration);
  220. }
  221. else
  222. {
  223. _ui.m_compHolder.m_compMover.target.TweenMoveY(BODY_Y, duration);
  224. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(1, 1), duration);
  225. }
  226. }
  227. private void UpdateList(bool tween)
  228. {
  229. _ui.m_listShop.RemoveChildrenToPool();
  230. int typeIndex = _ui.m_listType.selectedIndex;
  231. _dataList = ClothingShopCfgManager.Instance.GetList(_storeId, typeIndex, _scoreType);
  232. _ui.m_listShop.numItems = _dataList.Count;
  233. if (_ui.m_listShop.numItems > 0)
  234. {
  235. ClothingShopCfg clothingShopCfg = ClothingShopCfgArray.Instance.GetCfg(_selectedItemClothingId);
  236. int itemIndex = 0;
  237. if (_selectedItemId > 0 && clothingShopCfg != null)
  238. {
  239. itemIndex = _dataList.IndexOf(clothingShopCfg);
  240. _ui.m_listShop.ScrollToView(itemIndex < 0 ? 0 : itemIndex);
  241. _selectedItemId = 0;
  242. }
  243. UpdateSelectedItemInfo(_ui.m_listShop.GetChildAt(itemIndex) as GComponent, tween);
  244. }
  245. }
  246. private void OnClickListTypeItem(EventContext context)
  247. {
  248. UpdateList(true);
  249. }
  250. private void OnClickListShopItem(EventContext context)
  251. {
  252. UpdateSelectedItemInfo(context.data as GComponent, true);
  253. }
  254. private void ListShopItemRender(int index, GObject item)
  255. {
  256. UI_ShopListItemRender listItem = UI_ShopListItemRender.Proxy(item);
  257. ClothingShopCfg cfg = _dataList[index];
  258. listItem.target.data = cfg;
  259. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemID);
  260. listItem.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  261. string itemName = itemCfg.name;
  262. listItem.m_txtName.text = itemName;
  263. RarityIconController.UpdateRarityIcon(listItem.m_rarity, cfg.itemID, false);
  264. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(cfg.costID);
  265. listItem.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
  266. listItem.m_txtPrice.text = "" + cfg.costNum;
  267. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(cfg.itemID) > 0;
  268. }
  269. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  270. {
  271. _selectedListItem = listItem;
  272. listItem.AddChild(_imgSelected);
  273. ClothingShopCfg cfg = listItem.data as ClothingShopCfg;
  274. _cfgSelected = cfg;
  275. UpdateRole(tween);
  276. UpdateSelectedItemInfo();
  277. }
  278. private void UpdateSelectedItemInfo()
  279. {
  280. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
  281. string itemName = itemCfg.name;
  282. _ui.m_compItemInfo.m_txtName.text = itemName;
  283. _ui.m_compItemInfo.m_txtDesc.text = itemCfg.desc;
  284. RarityIconController.UpdateRarityIcon(_ui.m_compItemInfo.m_rarity, _cfgSelected.itemID, false);
  285. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.costID);
  286. _ui.m_compItemInfo.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
  287. _ui.m_compItemInfo.m_txtPrice.text = "" + _cfgSelected.costNum;
  288. _ui.m_compItemInfo.m_txtGong.text = "" + itemCfg.score1;
  289. _ui.m_compItemInfo.m_txtShang.text = "" + itemCfg.score2;
  290. _ui.m_compItemInfo.m_txtJue.text = "" + itemCfg.score3;
  291. _ui.m_compItemInfo.m_txtZhi.text = "" + itemCfg.score4;
  292. _ui.m_compItemInfo.m_txtOwned.SetVar("v1", "" + ItemDataManager.GetItemNum(_cfgSelected.itemID)).FlushVars();
  293. UI_ShopListItemRender listItem = UI_ShopListItemRender.Proxy(_selectedListItem);
  294. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_cfgSelected.itemID) > 0;
  295. _ui.m_compItemInfo.m_listTag.numItems = itemCfg.tagsArr.Length;
  296. }
  297. private void RenderListTagItem(int index, GObject obj)
  298. {
  299. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  300. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
  301. string[] tag = itemCfg.tagsArr[index].Split('_');
  302. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tag[0]);
  303. item.m_txtTag.text = tag[1];
  304. }
  305. }
  306. }