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.

457 lines
14 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("bazhongCreateRoomItem",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, "bazhongmj_room.json")
  7. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_bazhong.ui");
  8. self.ui = ui;
  9. self:addChild(ui);
  10. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  11. --房费
  12. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  13. --人数
  14. self.RenShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  15. --封顶
  16. self.FengDingCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  17. --点杠
  18. self.DianGangCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  19. --换三张
  20. self.SwapCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  21. --萝卜
  22. self.LuoBoCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
  23. --玩法
  24. self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  25. --低分加分
  26. self.DiFenJiaFenCheckBoxManager = 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. function MJCreateRoomItem:getCreateRoomCost(jushu)
  83. if self.cost then
  84. local costInfo = self.cost[jushu]
  85. if costInfo then
  86. local payMode = self.PayRadioManager:getResult()
  87. if payMode == 0 then
  88. return costInfo.roomCard or 0
  89. elseif payMode == 1 then
  90. return costInfo.roomCardAA or 0
  91. end
  92. end
  93. end
  94. return 0
  95. end
  96. function MJCreateRoomItem:onEnter()
  97. MJCreateRoomItem.super.onEnter(self)
  98. -- 整理不同局数对应的房卡消耗
  99. local payTypes={}
  100. local gameConfig = app.user:getGameConfig(GAME_IDS.bazhongMJ)--app.gameId);
  101. if gameConfig then
  102. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  103. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  104. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  105. for idx, gameRound in ipairs(arrGameRound) do
  106. payTypes[gameRound] =
  107. {
  108. roomCard = arrRequireCards[idx],
  109. roomCardAA = arrRequireCardsAA[idx],
  110. }
  111. end
  112. end
  113. self.cost = payTypes
  114. -- 玩家选择局数后,更新房卡消耗
  115. --[[local function updateCost(gameRound)
  116. local costInfo = payTypes[gameRound]
  117. if costInfo then
  118. self.ui.Items.Text_FangZhu:setText(tostring(costInfo.requireCards or 0))
  119. self.ui.Items.Text_AAPay:setText(tostring(costInfo.requireCardsAA or 0))
  120. end
  121. end --]]
  122. -- 房费
  123. if self.PayRadioManager then
  124. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  125. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  126. --self.PayRadioManager:addItem(self.ui.Items.CheckBox_WinFinal, 2); -- 大赢家支付
  127. local default = self:getDefaultValue("deductRule") or 0
  128. self.PayRadioManager:setDefault(default)
  129. --通知创建界面更新显示
  130. local function dispatchUpdateCost()
  131. app:dispatchEvent({name = "onChangePayMode"})
  132. end
  133. self.PayRadioManager:setCallback(dispatchUpdateCost);
  134. self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  135. end
  136. -- 封顶
  137. if self.FengDingCheckBoxManager then
  138. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_3fan, 3); -- 3番
  139. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_4fan, 4); -- 4番
  140. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_5fan, 5); -- 5番
  141. local default = self:getDefaultValue("limitfan") or 4
  142. self.FengDingCheckBoxManager:setDefault(default)
  143. end
  144. -- 点杠
  145. if self.DianGangCheckBoxManager then
  146. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
  147. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
  148. local default = self:getDefaultValue("gshmode") or 2
  149. self.DianGangCheckBoxManager:setDefault(default)
  150. end
  151. -- 换三张
  152. if self.SwapCheckBoxManager then
  153. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Change3, "swapcard", 1, 0); -- 换三张
  154. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_CanChangeAny, "swapcolourcard", 1, 0); -- 换不同花色的牌
  155. local swapcard = self:getDefaultValue("swapcard") or 0
  156. local swapcolourcard = self:getDefaultValue("swapcolourcard") or 0
  157. local selecteds = {}
  158. if swapcard==1 then
  159. table.insert(selecteds,"swapcard")
  160. end
  161. if swapcolourcard == 1 then
  162. table.insert(selecteds,"swapcolourcard")
  163. end
  164. self.SwapCheckBoxManager:setDefault(selecteds)
  165. --通知创建界面更新显示
  166. local function callBack()
  167. local index = self.SwapCheckBoxManager.curCheckBox
  168. if index == 1 then
  169. local bSet = self.ui.Items.CheckBox_Change3:getSelectedState()
  170. if not bSet then
  171. self.ui.Items.CheckBox_CanChangeAny:setSelectedState(false)
  172. self.ui.Items.Text_ChangeAny:setTextColor(cc.c4b(21,99,97,255))
  173. end
  174. elseif index == 2 then
  175. local bSet = self.ui.Items.CheckBox_CanChangeAny:getSelectedState()
  176. if bSet then
  177. self.ui.Items.CheckBox_Change3:setSelectedState(true)
  178. self.ui.Items.Text_Change3:setTextColor(cc.c4b(213,46,11,255))
  179. end
  180. end
  181. end
  182. self.SwapCheckBoxManager:setCallback(callBack);
  183. end
  184. --玩法
  185. if self.WanFaCheckBoxManager then
  186. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_YaoJiuJiangDui, "jdyj", 1, 0)
  187. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_MenQingZhongZhang, "mqzz", 1, 0)
  188. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TianDiHu, "tdh", 1, 0)
  189. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_FangNiu, "fanniu", 1, 0) -- 放牛必须过庄胡
  190. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_GuoShouPeng, "guoshoupeng", 1, 0)
  191. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_ChaDaJiao, "ChaDaJiao", 1, 0)
  192. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_DaDuiZiLiangFan, "DaDuiZiLiangFan", 1, 0)
  193. local jdyj = self:getDefaultValue("jdyj") or 0
  194. local mqzz = self:getDefaultValue("mqzz") or 0
  195. local tdh = self:getDefaultValue("tdh") or 0
  196. local fanniu = self:getDefaultValue("fanniu") or 0
  197. local guoshoupeng = self:getDefaultValue("guoshoupeng") or 0
  198. local ChaDaJiao = self:getDefaultValue("ChaDaJiao") or 0
  199. local DaDuiZiLiangFan = self:getDefaultValue("DaDuiZiLiangFan") or 0
  200. local selecteds = {}
  201. if jdyj==1 then
  202. table.insert(selecteds,"jdyj")
  203. end
  204. if mqzz==1 then
  205. table.insert(selecteds,"mqzz")
  206. else
  207. end
  208. if tdh==1 then
  209. table.insert(selecteds,"tdh")
  210. end
  211. if fanniu==1 then
  212. table.insert(selecteds,"fanniu")
  213. end
  214. if guoshoupeng == 1 then
  215. table.insert(selecteds, 'guoshoupeng')
  216. end
  217. if ChaDaJiao == 1 then
  218. table.insert(selecteds, 'ChaDaJiao')
  219. end
  220. if DaDuiZiLiangFan == 1 then
  221. table.insert(selecteds, 'DaDuiZiLiangFan')
  222. end
  223. self.WanFaCheckBoxManager:setDefault(selecteds)
  224. self:setDefaultTextColor()
  225. end
  226. self:initLayoutEvent()
  227. self:initJiFenBeiShu()
  228. self:initOtherCheckBoxManager()
  229. end
  230. ---
  231. -- 初始化其他选项
  232. -- @return
  233. --
  234. function MJCreateRoomItem:initOtherCheckBoxManager ()
  235. if not self.otherCheckBoxManager then
  236. return
  237. end
  238. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  239. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  240. local forbidProp = self:getDefaultValue("forbidProp") or 0
  241. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  242. local defaults = {}
  243. if forbidProp == 1 then
  244. table.insert(defaults, "forbidProp")
  245. end
  246. if forbidVoice == 1 then
  247. table.insert(defaults, "forbidVoice")
  248. end
  249. self.otherCheckBoxManager:setDefault(defaults)
  250. end
  251. -- 面板的点击事件,点击面板后,隐藏所有提示
  252. function MJCreateRoomItem:initLayoutEvent()
  253. self.ui.Items.Layout_1:registerClick(function()
  254. local buttons = {
  255. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  256. };
  257. -- 隐藏其他提示信息
  258. for k, v in ipairs(buttons) do
  259. local tipsNode = self.ui.Items[v.tipsName]
  260. tipsNode:setVisible(false)
  261. end
  262. end)
  263. end
  264. -- 初始化积分倍数
  265. function MJCreateRoomItem:initJiFenBeiShu()
  266. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  267. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  268. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  269. self:updateJiFenBeiShu()
  270. --积分倍数说明
  271. self.ui.Items.ImageView_JFBS:setVisible(false)
  272. self.ui.Items.Button_JFBS:registerClick(function()
  273. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  274. end)
  275. end
  276. --更新积分倍数
  277. function MJCreateRoomItem:updateJiFenBeiShu()
  278. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  279. self.ui.Items.Text_jifen:setText(self.curJFBS)
  280. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  281. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  282. end
  283. --按钮加
  284. function MJCreateRoomItem:onClickAdd()
  285. playBtnEffect()
  286. if not self.curJFBS then
  287. return
  288. end
  289. if self.curJFBS >= 1.0 then
  290. self.curJFBS = self.curJFBS + 1.0
  291. else
  292. self.curJFBS = self.curJFBS + 0.1
  293. end
  294. if self.curJFBS >= 100 then
  295. self.curJFBS = 100;
  296. end
  297. self:updateJiFenBeiShu()
  298. end
  299. --按钮减
  300. function MJCreateRoomItem:onClickJian()
  301. playBtnEffect()
  302. if not self.curJFBS then
  303. return
  304. end
  305. if self.curJFBS <= 1.0 then
  306. self.curJFBS = self.curJFBS - 0.1
  307. else
  308. self.curJFBS = self.curJFBS - 1.0
  309. end
  310. if self.curJFBS <= 0.1 then
  311. self.curJFBS = 0.1
  312. end
  313. self:updateJiFenBeiShu()
  314. end
  315. --设置选中值默认颜色
  316. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  317. if radio then
  318. local index = radio:getResult()
  319. local defaultText = string.format(text.."%d",index)
  320. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  321. end
  322. --[[local result = self.WanFaCheckBoxManager:getResult2()
  323. if result.mqzz == 1 then
  324. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  325. end--]]
  326. end
  327. --点击checkBox时,改变其text的颜色
  328. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  329. local function updataRadioTextColor()
  330. if boxType == "radioBox" then
  331. local index = radio:getResult()
  332. for k,value in pairs(valueTab) do
  333. local item = string.format(text.."%d",value)
  334. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  335. if value == index then
  336. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  337. end
  338. end
  339. elseif boxType == "checkBox" then
  340. --[[local result = self.WanFaCheckBoxManager:getResult2()
  341. local result = self.WanFaCheckBoxManager:getResult2()
  342. if result.mqzz == 1 then
  343. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  344. self.ui.Items.CheckBox_BoZiMo:setVisible(true)
  345. else
  346. self.ui.Items.Text_mqzz:setTextColor(NON_SELECT_COLOR)
  347. self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  348. end--]]
  349. end
  350. end
  351. radio:setCallback(updataRadioTextColor);
  352. end
  353. function MJCreateRoomItem:getRuleResult()
  354. local game_num = self.JuShuRadioManager:getResult()
  355. local payMode = self.PayRadioManager:getResult()
  356. local playnum = 4--self.RenShuRadioManager:getResult()
  357. local isfaststart = playnum==0 and 1 or 0
  358. playnum = playnum==0 and 4 or playnum
  359. --下面两局代码限制只有三人模式,没有快速成局
  360. --isfaststart = 0
  361. --playnum = 3
  362. local limitfan = self.FengDingCheckBoxManager:getResult()
  363. local gshmode = self.DianGangCheckBoxManager:getResult()
  364. local swapresult = self.SwapCheckBoxManager:getResult2()
  365. local wanFaResult = self.WanFaCheckBoxManager:getResult2()
  366. local jdyj = wanFaResult.jdyj
  367. local mqzz = wanFaResult.mqzz
  368. local tdh = wanFaResult.tdh
  369. local fanniu = wanFaResult.fanniu
  370. local guoshoupeng = wanFaResult.guoshoupeng
  371. local ChaDaJiao = wanFaResult.ChaDaJiao
  372. local DaDuiZiLiangFan = wanFaResult.DaDuiZiLiangFan
  373. local swapcard = swapresult.swapcard
  374. local swapcolourcard = swapresult.swapcolourcard
  375. local other = self.otherCheckBoxManager:getResult2()
  376. local forbidProp = other["forbidProp"]
  377. local forbidVoice = other["forbidVoice"]
  378. self.defaultValus =
  379. {
  380. gamerule = 1,
  381. totalgamenum = game_num,
  382. deductRule = payMode,
  383. playnum = playnum,
  384. isfaststart = isfaststart,
  385. faststart = isfaststart,
  386. limitfan = limitfan,
  387. gshmode = gshmode,
  388. swapcard = swapcard,
  389. swapcolourcard = swapcolourcard,
  390. jdyj = jdyj,
  391. mqzz = mqzz,
  392. tdh = tdh,
  393. baseMulti = self.curJFBS,
  394. forbidProp = forbidProp,
  395. forbidVoice = forbidVoice,
  396. fanniu = fanniu,
  397. guoshoupeng = guoshoupeng,
  398. ChaDaJiao = ChaDaJiao,
  399. DaDuiZiLiangFan = DaDuiZiLiangFan,
  400. }
  401. -- 保存玩家的选择
  402. self:saveDefaultValues()
  403. local strGameInfo = json.encode(self.defaultValus);
  404. return game_num, strGameInfo
  405. end
  406. return MJCreateRoomItem