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.

489 lines
14 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("xzdd4r2fCreateRoomItem",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_2r.json")
  7. self:loadUI()
  8. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  9. --房费
  10. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  11. --人数
  12. self.SwapCardRadioManager = 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.FanShuRadioManager = 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_2r.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. ---
  106. -- onEnter
  107. -- @return
  108. --
  109. function MJCreateRoomItem:onEnter()
  110. MJCreateRoomItem.super.onEnter(self)
  111. self:initPayRadioManager()
  112. self:initFengDingCheckBoxManager()
  113. self:initZiMoCheckBoxManager()
  114. self:initDianGangCheckBoxManager()
  115. self:initWanFaCheckBoxManager()
  116. self:initSwapCardRadioManager()
  117. self:initFanShuRadioManager()
  118. self:initOtherCheckBoxManager()
  119. self:initJiFenBeiShu()
  120. self:initLayoutEvent()
  121. end
  122. ---
  123. -- 初始化房费选项
  124. -- @return
  125. --
  126. function MJCreateRoomItem:initPayRadioManager ()
  127. -- 整理不同局数对应的房卡消耗
  128. local payTypes={}
  129. local gameConfig = app.user:getGameConfig(GAME_IDS.xzddMJ2r)--app.gameId);
  130. if gameConfig then
  131. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  132. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  133. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  134. for idx, gameRound in ipairs(arrGameRound) do
  135. payTypes[gameRound] =
  136. {
  137. roomCard = arrRequireCards[idx],
  138. roomCardAA = arrRequireCardsAA[idx],
  139. }
  140. end
  141. end
  142. self.cost = payTypes
  143. -- 房费
  144. if self.PayRadioManager then
  145. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  146. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  147. --self.PayRadioManager:addItem(self.ui.Items.CheckBox_WinFinal, 2); -- 大赢家支付
  148. local default = self:getDefaultValue("deductRule") or 0
  149. self.PayRadioManager:setDefault(default)
  150. --通知创建界面更新显示
  151. local function dispatchUpdateCost()
  152. app:dispatchEvent({name = "onChangePayMode"})
  153. end
  154. self.PayRadioManager:setCallback(dispatchUpdateCost);
  155. self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  156. end
  157. end
  158. ---
  159. -- 初始化封顶选项
  160. -- @return
  161. --
  162. function MJCreateRoomItem:initFengDingCheckBoxManager ()
  163. if self.FengDingCheckBoxManager then
  164. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_3fan, 2); -- 2番
  165. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_4fan, 3); -- 3番
  166. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_5fan, 4); -- 4番
  167. local default = self:getDefaultValue("limitfan") or 4
  168. self.FengDingCheckBoxManager:setDefault(default)
  169. end
  170. end
  171. ---
  172. -- 初始化自摸选项
  173. -- @return
  174. --
  175. function MJCreateRoomItem:initZiMoCheckBoxManager ()
  176. if self.ZiMoCheckBoxManager then
  177. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_1, 1); -- 自摸加底
  178. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_2, 2); -- 自摸加番
  179. local default = self:getDefaultValue("zimomode") or 2
  180. self.ZiMoCheckBoxManager:setDefault(default)
  181. end
  182. end
  183. ---
  184. -- 初始化点杠选项
  185. -- @return
  186. --
  187. function MJCreateRoomItem:initDianGangCheckBoxManager ()
  188. if self.DianGangCheckBoxManager then
  189. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
  190. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
  191. local default = self:getDefaultValue("gshmode") or 2
  192. self.DianGangCheckBoxManager:setDefault(default)
  193. end
  194. end
  195. ---
  196. -- 初始化玩法选项
  197. -- @return
  198. --
  199. function MJCreateRoomItem:initWanFaCheckBoxManager ()
  200. if self.WanFaCheckBoxManager then
  201. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_YaoJiu, "yj", 1, 0) -- 幺九
  202. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_JiangDui, "jd", 1, 0) -- 将对
  203. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TianDiHu, "tdh", 1, 0) -- 天地胡
  204. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_MenQing, "mq", 1, 0) -- 门清
  205. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_ZhongZhang, "zz", 1, 0) -- 中张
  206. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_2FenQiHu, "efqh", 1, 0) -- 两分起胡
  207. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TingPaiTiShi, "ting", 1, 0) -- 听牌提示
  208. local ting = self:getDefaultValue("ting") or 1
  209. local yj = self:getDefaultValue("yj") or 1
  210. local jd = self:getDefaultValue("jd") or 1
  211. local tdh = self:getDefaultValue("tdh") or 1
  212. local mq = self:getDefaultValue("mq") or 1
  213. local zz = self:getDefaultValue("zz") or 1
  214. local efqh = self:getDefaultValue("efqh") or 0
  215. local selecteds = {}
  216. if ting==1 then
  217. table.insert(selecteds,"ting")
  218. end
  219. if yj == 1 then
  220. table.insert(selecteds, "yj")
  221. end
  222. if jd == 1 then
  223. table.insert(selecteds, "jd")
  224. end
  225. if tdh == 1 then
  226. table.insert(selecteds, "tdh")
  227. end
  228. if mq == 1 then
  229. table.insert(selecteds, "mq")
  230. end
  231. if zz == 1 then
  232. table.insert(selecteds, "zz")
  233. end
  234. if efqh == 1 then
  235. table.insert(selecteds, "efqh")
  236. end
  237. self.WanFaCheckBoxManager:setDefault(selecteds)
  238. self:setDefaultTextColor()
  239. end
  240. end
  241. ---
  242. -- 初始化方数选项
  243. -- @return
  244. --
  245. function MJCreateRoomItem:initFanShuRadioManager ()
  246. if self.FanShuRadioManager then
  247. self.FanShuRadioManager:addItem(self.ui.Items.CheckBox_FanShu2, 2); -- 两方
  248. self.FanShuRadioManager:addItem(self.ui.Items.CheckBox_FanShu3, 3); -- 三方
  249. local default = self:getDefaultValue("cardtype") or 2
  250. self.FanShuRadioManager:setDefault(default)
  251. end
  252. end
  253. ---
  254. -- 初始化其他选项
  255. -- @return
  256. --
  257. function MJCreateRoomItem:initOtherCheckBoxManager ()
  258. if not self.otherCheckBoxManager then
  259. return
  260. end
  261. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  262. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  263. local forbidProp = self:getDefaultValue("forbidProp") or 0
  264. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  265. local defaults = {}
  266. if forbidProp > 0 then
  267. table.insert(defaults, "forbidProp")
  268. end
  269. if forbidVoice == 1 then
  270. table.insert(defaults, "forbidVoice")
  271. end
  272. self.otherCheckBoxManager:setDefault(defaults)
  273. end
  274. -- 面板的点击事件,点击面板后,隐藏所有提示
  275. function MJCreateRoomItem:initLayoutEvent()
  276. self.ui.Items.Layout_1:registerClick(function()
  277. local buttons = {
  278. --{buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
  279. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  280. };
  281. -- 隐藏其他提示信息
  282. for k, v in ipairs(buttons) do
  283. local tipsNode = self.ui.Items[v.tipsName]
  284. tipsNode:setVisible(false)
  285. end
  286. end)
  287. end
  288. ---
  289. -- 初始化换张选项
  290. -- @return
  291. --
  292. function MJCreateRoomItem:initSwapCardRadioManager ()
  293. if not self.SwapCardRadioManager then
  294. return
  295. end
  296. self.SwapCardRadioManager:addItem(self.ui.Items.CheckBox_SwapCard3, 3); -- 换三张
  297. self.SwapCardRadioManager:addItem(self.ui.Items.CheckBox_SwapCard4, 4); -- 换四张
  298. self.SwapCardRadioManager:addItem(self.ui.Items.CheckBox_SwapCard0, 0); -- 换四张
  299. local default = self:getDefaultValue("swapcard") or 3
  300. self.SwapCardRadioManager:setDefault(default)
  301. end
  302. --设置选中值默认颜色
  303. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  304. if radio then
  305. local index = radio:getResult()
  306. local defaultText = string.format(text.."%d",index)
  307. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  308. end
  309. --[[local result = self.WanFaCheckBoxManager:getResult2()
  310. if result.mqzz == 1 then
  311. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  312. end--]]
  313. end
  314. --点击checkBox时,改变其text的颜色
  315. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  316. local function updataRadioTextColor()
  317. if boxType == "radioBox" then
  318. local index = radio:getResult()
  319. for k,value in pairs(valueTab) do
  320. local item = string.format(text.."%d",value)
  321. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  322. if value == index then
  323. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  324. end
  325. end
  326. elseif boxType == "checkBox" then
  327. --[[local result = self.WanFaCheckBoxManager:getResult2()
  328. local result = self.WanFaCheckBoxManager:getResult2()
  329. if result.mqzz == 1 then
  330. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  331. self.ui.Items.CheckBox_BoZiMo:setVisible(true)
  332. else
  333. self.ui.Items.Text_mqzz:setTextColor(NON_SELECT_COLOR)
  334. self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  335. end--]]
  336. end
  337. end
  338. radio:setCallback(updataRadioTextColor);
  339. end
  340. -- 初始化积分倍数
  341. function MJCreateRoomItem:initJiFenBeiShu()
  342. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  343. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  344. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  345. self:updateJiFenBeiShu()
  346. --积分倍数说明
  347. self.ui.Items.ImageView_JFBS:setVisible(false)
  348. self.ui.Items.Button_JFBS:registerClick(function()
  349. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  350. end)
  351. end
  352. --更新积分倍数
  353. function MJCreateRoomItem:updateJiFenBeiShu()
  354. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  355. self.ui.Items.Text_jifen:setText(self.curJFBS)
  356. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  357. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  358. end
  359. --按钮加
  360. function MJCreateRoomItem:onClickAdd()
  361. playBtnEffect()
  362. if not self.curJFBS then
  363. return
  364. end
  365. if self.curJFBS >= 1.0 then
  366. self.curJFBS = self.curJFBS + 1.0
  367. else
  368. self.curJFBS = self.curJFBS + 0.1
  369. end
  370. if self.curJFBS >= 100 then
  371. self.curJFBS = 100;
  372. end
  373. self:updateJiFenBeiShu()
  374. end
  375. --按钮减
  376. function MJCreateRoomItem:onClickJian()
  377. playBtnEffect()
  378. if not self.curJFBS then
  379. return
  380. end
  381. if self.curJFBS <= 1.0 then
  382. self.curJFBS = self.curJFBS - 0.1
  383. else
  384. self.curJFBS = self.curJFBS - 1.0
  385. end
  386. if self.curJFBS <= 0.1 then
  387. self.curJFBS = 0.1
  388. end
  389. self:updateJiFenBeiShu()
  390. end
  391. function MJCreateRoomItem:getRuleResult()
  392. local game_num = self.JuShuRadioManager:getResult()
  393. local payMode = self.PayRadioManager:getResult()
  394. local playnum = 2
  395. local isfaststart = 0
  396. local limitfan = self.FengDingCheckBoxManager:getResult()
  397. local playmode = self.ZiMoCheckBoxManager:getResult()
  398. local gshmode = self.DianGangCheckBoxManager:getResult()
  399. local cardtype = self.FanShuRadioManager:getResult()
  400. local wanFaResult = self.WanFaCheckBoxManager:getResult2()
  401. local ting = wanFaResult.ting
  402. local yj = wanFaResult.yj
  403. local jd = wanFaResult.jd
  404. local tdh = wanFaResult.tdh
  405. local mq = wanFaResult.mq
  406. local zz = wanFaResult.zz
  407. local efqh = wanFaResult.efqh
  408. local other = self.otherCheckBoxManager:getResult2()
  409. local forbidProp = other["forbidProp"]
  410. local forbidVoice = other["forbidVoice"]
  411. local swapcard = self.SwapCardRadioManager:getResult()
  412. local efkh = efqh
  413. self.defaultValus =
  414. {
  415. gamerule = 1,
  416. totalgamenum = game_num,
  417. deductRule = payMode,
  418. playnum = playnum,
  419. isfaststart = isfaststart,
  420. faststart = isfaststart,
  421. limitfan = limitfan,
  422. playmode = playmode,
  423. gshmode = gshmode,
  424. ting = ting,
  425. yj = yj,
  426. jd = jd,
  427. tdh = tdh,
  428. mq = mq,
  429. zz = zz,
  430. efqh = efqh,
  431. cardtype = cardtype,
  432. baseMulti = self.curJFBS,
  433. forbidProp = forbidProp,
  434. forbidVoice = forbidVoice,
  435. swapcard = swapcard,
  436. efkh = efkh,
  437. }
  438. -- 保存玩家的选择
  439. self:saveDefaultValues()
  440. local strGameInfo = json.encode(self.defaultValus);
  441. return game_num, strGameInfo
  442. end
  443. return MJCreateRoomItem