UI.ts 2.4 KB

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