GalleryShopView.cs 15 KB

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