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.

529 lines
17 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("linshuiCreateRoomItem",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, "linshui_room.json")
  7. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_linshui.ui");
  8. self.ui = ui;
  9. self:addChild(ui);
  10. --房费
  11. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  12. --人数
  13. self.PlayCountRadioManager = import("luaScript.Tools.RadioManager"):new();
  14. -- 局数
  15. self.RoundNumRadioManager = import("luaScript.Tools.RadioManager"):new();
  16. --封顶
  17. self.FengDingRadioManager = import("luaScript.Tools.RadioManager"):new();
  18. -- 飘
  19. self.PiaoRadioManager = import("luaScript.Tools.RadioManager"):new();
  20. -- 底分
  21. self.DiFenRadioManager = import("luaScript.Tools.RadioManager"):new();
  22. --玩法
  23. self.WanFaRadioManager = import("luaScript.Tools.RadioManager"):new();
  24. --可选
  25. self.ExtendsionCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  26. --点杠
  27. self.DianGangCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  28. -- 其他选项
  29. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  30. self:onHideCestView() -- 隐藏cest的界面
  31. end
  32. function MJCreateRoomItem:onHideCestView()
  33. if self.ui.Items.Button_pay0_tips then
  34. self.ui.Items.Button_pay0_tips:setVisible(false)
  35. end
  36. if self.ui.Items.Button_pay1_tips then
  37. self.ui.Items.Button_pay1_tips:setVisible(false)
  38. end
  39. if self.ui.Items.ImageView_pay0_tips then
  40. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  41. end
  42. if self.ui.Items.ImageView_pay1_tips then
  43. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  44. end
  45. end
  46. function MJCreateRoomItem:onShowCestView()
  47. if self.ui.Items.Text_pay0 then
  48. self.ui.Items.Text_pay0:setText("免费")
  49. end
  50. if self.ui.Items.Text_pay1 then
  51. self.ui.Items.Text_pay1:setText("自费")
  52. end
  53. if self.ui.Items.Button_pay0_tips then
  54. self.ui.Items.Button_pay0_tips:setVisible(true)
  55. end
  56. if self.ui.Items.Button_pay1_tips then
  57. self.ui.Items.Button_pay1_tips:setVisible(true)
  58. end
  59. if self.ui.Items.ImageView_pay0_tips then
  60. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  61. end
  62. if self.ui.Items.Button_pay0_tips then
  63. self.ui.Items.Button_pay0_tips:registerClick(function()
  64. if self.ui.Items.ImageView_pay0_tips then
  65. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  66. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  67. end
  68. end)
  69. end
  70. if self.ui.Items.ImageView_pay1_tips then
  71. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  72. end
  73. if self.ui.Items.Button_pay1_tips then
  74. self.ui.Items.Button_pay1_tips:registerClick(function()
  75. if self.ui.Items.ImageView_pay1_tips then
  76. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  77. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  78. end
  79. end)
  80. end
  81. end
  82. --根据局数获取房费
  83. function MJCreateRoomItem:getCreateRoomCost(jushu)
  84. if self.cost then
  85. local costInfo = self.cost[jushu]
  86. if costInfo then
  87. local payMode = self.PayRadioManager:getResult()
  88. if payMode == 0 then
  89. return costInfo.roomCard or 0
  90. elseif payMode == 1 then
  91. return costInfo.roomCardAA or 0
  92. end
  93. end
  94. end
  95. return 0
  96. end
  97. function MJCreateRoomItem:onEnter()
  98. MJCreateRoomItem.super.onEnter(self)
  99. -- 整理不同局数对应的房卡消耗
  100. local payTypes={}
  101. local gameConfig = app.user:getGameConfig(GAME_IDS.linshuiMJ)--app.gameId);
  102. if gameConfig then
  103. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  104. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  105. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  106. for idx, gameRound in ipairs(arrGameRound) do
  107. payTypes[gameRound] =
  108. {
  109. roomCard = arrRequireCards[idx],
  110. roomCardAA = arrRequireCardsAA[idx],
  111. }
  112. end
  113. end
  114. self.cost = payTypes
  115. self:initPayRadioManager();
  116. self:initPlayCountRadioManager();
  117. --self:initFengDingRadioManager();
  118. --self:initPiaoRadioManager()
  119. --self:initDiFenRadioManager()
  120. self:initDianGangHuaRadioManager()
  121. --self:initWanFaRadioManager();
  122. self:initExtendsionCheckBoxManager();
  123. self:initLayoutEvent()
  124. self:initOtherCheckBoxManager();
  125. self:initJiFenBeiShu()
  126. end
  127. --[[
  128. -- 初始化房费支付选项
  129. --]]
  130. function MJCreateRoomItem:initPayRadioManager ( )
  131. if self.PayRadioManager then
  132. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  133. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  134. local default = self:getDefaultValue("deductRule") or 0
  135. self.PayRadioManager:setDefault(default)
  136. --通知创建界面更新显示
  137. local function dispatchUpdateCost()
  138. app:dispatchEvent({name = "onChangePayMode"})
  139. end
  140. self.PayRadioManager:setCallback(dispatchUpdateCost);
  141. -- self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  142. end
  143. end
  144. --[[
  145. -- 初始化人数选项
  146. --]]
  147. function MJCreateRoomItem:initPlayCountRadioManager ( )
  148. if self.PlayCountRadioManager then
  149. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_5, 5); -- 2人2房
  150. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 0); -- 快速开局
  151. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 4); -- 满4人开
  152. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 3); -- 满3人开
  153. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2); -- 满2人开
  154. local defaultValue = self:getDefaultValue("playnum") or 0
  155. local isfaststart = self:getDefaultValue("isfaststart") or 1
  156. local twoFang = self:getDefaultValue("twoFang") or 0
  157. if twoFang == 1 then
  158. defaultValue = 5
  159. end
  160. --2人时显示低分加分
  161. local function renShuCallBack(value)
  162. if value == 5 then
  163. self.ui.Items.CheckBox_DingQue:setSelectedState(false)
  164. self.ui.Items.CheckBox_DingQue:setEnabled(false)
  165. else
  166. self.ui.Items.CheckBox_DingQue:setEnabled(true)
  167. end
  168. --self.ui.Items.Layout_1:requestDoLayout()
  169. --self.ui.Items.Layout_1:doLayout();
  170. end
  171. if isfaststart==1 then
  172. self.PlayCountRadioManager:setDefault(0);
  173. renShuCallBack(0)
  174. else
  175. self.PlayCountRadioManager:setDefault(defaultValue);
  176. renShuCallBack(defaultValue)
  177. end
  178. -- self:setDefaultTextColor(self.PlayCountRadioManager, "Text_player")
  179. -- self:updataTextColor(self.PlayCountRadioManager, "Text_player","radioBox",{0,4,3,2})
  180. self.PlayCountRadioManager:setCallback(renShuCallBack);
  181. end
  182. --快速成局说明
  183. self.ui.Items.ImageView_KSCJ:setVisible(false)
  184. self.ui.Items.Button_KSCJ:registerClick(function()
  185. self.ui.Items.ImageView_KSCJ:setVisible(not self.ui.Items.ImageView_KSCJ:isVisible())
  186. end)
  187. --积分倍数说明
  188. self.ui.Items.ImageView_JFBS:setVisible(false)
  189. self.ui.Items.Button_JFBS:registerClick(function()
  190. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  191. end)
  192. end
  193. --[[
  194. -- 初始化封顶选项
  195. --]]
  196. function MJCreateRoomItem:initFengDingRadioManager ()
  197. -- 封顶
  198. if self.FengDingRadioManager then
  199. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_3fan, 3); -- 封顶3番
  200. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_4fan, 4); -- 封顶4番
  201. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_5fan, 5); -- 封顶5番
  202. local default = self:getDefaultValue("limitfan") or 3
  203. self.FengDingRadioManager:setDefault(default)
  204. end
  205. end
  206. --[[/**
  207. * 初始化飘选项
  208. * @return
  209. */--]]
  210. function MJCreateRoomItem:initPiaoRadioManager ()
  211. if not self.PiaoRadioManager then
  212. return
  213. end
  214. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_0, 0); -- 不飘
  215. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_1, 1); -- 随飘
  216. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_2, 2); -- 定飘
  217. local defaultValue = self:getDefaultValue("piaomode") or 0;
  218. self.PiaoRadioManager:setDefault(defaultValue);
  219. end
  220. --[[/**
  221. * 初始化底分选项
  222. * @return
  223. */--]]
  224. function MJCreateRoomItem:initDiFenRadioManager()
  225. --底分1-100
  226. self._txtDiFen = self.ui.Items.Text_difen
  227. local lstMin, lsMax = 1, 100
  228. self.Slider_limitScore = self.ui.Items.Slider_limitScore
  229. self.Slider_limitScore:addEventListener(function ( sender, eventType)
  230. if eventType == 0 then
  231. local per = sender:getPercent()
  232. self.limitScore = math.floor(lstMin + (lsMax-lstMin)/100 * per)
  233. self._txtDiFen:setString(string.format("%d", self.limitScore))
  234. end
  235. end)
  236. -- default
  237. self.limitScore = self:getDefaultValue("difen") or 1
  238. if self.limitScore == 0 then
  239. self.limitScore = 1
  240. end
  241. self._txtDiFen:setString(string.format("%d", tonumber(self.limitScore)))
  242. local lastlsPer = (self.limitScore-lstMin)/(lsMax-lstMin)*100
  243. self.Slider_limitScore:setPercent(lastlsPer)
  244. --local defaultValue = self:getDefaultValue("gamescore") or 1;
  245. --self.DiFenRadioManager:setDefault(defaultValue);
  246. end
  247. --[[/**
  248. * 初始化点杠花选项
  249. * @return
  250. */--]]
  251. function MJCreateRoomItem:initDianGangHuaRadioManager()
  252. if not self.DianGangCheckBoxManager then
  253. return
  254. end
  255. -- 点杠
  256. if self.DianGangCheckBoxManager then
  257. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
  258. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
  259. local default = self:getDefaultValue("gshmode") or 2
  260. self.DianGangCheckBoxManager:setDefault(default)
  261. end
  262. end
  263. --[[
  264. -- 初始化可选选项
  265. --]]
  266. function MJCreateRoomItem:initExtendsionCheckBoxManager ( )
  267. if self.ExtendsionCheckBoxManager then
  268. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_TingPaiTiShi, "tpts", 0x0001, 0); -- 听牌提示
  269. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_HuanSanZhang, "hsz", 0x0002, 0); -- 换三张
  270. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_DingQue, "dq", 0x0004, 0); -- 定缺
  271. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_BiFan, "bf", 0x0008, 0); -- 比番
  272. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_GZSPH, "gzsfh", 0x0010, 0); -- 过张升番
  273. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_ZJMM, "zjmm", 0x0020, 0); -- 庄家买马
  274. local specRule = self:getDefaultValue("specRule") or 1
  275. local selecteds = {};
  276. if getNumBand(specRule, 0x0001)>0 then
  277. table.insert(selecteds, "tpts")
  278. end
  279. if getNumBand(specRule, 0x0002)>0 then
  280. table.insert(selecteds, "hsz")
  281. end
  282. if getNumBand(specRule, 0x0004)>0 then
  283. table.insert(selecteds, "dq")
  284. end
  285. if getNumBand(specRule, 0x0008)>0 then
  286. table.insert(selecteds, "bf")
  287. end
  288. if getNumBand(specRule, 0x0010)>0 then
  289. table.insert(selecteds, "gzsfh")
  290. end
  291. if getNumBand(specRule, 0x0020)>0 then
  292. table.insert(selecteds, "zjmm")
  293. end
  294. self.ExtendsionCheckBoxManager:setDefault(selecteds)
  295. end
  296. end
  297. --[[
  298. -- 初始化玩法选项
  299. --]]
  300. function MJCreateRoomItem:initWanFaRadioManager ( )
  301. if self.WanFaRadioManager then
  302. self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_Baipai, "placecard", 0x0001, 0); -- 摆牌
  303. local selectedValue = {};
  304. local placecard = self:getDefaultValue("placecard") or 1;
  305. if placecard > 0 then
  306. table.insert(selectedValue, "placecard");
  307. end
  308. self.WanFaRadioManager:setDefault(selectedValue)
  309. end
  310. end
  311. -- 面板的点击事件,点击面板后,隐藏所有提示
  312. function MJCreateRoomItem:initLayoutEvent()
  313. self.ui.Items.Layout_1:registerClick(function()
  314. local buttons = {
  315. {buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
  316. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  317. };
  318. -- 隐藏其他提示信息
  319. for k, v in ipairs(buttons) do
  320. local tipsNode = self.ui.Items[v.tipsName]
  321. tipsNode:setVisible(false)
  322. end
  323. end)
  324. end
  325. ---
  326. -- 初始化其他选项
  327. -- @return
  328. --
  329. function MJCreateRoomItem:initOtherCheckBoxManager ()
  330. if not self.otherCheckBoxManager then
  331. return
  332. end
  333. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  334. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  335. local forbidProp = self:getDefaultValue("forbidProp") or 0
  336. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  337. local defaults = {}
  338. if forbidProp > 0 then
  339. table.insert(defaults, "forbidProp")
  340. end
  341. if forbidVoice == 1 then
  342. table.insert(defaults, "forbidVoice")
  343. end
  344. self.otherCheckBoxManager:setDefault(defaults)
  345. end
  346. -- 初始化积分倍数
  347. function MJCreateRoomItem:initJiFenBeiShu()
  348. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  349. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  350. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  351. self:updateJiFenBeiShu()
  352. end
  353. --更新积分倍数
  354. function MJCreateRoomItem:updateJiFenBeiShu()
  355. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  356. self.ui.Items.Text_jifen:setText(self.curJFBS)
  357. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  358. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  359. end
  360. --按钮加
  361. function MJCreateRoomItem:onClickAdd()
  362. playBtnEffect()
  363. if not self.curJFBS then
  364. return
  365. end
  366. if self.curJFBS >= 1.0 then
  367. self.curJFBS = self.curJFBS + 1.0
  368. else
  369. self.curJFBS = self.curJFBS + 0.1
  370. end
  371. if self.curJFBS >= 100 then
  372. self.curJFBS = 100;
  373. end
  374. self:updateJiFenBeiShu()
  375. end
  376. --按钮减
  377. function MJCreateRoomItem:onClickJian()
  378. playBtnEffect()
  379. if not self.curJFBS then
  380. return
  381. end
  382. if self.curJFBS <= 1.0 then
  383. self.curJFBS = self.curJFBS - 0.1
  384. else
  385. self.curJFBS = self.curJFBS - 1.0
  386. end
  387. if self.curJFBS <= 0.1 then
  388. self.curJFBS = 0.1
  389. end
  390. self:updateJiFenBeiShu()
  391. end
  392. --设置选中值默认颜色
  393. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  394. if radio then
  395. local index = radio:getResult()
  396. local defaultText = string.format(text.."%d",index)
  397. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  398. end
  399. local result = self.WanFaRadioManager:getResult2()
  400. if result.baojiao == 1 then
  401. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  402. end
  403. if result.xiqian == 1 then
  404. self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
  405. end
  406. end
  407. --点击checkBox时,改变其text的颜色
  408. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  409. local function updataRadioTextColor()
  410. if boxType == "radioBox" then
  411. local index = radio:getResult()
  412. for k,value in pairs(valueTab) do
  413. local item = string.format(text.."%d",value)
  414. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  415. if value == index then
  416. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  417. end
  418. end
  419. elseif boxType == "checkBox" then
  420. local result = self.WanFaRadioManager:getResult2()
  421. if result.baojiao == 1 then
  422. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  423. else
  424. self.ui.Items.Text_BaoJiao:setTextColor(NON_SELECT_COLOR)
  425. end
  426. if result.xiqian == 1 then
  427. self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
  428. else
  429. self.ui.Items.Text_XiQian:setTextColor(NON_SELECT_COLOR)
  430. end
  431. end
  432. end
  433. radio:setCallback(updataRadioTextColor);
  434. end
  435. function MJCreateRoomItem:getRuleResult()
  436. local gamerule = 1
  437. local payMode = self.PayRadioManager:getResult(); -- 支付模式
  438. local playnum = self.PlayCountRadioManager:getResult(); -- 玩牌人数, 0表示快速开局
  439. local twoFang = playnum == 5 and 1 or 0
  440. local isfaststart = playnum == 0 and 1 or 0; -- 是否快速开局
  441. playnum = playnum == 0 and 4 or playnum;
  442. if twoFang == 1 then
  443. playnum = 2
  444. end
  445. local gshmode = self.DianGangCheckBoxManager:getResult()
  446. local roundnum = self.RoundNumRadioManager:getResult(); -- 玩牌局数
  447. --local fengding = self.FengDingRadioManager:getResult(); -- 封顶番数
  448. --local gamescore = self.DiFenRadioManager:getResult(); -- 底分
  449. --local piaomode = self.PiaoRadioManager:getResult(); -- 飘
  450. local wanfa = self.WanFaRadioManager:getResult(); -- 自摸加番
  451. local extData = self.ExtendsionCheckBoxManager:getResult2(); -- 可选玩法
  452. local specRule = 0;
  453. for k, v in pairs(extData) do
  454. specRule = getNumOr(specRule, v);
  455. end
  456. local other = self.otherCheckBoxManager:getResult2()
  457. local forbidProp = other["forbidProp"]
  458. local forbidVoice = other["forbidVoice"]
  459. self.defaultValus = {
  460. --zimomode = wanfa,
  461. deductRule = payMode,
  462. playnum = playnum,
  463. gamerule = gamerule or 1, -- 玩法
  464. isfaststart = isfaststart,
  465. specRule = specRule,
  466. --difen = self.limitScore,
  467. --piaomode = piaomode,
  468. --placecard = extData["placecard"],
  469. baseMulti = self.curJFBS,
  470. gshmode = gshmode,
  471. forbidProp = forbidProp,
  472. forbidVoice = forbidVoice,
  473. twoFang = twoFang,
  474. };
  475. -- 保存玩家的选择
  476. self:saveDefaultValues()
  477. local strGameInfo = json.encode(self.defaultValus);
  478. return roundnum, strGameInfo
  479. end
  480. return MJCreateRoomItem