UI.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { _decorator, Component, director, Label, Node } from 'cc';
  2. import { EventManager } from '../EventManager';
  3. import HTTPS, { NetPost } from '../MyFrame/HTTPS';
  4. import { SDKManager } from '../MyFrame/SDK/SDKManager';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('UI')
  7. export class UI extends Component {
  8. @property(Node)
  9. FuhuoNode: Node = null;
  10. @property(Node)
  11. RestartNode: Node = null;
  12. @property(Node)
  13. HomeNode: Node = null;
  14. @property(Label)
  15. ScoreNode: Label = null;
  16. protected onLoad(): void {
  17. EventManager.instance.et.on(EventManager.EventType.OpenUIPnael, this.OpenUIPnael, this);
  18. }
  19. OpenUIPnael() {
  20. HTTPS.Instance.post(NetPost.UpdateScore,
  21. {
  22. score: this.ScoreNode.string,
  23. }).then((resp) => {
  24. console.error('更新分数成功');
  25. console.error(resp);
  26. })
  27. this.init()
  28. }
  29. init() {
  30. this.node.children.forEach((item: Node) => {
  31. item.active = true;
  32. })
  33. this.FuhuoNode.active = true;
  34. this.RestartNode.active = false;
  35. this.HomeNode.active = false;
  36. this.FuhuoNode.getComponentInChildren(Label).string = '3'
  37. this.schedule(() => {
  38. this.FuhuoNode.getComponentInChildren(Label).string = (parseInt(this.FuhuoNode.getComponentInChildren(Label).string) - 1) + ''
  39. }, 1, 3, 0)
  40. this.scheduleOnce(() => {
  41. this.FuhuoNode.active = false;
  42. this.RestartNode.active = true;
  43. this.HomeNode.active = true;
  44. }, 3)
  45. }
  46. Restart() {
  47. director.loadScene('Game', (err) => {
  48. if (err) {
  49. console.error(err);
  50. return;
  51. }
  52. console.log('加载场景成功');
  53. })
  54. this.close()
  55. }
  56. Home() {
  57. director.loadScene('loading', (err) => {
  58. if (err) {
  59. console.error(err);
  60. return;
  61. }
  62. console.log('加载场景成功');
  63. })
  64. this.close()
  65. }
  66. FuHuo() {
  67. SDKManager.getInstance().show_video((data) => {
  68. if (data == true) {
  69. EventManager.instance.et.emit(EventManager.EventType.Add_haert, 3);
  70. EventManager.instance.et.emit(EventManager.EventType.Set_Add_Score_BOOL, true);
  71. EventManager.instance.et.emit(EventManager.EventType.Reset_Role);
  72. this.close()
  73. } else {
  74. }
  75. })
  76. }
  77. close() {
  78. this.unscheduleAllCallbacks()
  79. this.node.children.forEach((item: Node) => {
  80. item.active = false;
  81. })
  82. }
  83. }