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.

517 lines
16 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("dazhouCreateRoomItem",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, "dazhoumj_room.json")
  7. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_xzdd_dazhou.ui");
  8. self.ui = ui;
  9. self:addChild(ui);
  10. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  11. --房费
  12. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  13. --人数
  14. self.RenShuRadioManager = 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.SwapCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  23. --萝卜
  24. self.LuoBoCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  25. --玩法
  26. self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  27. --低分加分
  28. self.DiFenJiaFenCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  29. -- 其他选项
  30. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  31. self:onHideCestView() -- 隐藏cest的界面
  32. end
  33. function MJCreateRoomItem:onHideCestView()
  34. if self.ui.Items.Button_pay0_tips then
  35. self.ui.Items.Button_pay0_tips:setVisible(false)
  36. end
  37. if self.ui.Items.Button_pay1_tips then
  38. self.ui.Items.Button_pay1_tips:setVisible(false)
  39. end
  40. if self.ui.Items.ImageView_pay0_tips then
  41. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  42. end
  43. if self.ui.Items.ImageView_pay1_tips then
  44. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  45. end
  46. end
  47. function MJCreateRoomItem:onShowCestView()
  48. if self.ui.Items.Text_pay0 then
  49. self.ui.Items.Text_pay0:setText("免费")
  50. end
  51. if self.ui.Items.Text_pay1 then
  52. self.ui.Items.Text_pay1:setText("自费")
  53. end
  54. if self.ui.Items.Button_pay0_tips then
  55. self.ui.Items.Button_pay0_tips:setVisible(true)
  56. end
  57. if self.ui.Items.Button_pay1_tips then
  58. self.ui.Items.Button_pay1_tips:setVisible(true)
  59. end
  60. if self.ui.Items.ImageView_pay0_tips then
  61. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  62. end
  63. if self.ui.Items.Button_pay0_tips then
  64. self.ui.Items.Button_pay0_tips:registerClick(function()
  65. if self.ui.Items.ImageView_pay0_tips then
  66. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  67. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  68. end
  69. end)
  70. end
  71. if self.ui.Items.ImageView_pay1_tips then
  72. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  73. end
  74. if self.ui.Items.Button_pay1_tips then
  75. self.ui.Items.Button_pay1_tips:registerClick(function()
  76. if self.ui.Items.ImageView_pay1_tips then
  77. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  78. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  79. end
  80. end)
  81. end
  82. end
  83. --根据局数获取房费
  84. function MJCreateRoomItem:getCreateRoomCost(jushu)
  85. if self.cost then
  86. local costInfo = self.cost[jushu]
  87. if costInfo then
  88. local payMode = self.PayRadioManager:getResult()
  89. if payMode == 0 then
  90. return costInfo.roomCard or 0
  91. elseif payMode == 1 then
  92. return costInfo.roomCardAA or 0
  93. end
  94. end
  95. end
  96. return 0
  97. end
  98. function MJCreateRoomItem:onEnter()
  99. MJCreateRoomItem.super.onEnter(self)
  100. -- 整理不同局数对应的房卡消耗
  101. local payTypes={}
  102. local gameConfig = app.user:getGameConfig(GAME_IDS.dazhouMJ)--app.gameId);
  103. if gameConfig then
  104. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  105. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  106. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  107. for idx, gameRound in ipairs(arrGameRound) do
  108. payTypes[gameRound] =
  109. {
  110. roomCard = arrRequireCards[idx],
  111. roomCardAA = arrRequireCardsAA[idx],
  112. }
  113. end
  114. end
  115. self.cost = payTypes
  116. -- 玩家选择局数后,更新房卡消耗
  117. --[[local function updateCost(gameRound)
  118. local costInfo = payTypes[gameRound]
  119. if costInfo then
  120. self.ui.Items.Text_FangZhu:setText(tostring(costInfo.requireCards or 0))
  121. self.ui.Items.Text_AAPay:setText(tostring(costInfo.requireCardsAA or 0))
  122. end
  123. end --]]
  124. -- 房费
  125. if self.PayRadioManager then
  126. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  127. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  128. --self.PayRadioManager:addItem(self.ui.Items.CheckBox_WinFinal, 2); -- 大赢家支付
  129. local default = self:getDefaultValue("deductRule") or 0
  130. self.PayRadioManager:setDefault(default)
  131. --通知创建界面更新显示
  132. local function dispatchUpdateCost()
  133. app:dispatchEvent({name = "onChangePayMode"})
  134. end
  135. self.PayRadioManager:setCallback(dispatchUpdateCost);
  136. self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  137. --self:updataTextColor(self.PayRadioManager,"Text_pay","radioBox",{0,1})
  138. end
  139. -- 封顶
  140. if self.FengDingCheckBoxManager then
  141. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_3fan, 2); -- 2番
  142. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_4fan, 3); -- 3番
  143. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_5fan, 4); -- 4番
  144. local default = self:getDefaultValue("limitfan") or 3
  145. self.FengDingCheckBoxManager:setDefault(default)
  146. --self:setDefaultTextColor(self.FengDingCheckBoxManager,"Text_limit")
  147. --self:updataTextColor(self.FengDingCheckBoxManager,"Text_limit","radioBox",{5,6})
  148. end
  149. -- 自摸
  150. if self.ZiMoCheckBoxManager then
  151. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_1, 1); -- 自摸加底
  152. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_2, 2); -- 自摸加番
  153. --self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_3, 0); -- 自摸不加
  154. local default = self:getDefaultValue("playmode") or 1
  155. self.ZiMoCheckBoxManager:setDefault(default)
  156. end
  157. -- 点杠
  158. if self.DianGangCheckBoxManager then
  159. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
  160. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
  161. local default = self:getDefaultValue("gshmode") or 2
  162. self.DianGangCheckBoxManager:setDefault(default)
  163. end
  164. -- 换三张
  165. if self.SwapCheckBoxManager then
  166. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Change3, 3); -- 换三张
  167. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Change4, 4); -- 换四张
  168. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Nothing, 0); -- 不换张
  169. local default = self:getDefaultValue("swapcardcount") or 3
  170. self.SwapCheckBoxManager:setDefault(default)
  171. end
  172. --玩法
  173. if self.WanFaCheckBoxManager then
  174. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_YaoJiuJiangDui, "jdyj", 1, 0) -- 幺九将对
  175. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_MenQingZhongZhang, "mqzz", 1, 0) -- 门清中张
  176. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TianDiHu, "tdh", 1, 0) -- 天地胡
  177. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_FangNiu, "fanniu", 1, 0) -- 放牛必须过庄胡
  178. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_GuoShouPeng, 'guoshoupeng', 1, 0) -- 过手碰
  179. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_ShiJiao,"sjbsj",1,0) -- 死叫不算叫
  180. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_HuJue,"hjzjf",1,0) -- 胡绝张加番
  181. local jdyj = self:getDefaultValue("jdyj") or 1
  182. local mqzz = self:getDefaultValue("mqzz") or 1
  183. local tdh = self:getDefaultValue("tdh") or 1
  184. local fanniu = self:getDefaultValue("fanniu") or 0
  185. local guoshoupeng = self:getDefaultValue('guoshoupeng') or 0
  186. local sjbsj = self:getDefaultValue("sjbsj") or 1
  187. local hjzjf = self:getDefaultValue("hjzjf") or 1
  188. local selecteds = {}
  189. if jdyj==1 then
  190. table.insert(selecteds,"jdyj")
  191. end
  192. if mqzz==1 then
  193. table.insert(selecteds,"mqzz")
  194. else
  195. --self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  196. end
  197. if tdh==1 then
  198. table.insert(selecteds,"tdh")
  199. end
  200. --[[if getNumBand(specrule, 0x0001)>0 then
  201. table.insert(selecteds, "guozhang")
  202. end
  203. if getNumBand(specrule, 0x0002)>0 then
  204. table.insert(selecteds, "bozimo")
  205. end--]]
  206. if fanniu==1 then
  207. table.insert(selecteds,"fanniu")
  208. end
  209. if guoshoupeng == 1 then
  210. table.insert(selecteds, 'guoshoupeng')
  211. end
  212. if sjbsj == 1 then
  213. table.insert(selecteds,"sjbsj")
  214. end
  215. if hjzjf == 1 then
  216. table.insert(selecteds,"hjzjf")
  217. end
  218. self.WanFaCheckBoxManager:setDefault(selecteds)
  219. self:setDefaultTextColor()
  220. --self:updataTextColor(self.WanFaCheckBoxManager,"","checkBox",{})
  221. end
  222. self:initLayoutEvent()
  223. self:initJiFenBeiShu()
  224. self:initOtherCheckBoxManager()
  225. -- 低分加分
  226. --[[if self.DiFenJiaFenCheckBoxManager then
  227. self.DiFenJiaFenCheckBoxManager:addItem(self.ui.Items.CheckBox_BuJiaFen, 0);-- 不加分
  228. self.DiFenJiaFenCheckBoxManager:addItem(self.ui.Items.CheckBox_JiaFen, 1); -- 加分
  229. local default = self:getDefaultValue("diFenLimit") or 0
  230. if default > 0 then
  231. default = 1
  232. end
  233. self.DiFenJiaFenCheckBoxManager:setDefault(default)
  234. --self:setDefaultTextColor(self.DiFenJiaFenCheckBoxManager,"Text_difenjiadi")
  235. end
  236. --小于多少分
  237. self._txtLimitScore = self.ui.Items.Text_limitScore
  238. local lstMin, lsMax = 1, 40
  239. self.Slider_limitScore = self.ui.Items.Slider_limitScore
  240. self.Slider_limitScore:addEventListener(function ( sender, eventType)
  241. if eventType == 0 then
  242. local per = sender:getPercent()
  243. self.limitScore = math.floor(lstMin + (lsMax-lstMin)/100 * per)
  244. self._txtLimitScore:setString(string.format("%d", self.limitScore))
  245. end
  246. end)
  247. -- default
  248. self.limitScore = self:getDefaultValue("diFenLimit") or 5
  249. if self.limitScore == 0 then
  250. self.limitScore = 5
  251. end
  252. self._txtLimitScore:setString(string.format("%d", tonumber(self.limitScore)))
  253. local lastlsPer = (self.limitScore-lstMin)/(lsMax-lstMin)*100
  254. self.Slider_limitScore:setPercent(lastlsPer)
  255. --加多少分
  256. self._txtAddScore = self.ui.Items.Text_addScore
  257. local asMin, asMax = 1, 40
  258. self.sliderAddScore = self.ui.Items.Slider_addScore
  259. self.sliderAddScore:addEventListener(function ( sender, eventType)
  260. if eventType == 0 then
  261. local per = sender:getPercent()
  262. self.addScore = math.floor(asMin + (asMax-asMin)/100 * per)
  263. self._txtAddScore:setString(string.format("%d", self.addScore))
  264. end
  265. end)
  266. -- default
  267. self.addScore = self:getDefaultValue("diFenAdd") or 5
  268. if self.addScore == 0 then
  269. self.addScore = 5
  270. end
  271. self._txtAddScore:setString(string.format("%d", tonumber(self.addScore)))
  272. local lastfaPer = (self.addScore-asMin)/(asMax-asMin)*100
  273. self.sliderAddScore:setPercent(lastfaPer)--]]
  274. end
  275. ---
  276. -- 初始化其他选项
  277. -- @return
  278. --
  279. function MJCreateRoomItem:initOtherCheckBoxManager ()
  280. if not self.otherCheckBoxManager then
  281. return
  282. end
  283. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  284. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  285. local forbidProp = self:getDefaultValue("forbidProp") or 0
  286. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  287. local defaults = {}
  288. if forbidProp == 1 then
  289. table.insert(defaults, "forbidProp")
  290. end
  291. if forbidVoice == 1 then
  292. table.insert(defaults, "forbidVoice")
  293. end
  294. self.otherCheckBoxManager:setDefault(defaults)
  295. end
  296. -- 面板的点击事件,点击面板后,隐藏所有提示
  297. function MJCreateRoomItem:initLayoutEvent()
  298. self.ui.Items.Layout_1:registerClick(function()
  299. local buttons = {
  300. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  301. };
  302. -- 隐藏其他提示信息
  303. for k, v in ipairs(buttons) do
  304. local tipsNode = self.ui.Items[v.tipsName]
  305. tipsNode:setVisible(false)
  306. end
  307. end)
  308. end
  309. -- 初始化积分倍数
  310. function MJCreateRoomItem:initJiFenBeiShu()
  311. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  312. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  313. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  314. self:updateJiFenBeiShu()
  315. --积分倍数说明
  316. self.ui.Items.ImageView_JFBS:setVisible(false)
  317. self.ui.Items.Button_JFBS:registerClick(function()
  318. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  319. end)
  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 = 0--self.RenShuRadioManager:getResult()
  402. local isfaststart = playnum==0 and 1 or 0
  403. playnum = playnum==0 and 4 or playnum
  404. --下面两局代码限制只有三人模式,没有快速成局
  405. isfaststart = 0 -- 达州麻将只能满4人才能开始
  406. --playnum = 3
  407. local limitfan = self.FengDingCheckBoxManager:getResult()
  408. local playmode = self.ZiMoCheckBoxManager:getResult()
  409. local gshmode = self.DianGangCheckBoxManager:getResult()
  410. local swapresult = self.SwapCheckBoxManager:getResult()
  411. local wanFaResult = self.WanFaCheckBoxManager:getResult2()
  412. local jdyj = wanFaResult.jdyj
  413. local mqzz = wanFaResult.mqzz
  414. local tdh = wanFaResult.tdh
  415. local fanniu = wanFaResult.fanniu
  416. local guoshoupeng = wanFaResult.guoshoupeng
  417. local sjbsj = wanFaResult.sjbsj
  418. local hjzjf = wanFaResult.hjzjf
  419. local swapcard = swapresult
  420. local isSwapcard = 1;
  421. -- if swapcard == 0 then
  422. -- isSwapcard = 0
  423. -- end
  424. if swapcard == 0 then
  425. isSwapcard = 0
  426. elseif swapcard == 3 then
  427. isSwapcard = 1
  428. elseif swapcard == 4 then
  429. isSwapcard = 2
  430. end
  431. local other = self.otherCheckBoxManager:getResult2()
  432. local forbidProp = other["forbidProp"]
  433. local forbidVoice = other["forbidVoice"]
  434. self.defaultValus =
  435. {
  436. gamerule = 1,
  437. totalgamenum = game_num,
  438. deductRule = payMode,
  439. playnum = playnum,
  440. isfaststart = isfaststart,
  441. faststart = isfaststart,
  442. limitfan = limitfan,
  443. playmode = playmode,
  444. gshmode = gshmode,
  445. swapcard = isSwapcard,
  446. jdyj = jdyj,
  447. mqzz = mqzz,
  448. tdh = tdh,
  449. baseMulti = self.curJFBS,
  450. forbidProp = forbidProp,
  451. forbidVoice = forbidVoice,
  452. fanniu = fanniu,
  453. guoshoupeng = guoshoupeng,
  454. sjbsj = sjbsj,
  455. hjzjf = hjzjf,
  456. swapcardcount = swapcard,
  457. }
  458. -- 保存玩家的选择
  459. self:saveDefaultValues()
  460. local strGameInfo = json.encode(self.defaultValus);
  461. return game_num, strGameInfo
  462. end
  463. return MJCreateRoomItem