gameQuit.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import Button from '../game/Button';
  2. import EventMgr from '../game/EventMgr';
  3. import { GameEvent } from '../game/GameEvent';
  4. import { SDK as sdk, CMD} from '../game/sdk';
  5. import { SDKIpt } from '../game/SDKIpt';
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class gameRank extends cc.Component {
  9. @property(cc.Node)
  10. private mainView:cc.Node = null
  11. @property(cc.Button)
  12. btnQuitCancel: cc.Button = null;
  13. @property(cc.Button)
  14. btnQuitConfirn: cc.Button = null;
  15. private get isActive(): boolean { return this.node.active; }
  16. private index:number = 1
  17. start () {
  18. this.btnQuitCancel.node.on("click",this.quit,this);
  19. this.btnQuitConfirn.node.on("click",this.confirn,this);
  20. EventMgr.Instance.add_event_listenner(GameEvent.SDK_UI_IPT,this,this.ON_SDK_UI_IPT);
  21. }
  22. protected onDestroy(): void {
  23. EventMgr.Instance.remove_event_listenner(GameEvent.SDK_UI_IPT,this,this.ON_SDK_UI_IPT);
  24. }
  25. ON_SDK_UI_IPT(SDK_UI_IPT: GameEvent, ipt: SDKIpt, ON_SDK_UI_IPT: any) {
  26. console.error("mainview 收到 sdk 动作:"+ipt );
  27. if (!this.isActive) { return; }
  28. switch (ipt) {
  29. case SDKIpt.left:
  30. this.index = this.index===1?0:1
  31. this._ButtonActive()
  32. break;
  33. case SDKIpt.right:
  34. this.index = this.index===0?1:0
  35. this._ButtonActive()
  36. break;
  37. case SDKIpt.rightFoot://主界面确认进入游戏//y
  38. if(this.index === 0)
  39. this.quit();
  40. else
  41. this.confirn();
  42. break;
  43. case SDKIpt.leftFoot:
  44. break;
  45. default:
  46. break;
  47. }
  48. }
  49. openDialog(){
  50. this.node.active = true;
  51. this.index = 1
  52. this._ButtonActive()
  53. }
  54. quit(){
  55. this.node.active = false
  56. this.mainView.active = true
  57. }
  58. confirn(){
  59. EventMgr.Instance.dispatch_event(GameEvent.SDK_QUIT);
  60. }
  61. _ButtonActive(){
  62. if(this.index == 0){
  63. this.btnQuitCancel.node.getComponent(Button).selected();
  64. this.btnQuitConfirn.node.getComponent(Button).unselected()
  65. }else{
  66. this.btnQuitCancel.node.getComponent(Button).unselected();
  67. this.btnQuitConfirn.node.getComponent(Button).selected()
  68. }
  69. }
  70. }