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.

484 lines
15 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("xzdd3r2fCreateRoomItem",CreateRoomItemBase)
  3. local SELECT_COLOR = cc.c4b(213,46,11,255)
  4. local NON_SELECT_COLOR = cc.c4b(21,99,97,255)
  5. function MJCreateRoomItem:ctor(defaultValues)
  6. MJCreateRoomItem.super.ctor(self, defaultValues, "xzddmj_room_3r2f.json")
  7. self:loadUI()
  8. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  9. --房费
  10. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  11. --人数
  12. self.PlayerNumRadioManager = import("luaScript.Tools.RadioManager"):new();
  13. --封顶
  14. self.FengDingCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  15. --自摸
  16. self.ZiMoCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  17. --点杠
  18. self.DianGangCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  19. --玩法
  20. self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  21. --低分加分
  22. self.DiFenJiaFenCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  23. -- 其他选项
  24. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  25. self:onHideCestView() -- 隐藏cest的界面
  26. end
  27. function MJCreateRoomItem:onHideCestView()
  28. if self.ui.Items.Button_pay0_tips then
  29. self.ui.Items.Button_pay0_tips:setVisible(false)
  30. end
  31. if self.ui.Items.Button_pay1_tips then
  32. self.ui.Items.Button_pay1_tips:setVisible(false)
  33. end
  34. if self.ui.Items.ImageView_pay0_tips then
  35. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  36. end
  37. if self.ui.Items.ImageView_pay1_tips then
  38. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  39. end
  40. end
  41. function MJCreateRoomItem:onShowCestView()
  42. if self.ui.Items.Text_pay0 then
  43. self.ui.Items.Text_pay0:setText("免费")
  44. end
  45. if self.ui.Items.Text_pay1 then
  46. self.ui.Items.Text_pay1:setText("自费")
  47. end
  48. if self.ui.Items.Button_pay0_tips then
  49. self.ui.Items.Button_pay0_tips:setVisible(true)
  50. end
  51. if self.ui.Items.Button_pay1_tips then
  52. self.ui.Items.Button_pay1_tips:setVisible(true)
  53. end
  54. if self.ui.Items.ImageView_pay0_tips then
  55. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  56. end
  57. if self.ui.Items.Button_pay0_tips then
  58. self.ui.Items.Button_pay0_tips:registerClick(function()
  59. if self.ui.Items.ImageView_pay0_tips then
  60. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  61. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  62. end
  63. end)
  64. end
  65. if self.ui.Items.ImageView_pay1_tips then
  66. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  67. end
  68. if self.ui.Items.Button_pay1_tips then
  69. self.ui.Items.Button_pay1_tips:registerClick(function()
  70. if self.ui.Items.ImageView_pay1_tips then
  71. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  72. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  73. end
  74. end)
  75. end
  76. end
  77. ---
  78. -- 加载UI
  79. -- @return
  80. --
  81. function MJCreateRoomItem:loadUI ()
  82. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_xzdd_3r2f.ui");
  83. self.ui = ui;
  84. self:addChild(ui);
  85. end
  86. ---
  87. -- 根据局数获取房费
  88. -- @param jushu
  89. -- @return
  90. --
  91. function MJCreateRoomItem: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.roomCard or 0
  98. elseif payMode == 1 then
  99. return costInfo.roomCardAA or 0
  100. end
  101. end
  102. end
  103. return 0
  104. end
  105. function MJCreateRoomItem:onEnter()
  106. MJCreateRoomItem.super.onEnter(self)
  107. self:initPayRadioManager()
  108. self:initFengDingCheckBoxManager()
  109. self:initZiMoCheckBoxManager()
  110. self:initDianGangCheckBoxManager()
  111. self:initWanFaCheckBoxManager()
  112. self:initPlayerNumRadioManager()
  113. self:initOtherCheckBoxManager()
  114. self:initLayoutEvent()
  115. self:initJiFenBeiShu()
  116. end
  117. ---
  118. -- 初始化房费选项
  119. -- @return
  120. --
  121. function MJCreateRoomItem:initPayRadioManager ()
  122. -- 整理不同局数对应的房卡消耗
  123. local payTypes={}
  124. local gameConfig = app.user:getGameConfig(GAME_IDS.xzddMJ)--app.gameId);
  125. if gameConfig then
  126. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  127. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  128. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  129. for idx, gameRound in ipairs(arrGameRound) do
  130. payTypes[gameRound] =
  131. {
  132. roomCard = arrRequireCards[idx],
  133. roomCardAA = arrRequireCardsAA[idx],
  134. }
  135. end
  136. end
  137. self.cost = payTypes
  138. -- 房费
  139. if self.PayRadioManager then
  140. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  141. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  142. --self.PayRadioManager:addItem(self.ui.Items.CheckBox_WinFinal, 2); -- 大赢家支付
  143. local default = self:getDefaultValue("deductRule") or 0
  144. self.PayRadioManager:setDefault(default)
  145. --通知创建界面更新显示
  146. local function dispatchUpdateCost()
  147. app:dispatchEvent({name = "onChangePayMode"})
  148. end
  149. self.PayRadioManager:setCallback(dispatchUpdateCost);
  150. self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  151. end
  152. end
  153. ---
  154. -- 初始化封顶选项
  155. -- @return
  156. --
  157. function MJCreateRoomItem:initFengDingCheckBoxManager ()
  158. if self.FengDingCheckBoxManager then
  159. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_3fan, 2); -- 2番
  160. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_4fan, 3); -- 3番
  161. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_5fan, 4); -- 4番
  162. local default = self:getDefaultValue("limitfan") or 4
  163. self.FengDingCheckBoxManager:setDefault(default)
  164. end
  165. end
  166. ---
  167. -- 初始化自摸选项
  168. -- @return
  169. --
  170. function MJCreateRoomItem:initZiMoCheckBoxManager ()
  171. if self.ZiMoCheckBoxManager then
  172. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_1, 1); -- 自摸加底
  173. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_2, 2); -- 自摸加番
  174. --self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_3, 0); -- 自摸不加
  175. local default = self:getDefaultValue("zimomode") or 2
  176. self.ZiMoCheckBoxManager:setDefault(default)
  177. end
  178. end
  179. ---
  180. -- 初始化点杠选项
  181. -- @return
  182. --
  183. function MJCreateRoomItem:initDianGangCheckBoxManager ()
  184. if self.DianGangCheckBoxManager then
  185. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
  186. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
  187. local default = self:getDefaultValue("gshmode") or 2
  188. self.DianGangCheckBoxManager:setDefault(default)
  189. end
  190. end
  191. ---
  192. -- 初始化玩法选项
  193. -- @return
  194. --
  195. function MJCreateRoomItem:initWanFaCheckBoxManager ()--玩法
  196. if self.WanFaCheckBoxManager then
  197. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_YaoJiuJiangDui, "jdyj", 1, 0) -- 幺九将对
  198. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_MenQingZhongZhang, "mqzz", 1, 0) -- 门清中张
  199. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TianDiHu, "tdh", 1, 0) -- 天地胡
  200. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_DuiDuiHuLiangFan, "duiduihu2fan", 1, 0) -- 对对胡两番
  201. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_JiaXinWu, "jiaxinwu", 1, 0) -- 夹心五
  202. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_DianPaoKePingHu, "dpcanxiaohu", 1, 0) -- 点炮可平胡
  203. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_FangNiu, "fanniu", 1, 0) -- 放牛必须过庄胡
  204. local jdyj = self:getDefaultValue("jdyj") or 1
  205. local mqzz = self:getDefaultValue("mqzz") or 1
  206. local tdh = self:getDefaultValue("tdh") or 1
  207. -- local ting = self:getDefaultValue("ting") or 1
  208. local duiduihu2fan = self:getDefaultValue("duiduihu2fan") or 1
  209. local jiaxinwu = self:getDefaultValue("jiaxinwu") or 1
  210. local dpcanxiaohu = self:getDefaultValue("dpcanxiaohu") or 0
  211. local fanniu = self:getDefaultValue("fanniu") or 0
  212. local selecteds = {}
  213. if jdyj==1 then
  214. table.insert(selecteds,"jdyj")
  215. end
  216. if mqzz==1 then
  217. table.insert(selecteds,"mqzz")
  218. else
  219. --self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  220. end
  221. if tdh==1 then
  222. table.insert(selecteds,"tdh")
  223. end
  224. if duiduihu2fan==1 then
  225. table.insert(selecteds,"duiduihu2fan")
  226. end
  227. if jiaxinwu==1 then
  228. table.insert(selecteds,"jiaxinwu")
  229. end
  230. if dpcanxiaohu==1 then
  231. table.insert(selecteds,"dpcanxiaohu")
  232. end
  233. if fanniu==1 then
  234. table.insert(selecteds,"fanniu")
  235. end
  236. self.WanFaCheckBoxManager:setDefault(selecteds)
  237. self:setDefaultTextColor()
  238. end
  239. end
  240. ---
  241. -- 初始化人数选项
  242. -- @return
  243. --
  244. function MJCreateRoomItem:initPlayerNumRadioManager ()
  245. if not self.PlayerNumRadioManager then
  246. return
  247. end
  248. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_2Ren, 2); -- 2人
  249. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_3Ren, 3); -- 3人
  250. self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_KSCJ, 0); -- 快速开局
  251. local isfaststart = self:getDefaultValue("isfaststart") or 1
  252. if isfaststart == 1 then
  253. self.PlayerNumRadioManager:setDefault(0)
  254. else
  255. local default = self:getDefaultValue("playnum") or 0
  256. self.PlayerNumRadioManager:setDefault(default)
  257. end
  258. --快速成局说明
  259. self.ui.Items.ImageView_KSCJ:setVisible(false)
  260. self.ui.Items.Button_KSCJ:registerClick(function()
  261. self.ui.Items.ImageView_KSCJ:setVisible(not self.ui.Items.ImageView_KSCJ:isVisible())
  262. end)
  263. end
  264. -- 面板的点击事件,点击面板后,隐藏所有提示
  265. function MJCreateRoomItem:initLayoutEvent()
  266. -- self.ui.Items.Layout_1:registerClick(function()
  267. -- local buttons = {
  268. -- {buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
  269. -- };
  270. -- -- 隐藏其他提示信息
  271. -- for k, v in ipairs(buttons) do
  272. -- local tipsNode = self.ui.Items[v.tipsName]
  273. -- tipsNode:setVisible(false)
  274. -- end
  275. -- end)
  276. end
  277. ---
  278. -- 初始化其他选项
  279. -- @return
  280. --
  281. function MJCreateRoomItem:initOtherCheckBoxManager ()
  282. if not self.otherCheckBoxManager then
  283. return
  284. end
  285. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  286. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  287. local forbidProp = self:getDefaultValue("forbidProp") or 0
  288. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  289. local defaults = {}
  290. if forbidProp > 0 then
  291. table.insert(defaults, "forbidProp")
  292. end
  293. if forbidVoice == 1 then
  294. table.insert(defaults, "forbidVoice")
  295. end
  296. self.otherCheckBoxManager:setDefault(defaults)
  297. end
  298. -- 初始化积分倍数
  299. function MJCreateRoomItem:initJiFenBeiShu()
  300. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  301. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  302. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  303. self:updateJiFenBeiShu()
  304. --积分倍数说明
  305. self.ui.Items.ImageView_JFBS:setVisible(false)
  306. self.ui.Items.Button_JFBS:registerClick(function()
  307. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  308. end)
  309. -- self.ui.Items.Layout_JiFenBeiShu:setVisible(false)
  310. end
  311. --更新积分倍数
  312. function MJCreateRoomItem:updateJiFenBeiShu()
  313. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  314. self.ui.Items.Text_jifen:setText(self.curJFBS)
  315. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  316. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  317. end
  318. --按钮加
  319. function MJCreateRoomItem:onClickAdd()
  320. playBtnEffect()
  321. if not self.curJFBS then
  322. return
  323. end
  324. if self.curJFBS >= 1.0 then
  325. self.curJFBS = self.curJFBS + 1.0
  326. else
  327. self.curJFBS = self.curJFBS + 0.1
  328. end
  329. if self.curJFBS >= 100 then
  330. self.curJFBS = 100;
  331. end
  332. self:updateJiFenBeiShu()
  333. end
  334. --按钮减
  335. function MJCreateRoomItem:onClickJian()
  336. playBtnEffect()
  337. if not self.curJFBS then
  338. return
  339. end
  340. if self.curJFBS <= 1.0 then
  341. self.curJFBS = self.curJFBS - 0.1
  342. else
  343. self.curJFBS = self.curJFBS - 1.0
  344. end
  345. if self.curJFBS <= 0.1 then
  346. self.curJFBS = 0.1
  347. end
  348. self:updateJiFenBeiShu()
  349. end
  350. --设置选中值默认颜色
  351. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  352. if radio then
  353. local index = radio:getResult()
  354. local defaultText = string.format(text.."%d",index)
  355. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  356. end
  357. --[[local result = self.WanFaCheckBoxManager:getResult2()
  358. if result.mqzz == 1 then
  359. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  360. end--]]
  361. end
  362. --点击checkBox时,改变其text的颜色
  363. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  364. local function updataRadioTextColor()
  365. if boxType == "radioBox" then
  366. local index = radio:getResult()
  367. for k,value in pairs(valueTab) do
  368. local item = string.format(text.."%d",value)
  369. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  370. if value == index then
  371. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  372. end
  373. end
  374. elseif boxType == "checkBox" then
  375. --[[local result = self.WanFaCheckBoxManager:getResult2()
  376. local result = self.WanFaCheckBoxManager:getResult2()
  377. if result.mqzz == 1 then
  378. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  379. self.ui.Items.CheckBox_BoZiMo:setVisible(true)
  380. else
  381. self.ui.Items.Text_mqzz:setTextColor(NON_SELECT_COLOR)
  382. self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  383. end--]]
  384. end
  385. end
  386. radio:setCallback(updataRadioTextColor);
  387. end
  388. function MJCreateRoomItem:getRuleResult()
  389. local game_num = self.JuShuRadioManager:getResult()
  390. local payMode = self.PayRadioManager:getResult()
  391. local playnum = self.PlayerNumRadioManager:getResult()
  392. local isfaststart = playnum == 0 and 1 or 0
  393. -- playnum = playnum == 0 and 3 or playnum
  394. --下面两局代码限制只有三人模式,没有快速成局
  395. -- isfaststart = 0
  396. -- playnum = 3
  397. local limitfan = self.FengDingCheckBoxManager:getResult()
  398. local playmode = self.ZiMoCheckBoxManager:getResult()
  399. local gshmode = self.DianGangCheckBoxManager:getResult()
  400. local wanFaResult = self.WanFaCheckBoxManager:getResult2()
  401. local jdyj = wanFaResult.jdyj
  402. local mqzz = wanFaResult.mqzz
  403. local tdh = wanFaResult.tdh
  404. local duiduihu2fan = wanFaResult.duiduihu2fan
  405. local jiaxinwu = wanFaResult.jiaxinwu
  406. local dpcanxiaohu = wanFaResult.dpcanxiaohu
  407. local fanniu = wanFaResult.fanniu
  408. local other = self.otherCheckBoxManager:getResult2()
  409. local forbidProp = other["forbidProp"]
  410. local forbidVoice = other["forbidVoice"]
  411. self.defaultValus =
  412. {
  413. gamerule = 1,
  414. totalgamenum = game_num,
  415. deductRule = payMode,
  416. playnum = playnum,
  417. isfaststart = isfaststart,
  418. faststart = isfaststart,
  419. limitfan = limitfan,
  420. playmode = playmode,
  421. gshmode = gshmode,
  422. jdyj = jdyj,
  423. mqzz = mqzz,
  424. tdh = tdh,
  425. ting = 1,
  426. duiduihu2fan = duiduihu2fan,
  427. jiaxinwu = jiaxinwu,
  428. dpcanxiaohu = dpcanxiaohu,
  429. baseMulti = self.curJFBS,
  430. forbidProp = forbidProp,
  431. forbidVoice = forbidVoice,
  432. fanniu = fanniu,
  433. }
  434. -- 保存玩家的选择
  435. self:saveDefaultValues()
  436. local strGameInfo = json.encode(self.defaultValus);
  437. return game_num, strGameInfo
  438. end
  439. return MJCreateRoomItem