25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

483 satır
15 KiB

  1. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  2. local MJCreateRoomItem=class("xueliuCreateRoomItem",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, "xueliumj_room.json")
  7. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_xueliu.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.PlayCountRadioManager = 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.RadioManager"):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.xueliuMJ)--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. if self.PayRadioManager then
  118. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  119. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  120. --self.PayRadioManager:addItem(self.ui.Items.CheckBox_WinFinal, 2); -- 大赢家支付
  121. local default = self:getDefaultValue("deductRule") or 0
  122. self.PayRadioManager:setDefault(default)
  123. --通知创建界面更新显示
  124. local function dispatchUpdateCost()
  125. app:dispatchEvent({name = "onChangePayMode"})
  126. end
  127. self.PayRadioManager:setCallback(dispatchUpdateCost);
  128. self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  129. --self:updataTextColor(self.PayRadioManager,"Text_pay","radioBox",{0,1})
  130. end
  131. -- 封顶
  132. if self.FengDingCheckBoxManager then
  133. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_3fan, 2); -- 2番
  134. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_4fan, 3); -- 3番
  135. self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_5fan, 4); -- 4番
  136. local default = self:getDefaultValue("limitfan") or 3
  137. self.FengDingCheckBoxManager:setDefault(default)
  138. end
  139. -- 自摸
  140. if self.ZiMoCheckBoxManager then
  141. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_1, 1); -- 自摸加底
  142. self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_2, 2); -- 自摸加番
  143. local default = self:getDefaultValue("playmode") or 1
  144. self.ZiMoCheckBoxManager:setDefault(default)
  145. end
  146. -- 点杠
  147. if self.DianGangCheckBoxManager then
  148. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
  149. self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
  150. local default = self:getDefaultValue("gshmode") or 2
  151. self.DianGangCheckBoxManager:setDefault(default)
  152. end
  153. -- 换三张
  154. if self.SwapCheckBoxManager then
  155. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Change3,3); -- 换三张
  156. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Change4,4); -- 换四张
  157. self.SwapCheckBoxManager:addItem(self.ui.Items.CheckBox_Nothing,0); -- 不换张
  158. -- local swapcard = self:getDefaultValue("swapcard") or 1
  159. -- local selecteds = {}
  160. -- if swapcard==1 then
  161. -- table.insert(selecteds,"swapcard")
  162. -- end
  163. -- self.SwapCheckBoxManager:setDefault(selecteds)
  164. -- todo
  165. local default = self:getDefaultValue("swapcardcount") or 3
  166. self.SwapCheckBoxManager:setDefault(default)
  167. end
  168. --玩法
  169. if self.WanFaCheckBoxManager then
  170. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_YaoJiuJiangDui, "jdyj", 1, 0)
  171. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_MenQingZhongZhang, "mqzz", 1, 0)
  172. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TianDiHu, "tdh", 1, 0)
  173. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_FangNiu, "fanniu", 1, 0) -- 放牛必须过庄胡
  174. self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_GuoShouPeng, 'guoshoupeng', 1, 0)
  175. local jdyj = self:getDefaultValue("jdyj") or 1
  176. local mqzz = self:getDefaultValue("mqzz") or 1
  177. local tdh = self:getDefaultValue("tdh") or 1
  178. --local specrule = self:getDefaultValue("specrule") or 0
  179. local fanniu = self:getDefaultValue("fanniu") or 0
  180. local guoshoupeng = self:getDefaultValue('guoshoupeng') or 0
  181. local selecteds = {}
  182. if jdyj==1 then
  183. table.insert(selecteds,"jdyj")
  184. end
  185. if mqzz==1 then
  186. table.insert(selecteds,"mqzz")
  187. else
  188. --self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  189. end
  190. if tdh==1 then
  191. table.insert(selecteds,"tdh")
  192. end
  193. --[[if getNumBand(specrule, 0x0001)>0 then
  194. table.insert(selecteds, "guozhang")
  195. end
  196. if getNumBand(specrule, 0x0002)>0 then
  197. table.insert(selecteds, "bozimo")
  198. end--]]
  199. if fanniu==1 then
  200. table.insert(selecteds,"fanniu")
  201. end
  202. if guoshoupeng == 1 then
  203. table.insert(selecteds, 'guoshoupeng')
  204. end
  205. self.WanFaCheckBoxManager:setDefault(selecteds)
  206. self:setDefaultTextColor()
  207. --self:updataTextColor(self.WanFaCheckBoxManager,"","checkBox",{})
  208. end
  209. self:initLayoutEvent()
  210. self:initJiFenBeiShu()
  211. self:initOtherCheckBoxManager()
  212. --人数
  213. self:initPlayCountRadioManager()
  214. end
  215. ---
  216. -- 初始化人数选项
  217. --
  218. function MJCreateRoomItem:initPlayCountRadioManager()
  219. if self.PlayCountRadioManager then
  220. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 0); -- 快速开局
  221. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 4); -- 满4人开
  222. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 3); -- 满3人开
  223. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2); -- 满2人开
  224. local defaultValue = self:getDefaultValue("playnum") or 0
  225. local isfaststart = self:getDefaultValue("isfaststart") or 1
  226. if isfaststart==1 then
  227. self.PlayCountRadioManager:setDefault(0);
  228. else
  229. self.PlayCountRadioManager:setDefault(defaultValue);
  230. end
  231. end
  232. --快速成局说明
  233. self.ui.Items.ImageView_KSCJ:setVisible(false)
  234. self.ui.Items.Button_KSCJ:registerClick(function()
  235. self.ui.Items.ImageView_KSCJ:setVisible(not self.ui.Items.ImageView_KSCJ:isVisible())
  236. end)
  237. end
  238. ---
  239. -- 初始化其他选项
  240. -- @return
  241. --
  242. function MJCreateRoomItem:initOtherCheckBoxManager ()
  243. if not self.otherCheckBoxManager then
  244. return
  245. end
  246. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  247. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  248. local forbidProp = self:getDefaultValue("forbidProp") or 0
  249. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  250. local defaults = {}
  251. if forbidProp == 1 then
  252. table.insert(defaults, "forbidProp")
  253. end
  254. if forbidVoice == 1 then
  255. table.insert(defaults, "forbidVoice")
  256. end
  257. self.otherCheckBoxManager:setDefault(defaults)
  258. end
  259. -- 面板的点击事件,点击面板后,隐藏所有提示
  260. function MJCreateRoomItem:initLayoutEvent()
  261. self.ui.Items.Layout_1:registerClick(function()
  262. local buttons = {
  263. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  264. };
  265. -- 隐藏其他提示信息
  266. for k, v in ipairs(buttons) do
  267. local tipsNode = self.ui.Items[v.tipsName]
  268. tipsNode:setVisible(false)
  269. end
  270. end)
  271. end
  272. -- 初始化积分倍数
  273. function MJCreateRoomItem:initJiFenBeiShu()
  274. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  275. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  276. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  277. self:updateJiFenBeiShu()
  278. --积分倍数说明
  279. self.ui.Items.ImageView_JFBS:setVisible(false)
  280. self.ui.Items.Button_JFBS:registerClick(function()
  281. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  282. end)
  283. end
  284. --更新积分倍数
  285. function MJCreateRoomItem:updateJiFenBeiShu()
  286. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  287. self.ui.Items.Text_jifen:setText(self.curJFBS)
  288. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  289. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  290. end
  291. --按钮加
  292. function MJCreateRoomItem:onClickAdd()
  293. playBtnEffect()
  294. if not self.curJFBS then
  295. return
  296. end
  297. if self.curJFBS >= 1.0 then
  298. self.curJFBS = self.curJFBS + 1.0
  299. else
  300. self.curJFBS = self.curJFBS + 0.1
  301. end
  302. if self.curJFBS >= 100 then
  303. self.curJFBS = 100;
  304. end
  305. self:updateJiFenBeiShu()
  306. end
  307. --按钮减
  308. function MJCreateRoomItem:onClickJian()
  309. playBtnEffect()
  310. if not self.curJFBS then
  311. return
  312. end
  313. if self.curJFBS <= 1.0 then
  314. self.curJFBS = self.curJFBS - 0.1
  315. else
  316. self.curJFBS = self.curJFBS - 1.0
  317. end
  318. if self.curJFBS <= 0.1 then
  319. self.curJFBS = 0.1
  320. end
  321. self:updateJiFenBeiShu()
  322. end
  323. --设置选中值默认颜色
  324. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  325. if radio then
  326. local index = radio:getResult()
  327. local defaultText = string.format(text.."%d",index)
  328. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  329. end
  330. --[[local result = self.WanFaCheckBoxManager:getResult2()
  331. if result.mqzz == 1 then
  332. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  333. end--]]
  334. end
  335. --点击checkBox时,改变其text的颜色
  336. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  337. local function updataRadioTextColor()
  338. if boxType == "radioBox" then
  339. local index = radio:getResult()
  340. for k,value in pairs(valueTab) do
  341. local item = string.format(text.."%d",value)
  342. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  343. if value == index then
  344. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  345. end
  346. end
  347. elseif boxType == "checkBox" then
  348. --[[local result = self.WanFaCheckBoxManager:getResult2()
  349. local result = self.WanFaCheckBoxManager:getResult2()
  350. if result.mqzz == 1 then
  351. self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
  352. self.ui.Items.CheckBox_BoZiMo:setVisible(true)
  353. else
  354. self.ui.Items.Text_mqzz:setTextColor(NON_SELECT_COLOR)
  355. self.ui.Items.CheckBox_BoZiMo:setVisible(false)
  356. end--]]
  357. end
  358. end
  359. radio:setCallback(updataRadioTextColor);
  360. end
  361. function MJCreateRoomItem:getRuleResult()
  362. local game_num = self.JuShuRadioManager:getResult()
  363. local payMode = self.PayRadioManager:getResult()
  364. -- local playnum = 0--self.RenShuRadioManager:getResult()
  365. local playnum = self.PlayCountRadioManager:getResult()
  366. local isfaststart = playnum==0 and 1 or 0
  367. playnum = playnum==0 and 4 or playnum
  368. --下面两局代码限制只有三人模式,没有快速成局
  369. --isfaststart = 0
  370. --playnum = 3
  371. local limitfan = self.FengDingCheckBoxManager:getResult()
  372. local playmode = self.ZiMoCheckBoxManager:getResult()
  373. local gshmode = self.DianGangCheckBoxManager:getResult()
  374. -- local swapresult = self.SwapCheckBoxManager:getResult2()
  375. local swapresult = self.SwapCheckBoxManager:getResult() -- todo lwq
  376. local wanFaResult = self.WanFaCheckBoxManager:getResult2()
  377. local jdyj = wanFaResult.jdyj
  378. local mqzz = wanFaResult.mqzz
  379. local tdh = wanFaResult.tdh
  380. local fanniu = wanFaResult.fanniu
  381. local guoshoupeng = wanFaResult.guoshoupeng
  382. -- local swapcard = swapresult.swapcard
  383. local isSwapcard = 1
  384. local swapcard = swapresult
  385. if swapcard == 0 then
  386. isSwapcard = 0
  387. elseif swapcard == 3 then
  388. isSwapcard = 1
  389. elseif swapcard then
  390. isSwapcard = 2
  391. end
  392. local other = self.otherCheckBoxManager:getResult2()
  393. local forbidProp = other["forbidProp"]
  394. local forbidVoice = other["forbidVoice"]
  395. self.defaultValus =
  396. {
  397. gamerule = 1,
  398. totalgamenum = game_num,
  399. deductRule = payMode,
  400. playnum = playnum,
  401. isfaststart = isfaststart,
  402. faststart = isfaststart,
  403. limitfan = limitfan,
  404. playmode = playmode,
  405. gshmode = gshmode,
  406. -- swapcard = swapcard,
  407. swapcard = isSwapcard, --todo lwq
  408. jdyj = jdyj,
  409. mqzz = mqzz,
  410. tdh = tdh,
  411. baseMulti = self.curJFBS,
  412. forbidProp = forbidProp,
  413. forbidVoice = forbidVoice,
  414. fanniu = fanniu,
  415. guoshoupeng = guoshoupeng,
  416. -- todo lwq
  417. swapcardcount = swapcard,
  418. }
  419. -- 保存玩家的选择
  420. self:saveDefaultValues()
  421. local strGameInfo = json.encode(self.defaultValus);
  422. return game_num, strGameInfo
  423. end
  424. return MJCreateRoomItem