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.

588 lines
16 KiB

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