shop.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. console.log('zh:shop.js 点击了 hammer_btn')
  23. Tools.changeGold(-gameConfig.price_hammer, () => {
  24. CacheMgr.setting.hammerNum++
  25. CacheMgr.setting = CacheMgr.setting
  26. })
  27. })
  28. this.change_price(this.hammer_btn, gameConfig.price_hammer)
  29. this.sprite_btn = this.getNode("content/sprite/btn")
  30. this.onTouch(this.sprite_btn, () => {
  31. console.log('zh:shop.js 点击了 sprite_btn')
  32. Tools.changeGold(-gameConfig.price_sprite, () => {
  33. CacheMgr.setting.spriteNum++
  34. CacheMgr.setting = CacheMgr.setting
  35. })
  36. })
  37. this.change_price(this.sprite_btn, gameConfig.price_sprite)
  38. this.stamina_btn = this.getNode("content/stamina/btn")
  39. this.onTouch(this.stamina_btn, () => {
  40. console.log('zh:shop.js 点击了 stamina_btn')
  41. Tools.changeGold(-gameConfig.price_stamina, () => {
  42. CacheMgr.stamina = CacheMgr.stamina + 1
  43. })
  44. })
  45. this.change_price(this.stamina_btn, gameConfig.price_stamina)
  46. this.close_btn = this.getNode("btn")
  47. this.onTouch(this.close_btn, () => {
  48. PanelMgr.INS.closePanel(Shop) ;
  49. })
  50. }
  51. change_price(node: cc.Node, num: number) {
  52. let label = node.getChildByName("num").getComponent(cc.Label)
  53. label.string = num.toString()
  54. }
  55. show(param: any): void {
  56. }
  57. hide() {
  58. }
  59. }