ClothingShopView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. using UI.ClothingShop;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using UnityEngine;
  5. using System.Collections.Generic;
  6. using System;
  7. using System.Linq;
  8. using cfg.GfgCfg;
  9. using ET;
  10. using DG.Tweening;
  11. namespace GFGGame
  12. {
  13. public class ClothingShopView : BaseWindow
  14. {
  15. private const int SHOES_Y = 105;
  16. private const int HEAD_Y = 609;
  17. private const int BODY_Y = 412;
  18. private const float SCALE_MAX = 1.5f;
  19. private const float DURATION = 0.6f;
  20. private readonly int[] HEAD_Y_ARR = new int[]
  21. {
  22. ConstDressUpItemType.FA_XING, ConstDressUpItemType.NEI_DA, ConstDressUpItemType.SHANG_YI,
  23. ConstDressUpItemType.TOU_SHI, ConstDressUpItemType.ER_SHI, ConstDressUpItemType.JING_SHI
  24. };
  25. private readonly int[] SHOES_Y_ARR = new int[]
  26. {
  27. ConstDressUpItemType.XIA_ZHUANG, ConstDressUpItemType.WA_ZI, ConstDressUpItemType.XIE_ZI,
  28. ConstDressUpItemType.SHOU_SHI, ConstDressUpItemType.YAO_SHI
  29. };
  30. private UI_ClothingShopUI _ui;
  31. private DressUpObjUI _dressUpObjUI;
  32. private ValueBarController _valueBarController;
  33. private List<ShopCfg> _dataList;
  34. private GImage _comSelected;
  35. private ShopCfg _cfgSelected;
  36. private const int MAX_COUNT = 99;
  37. private const int INIT_COUNT = 1;
  38. private int _scoreType;
  39. private int _storeId = 1;
  40. private GObject _selectedListItem;
  41. private int _selectedItemId; //打开界面时选中的物品id
  42. private int _selectedType = 0; //打开界面时选中的物品类型
  43. private int _selectedItemCount;
  44. private int _selectedId;
  45. public override void Dispose()
  46. {
  47. if (_valueBarController != null)
  48. {
  49. _valueBarController.Dispose();
  50. _valueBarController = null;
  51. }
  52. if (_comSelected != null)
  53. {
  54. _comSelected.RemoveFromParent();
  55. _comSelected.Dispose();
  56. }
  57. if (_dressUpObjUI != null)
  58. {
  59. _dressUpObjUI.Dispose();
  60. _dressUpObjUI = null;
  61. }
  62. _cfgSelected = null;
  63. if (_ui != null)
  64. {
  65. _ui.Dispose();
  66. _ui = null;
  67. }
  68. base.Dispose();
  69. }
  70. protected override void OnInit()
  71. {
  72. base.OnInit();
  73. packageName = UI_ClothingShopUI.PACKAGE_NAME;
  74. _ui = UI_ClothingShopUI.Create();
  75. this.viewCom = _ui.target;
  76. isfullScreen = true;
  77. //isReturnView = true;
  78. _valueBarController = new ValueBarController(_ui.m_valueBar);
  79. //_dressUpObjUI = new DressUpObjUI("SceneDressUp");
  80. _comSelected = new GImage();
  81. _comSelected.x = -5;
  82. _comSelected.y = -3;
  83. _comSelected = UIPackage.CreateObject(UI_ClothingShopUI.PACKAGE_NAME, "fzd_fzxzhong").asImage;
  84. _ui.m_listShop.itemRenderer = ListShopItemRender;
  85. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  86. _ui.m_compItemInfo.m_btnBuy.onClick.Add(OnclickBtnBuy);
  87. _ui.m_listType.onClickItem.Add(OnClickListTypeItem);
  88. _ui.m_listShop.onClickItem.Add(OnClickListShopItem);
  89. _ui.m_compItemInfo.m_listTag.itemRenderer = RenderListTagItem;
  90. // EventAgent.DispatchEvent(ConstMessage.MONEY_CHANGE, RoleDataManager.gold);
  91. }
  92. protected override void AddEventListener()
  93. {
  94. base.AddEventListener();
  95. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  96. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  97. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
  98. }
  99. protected override void OnShown()
  100. {
  101. base.OnShown();
  102. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  103. _storeId = ConstStoreId.CLOTHING_STORE_ID;
  104. _scoreType = 0;
  105. _selectedItemId = 0;
  106. _selectedType = 0;
  107. if (this.viewData != null)
  108. {
  109. //this.viewData[0]=storeId(商店Id)
  110. //this.viewData[1]=_scoreType(服装属性:风花雪月)
  111. //this.viewData[2]=_selectedItemId
  112. //this.viewData[3]=_selectedItemCount
  113. object[] objs = this.viewData as object[];
  114. if (objs.Length > 0 && objs[0] != null)
  115. {
  116. _storeId = (int)objs[0]; //从抽奖跳转到商店会区分商店Id
  117. }
  118. if (objs.Length > 1 && objs[1] != null)
  119. {
  120. _scoreType = (int)objs[1]; //从战斗跳转到商店需要服装突出属性用来服装排序
  121. }
  122. if (objs.Length > 2 && objs[2] != null)
  123. {
  124. _selectedItemId = (int)objs[2]; //从物品来源面板跳转到商店,需要物品id方便打开界面时做选中处理
  125. long selectedItemCount = (long)objs[3];
  126. _selectedItemCount = (int)selectedItemCount;
  127. List<ShopCfg> dataArray =
  128. CommonDataManager.Tables.TblShopCfg.DataList.Where(a =>
  129. a.Menu1 == ConstStoreTabId.FU_ZHUANG_DIAN && a.Menu2 == ConstStoreSubId.FU_ZHUANG_DIAN)
  130. .ToList();
  131. for (int i = 0; i < dataArray.Count; i++)
  132. {
  133. if (dataArray[i].ItemId == _selectedItemId)
  134. {
  135. _selectedType = int.Parse(dataArray[i].TypeIndex);
  136. _selectedId = dataArray[i].Id;
  137. // ShopCfg clothingShopCfg = ShopCfgClothingArray.Instance.GetCfg(_selectedItemClothingId);
  138. _ui.m_listType.selectedIndex = _selectedType;
  139. break;
  140. }
  141. }
  142. }
  143. }
  144. _ui.m_c1.selectedIndex = _storeId;
  145. _ui.m_compItemInfo.m_c1.selectedIndex = _storeId;
  146. _ui.m_listType.selectedIndex = _selectedType;
  147. _ui.m_listType.ScrollToView(_selectedType);
  148. UpdateList(false);
  149. _ui.m_listShop.height = _ui.target.height - _ui.m_listShop.y;
  150. _ui.m_bgList.height = _ui.target.height - _ui.m_bgList.y;
  151. UpdateCJGoodsCount();
  152. _valueBarController.OnShown();
  153. _valueBarController.Controller(5);
  154. if (_storeId == ConstStoreId.CLOTHING_STORE_ID)
  155. {
  156. _valueBarController.Controller(5);
  157. }
  158. else if (_storeId == ConstStoreId.LUCKY_BOX_STORE_ID)
  159. {
  160. _valueBarController.Controller(2);
  161. }
  162. else if (_storeId == ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID)
  163. {
  164. _valueBarController.Controller(3);
  165. }
  166. else if (_storeId == ConstStoreId.GALLERY_STORE_ID)
  167. {
  168. _valueBarController.Controller(8);
  169. }
  170. if (_selectedItemId > 0 && _selectedItemCount > 0)
  171. {
  172. ShopViewManager.Instance.BuyItem(_cfgSelected.Id, _selectedItemCount, ConstBuyType.TYPE_SHOP,
  173. _cfgSelected);
  174. }
  175. Timers.inst.AddUpdate(CheckGuide);
  176. }
  177. protected override void OnHide()
  178. {
  179. base.OnHide();
  180. _valueBarController.OnHide();
  181. _selectedItemId = 0;
  182. Timers.inst.Remove(CheckGuide);
  183. Timers.inst.Remove(OnTimerUpDate);
  184. }
  185. protected override void RemoveEventListener()
  186. {
  187. base.RemoveEventListener();
  188. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  189. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  190. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
  191. }
  192. private void OnClickBtnBack()
  193. {
  194. ViewManager.GoBackFrom(typeof(ClothingShopView).FullName);
  195. //this.Hide();
  196. }
  197. private void OnclickBtnBuy()
  198. {
  199. int count = _selectedItemId > 0 && _cfgSelected.ItemId == _selectedItemId ? _selectedItemCount : INIT_COUNT;
  200. // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
  201. count = Math.Max(1, count);
  202. ShopViewManager.Instance.BuyItem(_cfgSelected.Id, count, ConstBuyType.TYPE_SHOP, _cfgSelected);
  203. }
  204. private void UpdateItemChange()
  205. {
  206. UpdateCJGoodsCount();
  207. UpdateList(false);
  208. }
  209. private void UpdateCJGoodsCount()
  210. {
  211. // int luckyBoxId1 = LuckyBoxDataManager.BOX_ID_3;
  212. // LuckyBoxCfg luckyBoxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId1);
  213. // _ui.m_txtCount0.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg1.bonusArr[0][0]);
  214. // _ui.m_loaIcon0.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg1.bonusArr[0][0]).res);
  215. // int luckyBoxId2 = LuckyBoxDataManager.BOX_ID_2;
  216. // LuckyBoxCfg luckyBoxCfg2 = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId2);
  217. // _ui.m_txtCount1.text = "" + ItemDataManager.GetItemNum(luckyBoxCfg2.bonusArr[0][0]);
  218. // _ui.m_loaIcon1.icon = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg2.bonusArr[0][0]).res);
  219. }
  220. private EaseType ease = EaseType.CubicOut;
  221. private void OnTimerUpDate(object param = null)
  222. {
  223. bool tween = (bool)param;
  224. _dressUpObjUI.UpdateWrapper(_ui.m_compHolder.m_compMover.m_holder);
  225. // 根据服装类型设置动画
  226. int type = ItemUtilCS.GetItemSubType(_cfgSelected.ItemId);
  227. float duration = tween ? DURATION : 0;
  228. if (Array.IndexOf(HEAD_Y_ARR, type) >= 0)
  229. {
  230. _ui.m_compHolder.m_compMover.target.TweenMoveY(HEAD_Y, duration).SetEase(ease);
  231. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SCALE_MAX, SCALE_MAX), duration)
  232. .SetEase(ease);
  233. }
  234. else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)
  235. {
  236. _ui.m_compHolder.m_compMover.target.TweenMoveY(SHOES_Y, duration).SetEase(ease);
  237. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(SCALE_MAX, SCALE_MAX), duration)
  238. .SetEase(ease);
  239. }
  240. else
  241. {
  242. _ui.m_compHolder.m_compMover.target.TweenMoveY(BODY_Y, duration).SetEase(ease);
  243. _ui.m_compHolder.m_compMover.target.TweenScale(new Vector2(1, 1), duration).SetEase(ease);
  244. }
  245. }
  246. private void UpdateRole(bool tween)
  247. {
  248. if (_dressUpObjUI != null)
  249. {
  250. _dressUpObjUI.Dispose();
  251. _dressUpObjUI = null;
  252. }
  253. _dressUpObjUI = new DressUpObjUI("SceneDressUp");
  254. // 使用异步方式重置场景对象
  255. _dressUpObjUI.ResetSceneObjAsync(70, false, true, null, false, (sceneObj) =>
  256. {
  257. if (sceneObj != null)
  258. {
  259. // 场景对象加载完成后添加服装
  260. _dressUpObjUI.dressUpObj.AddOrRemove(_cfgSelected.ItemId, true, DressUpOption.Add);
  261. Timers.inst.Add(1f, 1, OnTimerUpDate, tween);
  262. }
  263. else
  264. {
  265. Debug.LogError("Failed to load scene object for role update");
  266. }
  267. });
  268. }
  269. private void UpdateList(bool tween)
  270. {
  271. _ui.m_listShop.RemoveChildrenToPool();
  272. int typeIndex = _ui.m_listType.selectedIndex;
  273. _dataList = ShopDataManager.Instance.GetList(_storeId, typeIndex, _scoreType);
  274. _ui.m_listShop.numItems = _dataList.Count;
  275. if (_ui.m_listShop.numItems > 0)
  276. {
  277. ShopCfg clothingShopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(_selectedId);
  278. int itemIndex = 0;
  279. if (_selectedItemId > 0 && clothingShopCfg != null)
  280. {
  281. // itemIndex = _dataList.IndexOf(clothingShopCfg);
  282. for (int i = 0; i < _dataList.Count; i++)
  283. {
  284. if (_dataList[i].Id == _selectedId)
  285. {
  286. itemIndex = i;
  287. break;
  288. }
  289. }
  290. _ui.m_listShop.ScrollToView(itemIndex < 0 ? 0 : itemIndex);
  291. // _selectedItemId = 0;
  292. }
  293. UpdateSelectedItemInfo(_ui.m_listShop.GetChildAt(itemIndex) as GComponent, tween);
  294. }
  295. }
  296. private void OnClickListTypeItem(EventContext context)
  297. {
  298. UpdateList(true);
  299. }
  300. private void OnClickListShopItem(EventContext context)
  301. {
  302. _selectedItemId = 0;
  303. // UI_ShopListItemRender selectedListItem = UI_ShopListItemRender.Proxy(_selectedListItem);
  304. // selectedListItem.m_grpSelect.visible = false;
  305. UpdateSelectedItemInfo(context.data as GComponent, true);
  306. }
  307. private void ListShopItemRender(int index, GObject item)
  308. {
  309. UI_ListClothingShopItem listItem = UI_ListClothingShopItem.Proxy(item);
  310. ShopCfg cfg = _dataList[index];
  311. listItem.target.data = cfg;
  312. // listItem.m_grpSelect.visible = false;
  313. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(cfg.ItemId);
  314. listItem.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  315. string itemName = itemCfg.Name;
  316. listItem.m_txtName.text = itemName;
  317. RarityIconController.UpdateRarityIcon(listItem.m_rarity, cfg.ItemId, false);
  318. ItemCfg costItemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(cfg.CostIdReal);
  319. listItem.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.Res;
  320. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(cfg.ItemId) > 0;
  321. listItem.m_txtPrice.text = ItemDataManager.GetItemNum(cfg.CostIdReal) >= cfg.Price
  322. ? StringUtil.GetColorText(cfg.Price.ToString(), "#DD994A")
  323. : StringUtil.GetColorText(cfg.Price.ToString(), "#F2989B");
  324. listItem.m_loaMainScore.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + (itemCfg.MainScore));
  325. UI_ListClothingShopItem.ProxyEnd();
  326. }
  327. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  328. {
  329. _selectedListItem = listItem;
  330. listItem.AddChildAt(_comSelected, 1);
  331. // UI_ShopListItemRender item = UI_ShopListItemRender.Proxy(listItem);
  332. // item.m_grpSelect.visible = true;
  333. // item.target.AddChild()
  334. ShopCfg cfg = listItem.data as ShopCfg;
  335. if (_cfgSelected != null)
  336. {
  337. _dressUpObjUI.dressUpObj.AddOrRemove(_cfgSelected.ItemId, true);
  338. }
  339. _cfgSelected = cfg;
  340. UpdateRole(tween);
  341. UpdateSelectedItemInfo();
  342. }
  343. private void UpdateSelectedItemInfo()
  344. {
  345. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_cfgSelected.ItemId);
  346. string itemName = itemCfg.Name;
  347. _ui.m_compItemInfo.m_txtName.text = itemName;
  348. _ui.m_compItemInfo.m_txtDesc.text = itemCfg.Desc;
  349. RarityIconController.UpdateRarityIcon(_ui.m_compItemInfo.m_rarity, _cfgSelected.ItemId, false);
  350. ItemCfg costItemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_cfgSelected.CostIdReal);
  351. _ui.m_compItemInfo.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.Res;
  352. _ui.m_compItemInfo.m_txtPrice.text = "" + _cfgSelected.Price;
  353. _ui.m_compItemInfo.m_txtGong.text = "" + itemCfg.Score1;
  354. _ui.m_compItemInfo.m_txtShang.text = "" + itemCfg.Score2;
  355. _ui.m_compItemInfo.m_txtJue.text = "" + itemCfg.Score3;
  356. _ui.m_compItemInfo.m_txtZhi.text = "" + itemCfg.Score4;
  357. _ui.m_compItemInfo.m_txtOwned.SetVar("v1", "" + ItemDataManager.GetItemNum(_cfgSelected.ItemId))
  358. .FlushVars();
  359. UI_ListClothingShopItem listItem = UI_ListClothingShopItem.Proxy(_selectedListItem);
  360. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(_cfgSelected.ItemId) > 0;
  361. UI_ListClothingShopItem.ProxyEnd();
  362. _ui.m_compItemInfo.m_listTag.numItems = itemCfg.Tags.Count;
  363. }
  364. private void RenderListTagItem(int index, GObject obj)
  365. {
  366. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(_cfgSelected.ItemId);
  367. UI_ListTagItem item = UI_ListTagItem.Proxy(obj);
  368. ItemUtil.UpdateTag(item.m_comTag.target, itemCfg.Tags[index].Name);
  369. item.m_txtTagScore.text = itemCfg.Tags[index].Val.ToString();
  370. UI_ListTagItem.ProxyEnd();
  371. }
  372. private void CheckGuide(object param)
  373. {
  374. if (GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  375. {
  376. UpdateToCheckGuide(null);
  377. }
  378. else
  379. {
  380. Timers.inst.Remove(CheckGuide);
  381. }
  382. }
  383. protected override void UpdateToCheckGuide(object param)
  384. {
  385. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  386. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.BUY_CLOTHING, 6, "回到换装。");
  387. }
  388. }
  389. }