UIjiesuan.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { _decorator, Component, Node, SpriteFrame, Sprite, Label, resources, Vec3 } from 'cc';
  2. import { ClientEvent } from '../clientEvent';
  3. import { Constant } from '../constant';
  4. import { GameMng, quit_chess_show_view } from '../GameMng';
  5. import AudioMng from '../gcommon/AudioMng';
  6. import GameData from '../gcommon/GameData';
  7. import GameUtil from '../gcommon/GameUtil';
  8. import { ResMng } from '../gcommon/ResMng';
  9. import ScenceMng from '../gcommon/ScenceMng';
  10. import { UIButton } from '../gcommon/UIButton';
  11. import { msgManager } from '../socket/msgManager';
  12. import { Tools } from '../Tools';
  13. import { roomData } from '../UserData/roomData';
  14. import { settlementData } from '../UserData/settlementData';
  15. import GBoardChess from './ChessGame/GBoardChess';
  16. import { jifen_jiesuan } from './ChessGame/jifen_jiesuan';
  17. import ChessMng, { ChessType } from './DiffSel/ChessMng';
  18. import UIDiffSel from './DiffSel/UIDiffSel';
  19. import { tongqian_jiesuan } from './tongqian_jiesuan';
  20. const { ccclass, property } = _decorator;
  21. @ccclass('UIjiesuan')
  22. export class UIjiesuan extends Component {
  23. @property(Node)
  24. btn_close:Node=null; //
  25. @property(Node)
  26. btn_new:Node=null; //
  27. @property(Node)
  28. btn_again:Node=null;//
  29. @property(Node)
  30. btn_share:Node=null;//
  31. @property(Node)
  32. btn_reinfo:Node=null;//复盘
  33. @property(Node)
  34. lab_des:Node=null;//对盘信息
  35. @property(Node)
  36. sp_isWin:Node=null;//
  37. @property(SpriteFrame)
  38. winSp:SpriteFrame=null;//
  39. @property(SpriteFrame)
  40. loseSp:SpriteFrame=null;//
  41. @property(SpriteFrame)
  42. heqiSp:SpriteFrame=null;//
  43. @property(Node)
  44. self_head_sp:Node=null;//
  45. @property(Node)
  46. rival_head_sp:Node=null;//
  47. @property(Node)
  48. self_name:Node=null;//
  49. @property(Node)
  50. rival_name:Node=null;//
  51. @property(Node)
  52. block_node:Node =null;
  53. @property(Node)
  54. ui_node:Node =null;
  55. @property(Node)
  56. jifen_node:Node =null;
  57. @property(Node)
  58. tongqian_node:Node =null;
  59. start() {
  60. let self = this;
  61. UIButton.BindClick(this.btn_close,()=>{
  62. self.node.active = false;
  63. // AudioMng.Instance.PlayBGM(GameMng.Instance.mainbgm);
  64. // ScenceMng.Instance.load('GameLaunch');
  65. },this);
  66. UIButton.BindClick(this.btn_new,()=>{
  67. if(ChessMng.Instance.isHaoyouRoom()){
  68. GameMng.Instance.quit_view = quit_chess_show_view.haoyou
  69. msgManager.quitRoom()
  70. }else if(ChessType.renjiboyi==ChessMng.Instance.chesstype){
  71. GameMng.Instance.quit_view = quit_chess_show_view.renji
  72. GBoardChess.instance.recvQuit()
  73. }
  74. },this);
  75. UIButton.BindClick(this.btn_again,()=>{
  76. this.node.active=false;
  77. if(ChessMng.Instance.isHaoyouRoom()){
  78. if(GameMng._userData.room===null){
  79. }else{
  80. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_ready)
  81. }
  82. }else if(ChessType.renjiboyi==ChessMng.Instance.chesstype){
  83. GBoardChess.instance.restartGame()
  84. }else if(ChessMng.Instance.isJiFenRoom()){
  85. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_5_10_20_ready)
  86. }
  87. },this);
  88. UIButton.BindClick(this.btn_share,()=>{
  89. },this);
  90. UIButton.BindClick(this.btn_reinfo,()=>{
  91. },this);
  92. }
  93. update(deltaTime: number) {
  94. }
  95. setData(data:settlementData,time:string,bushu:number){
  96. this.block_node.active = true;
  97. this.ui_node.scale = new Vec3(0,0,1)
  98. this.scheduleOnce(()=>{
  99. this.ui_node.scale = new Vec3(1,1,1)
  100. },2)
  101. if(ChessMng.Instance.chesstype===ChessType.renjiboyi){
  102. data.result = 1-data.result;
  103. }
  104. if(data.result==1){
  105. this.sp_isWin.getComponent(Sprite).spriteFrame = this.winSp;
  106. AudioMng.Instance.PlaySoundByName(GameMng.Instance.winclip);
  107. }else if(data.result==0){
  108. this.sp_isWin.getComponent(Sprite).spriteFrame = this.loseSp;
  109. AudioMng.Instance.PlaySoundByName(GameMng.Instance.failclip);
  110. }
  111. var data = GBoardChess.instance.last_settlementData;
  112. if(data!=null){
  113. switch(data.result_type){
  114. case 0:{ //正常绝杀
  115. break;
  116. }
  117. case 1:{ //到时间
  118. if(data.result==1){
  119. }else{
  120. }
  121. break;
  122. }
  123. case 2:{ //逃跑
  124. break;
  125. }
  126. case 3:{ //认输
  127. break;
  128. }
  129. case 4:{ //和棋
  130. this.sp_isWin.getComponent(Sprite).spriteFrame = this.heqiSp;
  131. break;
  132. }
  133. }
  134. }
  135. this.self_name.getComponent(Label).string = GameMng._userData.user_name
  136. if(GameMng._userData.user_avatar!=""){
  137. Tools.loadWeiXinHead(GameMng._userData.user_avatar,this.self_head_sp.getComponent(Sprite))
  138. }
  139. let name = ""
  140. if(ChessMng.Instance.chesstype===ChessType.renjiboyi){
  141. name = "人机对战,"
  142. this.rival_name.getComponent(Label).string = UIDiffSel.lvArr[UIDiffSel.selectIndex]
  143. ResMng.LoadAvatar(Tools.getAvatarByIndex(UIDiffSel.selectIndex+1),this.rival_head_sp.getComponent(Sprite))
  144. this.lab_des.getComponent(Label).string = name+bushu+"步,"+GameUtil.timestampToTime()
  145. }else if(ChessMng.Instance.isHaoyouRoom()){
  146. name = "好友对战,"
  147. if(GameMng._userData.room!=null){
  148. if(GameMng._userData.room.rival!=null){
  149. this.rival_name.getComponent(Label).string = GameMng._userData.room.rival.user_name
  150. if(GameMng._userData.room.rival.user_avatar!=""){
  151. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head_sp.getComponent(Sprite))
  152. }
  153. }
  154. if(GBoardChess.instance.last_settlementData!=null){
  155. this.lab_des.getComponent(Label).string = name+GBoardChess.instance.last_settlementData.round+"回合,"+GBoardChess.instance.last_settlementData.server_time
  156. }
  157. }
  158. }else if(ChessMng.Instance.isJiFenRoom()){
  159. name = "积分对战,"
  160. this.jifen_node.getComponent(jifen_jiesuan).show(data)
  161. if(GameMng._userData.room!=null){
  162. if(GameMng._userData.room.rival!=null){
  163. this.rival_name.getComponent(Label).string = GameMng._userData.room.rival.user_name
  164. if(GameMng._userData.room.rival.user_avatar!=""){
  165. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head_sp.getComponent(Sprite))
  166. }
  167. }
  168. if(GBoardChess.instance.last_settlementData!=null){
  169. this.lab_des.getComponent(Label).string = name+GBoardChess.instance.last_settlementData.round+"回合,"+GBoardChess.instance.last_settlementData.server_time
  170. }
  171. }
  172. }else if(ChessMng.Instance.isTongqianRoom()){
  173. name = "铜钱对战,"
  174. this.tongqian_node.getComponent(tongqian_jiesuan).show(data)
  175. if(GameMng._userData.room!=null){
  176. if(GameMng._userData.room.rival!=null){
  177. this.rival_name.getComponent(Label).string = GameMng._userData.room.rival.user_name
  178. if(GameMng._userData.room.rival.user_avatar!=""){
  179. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head_sp.getComponent(Sprite))
  180. }
  181. }
  182. if(GBoardChess.instance.last_settlementData!=null){
  183. this.lab_des.getComponent(Label).string = name+GBoardChess.instance.last_settlementData.round+"回合,"+GBoardChess.instance.last_settlementData.server_time
  184. }
  185. }
  186. }
  187. GameData.SaveGame();
  188. }
  189. }