ShopMain.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const TagType = {
  2. HOT: 0,
  3. KINIFE: 100, // 匕首
  4. HANDGUN: 200, // 手枪
  5. SHOTGUN: 300, // 散弹枪
  6. RIFLE: 400, // 步枪
  7. PRINTING: 500, // 印花
  8. LSTA: 600, // 轻机枪
  9. GLOVE: 700, // 手套
  10. OTHER: 99999,
  11. };
  12. cc.Class({
  13. extends: cc.Component,
  14. editor: {
  15. menu: 'Shop/ShopMain'
  16. },
  17. properties: {
  18. goldNumText: cc.Label,
  19. shopView: cc.Node,
  20. itemPrefab: cc.Prefab,
  21. hotToggle: cc.Toggle,
  22. },
  23. onLoad() {
  24. this.initData();
  25. this.initUI();
  26. },
  27. initData() {
  28. this.goods = {};
  29. let itemConfig = G.CfgMgr.resItemConfig.table;
  30. for (let config of itemConfig) {
  31. if (!config.inShop) {
  32. continue;
  33. }
  34. let itemname = config.name;
  35. let cost = config.price ? config.price : 0;
  36. let surface = config.surface;
  37. let surfaceConfig = G.CfgMgr.resItemSurfaceConfig.getByMainKey(surface);
  38. let surfaceStr = "";
  39. if (surfaceConfig) {
  40. surfaceStr = surfaceConfig.name;
  41. }
  42. surface = surfaceStr == "" ? 0 : surface;
  43. let quality = config.quality;
  44. let model = config.model;
  45. let itemData = {
  46. name: itemname,
  47. cost: cost,
  48. surface: surface,
  49. surfaceStr: surfaceStr,
  50. quality: quality,
  51. model: model,
  52. itemConfig: config,
  53. cb: this.shopItemOnClicked
  54. }
  55. let tagType = TagType.OTHER;
  56. for (var temp in TagType) {
  57. if (TagType[temp] == config.type) {
  58. tagType = TagType[temp];
  59. break;
  60. }
  61. }
  62. if (!this.goods[tagType]) {
  63. this.goods[tagType] = [];
  64. }
  65. this.goods[tagType].push(itemData);
  66. if (config.hot) {
  67. if (!this.goods[TagType.HOT]) {
  68. this.goods[TagType.HOT] = [];
  69. }
  70. this.goods[TagType.HOT].push(itemData);
  71. }
  72. }
  73. },
  74. initUI() {
  75. let goldNum = G.BagMgr.getItemNumById(JMC.ITEM_ID.GOLD);
  76. this.goldNumText.string = goldNum;
  77. this.hotToggle.isChecked = true;
  78. this.showShopViewByTag(TagType.HOT);
  79. },
  80. showShopViewByTag(tag) {
  81. let list = this.goods[tag];
  82. this.shopView.removeAllChildren();
  83. if (!list || list.length == 0) return;
  84. for (let i = 0; i < list.length; i++) {
  85. let data = list[i];
  86. let itemNode = cc.instantiate(this.itemPrefab);
  87. let shopItemCtr = itemNode.getComponent('ShopItem');
  88. shopItemCtr.reloadData(data);
  89. this.shopView.addChild(itemNode);
  90. }
  91. },
  92. typeChooseToggleOnClicked(toggleData, eventKey) {
  93. this.showShopViewByTag(eventKey);
  94. },
  95. shopItemOnClicked(data) {
  96. G.AppUtils.getSceneCtrl().showAlert(
  97. 'edt_prefab/Shop/ShopItemAlert',
  98. data
  99. );
  100. }
  101. });