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.

459 regels
14 KiB

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