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.

823 lines
25 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("huamajiangCreateRoomItem", 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, "huamajiang_room.json")
  11. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_huamajiang_three.ui");
  12. self.ui = ui;
  13. self:addChild(ui);
  14. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  15. --房费
  16. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  17. --人数
  18. self.PlayerNumRadioManager = import("luaScript.Tools.RadioManager"):new();
  19. -- 点杠花
  20. self.DianGangHuaRadioManager = import("luaScript.Tools.RadioManager"):new();
  21. -- 多头
  22. self.DuoTouRadioManager = import("luaScript.Tools.RadioManager"):new();
  23. --玩法
  24. self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  25. --换三张
  26. self.HuanSanZhangRadioManager = import("luaScript.Tools.RadioManager"):new();
  27. --萝卜
  28. self.LuoBoRadioManager = import("luaScript.Tools.RadioManager"):new();
  29. --天胡全胡
  30. self.TianHuQuanHuCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  31. --四人胡完
  32. self.SiRenHuWanCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  33. --七对全胡
  34. self.QiDuiRadioManager = import("luaScript.Tools.RadioManager"):new();
  35. --神龙
  36. self.ShenLongRadioManager = import("luaScript.Tools.RadioManager"):new();
  37. -- 飘
  38. self.PiaoRadioManager = import("luaScript.Tools.RadioManager"):new();
  39. --封顶
  40. self.FengDingRadioManager = import("luaScript.Tools.RadioManager"):new();
  41. -- 其他选项
  42. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  43. self:onHideCestView() -- 隐藏cest的界面
  44. end
  45. function MJCreateRoomItem:onHideCestView()
  46. if self.ui.Items.Button_pay0_tips then
  47. self.ui.Items.Button_pay0_tips:setVisible(false)
  48. end
  49. if self.ui.Items.Button_pay1_tips then
  50. self.ui.Items.Button_pay1_tips:setVisible(false)
  51. end
  52. if self.ui.Items.ImageView_pay0_tips then
  53. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  54. end
  55. if self.ui.Items.ImageView_pay1_tips then
  56. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  57. end
  58. end
  59. function MJCreateRoomItem:onShowCestView()
  60. if self.ui.Items.Text_pay0 then
  61. self.ui.Items.Text_pay0:setText("免费")
  62. end
  63. if self.ui.Items.Text_pay1 then
  64. self.ui.Items.Text_pay1:setText("自费")
  65. end
  66. if self.ui.Items.Button_pay0_tips then
  67. self.ui.Items.Button_pay0_tips:setVisible(true)
  68. end
  69. if self.ui.Items.Button_pay1_tips then
  70. self.ui.Items.Button_pay1_tips:setVisible(true)
  71. end
  72. if self.ui.Items.ImageView_pay0_tips then
  73. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  74. end
  75. if self.ui.Items.Button_pay0_tips then
  76. self.ui.Items.Button_pay0_tips:registerClick(function()
  77. if self.ui.Items.ImageView_pay0_tips then
  78. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  79. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  80. end
  81. end)
  82. end
  83. if self.ui.Items.ImageView_pay1_tips then
  84. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  85. end
  86. if self.ui.Items.Button_pay1_tips then
  87. self.ui.Items.Button_pay1_tips:registerClick(function()
  88. if self.ui.Items.ImageView_pay1_tips then
  89. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  90. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  91. end
  92. end)
  93. end
  94. end
  95. function MJCreateRoomItem:onEnter()
  96. MJCreateRoomItem.super.onEnter(self)
  97. self:initPlayTips();
  98. self:initPayRadioManager();
  99. self:initPlayerNumRadioManager();
  100. self:initDianGangHuaRadioManager();
  101. self:initDuoTouRadioManager();
  102. self:initWanFaCheckBoxManager();
  103. self:initHuanSanZhangRadioManager();
  104. self:initLuoBoRadioManager();
  105. self:initTianHuQuanHuCheckBoxManager();
  106. self:initSiRenHuWanCheckBoxManager();
  107. self:initQiDuiRadioManager();
  108. self:initShenLongRadioManager();
  109. self:initPiaoRadioManager();
  110. self:initFengDingRadioManager();
  111. self:initOtherCheckBoxManager();
  112. self:initLayoutEvent()
  113. self:initJiFenBeiShu()
  114. end
  115. --[[/**
  116. * 父类调用
  117. * 根据局数获取房费
  118. * @param jushu
  119. * @return
  120. */--]]
  121. function MJCreateRoomItem:getCreateRoomCost(jushu)
  122. local payTypes = self:getPayTypes();
  123. if not payTypes then
  124. return 0;
  125. end
  126. local payInfo = payTypes[jushu]
  127. if not payInfo then
  128. return 0;
  129. end
  130. local payMode = self.PayRadioManager:getResult()
  131. if payMode == 0 then
  132. return payInfo.roomCard or 0
  133. elseif payMode == 1 then
  134. return payInfo.roomCardAA or 0
  135. end
  136. end
  137. ---
  138. --[[/**
  139. * 整理不同局数对应的房卡消耗
  140. * @param
  141. * @return
  142. */--]]
  143. function MJCreateRoomItem:getPayTypes( )
  144. local payTypes={}
  145. local gameConfig = app.user:getGameConfig(GAME_IDS.huamajiang)--app.gameId);
  146. if not gameConfig then
  147. return ;
  148. end
  149. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  150. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  151. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  152. for idx, gameRound in ipairs(arrGameRound) do
  153. payTypes[gameRound] =
  154. {
  155. roomCard = arrRequireCards[idx],
  156. roomCardAA = arrRequireCardsAA[idx],
  157. }
  158. end
  159. return payTypes;
  160. end
  161. --[[/**
  162. * 初始化帮助信息
  163. * @return
  164. */--]]
  165. function MJCreateRoomItem:initPlayTips()
  166. local buttons = {
  167. {buttonName = "Button_QuickStartTips", tipsName = "ImageView_QuickStartTips"},
  168. {buttonName = "Button_HuLuoBo", tipsName = "ImageView_HuLuoBo"},
  169. {buttonName = "Button_FeiPai", tipsName = "ImageView_FeiPai"},
  170. {buttonName = "Button_ChaoJiLuoBo", tipsName = "ImageView_ChaoJiLuoBo"},
  171. {buttonName = "Button_HuJiaMoPai", tipsName = "ImageView_HuJiaMoPai"},
  172. {buttonName = "Button_ZiDongHu", tipsName = "ImageView_ZiDongHu"},
  173. {buttonName = "Button_MoJiaHuPai", tipsName = "ImageView_MoJiaHuPai"},
  174. {buttonName = "Button_TianHuQuanHu", tipsName = "ImageView_TianHuQuanHu"},
  175. {buttonName = "Button_QiDui_1", tipsName = "ImageView_QiDui_1"},
  176. {buttonName = "Button_QiDui_2", tipsName = "ImageView_QiDui_2"},
  177. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  178. };
  179. -- 点击其中一个,隐藏其他提示信息
  180. local hideOtherTips = function (buttonName)
  181. for k, v in ipairs(buttons) do
  182. local btnNode = self.ui.Items[v.buttonName];
  183. local tipsNode = self.ui.Items[v.tipsName];
  184. if v.buttonName ~= buttonName then
  185. tipsNode:setVisible(false);
  186. end
  187. end
  188. end
  189. -- 注册问号按钮事件
  190. for k, v in ipairs(buttons) do
  191. local btnNode = self.ui.Items[v.buttonName];
  192. local tipsNode = self.ui.Items[v.tipsName];
  193. tipsNode:setVisible(false);
  194. btnNode:registerClick(handler(self, function (obj)
  195. local isVisible = tipsNode:isVisible();
  196. tipsNode:setVisible(not isVisible);
  197. hideOtherTips(v.buttonName);
  198. end));
  199. tipsNode:setTouchEnabled(true);
  200. end
  201. self.ui.Items["Button_ZiDongHu"]:setVisible(false); -- 隐藏胡家摸牌帮助
  202. end
  203. ---
  204. --[[/**
  205. * 初始化房费支付选项
  206. * @return
  207. */--]]
  208. function MJCreateRoomItem:initPayRadioManager ()
  209. if not self.PayRadioManager then
  210. return;
  211. end
  212. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  213. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  214. local default = self:getDefaultValue("deductRule") or 0
  215. self.PayRadioManager:setDefault(default)
  216. self.PayRadioManager:setCallback(function ()
  217. -- 通知创建界面更新显示
  218. app:dispatchEvent({name = "onChangePayMode"})
  219. end);
  220. self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  221. end
  222. --[[/**
  223. * 初始化人数选项
  224. * @return
  225. */--]]
  226. function MJCreateRoomItem:initPlayerNumRadioManager ()
  227. if not self.PlayerNumRadioManager then
  228. return ;
  229. end
  230. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_0, 0);
  231. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_2, 2);
  232. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_3, 3);
  233. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_4, 4);
  234. local defaultValue = self:getDefaultValue("playnum") or 3
  235. local isfaststart = self:getDefaultValue("isfaststart") or 1
  236. if isfaststart==1 then
  237. defaultValue = 0;
  238. end
  239. self.PlayerNumRadioManager:setDefault(defaultValue);
  240. local function refreshWanFaItems(value)
  241. if value == 2 then
  242. -- self.ui.Items.CheckBox_QuPai:setSelectedState(true);
  243. -- self.PiaoRadioManager:setDefault(0);
  244. -- self.ui.Items.CheckBox_HuJiaMoPai:setSelectedState(false);
  245. self.ui.Items.CheckBox_HuLuoBo:setSelectedState(true);
  246. self.ui.Items.CheckBox_ChaoJiLuoBo:setEnabled(true);
  247. self.ui.Items.CheckBox_MoJiaHuPai:setSelectedState(false);
  248. end
  249. -- self.ui.Items.CheckBox_HuJiaMoPai:setEnabled(value ~= 2);
  250. self.ui.Items.CheckBox_HuLuoBo:setEnabled(value ~= 2);
  251. -- self.ui.Items.CheckBox_QuPai:setEnabled(value ~= 2);
  252. -- self.ui.Items.CheckBox_Piao_0:setEnabled(value ~= 2);
  253. -- self.ui.Items.CheckBox_Piao_1:setEnabled(value ~= 2);
  254. -- self.ui.Items.CheckBox_Piao_2:setEnabled(value ~= 2);
  255. self.ui.Items.CheckBox_MoJiaHuPai:setEnabled(value ~= 2);
  256. --新增四人胡完
  257. self.ui.Items.CheckBox_SiRenHuWan:setVisible(value == 4 or value == 0)
  258. --天胡全胡
  259. self.ui.Items.CheckBox_TianHuQuanHu:setVisible(value ~= 2);
  260. --天胡全胡提示按钮
  261. self.ui.Items.Button_TianHuQuanHu:setVisible(value ~= 2);
  262. --神龙和七对全胡二人不显示
  263. self.ui.Items.Layout_Play_5:setVisible(value ~= 2);
  264. self.ui.Items.Layout_QiDui:setVisible(value ~= 2);
  265. end
  266. self.PlayerNumRadioManager:setCallback(function (value)
  267. refreshWanFaItems(value);
  268. self.ui.Items.Layout_1:requestDoLayout()
  269. self.ui.Items.Layout_1:doLayout()
  270. end);
  271. refreshWanFaItems(defaultValue);
  272. end
  273. --[[/**
  274. * 初始化点杠花选项
  275. * @param
  276. * @return
  277. */--]]
  278. function MJCreateRoomItem:initDianGangHuaRadioManager( )
  279. if not self.DianGangHuaRadioManager then
  280. return ;
  281. end
  282. self.DianGangHuaRadioManager:addItem(self.ui.Items.CheckBox_gang_1, 0x02); -- 自摸
  283. self.DianGangHuaRadioManager:addItem(self.ui.Items.CheckBox_gang_2, 0x01); -- 点炮
  284. local specRule = self:getDefaultValue("specRule") or 0;
  285. local defaultValue = 0x02;
  286. if getNumBand(specRule, 0x01) > 0 then
  287. defaultValue = 0x01;
  288. end
  289. if getNumBand(specRule, 0x02) > 0 then
  290. defaultValue = 0x02;
  291. end
  292. self.DianGangHuaRadioManager:setDefault(defaultValue);
  293. end
  294. --[[/**
  295. * 初始化多头选项
  296. * @return
  297. */--]]
  298. function MJCreateRoomItem:initDuoTouRadioManager ()
  299. if not self.DuoTouRadioManager then
  300. return ;
  301. end
  302. self.DuoTouRadioManager:addItem(self.ui.Items.CheckBox_DuoTou_1, 1); -- 多头杠加番
  303. self.DuoTouRadioManager:addItem(self.ui.Items.CheckBox_DuoTou_2, 2); -- 多头加番
  304. local defaultValue = self:getDefaultValue("duogang") or 2;
  305. self.DuoTouRadioManager:setDefault(defaultValue);
  306. end
  307. --[[/**
  308. * 初始化换三张选项
  309. * @return
  310. */--]]
  311. function MJCreateRoomItem:initHuanSanZhangRadioManager()
  312. if not self.HuanSanZhangRadioManager then
  313. return ;
  314. end
  315. self.HuanSanZhangRadioManager:addItem(self.ui.Items.CheckBox_HuanSanZhang, 0x1000)
  316. self.HuanSanZhangRadioManager:addItem(self.ui.Items.CheckBox_BuHuanZhang, 0x2000)
  317. self.HuanSanZhangRadioManager:addItem(self.ui.Items.CheckBox_HunSeHuanSanZhang, 0x80000)
  318. -- 设置默认数据
  319. local specRule = self:getDefaultValue("specRule") or 0x2000
  320. local defaultValue = 0x2000;
  321. if getNumBand(specRule, 0x1000) > 0 then
  322. defaultValue = 0x1000
  323. end
  324. if getNumBand(specRule, 0x2000) > 0 then
  325. defaultValue = 0x2000
  326. end
  327. if getNumBand(specRule, 0x80000) > 0 then
  328. defaultValue = 0x80000
  329. end
  330. self.HuanSanZhangRadioManager:setDefault(defaultValue);
  331. end
  332. --[[/**
  333. * 初始化起始萝卜选项
  334. * @return
  335. */--]]
  336. function MJCreateRoomItem:initLuoBoRadioManager()
  337. if not self.LuoBoRadioManager then
  338. return ;
  339. end
  340. self.LuoBoRadioManager:addItem(self.ui.Items.CheckBox_Luobo_2, 0x4000)
  341. self.LuoBoRadioManager:addItem(self.ui.Items.CheckBox_Luobo_4, 0x8000)
  342. self.LuoBoRadioManager:addItem(self.ui.Items.CheckBox_Luobo_6, 0x10000)
  343. local specRule = self:getDefaultValue("specRule") or 0;
  344. local defaultValue = 0x8000;
  345. if getNumBand(specRule, 0x4000) > 0 then
  346. defaultValue = 0x4000;
  347. end
  348. if getNumBand(specRule, 0x8000) > 0 then
  349. defaultValue = 0x8000;
  350. end
  351. if getNumBand(specRule, 0x10000) > 0 then
  352. defaultValue = 0x10000;
  353. end
  354. self.LuoBoRadioManager:setDefault(tonumber(defaultValue));
  355. end
  356. --[[/**
  357. * 初始化天胡全胡选项
  358. * @return
  359. */--]]
  360. function MJCreateRoomItem:initTianHuQuanHuCheckBoxManager()
  361. if not self.TianHuQuanHuCheckBoxManager then
  362. return ;
  363. end
  364. local checkbox = self.TianHuQuanHuCheckBoxManager;
  365. checkbox:addItem(self.ui.Items.CheckBox_TianHuQuanHu,"tianhuquanhu", 0x20000, 0)
  366. -- 设置默认状态
  367. local defaultValue = self:getDefaultValue("specRule") or 0x20000
  368. local selecteds = {};
  369. if getNumBand(defaultValue, 0x20000)>0 then
  370. table.insert(selecteds, "tianhuquanhu")
  371. end
  372. checkbox:setDefault(selecteds)
  373. end
  374. --[[/**
  375. * 初始化四人全胡选项
  376. * @return
  377. */--]]
  378. function MJCreateRoomItem:initSiRenHuWanCheckBoxManager()
  379. if not self.SiRenHuWanCheckBoxManager then
  380. return ;
  381. end
  382. local checkbox = self.SiRenHuWanCheckBoxManager;
  383. checkbox:addItem(self.ui.Items.CheckBox_SiRenHuWan,"sirenhuwan", 0x40000, 0)
  384. -- 设置默认状态
  385. local defaultValue = self:getDefaultValue("specRule") or 0x40000
  386. local selecteds = {};
  387. if getNumBand(defaultValue, 0x40000)>0 then
  388. table.insert(selecteds, "sirenhuwan")
  389. end
  390. checkbox:setDefault(selecteds)
  391. end
  392. --[[/**
  393. * 初始化七对选项
  394. * @return
  395. */--]]
  396. function MJCreateRoomItem:initQiDuiRadioManager()
  397. if not self.QiDuiRadioManager then
  398. return ;
  399. end
  400. self.QiDuiRadioManager:addItem(self.ui.Items.CheckBox_QiDui_0, 0)
  401. self.QiDuiRadioManager:addItem(self.ui.Items.CheckBox_QiDui_1, 1)
  402. self.QiDuiRadioManager:addItem(self.ui.Items.CheckBox_QiDui_2, 2)
  403. local defaultValue = self:getDefaultValue("QiDuiQuanHu") or 1;
  404. self.QiDuiRadioManager:setDefault(defaultValue);
  405. end
  406. --[[/**
  407. * 初始化神龙选项
  408. * @return
  409. */--]]
  410. function MJCreateRoomItem:initShenLongRadioManager()
  411. if not self.ShenLongRadioManager then
  412. return ;
  413. end
  414. self.ShenLongRadioManager:addItem(self.ui.Items.CheckBox_ShenLong_0, 0)
  415. self.ShenLongRadioManager:addItem(self.ui.Items.CheckBox_ShenLong_1, 10)
  416. self.ShenLongRadioManager:addItem(self.ui.Items.CheckBox_ShenLong_2, 20)
  417. local defaultValue = self:getDefaultValue("ShenLong") or 10;
  418. self.ShenLongRadioManager:setDefault(defaultValue);
  419. end
  420. --[[/**
  421. * 初始化玩法选项
  422. * @return
  423. */--]]
  424. function MJCreateRoomItem:initWanFaCheckBoxManager ()
  425. if not self.WanFaCheckBoxManager then
  426. return ;
  427. end
  428. local checkbox = self.WanFaCheckBoxManager;
  429. checkbox:addItem(self.ui.Items.CheckBox_HuJiaMoPai, "hujiamopai", 0x04, 0);--胡家默牌
  430. checkbox:addItem(self.ui.Items.CheckBox_ZiDongHu, "zidonghu", 0x08, 0);--自动胡
  431. checkbox:addItem(self.ui.Items.CheckBox_FeiPai, "feipai", 0x10, 0);--废牌
  432. checkbox:addItem(self.ui.Items.CheckBox_HuLuoBo, "huluobo", 0x20, 0);--胡萝卜
  433. checkbox:addItem(self.ui.Items.CheckBox_ChaoJiLuoBo, "chaojiluobo", 0x40, 0);--超级萝卜
  434. checkbox:addItem(self.ui.Items.CheckBox_MoJiaHuPai, "mojiahupai", 0x100, 0);--末家胡牌
  435. checkbox:addItem(self.ui.Items.CheckBox_HuJiaQiangGang, "hujiaqianggang", 0x200, 0);--胡家可抢杠
  436. checkbox:addItem(self.ui.Items.CheckBox_ZhuanShou, "zhuanshou", 0x400, 0); -- 转手
  437. checkbox:addItem(self.ui.Items.CheckBox_ChaJiao, "chajiao", 1, 0) -- 查叫
  438. checkbox:addItem(self.ui.Items.CheckBox_NoQiangGang, "noqianggang", 0x800, 0); -- 不可抢杠胡家
  439. local refreshItems = function ()
  440. if not tolua.isnull(self.WanFaCheckBoxManager) then
  441. local result = self.WanFaCheckBoxManager:getResult2();
  442. self.ui.Items.CheckBox_ChaoJiLuoBo:setEnabled(result["huluobo"] > 0);
  443. if result["huluobo"] <= 0 then
  444. self.WanFaCheckBoxManager:setSelectedState("chaojiluobo", false);
  445. end
  446. end
  447. end
  448. local specRule = self:getDefaultValue("specRule") or 0;
  449. local defaultValues = {};
  450. local chajiaoValue = self:getDefaultValue("chajiao") or 1;
  451. if chajiaoValue > 0 then
  452. table.insert( defaultValues, "chajiao")
  453. end
  454. if specRule ~= 0 then
  455. if getNumBand(specRule, 0x04) > 0 then
  456. table.insert(defaultValues, "hujiamopai");
  457. end
  458. if getNumBand(specRule, 0x08) > 0 then
  459. table.insert(defaultValues, "zidonghu");
  460. end
  461. if getNumBand(specRule, 0x10) > 0 then
  462. table.insert(defaultValues, "feipai");
  463. end
  464. if getNumBand(specRule, 0x20) > 0 then
  465. table.insert(defaultValues, "huluobo");
  466. end
  467. if getNumBand(specRule, 0x40) > 0 then
  468. table.insert(defaultValues, "chaojiluobo");
  469. end
  470. if getNumBand(specRule, 0x100) > 0 then
  471. table.insert(defaultValues, "mojiahupai");
  472. end
  473. if getNumBand(specRule, 0x200) > 0 then
  474. table.insert(defaultValues, "hujiaqianggang");
  475. end
  476. if getNumBand(specRule, 0x400) > 0 then
  477. table.insert(defaultValues, "zhuanshou")
  478. end
  479. if getNumBand(specRule, 0x800) > 0 then
  480. table.insert(defaultValues, "noqianggang")
  481. end
  482. else
  483. table.insert(defaultValues, "hujiamopai");
  484. table.insert(defaultValues, "zidonghu");
  485. table.insert(defaultValues, "huluobo");
  486. table.insert(defaultValues, "chaojiluobo");
  487. end
  488. checkbox:setDefault(defaultValues)
  489. checkbox:setCallback(refreshItems);
  490. refreshItems();
  491. end
  492. --[[/**
  493. * 初始化飘选项
  494. * @return
  495. */--]]
  496. function MJCreateRoomItem:initPiaoRadioManager ()
  497. if not self.PiaoRadioManager then
  498. return ;
  499. end
  500. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_0, 0); -- 不飘
  501. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_1, 1); -- 随飘
  502. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_2, 2); -- 必飘
  503. local defaultValue = self:getDefaultValue("piaomode") or 0;
  504. self.PiaoRadioManager:setDefault(defaultValue);
  505. end
  506. --[[/**
  507. * 初始化封顶选项
  508. * @return
  509. */--]]
  510. function MJCreateRoomItem:initFengDingRadioManager ()
  511. if not self.FengDingRadioManager then
  512. return ;
  513. end
  514. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_0fan, -1); -- 封顶3番
  515. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_3fan, 3); -- 封顶3番
  516. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_4fan, 4); -- 封顶4番
  517. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_5fan, 5); -- 封顶5番
  518. local defaultValue = self:getDefaultValue("limitfan") or 5;
  519. self.FengDingRadioManager:setDefault(defaultValue);
  520. end
  521. -- 面板的点击事件,点击面板后,隐藏所有提示
  522. function MJCreateRoomItem:initLayoutEvent()
  523. self.ui.Items.Layout_1:registerClick(function ()
  524. local buttons = {
  525. {buttonName = "Button_QuickStartTips", tipsName = "ImageView_QuickStartTips"},
  526. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  527. {buttonName = "Button_HuLuoBo", tipsName = "ImageView_HuLuoBo"},
  528. {buttonName = "Button_MoJiaHuPai", tipsName = "ImageView_MoJiaHuPai"},
  529. {buttonName = "Button_HuJiaMoPai", tipsName = "ImageView_HuJiaMoPai"},
  530. {buttonName = "Button_ZiDongHu", tipsName = "ImageView_ZiDongHu"},
  531. {buttonName = "Button_ChaoJiLuoBo", tipsName = "ImageView_ChaoJiLuoBo"},
  532. {buttonName = "Button_FeiPai", tipsName = "ImageView_FeiPai"},
  533. {buttonName = "Button_TianHuQuanHu", tipsName = "ImageView_TianHuQuanHu"},
  534. {buttonName = "Button_QiDui_1", tipsName = "ImageView_QiDui_1"},
  535. {buttonName = "Button_QiDui_2", tipsName = "ImageView_QiDui_2"},
  536. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  537. };
  538. -- 隐藏其他提示信息
  539. for k, v in ipairs(buttons) do
  540. local tipsNode = self.ui.Items[v.tipsName]
  541. tipsNode:setVisible(false)
  542. end
  543. end)
  544. end
  545. ---
  546. -- 初始化其他选项
  547. -- @return
  548. --
  549. function MJCreateRoomItem:initOtherCheckBoxManager ()
  550. if not self.otherCheckBoxManager then
  551. return
  552. end
  553. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  554. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  555. local forbidProp = self:getDefaultValue("forbidProp") or 0
  556. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  557. local defaults = {}
  558. if forbidProp > 0 then
  559. table.insert(defaults, "forbidProp")
  560. end
  561. if forbidVoice == 1 then
  562. table.insert(defaults, "forbidVoice")
  563. end
  564. self.otherCheckBoxManager:setDefault(defaults)
  565. end
  566. -- 初始化积分倍数
  567. function MJCreateRoomItem:initJiFenBeiShu()
  568. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  569. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  570. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  571. self:updateJiFenBeiShu()
  572. --积分倍数说明
  573. -- self.ui.Items.ImageView_JFBS:setVisible(false)
  574. -- self.ui.Items.Button_JFBS:registerClick(function()
  575. -- self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  576. -- end)
  577. -- self.ui.Items.Layout_JiFenBeiShu:setVisible(false)
  578. end
  579. --更新积分倍数
  580. function MJCreateRoomItem:updateJiFenBeiShu()
  581. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  582. self.ui.Items.Text_jifen:setText(self.curJFBS)
  583. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  584. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  585. end
  586. --按钮加
  587. function MJCreateRoomItem:onClickAdd()
  588. playBtnEffect()
  589. if not self.curJFBS then
  590. return
  591. end
  592. if self.curJFBS >= 1.0 then
  593. self.curJFBS = self.curJFBS + 1.0
  594. else
  595. self.curJFBS = self.curJFBS + 0.1
  596. end
  597. if self.curJFBS >= 100 then
  598. self.curJFBS = 100;
  599. end
  600. self:updateJiFenBeiShu()
  601. end
  602. --按钮减
  603. function MJCreateRoomItem:onClickJian()
  604. playBtnEffect()
  605. if not self.curJFBS then
  606. return
  607. end
  608. if self.curJFBS <= 1.0 then
  609. self.curJFBS = self.curJFBS - 0.1
  610. else
  611. self.curJFBS = self.curJFBS - 1.0
  612. end
  613. if self.curJFBS <= 0.1 then
  614. self.curJFBS = 0.1
  615. end
  616. self:updateJiFenBeiShu()
  617. end
  618. --设置选中值默认颜色
  619. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  620. if radio then
  621. local index = radio:getResult()
  622. local defaultText = string.format(text.."%d",index)
  623. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  624. end
  625. local result = self.WanFaCheckBoxManager:getResult2()
  626. if result.baojiao == 1 then
  627. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  628. end
  629. end
  630. --点击checkBox时,改变其text的颜色
  631. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  632. local function updataRadioTextColor()
  633. if boxType == "radioBox" then
  634. local index = radio:getResult()
  635. for k,value in pairs(valueTab) do
  636. local item = string.format(text.."%d",value)
  637. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  638. if value == index then
  639. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  640. end
  641. end
  642. elseif boxType == "checkBox" then
  643. local result = self.WanFaCheckBoxManager:getResult2()
  644. if result.baojiao == 1 then
  645. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  646. else
  647. self.ui.Items.Text_BaoJiao:setTextColor(NON_SELECT_COLOR)
  648. end
  649. end
  650. end
  651. radio:setCallback(updataRadioTextColor);
  652. end
  653. function MJCreateRoomItem:getRuleResult()
  654. local game_num = self.JuShuRadioManager:getResult()
  655. local payMode = self.PayRadioManager:getResult()
  656. local playnum = self.PlayerNumRadioManager:getResult();
  657. local isfaststart = (playnum == 0) and 1 or 0;
  658. playnum = (playnum == 0) and 4 or playnum;
  659. local duogang = self.DuoTouRadioManager:getResult();
  660. local piaomode = self.PiaoRadioManager:getResult();
  661. local limitfan = self.FengDingRadioManager:getResult();
  662. local dianganghua = self.DianGangHuaRadioManager:getResult();
  663. local specialRule = 0;
  664. specialRule = getNumOr(specialRule, dianganghua);
  665. local wanfaResult = self.WanFaCheckBoxManager:getResult2();
  666. for k, v in pairs(wanfaResult or {}) do
  667. if k ~= "chaojiluobo" and k~= "chajiao" and v > 0 then
  668. specialRule = getNumOr(specialRule, v);
  669. end
  670. end
  671. if wanfaResult["huluobo"] > 0 then
  672. specialRule = getNumOr(specialRule, wanfaResult["chaojiluobo"]);
  673. end
  674. --换三张
  675. local hszResult = self.HuanSanZhangRadioManager:getResult();
  676. specialRule = getNumOr(specialRule, hszResult);
  677. --起始萝卜
  678. local luoboResult = self.LuoBoRadioManager:getResult();
  679. specialRule = getNumOr(specialRule, luoboResult);
  680. --七对全胡
  681. local qidui = self.QiDuiRadioManager:getResult()
  682. qidui = playnum == 2 and 0 or qidui
  683. --四人胡完
  684. local sirenhuwanResult = self.SiRenHuWanCheckBoxManager:getResult2();
  685. if playnum == 4 or isfaststart == 1 then
  686. specialRule = getNumOr(specialRule, sirenhuwanResult["sirenhuwan"]);
  687. end
  688. local tianhuquanhuResult = self.TianHuQuanHuCheckBoxManager:getResult2();
  689. if playnum ~= 2 then
  690. --天胡全胡
  691. specialRule = getNumOr(specialRule, tianhuquanhuResult["tianhuquanhu"]);
  692. end
  693. --神龙
  694. local shenlong = self.ShenLongRadioManager:getResult()
  695. local chajiao = wanfaResult["chajiao"];
  696. local other = self.otherCheckBoxManager:getResult2()
  697. local forbidProp = other["forbidProp"]
  698. local forbidVoice = other["forbidVoice"]
  699. self.defaultValus = {
  700. gamerule = 2,
  701. QiDuiQuanHu = qidui,
  702. ShenLong = shenlong,
  703. totalgamenum = game_num,
  704. deductRule = payMode,
  705. playnum = playnum,
  706. isfaststart = isfaststart,
  707. limitfan = limitfan,
  708. piaomode = piaomode,
  709. duogang = duogang,
  710. specRule = specialRule,
  711. chajiao = chajiao,
  712. forbidProp = forbidProp,
  713. forbidVoice = forbidVoice,
  714. tingpai = 1,
  715. baseMulti = self.curJFBS,
  716. };
  717. -- 保存玩家的选择
  718. self:saveDefaultValues()
  719. local strGameInfo = json.encode(self.defaultValus);
  720. return game_num, strGameInfo
  721. end
  722. return MJCreateRoomItem