GalleryShopView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. _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. List<ShopCfg> dataArray = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY);
  96. for (int i = 0; i < dataArray.Count; i++)
  97. {
  98. if (dataArray[i].itemId == _selectedItemId)
  99. {
  100. _selectedType = int.Parse(dataArray[i].typeIndex);
  101. _selectedId = 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. ShopViewManager.Instance.BuyItem(_cfgSelected.id, _selectedItemCount, _storeId, _cfgSelected);
  115. }
  116. }
  117. protected override void OnHide()
  118. {
  119. base.OnHide();
  120. _valueBarController.OnHide();
  121. _selectedItemId = 0;
  122. }
  123. protected override void RemoveEventListener()
  124. {
  125. base.RemoveEventListener();
  126. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateSelectedItemInfo);
  127. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateItemChange);
  128. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateItemChange);
  129. }
  130. private void OnClickBtnBack()
  131. {
  132. ViewManager.GoBackFrom(typeof(GalleryShopView).FullName);
  133. }
  134. private void OnclickBtnBuy()
  135. {
  136. int count = _selectedItemId > 0 && _cfgSelected.itemId == _selectedItemId ? _selectedItemCount : INIT_COUNT;
  137. // BuyItemConteoller.Show(_cfgSelected.itemID, _cfgSelected.costID, INIT_COUNT, _cfgSelected.costNum, count, null, true, false, MAX_COUNT);
  138. count = Math.Max(1, count);
  139. ShopViewManager.Instance.BuyItem(_cfgSelected.id, count, _storeId, _cfgSelected);
  140. }
  141. private void UpdateItemChange()
  142. {
  143. UpdateList(false);
  144. }
  145. private void UpdateList(bool tween)
  146. {
  147. int typeIndex = _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex;
  148. _dataList = ShopDataManager.Instance.GetList(_storeId, typeIndex, _scoreType);
  149. _ui.m_comItemList.m_list.numItems = _dataList.Count;
  150. if (_ui.m_comItemList.m_list.numItems > 0)
  151. {
  152. ShopCfg clothingShopCfg = ShopCfgArray.Instance.GetCfg(_selectedId);
  153. int itemIndex = 0;
  154. if (_selectedItemId > 0 && clothingShopCfg != null)
  155. {
  156. for (int i = 0; i < _dataList.Count; i++)
  157. {
  158. if (_dataList[i].id == _selectedId)
  159. {
  160. itemIndex = i;
  161. break;
  162. }
  163. }
  164. _ui.m_comItemList.m_list.ScrollToView(itemIndex < 0 ? 0 : itemIndex);
  165. _ui.m_comItemList.m_list.selectedIndex = itemIndex;
  166. }
  167. UpdateSelectedItemInfo(_ui.m_comItemList.m_list.GetChildAt(itemIndex) as GComponent, tween);
  168. }
  169. }
  170. private void OnClickListTypeItem(EventContext context)
  171. {
  172. UpdateList(true);
  173. }
  174. private void ListShopItemRender(int index, GObject item)
  175. {
  176. UI_ListGalleryShopItem listItem = UI_ListGalleryShopItem.Proxy(item);
  177. ShopCfg cfg = _dataList[index];
  178. listItem.target.data = cfg;
  179. // listItem.m_grpSelect.visible = false;
  180. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.itemId);
  181. listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  182. string itemName = itemCfg.name;
  183. listItem.m_txtName.text = itemName;
  184. // RarityIconController.UpdateRarityIcon(listItem.m_rarity, cfg.itemID, false);
  185. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(cfg.costId);
  186. listItem.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
  187. listItem.m_imgOwned.visible = ItemDataManager.GetItemNum(cfg.itemId) > 0;
  188. // listItem.m_txtPrice.text = ItemDataManager.GetItemNum(cfg.costID) >= cfg.costNum ? StringUtil.GetColorText(cfg.costNum.ToString(), "#DD994A") : StringUtil.GetColorText(cfg.costNum.ToString(), "#F2989B");
  189. listItem.m_txtPrice.text = cfg.price.ToString();
  190. UI_ListGalleryShopItem.ProxyEnd();
  191. }
  192. private void OnClickListShopItem(EventContext context)
  193. {
  194. _selectedItemId = 0;
  195. UpdateSelectedItemInfo(context.data as GComponent, true);
  196. }
  197. private void UpdateSelectedItemInfo(GComponent listItem, bool tween)
  198. {
  199. if (_selectedListItem != null) _selectedListItem.selected = false;
  200. _selectedListItem = listItem.asButton;
  201. _selectedListItem.selected = true;
  202. ShopCfg cfg = listItem.data as ShopCfg;
  203. _cfgSelected = cfg;
  204. UpdateRole(tween);
  205. UpdateSelectedItemInfo();
  206. }
  207. private void UpdateRole(bool tween)
  208. {
  209. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemId);
  210. string ext = ItemUtil.GetItemResExt(itemCfg.itemType, itemCfg.subType);
  211. _ui.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); ;
  212. // _ui.m_comRes.m_loaBg.visible = false;
  213. // _ui.m_comRes.m_c1.selectedIndex = _ui.m_comItemList.m_comBtnTab.m_c1.selectedIndex;
  214. // switch (_ui.m_comRes.m_c1.selectedIndex)
  215. // {
  216. // case GalleryShopTabType.BG:
  217. // // _ui.m_comRes.m_loaBg.url = ResPathUtil.GetDressUpPath(itemCfg.res, ext);
  218. // _ui.m_comRes.m_loaBg.url = ResPathUtil.GetIconPath(itemCfg); ;
  219. // // _ui.m_loaBgRes.visible = true;
  220. // _ui.m_comRes.m_loaBg.visible = true;
  221. // break;
  222. // case GalleryShopTabType.NPC:
  223. // // _ui.m_comRes.m_loaNpc.url = ResPathUtil.GetNpcPicFPath(itemCfg.res);
  224. // _ui.m_comRes.m_loaNpc.url = ResPathUtil.GetIconPath(itemCfg); ;
  225. // break;
  226. // case GalleryShopTabType.ITEM:
  227. // ItemTypeCfg typeCfg = ItemTypeCfgArray.Instance.GetCfg(itemCfg.subType);
  228. // int sortingOrder = typeCfg.defaultLayer;
  229. // string res = itemCfg.res;
  230. // // _ui.m_comRes.m_comItem.m_loaItem0.visible = false;
  231. // // _ui.m_comRes.m_comItem.m_loaItem1.visible = false;
  232. // // _ui.m_comRes.m_comItem.m_loaItem2.visible = false;
  233. // // _ui.m_comRes.m_comItem.m_loaItem0.url = ResPathUtil.GetIconPath(itemCfg); ;
  234. // // if (!string.IsNullOrEmpty(itemCfg.resLayer1))
  235. // // {
  236. // // res = itemCfg.resLayer1 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer1);
  237. // // string resPath = ResPathUtil.GetDressUpPath(res, ext);
  238. // // // Texture2D texture2D = GFGAsset.Load<Texture2D>(resPath);
  239. // // // _ui.m_comRes.m_loaItem0.texture = new NTexture(texture2D); ;
  240. // // _ui.m_comRes.m_comItem.m_loaItem0.url = resPath;
  241. // // float tx, ty;
  242. // // DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
  243. // // _ui.m_comRes.m_comItem.m_loaItem0.SetXY(tx, ty);
  244. // // _ui.m_comRes.m_comItem.m_loaItem0.visible = true;
  245. // // _ui.m_comRes.m_comItem.m_loaItem0.sortingOrder = sortingOrder;
  246. // // }
  247. // // if (!string.IsNullOrEmpty(itemCfg.resLayer2))
  248. // // {
  249. // // sortingOrder = typeCfg.specialLayer;
  250. // // res = itemCfg.resLayer2 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer2);
  251. // // string resPath = ResPathUtil.GetDressUpPath(res, ext);
  252. // // // Texture2D texture2D = GFGAsset.Load<Texture2D>(resPath);
  253. // // // _ui.m_comRes.m_loaItem1.texture = new NTexture(texture2D); ;
  254. // // _ui.m_comRes.m_comItem.m_loaItem1.url = resPath;
  255. // // float tx, ty;
  256. // // DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
  257. // // _ui.m_comRes.m_comItem.m_loaItem1.SetXY(tx, ty);
  258. // // _ui.m_comRes.m_comItem.m_loaItem1.visible = true;
  259. // // _ui.m_comRes.m_comItem.m_loaItem1.sortingOrder = sortingOrder;
  260. // // }
  261. // // if (!string.IsNullOrEmpty(itemCfg.resLayer3))
  262. // // {
  263. // // sortingOrder = typeCfg.thirdlLayer;
  264. // // res = itemCfg.resLayer3 == "n" ? res : string.Format("{0}_{1}", res, itemCfg.resLayer3);
  265. // // string resPath = ResPathUtil.GetDressUpPath(res, ext);
  266. // // // Texture2D texture2D = GFGAsset.Load<Texture2D>(res);
  267. // // // _ui.m_comRes.m_loaItem2.texture = new NTexture(texture2D);
  268. // // _ui.m_comRes.m_comItem.m_loaItem2.url = resPath;
  269. // // float tx, ty;
  270. // // DressUpUtil.LoadSpritePos(resPath, out tx, out ty);
  271. // // _ui.m_comRes.m_comItem.m_loaItem2.SetXY(tx, ty);
  272. // // _ui.m_comRes.m_comItem.m_loaItem2.visible = true;
  273. // // _ui.m_comRes.m_comItem.m_loaItem2.sortingOrder = sortingOrder;
  274. // // }
  275. // // _ui.m_comRes.m_comItem.target.SetSize(_ui.m_comRes.m_comItem.m_grpItem.width, _ui.m_comRes.m_comItem.m_grpItem.height);
  276. // break;
  277. // case GalleryShopTabType.BORDER:
  278. // // _ui.m_comRes.m_loaBorder.url = ResPathUtil.GetPhotographBorderPath(itemCfg.res);
  279. // _ui.m_comRes.m_loaBorder.url = ResPathUtil.GetIconPath(itemCfg); ;
  280. // break;
  281. // case GalleryShopTabType.EFFECT:
  282. // break;
  283. // }
  284. }
  285. private void UpdateSelectedItemInfo()
  286. {
  287. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_cfgSelected.itemId);
  288. _ui.m_txtName.text = itemCfg.name;
  289. _ui.m_txtDesc.text = itemCfg.desc;
  290. }
  291. }
  292. }