ClothingShopView.cs 16 KB

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