createFirendRoom.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import { _decorator, Component, Node, Sprite, Color, Label, NodeEventType, tween, color, Vec3, SpriteFrame } from 'cc';
  2. import { ClientEvent } from '../clientEvent';
  3. import { Constant, room_type } from '../constant';
  4. import { GameMng } from '../GameMng';
  5. import GBaseUI from '../gcommon/GBaseUI';
  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 { roomData } from '../UserData/roomData';
  11. import ChessRBSel from './ChessGame/ChessRBSel';
  12. import ChessMng, { ChessType } from './DiffSel/ChessMng';
  13. import UIDiffSel from './DiffSel/UIDiffSel';
  14. const { ccclass, property } = _decorator;
  15. var JU_SHI = [ "10分钟", "45分钟", "30分钟", "20分钟", "15分钟", "5分钟", "3分钟", "2分钟"];//局时
  16. var JU_SHI_NUM = [ 600, 2700, 1800,1200, 900, 300, 180, 120];//局时
  17. var BU_SHI = [ "1分钟", "5分钟", "3分钟", "2分钟", "30秒"];//步时
  18. var BU_SHI_NUM = [ 60, 300, 180, 120, 30];//步时
  19. var MEI_BU_JIA_SHI = [ "10秒", "20秒", "5秒", "3秒"];//每步加时
  20. var MEI_BU_JIA_SHI_NUM = [ 10, 20, 5, 3];//每步加时
  21. var WO_FANG = [ "执黑", "执红"];//我方棋局先后手
  22. var DU_MIAO = [ "0秒", "60秒","30秒"];//读秒
  23. var DU_MIAO_NUM = [ 0, 60,30];//读秒
  24. @ccclass('createFirendRoom')
  25. export class createFirendRoom extends GBaseUI {
  26. @property(Node)
  27. btnClose: Node = null;
  28. @property(SpriteFrame) sp_jing_dian:SpriteFrame =null
  29. @property(SpriteFrame) sp_jing_dian_0:SpriteFrame =null
  30. @property(SpriteFrame) sp_mei_bu:SpriteFrame =null
  31. @property(SpriteFrame) sp_mei_bu_0:SpriteFrame =null
  32. @property(Node)
  33. btnJingdian: Node = null; //经典
  34. @property(Node)
  35. btnMeibujiashi: Node = null; //每步加时
  36. //局时
  37. @property(Node)
  38. labJushi: Node = null; //局时间
  39. @property(Node)
  40. btn_Jushi_select: Node = null; //局时间选择
  41. //步时
  42. @property(Node)
  43. labBushi: Node = null; //步时间
  44. @property(Node)
  45. btn_Bushi_select: Node = null; //步时间选择
  46. //读秒
  47. @property(Node)
  48. labDumiao: Node = null; //读秒
  49. @property(Node)
  50. btn_Dumiao_select: Node = null; //读秒选择
  51. @property(Node)
  52. nodeDumiao: Node = null; //读秒节点
  53. //我方(红白方选择)
  54. @property(Node)
  55. labWofang: Node = null; //我方(红白方选择)
  56. @property(Node)
  57. btn_Wofang_select: Node = null; //我方(红白方选择)
  58. //每步加时
  59. @property(Node)
  60. labMeibujiashi: Node = null; //每步加时
  61. @property(Node)
  62. btn_Meibujiashi_select: Node = null; //每步加时选择
  63. @property(Node)
  64. nodeMeibujiashi: Node = null; //每步加时节点
  65. //显示选择页面
  66. @property(Node)
  67. select_node: Node = null; //显示选择页面
  68. //局时选择页面
  69. @property(Node)
  70. select_jushi_node: Node = null; //局时选择页面
  71. //步时选择页面
  72. @property(Node)
  73. select_bushi_node: Node = null; //步时选择页面
  74. //读秒选择页面
  75. @property(Node)
  76. select_dumiao_node: Node = null; //读秒选择页面
  77. //我方选择页面
  78. @property(Node)
  79. select_wofang_node: Node = null; //我方选择页面
  80. //每步加时选择页面
  81. @property(Node)
  82. select_meibujiashi_node: Node = null; //每步加时选择页面
  83. //局时选择页面容器
  84. @property(Node)
  85. select_jushi_content: Node = null; //局时选择页面容器
  86. //步时选择页面容器
  87. @property(Node)
  88. select_bushi_content: Node = null; //步时选择页面容器
  89. //读秒选择页面容器
  90. @property(Node)
  91. select_dumiao_content: Node = null; //读秒选择页面容器
  92. //我方选择页面容器
  93. @property(Node)
  94. select_wofang_content: Node = null; //我方选择页面容器
  95. //每步加时选择页面容器
  96. @property(Node)
  97. select_meibujiashi_content: Node = null; //每步加时选择页面容器
  98. //取消
  99. @property(Node)
  100. btn_cancel: Node = null; //
  101. //创建
  102. @property(Node)
  103. btn_create: Node = null; //创建
  104. curSelectMode:room_type=room_type._jing_dian_hao_you;
  105. curSelectJushiIndex:number=7; //默认选择下标7的局时
  106. curSelectBushiIndex:number=4; //默认选择下标4的步时
  107. curSelectDumiaoIndex:number=0; //默认选择下标0的读秒
  108. curSelectWofangIndex:number=0; //默认选择下标0的先后手
  109. curSelectMeibujiashiIndex:number=0; //默认选择下标0的每步加时
  110. isInitJuShiContent:boolean = false;
  111. isInitBuShiContent:boolean = false;
  112. isInitDuMiaoContent:boolean = false;
  113. isInitWoFangContent:boolean = false;
  114. isInitMeiBuJiaShiContent:boolean = false;
  115. color:Color = new Color()
  116. room:roomData = new roomData();
  117. static Show(parent?:any){
  118. UIManager.AddPrefab(GameMng.Instance.createFirend,parent);
  119. }
  120. start() {
  121. this.initBtns();
  122. this.selectModeChange();
  123. this.initView();
  124. ClientEvent.on(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this)
  125. }
  126. onDestroy(){
  127. ClientEvent.off(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this)
  128. }
  129. onRecvCreateRoom(room:roomData){
  130. console.log("room",room)
  131. GameMng.updateRoomData(room);
  132. ScenceMng.Instance.load('Chess')
  133. this.onCreate()
  134. }
  135. selectModeChange(){
  136. if(this.curSelectMode===room_type._jing_dian_hao_you){
  137. this.btnJingdian.getComponent(Sprite).spriteFrame = this.sp_jing_dian;
  138. this.btnMeibujiashi.getComponent(Sprite).spriteFrame = this.sp_mei_bu_0;
  139. this.nodeMeibujiashi.active = false;
  140. this.nodeDumiao.active = true;
  141. }else{
  142. this.btnJingdian.getComponent(Sprite).spriteFrame = this.sp_jing_dian_0;
  143. this.btnMeibujiashi.getComponent(Sprite).spriteFrame = this.sp_mei_bu;
  144. this.nodeMeibujiashi.active = true;
  145. this.nodeDumiao.active = false;
  146. }
  147. }
  148. initView(){
  149. this.labJushi.getComponent(Label).string = JU_SHI[this.curSelectJushiIndex];
  150. this.labBushi.getComponent(Label).string = BU_SHI[this.curSelectBushiIndex];
  151. this.labMeibujiashi.getComponent(Label).string = MEI_BU_JIA_SHI[this.curSelectMeibujiashiIndex];
  152. this.labWofang.getComponent(Label).string = WO_FANG[this.curSelectWofangIndex];
  153. this.labDumiao.getComponent(Label).string = DU_MIAO[this.curSelectDumiaoIndex];
  154. }
  155. onCreate(){
  156. // this.room.butime = BU_SHI_NUM[this.curSelectBushiIndex]
  157. // this.room.jutime = JU_SHI_NUM[this.curSelectJushiIndex]
  158. // this.room.meibujiashi = MEI_BU_JIA_SHI_NUM[this.curSelectMeibujiashiIndex]
  159. // this.room.zhenying = this.curSelectWofangIndex
  160. //this.room.countdown = DU_MIAO_NUM[this.curSelectDumiaoIndex]
  161. }
  162. initBtns(){
  163. UIButton.BindClick(this.btnClose,()=>{
  164. this.closeUI();
  165. },this);
  166. UIButton.BindClick(this.btnJingdian,()=>{
  167. if(this.curSelectMode==room_type._jing_dian_hao_you){
  168. }else{
  169. this.curSelectMode = room_type._jing_dian_hao_you;
  170. this.selectModeChange();
  171. }
  172. },this);
  173. UIButton.BindClick(this.btnMeibujiashi,()=>{
  174. if(this.curSelectMode==room_type._mei_miao_die_jia_hao_you){
  175. }else{
  176. this.curSelectMode = room_type._mei_miao_die_jia_hao_you;
  177. this.selectModeChange();
  178. }
  179. },this);
  180. UIButton.BindClick(this.btn_Jushi_select,()=>{
  181. this.showJuShiSelectView();
  182. },this);
  183. UIButton.BindClick(this.btn_Bushi_select,()=>{
  184. this.showBuShiSelectView();
  185. },this);
  186. UIButton.BindClick(this.btn_Dumiao_select,()=>{
  187. this.showDumiaoSelectView();
  188. },this);
  189. UIButton.BindClick(this.btn_Wofang_select,()=>{
  190. this.showWofangSelectView();
  191. },this);
  192. UIButton.BindClick(this.btn_Meibujiashi_select,()=>{
  193. this.showMeibujiashiSelectView();
  194. },this);
  195. UIButton.BindClick(this.btn_cancel,()=>{
  196. this.closeUI();
  197. },this);
  198. UIButton.BindClick(this.btn_create,()=>{
  199. msgManager.createRoom(JU_SHI_NUM[this.curSelectJushiIndex],BU_SHI_NUM[this.curSelectBushiIndex],this.curSelectWofangIndex,this.curSelectMode,DU_MIAO_NUM[this.curSelectDumiaoIndex],MEI_BU_JIA_SHI_NUM[this.curSelectMeibujiashiIndex])
  200. // ClientEvent.dispatchEvent(Constant.EVENT_TYPE.MSG_CREATE_ROOM,this.onRecvCreateRoom,this)
  201. },this);
  202. }
  203. hideAllSelectView(){
  204. this.select_jushi_node.active = false;
  205. this.select_bushi_node.active = false;
  206. this.select_meibujiashi_node.active = false;
  207. this.select_wofang_node.active = false;
  208. this.select_dumiao_node.active = false;
  209. }
  210. showJuShiSelectView(){
  211. this.select_node.active = true;
  212. this.hideAllSelectView()
  213. this.showSelectContenAni(this.select_jushi_node);
  214. if(!this.isInitJuShiContent){
  215. let self = this;
  216. for (let index = 0; index < this.select_jushi_content.children.length; index++) {
  217. const jushi_item = this.select_jushi_content.children[index] as Node;
  218. let lab = jushi_item.getChildByName("Label")
  219. if(JU_SHI[index]){
  220. lab.getComponent(Label).string = JU_SHI[index];
  221. }
  222. jushi_item.on(NodeEventType.TOUCH_END,function(){
  223. console.log("选中",JU_SHI[index])
  224. self.curSelectJushiIndex = index;
  225. self.initView()
  226. self.onQuitSelectView()
  227. })
  228. }
  229. this.isInitJuShiContent = true;
  230. }
  231. }
  232. showBuShiSelectView(){
  233. this.select_node.active = true;
  234. this.hideAllSelectView()
  235. this.showSelectContenAni(this.select_bushi_node);
  236. if(!this.isInitBuShiContent){
  237. let self = this;
  238. for (let index = 0; index < this.select_bushi_content.children.length; index++) {
  239. const bushi_item = this.select_bushi_content.children[index] as Node;
  240. let lab = bushi_item.getChildByName("Label")
  241. if(BU_SHI[index]){
  242. lab.getComponent(Label).string = BU_SHI[index];
  243. }
  244. bushi_item.on(NodeEventType.TOUCH_END,function(){
  245. console.log("选中",BU_SHI[index])
  246. self.curSelectBushiIndex = index;
  247. self.initView()
  248. self.onQuitSelectView()
  249. })
  250. }
  251. this.isInitBuShiContent = true;
  252. }
  253. }
  254. showMeibujiashiSelectView(){
  255. this.select_node.active = true;
  256. this.hideAllSelectView()
  257. this.showSelectContenAni(this.select_meibujiashi_node);
  258. if(!this.isInitMeiBuJiaShiContent){
  259. let self = this;
  260. for (let index = 0; index < this.select_meibujiashi_content.children.length; index++) {
  261. const meibujiashi_item = this.select_meibujiashi_content.children[index] as Node;
  262. let lab = meibujiashi_item.getChildByName("Label")
  263. if(MEI_BU_JIA_SHI[index]){
  264. lab.getComponent(Label).string = MEI_BU_JIA_SHI[index];
  265. }
  266. meibujiashi_item.on(NodeEventType.TOUCH_END,function(){
  267. console.log("选中",MEI_BU_JIA_SHI[index])
  268. self.curSelectMeibujiashiIndex = index;
  269. self.initView()
  270. self.onQuitSelectView()
  271. })
  272. }
  273. this.isInitMeiBuJiaShiContent = true;
  274. }
  275. }
  276. showWofangSelectView(){
  277. this.select_node.active = true;
  278. this.hideAllSelectView()
  279. this.showSelectContenAni(this.select_wofang_node);
  280. if(!this.isInitWoFangContent){
  281. let self = this;
  282. for (let index = 0; index < this.select_wofang_content.children.length; index++) {
  283. const wofang_item = this.select_wofang_content.children[index] as Node;
  284. let lab = wofang_item.getChildByName("Label")
  285. if(WO_FANG[index]){
  286. lab.getComponent(Label).string = WO_FANG[index];
  287. }
  288. wofang_item.on(NodeEventType.TOUCH_END,function(){
  289. console.log("选中",WO_FANG[index])
  290. self.curSelectWofangIndex = index;
  291. self.initView()
  292. self.onQuitSelectView()
  293. })
  294. }
  295. this.isInitWoFangContent = true;
  296. }
  297. }
  298. showDumiaoSelectView(){
  299. this.select_node.active = true;
  300. this.hideAllSelectView();
  301. this.showSelectContenAni(this.select_dumiao_node);
  302. if(!this.isInitDuMiaoContent){
  303. let self = this;
  304. for (let index = 0; index < this.select_dumiao_content.children.length; index++) {
  305. const dumiao_item = this.select_dumiao_content.children[index] as Node;
  306. let lab = dumiao_item.getChildByName("Label")
  307. if(DU_MIAO[index]){
  308. lab.getComponent(Label).string = DU_MIAO[index];
  309. }
  310. dumiao_item.on(NodeEventType.TOUCH_END,function(){
  311. console.log("选中",DU_MIAO[index])
  312. self.curSelectDumiaoIndex = index;
  313. self.initView()
  314. self.onQuitSelectView()
  315. })
  316. }
  317. this.isInitDuMiaoContent = true;
  318. }
  319. }
  320. showSelectContenAni(node:Node){
  321. node.scale = new Vec3(1,0.5,1);
  322. node.active = true;
  323. tween(node).to(0.1,{scale:new Vec3(1,1,1)}).start()
  324. }
  325. onQuitSelectView(){
  326. this.select_node.active = false;
  327. }
  328. update(deltaTime: number) {
  329. }
  330. }