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.

1000 lines
32 KiB

  1. local CRConfig = require("luaScript.Views.CreateRoom.Com.CRConfig")
  2. -- 茶馆修改游戏玩法Layout
  3. local ClubChangeRule = class("ClubChangeRule" , cc.UIView);
  4. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  5. -- @param clubId 俱乐部ID
  6. -- @param gameId 游戏ID,黄十八,碰胡的ID大于1万
  7. -- @param ruleId 玩法ID
  8. -- @param baoJianId 包间ID
  9. -- @param index 包间的序号
  10. function ClubChangeRule:ctor(clubId, gameId, ruleId, baoJianId,index)
  11. ClubChangeRule.super.ctor(self)
  12. if gameId == 0 then
  13. logD("ClubChangeRule:ctor()", debug.traceback())
  14. end
  15. logD("ClubChangeRule:ctor gameId :",gameId)
  16. logD("clubId :",clubId)
  17. logD("ruleId :",ruleId)
  18. logD("baoJianId :",baoJianId)
  19. logD("index :",index)
  20. self:loadUI()
  21. --单个茶馆数据
  22. self.clubInfo = app.club_php.clubList[clubId]
  23. self.normalColor = cc.c3b(130,201,200)
  24. self.selectColor = cc.c3b(255,255,255)
  25. self.baoJianNoSelColor = cc.c4b(206,236,253,255)
  26. if type(gameId) == "table" then
  27. --单玩法,混合玩法添加包间
  28. self.strGameId = gameId[1] and tostring(gameId[1]) or nil
  29. --未激活游戏列表
  30. self.noActiveGames = gameId
  31. else
  32. --子游戏多包间
  33. self.strGameId = gameId and tostring(gameId) or nil
  34. end
  35. self.realGameId = tonumber(self.strGameId)
  36. if toNumber(self.strGameId) > 10000 then
  37. self.realGameId = math.floor(toNumber(self.strGameId)/10000)
  38. self.ruleId = math.floor(toNumber(self.strGameId)%10000)
  39. else
  40. self.ruleId = ruleId
  41. end
  42. self.baoJianId = baoJianId
  43. self._baoJianName = ""
  44. self.index = index
  45. local baoJian = app.club_php:getBaoJian(clubId,baoJianId)
  46. if baoJian then
  47. self.arena = baoJian.arena
  48. else
  49. self.arena = ""
  50. end
  51. if self.strGameId and baoJianId and baoJianId > 0 then
  52. self.defaultValues = json.decode(self.clubInfo.baoJians[tonumber(baoJianId)].strGameRule or "") or {}
  53. else
  54. self.defaultValues = {}
  55. end
  56. end
  57. function ClubChangeRule:loadUI()
  58. local ui = loadUI("res/ui/ui_chuangjian/ui_chuangjian.ui")
  59. self.ui = ui
  60. self:addChild(ui)
  61. end
  62. function ClubChangeRule:onEnter()
  63. ClubChangeRule.super.onEnter(self)
  64. self:initView()
  65. self:initButton()
  66. self:intBindEvent()
  67. --请求茶馆游戏玩法总配置
  68. app.club_php:requestGameRule(self.clubInfo.clubId)
  69. end
  70. function ClubChangeRule:initView()
  71. self.ui.Items.Text_Tip:setText("注:第一局未发牌扣除的"..PLN.CURRENCY.."将在1小时内返回。")
  72. self.ui.Items.ImageView_title:loadTexture("res/ui/zy_dating/chuanjian/createRoom_title_modify_wanfa.png")
  73. self.ui.Items.Button_Create:loadTextureNormal("res/ui/zy_dating/chuanjian/createRoom_btn_save.png")
  74. self.ui.Items.Button_Match:setVisible(false)
  75. self.ui.Items.Layout_BaoJian_Name:setVisible(true)
  76. self.ui.Items.ImageView_Input_Normal:setVisible(true)
  77. self.ui.Items.ImageView_Input_Error:setVisible(false)
  78. self.ui.Items.Layout_leixing:setVisible(false)
  79. self.ui.Items.ScrollView_rule:setVisible(false)
  80. self.ui.Items.ScrollView_rule_club:setVisible(true)
  81. self.ui.Items.ScrollView:hideAllBar()
  82. self.ui.Items.ScrollView:getInnerContainer():setAutoSize(true)
  83. self.ui.Items.ScrollView:requestDoLayout()
  84. self.ui.Items.ScrollView:doLayout()
  85. self.ui.Items.CheckBox_baojian:setVisible(false)
  86. --比赛场模块
  87. if app.config.ModuleConfig.IsSupportDaLianMeng and self.clubInfo.isArena ~= ClubDefine.MATCH_SWITCH.SERVER_CLOSE then
  88. if (self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.CLIENT_OPEN or
  89. self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_MATCH_OPEN) and self.clubInfo.role == ClubDefine.Job.Creator then
  90. self.ui.Items.Button_Match:setVisible(true)
  91. end
  92. if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_MATCH_OPEN then
  93. self.ui.Items.Button_Match:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_match.png")
  94. end
  95. -- todo lwqcest cest海选赛
  96. if (self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.CLIENT_OPEN or
  97. self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN) and self.clubInfo.role == ClubDefine.Job.Creator then
  98. self.ui.Items.Button_Match:setVisible(true)
  99. self.ui.Items.Text:setText("赛事名:")
  100. end
  101. if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
  102. self.ui.Items.Button_Match:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_match_n.png")
  103. end
  104. end
  105. --初始化包间名字
  106. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId) or {}
  107. self.ui.Items.TextField_BaoJian_Name:setText(baoJian.title or "")
  108. --箭头动画
  109. local action = cc.Sequence:create(cc.MoveBy:create(0.5,cc.p(0,10)),cc.MoveBy:create(0.5,cc.p(0,-10)))
  110. self.ui.Items.ImageView_Arrow:runAction(cc.RepeatForever:create(action))
  111. local action = cc.Sequence:create(cc.ScaleTo:create(0.4,0.95),cc.ScaleTo:create(0.4,1.2))
  112. self.ui.Items.ImageView_hand:runAction(cc.RepeatForever:create(action))
  113. self.ui.Items.ImageView_hand:setVisible(false)
  114. self:initBaoJianView()
  115. --包间开启or关闭
  116. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId) or {}
  117. self.ui.Items.CheckBox:setSelectedState(toNumber(baoJian.is_use) == 1)
  118. if not self.baoJianId then
  119. self.ui.Items.CheckBox:setVisible(false)
  120. end
  121. -- CEST
  122. if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
  123. self.ui.Items.CheckBox:loadTextureBackGroundSelected("res/ui/zy_club/club_room/club_cest_baojian/club_baojian_close.png")
  124. self.ui.Items.CheckBox:loadTextureFrontCross("res/ui/zy_club/club_room/club_cest_baojian/club_baojian_open.png")
  125. self.ui.Items.CheckBox:loadTextureBackGround("res/ui/zy_club/club_room/club_cest_baojian/club_baojian_close.png")
  126. end
  127. end
  128. function ClubChangeRule:initBaoJianView()
  129. self.ui.Items.Layout_BaoJian:removeAllChildren()
  130. --五个包间节点
  131. self.baoJianList = {}
  132. self.baoJianListUI = {}
  133. self.radioManager = import("luaScript.Tools.RadioManager"):new()
  134. self.radioManager:setNormalColor(self.baoJianNoSelColor)
  135. self.radioManager:setSelectColor(cc.c4b(200,62,7,255))
  136. local baojians = app.club_php:getBaoJianByGameId(self.clubInfo.clubId,self.strGameId)
  137. for k,v in pairsByKeys(baojians) do
  138. table.insert(self.baoJianList,toNumber(v.baoJianId))
  139. end
  140. table.sort(self.baoJianList,function (a,b)
  141. if a ~= nil and b ~= nil then
  142. return a < b
  143. else
  144. return a < b
  145. end
  146. end)
  147. if #self.baoJianList == 0 then
  148. self:createBaoJianItem(1,1)
  149. else
  150. for i = 1, #self.baoJianList do
  151. self:createBaoJianItem(#self.baoJianList,i)
  152. if self.baoJianList[i] and self.baoJianList[i] == self.baoJianId then
  153. self.index = i
  154. end
  155. end
  156. end
  157. if not self.index then
  158. self.index = 1
  159. end
  160. self.ui.Items.Layout_addBaoJian:setVisible(#self.baoJianListUI ~= ClubDefine.BaoJianCount)
  161. self.radioManager:setCallback(handler(self , self.onClickBaoJianTag))
  162. self.radioManager:setDefault(self.index)
  163. self.ui.Items.Layout_BaoJian:requestDoLayout()
  164. self.ui.Items.Layout_BaoJian:doLayout()
  165. self.ui.Items.ScrollView:requestDoLayout()
  166. self.ui.Items.ScrollView:doLayout()
  167. self.ui.Items.ScrollView:setInnerContainerSize(self.ui.Items.ScrollView:getSize())
  168. runDelayWithTime(function ()
  169. self.ui.Items.ScrollView:jumpToLeft()
  170. end,0.05)
  171. end
  172. function ClubChangeRule:createBaoJianItem(totalNum,index)
  173. local node = self.ui.Items.CheckBox_baojian:getCopied()
  174. node.Items = getUIItems(node)
  175. if totalNum == 1 then
  176. local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_single.png"
  177. node:loadTextureBackGroundSelected(file)
  178. node:loadTextureFrontCross(file)
  179. elseif totalNum >= 2 then
  180. if index == 1 then --首
  181. local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_left.png"
  182. node:loadTextureBackGroundSelected(file)
  183. node:loadTextureFrontCross(file)
  184. elseif index == totalNum then --末端
  185. local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_right.png"
  186. node:loadTextureBackGroundSelected(file)
  187. node:loadTextureFrontCross(file)
  188. --反向修改前一个
  189. if totalNum >= 2 then
  190. --倒数第二个
  191. local frontNode = self.baoJianListUI[totalNum - 1]
  192. local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn.png"
  193. frontNode:loadTextureBackGroundSelected(file)
  194. frontNode:loadTextureFrontCross(file)
  195. --第一个
  196. local frontNode = self.baoJianListUI[1]
  197. local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_left.png"
  198. frontNode:loadTextureBackGroundSelected(file)
  199. frontNode:loadTextureFrontCross(file)
  200. end
  201. elseif index > 1 and index < totalNum then
  202. local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn.png"
  203. node:loadTextureBackGroundSelected(file)
  204. node:loadTextureFrontCross(file)
  205. end
  206. end
  207. -- todo lwqcest
  208. if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
  209. node.Items.Text_Name:setText("赛事"..index)
  210. else
  211. node.Items.Text_Name:setText("包间"..index)
  212. end
  213. node.Items.Text_Name:setTextColor(self.baoJianNoSelColor)
  214. self.radioManager:addItem(node,index)
  215. self.ui.Items.Layout_BaoJian:addChild(node)
  216. self.baoJianListUI[index] = node
  217. end
  218. function ClubChangeRule:onClickAddBaoJian()
  219. playBtnEffect()
  220. self:createBaoJianItem(#self.baoJianListUI + 1,#self.baoJianListUI + 1)
  221. if #self.baoJianListUI == ClubDefine.BaoJianCount then
  222. self.ui.Items.Layout_addBaoJian:setVisible(false)
  223. end
  224. self.ui.Items.Layout_BaoJian:requestDoLayout()
  225. self.ui.Items.Layout_BaoJian:doLayout()
  226. self.ui.Items.ScrollView:requestDoLayout()
  227. self.ui.Items.ScrollView:doLayout()
  228. self.ui.Items.ScrollView:setInnerContainerSize(self.ui.Items.ScrollView:getSize())
  229. runDelayWithTime(function ()
  230. self.ui.Items.ScrollView:jumpToRight()
  231. self.index = #self.baoJianListUI
  232. self.radioManager:setDefault(self.index)
  233. end,0.05)
  234. end
  235. function ClubChangeRule:initButton()
  236. --关闭
  237. self.ui.Items.Button_close:registerClick(handler(self , self.onClose))
  238. --保存
  239. self.ui.Items.Button_Create:registerClick(handler(self , self.onSave))
  240. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickJuShuAdd))
  241. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJuShuJian))
  242. self.ui.Items.Button_Match:registerClick(handler(self, self.onClickMatchSet))
  243. self.ui.Items.ButtonAdd:registerClick(handler(self, self.onClickAddBaoJian))
  244. self.ui.Items.CheckBox:registerClick(function ()
  245. self.isOpen = self.ui.Items.CheckBox:getSelectedState() and 0 or 1
  246. self.ui.Items.CheckBox:setSelectedState(not self.ui.Items.CheckBox:getSelectedState())
  247. logD("self.baoJianId",self.baoJianId)
  248. local txt = self.isOpen == 1 and "是否开启包间" or "是否关闭包间"
  249. if app.club_php:getCestIsOpen(self.clubInfo.clubId) then
  250. txt = self.isOpen == 1 and "是否开启赛事" or "是否关闭赛事"
  251. end
  252. if self.baoJianId then
  253. showConfirmDialog(txt,function ()
  254. app.club_php:requestActiveRule(self.clubInfo.clubId,self.isOpen,self.baoJianId)
  255. end,function ()end)
  256. end
  257. end)
  258. self.ui.Items.ScrollView_rule_club:addEventListener(function (obj, type)
  259. local inner = self.ui.Items.ScrollView_rule_club:getInnerContainer()
  260. local innerSize = inner:getContentSize()
  261. local pos = inner:getPosition()
  262. local h = innerSize.height - self.ui.Items.ScrollView_rule_club:getContentSize().height
  263. if h>0 then
  264. if pos.y>=-h + 10 then
  265. self.ui.Items.ImageView_Arrow:setVisible(false)
  266. else
  267. self.ui.Items.ImageView_Arrow:setVisible(true)
  268. end
  269. end
  270. end)
  271. end
  272. function ClubChangeRule:intBindEvent()
  273. --绑定修改玩法成功回调
  274. self:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_RULE , handler(self , self.onChangeRuleCallback));
  275. --请求茶馆玩法回调
  276. self:bindEvent(app.club_php , GAME_EVENT.CLUB_GAME_RULE , handler(self , self.onUpdateGameRule))
  277. --创建界面修改支付模式通知这里更新显示
  278. self:bindEvent(app, "onChangePayMode", handler(self, self.updateJushuData));
  279. --绑定比赛开关
  280. self:bindEvent(app.club_php , GAME_EVENT.CLUB_SET , handler(self , self.onSetSuccess));
  281. --激活包间成功后关闭
  282. self:bindEvent(app.club_php , GAME_EVENT.CLUB_ACTIVE_RULE , handler(self , self.onActiveRuleResponse))
  283. --
  284. self:bindEvent(app , GAME_EVENT.UPDATE_SCOREVIEW_SIZE , handler(self , self.updateScollowViewSize))
  285. -- 支付方式发生改变时更新房卡消耗
  286. if CRConfig then
  287. self.ui:bindEvent(app, CRConfig.CREATE_ROOM_DEDUCTRULE_CHANGE, handler(self, self.updateDiamondCost))
  288. end
  289. end
  290. function ClubChangeRule:onClose()
  291. playBtnCloseEffect()
  292. self:removeFromParent()
  293. end
  294. function ClubChangeRule:onActiveRuleResponse()
  295. self.ui.Items.CheckBox:setSelectedState(not self.ui.Items.CheckBox:getSelectedState())
  296. end
  297. --修改玩法回调
  298. function ClubChangeRule:onChangeRuleCallback(data)
  299. if not data or (self.clubInfo.clubId~=data.clubId) then
  300. return
  301. end
  302. local clubId = data.clubId
  303. local baoJianId = data.baoJianId
  304. local baoJian = app.club_php:getBaoJian(clubId,baoJianId)
  305. --修改内存数据
  306. self.baoJianList[self.index] = baoJianId
  307. self.baoJianId = baoJianId
  308. self._baoJianName = baoJian.title
  309. --刷新当前标签
  310. self:onClickBaoJianTag(self.index)
  311. end
  312. -- 当比赛一关,其他和比赛有关的界面需要关闭
  313. function ClubChangeRule:onSetSuccess(data)
  314. if not data or not data.setType then
  315. return
  316. end
  317. if data.setType == GAME_CLUB_SET_STATE.Math_Switch then
  318. self.ui.Items.Button_Match:setVisible(false)
  319. if app.config.ModuleConfig.IsSupportDaLianMeng and self.clubInfo.isArena ~= 0 then
  320. if self.clubInfo.isArena == 2 and self.clubInfo.role == ClubDefine.Job.Creator then
  321. self.ui.Items.Button_Match:setVisible(true)
  322. end
  323. end
  324. end
  325. end
  326. --更新游戏类型
  327. function ClubChangeRule:onUpdateGameRule(event)
  328. self.gameRules = event.result or {}
  329. if table.nums(self.gameRules) == 0 then
  330. return
  331. end
  332. --游戏类型
  333. local gameTypes = {}
  334. for strGameId,v in pairs(self.gameRules) do
  335. local gameConfig = getSubGameConfig(tonumber(strGameId))
  336. if gameConfig then
  337. gameTypes[gameConfig.belongType] = gameConfig.belongType
  338. end
  339. end
  340. local selectGameType
  341. local gameConfig = getSubGameConfig(tonumber(self.realGameId or 0))
  342. if gameConfig then
  343. selectGameType = gameConfig.belongType
  344. end
  345. --先清空当前类型Item
  346. self.gameTypeItem = {}
  347. for k, gameType in pairsByKeys(gameTypes) do
  348. self.ui.Items["Button_leixing_"..gameType]:registerClick(function ()
  349. playBtnTagEffect()
  350. if selectGameType~= gameType then
  351. selectGameType = gameType
  352. self.strGameId = nil --切换标签重置gameid
  353. self.ruleId = nil
  354. self:setGameTypeBtnStatus(gameType)
  355. self:updateGameRuleItem(gameType)
  356. self:updateRuleUI()
  357. --self:onGameItemClicked(tostring(strGameId), nil, gameType)
  358. end
  359. end)
  360. self.gameTypeItem[gameType] = self.ui.Items["Button_leixing_"..gameType]
  361. --没有类型设置默认为第一个
  362. if not selectGameType then
  363. selectGameType = gameType
  364. end
  365. end
  366. --设置左边游戏类型按钮状态
  367. self:setGameTypeBtnStatus(selectGameType)
  368. self:updateGameRuleItem(selectGameType)
  369. self:updateRuleUI()
  370. end
  371. --更新条目选项
  372. function ClubChangeRule:updateGameRuleItem(gameType,bNotJump)
  373. local gameIDs = {}
  374. local gameList = app.serverConfigs.subGameList
  375. if self.noActiveGames then
  376. gameIDs = self.noActiveGames
  377. else
  378. --logD("ClubChangeRule:updateGameRuleItem:",table.tostring(self.gameRules))
  379. --[[for strGameId,v in pairs(self.gameRules) do
  380. local gameConfig = getSubGameConfig(tonumber(strGameId))
  381. if gameConfig and gameConfig.belongType==gameType and v.status ~= 3 then
  382. table.insert(gameIDs,strGameId)
  383. end
  384. end
  385. table.sort(gameIDs, function (aGameId,bGameId)
  386. local gameA = gameList[tonumber(aGameId)]
  387. local gameB = gameList[tonumber(bGameId)]
  388. return gameA.sortIndex<gameB.sortIndex
  389. end)--]]
  390. table.insert(gameIDs,self.strGameId)
  391. end
  392. local mScorllView = self.ui.Items.ScrollView_game;
  393. mScorllView:hideAllBar()
  394. local mListView = self.ui.Items.Layout_scrollview_game
  395. mListView:removeAllChildren()
  396. local uiTemplate = self.ui.Items.Layout_game_item
  397. for k,strGameId in pairsByKeys(gameIDs) do
  398. if not self.strGameId then --没有Id设置默认的
  399. self.strGameId = strGameId
  400. end
  401. local ruleID = 0
  402. if toNumber(strGameId) > 10000 then
  403. ruleID = math.floor(toNumber(strGameId)%10000)
  404. strGameId = math.floor(toNumber(strGameId)/10000)
  405. end
  406. local gameConfig = getSubGameConfig(toNumber(strGameId))
  407. if gameConfig then
  408. if gameConfig.bSingleGame then
  409. local uiItem = uiTemplate:getCopied()
  410. uiItem.Items = getUIItems(uiItem)
  411. mListView:addChild(uiItem)
  412. --隐藏更新标签
  413. uiItem.Items.ImageView_update_icon:setVisible(false)
  414. -- 游戏名字按钮
  415. uiItem.Items.Button_game:registerClick(function ()
  416. self.defaultValues = {}
  417. playBtnTagEffect()
  418. if toNumber(self.strGameId) ~= tonumber(strGameId) or self.ruleId ~= ruleID then
  419. self:onGameItemClicked(tostring(strGameId), ruleID, gameType)
  420. end
  421. end)
  422. if tonumber(self.realGameId) == tonumber(strGameId) and self.ruleId == ruleID then
  423. uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_sel.png")
  424. uiItem.Items.Text_GameName:setVisible(false)
  425. uiItem.Items.Text_GameName_sel:setVisible(true)
  426. else
  427. uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_nor.png")
  428. uiItem.Items.Text_GameName:setVisible(true)
  429. uiItem.Items.Text_GameName_sel:setVisible(false)
  430. end
  431. uiItem.Items.Text_GameName:setString(gameConfig.GameType[ruleID] or "")
  432. uiItem.Items.Text_GameName_sel:setString(gameConfig.GameType[ruleID] or "")
  433. --刷新layout布局
  434. uiItem:requestDoLayout()
  435. uiItem:doLayout()
  436. else
  437. local uiItem = uiTemplate:getCopied()
  438. uiItem.Items = getUIItems(uiItem)
  439. if toNumber(self.strGameId) == toNumber(strGameId) then
  440. uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_sel.png")
  441. uiItem.Items.Text_GameName:setVisible(false)
  442. uiItem.Items.Text_GameName_sel:setVisible(true)
  443. else
  444. uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_nor.png")
  445. uiItem.Items.Text_GameName:setVisible(true)
  446. uiItem.Items.Text_GameName_sel:setVisible(false)
  447. end
  448. --隐藏更新标签
  449. uiItem.Items.ImageView_update_icon:setVisible(false)
  450. -- 游戏名字按钮
  451. uiItem.Items.Button_game:registerClick(function ()
  452. self.defaultValues = {}
  453. playBtnTagEffect()
  454. if self.strGameId ~= strGameId then
  455. self:onGameItemClicked(tostring(strGameId), nil, gameType)
  456. end
  457. end)
  458. --添加规则
  459. local uiRuleTemplate = self.ui.Items.Layout_rule_item
  460. local rules = self.gameRules[tostring(self.realGameId)].gamerule
  461. if not self.ruleId then --默认规则 2个玩法以上时服务器的key变成了字符
  462. self.ruleId = rules[1] and rules[1].rulekey or rules["1"].rulekey--rules["1"].rulekey or rules[1].rulekey
  463. end
  464. if table.nums(rules) > 1 and tonumber(self.realGameId) == tonumber(strGameId) then
  465. for _,v in pairsByKeys(rules) do
  466. local uiRuleItem = uiRuleTemplate:getCopied()
  467. uiRuleItem.Items = getUIItems(uiRuleItem)
  468. if self.ruleId ~= v.rulekey then
  469. uiRuleItem.Items.ImageView_bg_select:setVisible(false)
  470. uiRuleItem.Items.Text_rule_name:setColor(self.normalColor)
  471. local config = uiRuleItem.Items.Text_rule_name:getFontConfig()
  472. config.fontSize = 32
  473. uiRuleItem.Items.Text_rule_name:setFontConfig(config)
  474. else
  475. uiRuleItem.Items.Text_rule_name:setColor(self.selectColor)
  476. end
  477. --玩法名
  478. uiRuleItem.Items.Text_rule_name:setText(v.rulename)
  479. --点击事件
  480. uiRuleItem.Items.Layout_touch:registerClick(function ()
  481. playBtnTagEffect()
  482. if self.ruleId~= v.rulekey then
  483. self.ruleId = v.rulekey
  484. self:updateGameRuleItem(gameType, true) --ljx添加 二级游戏菜单不跳转到最顶部
  485. self:updateRuleUI()
  486. end
  487. end)
  488. uiItem:addChild(uiRuleItem)
  489. end
  490. --刷新layout布局
  491. uiItem:requestDoLayout()
  492. uiItem:doLayout()
  493. end
  494. local cfg = getSubGameConfig(strGameId)
  495. uiItem.Items.Text_GameName:setString(cfg.gameName or "")
  496. uiItem.Items.Text_GameName_sel:setString(cfg.gameName or "")
  497. mListView:addChild(uiItem)
  498. end
  499. end
  500. end
  501. mListView:requestDoLayout()
  502. mListView:doLayout()
  503. local layoutSize = mListView:getContentSize()
  504. mScorllView:setInnerContainerSize(layoutSize)
  505. if bNotJump then
  506. return
  507. end
  508. mScorllView:jumpToTop()
  509. end
  510. function ClubChangeRule:onGameItemClicked(gameId, ruleId, gameType)
  511. self.strGameId = gameId
  512. local config = getSubGameConfig(tonumber(gameId))
  513. if config and config.bSingleGame then
  514. self.strGameId = tostring(tonumber(gameId) * 10000 + tonumber(ruleId))
  515. end
  516. self.ruleId = ruleId
  517. self.realGameId = toNumber(self.strGameId)
  518. if toNumber(self.strGameId) > 10000 then
  519. self.realGameId = math.floor(toNumber(self.strGameId)/10000)
  520. end
  521. self.baoJianList = {}
  522. local baojians = app.club_php:getBaoJianByGameId(self.clubInfo.clubId,self.strGameId)
  523. for k,v in pairsByKeys(baojians) do
  524. table.insert(self.baoJianList,toNumber(v.baoJianId))
  525. end
  526. table.sort(self.baoJianList,function (a,b)
  527. if a ~= nil and b ~= nil then
  528. return a < b
  529. else
  530. return a < b
  531. end
  532. end)
  533. self.radioManager:setDefault(1)
  534. self:initBaoJianView()
  535. end
  536. --更新选项UI
  537. function ClubChangeRule:updateRuleUI()
  538. local mScorllView = self.ui.Items.ScrollView_rule_club
  539. mScorllView:hideAllBar()
  540. mScorllView:removeAllChildren()
  541. if self.ruleView then
  542. self.ruleView = nil
  543. end
  544. ruleId = tonumber(self.ruleId)
  545. gameId = tonumber(self.realGameId)
  546. local ruleConfig = getSubGameCreateRuleConfig(gameId)
  547. if ruleConfig then
  548. self.ruleView = import("core.luaScript.Views.CreateRoom.CreateRoomItemNew"):new(ruleConfig, self.defaultValues, gameId, ruleId, true)
  549. mScorllView:addChild(self.ruleView)
  550. self:updateScollowViewSize()
  551. else
  552. local ruleClass = getSubGameCreateRoomUi(gameId, ruleId)
  553. if ruleClass then
  554. self.ruleView = import(ruleClass):new(self.defaultValues, ruleId)
  555. mScorllView:addChild(self.ruleView)
  556. self:updateScollowViewSize()
  557. -- todo lwqcest
  558. if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
  559. if type(self.ruleView.onShowCestView) == "function" then
  560. self.ruleView:onShowCestView()
  561. end
  562. end
  563. end
  564. end
  565. self:initJuShu()
  566. mScorllView:jumpToTop()
  567. end
  568. function ClubChangeRule:updateScollowViewSize()
  569. local mScorllView = self.ui.Items.ScrollView_rule_club
  570. local layoutSize = self.ruleView:getLayoutContentSize()
  571. if layoutSize then
  572. mScorllView:setInnerContainerSize(layoutSize)
  573. end
  574. local innerSize = mScorllView:getInnerContainer():getContentSize()
  575. if innerSize.height > mScorllView:getContentSize().height then
  576. self.ui.Items.ImageView_Arrow:setVisible(true)
  577. else
  578. self.ui.Items.ImageView_Arrow:setVisible(false)
  579. end
  580. end
  581. --初始化局数
  582. function ClubChangeRule:initJuShu()
  583. if self.realGameId then
  584. local gameConfig = getSubGameConfig(tonumber(self.realGameId))
  585. if gameConfig then
  586. self.curGameCount = app.serverConfigs:getSubGameCostInfo(self.realGameId)
  587. if self.curGameCount and #self.curGameCount > 0 then
  588. -- 局数最大索引
  589. self.maxSelJushuIndex = #self.curGameCount
  590. -- 从后台数据中读取默认值
  591. local defaultValue
  592. if self.defaultValues and table.nums(self.defaultValues) > 0 then
  593. defaultValue = self.defaultValues.jushu or self.curGameCount[1].round or 0
  594. else
  595. defaultValue = gameConfig.defaultRound or self.curGameCount[1].round or 0
  596. end
  597. --找到当前选中的局数在配置中的下标
  598. for i,v in pairs(self.curGameCount) do
  599. if v.round == tonumber(defaultValue) then
  600. self.curSelJushuIndex = i
  601. end
  602. end
  603. if not self.curSelJushuIndex then
  604. self.curSelJushuIndex = 1
  605. end
  606. self:updateJushuData(self.curSelJushuIndex)
  607. else
  608. if gameConfig.gameCount then
  609. self.curGameCount = gameConfig.gameCount
  610. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId)
  611. local jushu = nil
  612. if baoJian then
  613. jushu = baoJian.gameNum
  614. end
  615. local gameConfig = getSubGameConfig(tonumber(self.realGameId))
  616. local defaultValue = gameConfig.gameCount[1]
  617. if gameConfig.bSingleGame then
  618. defaultValue = jushu or gameConfig.gameCount[gameConfig.defaultJushuIndex[self.ruleId] or 1]
  619. else
  620. defaultValue = jushu or gameConfig.gameCount[gameConfig.defaultJushuIndex] or gameConfig.gameCount[1]
  621. end
  622. --找到当前选中的局数在配置中的下标
  623. for i,v in pairs(gameConfig.gameCount) do
  624. if v == tonumber(defaultValue) then
  625. self.curSelJushuIndex = i
  626. end
  627. end
  628. if not self.curSelJushuIndex then
  629. self.curSelJushuIndex = 1
  630. defaultValue = gameConfig.gameCount[1]
  631. end
  632. self:updateJushuData(defaultValue)
  633. end
  634. end
  635. end
  636. end
  637. end
  638. -- 更新房卡消耗
  639. function ClubChangeRule:updateDiamondCost()
  640. if self.ruleView then
  641. local costCard = self.ruleView:getCreateRoomCost(self.curRound)
  642. self.ui.Items.Text_Diamond:setText("x "..costCard)
  643. end
  644. end
  645. --刷新局数数据显示
  646. function ClubChangeRule:updateJushuData(jushu)
  647. local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
  648. if severConfig then
  649. if not self.curSelJushuIndex
  650. or not self.maxSelJushuIndex
  651. or tonumber(self.curSelJushuIndex) <= 0
  652. or tonumber(self.curSelJushuIndex) > tonumber(self.maxSelJushuIndex) then
  653. return
  654. end
  655. jushu = self.curGameCount[self.curSelJushuIndex].round or 0
  656. else
  657. if not tonumber(jushu) then
  658. if self.curGameCount and self.curSelJushuIndex then
  659. jushu = self.curGameCount[self.curSelJushuIndex]
  660. end
  661. end
  662. end
  663. self.curRound = jushu
  664. self.ui.Items.Text_jushu:setText(jushu.."局")
  665. self:updateDiamondCost()
  666. end
  667. --局数按钮加
  668. function ClubChangeRule:onClickJuShuAdd()
  669. if not self.curSelJushuIndex then
  670. return
  671. end
  672. local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
  673. if severConfig then
  674. if self.curSelJushuIndex >= self.maxSelJushuIndex then
  675. return
  676. end
  677. playBtnEffect()
  678. self.curSelJushuIndex = self.curSelJushuIndex + 1
  679. self:updateJushuData(self.curSelJushuIndex)
  680. else
  681. playBtnEffect()
  682. self.curSelJushuIndex = self.curSelJushuIndex + 1
  683. if tonumber(self.strGameId) == 2 and (self.ruleId == 1 or self.ruleId == 3) then
  684. if self.curSelJushuIndex > 2 then
  685. self.curSelJushuIndex = 2
  686. return
  687. end
  688. end
  689. if self.curGameCount and self.curGameCount[self.curSelJushuIndex] then
  690. self:updateJushuData(self.curGameCount[self.curSelJushuIndex])
  691. else
  692. self.curSelJushuIndex = self.curSelJushuIndex - 1
  693. end
  694. end
  695. end
  696. --局数按钮减
  697. function ClubChangeRule:onClickJuShuJian()
  698. if not self.curSelJushuIndex then
  699. return
  700. end
  701. local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
  702. if severConfig then
  703. playBtnEffect()
  704. if self.curSelJushuIndex <= 1 then
  705. return
  706. end
  707. self.curSelJushuIndex = self.curSelJushuIndex - 1
  708. self:updateJushuData(self.curSelJushuIndex)
  709. else
  710. playBtnEffect()
  711. self.curSelJushuIndex = self.curSelJushuIndex - 1
  712. --兼容下原有的局数和新的局数配置不等时候导致修改不了的问题
  713. if self.curSelJushuIndex <= 0 then
  714. self.curSelJushuIndex = 1
  715. end
  716. if self.curGameCount and self.curGameCount[self.curSelJushuIndex] then
  717. self:updateJushuData(self.curGameCount[self.curSelJushuIndex])
  718. else
  719. self.curSelJushuIndex = self.curSelJushuIndex + 1
  720. end
  721. end
  722. end
  723. --比赛设置
  724. function ClubChangeRule:onClickMatchSet()
  725. playBtnEffect()
  726. self.ui.Items.ImageView_hand:setVisible(false)
  727. local function callBack(data)
  728. self.arena = data
  729. end
  730. if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_MATCH_OPEN then
  731. local view = import("luaScript.Views.Club.Match.ClubCreateRoomChongBangSet"):new(self.clubInfo.clubId,self.baoJianId,self.realGameId,self.arena,callBack)
  732. view:setAnchorPoint(cc.p(0.5, 0.5))
  733. app:showWaitDialog(view)
  734. elseif self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
  735. local view = import("luaScript.Views.Club.Cest.ClubCestCreateRoomChongBangSet"):new(self.clubInfo.clubId,self.baoJianId,self.realGameId,self.arena,callBack)
  736. view:setAnchorPoint(cc.p(0.5, 0.5))
  737. app:showWaitDialog(view)
  738. else
  739. local view = import("luaScript.Views.Club.Match.ClubCreateRoomMatchSet"):new(self.clubInfo.clubId,self.baoJianId,self.arena,callBack)
  740. view:setAnchorPoint(cc.p(0.5, 0.5))
  741. app:showWaitDialog(view)
  742. end
  743. -- todo lwqcest
  744. -- 先写死,进入到cest
  745. end
  746. --点击选择游戏类型
  747. function ClubChangeRule:setGameTypeBtnStatus(curGameType)
  748. for gameType,item in pairsByKeys(self.gameTypeItem) do
  749. local gameImgName = ""
  750. if tonumber(gameType) == tonumber(curGameType) then
  751. item:setBright(false)
  752. else
  753. item:setBright(true)
  754. end
  755. end
  756. end
  757. function ClubChangeRule:onSave()
  758. playBtnEffect()
  759. --未选择任何玩法时,不做处理
  760. if not self.ruleView then
  761. showTooltip("请先选择玩法!");
  762. return
  763. end
  764. local baoJianName = self.ui.Items.TextField_BaoJian_Name:getText()
  765. self._baoJianName = baoJianName
  766. local function onClickOk()
  767. if not self.ruleView then
  768. showTooltip("请先选择玩法!");
  769. return
  770. end
  771. local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
  772. local jushu
  773. local strRuleInfo
  774. if severConfig then
  775. jushu = self.curGameCount[self.curSelJushuIndex].round
  776. _, strRuleInfo = self.ruleView:getRuleResult()
  777. else
  778. jushu, strRuleInfo = self.ruleView:getRuleResult()
  779. jushu = self.curGameCount[self.curSelJushuIndex]
  780. end
  781. if not strRuleInfo or type(strRuleInfo) ~= "string" then
  782. showTooltip("玩法选择失败,请重新选择!");
  783. return
  784. end
  785. local stRuleInfo = json.decode(strRuleInfo)
  786. if stRuleInfo then
  787. stRuleInfo.jushu = jushu
  788. strRuleInfo = json.encode(stRuleInfo)
  789. end
  790. local isDelete = 0;
  791. local gameId = self.strGameId
  792. --排名赛模式下,校验排名赛规则是否设置
  793. if self.arena == "" and app.club_php:getMatchIsOpen(self.clubInfo.clubId) then
  794. showTooltip("请设置排名赛规则!")
  795. self.ui.Items.ImageView_hand:setVisible(true)
  796. return
  797. end
  798. --海选模式下,校验海选赛规则是否设置
  799. if self.arena == "" and app.club_php:getCestIsOpen(self.clubInfo.clubId) then
  800. showTooltip("请设置赛事规则!")
  801. self.ui.Items.ImageView_hand:setVisible(true)
  802. return
  803. end
  804. app.club_php:requestChangeRule(self.clubInfo.clubId,self.baoJianId and self.baoJianId or 0,gameId,jushu,strRuleInfo,isDelete,self.arena,self._baoJianName);
  805. end
  806. local function onClickCancel()
  807. end
  808. --防止暴力点击
  809. self.ui.Items.Button_Create:setTouchEnabled(false)
  810. self.ui.Items.Button_Create:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
  811. self.ui.Items.Button_Create:setTouchEnabled(true)
  812. end)))
  813. --包间开启or关闭
  814. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId) or {}
  815. --没有包间ID 证明是新增,新增或者存在的包间但关闭了,不走二次确认
  816. if not self.baoJianId or self.baoJianId and toNumber(baoJian.is_use) == 0 then
  817. onClickOk()
  818. else
  819. local view = import("luaScript.Views.Club.ClubBaoJianChangeTip"):new(onClickOk,onClickCancel)
  820. view:setAnchorPoint(cc.p(0.5, 0.5))
  821. app:showWaitDialog(view)
  822. end
  823. end
  824. function ClubChangeRule:onClickBaoJianTag(value,node)
  825. self.ui.Items.ImageView_hand:setVisible(false)
  826. self.baoJianId = self.baoJianList[value]
  827. self._baoJianName = ""
  828. local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId)
  829. if baoJian then
  830. self.ui.Items.TextField_BaoJian_Name:setText(baoJian.title or "")
  831. self.ui.Items.CheckBox:setSelectedState(toNumber(baoJian.is_use) == 1)
  832. else
  833. self.ui.Items.TextField_BaoJian_Name:setText("")
  834. self.ui.Items.CheckBox:setSelectedState(false)
  835. end
  836. if not self.baoJianId then
  837. self.ui.Items.CheckBox:setVisible(false)
  838. else
  839. self.ui.Items.CheckBox:setVisible(true)
  840. end
  841. if baoJian and baoJian.strGameRule then
  842. local strGameRule = json.decode(baoJian.strGameRule)
  843. self.ruleId = tonumber(strGameRule.gamerule)
  844. end
  845. self.index = value
  846. if baoJian then
  847. self.arena = baoJian.arena
  848. else
  849. self.arena = ""
  850. end
  851. if self.strGameId and self.baoJianId and self.baoJianId > 0 then
  852. self.defaultValues = json.decode(self.clubInfo.baoJians[tonumber(self.baoJianId)].strGameRule or "") or {}
  853. else
  854. self.defaultValues = {}
  855. end
  856. local selectGameType
  857. if self.gameRules then
  858. local gameConfig = getSubGameConfig(tonumber(self.realGameId or 0))
  859. if gameConfig then
  860. selectGameType = gameConfig.belongType
  861. end
  862. self:updateGameRuleItem(selectGameType,true)
  863. end
  864. self:updateRuleUI()
  865. end
  866. return ClubChangeRule