PageShop.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import { CommonTabsTitle, OnTabClickListener } from "../common/CommonTabsTitle";
  4. import { Tips } from "../../scripts/mgr/Tips";
  5. import { ScrollView } from "cc";
  6. import { instantiate } from "cc";
  7. import { GamePassItem } from "../item/GamePassItem";
  8. import PogHttp from "../../scripts/net/PogHttp";
  9. import { PogBoosterItem } from "../item/PogBoosterItem";
  10. import ShopM from "../../scripts/api/ShopM";
  11. import UserM from "../../scripts/api/UserM";
  12. import { GoodsId } from "../../scripts/api/GoodsId";
  13. import ConfigM, { ClientConfig } from "../../scripts/api/ConfigM";
  14. import { Sprite } from "cc";
  15. import { Event } from "cc";
  16. import { FlyContainer, FlyType } from "./FlyContainer";
  17. import { RewardLayer } from "../layer/RewardLayer";
  18. import ItemsM from "../../scripts/mgr/ItemsM";
  19. import EV, { EV_TYPE } from "../../scripts/mgr/EV";
  20. const { ccclass, property } = _decorator;
  21. @ccclass("PageShop")
  22. export class PageShop extends BaseUI implements OnTabClickListener {
  23. switchTab(tab: { index: number; name: string; }) {
  24. this.onTabClick(tab.index);
  25. }
  26. protected onLoad(): void {
  27. super.onLoad();
  28. this.init();
  29. }
  30. static readonly TAB_GAME_PASS = {
  31. index: 0,
  32. name: "ScrollViewGamePass",
  33. };
  34. static readonly TAB_POG_BOOSTER = {
  35. index: 1,
  36. name: "ScrollViewPogBooster",
  37. };
  38. static readonly TAB_ITEM_BOX = {
  39. index: 2,
  40. name: "ScrollViewItemBox",
  41. };
  42. static readonly TAB_POG_BOX = { index: 3, name: "ScrollViewPogBox" };
  43. private _tabsTitle: CommonTabsTitle = null;
  44. init() {
  45. this._tabsTitle = this.getComponentInChildren(CommonTabsTitle);
  46. let titles = ["GAME PASS", "POG CRIT", "ITEM BOX", "POG BOX"];
  47. this._tabsTitle.init(titles, this);
  48. this.onTabClick(PageShop.TAB_GAME_PASS.index);
  49. this.FindNode("GamePassItem").active = false;
  50. this.FindNode("PogBoosterItem").active = false;
  51. }
  52. onTabClick(index: number) {
  53. this.FindNode("ShopPageContainer").children.forEach((child) => {
  54. child.active = false;
  55. });
  56. switch (index) {
  57. case PageShop.TAB_GAME_PASS.index:
  58. this.showGamePass();
  59. break;
  60. case PageShop.TAB_POG_BOOSTER.index:
  61. this.showPogBooster(2);
  62. break;
  63. case PageShop.TAB_ITEM_BOX.index:
  64. // this.FindNode(PageShop.TAB_ITEM_BOX.name).active = true;
  65. this.showPogBooster(3);
  66. break;
  67. case PageShop.TAB_POG_BOX.index:
  68. // this.FindNode(PageShop.TAB_POG_BOX.name).active = true;
  69. this.showPogBooster(4);
  70. break;
  71. }
  72. }
  73. private showHelp(type: number) {
  74. this.FindNode("HelpLayout").children.forEach((child) => {
  75. child.active = false;
  76. });
  77. this.FindNode("HelpLayout").children[type - 2].active = true;
  78. }
  79. async showPogBooster(type: number) {
  80. this.showHelp(type);
  81. // let helpTitle = ConfigM.ins.getHelpTitle(type);
  82. // this.setText("lbl_help_title", helpTitle);
  83. let helpDesc = ConfigM.ins.getHelpDesc(type);
  84. this.setText("lbl_help_desc", helpDesc);
  85. this.FindNode(PageShop.TAB_POG_BOOSTER.name).active = true;
  86. let scrollView = this.FindNode(PageShop.TAB_POG_BOOSTER.name).getComponent(
  87. ScrollView
  88. );
  89. scrollView.node.active = true;
  90. let grid = scrollView.content.getChildByName("grid");
  91. grid.removeAllChildren();
  92. let tpl = this.FindNode("PogBoosterItem");
  93. let list = await ShopM.ins.getShopListByStoreId(type);
  94. for (let item of list) {
  95. let itemNode = instantiate(tpl);
  96. itemNode.active = true;
  97. grid.addChild(itemNode);
  98. itemNode.getComponent(PogBoosterItem).init(type, item);
  99. }
  100. }
  101. async initGamePassShard() {
  102. let puzzle_count = UserM.ins.getGoodsCount(GoodsId.GAME_PASS_SHARD);
  103. this.setText(
  104. "lbl_game_pass_puzzle",
  105. "" + puzzle_count + "/" + ClientConfig.PuzzleToGamePassCount
  106. );
  107. if (puzzle_count < ClientConfig.PuzzleToGamePassCount) {
  108. let node = this.FindNode("btn_puzzle_to_claim_game_pass");
  109. node.getComponent(Sprite).grayscale = true;
  110. }
  111. }
  112. async showGamePass() {
  113. this.initGamePassShard();
  114. let scrollView = this.FindNode(PageShop.TAB_GAME_PASS.name).getComponent(
  115. ScrollView
  116. );
  117. scrollView.node.active = true;
  118. // if (scrollView.content.children.length > 0) {
  119. // return;
  120. // }
  121. scrollView.content.removeAllChildren();
  122. let gamePassItem = this.FindNode("GamePassItem");
  123. let list = await ShopM.ins.getShopListByStoreId(1);
  124. for (let i = 0; i < list.length; i++) {
  125. let item = instantiate(gamePassItem);
  126. item.active = true;
  127. scrollView.content.addChild(item);
  128. let c= ConfigM.ins.getShopListByStoreId(1)[i];
  129. item.getComponent(GamePassItem).init(list[i],c)
  130. }
  131. }
  132. async PuzzleToGamePass() {
  133. // Tips.show("Coming soon");
  134. // FlyContainer.ins.fly(FlyType.POG);
  135. let count = UserM.ins.getGoodsCount(GoodsId.GAME_PASS_SHARD);
  136. if (count < ClientConfig.PuzzleToGamePassCount) {
  137. Tips.show("Insufficient Game Shards");
  138. return;
  139. }
  140. UserM.ins.subtractGoods(
  141. GoodsId.GAME_PASS_SHARD,
  142. ClientConfig.PuzzleToGamePassCount
  143. );
  144. let result = await ShopM.ins.shardToGamePass();
  145. if (result) {
  146. RewardLayer.show([
  147. {
  148. id: GoodsId.GAME_PASS,
  149. count: 1,
  150. },
  151. ]);
  152. await UserM.ins.refreshInfo();
  153. }
  154. this.initGamePassShard();
  155. }
  156. protected simpleOnBtnClick(name: string): void {
  157. switch (name) {
  158. case "btn_puzzle_to_claim_game_pass":
  159. this.PuzzleToGamePass();
  160. break;
  161. }
  162. }
  163. }