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.

305 lines
8.9 KiB

  1. -- 茶馆桌子ItemLayout
  2. local ClubTableBaoJianItem = class("ClubTableBaoJianItem");
  3. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  4. function ClubTableBaoJianItem:ctor(baoJianInfo,clubId)
  5. --单个茶馆数据
  6. self.clubInfo = app.club_php:getClubInfo(clubId)
  7. self.baoJian = baoJianInfo
  8. self.baoJianId = self.baoJian.baoJianId
  9. self.playerNum = 0;
  10. self.lastPlayerNum = 0;
  11. self.layout = cc.Layout:create()
  12. self.layout:setSize(cc.size(310, 230))
  13. -- 更新界面
  14. self:updateView()
  15. --监听包间名修改
  16. self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_RULE_PUSH , handler(self , self.updateView))
  17. end
  18. function ClubTableBaoJianItem:removeSelf()
  19. if self.layout then
  20. self.layout:removeFromParent()
  21. end
  22. end
  23. function ClubTableBaoJianItem:updateData(baoJian)
  24. self.baoJian = baoJian;
  25. self:updateView();
  26. end
  27. function ClubTableBaoJianItem:updateView()
  28. --显示桌子
  29. self:showTable()
  30. --玩家数据
  31. self:showTableInfo()
  32. --桌子下标
  33. self.tableIndex = nil
  34. --再来一局逻辑
  35. self.conbo = false
  36. local baojiandata = isContinueRoomGamedata()
  37. if baojiandata then
  38. if isContinueRoomGamebol() and baojiandata.baoJianId == self.baoJianId then
  39. self.conbo = true
  40. self.baoJian = isContinueRoomGamedata()
  41. setisContinueRoomGamedata(nil)
  42. self:createRoom()
  43. end
  44. end
  45. self.bPlayAgain = false
  46. local againBaoJianId = getAgainGameBaoJianId()
  47. local bPlayAgain,wanfa = getIsAgainGamebol()
  48. if againBaoJianId ~= -1 and bPlayAgain and self.baoJian.baoJianId == tonumber(againBaoJianId) then
  49. setMyGameCreateStatus(true)
  50. setIsAgainGamebol(false)
  51. self.bPlayAgain = true
  52. self:createRoom()
  53. end
  54. end
  55. function ClubTableBaoJianItem:updatePlayerNum()
  56. self.playerNum = app.club_php:getPlayerNum(self.baoJian)
  57. end
  58. function ClubTableBaoJianItem:showTable()
  59. --更新游戏所需玩家人数
  60. self:updatePlayerNum()
  61. if self.lastPlayerNum ~= self.playerNum then
  62. self.lastPlayerNum = self.playerNum
  63. if self.playerNum == 2 then
  64. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_2.ui");
  65. elseif self.playerNum == 3 then
  66. self.ui = loadUI("res/ui/ui_club/ui_club_table_item.ui");
  67. elseif self.playerNum == 4 then
  68. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_4.ui");
  69. elseif self.playerNum == 5 then
  70. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_5.ui");
  71. elseif self.playerNum == 6 then
  72. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_6.ui");
  73. elseif self.playerNum >= 7 then
  74. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_8.ui");
  75. end
  76. self.ui:bindEvent(app.club,GAME_EVENT.CLUB_CREATE_ERR , handler(self , self.onCreateRoomErr))
  77. self.ui.Items.Layout_Touch:registerClick(handler(self , self.onTouchTable))
  78. if self.layout then
  79. self.layout:removeAllChildren()
  80. self.layout:addChild(self.ui)
  81. end
  82. end
  83. end
  84. --创建桌子失败
  85. function ClubTableBaoJianItem:onCreateRoomErr()
  86. if self.tableIndex then
  87. logD("ClubTableBaoJianItem:onCreateRoomErr = ",tostring(self.tableIndex))
  88. self.tableIndex = self.tableIndex + 1
  89. self:createRoom(self.tableIndex)
  90. end
  91. end
  92. function ClubTableBaoJianItem:hidNode()
  93. if self.baoJian then
  94. local gameId = self.baoJian.realGameId
  95. self.ui.Items.Text_Game_Rule:setText((self.baoJian.title and #self.baoJian.title > 0) and self.baoJian.title or "未设包间名");
  96. local strGameRule = json.decode(self.baoJian.strGameRule)
  97. local gamerule = strGameRule.gamerule or strGameRule.gameRule -- gameRule 为了兼容个别特殊的游戏和线上情况,以后统一用gamerule
  98. local gameNum = self.baoJian.gameNum
  99. local config = getSubGameConfig(tonumber(gameId))
  100. --包间名称
  101. self.ui.Items.ImageView_Game_Rule:setVisible(self.baoJian.title and #self.baoJian.title > 0)
  102. --桌子玩法名称
  103. local ruleName = getSubGameRuleName(self.baoJian.realGameId,gamerule)
  104. self.ui.Items.Text_game_name:setText(tostring(ruleName)..tostring(gameNum).."局")
  105. --桌子信息
  106. local extraInfo = getClubTableRuleString(gameId, self.baoJian.strGameRule,self.playerNum) or ""
  107. self.ui.Items.Text_playernum:setText(extraInfo)
  108. --桌子颜色
  109. local baoJian = self.baoJian
  110. local strExtJson = baoJian.ext or ""
  111. local extInfo = json.decode(strExtJson) or {}
  112. local tableStyle = extInfo.tableStyle or 1
  113. --4人桌子有方有圆特殊处理
  114. local desktopBgPath = string.format("res/ui/zy_club/club_room/club_table_pic/club_room_table_%d_%d.png", tableStyle,self.playerNum)
  115. self.ui.Items.ImageView:loadTexture(desktopBgPath)
  116. end
  117. for i = 1,self.playerNum do
  118. local nodeName = string.format("Layout_player_%d",i);
  119. if self.ui.Items and self.ui.Items[nodeName] then
  120. self.ui.Items[nodeName]:setVisible(false);
  121. end
  122. end
  123. end
  124. function ClubTableBaoJianItem:showTableInfo()
  125. self:hidNode()
  126. --包间桌子不显示下标
  127. self.ui.Items.TextBMFont_table_num:setVisible(false)
  128. end
  129. --点击桌子加入房间
  130. function ClubTableBaoJianItem:onTouchTable()
  131. self.ui.Items.Layout_Touch:setTouchEnabled(false)
  132. self.ui.Items.Layout_Touch:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  133. self.ui.Items.Layout_Touch:setTouchEnabled(true)
  134. end)))
  135. self:createRoom()
  136. end
  137. --开设房间
  138. function ClubTableBaoJianItem:createRoom(newTableIndex)
  139. setisContinueRoomGamebol(false)
  140. if self.clubInfo.status == 2 then
  141. showConfirmDialog(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_DONG_JIE_TIP or PLN.CLUB_DONG_JIE_TIP);
  142. return
  143. end
  144. local memberInfo = self.clubInfo.memberInfo
  145. if memberInfo and memberInfo.status == 0 then
  146. showTooltip("您已被暂停游戏,请联系管理员!")
  147. return
  148. end
  149. local rooms = app.club_php:getBaoJianRooms(self.clubInfo.clubId,self.baoJianId)
  150. local total = 0
  151. for k,v in pairs(rooms) do
  152. --人没满 且未开局
  153. if table.nums(v.players)<self.playerNum and v.status==1 then
  154. total = total+1
  155. end
  156. end
  157. if total >= PLN.CLUB_LIMLIT_TABLE then
  158. showConfirmDialog("亲,已经有"..PLN.CLUB_LIMLIT_TABLE.."张未坐满的桌子,请点击任意一张桌子进入房间!")
  159. return
  160. end
  161. local tableIdx = nil;
  162. if newTableIndex then
  163. tableIdx = newTableIndex
  164. else
  165. --如果是1号包间 房间下标要去掉包间的数量
  166. --local startIndex = self.baoJian.orderId == 1 and table.nums(self.clubInfo.baoJians)+1 or (self.baoJian.orderId - 1) * 100 + 1
  167. local startIndex = (self.baoJian.orderId - 1) * ClubDefine.TableCountMax + 1
  168. for i=startIndex,startIndex + (ClubDefine.TableCountMax - 1) do
  169. if not self.clubInfo.posList[i] then
  170. tableIdx = i
  171. break
  172. end
  173. end
  174. end
  175. if not tableIdx then
  176. showTooltip("当前房间数量已达到上限!")
  177. return
  178. end
  179. local myRoom = app.club_php:getMyInRoom(self.clubInfo.clubId)
  180. if myRoom then
  181. showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  182. return
  183. end
  184. if self.ui.Items.Button_enter_table then
  185. if self.ui.Items.Button_enter_table:isVisible() then
  186. showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
  187. return
  188. end
  189. end
  190. if not app.subGameManager:isInstaller(self.baoJian.realGameId) or app.subGameManager:isNeedUpdate(self.baoJian.realGameId) then
  191. requestDownloadSubGame(self.baoJian.realGameId, function ()
  192. showTooltip("下载完成")
  193. end, true)
  194. return
  195. end
  196. if not isEnableEnterRoom() then
  197. return
  198. end
  199. self.tableIndex = tableIdx
  200. local request = self:getCreateRoomData(tableIdx)
  201. logD("clubCreateRoomRequest() request = ",table.tostring(request));
  202. --开房时记录茶馆id,用于退出房间时返回界面做判断
  203. app.club_php.clubID = self.clubInfo.clubId
  204. app.club:requesetCreateRoomInClub(request)
  205. end
  206. function ClubTableBaoJianItem:getCreateRoomData(tableIdx)
  207. --记录茶馆桌子下标,用于房间切换回茶馆时做判断
  208. app.club_php.tableIdx = tableIdx
  209. local gameId = self.baoJian.realGameId
  210. local request = ClubCreateRoomRequest:new()
  211. request.gameid = gameId--游戏id
  212. request.groupId =self.clubInfo.clubId--茶馆标识
  213. request.groupIndex = tableIdx --茶馆桌子序号
  214. request.groupUid = self.clubInfo.ownerId--茶馆管理员ID
  215. request.groupMemNum = self.clubInfo.playerNum--茶馆成员人数
  216. --游戏局数
  217. request.gameNum = self.baoJian.gameNum
  218. --游戏信息,同游戏创建参数
  219. local gameinfo = self.baoJian.strGameRule
  220. local ttGameInfo = json.decode(gameinfo) or {}
  221. ttGameInfo.clubId = self.clubInfo.clubId
  222. ttGameInfo.tableIdx = tableIdx
  223. ttGameInfo.ruleid = self.baoJianId
  224. ttGameInfo.isArena = app.club_php.isArena
  225. --黄十八兼容性
  226. if gameId == 2 and not ttGameInfo.startMode then
  227. ttGameInfo.startMode = 1
  228. end
  229. gameinfo = json.encode(ttGameInfo)
  230. request.gameInfo = gameinfo
  231. --发起创建的用户信息
  232. local tt = json.decode(app.user.userInfo)
  233. tt.unionid = app.user.unionid
  234. tt.openid = app.user.openid
  235. tt.sex = tonumber(tt.sex)
  236. request.usrinfo =json.encode(tt)
  237. return request;
  238. end
  239. --获取touch层
  240. function ClubTableBaoJianItem:getTouchLayout()
  241. return self.ui.Items.Layout_Touch;
  242. end
  243. --获取下标
  244. function ClubTableBaoJianItem:getTableIdx()
  245. return self.index
  246. end
  247. return ClubTableBaoJianItem