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.

495 lines
15 KiB

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