ClothingShopView.cs 16 KB

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