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.

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