您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

542 行
16 KiB

  1. -- local MJSelectRadioCompnent = require("luaScript.Views.CreateRoom.Compnent.MJSelectRadioCompnent")
  2. -- local MJGroupCompnent = require("luaScript.Views.CreateRoom.Compnent.MJGroupCompnent")
  3. -- local MJCheckBoxCompnent = require("luaScript.Views.CreateRoom.Compnent.MJCheckBoxCompnent")
  4. -- local MJWanFa=MJFramework.ImportWanFa("MaJiang.MJWanFa")
  5. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  6. local MJCreateRoomItem=class("yibinmajiangCreateRoomItem", CreateRoomItemBase)
  7. local SELECT_COLOR = cc.c4b(213,46,11,255)
  8. local NON_SELECT_COLOR = cc.c4b(21,99,97,255)
  9. function MJCreateRoomItem:ctor(defaultValues)
  10. MJCreateRoomItem.super.ctor(self, defaultValues, "yibinmajiang_room.json")
  11. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_yibinmajiang.ui");
  12. self.ui = ui;
  13. self:addChild(ui);
  14. -- 房费
  15. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  16. -- 人数
  17. self.PlayerNumRadioManager = import("luaScript.Tools.RadioManager"):new();
  18. -- 封顶
  19. self.FengDingRadioManager = import("luaScript.Tools.RadioManager"):new();
  20. -- 飘
  21. self.PiaoRadioManager = import("luaScript.Tools.RadioManager"):new();
  22. -- 听用
  23. self.TingYongRadioManager = import("luaScript.Tools.RadioManager"):new();
  24. -- 11听用多的规则
  25. self.TingYong11MoreCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  26. -- 胡牌
  27. self.HuPaiRadioManager = import("luaScript.Tools.RadioManager"):new();
  28. --玩法
  29. self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):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:initPlayTips()
  87. self:initLayoutEvent()
  88. self:initPayRadioManager()
  89. self:initPlayerNumRadioManager()
  90. self:initFengDingRadioManager()
  91. self:initPiaoRadioManager()
  92. self:initTingYongManager()
  93. self:initTingYong11MoreCheckBoxManager()
  94. self:initHuPaiRadioManager()
  95. self:initWanFaCheckBoxManager()
  96. self:initLayoutEvent()
  97. self:initJiFenBeiShu()
  98. self:initOtherCheckBoxManager()
  99. end
  100. ---
  101. -- 初始化其他选项
  102. -- @return
  103. --
  104. function MJCreateRoomItem:initOtherCheckBoxManager ()
  105. if not self.otherCheckBoxManager then
  106. return
  107. end
  108. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  109. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  110. local forbidProp = self:getDefaultValue("forbidProp") or 0
  111. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  112. local defaults = {}
  113. if forbidProp > 0 then
  114. table.insert(defaults, "forbidProp")
  115. end
  116. if forbidVoice == 1 then
  117. table.insert(defaults, "forbidVoice")
  118. end
  119. self.otherCheckBoxManager:setDefault(defaults)
  120. end
  121. -- 初始化积分倍数
  122. function MJCreateRoomItem:initJiFenBeiShu()
  123. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  124. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  125. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  126. self:updateJiFenBeiShu()
  127. --积分倍数说明
  128. self.ui.Items.ImageView_JFBS:setVisible(false)
  129. end
  130. --更新积分倍数
  131. function MJCreateRoomItem:updateJiFenBeiShu()
  132. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  133. self.ui.Items.Text_jifen:setText(self.curJFBS)
  134. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  135. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  136. end
  137. --按钮加
  138. function MJCreateRoomItem:onClickAdd()
  139. playBtnEffect()
  140. if not self.curJFBS then
  141. return
  142. end
  143. if self.curJFBS >= 1.0 then
  144. self.curJFBS = self.curJFBS + 1.0
  145. else
  146. self.curJFBS = self.curJFBS + 0.1
  147. end
  148. if self.curJFBS >= 100 then
  149. self.curJFBS = 100;
  150. end
  151. self:updateJiFenBeiShu()
  152. end
  153. --按钮减
  154. function MJCreateRoomItem:onClickJian()
  155. playBtnEffect()
  156. if not self.curJFBS then
  157. return
  158. end
  159. if self.curJFBS <= 1.0 then
  160. self.curJFBS = self.curJFBS - 0.1
  161. else
  162. self.curJFBS = self.curJFBS - 1.0
  163. end
  164. if self.curJFBS <= 0.1 then
  165. self.curJFBS = 0.1
  166. end
  167. self:updateJiFenBeiShu()
  168. end
  169. --[[/**
  170. * 父类调用
  171. * 根据局数获取房费
  172. * @param jushu
  173. * @return
  174. */--]]
  175. function MJCreateRoomItem:getCreateRoomCost(jushu)
  176. local payTypes = self:getPayTypes();
  177. if not payTypes then
  178. return 0
  179. end
  180. local payInfo = payTypes[jushu]
  181. if not payInfo then
  182. return 0
  183. end
  184. local payMode = self.PayRadioManager:getResult()
  185. if payMode == 0 then
  186. return payInfo.roomCard or 0
  187. elseif payMode == 1 then
  188. return payInfo.roomCardAA or 0
  189. end
  190. end
  191. ---
  192. --[[/**
  193. * 整理不同局数对应的房卡消耗
  194. * @param
  195. * @return
  196. */--]]
  197. function MJCreateRoomItem:getPayTypes( )
  198. local payTypes={}
  199. local gameConfig = app.user:getGameConfig(GAME_IDS.yibinmajiang)--app.gameId);
  200. if not gameConfig then
  201. return
  202. end
  203. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  204. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  205. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  206. for idx, gameRound in ipairs(arrGameRound) do
  207. payTypes[gameRound] =
  208. {
  209. roomCard = arrRequireCards[idx],
  210. roomCardAA = arrRequireCardsAA[idx],
  211. }
  212. end
  213. return payTypes;
  214. end
  215. --[[/**
  216. * 初始化帮助信息
  217. * @return
  218. */--]]
  219. function MJCreateRoomItem:initPlayTips()
  220. local buttons = {
  221. {buttonName = "Button_QuickStartTips", tipsName = "ImageView_QuickStartTips"},
  222. {buttonName = "Button_2FanQiHu", tipsName = "ImageView_2FanQiHu"},
  223. {buttonName = "Button_TianHuManGuan", tipsName = "ImageView_TianHuManGuan"},
  224. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  225. };
  226. -- 点击其中一个,隐藏其他提示信息
  227. local hideOtherTips = function (buttonName)
  228. for k, v in ipairs(buttons) do
  229. local btnNode = self.ui.Items[v.buttonName];
  230. local tipsNode = self.ui.Items[v.tipsName];
  231. if v.buttonName ~= buttonName then
  232. tipsNode:setVisible(false);
  233. end
  234. end
  235. end
  236. -- 注册问号按钮事件
  237. for k, v in ipairs(buttons) do
  238. local btnNode = self.ui.Items[v.buttonName];
  239. local tipsNode = self.ui.Items[v.tipsName];
  240. -- 按钮点击事件
  241. tipsNode:setVisible(false);
  242. btnNode:registerClick(handler(self, function (obj)
  243. local isVisible = tipsNode:isVisible();
  244. tipsNode:setVisible(not isVisible);
  245. hideOtherTips(v.buttonName);
  246. end));
  247. -- 图片面板点击事件
  248. tipsNode:registerClick(handler(self, function (obj)
  249. tipsNode:setVisible(false);
  250. end));
  251. tipsNode:setTouchEnabled(true);
  252. end
  253. end
  254. -- 面板的点击事件,点击面板后,隐藏所有提示
  255. function MJCreateRoomItem:initLayoutEvent()
  256. self.ui.Items.Layout_1:registerClick(function()
  257. local buttons = {
  258. {buttonName = "Button_QuickStartTips", tipsName = "ImageView_QuickStartTips"},
  259. {buttonName = "Button_2FanQiHu", tipsName = "ImageView_2FanQiHu"},
  260. {buttonName = "Button_TianHuManGuan", tipsName = "ImageView_TianHuManGuan"},
  261. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  262. };
  263. -- 隐藏其他提示信息
  264. for k, v in ipairs(buttons) do
  265. local tipsNode = self.ui.Items[v.tipsName]
  266. tipsNode:setVisible(false)
  267. end
  268. end)
  269. end
  270. ---
  271. --[[/**
  272. * 初始化房费支付选项
  273. * @return
  274. */--]]
  275. function MJCreateRoomItem:initPayRadioManager ()
  276. if not self.PayRadioManager then
  277. return
  278. end
  279. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  280. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  281. local default = self:getDefaultValue("deductRule") or 0
  282. self.PayRadioManager:setDefault(default)
  283. self.PayRadioManager:setCallback(function ()
  284. -- 通知创建界面更新显示
  285. app:dispatchEvent({name = "onChangePayMode"})
  286. end);
  287. end
  288. --[[/**
  289. * 初始化人数选项
  290. * @return
  291. */--]]
  292. function MJCreateRoomItem:initPlayerNumRadioManager ()
  293. if not self.PlayerNumRadioManager then
  294. return
  295. end
  296. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_0, 0);
  297. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_2, 2);
  298. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_3, 3);
  299. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_4, 4);
  300. local defaultValue = self:getDefaultValue("playnum") or 4
  301. local isfaststart = self:getDefaultValue("isfaststart") or 0
  302. if isfaststart==1 then
  303. defaultValue = 0;
  304. end
  305. self.PlayerNumRadioManager:setDefault(defaultValue);
  306. end
  307. --[[/**
  308. * 初始化封顶选项
  309. * @return
  310. */--]]
  311. function MJCreateRoomItem:initFengDingRadioManager ()
  312. if not self.FengDingRadioManager then
  313. return
  314. end
  315. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_5fan, 5);
  316. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_6fan, 6);
  317. local defaultValue = self:getDefaultValue("limitfan") or 5
  318. self.FengDingRadioManager:setDefault(defaultValue);
  319. end
  320. --[[/**
  321. * 初始化飘选项
  322. * @return
  323. */--]]
  324. function MJCreateRoomItem:initPiaoRadioManager ()
  325. if not self.PiaoRadioManager then
  326. return
  327. end
  328. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_0, 0); -- 不飘
  329. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_1, 1); -- 随飘
  330. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_2, 2); -- 定飘
  331. local defaultValue = self:getDefaultValue("piaomode") or 0;
  332. self.PiaoRadioManager:setDefault(defaultValue);
  333. end
  334. --[[/**
  335. * 初始化听用选项
  336. * @return
  337. */--]]
  338. function MJCreateRoomItem:initTingYongManager ()
  339. if not self.TingYongRadioManager then
  340. return
  341. end
  342. self.TingYongRadioManager:addItem(self.ui.Items.CheckBox_tingyong_1, 4)
  343. self.TingYongRadioManager:addItem(self.ui.Items.CheckBox_tingyong_2, 8)
  344. self.TingYongRadioManager:addItem(self.ui.Items.CheckBox_tingyong_3, 11)
  345. local defaultValue = self:getDefaultValue("jingnum") or 8
  346. self.TingYongRadioManager:setDefault(defaultValue);
  347. local function refreshTingYongWanFaItems(value)
  348. if value == 11 then
  349. self.ui.Items.Layout_TingYong_11:setVisible(true)
  350. else
  351. self.ui.Items.Layout_TingYong_11:setVisible(false)
  352. end
  353. self.ui.Items.Layout_1:requestDoLayout()
  354. self.ui.Items.Layout_1:doLayout()
  355. end
  356. self.TingYongRadioManager:setCallback(function (value)
  357. refreshTingYongWanFaItems(value)
  358. end)
  359. refreshTingYongWanFaItems(defaultValue)
  360. end
  361. --[[/**
  362. * 初始化11听用多玩法选项
  363. * @return
  364. */--]]
  365. function MJCreateRoomItem:initTingYong11MoreCheckBoxManager()
  366. if not self.TingYong11MoreCheckBoxManager then
  367. return
  368. end
  369. local checkbox = self.TingYong11MoreCheckBoxManager
  370. checkbox:addItem(self.ui.Items.CheckBox_2FanQiHu, "fan2qihu", 0x01, 0)
  371. checkbox:addItem(self.ui.Items.CheckBox_Jia3Fan, "jia3fan", 0x02, 0)
  372. local jingelevenrule = self:getDefaultValue("jingelevenrule") or 0
  373. local defaultValues = {}
  374. if jingelevenrule ~= 0 then
  375. if getNumBand(jingelevenrule, 0x01) > 0 then
  376. table.insert(defaultValues, "fan2qihu")
  377. end
  378. if getNumBand(jingelevenrule, 0x02) > 0 then
  379. table.insert(defaultValues, "jia3fan")
  380. end
  381. end
  382. checkbox:setDefault(defaultValues)
  383. end
  384. --[[/**
  385. * 初始化胡牌选项
  386. * @return
  387. */--]]
  388. function MJCreateRoomItem:initHuPaiRadioManager ()
  389. if not self.HuPaiRadioManager then
  390. return
  391. end
  392. self.HuPaiRadioManager:addItem(self.ui.Items.CheckBox_DianPaoHu, 2)
  393. self.HuPaiRadioManager:addItem(self.ui.Items.CheckBox_ZiMouHu, 1)
  394. local defaultValue = self:getDefaultValue("humode") or 1
  395. self.HuPaiRadioManager:setDefault(defaultValue)
  396. end
  397. --[[/**
  398. * 初始化玩法选项
  399. * @return
  400. */--]]
  401. function MJCreateRoomItem:initWanFaCheckBoxManager ()
  402. if not self.WanFaCheckBoxManager then
  403. return
  404. end
  405. local checkbox = self.WanFaCheckBoxManager
  406. checkbox:addItem(self.ui.Items.CheckBox_DingQue, "dingque", 0x01, 0)
  407. checkbox:addItem(self.ui.Items.CheckBox_TianHuManGuan, "tianhumanguan", 0x02, 0)
  408. local specialrule = self:getDefaultValue("specialrule") or 0
  409. local defaultValues = {}
  410. if specialrule ~= 0 then
  411. if getNumBand(specialrule, 0x01) > 0 then
  412. table.insert(defaultValues, "dingque")
  413. end
  414. if getNumBand(specialrule, 0x02) > 0 then
  415. table.insert(defaultValues, "tianhumanguan")
  416. end
  417. end
  418. checkbox:setDefault(defaultValues)
  419. end
  420. -- 获取结果
  421. function MJCreateRoomItem:getRuleResult()
  422. local payMode = self.PayRadioManager:getResult() -- 房费
  423. local playnum = self.PlayerNumRadioManager:getResult() -- 人数
  424. local isfaststart = (playnum == 0) and 1 or 0 -- 是否快开
  425. playnum = (playnum == 0) and 4 or playnum -- 人数
  426. local limitfan = self.FengDingRadioManager:getResult() -- 封顶
  427. local piaomode = self.PiaoRadioManager:getResult() -- 飘
  428. local jingnum = self.TingYongRadioManager:getResult() -- 听用
  429. -- 11听用规则
  430. local tingyongmore = self.TingYong11MoreCheckBoxManager:getResult2()
  431. local jingelevenrule = 0
  432. if jingnum == 11 then
  433. for k, v in pairs(tingyongmore or {}) do
  434. jingelevenrule = getNumOr(jingelevenrule, v);
  435. end
  436. else
  437. jingelevenrule = 0
  438. end
  439. -- 胡牌模式
  440. local humode = self.HuPaiRadioManager:getResult()
  441. -- 玩法规则
  442. local specialrule = 0
  443. local wanfaRule = self.WanFaCheckBoxManager:getResult2()
  444. for k, v in pairs(wanfaRule or {}) do
  445. specialrule = getNumOr(specialrule, v)
  446. end
  447. local other = self.otherCheckBoxManager:getResult2()
  448. local forbidProp = other["forbidProp"]
  449. local forbidVoice = other["forbidVoice"]
  450. self.defaultValus = {
  451. gamerule = 1, -- 使用的规则,这个与GameType一致
  452. deductRule = payMode, -- 支付
  453. playnum = playnum, -- 人数
  454. limitfan = limitfan, -- 封顶(番数)
  455. piaomode = piaomode, -- 漂
  456. jingnum = jingnum, -- 听用数
  457. jingelevenrule = jingelevenrule, -- 11听用复选规则
  458. humode = humode, -- 胡牌模式
  459. specialrule = specialrule, -- 玩法规则
  460. isfaststart = isfaststart, -- 是否快开
  461. tingpai = 1, -- 听牌
  462. baseMulti = self.curJFBS,
  463. forbidProp = forbidProp,
  464. forbidVoice = forbidVoice,
  465. };
  466. -- 保存玩家的选择
  467. self:saveDefaultValues()
  468. local strGameInfo = json.encode(self.defaultValus);
  469. return game_num, strGameInfo
  470. end
  471. return MJCreateRoomItem