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.

496 lines
16 KiB

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