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.

462 lines
14 KiB

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