GalleryShopView.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. class GalleryShopTabType
  10. {
  11. public const int BG = 0;
  12. public const int NPC = 1;
  13. public const int ITEM = 2;
  14. public const int BORDER = 3;
  15. public const int EFFECT = 4;
  16. }
  17. public class GalleryShopView : BaseView
  18. {
  19. private UI_GalleryShopUI _ui;
  20. private ValueBarController _valueBarController;
  21. private List<ShopCfg> _dataList;
  22. private ShopCfg _cfgSelected;
  23. private const int MAX_COUNT = 99;
  24. private const int INIT_COUNT = 1;
  25. private int _scoreType;
  26. private int _storeId = 1;
  27. private GButton _selectedListItem;
  28. private int _selectedItemId;//打开界面时选中的物品id
  29. private int _selectedType = 0;//打开界面时选中的物品类型
  30. private int _selectedItemCount;
  31. private int _selectedItemClothingId;
  32. public override void Dispose()
  33. {
  34. if (_valueBarController != null)
  35. {
  36. _valueBarController.Dispose();
  37. _valueBarController = null;
  38. }
  39. _cfgSelected = null;
  40. if (_ui != null)
  41. {
  42. _ui.Dispose();
  43. _ui = null;
  44. }
  45. base.Dispose();
  46. }
  47. protected override void OnInit()
  48. {
  49. base.OnInit();
  50. packageName = UI_GalleryShopUI.PACKAGE_NAME;
  51. _ui = UI_GalleryShopUI.Create();
  52. this.viewCom = _ui.target;
  53. isfullScreen = true;
  54. _valueBarController = new ValueBarController(_ui.m_valueBar);
  55. _ui.m_comItemList.m_list.itemRenderer = ListShopItemRender;
  56. _ui.m_comItemList.m_list.onClickItem.Add(OnClickListShopItem);
  57. _ui.m_comItemList.m_comBtnTab.m_c1.onChanged.Add(OnClickListTypeItem);
  58. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  59. _ui.m_btnBuy.onClick.Add(OnclickBtnBuy);
  60. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hz_bjbj");
  61. }
  62. protected override void AddEventListener()
  63. {
  64. base.AddEventListener();
  65. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  66. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  67. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
  68. }
  69. protected override void OnShown()
  70. {
  71. base.OnShown();
  72. _storeId = ConstStoreId.GALLERY_STORE_ID;
  73. _scoreType = 0;
  74. _selectedItemId = 0;
  75. _selectedType = 0;
  76. if (this.viewData != null)
  77. {
  78. //this.viewData[0]=storeId(商店Id)
  79. //this.viewData[1]=_scoreType(服装属性:风花雪月)
  80. //this.viewData[2]=_selectedItemId
  81. //this.viewData[3]=_selectedItemCount
  82. object[] objs = this.viewData as object[];
  83. if (objs.Length > 0 && objs[0] != null)
  84. {
  85. _storeId = (int)objs[0];//从抽奖跳转到商店会区分商店Id
  86. }
  87. if (objs.Length > 1 && objs[1] != null)
  88. {
  89. _scoreType = (int)objs[1];//从战斗跳转到商店需要服装突出属性用来服装排序
  90. }
  91. if (objs.Length > 2 && objs[2] != null)
  92. {
  93. _selectedItemId = (int)objs[2];//从物品来源面板跳转到商店,需要物品id方便打开界面时做选中处理
  94. _selectedItemCount = (int)objs[3];
  95. ShopCfg[] dataArray = ClothingShopCfgManager.Instance.GetShopCfgs(_storeId);
  96. for (int i = 0; i < dataArray.Length; i++)
  97. {
  98. if (dataArray[i].itemID == _selectedItemId)
  99. {
  100. _selectedType = dataArray[i].typeIndex;
  101. _selectedItemClothingId = dataArray[i].id;
  102. _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex = _selectedType;
  103. break;
  104. }
  105. }
  106. }
  107. }
  108. _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex = _selectedType;
  109. // _ui.m_listType.ScrollToView(_selectedType);
  110. UpdateList(false);
  111. _valueBarController.OnShown();
  112. if (_selectedItemId > 0 && _selectedItemCount > 0)
  113. {
  114. ShopDataManager.Instance.BuyItem(_cfgSelected.id, _selectedItemCount, _storeId, _cfgSelected);
  115. }
  116. Timers.inst.AddUpdate(CheckGuide);
  117. }
  118. protected override void OnHide()
  119. {
  120. base.OnHide();
  121. _valueBarController.OnHide();
  122. _selectedItemId = 0;
  123. Timers.inst.Remove(CheckGuide);
  124. }
  125. protected override void RemoveEventListener()
  126. {
  127. base.RemoveEventListener();
  128. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  129. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  130. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
  131. }
  132. private void OnClickBtnBack()
  133. {
  134. ViewManager.GoBackFrom(typeof(GalleryShopView).FullName);
  135. }
  136. private void OnclickBtnBuy()
  137. {
  138. int count = _selectedItemId > 0 && _cfgSelected.itemID == _selectedItemId ? _selectedItemCount : INIT_COUNT;
  139. // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
  140. count = Math.Max(1, count);
  141. ShopDataManager.Instance.BuyItem(_cfgSelected.id, count, _storeId, _cfgSelected);
  142. }
  143. private void UpdateItemChange()
  144. {
  145. UpdateList(false);
  146. }
  147. private void UpdateList(bool tween)
  148. {
  149. int typeIndex = _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex;
  150. _dataList = ClothingShopCfgManager.Instance.GetList(_storeId, typeIndex, _scoreType);
  151. _ui.m_comItemList.m_list.numItems = _dataList.Count;
  152. if (_ui.m_comItemList.m_list.numItems > 0)
  153. {
  154. ShopCfg clothingShopCfg = ClothingShopCfgManager.Instance.GetShopCfg(_selectedItemClothingId, _storeId);
  155. int itemIndex = 0;
  156. if (_selectedItemId > 0 && clothingShopCfg != null)
  157. {
  158. for (int i = 0; i < _dataList.Count; i++)
  159. {
  160. if (_dataList[i].id == _selectedItemClothingId)
  161. {
  162. itemIndex = i;
  163. break;
  164. }
  165. }
  166. _ui.m_comItemList.m_list.ScrollToView(itemIndex < 0 ? 0 : itemIndex);
  167. _ui.m_comItemList.m_list.selectedIndex = itemIndex;
  168. }
  169. UpdateSelectedItemInfo(_ui.m_comItemList.m_list.GetChildAt(itemIndex) as GComponent, tween);
  170. }
  171. }
  172. private void OnClickListTypeItem(EventContext context)
  173. {
  174. UpdateList(true);
  175. }
  176. private void ListShopItemRender(int index, GObject item)
  177. {
  178. UI_ListGalleryShopItem listItem = UI_ListGalleryShopItem.Proxy(item);
  179. ShopCfg cfg = _dataList[index];
  180. listItem.target.data = cfg;
  181. // listItem.m_grpSelect.visible = false;
  182. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemID);
  183. listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  184. string itemName = itemCfg.name;
  185. listItem.m_txtName.text = itemName;
  186. // RarityIconController.UpdateRarityIcon(listItem.m_rarity, cfg.itemID, false);
  187. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(cfg.costID);
  188. listItem.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
  189. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(cfg.itemID) > 0;
  190. // listItem.m_txtPrice.text = ItemDataManager.GetItemNum(cfg.costID) >= cfg.costNum ? StringUtil.GetColorText(cfg.costNum.ToString(), "#DD994A") : StringUtil.GetColorText(cfg.costNum.ToString(), "#F2989B");
  191. listItem.m_txtPrice.text = cfg.costNum.ToString();
  192. UI_ListGalleryShopItem.ProxyEnd();
  193. }
  194. private void OnClickListShopItem(EventContext context)
  195. {
  196. _selectedItemId = 0;
  197. UpdateSelectedItemInfo(context.data as GComponent, true);
  198. }
  199. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  200. {
  201. if (_selectedListItem != null) _selectedListItem.selected = false;
  202. _selectedListItem = listItem.asButton;
  203. _selectedListItem.selected = true;
  204. ShopCfg cfg = listItem.data as ShopCfg;
  205. _cfgSelected = cfg;
  206. UpdateRole(tween);
  207. UpdateSelectedItemInfo();
  208. }
  209. private void UpdateRole(bool tween)
  210. {
  211. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
  212. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  213. _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); ;
  214. // _ui.m_comRes.m_loaBg.visible = false;
  215. // _ui.m_comRes.m_c1.selectedIndex = _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex;
  216. // switch (_ui.m_comRes.m_c1.selectedIndex)
  217. // {
  218. // case GalleryShopTabType.BG:
  219. // // _ui.m_comRes.m_loaBg.url = ResPathUtil.GetDressUpPath(itemCfg.res, ext);
  220. // _ui.m_comRes.m_loaBg.url = ResPathUtil.GetIconPath(itemCfg); ;
  221. // // _ui.m_loaBgRes.visible = true;
  222. // _ui.m_comRes.m_loaBg.visible = true;
  223. // break;
  224. // case GalleryShopTabType.NPC:
  225. // // _ui.m_comRes.m_loaNpc.url = ResPathUtil.GetNpcPicFPath(itemCfg.res);
  226. // _ui.m_comRes.m_loaNpc.url = ResPathUtil.GetIconPath(itemCfg); ;
  227. // break;
  228. // case GalleryShopTabType.ITEM:
  229. // ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
  230. // int sortingOrder = typeCfg.defaultLayer;
  231. // string res = itemCfg.res;
  232. // // _ui.m_comRes.m_comItem.m_loaItem0.visible = false;
  233. // // _ui.m_comRes.m_comItem.m_loaItem1.visible = false;
  234. // // _ui.m_comRes.m_comItem.m_loaItem2.visible = false;
  235. // // _ui.m_comRes.m_comItem.m_loaItem0.url = ResPathUtil.GetIconPath(itemCfg); ;
  236. // // if (!string.IsNullOrEmpty(itemCfg.resLayer1))
  237. // // {
  238. // // res = itemCfg.resLayer1 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer1);
  239. // // string resPath = ResPathUtil.GetDressUpPath(res, ext);
  240. // // // Texture2D texture2D = GFGAsset.Load<Texture2D>(resPath);
  241. // // // _ui.m_comRes.m_loaItem0.texture = new NTexture(texture2D); ;
  242. // // _ui.m_comRes.m_comItem.m_loaItem0.url = resPath;
  243. // // float tx, ty;
  244. // // DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
  245. // // _ui.m_comRes.m_comItem.m_loaItem0.SetXY(tx, ty);
  246. // // _ui.m_comRes.m_comItem.m_loaItem0.visible = true;
  247. // // _ui.m_comRes.m_comItem.m_loaItem0.sortingOrder = sortingOrder;
  248. // // }
  249. // // if (!string.IsNullOrEmpty(itemCfg.resLayer2))
  250. // // {
  251. // // sortingOrder = typeCfg.specialLayer;
  252. // // res = itemCfg.resLayer2 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer2);
  253. // // string resPath = ResPathUtil.GetDressUpPath(res, ext);
  254. // // // Texture2D texture2D = GFGAsset.Load<Texture2D>(resPath);
  255. // // // _ui.m_comRes.m_loaItem1.texture = new NTexture(texture2D); ;
  256. // // _ui.m_comRes.m_comItem.m_loaItem1.url = resPath;
  257. // // float tx, ty;
  258. // // DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
  259. // // _ui.m_comRes.m_comItem.m_loaItem1.SetXY(tx, ty);
  260. // // _ui.m_comRes.m_comItem.m_loaItem1.visible = true;
  261. // // _ui.m_comRes.m_comItem.m_loaItem1.sortingOrder = sortingOrder;
  262. // // }
  263. // // if (!string.IsNullOrEmpty(itemCfg.resLayer3))
  264. // // {
  265. // // sortingOrder = typeCfg.thirdlLayer;
  266. // // res = itemCfg.resLayer3 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer3);
  267. // // string resPath = ResPathUtil.GetDressUpPath(res, ext);
  268. // // // Texture2D texture2D = GFGAsset.Load<Texture2D>(res);
  269. // // // _ui.m_comRes.m_loaItem2.texture = new NTexture(texture2D);
  270. // // _ui.m_comRes.m_comItem.m_loaItem2.url = resPath;
  271. // // float tx, ty;
  272. // // DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
  273. // // _ui.m_comRes.m_comItem.m_loaItem2.SetXY(tx, ty);
  274. // // _ui.m_comRes.m_comItem.m_loaItem2.visible = true;
  275. // // _ui.m_comRes.m_comItem.m_loaItem2.sortingOrder = sortingOrder;
  276. // // }
  277. // // _ui.m_comRes.m_comItem.target.SetSize(_ui.m_comRes.m_comItem.m_grpItem.width, _ui.m_comRes.m_comItem.m_grpItem.height);
  278. // break;
  279. // case GalleryShopTabType.BORDER:
  280. // // _ui.m_comRes.m_loaBorder.url = ResPathUtil.GetPhotographBorderPath(itemCfg.res);
  281. // _ui.m_comRes.m_loaBorder.url = ResPathUtil.GetIconPath(itemCfg); ;
  282. // break;
  283. // case GalleryShopTabType.EFFECT:
  284. // break;
  285. // }
  286. }
  287. private void UpdateSelectedItemInfo()
  288. {
  289. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemID);
  290. _ui.m_txtName.text = itemCfg.name;
  291. _ui.m_txtDesc.text = itemCfg.desc;
  292. }
  293. private void CheckGuide(object param)
  294. {
  295. if (GuideDataManager.IsGuideFinish(ConstGuideId.BUY_CLOTHING) <= 0)
  296. {
  297. UpdateToCheckGuide(null);
  298. }
  299. else
  300. {
  301. Timers.inst.Remove(CheckGuide);
  302. }
  303. }
  304. protected override void UpdateToCheckGuide(object param)
  305. {
  306. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  307. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.BUY_CLOTHING, 6, "回到换装。", -1, true, 140);
  308. }
  309. }
  310. }