GameLaunch.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import CanjuModel, { CanjuData } from "./Game/ChessCanJuSel/CanjuModel";
  2. import ChessMng, { ChessType } from "./Game/DiffSel/ChessMng";
  3. import UIDiffSel from "./Game/DiffSel/UIDiffSel";
  4. import AudioMng from "./gcommon/AudioMng";
  5. import { UIButton } from "./gcommon/UIButton";
  6. import GameData from "./gcommon/GameData";
  7. import ScenceMng from "./gcommon/ScenceMng";
  8. import { GameMng, quit_chess_show_view } from "./GameMng";
  9. import { _decorator,Component,TextAsset,Node,setDisplayStats, game, sys, native, EventTouch } from "cc";
  10. import gameSocket from "./socket/gameSocket";
  11. import UIduizhan from "./Game/UIduizhan";
  12. import UITips from "./gcommon/UITips";
  13. import { ClientEvent } from "./clientEvent";
  14. import { Constant } from "./constant";
  15. import { Tools } from "./Tools";
  16. import { page_btn } from "./Main/page_btn";
  17. import UIDialog from "./Game/UIDialog";
  18. import { native_manager } from "./native_manager";
  19. const {ccclass, property} = _decorator;
  20. var pageList = new Map();
  21. var pageBtnList = new Map();
  22. @ccclass
  23. export default class GameLaunch extends Component {
  24. @property(TextAsset)
  25. fen: TextAsset = null;
  26. static isLaunch:boolean=false;
  27. // @property(Node)
  28. // btn1: Node = null;
  29. // @property(Node)
  30. // btn2: Node = null;
  31. @property(Node)
  32. btn_duizhan: Node = null;
  33. @property(Node)
  34. login_view: Node = null;
  35. @property(Node)
  36. xiaqi_page: Node = null;
  37. @property(Node)
  38. xueqi_page: Node = null;
  39. @property(Node)
  40. qijie_page: Node = null;
  41. @property(Node)
  42. faxian_page: Node = null;
  43. @property(Node)
  44. wode_page: Node = null;
  45. @property(Node)
  46. xiaqi_page_btn: Node = null;
  47. @property(Node)
  48. xueqi_page_btn: Node = null;
  49. @property(Node)
  50. qijie_page_btn: Node = null;
  51. @property(Node)
  52. faxian_page_btn: Node = null;
  53. @property(Node)
  54. wode_page_btn: Node = null;
  55. cur_select_page:string = ""
  56. start() {
  57. if(!GameLaunch.isLaunch){
  58. this.initGame();
  59. GameLaunch.isLaunch=true;
  60. }
  61. this.clearList()
  62. // UIButton.BindClick(this.btn1,()=>{
  63. // ChessMng.Instance.chesstype=ChessType.renjiboyi;
  64. // ScenceMng.Instance.load('ChessDiffSel')
  65. // },this);
  66. // UIButton.BindClick(this.btn2,()=>{
  67. // ChessMng.Instance.chesstype=ChessType.canju;
  68. // ScenceMng.Instance.load('ChessCanJuSel')
  69. // },this);
  70. if(CanjuModel.Instance.canjuDataArr.length==0){
  71. let arr=this.fen.text.split('\n')
  72. arr.forEach((item,index)=>{
  73. let arr = item.split(';');
  74. let canjudata: CanjuData = { fen: arr[0], name: arr[1] }
  75. CanjuModel.Instance.canjuDataArr.push(canjudata)
  76. })
  77. }
  78. UIButton.BindClick(this.btn_duizhan,()=>{
  79. UIduizhan.Show();
  80. },this);
  81. if(GameMng._userData == null){
  82. this.login_view.active = true;
  83. }else{
  84. this.login_view.active = false;
  85. }
  86. gameSocket.Instance.connect(Tools.makeUrl())
  87. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_FIREND,this.show_firend,this)
  88. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_RENJI,this.show_renji,this)
  89. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN,this.show_jifen,this)
  90. ClientEvent.on(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN,this.show_login,this)
  91. if(GameMng.Instance.quit_view!=null){
  92. switch(GameMng.Instance.quit_view){
  93. case quit_chess_show_view.haoyou:{
  94. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_FIREND)
  95. break;
  96. }
  97. case quit_chess_show_view.renji:{
  98. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_RENJI)
  99. break;
  100. }
  101. case quit_chess_show_view.jifen:{
  102. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN)
  103. break;
  104. }
  105. case quit_chess_show_view.login:{
  106. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN)
  107. break;
  108. }
  109. case quit_chess_show_view.beitichu:{
  110. UIDialog.Show(()=>{
  111. },()=>{
  112. },"你已被桌主踢出房间!",null,false)
  113. break;
  114. }
  115. }
  116. }
  117. GameMng.Instance.quit_view = null;
  118. this.initPage()
  119. this.initPageBtns()
  120. this.showPage(0,'xiaqi',true)
  121. }
  122. initPage(){
  123. if(pageList.get(Constant.PAGE_XIAQI)===null){
  124. pageList.set(Constant.PAGE_XIAQI,this.xiaqi_page)
  125. }
  126. if(pageList.get(Constant.PAGE_XUEQI)===null){
  127. pageList.set(Constant.PAGE_XUEQI,this.xueqi_page)
  128. }
  129. if(pageList.get(Constant.PAGE_QIJIE)===null){
  130. pageList.set(Constant.PAGE_QIJIE,this.qijie_page)
  131. }
  132. if(pageList.get(Constant.PAGE_FAXIAN)===null){
  133. pageList.set(Constant.PAGE_FAXIAN,this.faxian_page)
  134. }
  135. if(pageList.get(Constant.PAGE_WODE)===null){
  136. pageList.set(Constant.PAGE_WODE,this.wode_page)
  137. }
  138. }
  139. initPageBtns(){
  140. if(pageBtnList.get(Constant.PAGE_XIAQI)===null){
  141. pageBtnList.set(Constant.PAGE_XIAQI,this.xiaqi_page_btn)
  142. }
  143. if(pageBtnList.get(Constant.PAGE_XUEQI)===null){
  144. pageBtnList.set(Constant.PAGE_XUEQI,this.xueqi_page_btn)
  145. }
  146. if(pageBtnList.get(Constant.PAGE_QIJIE)===null){
  147. pageBtnList.set(Constant.PAGE_QIJIE,this.qijie_page_btn)
  148. }
  149. if(pageBtnList.get(Constant.PAGE_FAXIAN)===null){
  150. pageBtnList.set(Constant.PAGE_FAXIAN,this.faxian_page_btn)
  151. }
  152. if(pageBtnList.get(Constant.PAGE_WODE)===null){
  153. pageBtnList.set(Constant.PAGE_WODE,this.wode_page_btn)
  154. }
  155. }
  156. onEnable(){
  157. native_manager.hideSplash()
  158. }
  159. show_firend(){
  160. UIduizhan.Show(quit_chess_show_view.haoyou);
  161. }
  162. show_renji(){
  163. UIduizhan.Show(quit_chess_show_view.renji);
  164. }
  165. show_jifen(){
  166. UIduizhan.Show(quit_chess_show_view.jifen);
  167. }
  168. show_login(){
  169. this.login_view.active = true;
  170. GameMng._userData = null;
  171. gameSocket.Instance.stopConnected = false;
  172. }
  173. onDestroy(){
  174. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_FIREND,this.show_firend,this)
  175. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_RENJI,this.show_renji,this)
  176. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_JIFEN,this.show_jifen,this)
  177. ClientEvent.off(Constant.UI_EVENT.UI_MSG_SHOW_LOGIN,this.show_login,this)
  178. }
  179. clearList(){
  180. pageList.set(Constant.PAGE_XIAQI, null);
  181. pageList.set(Constant.PAGE_XUEQI, null);
  182. pageList.set(Constant.PAGE_QIJIE, null);
  183. pageList.set(Constant.PAGE_FAXIAN, null);
  184. pageList.set(Constant.PAGE_WODE, null);
  185. pageBtnList.set(Constant.PAGE_XIAQI, null);
  186. pageBtnList.set(Constant.PAGE_XUEQI, null);
  187. pageBtnList.set(Constant.PAGE_QIJIE, null);
  188. pageBtnList.set(Constant.PAGE_FAXIAN, null);
  189. pageBtnList.set(Constant.PAGE_WODE, null);
  190. }
  191. clickNot(){
  192. UITips.show("暂未开放,敬请期待!");
  193. }
  194. initGame(){
  195. setDisplayStats(false);
  196. console.log("initGame")
  197. GameData.LoadGame();
  198. AudioMng.Instance.PlayBGM(GameMng.Instance.mainbgm);
  199. }
  200. showPage(event:any,name:string,isFirst:boolean=false){
  201. console.log("name",name)
  202. if(pageList.get(name+"")!=null&&this.cur_select_page!=name){
  203. console.log("data",name)
  204. this.hideAllPage(name)
  205. this.showPageBtn(name)
  206. if(!isFirst){
  207. AudioMng.Instance.PlaySoundByName(GameMng.Instance.buttonclick);
  208. }
  209. this.cur_select_page = name;
  210. }
  211. }
  212. showPageBtn(name:string){
  213. pageBtnList.forEach((element, key, map) =>{
  214. if(element){
  215. if(name!=key){
  216. element.getComponent(page_btn).status_unselect()
  217. }else{
  218. element.getComponent(page_btn).status_select()
  219. }
  220. }
  221. })
  222. }
  223. hideAllPage(name){
  224. pageList.forEach((element, key, map) =>{
  225. if(element){
  226. if(name!=key){
  227. element.active = false;
  228. }else{
  229. element.active = true;
  230. }
  231. }
  232. })
  233. }
  234. }