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.

500 lines
16 KiB

  1. --- 红中麻将
  2. local RadioManager = require("luaScript.Tools.RadioManager");
  3. local CheckBoxManager = require("luaScript.Tools.CheckBoxManager");
  4. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  5. local MJCreateRoomItem=class("hongzhongCreateRoomItem",CreateRoomItemBase)
  6. function MJCreateRoomItem:ctor(defaultValues)
  7. MJCreateRoomItem.super.ctor(self, defaultValues, "hongzhong_room.json");
  8. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_hongzhong.ui");
  9. self.ui = ui;
  10. self:addChild(ui);
  11. self:initCreateRoomCost();
  12. -- 支付方式
  13. self.PayRadioManager = RadioManager:new();
  14. -- 人数
  15. self.PlayerCountRadioManager = RadioManager:new();
  16. -- 胡牌
  17. self.HuTypeRadioManager = RadioManager:new();
  18. -- 玩法
  19. self.WanFaCheckBoxManager = CheckBoxManager:new();
  20. -- 红中
  21. self.HongZhongRadioManager = RadioManager:new();
  22. -- 分数
  23. self.FenShuRadioManager = RadioManager:new();
  24. -- 托管
  25. self.HostingCheckBoxManager = CheckBoxManager:new();
  26. -- 抓鸟
  27. self.ZhuaNiaoRadioManager = RadioManager:new();
  28. -- 鸟分
  29. self.NiaoFenRadioManager = RadioManager:new();
  30. -- 其他选项
  31. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  32. self:onHideCestView() -- 隐藏cest的界面
  33. end
  34. function MJCreateRoomItem:onHideCestView()
  35. if self.ui.Items.Button_pay0_tips then
  36. self.ui.Items.Button_pay0_tips:setVisible(false)
  37. end
  38. if self.ui.Items.Button_pay1_tips then
  39. self.ui.Items.Button_pay1_tips:setVisible(false)
  40. end
  41. if self.ui.Items.ImageView_pay0_tips then
  42. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  43. end
  44. if self.ui.Items.ImageView_pay1_tips then
  45. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  46. end
  47. end
  48. function MJCreateRoomItem:onShowCestView()
  49. if self.ui.Items.Text_pay0 then
  50. self.ui.Items.Text_pay0:setText("免费")
  51. end
  52. if self.ui.Items.Text_pay1 then
  53. self.ui.Items.Text_pay1:setText("自费")
  54. end
  55. if self.ui.Items.Button_pay0_tips then
  56. self.ui.Items.Button_pay0_tips:setVisible(true)
  57. end
  58. if self.ui.Items.Button_pay1_tips then
  59. self.ui.Items.Button_pay1_tips:setVisible(true)
  60. end
  61. if self.ui.Items.ImageView_pay0_tips then
  62. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  63. end
  64. if self.ui.Items.Button_pay0_tips then
  65. self.ui.Items.Button_pay0_tips:registerClick(function()
  66. if self.ui.Items.ImageView_pay0_tips then
  67. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  68. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  69. end
  70. end)
  71. end
  72. if self.ui.Items.ImageView_pay1_tips then
  73. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  74. end
  75. if self.ui.Items.Button_pay1_tips then
  76. self.ui.Items.Button_pay1_tips:registerClick(function()
  77. if self.ui.Items.ImageView_pay1_tips then
  78. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  79. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  80. end
  81. end)
  82. end
  83. end
  84. function MJCreateRoomItem:onEnter(...)
  85. MJCreateRoomItem.super.onEnter(self, ...);
  86. self:initPayRadioManager();
  87. self:initPlayerCountRadioManager();
  88. self:initHuTypeRadioManager();
  89. self:initWanFaCheckBoxManager();
  90. self:initHongZhongRadioManager();
  91. self:initFenShuRadioManager();
  92. self:initZhuaNiaoRadioManager();
  93. self:initNiaoFenRadioManager();
  94. self:initHostingCheckBoxManager();
  95. self:initOtherCheckBoxManager();
  96. self:initJiFenBeiShu();
  97. end
  98. function MJCreateRoomItem:initCreateRoomCost ()
  99. -- 整理不同局数对应的房卡消耗
  100. local payTypes={}
  101. local gameConfig = app.user:getGameConfig(GAME_IDS.HongZhong)--app.gameId);
  102. if gameConfig then
  103. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  104. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  105. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  106. for idx, gameRound in ipairs(arrGameRound) do
  107. payTypes[gameRound] =
  108. {
  109. roomCard = arrRequireCards[idx],
  110. roomCardAA = arrRequireCardsAA[idx],
  111. }
  112. end
  113. end
  114. self.cost = payTypes
  115. end
  116. function MJCreateRoomItem:getCreateRoomCost (jushu)
  117. if self.cost then
  118. local costInfo = self.cost[jushu]
  119. if costInfo then
  120. local payMode = self.PayRadioManager:getResult()
  121. if payMode == 0 then
  122. return costInfo.roomCard or 0
  123. elseif payMode == 1 then
  124. return costInfo.roomCardAA or 0
  125. end
  126. end
  127. end
  128. return 0
  129. end
  130. function MJCreateRoomItem:initPayRadioManager ()
  131. if not self.PayRadioManager then
  132. return ;
  133. end
  134. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0);
  135. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AA, 1);
  136. local defaultValue = self:getDefaultValue("deductRule") or 0
  137. self.PayRadioManager:setDefault(tonumber(defaultValue))
  138. self.PayRadioManager:setCallback(function ()
  139. playBtnEffect()
  140. app:dispatchEvent({name = "onChangePayMode"})
  141. end)
  142. end
  143. function MJCreateRoomItem:initPlayerCountRadioManager()
  144. if not self.PlayerCountRadioManager then
  145. return ;
  146. end
  147. self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_0, 4);
  148. self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 0);
  149. self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 1);
  150. self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 2);
  151. local defaultValue = self:getDefaultValue("playnum") or 2;
  152. local isfaststart = self:getDefaultValue("isfaststart") or 1
  153. if isfaststart == 1 then
  154. defaultValue = 4
  155. end
  156. self.PlayerCountRadioManager:setDefault(tonumber(defaultValue));
  157. self.ui.Items.ImageView_2:setVisible(false)
  158. self.ui.Items.Button_KSCJ:registerClick(function()
  159. local isVisible = not self.ui.Items.ImageView_2:isVisible()
  160. self.ui.Items.ImageView_2:setVisible(isVisible)
  161. end)
  162. end
  163. function MJCreateRoomItem:initHuTypeRadioManager()
  164. if not self.HuTypeRadioManager then
  165. return ;
  166. end
  167. self.HuTypeRadioManager:addItem(self.ui.Items.CheckBox_ZiMoHu, 1);
  168. self.HuTypeRadioManager:addItem(self.ui.Items.CheckBox_DianPaoHu, 2);
  169. self.HuTypeRadioManager:setCallback(function (value)
  170. self.ui.Items.CheckBox_HongZhonBuJiePao:setEnabled(value == 2);
  171. self.ui.Items.CheckBox_WuHongZhong:setEnabled(value ~= 2);
  172. self.ui.Items.CheckBox_ZiMo2:setEnabled(value == 1);
  173. self.ui.Items.CheckBox_ZiMo5:setEnabled(value == 1);
  174. if value ~= 2 then
  175. self.ui.Items.CheckBox_HongZhonBuJiePao:setSelectedState(false);
  176. else
  177. self.ui.Items.CheckBox_WuHongZhong:setSelectedState(false);
  178. end
  179. end);
  180. local defaultValue = self:getDefaultValue("playmode") or 1;
  181. if defaultValue == 3 then
  182. defaultValue = 2;
  183. end
  184. self.HuTypeRadioManager:setDefault(defaultValue);
  185. end
  186. function MJCreateRoomItem:initWanFaCheckBoxManager()
  187. if not self.WanFaCheckBoxManager then
  188. return ;
  189. end
  190. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_HongZhonBuJiePao, "hongzhonbujiepao", 3, 0);
  191. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_Piao, "piaotype", 1, 0);
  192. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_DaiQiangGangPao, "canqiangganghu", 1, 0);
  193. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_QiDuiHu, "extrahutype", 1, 0);
  194. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_WuHongZhong, "noredaddniao", 1, 0);
  195. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_BuKePeng, "embarpeng", 1, 0);
  196. -- canqiangganghu = self.checkQiangGangCompnent.isSelect and MJWanFa.canqiangganghu[2].value or MJWanFa.canqiangganghu[1].value,
  197. -- noredaddniao = self.checkWuHongZhongCompnent.isSelect and MJWanFa.noredaddniao[2].value or MJWanFa.noredaddniao[1].value,
  198. -- embarpeng = self.checkPengCompnent.isSelect and MJWanFa.embarpeng[2].value or MJWanFa.embarpeng[1].value,
  199. -- piaotype = self.checkPiaoFenCompnent:getValue(),-- and MJWanFa.piaotype[2].value or MJWanFa.piaotype[1].value,
  200. local defaultValues = {};
  201. local playmode = self:getDefaultValue("playmode") or 1;
  202. if playmode == 3 then
  203. table.insert(defaultValues, "hongzhonbujiepao");
  204. end
  205. local piaotype = self:getDefaultValue("piaotype") or 1;
  206. if piaotype > 0 then
  207. table.insert(defaultValues, "piaotype");
  208. end
  209. local canqiangganghu = self:getDefaultValue("canqiangganghu") or 1;
  210. if canqiangganghu > 0 then
  211. table.insert(defaultValues, "canqiangganghu");
  212. end
  213. local extrahutype = self:getDefaultValue("extrahutype") or 1;
  214. if extrahutype > 0 then
  215. table.insert(defaultValues, "extrahutype");
  216. end
  217. local noredaddniao = self:getDefaultValue("noredaddniao") or 1;
  218. if noredaddniao > 0 then
  219. table.insert(defaultValues, "noredaddniao");
  220. end
  221. local embarpeng = self:getDefaultValue("embarpeng") or 1;
  222. if embarpeng > 0 then
  223. table.insert(defaultValues, "embarpeng");
  224. end
  225. self.WanFaCheckBoxManager:setDefault(defaultValues);
  226. end
  227. --- MJCreateRoomItem:HongZhongRadioManager 红中
  228. function MJCreateRoomItem:initHongZhongRadioManager()
  229. if not self.HongZhongRadioManager then
  230. return ;
  231. end
  232. self.HongZhongRadioManager:addItem(self.ui.Items.CheckBox_HongZhong, 4);
  233. self.HongZhongRadioManager:addItem(self.ui.Items.CheckBox_8HongZhong, 8);
  234. local defaultValue = self:getDefaultValue("redsize") or 4;
  235. self.HongZhongRadioManager:setDefault(defaultValue);
  236. end
  237. -- MJCreateRoomItem:FenShuRadioManager 分数
  238. function MJCreateRoomItem:initFenShuRadioManager()
  239. if not self.FenShuRadioManager then
  240. return ;
  241. end
  242. self.FenShuRadioManager:addItem(self.ui.Items.CheckBox_ZiMo2, 2);
  243. self.FenShuRadioManager:addItem(self.ui.Items.CheckBox_ZiMo5, 5);
  244. local defaultValue = self:getDefaultValue("zimoscore") or 2;
  245. self.FenShuRadioManager:setDefault(defaultValue);
  246. end
  247. --- MJCreateRoomItem:ZhuaNiaoRadioManager 抓鸟
  248. function MJCreateRoomItem:initZhuaNiaoRadioManager()
  249. if not self.ZhuaNiaoRadioManager then
  250. return ;
  251. end
  252. self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_BuZhuaNiao, 0);
  253. self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_YiMaQuanZhong, 1);
  254. self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_Zhua2Niao, 2);
  255. self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_Zhua4Niao, 4);
  256. self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_Zhua6Niao, 6);
  257. self.ZhuaNiaoRadioManager:setCallback(function (value)
  258. self.ui.Items.CheckBox_Niao1:setEnabled(value > 0);
  259. self.ui.Items.CheckBox_Niao2:setEnabled(value > 0);
  260. self.ui.Items.CheckBox_WuHongZhong:setEnabled(value ~= 0)
  261. if value == 0 then
  262. self.ui.Items.CheckBox_WuHongZhong:setSelectedState(false)
  263. end
  264. end);
  265. local defaultValue = self:getDefaultValue("niaonumber") or 4;
  266. self.ZhuaNiaoRadioManager:setDefault(defaultValue);
  267. end
  268. --- MJCreateRoomItem:NiaoFenRadioManager 鸟分
  269. function MJCreateRoomItem:initNiaoFenRadioManager()
  270. if not self.NiaoFenRadioManager then
  271. return ;
  272. end
  273. self.NiaoFenRadioManager:addItem(self.ui.Items.CheckBox_Niao1, 1);
  274. self.NiaoFenRadioManager:addItem(self.ui.Items.CheckBox_Niao2, 2);
  275. local defaultValue = self:getDefaultValue("niaopoint") or 2;
  276. self.NiaoFenRadioManager:setDefault(defaultValue);
  277. end
  278. function MJCreateRoomItem:initHostingCheckBoxManager()
  279. if not self.HostingCheckBoxManager then
  280. return ;
  281. end
  282. self.HostingCheckBoxManager:addItem(self.ui.Items.CheckBox_type_6, "hosting", 1, 0);
  283. self.HostingCheckBoxManager:setCallback(function ()
  284. local values = self.HostingCheckBoxManager:getResult2();
  285. self.ui.Items.Slider_hosttime:setEnabled(values["hosting"] > 0);
  286. end);
  287. local defaultValues = {};
  288. local hosting = self:getDefaultValue("hosting") or 0;
  289. if hosting > 0 then
  290. table.insert(defaultValues, "hosting");
  291. end
  292. self.HostingCheckBoxManager:setDefault(defaultValues);
  293. self.ui.Items.Slider_hosttime:setEnabled(hosting > 0);
  294. local hostMin, hostMax = 30, 240
  295. local slider = self.ui.Items.Slider_hosttime;
  296. local txtSeconds = self.ui.Items.Text_hosting_time;
  297. slider:addEventListener(function ( sender, eventType)
  298. if eventType == 0 then
  299. local per = sender:getPercent()
  300. self.hostingtime = math.floor(hostMin + (hostMax-hostMin)/100 * per)
  301. txtSeconds:setString(string.format("%d", self.hostingtime))
  302. end
  303. end)
  304. -- default
  305. self.hostingtime = self:getDefaultValue("hostingtime") or 60
  306. if self.hostingtime < 30 then self.hostingtime = 60 end
  307. txtSeconds:setString(string.format("%d", tonumber(self.hostingtime)))
  308. local lastPer = (self.hostingtime - hostMin) / (hostMax - hostMin) * 100
  309. slider:setPercent(lastPer)
  310. end
  311. ---
  312. -- 初始化其他选项
  313. -- @return
  314. --
  315. function MJCreateRoomItem:initOtherCheckBoxManager ()
  316. if not self.otherCheckBoxManager then
  317. return
  318. end
  319. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  320. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  321. local forbidProp = self:getDefaultValue("forbidProp") or 0
  322. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  323. local defaults = {}
  324. if forbidProp > 0 then
  325. table.insert(defaults, "forbidProp")
  326. end
  327. if forbidVoice == 1 then
  328. table.insert(defaults, "forbidVoice")
  329. end
  330. self.otherCheckBoxManager:setDefault(defaults)
  331. end
  332. -- 初始化积分倍数
  333. function MJCreateRoomItem:initJiFenBeiShu()
  334. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  335. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  336. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  337. self:updateJiFenBeiShu()
  338. --积分倍数说明
  339. self.ui.Items.ImageView_JFBS:setVisible(false)
  340. self.ui.Items.Button_JFBS:registerClick(function()
  341. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  342. end)
  343. -- self.ui.Items.Layout_JiFenBeiShu:setVisible(false)
  344. end
  345. --更新积分倍数
  346. function MJCreateRoomItem:updateJiFenBeiShu()
  347. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  348. self.ui.Items.Text_jifen:setText(self.curJFBS)
  349. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  350. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  351. end
  352. --按钮加
  353. function MJCreateRoomItem:onClickAdd()
  354. playBtnEffect()
  355. if not self.curJFBS then
  356. return
  357. end
  358. if self.curJFBS >= 1.0 then
  359. self.curJFBS = self.curJFBS + 1.0
  360. else
  361. self.curJFBS = self.curJFBS + 0.1
  362. end
  363. if self.curJFBS >= 100 then
  364. self.curJFBS = 100;
  365. end
  366. self:updateJiFenBeiShu()
  367. end
  368. --按钮减
  369. function MJCreateRoomItem:onClickJian()
  370. playBtnEffect()
  371. if not self.curJFBS then
  372. return
  373. end
  374. if self.curJFBS <= 1.0 then
  375. self.curJFBS = self.curJFBS - 0.1
  376. else
  377. self.curJFBS = self.curJFBS - 1.0
  378. end
  379. if self.curJFBS <= 0.1 then
  380. self.curJFBS = 0.1
  381. end
  382. self:updateJiFenBeiShu()
  383. end
  384. function MJCreateRoomItem:getRuleResult()
  385. -- 支付方式
  386. local deductRule = self.PayRadioManager:getResult();
  387. -- 人数
  388. local playnum = self.PlayerCountRadioManager:getResult();
  389. -- 是否快速开局
  390. local isfaststart = playnum == 4 and 1 or 0;
  391. -- 鸟分
  392. local niaopoint = self.NiaoFenRadioManager:getResult();
  393. -- 抓鸟
  394. local niaonumber = self.ZhuaNiaoRadioManager:getResult();
  395. -- 分数
  396. local zimoscore = self.FenShuRadioManager:getResult();
  397. -- 胡牌类型
  398. local playmode = self.HuTypeRadioManager:getResult();
  399. -- 红中
  400. local redsize = self.HongZhongRadioManager:getResult();
  401. local wanfaValues = self.WanFaCheckBoxManager:getResult2();
  402. local extrahutype = wanfaValues["extrahutype"];
  403. local canqiangganghu = wanfaValues["canqiangganghu"];
  404. local noredaddniao = wanfaValues["noredaddniao"];
  405. local embarpeng = wanfaValues["embarpeng"];
  406. local piaotype = wanfaValues["piaotype"];
  407. for k, v in pairs(wanfaValues or {}) do
  408. if k == "hongzhonbujiepao" and v > 0 then
  409. playmode = 3;
  410. end
  411. end
  412. local hostingValues = self.HostingCheckBoxManager:getResult2();
  413. hosting = hostingValues["hosting"] or 0;
  414. if playmode == 2 or playmode == 3 then
  415. zimoscore = nil;
  416. end
  417. local other = self.otherCheckBoxManager:getResult2()
  418. local forbidProp = other["forbidProp"]
  419. local forbidVoice = other["forbidVoice"]
  420. self.defaultValus={
  421. gamerule = 1,
  422. playmode = playmode,
  423. deductRule = deductRule,
  424. playnum = playnum,
  425. isfaststart = isfaststart,
  426. niaopoint = niaopoint,
  427. niaonumber = niaonumber,
  428. zimoscore = zimoscore,
  429. redsize = redsize,
  430. extrahutype = extrahutype,
  431. canqiangganghu = canqiangganghu,
  432. noredaddniao = noredaddniao,
  433. embarpeng = embarpeng,
  434. piaotype = piaotype,
  435. hosting = hosting,
  436. hostingtime = self.hostingtime or 60,
  437. isHongZhong = 1,
  438. baseMulti = self.curJFBS,
  439. forbidProp = forbidProp,
  440. forbidVoice = forbidVoice,
  441. }
  442. -- 保存玩家的选择
  443. self:saveDefaultValues()
  444. return 0, json.encode(self.defaultValus);
  445. end
  446. return MJCreateRoomItem