Gold.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. @property(cc.Label)
  16. Label: cc.Label
  17. onLoad(): void {
  18. if (!this.Label) {
  19. this.Label = this.node.getComponentInChildren(cc.Label)
  20. }
  21. }
  22. start() {
  23. this.regEvent(EventName.changeGold, this.UpdataGold, this)
  24. this.scheduleOnce(() => {
  25. cc.systemEvent.emit(EventName.changeGold);
  26. }, 0)
  27. }
  28. UpdataGold() {
  29. if (this?.Label) {
  30. this.Label.string = LocalData.getInstance().getGold().toString()
  31. }
  32. }
  33. @ButtonLock(1, null)
  34. ClickGold() {
  35. let temp: PopType = new PopType()
  36. temp.string = EventLabel.OpenVideo
  37. temp.Title = '提示'
  38. temp.OK = () => {
  39. let OPenVideo: PopType = new PopType()
  40. OPenVideo.OK = () => {
  41. LocalData.getInstance().setGold(Global.adReward, '+')
  42. }
  43. SDKManager.instance.OPenVideo(OPenVideo)
  44. }
  45. temp.Fail = () => {
  46. }
  47. this.Pop(temp)
  48. }
  49. // update (dt) {}
  50. }