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.

337 lines
10 KiB

  1. --茶馆包间Layout
  2. local ClubBaojian = class("ClubBaojian",cc.UIView)
  3. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  4. function ClubBaojian:ctor(clubId)
  5. --单个茶馆数据
  6. self.clubInfo = app.club_php.clubList[clubId]
  7. self:initUI()
  8. self:initBindEvent()
  9. self.lastSendAdd = 0
  10. --请求茶馆游戏玩法总配置
  11. app.club_php:requestGameRule(self.clubInfo.clubId)
  12. end
  13. function ClubBaojian:initUI()
  14. self.ui = loadUI("res/ui/ui_club/ui_club_baojian.ui")
  15. self:addChild(self.ui)
  16. self.ui.Items.Layout_baojian_item:setVisible(false);
  17. self.ui.Items.Layout_baojian_create:setVisible(false);
  18. self.ui.Items.Layout_show_rule:setVisible(false)
  19. if app.club_php:getCestIsOpen(self.clubInfo.clubId) then
  20. self.ui.Items.ImageView_title:loadTexture("res/ui/zy_club/club_room/club_baojian/club_cest_bisai_title.png")
  21. end
  22. end
  23. function ClubBaojian:initBindEvent()
  24. --如果添加新的游戏玩法成功了,游戏被激活,需要重新计算未激活游戏的数量
  25. self:bindEvent(app.club_php , GAME_EVENT.CLUB_CALUATE_ACTIVE_GAME , handler(self , self.onUpdateActiveGame))
  26. --请求茶馆玩法回调
  27. self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_RULE_PUSH , handler(self , self.updateBaoJian))
  28. --切换包间时候会重新请求桌子需要刷新一下
  29. self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_TABLE , handler(self , self.updateBaoJian))
  30. --获取游戏数据
  31. self:bindEvent(app.club_php , GAME_EVENT.CLUB_GAME_RULE , handler(self , self.onClubGameRule));
  32. --激活包间成功后关闭
  33. self:bindEvent(app.club_php , GAME_EVENT.CLUB_ACTIVE_RULE , handler(self , self.onActiveRuleResponse))
  34. end
  35. function ClubBaojian:onActiveRuleResponse(data)
  36. local status = data.status
  37. local groupView = self.ui.Items.ScrollView_BaoJian
  38. local pos = groupView:getInnerContainer():getPosition()
  39. if status == 0 then
  40. groupView:getInnerContainer():requestDoLayout()
  41. groupView:getInnerContainer():doLayout()
  42. groupView:requestDoLayout()
  43. groupView:doLayout()
  44. groupView:getInnerContainer():setPosition(cc.p(0,0))
  45. end
  46. end
  47. function ClubBaojian:updateBaoJian()
  48. local baoJians = self.clubInfo.baoJians
  49. --包间个数
  50. local baojianNum = table.nums(baoJians)
  51. local groupView = self.ui.Items.ScrollView_BaoJian
  52. groupView:getInnerContainer():setAutoSize(true)
  53. groupView:hideAllBar()
  54. groupView:removeAllChildren()
  55. local uiTemplate = self.ui.Items.Layout_baojian_item
  56. local index = 1
  57. --包间排序
  58. local newBaoJians = app.club_php:getSortClubBaoJians(self.clubInfo.clubId)
  59. for _,baojian in ipairs(newBaoJians) do
  60. if tonumber(baojian.is_use) == 1 then
  61. local uiItem = uiTemplate:getCopied()
  62. uiItem.Items = getUIItems(uiItem)
  63. local gameId = baojian.realGameId
  64. --包间下标
  65. uiItem.Items.Text_index:setText(index)
  66. --包间名
  67. local baojianName = baojian.title
  68. if not baojianName or baojianName == "" then
  69. if self.clubInfo.role == ClubDefine.Job.Manager or self.clubInfo.role == ClubDefine.Job.Creator then
  70. baojianName = "设置包间名"
  71. if app.club_php:getCestIsOpen(self.clubInfo.clubId) then
  72. baojianName = "设置赛事名"
  73. end
  74. else
  75. baojianName = "管理员未设置名字"
  76. end
  77. end
  78. uiItem.Items.Text_baojian_name:setText(baojianName)
  79. -- 局数
  80. uiItem.Items.Text_jushu:setText(baojian.gameNum.."局")
  81. -- 玩法名
  82. local rules = json.decode(baojian.strGameRule);
  83. local gamerule = rules.gamerule or rules.gameRule
  84. if gamerule then
  85. local ruleName = getSubGameRuleName(gameId, gamerule)
  86. uiItem.Items.Text_rule:setText(ruleName)
  87. end
  88. if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then
  89. uiItem.Items.ImageView_selected:setVisible(false)
  90. else
  91. --普通模式添加切换包间
  92. uiItem.Items.Layout_touch_item:registerClick(function ()
  93. --选择当前包间
  94. playBtnEffect()
  95. app.club_php:requestRuleSet(self.clubInfo.clubId, baojian.baoJianId, 1, 1)
  96. end)
  97. logD("self.clubInfo.settings.baoJianId:",self.clubInfo.settings.baoJianId)
  98. if self.clubInfo.settings.baoJianId == baojian.baoJianId then
  99. uiItem.Items.ImageView_selected:setVisible(true)
  100. else
  101. uiItem.Items.ImageView_selected:setVisible(false)
  102. end
  103. end
  104. --(1:成员 2:管理员 3:创始人)
  105. if (self.clubInfo.role == ClubDefine.Job.Manager or self.clubInfo.role == ClubDefine.Job.Creator) and not app.club_php:getIsSlaveUnion(self.clubInfo.clubId) then
  106. uiItem.Items.Button_change_name:setVisible(true)
  107. uiItem.Items.Button_set_rule:setVisible(true)
  108. uiItem.Items.Button_look:setVisible(false)
  109. --包间名修改
  110. uiItem.Items.Button_change_name:registerClick(function ()
  111. playBtnEffect()
  112. local view = import("luaScript.Views.Club.ClubBaojianChangeName"):new(self.clubInfo.clubId, baojian.baoJianId, baojian.title)
  113. view:setAnchorPoint(cc.p(0.5, 0.5))
  114. app:showWaitDialog(view)
  115. end)
  116. --修改玩法规则
  117. uiItem.Items.Button_set_rule:registerClick(function ()
  118. playBtnEffect()
  119. local view = import("luaScript.Views.Club.ClubChangeRule"):new(self.clubInfo.clubId, baojian.gameId, gamerule, baojian.baoJianId)
  120. view:setAnchorPoint(cc.p(0.5, 0.5))
  121. app:showWaitDialog(view)
  122. end)
  123. else
  124. uiItem.Items.Button_change_name:setVisible(false)
  125. uiItem.Items.Button_set_rule:setVisible(false)
  126. uiItem.Items.Button_look:setVisible(true)
  127. --查看玩法详情
  128. uiItem.Items.Button_look:registerClick(function ()
  129. playBtnEffect()
  130. self:showBaojianRuleInfo(uiItem, baojian,uiItem.Items.Button_look)
  131. end)
  132. end
  133. groupView:addChild(uiItem)
  134. index = index + 1
  135. end
  136. end
  137. --包间小于后台下发的个数 显示添加按钮
  138. if self.noActiveGames and type(self.noActiveGames) == "table" and table.nums(self.noActiveGames) > 0 and (self.clubInfo.role == ClubDefine.Job.Manager
  139. or self.clubInfo.role == ClubDefine.Job.Creator) and not app.club_php:getIsSlaveUnion(self.clubInfo.clubId) then
  140. local uiAddItem = self.ui.Items.Layout_baojian_create:getCopied()
  141. uiAddItem.Items = getUIItems(uiAddItem)
  142. --新增包间
  143. uiAddItem.Items.Button_add_baojian:registerClick(function ()
  144. playBtnEffect()
  145. local timeNow = os.time();
  146. if timeNow - self.lastSendAdd <= 1 then
  147. showTooltip("正在更新包间,请稍后")
  148. return
  149. end
  150. self.lastSendAdd = timeNow;
  151. local view = import("luaScript.Views.Club.ClubChangeRule"):new(self.clubInfo.clubId,self.noActiveGames)
  152. view:setAnchorPoint(cc.p(0.5, 0.5))
  153. app:showWaitDialog(view)
  154. end)
  155. groupView:addChild(uiAddItem);
  156. end
  157. --groupView:jumpToTopOnSizeChanged()
  158. end
  159. ---
  160. -- 显示包间玩法信息(新版,玩法显示调用比赛场的框)
  161. -- @param baojian
  162. -- @return
  163. --
  164. function ClubBaojian:showClubBaoJianInfo(baojian)
  165. local clubId = self.clubInfo.clubId
  166. local gameId = baojian.realGameId
  167. local gameNum = baojian.gameNum
  168. local strGameRule = baojian.strGameRule
  169. local arena = baojian.arena
  170. local title = baojian.title
  171. local ClubBaoJianInfoClass = import("luaScript.Views.Club.ClubBaoJianInfo")
  172. local view = ClubBaoJianInfoClass:new(clubId, gameId, gameNum, strGameRule, arena, title)
  173. view:setAnchorPoint(cc.p(0.5, 0.5))
  174. app:showWaitDialog(view)
  175. end
  176. function ClubBaojian:showBaojianRuleInfo(parentNode, baoJian,btn)
  177. if true then
  178. self:showClubBaoJianInfo(baoJian)
  179. return
  180. end
  181. self.ui:removeChildByTag(100)
  182. local uiTemplate = self.ui.Items.Layout_show_rule;
  183. local uiRuleItem = uiTemplate:getCopied()
  184. uiRuleItem.Items = getUIItems(uiRuleItem)
  185. uiRuleItem.Items.Layout_Rule_item:setVisible(false)
  186. local scrollUI = uiRuleItem.Items.ScrollView_show_rule
  187. scrollUI:getInnerContainer():setAutoSize(true);
  188. scrollUI:hideAllBar();
  189. scrollUI:removeAllChildren();
  190. --增加数据
  191. if table.nums(baoJian) > 0 then
  192. local tt = getRuleFromString(baoJian.realGameId, baoJian.gameNum, baoJian.strGameRule)
  193. local ttMatch = getClubMatchRule(baoJian.arena,"比赛规则")
  194. for k,v in ipairs(ttMatch) do
  195. table.insert(tt,v)
  196. end
  197. local uiTemp = uiRuleItem.Items.Layout_Rule_item
  198. for k,v in ipairs(tt) do
  199. local uiItem = uiTemp:getCopied()
  200. uiItem.Items = getUIItems(uiItem)
  201. -- 标题
  202. uiItem.Items.Text_RuleName:setText(v.name)
  203. -- 内容
  204. local text = ""
  205. for kk, vv in pairs(v.value) do
  206. if "" == text then
  207. text = vv
  208. else
  209. text = text .. "," .. vv
  210. end
  211. end
  212. uiItem.Items.Text_RuleText:setText(text);
  213. scrollUI:addChild(uiItem);
  214. end
  215. uiRuleItem:setTag(100)
  216. end
  217. scrollUI:jumpToTopOnSizeChanged()
  218. local idx = parentNode.Items.Text_index:getText()
  219. self.ui:addChild(uiRuleItem)
  220. --
  221. local worldPos = btn:getWorldPosition()
  222. --计算坐标
  223. local x = self.ui.Items.Layout_rule:getPositionX()
  224. local y = worldPos.y - uiRuleItem:getSize().height*2/3 - 9
  225. local newPos = cc.p(x, y);
  226. uiRuleItem:setPosition(newPos)
  227. end
  228. function ClubBaojian:onClubGameRule(event)
  229. self.gameRules = event.result or {}
  230. if table.nums(self.gameRules) == 0 then
  231. return
  232. end
  233. --计算未激活的游戏
  234. self:onUpdateActiveGame()
  235. end
  236. function ClubBaojian:onUpdateActiveGame()
  237. if not self.gameRules then
  238. return
  239. end
  240. local tt = {}
  241. for strGameId,v in pairs(self.gameRules) do
  242. if v.status == 1 then
  243. local gameConfig = getSubGameConfig(tonumber(strGameId))
  244. if gameConfig and gameConfig.bSingleGame then
  245. for k,v in pairsByKeys(gameConfig.GameType) do
  246. table.insert(tt,tostring(k + tonumber(strGameId) * 10000))
  247. end
  248. else
  249. table.insert(tt,tostring(strGameId))
  250. end
  251. end
  252. end
  253. local activeGames = self.clubInfo.activeGames
  254. for i,j in ipairs(activeGames) do
  255. for k,strGameId in ipairs(tt) do
  256. local baoJians = app.club_php:getBaoJianByGameId(self.clubInfo.clubId,tonumber(j))
  257. local isUseNum = 0
  258. if baoJians then
  259. for k,v in pairs(baoJians) do
  260. if tonumber(v.is_use) == 1 then
  261. isUseNum = isUseNum + 1
  262. end
  263. end
  264. end
  265. if tonumber(strGameId) == tonumber(j) and isUseNum > 0 then
  266. table.remove(tt,k)
  267. break
  268. end
  269. end
  270. end
  271. table.sort(tt,function (a,b)
  272. return toNumber(a) < toNumber(b)
  273. end)
  274. logD("self.noActiveGames:",table.tostring(self.noActiveGames))
  275. self.noActiveGames = tt
  276. --更新包间
  277. self:updateBaoJian()
  278. end
  279. return ClubBaojian