ClothingShopView.cs 17 KB

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