You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

634 lines
18 KiB

  1. -- 桌子操作按钮Layout
  2. local ClubTableNewOperatMenu = class("ClubTableNewOperatMenu" , cc.UIView);
  3. --按钮对应编号
  4. -- 1 : 邀请好友
  5. -- 2 : 进入游戏
  6. -- 3 : 解散房间
  7. -- 4 : 踢出房间
  8. -- tableIndex:点击桌子的下标
  9. -- menuIdxs = {1,2,3,4}
  10. -- callback : 点击按钮之后的回调
  11. function ClubTableNewOperatMenu:ctor(tableIndex,clubId,showIndex,isgamebol)
  12. ClubTableNewOperatMenu.super.ctor(self)
  13. self:loadUI()
  14. --单个茶馆数据
  15. self.clubInfo = app.club_php.clubList[clubId]
  16. self.tableIndex = tableIndex
  17. self.showIndex = showIndex
  18. --是否直接进入
  19. self.directbol = true
  20. if isgamebol == false then
  21. self.directbol = isgamebol
  22. end
  23. self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground))
  24. if isContinueRoomGamebol() then
  25. setisContinueRoomGamebol(false)
  26. setIsRoomGamedata(nil)
  27. self:onGameEnter()
  28. end
  29. end
  30. function ClubTableNewOperatMenu:loadUI()
  31. local ui = loadUI("res/ui/ui_club/clubnew/ui_club_table_operat_menu_new.ui")
  32. self.ui = ui
  33. self:addChild(ui)
  34. end
  35. function ClubTableNewOperatMenu:getMenus()
  36. -- 1 : 邀请好友
  37. -- 2 : 进入游戏
  38. -- 3 : 解散房间
  39. -- 4 : 踢出房间
  40. local ttMenuIdx = {}
  41. if self.clubInfo ~= nil then
  42. if table.nums(self.clubInfo.rooms) <= 0 then
  43. --此桌子没有开房
  44. if self.clubInfo.role == 2 or self.clubInfo.role == 3 then
  45. -- 邀请好友
  46. table.insert(ttMenuIdx, 1)
  47. -- 进入游戏
  48. table.insert(ttMenuIdx, 2)
  49. end
  50. else
  51. --当前桌子已有房间信息
  52. if self.clubInfo.role == 2 or self.clubInfo.role == 3 then
  53. --2:管理员 3:创始人
  54. -- 邀请好友
  55. table.insert(ttMenuIdx, 1)
  56. -- 进入游戏
  57. table.insert(ttMenuIdx, 2)
  58. if self.clubInfo.rooms[self.tableIndex] ~= nil then
  59. --只有管理员和创始人才有解散房间权限
  60. table.insert(ttMenuIdx, 3)
  61. --当前房间是否已开局
  62. local gameStatus = self.clubInfo.rooms[self.tableIndex].status
  63. if gameStatus == 1 and table.nums(self.clubInfo.rooms[self.tableIndex].players) > 0 then
  64. --未开局且有一个以上用户,没用户,不需要显示踢出按钮
  65. -- 踢出房间
  66. table.insert(ttMenuIdx, 4)
  67. end
  68. end
  69. end
  70. end
  71. else
  72. -- 邀请好友
  73. table.insert(ttMenuIdx, 1)
  74. -- 进入游戏
  75. table.insert(ttMenuIdx, 2)
  76. end
  77. return ttMenuIdx;
  78. end
  79. function ClubTableNewOperatMenu:onEnter()
  80. ClubTableNewOperatMenu.super.onEnter(self)
  81. -- 注册点击事件
  82. for i =1,4 do
  83. local name = string.format("Button_%d",i)
  84. local node = self.ui.Items[name]
  85. if node then
  86. node:registerClick(function()
  87. self:onClickButton(i)
  88. end)
  89. end
  90. end
  91. -- 将需要显示的按钮索引标为 true
  92. local menus = self:getMenus()
  93. if #menus==0 then --如果没有菜单按钮显示直接进入
  94. self.ui:setVisible(false)
  95. runInNextFrame(function()
  96. if self.directbol == true then
  97. self:onClickEnter()
  98. end
  99. self:removeFromParent()
  100. end)
  101. return
  102. end
  103. local tt = {}
  104. for k,idx in pairs(menus) do
  105. tt[idx] = true
  106. end
  107. -- 隐藏不相关的按钮
  108. for i = 1,4 do
  109. local name = string.format("Layout_Btn_%d", i)
  110. local node = self.ui.Items[name]
  111. if node then
  112. -- 标记为true的显示
  113. -- 否则不显示
  114. if tt[i] then
  115. node:setVisible(true)
  116. else
  117. node:setVisible(false)
  118. end
  119. end
  120. end
  121. -- 重新布局
  122. self.ui.Items.Layout_btn_menu:requestDoLayout()
  123. self.ui.Items.Layout_btn_menu:doLayout()
  124. end
  125. --设置管理员
  126. function ClubTableNewOperatMenu:onClickButton(idx)
  127. if idx==1 then
  128. self:onClickInvite()
  129. elseif idx==2 then
  130. self:onClickEnter()
  131. elseif idx==3 then
  132. self:onClickJieSan()
  133. elseif idx==4 then
  134. self:onClickKick()
  135. end
  136. if idx~=4 then
  137. self:removeFromParent()
  138. end
  139. end
  140. function ClubTableNewOperatMenu:getMoreLayout()
  141. return self.ui.Items.Layout_more;
  142. end
  143. function ClubTableNewOperatMenu:onClickInvite()
  144. local gameId = "";
  145. local rooID = ""
  146. local contStr = ""
  147. local tableIdx = self.tableIndex
  148. if self.clubInfo ~= nil then
  149. if self.clubInfo.mode == 1 then
  150. if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then
  151. --获取游戏id(多玩法只能在包间信息里获取游戏id,roomlist里面没有)
  152. local baoJianId = self.clubInfo.rooms[tableIdx].baoJianId
  153. local baoJian = self.clubInfo.baoJians[baoJianId]
  154. if baoJian then
  155. gameId = baoJian.gameId
  156. end
  157. end
  158. else
  159. if self.clubInfo.settings ~= nil then
  160. gameId = self.clubInfo.settings.gameId
  161. end
  162. end
  163. if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then
  164. rooID = self.clubInfo.rooms[tableIdx].roomId
  165. contStr = "\n复制信息打开游戏将自动入座"
  166. end
  167. end
  168. --游戏名+房间号
  169. local gameName = getSubGameName(gameId) or ""
  170. if rooID ~= "" then
  171. gameName = string.format("%s[%d]", gameName, rooID)
  172. end
  173. --桌子号
  174. local tableNum = string.format("%d号桌", tonumber(self.showIndex))
  175. --房间设置的玩法
  176. local setStr = ""
  177. local setInfo = self.clubInfo.settings
  178. if table.nums(setInfo) > 0 then
  179. -- local ruleID = json.encode(setInfo);
  180. local tt = getRuleFromString(setInfo.gameId, setInfo.gameNum, setInfo.strGameRule)
  181. for k,v in ipairs(tt) do
  182. -- 内容
  183. local text = ""
  184. for kk, vv in pairs(v.value) do
  185. if "" == text then
  186. text = vv
  187. else
  188. text = text .. " " .. vv
  189. end
  190. end
  191. setStr = setStr .. v.name.. ":" .. text .." "
  192. end
  193. end
  194. local _name = (app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME)
  195. local copyData = string.format("%s %sID【%s】\n%s\n %s %s%s",self.clubInfo.clubName,
  196. _name,
  197. self.clubInfo.clubId,
  198. gameName,
  199. tableNum,
  200. setStr,
  201. contStr)
  202. --需要显示的按钮(1:微信 2:复制 3:茶馆 )
  203. local menuIdxs = {1,4,5,6}
  204. local title = string.format("%s名称:%s",_name, self.clubInfo.clubName)
  205. local content = string.format("可视化牌桌,不用自己开房就可以玩牌。")
  206. local desc = string.format("%sID:%s\n%s",_name, self.clubInfo.clubId,content)
  207. local info = {}
  208. info.ClubID = self.clubInfo.clubId
  209. info.title = title
  210. info.description = desc
  211. print("用户开始分享")
  212. --需要显示的按钮(1:微信 2:复制 3:茶馆 )
  213. if type(menuIdxs) ~= "table" then
  214. info.menuIdxs = {1,4,5,6}
  215. end
  216. if type(copyData) == "string" then
  217. info.copyData = copyData
  218. else
  219. info.copyData = ""
  220. end
  221. local view = import("luaScript.Views.Main.ShareView"):new(info)
  222. view:setAnchorPoint(cc.p(0.5, 0.5))
  223. app:showWaitDialog(view)
  224. end
  225. function ClubTableNewOperatMenu:onGameEnter()
  226. local rooms = self.clubInfo.rooms
  227. local room = rooms[self.tableIndex]
  228. local baojian = room and app.club_php:getBaoJian(self.clubInfo.clubId,room.baoJianId) or nil
  229. local settings =self.clubInfo.mode==1 and baojian or self.clubInfo.settings
  230. local myRoom = app.club_php:getMyInRoom()
  231. if room then --如果点击的桌子存在
  232. if myRoom then
  233. -- if myRoom == room then
  234. local view = app:getCurrentView()
  235. -- logD(view.__cname)
  236. if view and view.__cname ~= "MainView" then --没有主界面则在房间界面
  237. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  238. else
  239. self:joinClubRoom(self.tableIndex,room.roomId,settings)
  240. end
  241. return
  242. end
  243. if self.ui.Items.Button_enter_table then
  244. if self.ui.Items.Button_enter_table:isVisible() then
  245. local view = app:getCurrentView()
  246. if view and view.__cname ~= "MainView" then --没有主界面则在房间界面
  247. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  248. else
  249. self:joinClubRoom(self.tableIndex,room.roomId,settings)
  250. end
  251. return
  252. end
  253. end
  254. local gameConfig = getSubGameConfig(self.clubInfo.settings.gameId) or {}
  255. local num = app.club_php:getPlayerNum(settings)
  256. if gameConfig.isSupportWatch or table.nums(room.players) < num then
  257. self:joinClubRoom(self.tableIndex,room.roomId,settings)
  258. else
  259. showTooltip("当前桌子已经坐满!")
  260. end
  261. else
  262. showTooltip("当前桌子已经坐满!")
  263. end
  264. end
  265. function ClubTableNewOperatMenu:onClickEnter()
  266. local rooms = self.clubInfo.rooms
  267. local room = rooms[self.tableIndex]
  268. local baojian = room and app.club_php:getBaoJian(self.clubInfo.clubId,room.baoJianId) or nil
  269. local settings =self.clubInfo.mode==1 and baojian or self.clubInfo.settings
  270. local myRoom = app.club_php:getMyInRoom()
  271. if room then --如果点击的桌子存在
  272. -- if myRoom or self.ui.Items.Button_enter_table:isVisible() then
  273. if myRoom then
  274. if myRoom == room then
  275. local view = app:getCurrentView()
  276. -- logD(view.__cname)
  277. if view and view.__cname ~= "MainView" then --没有主界面则在房间界面
  278. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  279. else
  280. self:joinClubRoom(self.tableIndex,room.roomId,settings)
  281. end
  282. else
  283. if room.status == 2 then
  284. local gameConfig = getSubGameConfig(self.clubInfo.settings.gameId) or {}
  285. local num = app.club_php:getPlayerNum(settings)
  286. if gameConfig.isSupportWatch or table.nums(room.players) < num then
  287. self:joinClubRoom(self.tableIndex,room.roomId,settings)
  288. else
  289. showTooltip("当前桌子已经坐满!")
  290. end
  291. else
  292. -- showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  293. if getMyGameStatus() == false then
  294. local content = "加入新牌桌需退出当前牌桌,是否继续?";
  295. local function onOk()
  296. -- setisContinueRoomGamedata(baojian)
  297. local param = {
  298. clubInfo = self.clubInfo,
  299. tableIndex = self.tableIndex,
  300. showIndex = self.showIndex,
  301. }
  302. setIsRoomGamedata(param)
  303. self.ui:sendMsg(app.room, "callLeaveRequest")
  304. end
  305. local function onCancel()
  306. end
  307. showConfirmDialog(content, onOk,onCancel);
  308. else
  309. showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  310. end
  311. end
  312. end
  313. return
  314. else
  315. local view = app:getCurrentView()
  316. local isInMainView = view.__cname == "MainView"
  317. if not isInMainView then
  318. showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  319. return
  320. end
  321. end
  322. local gameConfig = getSubGameConfig(self.clubInfo.settings.gameId) or {}
  323. local num = app.club_php:getPlayerNum(settings)
  324. if gameConfig.isSupportWatch or table.nums(room.players) < num then
  325. self:joinClubRoom(self.tableIndex,room.roomId,settings)
  326. else
  327. showTooltip("当前桌子已经坐满!")
  328. end
  329. else
  330. -- if myRoom or self.ui.Items.Button_enter_table:isVisible() then
  331. if myRoom then
  332. -- showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  333. if getMyGameStatus() == false then
  334. local content = "加入新牌桌需退出当前牌桌,是否继续?";
  335. local function onOk()
  336. -- setisContinueRoomGamedata(baojian)
  337. local param = {
  338. clubInfo = self.clubInfo,
  339. tableIndex = self.tableIndex,
  340. showIndex = self.showIndex,
  341. }
  342. setIsRoomGamedata(param)
  343. self.ui:sendMsg(app.room, "callLeaveRequest")
  344. end
  345. local function onCancel()
  346. end
  347. showConfirmDialog(content, onOk,onCancel);
  348. else
  349. showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  350. end
  351. return
  352. else
  353. local view = app:getCurrentView()
  354. local isInMainView = view.__cname == "MainView"
  355. if not isInMainView then
  356. showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  357. return
  358. end
  359. end
  360. self:createRoom(settings)
  361. end
  362. end
  363. function ClubTableNewOperatMenu:createRoom(ruleInfo)
  364. if self.clubInfo.status == 2 then
  365. showConfirmDialog(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_DONG_JIE_TIP or PLN.CLUB_DONG_JIE_TIP);
  366. return
  367. end
  368. if table.nums(ruleInfo) <= 0 then
  369. showConfirmDialog("未设置游戏玩法,请先设置游戏玩法后再来开房!")
  370. return
  371. end
  372. local memberInfo = self.clubInfo.memberInfo
  373. if memberInfo and memberInfo.status == 0 then
  374. showTooltip("您已被暂停游戏,请联系管理员!")
  375. return
  376. end
  377. if not app.subGameManager:isInstaller(tonumber(ruleInfo.gameId)) or app.subGameManager:isNeedUpdate(tonumber(ruleInfo.gameId)) then
  378. requestDownloadSubGame(tonumber(ruleInfo.gameId), function ()
  379. showTooltip("下载完成")
  380. end, true)
  381. return
  382. end
  383. --[[if tonumber(ruleInfo.gameId) ~= GAME_IDS.LuZhouMJ then
  384. showTooltip("开发中...")
  385. return
  386. end--]]
  387. local request = self:getCreateRoomData(self.tableIndex, ruleInfo);
  388. print("clubCreateRoomRequest() request = ",table.tostring(request));
  389. --开房时记录茶馆id,用于退出房间时返回界面做判断
  390. app.club_php.clubID = self.clubInfo.clubId
  391. app.club:requesetCreateRoomInClub(request)
  392. end
  393. function ClubTableNewOperatMenu:getCreateRoomData(index, ruleInfo)
  394. --局数
  395. local jushu = 0;
  396. if table.nums(ruleInfo) > 0 then
  397. jushu = ruleInfo.gameNum;
  398. end
  399. local tableIdx = index;
  400. --记录茶馆桌子下标,用于房间切换回茶馆时做判断
  401. app.club_php.tableIdx = tableIdx
  402. local request = ClubCreateRoomRequest:new()
  403. request.gameid = tonumber(ruleInfo.gameId);--游戏id
  404. request.groupId = tonumber(self.clubInfo.clubId);--茶馆标识
  405. request.groupIndex = tostring(tableIdx); --茶馆桌子序号
  406. request.groupUid = tonumber(self.clubInfo.ownerId);--茶馆管理员ID
  407. request.groupMemNum = tonumber(self.clubInfo.playerNum);--茶馆成员人数
  408. --游戏局数
  409. request.gameNum = jushu;
  410. --游戏信息,同游戏创建参数
  411. local gameinfo = ruleInfo.strGameRule
  412. local ttGameInfo = json.decode(gameinfo) or {}
  413. ttGameInfo.clubId = tonumber(self.clubInfo.clubId)
  414. ttGameInfo.tableIdx = tonumber(tableIdx)
  415. ttGameInfo.ruleid = tostring(ruleInfo.baoJianId)
  416. --柳州字牌增加23人玩法
  417. if tonumber(ruleInfo.gameId) == 20 and not ttGameInfo.startMode then
  418. ttGameInfo.startMode = 1
  419. end
  420. gameinfo = json.encode(ttGameInfo)
  421. request.gameInfo = gameinfo
  422. --发起创建的用户信息
  423. local tt = json.decode(app.user.userInfo)
  424. tt.unionid = app.user.unionid
  425. tt.openid = app.user.openid
  426. tt.sex = tonumber(tt.sex)
  427. request.usrinfo =json.encode(tt)
  428. return request;
  429. end
  430. function ClubTableNewOperatMenu:joinClubRoom( index, roomid, ruleInfo)
  431. if self.clubInfo.status == 2 then
  432. showConfirmDialog("当前茶馆已被冻结,请联系馆主解冻茶馆!");
  433. return;
  434. end
  435. local memberInfo = self.clubInfo.memberInfo
  436. if memberInfo and memberInfo.status == 0 then
  437. showTooltip("您已被暂停游戏,请联系管理员!")
  438. return
  439. end
  440. if not app.subGameManager:isInstaller(tonumber(ruleInfo.gameId)) or app.subGameManager:isNeedUpdate(tonumber(ruleInfo.gameId)) then
  441. requestDownloadSubGame(tonumber(ruleInfo.gameId), function ()
  442. showTooltip("下载完成")
  443. end, true)
  444. return
  445. end
  446. local request = ClubJoinRoomRequest:new()
  447. request.gameid = tonumber(ruleInfo.gameId); --游戏id
  448. request.tableid = tonumber(roomid); --房间号
  449. request.grouId = tonumber(self.clubInfo.clubId); --茶馆标识
  450. request.groupIndex = tonumber(index); --茶馆桌子序号
  451. --发起创建的用户信息
  452. local tt = json.decode(app.user.userInfo)
  453. tt.unionid = app.user.unionid
  454. tt.openid = app.user.openid
  455. tt.sex = tonumber(sex)
  456. request.usrinfo =json.encode(tt)
  457. --游戏信息,同游戏创建参数
  458. local gameinfo = json.decode(ruleInfo.strGameRule)
  459. if gameinfo then
  460. request.gamerule = gameinfo.gamerule
  461. end
  462. print("clubJoinRoomRequest() request = ",table.tostring(request));
  463. --开房时记录茶馆id,用于退出房间时返回界面做判断
  464. app.club_php.clubID = self.clubInfo.clubId;
  465. local createRoomRequest = self:getCreateRoomData(index, ruleInfo);
  466. app.club:requestJoinRoomInClub(request, createRoomRequest)
  467. end
  468. --点击解散
  469. function ClubTableNewOperatMenu:onClickJieSan()
  470. --解散房间
  471. local content = "是否要强制解散当前正在游戏的"..tostring(self.showIndex).."号桌子?";
  472. local gameId = "";
  473. local roomid = "";
  474. local tableIdx = self.tableIndex
  475. if self.clubInfo ~= nil then
  476. if self.clubInfo.mode == 1 then
  477. -- tableIdx = tonumber(self.tableIndex)
  478. if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then
  479. --房间号
  480. roomid = self.clubInfo.rooms[tableIdx].roomId
  481. --获取游戏id(多玩法只能在包间信息里获取游戏id,roomlist里面没有)
  482. local baoJianId = self.clubInfo.rooms[tableIdx].baoJianId
  483. local baoJian = self.clubInfo.baoJians[baoJianId]--app.club_php.clubRuleList;
  484. if baoJian then
  485. gameId = baoJian.gameId
  486. end
  487. end
  488. else
  489. gameId = self.clubInfo.settings.gameId
  490. if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then
  491. roomid = self.clubInfo.rooms[tableIdx].roomId
  492. end
  493. end
  494. end
  495. --确认回调
  496. local function okCallback()
  497. local dismissInfo = ClubDismissRequest:new()
  498. --游戏id
  499. dismissInfo.gameid = gameId
  500. --房间号
  501. dismissInfo.tableid = roomid
  502. --茶馆id
  503. dismissInfo.groupid = self.clubInfo.clubId
  504. app.club:requestDismissInClub(dismissInfo)
  505. end
  506. local function onCancel()
  507. end
  508. showConfirmDialog(content, okCallback, onCancel, nil);
  509. end
  510. function ClubTableNewOperatMenu:onClickKick()
  511. local function onClose()
  512. self:removeFromParent()
  513. end
  514. local director = cc.Director:getInstance()
  515. local resolutionSize = director:getOpenGLView():getDesignResolutionSize()
  516. --踢出房间
  517. local view = import("luaScript.Views.Club.ClubTableKickMenu"):new(self.clubInfo.clubId, self.tableIndex ,onClose)
  518. view:setAnchorPoint(cc.p(0.5, 0.5))
  519. --计算坐标
  520. local viewNode = self:getMoreLayout();
  521. local worldPos = viewNode:getWorldPosition();
  522. local viewContentSize = cc.size(545, 80);
  523. local x = worldPos.x + viewNode:getContentSize().width;
  524. if worldPos.x>resolutionSize.width/2 then
  525. x = worldPos.x - viewContentSize.width;
  526. view.ui.Items.ImageView_1:setVisible(false)
  527. else
  528. view.ui.Items.ImageView_2:setVisible(false)
  529. end
  530. local y = worldPos.y;
  531. local newPos = cc.p(x, y);
  532. view:setPosition(newPos);
  533. app:showWaitDialog(view, 0, true);
  534. self._kickTableMenu = view
  535. end
  536. function ClubTableNewOperatMenu:onApplicationDidEnterBackground()
  537. if not tolua.isnull(self._kickTableMenu) then
  538. self._kickTableMenu:removeFromParent()
  539. end
  540. self._kickTableMenu = nil
  541. end
  542. return ClubTableNewOperatMenu