shop.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import LayerPanel, {UrlInfo} from "../../../../Common/manage/Layer/LayerPanel";
  2. import Tools from "../../../../Common/Tools";
  3. import gameConfig from "../common/config";
  4. import CacheMgr from "../../../../Common/manage/CacheMgr";
  5. import PanelMgr from "../../../../Common/manage/PanelMgr";
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class Shop extends LayerPanel {
  9. private hammer_btn: cc.Node = null
  10. private sprite_btn: cc.Node = null
  11. private stamina_btn: cc.Node = null
  12. private close_btn: cc.Node = null
  13. public static getUrl(): UrlInfo {
  14. return {
  15. bundle: "game",
  16. name: "shop"
  17. }
  18. }
  19. initUI() {
  20. this.hammer_btn = this.getNode("content/hammer/btn")
  21. this.onTouch(this.hammer_btn, () => {
  22. Tools.changeGold(-gameConfig.price_hammer, () => {
  23. CacheMgr.setting.hammerNum++
  24. CacheMgr.setting = CacheMgr.setting
  25. })
  26. })
  27. this.change_price(this.hammer_btn, gameConfig.price_hammer)
  28. this.sprite_btn = this.getNode("content/sprite/btn")
  29. this.onTouch(this.sprite_btn, () => {
  30. Tools.changeGold(-gameConfig.price_sprite, () => {
  31. CacheMgr.setting.spriteNum++
  32. CacheMgr.setting = CacheMgr.setting
  33. })
  34. })
  35. this.change_price(this.sprite_btn, gameConfig.price_sprite)
  36. this.stamina_btn = this.getNode("content/stamina/btn")
  37. this.onTouch(this.stamina_btn, () => {
  38. Tools.changeGold(-gameConfig.price_stamina, () => {
  39. CacheMgr.stamina = CacheMgr.stamina + 1
  40. })
  41. })
  42. this.change_price(this.stamina_btn, gameConfig.price_stamina)
  43. this.close_btn = this.getNode("btn")
  44. this.onTouch(this.close_btn, () => {
  45. PanelMgr.INS.closePanel(Shop) ;
  46. })
  47. }
  48. change_price(node: cc.Node, num: number) {
  49. let label = node.getChildByName("num").getComponent(cc.Label)
  50. label.string = num.toString()
  51. }
  52. show(param: any): void {
  53. }
  54. hide() {
  55. }
  56. }