menuList.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import { _decorator, Component, Node, Color, Label, Button, director, Director, SpriteFrame, Sprite } from 'cc';
  2. import { ClientEvent } from '../clientEvent';
  3. import { Constant } from '../constant';
  4. import { GameMng } from '../GameMng';
  5. import AudioMng from '../gcommon/AudioMng';
  6. import ScenceMng from '../gcommon/ScenceMng';
  7. import { UIButton } from '../gcommon/UIButton';
  8. import { UIManager } from '../gcommon/UIManager';
  9. import { msgManager } from '../socket/msgManager';
  10. import GBoardChess from './ChessGame/GBoardChess';
  11. import UIDialog from './UIDialog';
  12. import { waitView } from './waitView';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('menuList')
  15. export class menuList extends Component {
  16. @property(Node)
  17. btn_quit: Node = null; //离开
  18. @property(Node)
  19. spr_renshu: Node = null;//认输
  20. @property(SpriteFrame)
  21. sp_renshu_1: SpriteFrame = null;//认输
  22. @property(SpriteFrame)
  23. sp_renshu_0: SpriteFrame = null;//认输
  24. @property(Node)
  25. spr_qiuhe: Node = null;//求和
  26. @property(SpriteFrame)
  27. sp_qiuhe_1: SpriteFrame = null;//求和
  28. @property(SpriteFrame)
  29. sp_qiuhe_0: SpriteFrame = null;//求和
  30. @property(Node)
  31. spr_huiqi: Node = null;//悔棋
  32. @property(SpriteFrame)
  33. sp_huiqi_0: SpriteFrame = null;//悔棋
  34. @property(SpriteFrame)
  35. sp_huiqi_1: SpriteFrame = null;//悔棋
  36. @property(Node)
  37. btn_renshu: Node = null;//认输
  38. @property(Node)
  39. btn_qiuhe: Node = null;//求和
  40. @property(Node)
  41. btn_huiqi: Node = null;//悔棋
  42. @property(Node)
  43. lab_qiuhe: Node = null;//求和
  44. @property(Node)
  45. lab_huiqi: Node = null;//悔棋
  46. @property(Node)
  47. lab_renshu: Node = null;//认输
  48. @property(Node)
  49. btn_shezhi: Node = null;//设置
  50. color:Color = new Color()
  51. start() {
  52. UIButton.BindClick(this.btn_quit,function(){
  53. this.onClickQuit();
  54. UIDialog.Show(()=>{
  55. msgManager.quitRoom()
  56. },()=>{
  57. },"是否确定退出",GBoardChess.instance.uiLayer,true)
  58. },this)
  59. UIButton.BindClick(this.btn_renshu,function(){
  60. this.onClickQuit();
  61. UIDialog.Show(()=>{
  62. msgManager.renshu_game()
  63. },()=>{
  64. },"是否认输",GBoardChess.instance.uiLayer,true)
  65. },this)
  66. UIButton.BindClick(this.btn_qiuhe,function(){
  67. this.onClickQuit();
  68. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HEQI)
  69. },this)
  70. UIButton.BindClick(this.btn_shezhi,function(){
  71. this.onClickQuit();
  72. UIManager.AddPrefab(GameMng.Instance.uiChessSettingView)
  73. },this)
  74. UIButton.BindClick(this.btn_huiqi,function(){
  75. this.onClickQuit();
  76. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HUIQI)
  77. },this)
  78. this.updateBtnsStatus()
  79. ClientEvent.on(Constant.UI_EVENT.UI_MSG_UPDATE_MENU_STATUS,this.updateBtnsStatus,this)
  80. }
  81. onDestroy(){
  82. ClientEvent.off(Constant.UI_EVENT.UI_MSG_UPDATE_MENU_STATUS,this.updateBtnsStatus,this)
  83. }
  84. onEnable(){
  85. director.once(Director.EVENT_AFTER_DRAW,function(){
  86. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_UPDATE_MENU_STATUS)
  87. })
  88. }
  89. updateBtnsStatus(){
  90. // var x = (GameMng._userData.room.huiqi_number-GBoardChess.instance.huiqi_number);
  91. // var y = (GameMng._userData.room.heqi_number-GBoardChess.instance.heqi_number);
  92. this.lab_huiqi.getComponent(Label).string = "悔棋("+ GBoardChess.instance.huiqi_number+")"
  93. this.lab_qiuhe.getComponent(Label).string = "和棋("+GBoardChess.instance.heqi_number+")"
  94. var hui_se = this.color.fromHEX("#949494")
  95. this.lab_huiqi.getComponent(Label).color = hui_se
  96. this.lab_qiuhe.getComponent(Label).color = hui_se
  97. this.lab_renshu.getComponent(Label).color = hui_se
  98. this.btn_huiqi.getComponent(Button).enabled = false;
  99. this.btn_qiuhe.getComponent(Button).enabled = false;
  100. this.btn_renshu.getComponent(Button).enabled = false;
  101. this.spr_renshu.getComponent(Sprite).spriteFrame = this.sp_renshu_0
  102. this.spr_qiuhe.getComponent(Sprite).spriteFrame = this.sp_qiuhe_0
  103. this.spr_huiqi.getComponent(Sprite).spriteFrame = this.sp_huiqi_0
  104. console.log("当前是游戏已开",GBoardChess.instance.rund_number)
  105. console.log("悔棋剩余",GBoardChess.instance.huiqi_number)
  106. console.log("和棋剩余",GBoardChess.instance.heqi_number)
  107. if(!GBoardChess.instance.isStartGame){
  108. }else{
  109. if(GBoardChess.instance.rund_number>=3){
  110. this.color = this.color.fromHEX("#5F3D36")
  111. if(GBoardChess.instance.rund_number>=10){
  112. this.btn_renshu.getComponent(Button).enabled = true;
  113. this.lab_renshu.getComponent(Label).color = this.color
  114. this.spr_renshu.getComponent(Sprite).spriteFrame = this.sp_renshu_1
  115. }
  116. if(GBoardChess.instance.who_round===1){ //自己回合
  117. console.log("当前是自己回合")
  118. }else{
  119. console.log("当前是对手回合")
  120. if(!GBoardChess.instance.isStartGame){
  121. }else{
  122. if(GBoardChess.instance.huiqi_number>0&&GBoardChess.instance.huiqi_setup!=GBoardChess.instance.rund_number){
  123. this.btn_huiqi.getComponent(Button).enabled = true;
  124. this.lab_huiqi.getComponent(Label).color = this.color;
  125. this.spr_huiqi.getComponent(Sprite).spriteFrame = this.sp_huiqi_1
  126. }
  127. if(GBoardChess.instance.rund_number>=10){
  128. if(GBoardChess.instance.heqi_number>0){
  129. this.btn_qiuhe.getComponent(Button).enabled = true;
  130. this.lab_qiuhe.getComponent(Label).color = this.color;
  131. this.spr_qiuhe.getComponent(Sprite).spriteFrame = this.sp_qiuhe_1
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. // recvQuit(){
  140. // GameMng._userData.room = null;
  141. // AudioMng.Instance.PlayBGM(GameMng.Instance.mainbgm);
  142. // ScenceMng.Instance.load('GameLaunch');
  143. // }
  144. update(deltaTime: number) {
  145. }
  146. onClickQuit(){
  147. this.node.active = false;
  148. }
  149. }