UIjiesuan.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. @property(Node)
  60. rival_tongbi_node:Node =null;
  61. @property(Node)
  62. self_tongbi_node:Node =null;
  63. start() {
  64. let self = this;
  65. UIButton.BindClick(this.btn_close,()=>{
  66. self.node.active = false;
  67. // AudioMng.Instance.PlayBGM(GameMng.Instance.mainbgm);
  68. // ScenceMng.Instance.load('GameLaunch');
  69. },this);
  70. UIButton.BindClick(this.btn_new,()=>{
  71. if(ChessMng.Instance.isHaoyouRoom()){
  72. GameMng.Instance.quit_view = quit_chess_show_view.haoyou
  73. msgManager.quitRoom()
  74. }else if(ChessType.renjiboyi==ChessMng.Instance.chesstype){
  75. GameMng.Instance.quit_view = quit_chess_show_view.renji
  76. GBoardChess.instance.recvQuit()
  77. }
  78. },this);
  79. UIButton.BindClick(this.btn_again,()=>{
  80. this.node.active=false;
  81. if(ChessMng.Instance.isHaoyouRoom()){
  82. if(GameMng._userData.room===null){
  83. }else{
  84. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_ready)
  85. }
  86. }else if(ChessType.renjiboyi==ChessMng.Instance.chesstype){
  87. GBoardChess.instance.restartGame()
  88. }else if(ChessMng.Instance.isJiFenRoom()){
  89. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_5_10_20_ready)
  90. }
  91. },this);
  92. UIButton.BindClick(this.btn_share,()=>{
  93. },this);
  94. UIButton.BindClick(this.btn_reinfo,()=>{
  95. },this);
  96. }
  97. update(deltaTime: number) {
  98. }
  99. setData(data:settlementData,time:string,bushu:number){
  100. this.block_node.active = true;
  101. this.rival_tongbi_node.active =false;
  102. this.self_tongbi_node.active = false;
  103. this.ui_node.scale = new Vec3(0,0,1)
  104. this.scheduleOnce(()=>{
  105. this.ui_node.scale = new Vec3(1,1,1)
  106. },2)
  107. if(ChessMng.Instance.chesstype===ChessType.renjiboyi){
  108. data.result = 1-data.result;
  109. }
  110. if(data.result==1){
  111. this.sp_isWin.getComponent(Sprite).spriteFrame = this.winSp;
  112. AudioMng.Instance.PlaySoundByName(GameMng.Instance.winclip);
  113. }else if(data.result==0){
  114. this.sp_isWin.getComponent(Sprite).spriteFrame = this.loseSp;
  115. AudioMng.Instance.PlaySoundByName(GameMng.Instance.failclip);
  116. }
  117. var data = GBoardChess.instance.last_settlementData;
  118. if(data!=null){
  119. switch(data.result_type){
  120. case 0:{ //正常绝杀
  121. break;
  122. }
  123. case 1:{ //到时间
  124. if(data.result==1){
  125. }else{
  126. }
  127. break;
  128. }
  129. case 2:{ //逃跑
  130. break;
  131. }
  132. case 3:{ //认输
  133. break;
  134. }
  135. case 4:{ //和棋
  136. this.sp_isWin.getComponent(Sprite).spriteFrame = this.heqiSp;
  137. break;
  138. }
  139. }
  140. }
  141. this.self_name.getComponent(Label).string = GameMng._userData.user_name
  142. if(GameMng._userData.user_avatar!=""){
  143. Tools.loadWeiXinHead(GameMng._userData.user_avatar,this.self_head_sp.getComponent(Sprite))
  144. }
  145. let name = ""
  146. if(ChessMng.Instance.chesstype===ChessType.renjiboyi){
  147. name = "人机对战,"
  148. this.rival_name.getComponent(Label).string = UIDiffSel.lvArr[UIDiffSel.selectIndex]
  149. ResMng.LoadAvatar(Tools.getAvatarByIndex(UIDiffSel.selectIndex+1),this.rival_head_sp.getComponent(Sprite))
  150. this.lab_des.getComponent(Label).string = name+bushu+"步,"+GameUtil.timestampToTime()
  151. }else if(ChessMng.Instance.isHaoyouRoom()){
  152. name = "好友对战,"
  153. if(GameMng._userData.room!=null){
  154. if(GameMng._userData.room.rival!=null){
  155. this.rival_name.getComponent(Label).string = GameMng._userData.room.rival.user_name
  156. if(GameMng._userData.room.rival.user_avatar!=""){
  157. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head_sp.getComponent(Sprite))
  158. }
  159. }
  160. if(GBoardChess.instance.last_settlementData!=null){
  161. this.lab_des.getComponent(Label).string = name+GBoardChess.instance.last_settlementData.round+"回合,"+GBoardChess.instance.last_settlementData.server_time
  162. }
  163. }
  164. }else if(ChessMng.Instance.isJiFenRoom()){
  165. name = "积分对战,"
  166. this.jifen_node.getComponent(jifen_jiesuan).show(data)
  167. if(GameMng._userData.room!=null){
  168. if(GameMng._userData.room.rival!=null){
  169. this.rival_name.getComponent(Label).string = GameMng._userData.room.rival.user_name
  170. if(GameMng._userData.room.rival.user_avatar!=""){
  171. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head_sp.getComponent(Sprite))
  172. }
  173. }
  174. if(GBoardChess.instance.last_settlementData!=null){
  175. this.lab_des.getComponent(Label).string = name+GBoardChess.instance.last_settlementData.round+"回合,"+GBoardChess.instance.last_settlementData.server_time
  176. }
  177. }
  178. }else if(ChessMng.Instance.isTongqianRoom()){
  179. this.rival_tongbi_node.active =true;
  180. this.self_tongbi_node.active = true;
  181. name = "铜钱对战,"
  182. this.tongqian_node.getComponent(tongqian_jiesuan).show(data)
  183. if(GameMng._userData.room!=null){
  184. if(GameMng._userData.room.rival!=null){
  185. this.rival_name.getComponent(Label).string = GameMng._userData.room.rival.user_name
  186. if(GameMng._userData.room.rival.user_avatar!=""){
  187. Tools.loadWeiXinHead(GameMng._userData.room.rival.user_avatar,this.rival_head_sp.getComponent(Sprite))
  188. }
  189. }
  190. if(GBoardChess.instance.last_settlementData!=null){
  191. this.lab_des.getComponent(Label).string = name+GBoardChess.instance.last_settlementData.round+"回合,"+GBoardChess.instance.last_settlementData.server_time
  192. }
  193. }
  194. }
  195. GameData.SaveGame();
  196. }
  197. }