Gold.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName, { EventLabel, PopType } from "../EventName/EventName";
  8. import { Global } from "../Global";
  9. import LocalData from "../LocalData";
  10. import SDKManager from "../SDKManager";
  11. import MyComponent, { ButtonLock } from "../Template/MyComponent";
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class Gold extends MyComponent {
  15. Label: cc.Label = null
  16. onLoad(): void {
  17. this.regEvent(EventName.changeGold, this.UpdataGold, this)
  18. }
  19. start() {
  20. let add = this.node.getChildByName("add")
  21. this.Label = this.node.getChildByName("Label").getComponent(cc.Label)
  22. switch (cc.director.getScene().name) {
  23. case 'Game':
  24. add.active = false
  25. break;
  26. case 'Hall':
  27. add.active = true
  28. break;
  29. default:
  30. break;
  31. }
  32. this.Label.string = LocalData.getInstance().getGold().toString()
  33. }
  34. UpdataGold() {
  35. this.Label.string = LocalData.getInstance().getGold().toString()
  36. }
  37. @ButtonLock(1, null)
  38. ClickGold() {
  39. let temp: PopType = new PopType()
  40. temp.string = EventLabel.OpenVideo
  41. temp.Title = '提示'
  42. temp.OK = () => {
  43. let OPenVideo: PopType = new PopType()
  44. OPenVideo.OK = () => {
  45. LocalData.getInstance().setGold(Global.adReward, '+')
  46. }
  47. SDKManager.instance.OPenVideo(OPenVideo)
  48. }
  49. temp.Fail = () => {
  50. }
  51. this.Pop(temp)
  52. }
  53. // update (dt) {}
  54. }