您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

489 行
15 KiB

  1. local CreateRoom_nanchong = class("CreateRoom_nanchong", require("luaScript.Views.CreateRoom.CreateRoomItemBase"))
  2. --[[
  3. isCreateRoom和defaultValus决定了从哪里读取默认值
  4. isCreateRoom 为true时,从本地文件读取,defaultValus无效.
  5. 否则使用defaultValus的值
  6. defaultValus : 跟服务器strGameInfo对应的json对象
  7. --]]
  8. function CreateRoom_nanchong:ctor(defaultValues)
  9. CreateRoom_nanchong.super.ctor(self, defaultValues, "CreateRoom_nanchong.json");
  10. local ui = loadUI("res/ui/ui_chuangjian/zp_chuangjian_nanchongkaokao.ui");
  11. self.ui = ui;
  12. self:addChild(ui);
  13. logD("CreateRoom_nanchong:ctor self.ui.Items:", table.tostring(self.ui.Items))
  14. -- 局数
  15. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  16. -- 房卡
  17. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new()
  18. -- 人数
  19. self.pcountRadioManager = import("luaScript.Tools.RadioManager"):new()
  20. -- 飘
  21. self.PiaoRadioManager = import("luaScript.Tools.RadioManager"):new()
  22. -- 番数
  23. self.FanshuManager = import("luaScript.Tools.RadioManager"):new()
  24. -- 锥
  25. self.Zhui1RadioManager = import("luaScript.Tools.RadioManager"):new()
  26. -- 打法 (乱吃乱打 正吃正打)
  27. self.DafaRadioManager = import("luaScript.Tools.RadioManager"):new()
  28. -- 头当
  29. self.TouDangCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  30. -- 推当
  31. self.TiuDangCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  32. -- 滚翻或梯番
  33. self.BeishuRadioManager = import("luaScript.Tools.RadioManager"):new()
  34. --玩法
  35. self.WanfaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  36. -- 其他选项
  37. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  38. self:onHideCestView() -- 隐藏cest的界面
  39. end
  40. function CreateRoom_nanchong:onHideCestView()
  41. if self.ui.Items.Button_pay0_tips then
  42. self.ui.Items.Button_pay0_tips:setVisible(false)
  43. end
  44. if self.ui.Items.Button_pay1_tips then
  45. self.ui.Items.Button_pay1_tips:setVisible(false)
  46. end
  47. if self.ui.Items.ImageView_pay0_tips then
  48. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  49. end
  50. if self.ui.Items.ImageView_pay1_tips then
  51. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  52. end
  53. end
  54. function CreateRoom_nanchong:onShowCestView()
  55. if self.ui.Items.Text_pay0 then
  56. self.ui.Items.Text_pay0:setText("免费")
  57. end
  58. if self.ui.Items.Text_pay1 then
  59. self.ui.Items.Text_pay1:setText("自费")
  60. end
  61. if self.ui.Items.Button_pay0_tips then
  62. self.ui.Items.Button_pay0_tips:setVisible(true)
  63. end
  64. if self.ui.Items.Button_pay1_tips then
  65. self.ui.Items.Button_pay1_tips:setVisible(true)
  66. end
  67. if self.ui.Items.ImageView_pay0_tips then
  68. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  69. end
  70. if self.ui.Items.Button_pay0_tips then
  71. self.ui.Items.Button_pay0_tips:registerClick(function()
  72. if self.ui.Items.ImageView_pay0_tips then
  73. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  74. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  75. end
  76. end)
  77. end
  78. if self.ui.Items.ImageView_pay1_tips then
  79. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  80. end
  81. if self.ui.Items.Button_pay1_tips then
  82. self.ui.Items.Button_pay1_tips:registerClick(function()
  83. if self.ui.Items.ImageView_pay1_tips then
  84. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  85. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  86. end
  87. end)
  88. end
  89. end
  90. --根据局数获取房费
  91. function CreateRoom_nanchong:getCreateRoomCost(jushu)
  92. if self.cost then
  93. local costInfo = self.cost[jushu]
  94. if costInfo then
  95. local payMode = self.PayRadioManager:getResult()
  96. if payMode == 0 then
  97. return costInfo.requireCards or 0
  98. elseif payMode == 1 then
  99. return costInfo.requireCardsAA or 0
  100. end
  101. end
  102. end
  103. return 0
  104. end
  105. function CreateRoom_nanchong:onEnter()
  106. CreateRoom_nanchong.super.onEnter(self)
  107. -- 整理不同局数对应的房卡消耗
  108. local ttCost = {}
  109. local gameConfig = app.user:getGameConfig(GAME_IDS.nanchongkk);
  110. if gameConfig then
  111. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  112. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  113. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  114. for idx, gameRound in ipairs(arrGameRound) do
  115. ttCost[gameRound] =
  116. {
  117. requireCards = arrRequireCards[idx],
  118. requireCardsAA = arrRequireCardsAA[idx],
  119. }
  120. end
  121. end
  122. self.cost = ttCost
  123. -- 玩家选择局数后,更新房卡消耗
  124. local function updateCost(gameRound)
  125. local costInfo = ttCost[gameRound]
  126. if costInfo then
  127. self.ui.Items.Text_FangZhu:setText(tostring(costInfo.requireCards or 0))
  128. self.ui.Items.Text_AAPay:setText(tostring(costInfo.requireCardsAA or 0))
  129. end
  130. end
  131. -- 房费 deductRule
  132. if self.PayRadioManager then
  133. self.PayRadioManager:addItem(self.ui.Items.CheckBox_4, 1); -- AA支付
  134. self.PayRadioManager:addItem(self.ui.Items.CheckBox_5, 0); -- 房主支付
  135. -- 设置默认数据
  136. local defaultValue = self:getDefaultValue("deductRule") or 0
  137. self.PayRadioManager:setDefault(tonumber(defaultValue));
  138. --通知创建界面更新显示
  139. local function dispatchUpdateCost()
  140. app:dispatchEvent({name = "onChangePayMode"})
  141. end
  142. self.PayRadioManager:setCallback(dispatchUpdateCost);
  143. end
  144. -- 漂
  145. if self.PiaoRadioManager then
  146. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_6, 1); -- 随漂
  147. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_7, 0); -- 不飘
  148. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_16, 2);-- 定飘
  149. -- 设置默认数据
  150. local defaultValue = self:getDefaultValue("Piaorule") or 0
  151. self.PiaoRadioManager:setDefault(tonumber(defaultValue));
  152. end
  153. -- 番数
  154. if self.FanshuManager then
  155. self.FanshuManager:addItem(self.ui.Items.CheckBox_10, 1); -- 3番
  156. self.FanshuManager:addItem(self.ui.Items.CheckBox_11, 0); -- 4番
  157. self.FanshuManager:addItem(self.ui.Items.CheckBox_12, 2); -- 5番
  158. -- 设置默认数据
  159. local defaultValue = self:getDefaultValue("highLimit") or 1
  160. self.FanshuManager:setDefault(tonumber(defaultValue));
  161. end
  162. --快速成局说明
  163. self.ui.Items.ImageView_2:setVisible(false)
  164. self.ui.Items.Button_KSCJ:registerClick(function()
  165. playBtnEffect()
  166. self.ui.Items.ImageView_2:setVisible(not self.ui.Items.ImageView_2:isVisible())
  167. end)
  168. -- 特殊玩法
  169. if self.Zhui1RadioManager then
  170. self.Zhui1RadioManager:addItem(self.ui.Items.CheckBox_13, 0x0080); -- 吊锥
  171. self.Zhui1RadioManager:addItem(self.ui.Items.CheckBox_18, 0x0100); -- 扯锥
  172. -- 设置默认数据
  173. local defaultValue = self:getDefaultValue("specRule") or 0x0080
  174. self.Zhui1RadioManager:setDefault(tonumber(defaultValue));
  175. end
  176. --打法
  177. if self.DafaRadioManager then
  178. self.DafaRadioManager:addItem(self.ui.Items.CheckBox_19, 0x0200); -- 乱吃乱打
  179. self.DafaRadioManager:addItem(self.ui.Items.CheckBox_20, 0x0040); -- 正吃正打
  180. -- 设置默认数据
  181. local defaultValue = self:getDefaultValue("specRule") or 0x0200
  182. self.DafaRadioManager:setDefault(tonumber(defaultValue));
  183. end
  184. -- 头当推当
  185. if self.TouDangCheckBoxManager then
  186. self.TouDangCheckBoxManager:addItem(self.ui.Items.CheckBox_14, "toudang", 0x0010, 0) -- 头当
  187. -- 设置默认状态
  188. local defaultValue = self:getDefaultValue("specRule") or 0
  189. local selecteds = {};
  190. if getNumBand(defaultValue, 0x0010)>0 then
  191. table.insert(selecteds, "toudang")
  192. end
  193. self.TouDangCheckBoxManager:setDefault(selecteds);
  194. local function callBack()
  195. local bSel1 = self.ui.Items.CheckBox_14:getSelectedState()
  196. if bSel1 then
  197. self.ui.Items.CheckBox_15:setSelectedState(false)
  198. self.ui.Items.Text_20:setTextColor(cc.c4b(21,99,97,255))
  199. end
  200. end
  201. self.TouDangCheckBoxManager:setCallback(callBack);
  202. end
  203. if self.TiuDangCheckBoxManager then
  204. self.TiuDangCheckBoxManager:addItem(self.ui.Items.CheckBox_15, "tuidang", 0x0400, 0) -- 推当
  205. -- 设置默认状态
  206. local defaultValue = self:getDefaultValue("specRule") or 0x0400
  207. local selecteds = {};
  208. if getNumBand(defaultValue, 0x0400)>0 then
  209. table.insert(selecteds, "tuidang")
  210. end
  211. self.TiuDangCheckBoxManager:setDefault(selecteds);
  212. local function callBack()
  213. local bSel2 = self.ui.Items.CheckBox_15:getSelectedState()
  214. if bSel2 then
  215. self.ui.Items.CheckBox_14:setSelectedState(false)
  216. self.ui.Items.Text_19:setTextColor(cc.c4b(21,99,97,255))
  217. end
  218. end
  219. self.TiuDangCheckBoxManager:setCallback(callBack);
  220. end
  221. -- 滚翻梯番
  222. if self.BeishuRadioManager then
  223. self.BeishuRadioManager:addItem(self.ui.Items.CheckBox_31, 0x0800); -- 滚番
  224. self.BeishuRadioManager:addItem(self.ui.Items.CheckBox_32, 0x1000); -- 梯番
  225. -- 设置默认数据
  226. local defaultValue = self:getDefaultValue("specRule") or 0x0800
  227. self.BeishuRadioManager:setDefault(tonumber(defaultValue));
  228. end
  229. -- 玩法
  230. if self.WanfaCheckBoxManager then
  231. self.WanfaCheckBoxManager:addItem(self.ui.Items.CheckBox_17, "zhaochiwujiao", 0x0008, 0) -- 召吃无叫
  232. self.WanfaCheckBoxManager:addItem(self.ui.Items.CheckBox_23, "kewanjiao", 0x0002, 0) -- 可弯叫
  233. self.WanfaCheckBoxManager:addItem(self.ui.Items.CheckBox_24, "ruansigenjiafan", 0x2000, 0) -- 软四根加番
  234. self.WanfaCheckBoxManager:addItem(self.ui.Items.CheckBox_25, "xiaojiazimojiafan", 0x0020, 0) -- 小家自摸加番
  235. self.WanfaCheckBoxManager:addItem(self.ui.Items.CheckBox_26, "zhanshanwanfa", 0x0004, 0) -- 占山玩法
  236. -- 设置默认状态
  237. local defaultValue = self:getDefaultValue("specRule") or 0x0002
  238. local selecteds = {};
  239. if getNumBand(defaultValue, 0x0008)>0 then
  240. table.insert(selecteds, "zhaochiwujiao")
  241. end
  242. if getNumBand(defaultValue, 0x0002)>0 then
  243. table.insert(selecteds, "kewanjiao")
  244. end
  245. if getNumBand(defaultValue, 0x2000)>0 then
  246. table.insert(selecteds, "ruansigenjiafan")
  247. end
  248. if getNumBand(defaultValue, 0x0020)>0 then
  249. table.insert(selecteds, "xiaojiazimojiafan")
  250. end
  251. if getNumBand(defaultValue, 0x0004)>0 then
  252. table.insert(selecteds, "zhanshanwanfa")
  253. end
  254. self.WanfaCheckBoxManager:setDefault(selecteds);
  255. end
  256. -- 人数
  257. self.hadHideFangShu = false
  258. if self.pcountRadioManager then
  259. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 3) -- (3人)
  260. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 4) -- (4人)
  261. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, -1) -- (快速成局)
  262. local defaultValue = self:getDefaultValue("playnum") or 3
  263. local startMode = self:getDefaultValue("startMode") or 0
  264. if startMode == 3 then
  265. defaultValue = -1
  266. end
  267. self.pcountRadioManager:setDefault(defaultValue)
  268. self.ui.Items.CheckBox_25:setVisible(defaultValue == 4)
  269. -- 不需要重置勾选 JoonHyun 2021/4/13
  270. --self.ui.Items.CheckBox_25:setSelectedState(false)
  271. self.ui.Items.Text_37:setTextColor(cc.c4b(21,99,97,255))
  272. local function callback1(id)
  273. --local bSel = self.ui.Items.CheckBox_playerCount_3:getResult();
  274. --local result = self.pcountRadioManager:getResult()
  275. if id == 4 then
  276. self.ui.Items.CheckBox_25:setVisible(true)
  277. else
  278. self.ui.Items.CheckBox_25:setVisible(false)
  279. self.ui.Items.CheckBox_25:setSelectedState(false)
  280. self.ui.Items.Text_37:setTextColor(cc.c4b(21,99,97,255))
  281. end
  282. end
  283. self.pcountRadioManager:setCallback(callback1);
  284. end
  285. self:initOtherCheckBoxManager()
  286. self:initLayoutEvent()
  287. self:initJiFenBeiShu()
  288. end
  289. ---
  290. -- 初始化其他选项
  291. -- @return
  292. --
  293. function CreateRoom_nanchong:initOtherCheckBoxManager ()
  294. if not self.otherCheckBoxManager then
  295. return
  296. end
  297. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)
  298. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidChat, "forbidVoice", 1, 0)
  299. local forbidProp = self:getDefaultValue("forbidProp") or 0
  300. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  301. local defaults = {}
  302. if forbidProp > 0 then
  303. table.insert(defaults, "forbidProp")
  304. end
  305. if forbidVoice == 1 then
  306. table.insert(defaults, "forbidVoice")
  307. end
  308. end
  309. -- 面板的点击事件,点击面板后,隐藏所有提示
  310. function CreateRoom_nanchong:initLayoutEvent()
  311. self.ui.Items.Layout_3:registerClick(function()
  312. local buttons = {
  313. {buttonName = "Button_JFBS", tipsName = "ImageView_2"},
  314. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  315. };
  316. -- 隐藏其他提示信息
  317. for k, v in ipairs(buttons) do
  318. local tipsNode = self.ui.Items[v.tipsName]
  319. tipsNode:setVisible(false)
  320. end
  321. end)
  322. end
  323. -- 初始化积分倍数
  324. function CreateRoom_nanchong:initJiFenBeiShu()
  325. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  326. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  327. --当前积分数值
  328. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  329. self:updateJiFenBeiShu()
  330. --积分倍数说明
  331. self.ui.Items.ImageView_JFBS:setVisible(false)
  332. self.ui.Items.Button_JFBS:registerClick(function()
  333. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  334. end)
  335. end
  336. --更新积分倍数
  337. function CreateRoom_nanchong:updateJiFenBeiShu()
  338. self.ui.Items.Text_jifen:setText(self.curJFBS)
  339. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  340. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 1)
  341. end
  342. --按钮加
  343. function CreateRoom_nanchong:onClickAdd()
  344. playBtnEffect()
  345. if not self.curJFBS then
  346. return
  347. end
  348. self.curJFBS = self.curJFBS + 1
  349. if self.curJFBS >= 100 then
  350. self.curJFBS = 100;
  351. end
  352. self:updateJiFenBeiShu()
  353. end
  354. --按钮减
  355. function CreateRoom_nanchong:onClickJian()
  356. playBtnEffect()
  357. if not self.curJFBS then
  358. return
  359. end
  360. self.curJFBS = self.curJFBS - 1
  361. if self.curJFBS <= 0 then
  362. self.curJFBS = 1
  363. end
  364. self:updateJiFenBeiShu()
  365. end
  366. function CreateRoom_nanchong:getRuleResult()
  367. local game_num = self.JuShuRadioManager:getResult()
  368. local payMode = self.PayRadioManager:getResult()
  369. local highLimit = self.FanshuManager:getResult()
  370. local zhui = self.Zhui1RadioManager:getResult()
  371. local dafa = self.DafaRadioManager:getResult()
  372. local toudang = self.TouDangCheckBoxManager:getResult2()
  373. local tuidang = self.TiuDangCheckBoxManager:getResult2()
  374. local beishu = self.BeishuRadioManager:getResult()
  375. local wanFaResult = self.WanfaCheckBoxManager:getResult2()
  376. local playnum = self.pcountRadioManager:getResult()--玩家人数
  377. local Piaorule = self.PiaoRadioManager:getResult()
  378. local startMode = 0
  379. if playnum == -1 then--选择的是快速组局
  380. --playnum = 4
  381. startMode = 1
  382. end
  383. local specRule = 0
  384. for k, v in pairs(wanFaResult) do
  385. if v > 0 then
  386. specRule = getNumOr(specRule, v);
  387. end
  388. end
  389. specRule = getNumOr(specRule, zhui);
  390. specRule = getNumOr(specRule, dafa);
  391. for k, v in pairs(toudang) do
  392. if v > 0 then
  393. specRule = getNumOr(specRule, v);
  394. end
  395. end
  396. for k, v in pairs(tuidang) do
  397. if v > 0 then
  398. specRule = getNumOr(specRule, v);
  399. end
  400. end
  401. specRule = getNumOr(specRule, beishu);
  402. local other = self.otherCheckBoxManager:getResult2()
  403. local forbidProp = other["forbidProp"]
  404. local forbidVoice = other["forbidVoice"]
  405. self.defaultValus =
  406. {
  407. gamerule = 0;
  408. jushu = jushu;
  409. game_num = game_num,
  410. --biHu = 1;
  411. deductRule = payMode,
  412. areaNo = app.user.areano,
  413. startMode = startMode,
  414. playnum = playnum,
  415. specRule = specRule,
  416. highLimit = highLimit,
  417. Piaorule = Piaorule,
  418. baseMulti = self.curJFBS,
  419. forbidProp = forbidProp,
  420. forbidVoice = forbidVoice,
  421. }
  422. -- 保存玩家的选择
  423. self:saveDefaultValues()
  424. local strGameInfo = json.encode(self.defaultValus)
  425. return game_num, strGameInfo
  426. end
  427. return CreateRoom_nanchong