GalleryShopView.cs 15 KB

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