ClothingShopView.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 : BaseView
  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<ShopCfg> _dataList;
  25. private GComponent _comSelected;
  26. private ShopCfg _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 _selectedItemCount;
  35. private int _selectedItemClothingId;
  36. public override void Dispose()
  37. {
  38. _valueBarController.Dispose();
  39. _valueBarController = null;
  40. if (_sceneObject != null)
  41. {
  42. GameObject.Destroy(_sceneObject);
  43. _sceneObject = null;
  44. }
  45. if (_scenePrefab != null)
  46. {
  47. GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneDressUp"));
  48. _scenePrefab = null;
  49. }
  50. if (_comSelected != null)
  51. {
  52. _comSelected.RemoveFromParent();
  53. _comSelected.Dispose();
  54. }
  55. if (_dressUpObjDataCache != null)
  56. {
  57. _dressUpObjDataCache.Dispose();
  58. _dressUpObjDataCache = null;
  59. }
  60. _cfgSelected = null;
  61. if (_ui != null)
  62. {
  63. _ui.Dispose();
  64. _ui = null;
  65. }
  66. base.Dispose();
  67. }
  68. protected override void OnInit()
  69. {
  70. base.OnInit();
  71. packageName = UI_ClothingShopUI.PACKAGE_NAME;
  72. _ui = UI_ClothingShopUI.Create();
  73. this.viewCom = _ui.target;
  74. isfullScreen = true;
  75. _valueBarController = new ValueBarController(_ui.m_valueBar);
  76. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  77. _dressUpObjDataCache = new DressUpObjDataCache();
  78. _comSelected = new GComponent();
  79. _comSelected.x = -5;
  80. _comSelected.y = -3;
  81. _comSelected = UIPackage.CreateObject(UI_ClothingShopUI.PACKAGE_NAME, "ComSelect").asCom;
  82. _ui.m_listShop.itemRenderer = ListShopItemRender;
  83. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  84. _ui.m_compItemInfo.m_btnBuy.onClick.Add(OnclickBtnBuy);
  85. _ui.m_listType.onClickItem.Add(OnClickListTypeItem);
  86. _ui.m_listShop.onClickItem.Add(OnClickListShopItem);
  87. _ui.m_compItemInfo.m_listTag.itemRenderer = RenderListTagItem;
  88. // EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.gold);
  89. }
  90. protected override void AddEventListener()
  91. {
  92. base.AddEventListener();
  93. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  94. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  95. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
  96. }
  97. protected override void OnShown()
  98. {
  99. base.OnShown();
  100. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  101. _storeId = ConstStoreId.CLOTHING_STORE_ID;
  102. _scoreType = 0;
  103. _selectedItemId = 0;
  104. _selectedType = 0;
  105. if (this.viewData != null)
  106. {
  107. //this.viewData[0]=storeId(商店Id)
  108. //this.viewData[1]=_scoreType(服装属性:风花雪月)
  109. //this.viewData[2]=_selectedItemId
  110. //this.viewData[3]=_selectedItemCount
  111. object[] objs = this.viewData as object[];
  112. if (objs.Length > 0 && objs[0] != null)
  113. {
  114. _storeId = (int)objs[0];//从抽奖跳转到商店会区分商店Id
  115. }
  116. if (objs.Length > 1 && objs[1] != null)
  117. {
  118. _scoreType = (int)objs[1];//从战斗跳转到商店需要服装突出属性用来服装排序
  119. }
  120. if (objs.Length > 2 && objs[2] != null)
  121. {
  122. _selectedItemId = (int)objs[2];//从物品来源面板跳转到商店,需要物品id方便打开界面时做选中处理
  123. _selectedItemCount = (int)objs[3];
  124. ShopCfg[] dataArray = ClothingShopCfgManager.Instance.GetShopCfgs(_storeId);
  125. for (int i = 0; i < dataArray.Length; i++)
  126. {
  127. if (dataArray[i].itemID == _selectedItemId)
  128. {
  129. _selectedType = dataArray[i].typeIndex;
  130. _selectedItemClothingId = dataArray[i].id;
  131. // ShopCfg clothingShopCfg = ShopCfgClothingArray.Instance.GetCfg(_selectedItemClothingId);
  132. _ui.m_listType.selectedIndex = _selectedType;
  133. break;
  134. }
  135. }
  136. }
  137. }
  138. _ui.m_c1.selectedIndex = _storeId;
  139. _ui.m_compItemInfo.m_c1.selectedIndex = _storeId;
  140. _ui.m_listType.selectedIndex = _selectedType;
  141. _ui.m_listType.ScrollToView(_selectedType);
  142. UpdateList(false);
  143. _ui.m_listShop.height = _ui.target.height - _ui.m_listShop.y;
  144. _ui.m_bgList.height = _ui.target.height - _ui.m_bgList.y;
  145. UpdateCJGoodsCount();
  146. _valueBarController.OnShown();
  147. _valueBarController.Controller(1);
  148. if (_storeId == ConstStoreId.CLOTHING_STORE_ID)
  149. {
  150. _valueBarController.Controller(1);
  151. }
  152. else if (_storeId == ConstStoreId.LUCKY_BOX_STORE_ID)
  153. {
  154. _valueBarController.Controller(2);
  155. }
  156. else if (_storeId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  157. {
  158. _valueBarController.Controller(3);
  159. }
  160. if (_selectedItemId > 0 && _selectedItemCount > 0)
  161. {
  162. ShopDataManager.Instance.BuyItem(_cfgSelected.id, _selectedItemCount, _storeId, _cfgSelected);
  163. }
  164. Timers.inst.AddUpdate(CheckGuide);
  165. }
  166. protected override void OnHide()
  167. {
  168. base.OnHide();
  169. _valueBarController.OnHide();
  170. if (_sceneObject != null)
  171. {
  172. GameObject.Destroy(_sceneObject);
  173. _sceneObject = null;
  174. }
  175. if (_wrapper != null)
  176. {
  177. _wrapper.wrapTarget = null;
  178. }
  179. _selectedItemId = 0;
  180. Timers.inst.Remove(CheckGuide);
  181. }
  182. protected override void RemoveEventListener()
  183. {
  184. base.RemoveEventListener();
  185. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  186. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  187. }
  188. private void OnClickBtnBack()
  189. {
  190. ViewManager.GoBackFrom(ViewName.CLOTHING_SHOP_VIEW);
  191. this.Hide();
  192. }
  193. private void OnclickBtnBuy()
  194. {
  195. int count = _selectedItemId > 0 && _cfgSelected.itemID == _selectedItemId ? _selectedItemCount : INIT_COUNT;
  196. // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
  197. count = Math.Max(1, count);
  198. ShopDataManager.Instance.BuyItem(_cfgSelected.id, count, _storeId, _cfgSelected);
  199. }
  200. private void UpdateItemChange()
  201. {
  202. UpdateCJGoodsCount();
  203. UpdateList(false);
  204. }
  205. private void UpdateCJGoodsCount()
  206. {
  207. int luckyBoxId1 = LuckyBoxDataManager.BOX_ID_3;
  208. LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1);
  209. _ui.m_txtCount0.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.bonusArr[0][0]);
  210. _ui.m_loaIcon0.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.bonusArr[0][0]).res);
  211. int luckyBoxId2 = LuckyBoxDataManager.BOX_ID_2;
  212. LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2);
  213. _ui.m_txtCount1.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.bonusArr[0][0]);
  214. _ui.m_loaIcon1.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.bonusArr[0][0]).res);
  215. }
  216. private void UpdateRole(bool tween)
  217. {
  218. if (_sceneObject != null)
  219. {
  220. GameObject.Destroy(_sceneObject);
  221. _sceneObject = null;
  222. }
  223. _sceneObject = GameObject.Instantiate(_scenePrefab);
  224. int scale = 70;
  225. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  226. _dressUpObjDataCache.setSceneObj(_sceneObject);
  227. _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
  228. _dressUpObjDataCache.AddOrRemove(_cfgSelected.itemID, true);
  229. if (_wrapper == null)
  230. {
  231. _wrapper = new GoWrapper(_sceneObject);
  232. _ui.m_compHolder.m_compMover.m_holder.SetNativeObject(_wrapper);
  233. }
  234. else
  235. {
  236. _wrapper.wrapTarget = _sceneObject;
  237. }
  238. int type = ItemUtilCS.GetItemSubType(_cfgSelected.itemID);
  239. float duration = DURATION;
  240. if (!tween)
  241. {
  242. duration = 0;
  243. }
  244. if (Array.IndexOf(HEAD_Y_ARR, type) >= 0)
  245. {
  246. _ui.m_compHolder.m_compMover.target.TweenMoveY(HEAD_Y, duration);
  247. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SCALE_MAX, SCALE_MAX), duration);
  248. }
  249. else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)
  250. {
  251. _ui.m_compHolder.m_compMover.target.TweenMoveY(SHOES_Y, duration);
  252. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SCALE_MAX, SCALE_MAX), duration);
  253. }
  254. else
  255. {
  256. _ui.m_compHolder.m_compMover.target.TweenMoveY(BODY_Y, duration);
  257. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(1, 1), duration);
  258. }
  259. }
  260. private void UpdateList(bool tween)
  261. {
  262. _ui.m_listShop.RemoveChildrenToPool();
  263. int typeIndex = _ui.m_listType.selectedIndex;
  264. _dataList = ClothingShopCfgManager.Instance.GetList(_storeId, typeIndex, _scoreType);
  265. _ui.m_listShop.numItems = _dataList.Count;
  266. if (_ui.m_listShop.numItems > 0)
  267. {
  268. ShopCfg clothingShopCfg = ClothingShopCfgManager.Instance.GetShopCfg(_selectedItemClothingId, _storeId);// ShopCfgClothingArray.Instance.GetCfg(_selectedItemClothingId);
  269. int itemIndex = 0;
  270. if (_selectedItemId > 0 && clothingShopCfg != null)
  271. {
  272. // itemIndex = _dataList.IndexOf(clothingShopCfg);
  273. for (int i = 0; i < _dataList.Count; i++)
  274. {
  275. if (_dataList[i].id == _selectedItemClothingId)
  276. {
  277. itemIndex = i;
  278. break;
  279. }
  280. }
  281. _ui.m_listShop.ScrollToView(itemIndex < 0 ? 0 : itemIndex);
  282. // _selectedItemId = 0;
  283. }
  284. UpdateSelectedItemInfo(_ui.m_listShop.GetChildAt(itemIndex) as GComponent, tween);
  285. }
  286. }
  287. private void OnClickListTypeItem(EventContext context)
  288. {
  289. UpdateList(true);
  290. }
  291. private void OnClickListShopItem(EventContext context)
  292. {
  293. _selectedItemId = 0;
  294. // UI_ShopListItemRender selectedListItem = UI_ShopListItemRender.Proxy(_selectedListItem);
  295. // selectedListItem.m_grpSelect.visible = false;
  296. UpdateSelectedItemInfo(context.data as GComponent, true);
  297. }
  298. private void ListShopItemRender(int index, GObject item)
  299. {
  300. UI_ShopListItemRender listItem = UI_ShopListItemRender.Proxy(item);
  301. ShopCfg cfg = _dataList[index];
  302. listItem.target.data = cfg;
  303. // listItem.m_grpSelect.visible = false;
  304. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemID);
  305. listItem.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  306. string itemName = itemCfg.name;
  307. listItem.m_txtName.text = itemName;
  308. RarityIconController.UpdateRarityIcon(listItem.m_rarity, cfg.itemID, false);
  309. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(cfg.costID);
  310. listItem.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
  311. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(cfg.itemID) > 0;
  312. listItem.m_txtPrice.text = ItemDataManager.GetItemNum(cfg.costID) >= cfg.costNum ? StringUtil.GetColorText(cfg.costNum.ToString(), "#DD994A") : StringUtil.GetColorText(cfg.costNum.ToString(), "#F2989B");
  313. UI_ShopListItemRender.ProxyEnd();
  314. }
  315. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  316. {
  317. _selectedListItem = listItem;
  318. listItem.AddChild(_comSelected);
  319. // UI_ShopListItemRender item = UI_ShopListItemRender.Proxy(listItem);
  320. // item.m_grpSelect.visible = true;
  321. // item.target.AddChild()
  322. ShopCfg cfg = listItem.data as ShopCfg;
  323. _cfgSelected = cfg;
  324. UpdateRole(tween);
  325. UpdateSelectedItemInfo();
  326. }
  327. private void UpdateSelectedItemInfo()
  328. {
  329. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
  330. string itemName = itemCfg.name;
  331. _ui.m_compItemInfo.m_txtName.text = itemName;
  332. _ui.m_compItemInfo.m_txtDesc.text = itemCfg.desc;
  333. RarityIconController.UpdateRarityIcon(_ui.m_compItemInfo.m_rarity, _cfgSelected.itemID, false);
  334. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.costID);
  335. _ui.m_compItemInfo.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
  336. _ui.m_compItemInfo.m_txtPrice.text = "" + _cfgSelected.costNum;
  337. _ui.m_compItemInfo.m_txtGong.text = "" + itemCfg.score1;
  338. _ui.m_compItemInfo.m_txtShang.text = "" + itemCfg.score2;
  339. _ui.m_compItemInfo.m_txtJue.text = "" + itemCfg.score3;
  340. _ui.m_compItemInfo.m_txtZhi.text = "" + itemCfg.score4;
  341. _ui.m_compItemInfo.m_txtOwned.SetVar("v1", "" + ItemDataManager.GetItemNum(_cfgSelected.itemID)).FlushVars();
  342. UI_ShopListItemRender listItem = UI_ShopListItemRender.Proxy(_selectedListItem);
  343. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_cfgSelected.itemID) > 0;
  344. UI_ShopListItemRender.ProxyEnd();
  345. _ui.m_compItemInfo.m_listTag.numItems = itemCfg.tagsArr.Length;
  346. }
  347. private void RenderListTagItem(int index, GObject obj)
  348. {
  349. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  350. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
  351. string[] tag = itemCfg.tagsArr[index].Split('_');
  352. item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tag[0]);
  353. item.m_txtTag.text = tag[1];
  354. UI_ListTagItem.ProxyEnd();
  355. }
  356. private void CheckGuide(object param)
  357. {
  358. if (GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  359. {
  360. UpdateToCheckGuide(null);
  361. }
  362. else
  363. {
  364. Timers.inst.Remove(CheckGuide);
  365. }
  366. }
  367. protected override void UpdateToCheckGuide(object param)
  368. {
  369. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  370. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.BUY_CLOTHING, 6, "回到换装", -1, true, 140);
  371. }
  372. }
  373. }