Menu.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { _decorator, Button, Component,director,find,game,Mask,Node,Prefab,Sprite, SpriteFrame } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('Menu')
  4. export class Menu extends Component {
  5. //加速Buton
  6. @property(Button)
  7. btnSpeed:Button = null;
  8. @property(SpriteFrame)
  9. imgSpeed_1:SpriteFrame = null;
  10. @property(SpriteFrame)
  11. imgSpeed_2:SpriteFrame = null;
  12. //暂停Button
  13. @property(Button)
  14. btnPause:Button = null;
  15. @property(SpriteFrame)
  16. imgPause_1:SpriteFrame = null;
  17. @property(SpriteFrame)
  18. imgPause_2:SpriteFrame = null;
  19. @property(SpriteFrame)
  20. imgMenuCenter_1:SpriteFrame = null;//第几波怪物
  21. @property(SpriteFrame)
  22. imgMenuCenter_2:SpriteFrame = null;//暂停中
  23. //弹出框
  24. //@property(Node)
  25. dialog:Node = null;
  26. isAccelerate:boolean = false;//是否加速
  27. currentState:boolean = null;//当前状态
  28. isPause:boolean = false;//是否暂停
  29. currentPauseState:boolean = null;//当前状态
  30. start(){
  31. this.dialog = this.node.getChildByName("Dialog");
  32. this.dialog.active = false;
  33. // let btnQuit = this.dialog.getChildByName("BtnQuit");
  34. // btnQuit.on(Button.EventType.CLICK,this.onBtnQuitDialog,this)
  35. // let btnSelect = this.dialog.getChildByName("BtnSelect");
  36. // btnSelect.on(Button.EventType.CLICK,this.onBtnSelectDialog,this);
  37. // let btnRestart = this.dialog.getChildByName("BtnRestart");
  38. // btnRestart.on(Button.EventType.CLICK,this.onBtnRestartDialog,this);
  39. // let btnResume = this.dialog.getChildByName("BtnResume");
  40. // btnResume.on(Button.EventType.CLICK,this.onBtnQuitDialog,this);
  41. const buttonConfigs = [
  42. {name : "BtnResume",handler : this.onBtnQuitDialog},
  43. {name : "BtnRestart",handler : this.onBtnRestartDialog},
  44. {name : "BtnSelect",handler : this.onBtnSelectDialog},
  45. {name : "BtnQuit",handler : this.onBtnQuitDialog}
  46. ]
  47. buttonConfigs.forEach(config =>{
  48. let button = this.dialog.getChildByName(config.name);
  49. button.on(Button.EventType.CLICK,config.handler,this);
  50. });
  51. this.currentState = this.isAccelerate; //当前状态没有加速
  52. this.btnSpeed.getComponent(Sprite).spriteFrame = this.imgSpeed_1;
  53. this.currentPauseState = this.isPause;
  54. this.btnPause.getComponent(Sprite).spriteFrame = this.imgPause_1;
  55. this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite).spriteFrame = this.imgMenuCenter_1;
  56. }
  57. //加速
  58. onBtnSpeed(){
  59. let btnSpeedComponent = this.btnSpeed.getComponent(Sprite);
  60. this.isAccelerate = !this.isAccelerate;//加速
  61. this.currentState = this.isAccelerate;//当前状态为加速
  62. if(!this.isAccelerate){
  63. btnSpeedComponent.spriteFrame = this.imgSpeed_1;
  64. }else{
  65. btnSpeedComponent.spriteFrame = this.imgSpeed_2;
  66. }
  67. }
  68. //暂停游戏
  69. onBtnPause(){
  70. let menuCenterComponent = this.node.getChildByName("MenuCenter_01_CN").getComponent(Sprite);
  71. let btnPauseComponent = this.btnPause.getComponent(Sprite);
  72. this.isPause = !this.isPause;//暂停
  73. this.currentPauseState = this.isPause;//当前状态为暂停
  74. if(!this.isPause){
  75. menuCenterComponent.spriteFrame = this.imgMenuCenter_1;
  76. btnPauseComponent.spriteFrame = this.imgPause_1;
  77. }else{
  78. menuCenterComponent.spriteFrame = this.imgMenuCenter_2;
  79. btnPauseComponent.spriteFrame = this.imgPause_2;
  80. }
  81. }
  82. //弹出dialog
  83. onBtnMore(){
  84. console.log("More")
  85. director.pause();
  86. this.dialog.active = true;
  87. }
  88. //退出 恢复暂停
  89. onBtnQuitDialog(){
  90. console.log("quitDialog");
  91. if(director.isPaused()){
  92. director.resume();
  93. return;
  94. }
  95. this.dialog.active = false;
  96. }
  97. //重新选择关卡
  98. onBtnSelectDialog(){
  99. director.loadScene("SelectLevel");
  100. console.log("SelectLevel");
  101. }
  102. //重新开始游戏
  103. onBtnRestartDialog(){
  104. console.log("Restart");
  105. }
  106. update(deltaTime: number) {
  107. }
  108. }