您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

391 行
12 KiB

  1. -- 茶馆桌子ItemLayout
  2. local ClubTableItem = class("ClubTableItem");
  3. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  4. -- clubId :(必需)俱乐部ID
  5. -- realIndex : (必需)桌子的真实下标
  6. -- showIndex :(非必需)桌子用来显示的下标
  7. function ClubTableItem:ctor(clubId, realIndex, showIndex)
  8. self.clubId = clubId;
  9. self.realIndex = realIndex
  10. self.showIndex = showIndex;
  11. --当前桌子是否有人坐下
  12. self.issitdown = false
  13. self.playerNum = 0;
  14. self.lastPlayerNum = 0;
  15. self.layout = cc.Layout:create()
  16. self.layout:setSize(cc.size(310, 230))
  17. self:updateView();
  18. end
  19. function ClubTableItem:removeSelf()
  20. if not tolua.isnull(self.layout) then
  21. self.layout:removeFromParent()
  22. end
  23. end
  24. function ClubTableItem:updateData(clubId, realIndex, showIndex)
  25. logD("ClubTableItem:updateData()", tostring(clubId), tostring(realIndex), tostring(showIndex))
  26. self.clubId = clubId;
  27. self.realIndex = realIndex
  28. self.showIndex = showIndex;
  29. self:updateView();
  30. end
  31. ----
  32. function ClubTableItem:updateView()
  33. logD("ClubTableItem:updateView()", tostring(self.clubId), tostring(self.realIndex))
  34. if not self.clubId or not self.realIndex then
  35. return
  36. end
  37. self.clubInfo = app.club_php:getClubInfo(self.clubId)
  38. if not self.clubInfo then
  39. logD("ClubTableItem:updateView() self.clubInfo is nil!")
  40. return
  41. end
  42. -- 多玩法模式时能拿到房间信息
  43. -- 包间模式可能拿不到房间信息
  44. --[[self.roomInfo = nil
  45. local showRooms, hideRooms = app.club_php:getShowRooms(self.clubId, nil)
  46. for k, v in pairs(showRooms or {}) do
  47. if v.pos == self.realIndex then
  48. self.roomInfo = v
  49. break
  50. end
  51. end--]]
  52. if self.clubInfo.rooms or self.clubInfo.rooms[self.realIndex] then
  53. self.roomInfo = self.clubInfo.rooms[self.realIndex];
  54. end
  55. --显示桌子
  56. self:showTable()
  57. --隐藏
  58. self:hidNode()
  59. --玩家数据
  60. self:showTableInfo()
  61. local againid = getAgainGameBaoJianId()
  62. local againbol,wanfa = getIsAgainGamebol()
  63. if againid ~= -1 and againbol and self.clubInfo.settings.baoJianId == tonumber(againid) and self.issitdown == true then
  64. setMyGameCreateStatus(true)
  65. setAgainGameBaoJianId(-1)
  66. setIsAgainGamebol(false)
  67. setisContinueRoomGamebol(true)
  68. self:onTouchTable()
  69. end
  70. end
  71. function ClubTableItem:updatePlayerNum()
  72. logD("self.clubInfo.mode:",self.clubInfo.mode)
  73. if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then
  74. if self.roomInfo then
  75. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.roomInfo.baoJianId)
  76. self.playerNum = app.club_php:getPlayerNum(baoJian)
  77. logD("ClubTableItem:updatePlayerNum() 1",self.playerNum)
  78. end
  79. else
  80. self.playerNum = app.club_php:getPlayerNum(self.clubInfo.settings)
  81. logD("ClubTableItem:updatePlayerNum() 2")
  82. end
  83. end
  84. function ClubTableItem:showTable()
  85. --更新游戏所需玩家人数
  86. self:updatePlayerNum()
  87. logD("self.playerNum",self.playerNum);
  88. if self.lastPlayerNum ~= self.playerNum then
  89. self.lastPlayerNum = self.playerNum
  90. if self.playerNum == 2 then
  91. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_2.ui");
  92. elseif self.playerNum == 3 then
  93. self.ui = loadUI("res/ui/ui_club/ui_club_table_item.ui");
  94. elseif self.playerNum == 4 then
  95. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_4.ui");
  96. elseif self.playerNum == 5 then
  97. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_5.ui");
  98. elseif self.playerNum == 6 then
  99. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_6.ui");
  100. elseif self.playerNum >= 7 then
  101. self.ui = loadUI("res/ui/ui_club/ui_club_table_item_8.ui");
  102. end
  103. self.ui.Items.Layout_Touch:registerClick(handler(self , self.onTouchTable))
  104. self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_UPDATE_TABLE , handler(self , self.updateTable))
  105. if self.layout then
  106. self.layout:removeAllChildren()
  107. self.layout:addChild(self.ui)
  108. end
  109. end
  110. end
  111. function ClubTableItem:updateTable(event)
  112. if not self.roomInfo or not event or event.pos ~= self.roomInfo.pos then
  113. return
  114. end
  115. self:updateData(self.clubId, self.realIndex,self.showIndex)
  116. end
  117. function ClubTableItem:hidNode()
  118. local baoJian
  119. if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then
  120. baoJian = self.roomInfo and app.club_php:getBaoJian(self.clubInfo.clubId, self.roomInfo.baoJianId)
  121. if baoJian then
  122. local gameId = baoJian.realGameId
  123. local strGameRule = json.decode(baoJian.strGameRule)
  124. local gamerule = strGameRule.gamerule or strGameRule.gameRule -- gameRule 为了兼容个别特殊的游戏和线上情况,以后统一用gamerule
  125. local gameNum = baoJian.gameNum
  126. local config = getSubGameConfig(tonumber(gameId))
  127. self.ui.Items.Text_Game_Rule:setText(baoJian.title or "");
  128. self.ui.Items.ImageView_Game_Rule:setVisible(baoJian.title and string.len(baoJian.title) > 0)
  129. --桌子玩法名称
  130. local ruleName = getSubGameRuleName(baoJian.realGameId,gamerule)
  131. self.ui.Items.Text_game_name:setText(tostring(ruleName)..tostring(gameNum).."局")
  132. --桌子信息
  133. local extraInfo = getClubTableRuleString(gameId, baoJian.strGameRule,self.playerNum) or ""
  134. self.ui.Items.Text_playernum:setText(extraInfo)
  135. end
  136. else
  137. baoJian = self.clubInfo.settings
  138. self.ui.Items.Layout_allMode_info:setVisible(false)
  139. self.ui.Items.ImageView_Game_Rule:setVisible(false)
  140. end
  141. if baoJian then
  142. local gameId = baoJian.realGameId
  143. local config = getSubGameConfig(tonumber(gameId))
  144. --桌子颜色
  145. local strExtJson = baoJian.ext or ""
  146. local extInfo = json.decode(strExtJson) or {}
  147. local tableStyle = extInfo.tableStyle or 1
  148. local desktopBgPath = string.format("res/ui/zy_club/club_room/club_table_pic/club_room_table_%d_%d.png", tableStyle,self.playerNum)
  149. self.ui.Items.ImageView:loadTexture(desktopBgPath)
  150. end
  151. for i = 1,self.playerNum do
  152. local nodeName = string.format("Layout_player_%d",i);
  153. if self.ui.Items and self.ui.Items[nodeName] then
  154. self.ui.Items[nodeName]:setVisible(false);
  155. end
  156. end
  157. end
  158. function ClubTableItem:showTableInfo()
  159. if tolua.isnull(self.ui) then
  160. return
  161. end
  162. local tableInfo = self.roomInfo
  163. if tableInfo == nil then
  164. self.issitdown = true
  165. end
  166. if tableInfo ~= nil then
  167. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId, tableInfo.baoJianId)
  168. if baoJian then
  169. if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then
  170. self.ui.Items.ImageView_Game_Rule:setVisible(baoJian.title and #baoJian.title > 0 and tableInfo.status ~= 2)
  171. end
  172. --桌子玩法名称
  173. if tableInfo.status == 2 then
  174. local strGameRule = json.decode(baoJian.strGameRule)
  175. local gamerule = strGameRule.gamerule
  176. local ruleName = getSubGameRuleName(baoJian.realGameId,gamerule)
  177. self.ui.Items.Text_game_name:setText(tostring(ruleName))
  178. end
  179. end
  180. --人数
  181. local playerIdx = 1;
  182. for k,v in pairsByKeys(tableInfo.players) do
  183. local nodeName = string.format("Layout_player_%d",playerIdx);
  184. if self.ui.Items and self.ui.Items[nodeName] then
  185. self.ui.Items[nodeName]:setVisible(true);
  186. end
  187. --头像
  188. local nodeHeadImg = string.format("ImageView_head_%d",playerIdx);
  189. local nodeHead = self.ui.Items[nodeHeadImg];
  190. if self.ui.Items and nodeHead then
  191. local headSize = nodeHead:getContentSize();
  192. setPlayerHeadImage(v.uid, v.headimgurl, nodeHead);
  193. end
  194. --名字
  195. local nameNode = string.format("Text_player_name_%d",playerIdx);
  196. if self.ui.Items and self.ui.Items[nameNode] then
  197. v.nickname = getSubStringNickname(v.nickname,self.ui.Items[nameNode])
  198. self.ui.Items[nameNode]:setText(v.nickname);
  199. end
  200. --准备状态
  201. local readyNode = string.format("ImageView_ready_%d", playerIdx)
  202. if self.ui.Items and self.ui.Items[readyNode] then
  203. -- -1未收到服务器处理消息0未连接,可判断离线1已登陆,正常为坐下
  204. --2准备3在玩4在玩过程中离线5准备但离线6坐下但离线
  205. if v.state == 2 or v.state == 5 then
  206. self.ui.Items[readyNode]:setVisible(true)
  207. else
  208. self.ui.Items[readyNode]:setVisible(false)
  209. end
  210. if k == tonumber(app.user.loginInfo.uid) then
  211. if v.state == 3 then--自己在游戏中
  212. setMyGameStatus(true)
  213. else
  214. setMyGameStatus(false)
  215. end
  216. end
  217. end
  218. --离线状态
  219. local offlineNode = string.format("ImageView_offline_%d", playerIdx)
  220. if self.ui.Items and self.ui.Items[offlineNode] then
  221. if v.state==4 or v.state==5 or v.state==6 then
  222. self.ui.Items[offlineNode]:setVisible(true)
  223. else
  224. self.ui.Items[offlineNode]:setVisible(false)
  225. end
  226. end
  227. --分数
  228. local scoreText = string.format("Text_score_%d", playerIdx)
  229. local scoreNode = string.format("ImageView_score_%d", playerIdx)
  230. if self.ui.Items and self.ui.Items[scoreText] then
  231. if self.roomInfo.status==1 or not v.score then
  232. self.ui.Items[scoreNode]:setVisible(false)
  233. else
  234. self.ui.Items[scoreNode]:setVisible(true)
  235. if v.score>0 then
  236. self.ui.Items[scoreText]:setTextColor(cc.c4b(255,227,113,255))
  237. self.ui.Items[scoreText]:setText("+"..v.score)
  238. else
  239. self.ui.Items[scoreText]:setTextColor(cc.c4b(140,232,255,255))
  240. self.ui.Items[scoreText]:setText(v.score)
  241. end
  242. end
  243. end
  244. playerIdx = playerIdx + 1;
  245. end
  246. -- self:updatePlayerNum()
  247. for i = playerIdx,self.playerNum do
  248. local nodeName = string.format("Layout_player_%d",i);
  249. if self.ui.Items and self.ui.Items[nodeName] then
  250. self.ui.Items[nodeName]:setVisible(false);
  251. end
  252. end
  253. else
  254. self:hidNode();
  255. end
  256. self.ui.Items.TextBMFont_table_num:setText(self.showIndex)
  257. self.ui.Items.TextBMFont_table_num:setVisible(false)
  258. self:updatePlayerReadyStatus()
  259. self:updateJushu()
  260. end
  261. --单独更新玩家准备状态
  262. function ClubTableItem:updatePlayerReadyStatus()
  263. if self.roomInfo ~= nil and table.nums(self.roomInfo) > 0 and table.nums(self.roomInfo.players) > 0 then
  264. local playerIdx = 1;
  265. for k,v in pairsByKeys(self.roomInfo.players) do
  266. --准备状态
  267. local readyNode = string.format("ImageView_ready_%d", playerIdx)
  268. if self.ui.Items and self.ui.Items[readyNode] then
  269. -- -1未收到服务器处理消息0未连接,可判断离线1已登陆,正常为坐下2准备3在玩4在玩过程中离线5准备但离线6坐下但离线
  270. if v.state == 2 or v.state == 5 then
  271. self.ui.Items[readyNode]:setVisible(true)
  272. else
  273. self.ui.Items[readyNode]:setVisible(false)
  274. end
  275. end
  276. playerIdx = playerIdx + 1;
  277. end
  278. end
  279. end
  280. --单独更新局数
  281. function ClubTableItem:updateJushu()
  282. if self.roomInfo ~= nil and table.nums(self.roomInfo) > 0 and table.nums(self.roomInfo.players) > 0 then
  283. --当前状态1未开局 2开局
  284. if self.roomInfo.status == 1 then
  285. --self.ui.Items.Text_jushu:setText("准备中");
  286. else
  287. self.ui.Items.Layout_allMode_info:setVisible(true)
  288. self.ui.Items.ImageView_rule_bg:setVisible(true)
  289. self.ui.Items.Text_game_name:setVisible(true)
  290. local jushuStr = string.format("第%d/%d局",self.roomInfo.currentNum,self.roomInfo.totalNum)
  291. self.ui.Items.Text_playernum:setText(jushuStr);
  292. end
  293. end
  294. end
  295. --点击桌子加入房间
  296. function ClubTableItem:onTouchTable()
  297. if not tolua.isnull(self._tableMenuView) then
  298. self._tableMenuView:removeFromParent()
  299. end
  300. self._tableMenuView = nil
  301. local bRuleChange = getRuleChangeStatus()
  302. if bRuleChange then
  303. local againbol,wanfa = getIsAgainGamebol()
  304. if wanfa ~= "" then
  305. showTooltip("房间创建失败,该包间玩法已被删除或修改!")
  306. end
  307. setIsAgainGamebol(false,"")
  308. setRuleChangeStatus(false)
  309. setisContinueRoomGamebol(false)
  310. return
  311. end
  312. local tableMenuView = import("luaScript.Views.Club.ClubTableOperatMenu"):new(self.clubId, self.realIndex, self.showIndex)
  313. tableMenuView.ui.Items.Button_enter_table = self.ui.Items.Button_enter_table
  314. tableMenuView:setAnchorPoint(cc.p(0.5, 0.5))
  315. local worldPos = self.ui.Items.ImageView:getWorldPosition();
  316. local x = worldPos.x + 20;
  317. local y = worldPos.y
  318. local newPos = cc.p(x, y);
  319. tableMenuView:setPosition(newPos);
  320. app:showWaitDialog(tableMenuView, 0, true)
  321. end
  322. --获取touch层
  323. function ClubTableItem:getTouchLayout()
  324. return self.ui.Items.Layout_Touch;
  325. end
  326. --获取下标
  327. function ClubTableItem:getTableIdx()
  328. return self.realIndex
  329. end
  330. return ClubTableItem