createFirendRoom.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. }
  125. onDestroy(){
  126. }
  127. selectModeChange(){
  128. if(this.curSelectMode===room_type._jing_dian_hao_you){
  129. this.btnJingdian.getComponent(Sprite).spriteFrame = this.sp_jing_dian;
  130. this.btnMeibujiashi.getComponent(Sprite).spriteFrame = this.sp_mei_bu_0;
  131. this.nodeMeibujiashi.active = false;
  132. this.nodeDumiao.active = true;
  133. }else{
  134. this.btnJingdian.getComponent(Sprite).spriteFrame = this.sp_jing_dian_0;
  135. this.btnMeibujiashi.getComponent(Sprite).spriteFrame = this.sp_mei_bu;
  136. this.nodeMeibujiashi.active = true;
  137. this.nodeDumiao.active = false;
  138. }
  139. }
  140. initView(){
  141. this.labJushi.getComponent(Label).string = JU_SHI[this.curSelectJushiIndex];
  142. this.labBushi.getComponent(Label).string = BU_SHI[this.curSelectBushiIndex];
  143. this.labMeibujiashi.getComponent(Label).string = MEI_BU_JIA_SHI[this.curSelectMeibujiashiIndex];
  144. this.labWofang.getComponent(Label).string = WO_FANG[this.curSelectWofangIndex];
  145. this.labDumiao.getComponent(Label).string = DU_MIAO[this.curSelectDumiaoIndex];
  146. }
  147. onCreate(){
  148. // this.room.butime = BU_SHI_NUM[this.curSelectBushiIndex]
  149. // this.room.jutime = JU_SHI_NUM[this.curSelectJushiIndex]
  150. // this.room.meibujiashi = MEI_BU_JIA_SHI_NUM[this.curSelectMeibujiashiIndex]
  151. // this.room.zhenying = this.curSelectWofangIndex
  152. //this.room.countdown = DU_MIAO_NUM[this.curSelectDumiaoIndex]
  153. }
  154. initBtns(){
  155. UIButton.BindClick(this.btnClose,()=>{
  156. this.closeUI();
  157. },this);
  158. UIButton.BindClick(this.btnJingdian,()=>{
  159. if(this.curSelectMode==room_type._jing_dian_hao_you){
  160. }else{
  161. this.curSelectMode = room_type._jing_dian_hao_you;
  162. this.selectModeChange();
  163. }
  164. },this);
  165. UIButton.BindClick(this.btnMeibujiashi,()=>{
  166. if(this.curSelectMode==room_type._mei_miao_die_jia_hao_you){
  167. }else{
  168. this.curSelectMode = room_type._mei_miao_die_jia_hao_you;
  169. this.selectModeChange();
  170. }
  171. },this);
  172. UIButton.BindClick(this.btn_Jushi_select,()=>{
  173. this.showJuShiSelectView();
  174. },this);
  175. UIButton.BindClick(this.btn_Bushi_select,()=>{
  176. this.showBuShiSelectView();
  177. },this);
  178. UIButton.BindClick(this.btn_Dumiao_select,()=>{
  179. this.showDumiaoSelectView();
  180. },this);
  181. UIButton.BindClick(this.btn_Wofang_select,()=>{
  182. this.showWofangSelectView();
  183. },this);
  184. UIButton.BindClick(this.btn_Meibujiashi_select,()=>{
  185. this.showMeibujiashiSelectView();
  186. },this);
  187. UIButton.BindClick(this.btn_cancel,()=>{
  188. this.closeUI();
  189. },this);
  190. UIButton.BindClick(this.btn_create,()=>{
  191. 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])
  192. },this);
  193. }
  194. hideAllSelectView(){
  195. this.select_jushi_node.active = false;
  196. this.select_bushi_node.active = false;
  197. this.select_meibujiashi_node.active = false;
  198. this.select_wofang_node.active = false;
  199. this.select_dumiao_node.active = false;
  200. }
  201. showJuShiSelectView(){
  202. this.select_node.active = true;
  203. this.hideAllSelectView()
  204. this.showSelectContenAni(this.select_jushi_node);
  205. if(!this.isInitJuShiContent){
  206. let self = this;
  207. for (let index = 0; index < this.select_jushi_content.children.length; index++) {
  208. const jushi_item = this.select_jushi_content.children[index] as Node;
  209. let lab = jushi_item.getChildByName("Label")
  210. if(JU_SHI[index]){
  211. lab.getComponent(Label).string = JU_SHI[index];
  212. }
  213. jushi_item.on(NodeEventType.TOUCH_END,function(){
  214. console.log("选中",JU_SHI[index])
  215. self.curSelectJushiIndex = index;
  216. self.initView()
  217. self.onQuitSelectView()
  218. })
  219. }
  220. this.isInitJuShiContent = true;
  221. }
  222. }
  223. showBuShiSelectView(){
  224. this.select_node.active = true;
  225. this.hideAllSelectView()
  226. this.showSelectContenAni(this.select_bushi_node);
  227. if(!this.isInitBuShiContent){
  228. let self = this;
  229. for (let index = 0; index < this.select_bushi_content.children.length; index++) {
  230. const bushi_item = this.select_bushi_content.children[index] as Node;
  231. let lab = bushi_item.getChildByName("Label")
  232. if(BU_SHI[index]){
  233. lab.getComponent(Label).string = BU_SHI[index];
  234. }
  235. bushi_item.on(NodeEventType.TOUCH_END,function(){
  236. console.log("选中",BU_SHI[index])
  237. self.curSelectBushiIndex = index;
  238. self.initView()
  239. self.onQuitSelectView()
  240. })
  241. }
  242. this.isInitBuShiContent = true;
  243. }
  244. }
  245. showMeibujiashiSelectView(){
  246. this.select_node.active = true;
  247. this.hideAllSelectView()
  248. this.showSelectContenAni(this.select_meibujiashi_node);
  249. if(!this.isInitMeiBuJiaShiContent){
  250. let self = this;
  251. for (let index = 0; index < this.select_meibujiashi_content.children.length; index++) {
  252. const meibujiashi_item = this.select_meibujiashi_content.children[index] as Node;
  253. let lab = meibujiashi_item.getChildByName("Label")
  254. if(MEI_BU_JIA_SHI[index]){
  255. lab.getComponent(Label).string = MEI_BU_JIA_SHI[index];
  256. }
  257. meibujiashi_item.on(NodeEventType.TOUCH_END,function(){
  258. console.log("选中",MEI_BU_JIA_SHI[index])
  259. self.curSelectMeibujiashiIndex = index;
  260. self.initView()
  261. self.onQuitSelectView()
  262. })
  263. }
  264. this.isInitMeiBuJiaShiContent = true;
  265. }
  266. }
  267. showWofangSelectView(){
  268. this.select_node.active = true;
  269. this.hideAllSelectView()
  270. this.showSelectContenAni(this.select_wofang_node);
  271. if(!this.isInitWoFangContent){
  272. let self = this;
  273. for (let index = 0; index < this.select_wofang_content.children.length; index++) {
  274. const wofang_item = this.select_wofang_content.children[index] as Node;
  275. let lab = wofang_item.getChildByName("Label")
  276. if(WO_FANG[index]){
  277. lab.getComponent(Label).string = WO_FANG[index];
  278. }
  279. wofang_item.on(NodeEventType.TOUCH_END,function(){
  280. console.log("选中",WO_FANG[index])
  281. self.curSelectWofangIndex = index;
  282. self.initView()
  283. self.onQuitSelectView()
  284. })
  285. }
  286. this.isInitWoFangContent = true;
  287. }
  288. }
  289. showDumiaoSelectView(){
  290. this.select_node.active = true;
  291. this.hideAllSelectView();
  292. this.showSelectContenAni(this.select_dumiao_node);
  293. if(!this.isInitDuMiaoContent){
  294. let self = this;
  295. for (let index = 0; index < this.select_dumiao_content.children.length; index++) {
  296. const dumiao_item = this.select_dumiao_content.children[index] as Node;
  297. let lab = dumiao_item.getChildByName("Label")
  298. if(DU_MIAO[index]){
  299. lab.getComponent(Label).string = DU_MIAO[index];
  300. }
  301. dumiao_item.on(NodeEventType.TOUCH_END,function(){
  302. console.log("选中",DU_MIAO[index])
  303. self.curSelectDumiaoIndex = index;
  304. self.initView()
  305. self.onQuitSelectView()
  306. })
  307. }
  308. this.isInitDuMiaoContent = true;
  309. }
  310. }
  311. showSelectContenAni(node:Node){
  312. node.scale = new Vec3(1,0.5,1);
  313. node.active = true;
  314. tween(node).to(0.1,{scale:new Vec3(1,1,1)}).start()
  315. }
  316. onQuitSelectView(){
  317. this.select_node.active = false;
  318. }
  319. update(deltaTime: number) {
  320. }
  321. }