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.

456 lines
14 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("ncmajCreateRoomItem",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, "ncmaj_room.json")
  7. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_ncmaj.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.nanchongMJ)--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. --积分倍数说明
  166. self.ui.Items.ImageView_JFBS:setVisible(false)
  167. self.ui.Items.Button_JFBS:registerClick(function()
  168. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  169. end)
  170. end
  171. --[[
  172. -- 初始化封顶选项
  173. --]]
  174. function MJCreateRoomItem:initFengDingRadioManager ()
  175. -- 封顶
  176. if self.FengDingRadioManager then
  177. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_3fan, 3); -- 封顶3番
  178. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_4fan, 4); -- 封顶4番
  179. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_5fan, 5); -- 封顶5番
  180. local default = self:getDefaultValue("limitfan") or 3
  181. self.FengDingRadioManager:setDefault(default)
  182. end
  183. end
  184. --[[/**
  185. * 初始化飘选项
  186. * @return
  187. */--]]
  188. function MJCreateRoomItem:initPiaoRadioManager ()
  189. if not self.PiaoRadioManager then
  190. return
  191. end
  192. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_0, 0); -- 不飘
  193. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_1, 1); -- 随飘
  194. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_2, 2); -- 定飘
  195. local defaultValue = self:getDefaultValue("piaomode") or 0;
  196. self.PiaoRadioManager:setDefault(defaultValue);
  197. end
  198. --[[/**
  199. * 初始化底分选项
  200. * @return
  201. */--]]
  202. function MJCreateRoomItem:initDiFenRadioManager()
  203. if not self.DiFenRadioManager then
  204. return
  205. end
  206. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_0, 1); -- 1分
  207. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_1, 2); -- 2分
  208. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_2, 3); -- 3分
  209. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_3, 4); -- 4分
  210. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_4, 5); -- 5分
  211. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_5, 10); -- 10分
  212. self.DiFenRadioManager:addItem(self.ui.Items.CheckBox_jiadi_6, 15); -- 15分
  213. local defaultValue = self:getDefaultValue("gamescore") or 1;
  214. self.DiFenRadioManager:setDefault(defaultValue);
  215. end
  216. --[[
  217. -- 初始化可选选项
  218. --]]
  219. function MJCreateRoomItem:initExtendsionCheckBoxManager ( )
  220. if self.ExtendsionCheckBoxManager then
  221. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_Baipai, "placecard", 0x0001, 0); -- 摆牌
  222. local selectedValue = {};
  223. local placecard = self:getDefaultValue("placecard") or 1;
  224. if placecard > 0 then
  225. table.insert(selectedValue, "placecard");
  226. end
  227. self.ExtendsionCheckBoxManager:setDefault(selectedValue)
  228. end
  229. end
  230. --[[
  231. -- 初始化玩法选项
  232. --]]
  233. function MJCreateRoomItem:initWanFaRadioManager ( )
  234. if self.WanFaRadioManager then
  235. self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_Baipai, "placecard", 0x0001, 0); -- 摆牌
  236. local selectedValue = {};
  237. local placecard = self:getDefaultValue("placecard") or 1;
  238. if placecard > 0 then
  239. table.insert(selectedValue, "placecard");
  240. end
  241. self.WanFaRadioManager:setDefault(selectedValue)
  242. end
  243. end
  244. -- 面板的点击事件,点击面板后,隐藏所有提示
  245. function MJCreateRoomItem:initLayoutEvent()
  246. self.ui.Items.Layout_1:registerClick(function()
  247. local buttons = {
  248. {buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
  249. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  250. };
  251. -- 隐藏其他提示信息
  252. for k, v in ipairs(buttons) do
  253. local tipsNode = self.ui.Items[v.tipsName]
  254. tipsNode:setVisible(false)
  255. end
  256. end)
  257. end
  258. ---
  259. -- 初始化其他选项
  260. -- @return
  261. --
  262. function MJCreateRoomItem:initOtherCheckBoxManager ()
  263. if not self.otherCheckBoxManager then
  264. return
  265. end
  266. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  267. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  268. local forbidProp = self:getDefaultValue("forbidProp") or 0
  269. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  270. local defaults = {}
  271. if forbidProp > 0 then
  272. table.insert(defaults, "forbidProp")
  273. end
  274. if forbidVoice == 1 then
  275. table.insert(defaults, "forbidVoice")
  276. end
  277. self.otherCheckBoxManager:setDefault(defaults)
  278. end
  279. -- 初始化积分倍数
  280. function MJCreateRoomItem:initJiFenBeiShu()
  281. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  282. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  283. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  284. self:updateJiFenBeiShu()
  285. end
  286. --更新积分倍数
  287. function MJCreateRoomItem:updateJiFenBeiShu()
  288. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  289. self.ui.Items.Text_jifen:setText(self.curJFBS)
  290. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  291. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  292. end
  293. --按钮加
  294. function MJCreateRoomItem:onClickAdd()
  295. playBtnEffect()
  296. if not self.curJFBS then
  297. return
  298. end
  299. if self.curJFBS >= 1.0 then
  300. self.curJFBS = self.curJFBS + 1.0
  301. else
  302. self.curJFBS = self.curJFBS + 0.1
  303. end
  304. if self.curJFBS >= 100 then
  305. self.curJFBS = 100;
  306. end
  307. self:updateJiFenBeiShu()
  308. end
  309. --按钮减
  310. function MJCreateRoomItem:onClickJian()
  311. playBtnEffect()
  312. if not self.curJFBS then
  313. return
  314. end
  315. if self.curJFBS <= 1.0 then
  316. self.curJFBS = self.curJFBS - 0.1
  317. else
  318. self.curJFBS = self.curJFBS - 1.0
  319. end
  320. if self.curJFBS <= 0.1 then
  321. self.curJFBS = 0.1
  322. end
  323. self:updateJiFenBeiShu()
  324. end
  325. --设置选中值默认颜色
  326. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  327. if radio then
  328. local index = radio:getResult()
  329. local defaultText = string.format(text.."%d",index)
  330. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  331. end
  332. local result = self.WanFaRadioManager:getResult2()
  333. if result.baojiao == 1 then
  334. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  335. end
  336. if result.xiqian == 1 then
  337. self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
  338. end
  339. end
  340. --点击checkBox时,改变其text的颜色
  341. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  342. local function updataRadioTextColor()
  343. if boxType == "radioBox" then
  344. local index = radio:getResult()
  345. for k,value in pairs(valueTab) do
  346. local item = string.format(text.."%d",value)
  347. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  348. if value == index then
  349. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  350. end
  351. end
  352. elseif boxType == "checkBox" then
  353. local result = self.WanFaRadioManager:getResult2()
  354. if result.baojiao == 1 then
  355. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  356. else
  357. self.ui.Items.Text_BaoJiao:setTextColor(NON_SELECT_COLOR)
  358. end
  359. if result.xiqian == 1 then
  360. self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
  361. else
  362. self.ui.Items.Text_XiQian:setTextColor(NON_SELECT_COLOR)
  363. end
  364. end
  365. end
  366. radio:setCallback(updataRadioTextColor);
  367. end
  368. function MJCreateRoomItem:getRuleResult()
  369. local payMode = self.PayRadioManager:getResult(); -- 支付模式
  370. local playnum = self.PlayCountRadioManager:getResult(); -- 玩牌人数, 0表示快速开局
  371. local isfaststart = playnum == 0 and 1 or 0; -- 是否快速开局
  372. playnum = playnum == 0 and 4 or playnum;
  373. local roundnum = self.RoundNumRadioManager:getResult(); -- 玩牌局数
  374. --local fengding = self.FengDingRadioManager:getResult(); -- 封顶番数
  375. local gamescore = self.DiFenRadioManager:getResult(); -- 底分
  376. local piaomode = self.PiaoRadioManager:getResult(); -- 飘
  377. local wanfa = self.WanFaRadioManager:getResult(); -- 自摸加番
  378. local extData = self.ExtendsionCheckBoxManager:getResult2(); -- 可选玩法
  379. local advancerule = 0;
  380. for k, v in pairs(extData) do
  381. advancerule = getNumOr(advancerule, v);
  382. end
  383. local other = self.otherCheckBoxManager:getResult2()
  384. local forbidProp = other["forbidProp"]
  385. local forbidVoice = other["forbidVoice"]
  386. self.defaultValus = {
  387. zimomode = wanfa,
  388. deductRule = payMode,
  389. playnum = playnum,
  390. -- totalgamenum = roundnum,
  391. --limitfan = fengding,
  392. gamerule = 1, -- 玩法
  393. isfaststart = isfaststart,
  394. --advancerule = advancerule,
  395. gamescore = gamescore,
  396. piaomode = piaomode,
  397. placecard = extData["placecard"],
  398. baseMulti = self.curJFBS,
  399. forbidProp = forbidProp,
  400. forbidVoice = forbidVoice,
  401. };
  402. -- 保存玩家的选择
  403. self:saveDefaultValues()
  404. local strGameInfo = json.encode(self.defaultValus);
  405. return roundnum, strGameInfo
  406. end
  407. return MJCreateRoomItem