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.

485 lines
15 KiB

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