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.

510 lines
17 KiB

  1. -- local MJSelectRadioCompnent = require("Views.CreateRoom.Compnent.MJSelectRadioCompnent")
  2. -- local MJGroupCompnent = require("Views.CreateRoom.Compnent.MJGroupCompnent")
  3. -- local MJCheckBoxCompnent = require("Views.CreateRoom.Compnent.MJCheckBoxCompnent")
  4. -- local MJWanFa=MJFramework.ImportWanFa("MaJiang.MJWanFa")
  5. local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
  6. local MJCreateRoomItem=class("luzhouguiCreateRoomItem",CreateRoomItemBase)
  7. local SELECT_COLOR = cc.c4b(213,46,11,255)
  8. local NON_SELECT_COLOR = cc.c4b(21,99,97,255)
  9. function MJCreateRoomItem:ctor(defaultValues)
  10. MJCreateRoomItem.super.ctor(self, defaultValues, "neijiangmj_room.json")
  11. local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_neijiang.ui");
  12. self.ui = ui;
  13. self:addChild(ui);
  14. --房费
  15. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  16. --人数
  17. self.PlayCountRadioManager = import("luaScript.Tools.RadioManager"):new();
  18. -- 局数
  19. self.RoundNumRadioManager = import("luaScript.Tools.RadioManager"):new();
  20. --封顶
  21. self.FengDingRadioManager = 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.BaoZiRadioManager = import("luaScript.Tools.RadioManager"):new();
  28. -- 其他选项
  29. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  30. self:onHideCestView() -- 隐藏cest的界面
  31. end
  32. function MJCreateRoomItem:onHideCestView()
  33. if self.ui.Items.Button_pay0_tips then
  34. self.ui.Items.Button_pay0_tips:setVisible(false)
  35. end
  36. if self.ui.Items.Button_pay1_tips then
  37. self.ui.Items.Button_pay1_tips:setVisible(false)
  38. end
  39. if self.ui.Items.ImageView_pay0_tips then
  40. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  41. end
  42. if self.ui.Items.ImageView_pay1_tips then
  43. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  44. end
  45. end
  46. function MJCreateRoomItem:onShowCestView()
  47. if self.ui.Items.Text_pay0 then
  48. self.ui.Items.Text_pay0:setText("免费")
  49. end
  50. if self.ui.Items.Text_pay1 then
  51. self.ui.Items.Text_pay1:setText("自费")
  52. end
  53. if self.ui.Items.Button_pay0_tips then
  54. self.ui.Items.Button_pay0_tips:setVisible(true)
  55. end
  56. if self.ui.Items.Button_pay1_tips then
  57. self.ui.Items.Button_pay1_tips:setVisible(true)
  58. end
  59. if self.ui.Items.ImageView_pay0_tips then
  60. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  61. end
  62. if self.ui.Items.Button_pay0_tips then
  63. self.ui.Items.Button_pay0_tips:registerClick(function()
  64. if self.ui.Items.ImageView_pay0_tips then
  65. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  66. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  67. end
  68. end)
  69. end
  70. if self.ui.Items.ImageView_pay1_tips then
  71. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  72. end
  73. if self.ui.Items.Button_pay1_tips then
  74. self.ui.Items.Button_pay1_tips:registerClick(function()
  75. if self.ui.Items.ImageView_pay1_tips then
  76. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  77. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  78. end
  79. end)
  80. end
  81. end
  82. --根据局数获取房费
  83. function MJCreateRoomItem:getCreateRoomCost(jushu)
  84. if self.cost then
  85. local costInfo = self.cost[jushu]
  86. if costInfo then
  87. local payMode = self.PayRadioManager:getResult()
  88. if payMode == 0 then
  89. return costInfo.roomCard or 0
  90. elseif payMode == 1 then
  91. return costInfo.roomCardAA or 0
  92. end
  93. end
  94. end
  95. return 0
  96. end
  97. function MJCreateRoomItem:onEnter()
  98. MJCreateRoomItem.super.onEnter(self)
  99. -- 整理不同局数对应的房卡消耗
  100. local payTypes={}
  101. local gameConfig = app.user:getGameConfig(GAME_IDS.NeiJiangMJ)--app.gameId);
  102. if gameConfig then
  103. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  104. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  105. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  106. for idx, gameRound in ipairs(arrGameRound) do
  107. payTypes[gameRound] =
  108. {
  109. roomCard = arrRequireCards[idx],
  110. roomCardAA = arrRequireCardsAA[idx],
  111. }
  112. end
  113. end
  114. self.cost = payTypes
  115. self:initPayRadioManager();
  116. self:initPlayCountRadioManager();
  117. -- self:initRoundNumRadioManager();
  118. self:initFengDingRadioManager();
  119. self:initWanFaRadioManager();
  120. self:initExtendsionCheckBoxManager();
  121. self:initBaoZiRadioManager();
  122. self:initLayoutEvent()
  123. self:initOtherCheckBoxManager()
  124. self:initJiFenBeiShu()
  125. end
  126. -- 面板的点击事件,点击面板后,隐藏所有提示
  127. function MJCreateRoomItem:initLayoutEvent()
  128. self.ui.Items.Layout_1:registerClick(function()
  129. local buttons = {
  130. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  131. {buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
  132. };
  133. -- 隐藏其他提示信息
  134. for k, v in ipairs(buttons) do
  135. local tipsNode = self.ui.Items[v.tipsName]
  136. tipsNode:setVisible(false)
  137. end
  138. end)
  139. end
  140. ---
  141. -- 初始化其他选项
  142. -- @return
  143. --
  144. function MJCreateRoomItem:initOtherCheckBoxManager ()
  145. if not self.otherCheckBoxManager then
  146. return
  147. end
  148. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  149. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  150. local forbidProp = self:getDefaultValue("forbidProp") or 0
  151. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  152. local defaults = {}
  153. if forbidProp > 0 then
  154. table.insert(defaults, "forbidProp")
  155. end
  156. if forbidVoice == 1 then
  157. table.insert(defaults, "forbidVoice")
  158. end
  159. self.otherCheckBoxManager:setDefault(defaults)
  160. end
  161. -- 初始化积分倍数
  162. function MJCreateRoomItem:initJiFenBeiShu()
  163. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  164. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  165. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  166. self:updateJiFenBeiShu()
  167. --积分倍数说明
  168. self.ui.Items.ImageView_JFBS:setVisible(false)
  169. self.ui.Items.Button_JFBS:registerClick(function()
  170. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  171. end)
  172. end
  173. --更新积分倍数
  174. function MJCreateRoomItem:updateJiFenBeiShu()
  175. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  176. self.ui.Items.Text_jifen:setText(self.curJFBS)
  177. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  178. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  179. end
  180. --按钮加
  181. function MJCreateRoomItem:onClickAdd()
  182. playBtnEffect()
  183. if not self.curJFBS then
  184. return
  185. end
  186. if self.curJFBS >= 1.0 then
  187. self.curJFBS = self.curJFBS + 1.0
  188. else
  189. self.curJFBS = self.curJFBS + 0.1
  190. end
  191. if self.curJFBS >= 100 then
  192. self.curJFBS = 100;
  193. end
  194. self:updateJiFenBeiShu()
  195. end
  196. --按钮减
  197. function MJCreateRoomItem:onClickJian()
  198. playBtnEffect()
  199. if not self.curJFBS then
  200. return
  201. end
  202. if self.curJFBS <= 1.0 then
  203. self.curJFBS = self.curJFBS - 0.1
  204. else
  205. self.curJFBS = self.curJFBS - 1.0
  206. end
  207. if self.curJFBS <= 0.1 then
  208. self.curJFBS = 0.1
  209. end
  210. self:updateJiFenBeiShu()
  211. end
  212. --[[
  213. -- 初始化房费支付选项
  214. --]]
  215. function MJCreateRoomItem:initPayRadioManager ( )
  216. if self.PayRadioManager then
  217. self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
  218. self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
  219. local default = self:getDefaultValue("deductRule") or 0
  220. self.PayRadioManager:setDefault(default)
  221. --通知创建界面更新显示
  222. local function dispatchUpdateCost()
  223. app:dispatchEvent({name = "onChangePayMode"})
  224. end
  225. self.PayRadioManager:setCallback(dispatchUpdateCost);
  226. -- self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
  227. end
  228. end
  229. --[[
  230. -- 初始化人数选项
  231. --]]
  232. function MJCreateRoomItem:initPlayCountRadioManager ( )
  233. if self.PlayCountRadioManager then
  234. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 0); -- 快速开局
  235. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 4); -- 满4人开
  236. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 3); -- 满3人开
  237. self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2); -- 满2人开
  238. local defaultValue = self:getDefaultValue("playnum") or 0
  239. local isfaststart = self:getDefaultValue("isfaststart") or 1
  240. if isfaststart==1 then
  241. self.PlayCountRadioManager:setDefault(0);
  242. else
  243. self.PlayCountRadioManager:setDefault(defaultValue);
  244. end
  245. -- self:setDefaultTextColor(self.PlayCountRadioManager, "Text_player")
  246. -- self:updataTextColor(self.PlayCountRadioManager, "Text_player","radioBox",{0,4,3,2})
  247. end
  248. --快速成局说明
  249. self.ui.Items.ImageView_KSCJ:setVisible(false)
  250. self.ui.Items.Button_KSCJ:registerClick(function()
  251. self.ui.Items.ImageView_KSCJ:setVisible(not self.ui.Items.ImageView_KSCJ:isVisible())
  252. end)
  253. end
  254. --[[
  255. -- 初始化局数
  256. --]]
  257. function MJCreateRoomItem:initRoundNumRadioManager( )
  258. -- 玩家选择局数后,更新房卡消耗
  259. local function updateCost(gameRound)
  260. local costInfo = payTypes[gameRound]
  261. if costInfo then
  262. self.ui.Items.Text_FangZhu:setText(tostring(costInfo.requireCards or 0))
  263. self.ui.Items.Text_AAPay:setText(tostring(costInfo.requireCardsAA or 0))
  264. end
  265. end
  266. if self.RoundNumRadioManager then
  267. self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round4, 4); -- 4 局
  268. self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round8, 8); -- 8 局
  269. self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round12, 12); -- 12 局
  270. self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round16, 16); -- 16 局
  271. local defaultValue = self:getDefaultValue("totalgamenum") or 4;
  272. self.RoundNumRadioManager:setDefault(defaultValue);
  273. --self.RoundNumRadioManager:setCallback(updateCost);
  274. --updateCost(defaultValue)
  275. end
  276. end
  277. --[[
  278. -- 初始化封顶选项
  279. --]]
  280. function MJCreateRoomItem:initFengDingRadioManager ()
  281. -- 封顶
  282. if self.FengDingRadioManager then
  283. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_Fan3, 3); -- 封顶3番
  284. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_Fan4, 4); -- 封顶4番
  285. self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_Fan5, 5); -- 封顶5番
  286. local default = self:getDefaultValue("limitfan") or 6
  287. self.FengDingRadioManager:setDefault(default)
  288. -- self:setDefaultTextColor(self.FengDingRadioManager,"Text_limit")
  289. -- self:updataTextColor(self.FengDingRadioManager,"Text_limit","radioBox",{3,4,5})
  290. end
  291. end
  292. --[[
  293. -- 初始化可选选项
  294. --]]
  295. function MJCreateRoomItem:initExtendsionCheckBoxManager ( )
  296. if self.ExtendsionCheckBoxManager then
  297. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_BaoJiao, "BaoJiao", 0x0001, 0); -- 报叫
  298. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_YiBanGao, "YiBanGao", 0x0100, 0); -- 一般高
  299. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_BaoZi, "BaoZi", 1, 0); -- 豹子,前端的值,不传给后端
  300. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_Piao, "Piao", 0x0080, 0); -- 飘
  301. self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_TingPai, "TingPai", 0x0200, 0); -- 听牌提示
  302. local selectedValue = {};
  303. local baojiaoValue = self:getDefaultValue("baojiao") or 0;
  304. if baojiaoValue > 0 then
  305. table.insert(selectedValue, "BaoJiao");
  306. end
  307. local yibangaoValue = self:getDefaultValue("yibangao") or 0;
  308. if yibangaoValue > 0 then
  309. table.insert(selectedValue, "YiBanGao");
  310. end
  311. local baoziValue = self:getDefaultValue("baozi") or 0;
  312. if baoziValue > 0 then
  313. table.insert(selectedValue, "BaoZi");
  314. end
  315. self.ui.Items.CheckBox_BaoZiExt1:setVisible(baoziValue > 0);
  316. self.ui.Items.CheckBox_BaoZiExt2:setVisible(baoziValue > 0);
  317. local piaoValue = self:getDefaultValue("piao") or 0;
  318. if piaoValue > 0 then
  319. table.insert(selectedValue, "Piao");
  320. end
  321. local tingpaiValue = self:getDefaultValue("tingpai") or 0;
  322. if tingpaiValue > 0 then
  323. table.insert(selectedValue, "TingPai");
  324. end
  325. self.ExtendsionCheckBoxManager:setDefault(selectedValue)
  326. self.ExtendsionCheckBoxManager:setCallback(function (value)
  327. local result = self.ExtendsionCheckBoxManager:getResult2();
  328. self.ui.Items.CheckBox_BaoZiExt1:setVisible(result["BaoZi"] > 0);
  329. self.ui.Items.CheckBox_BaoZiExt2:setVisible(result["BaoZi"] > 0);
  330. end);
  331. -- self:setDefaultTextColor(self.ExtendsionCheckBoxManager,"Text_gui")
  332. -- self:updataTextColor(self.ExtendsionCheckBoxManager,"Text_gui","checkBox",{0x0001,8,0x0002,12,12,0x0040,0x0080})
  333. end
  334. end
  335. --[[
  336. -- 初始化豹子扩展选项
  337. --]]
  338. function MJCreateRoomItem:initBaoZiRadioManager ()
  339. if self.BaoZiRadioManager then
  340. self.BaoZiRadioManager:addItem(self.ui.Items.CheckBox_BaoZiExt1, 0x0002); -- 骰子相同做豹子
  341. self.BaoZiRadioManager:addItem(self.ui.Items.CheckBox_BaoZiExt2, 0x0040); -- 骰子相加双数做豹子
  342. local defaultValue = self:getDefaultValue("baoziext") or 0
  343. self.BaoZiRadioManager:setDefault(defaultValue);
  344. end
  345. end
  346. --[[
  347. -- 初始化玩法选项
  348. --]]
  349. function MJCreateRoomItem:initWanFaRadioManager ( )
  350. if self.WanFaRadioManager then
  351. self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_ZiMoBuJia, 0); -- 自摸不加
  352. self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_ZiMoJiaFan, 1); -- 自摸加番
  353. self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_ZiMoJiaDi, 2); -- 自摸加底
  354. local defaultValue = self:getDefaultValue("zimorule") or 0
  355. self.WanFaRadioManager:setDefault(defaultValue);
  356. -- self:setDefaultTextColor()
  357. -- self:updataTextColor(self.WanFaRadioManager,"","radioBox",{})
  358. end
  359. end
  360. --设置选中值默认颜色
  361. function MJCreateRoomItem:setDefaultTextColor(radio,text)
  362. if radio then
  363. local index = radio:getResult()
  364. local defaultText = string.format(text.."%d",index)
  365. self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
  366. end
  367. local result = self.WanFaRadioManager:getResult2()
  368. if result.baojiao == 1 then
  369. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  370. end
  371. if result.xiqian == 1 then
  372. self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
  373. end
  374. end
  375. --点击checkBox时,改变其text的颜色
  376. function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
  377. local function updataRadioTextColor()
  378. if boxType == "radioBox" then
  379. local index = radio:getResult()
  380. for k,value in pairs(valueTab) do
  381. local item = string.format(text.."%d",value)
  382. self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
  383. if value == index then
  384. self.ui.Items[item]:setTextColor(SELECT_COLOR)
  385. end
  386. end
  387. elseif boxType == "checkBox" then
  388. local result = self.WanFaRadioManager:getResult2()
  389. if result.baojiao == 1 then
  390. self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
  391. else
  392. self.ui.Items.Text_BaoJiao:setTextColor(NON_SELECT_COLOR)
  393. end
  394. if result.xiqian == 1 then
  395. self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
  396. else
  397. self.ui.Items.Text_XiQian:setTextColor(NON_SELECT_COLOR)
  398. end
  399. end
  400. end
  401. radio:setCallback(updataRadioTextColor);
  402. end
  403. function MJCreateRoomItem:getRuleResult()
  404. local payMode = self.PayRadioManager:getResult(); -- 支付模式
  405. local playnum = self.PlayCountRadioManager:getResult(); -- 玩牌人数, 0表示快速开局
  406. local isfaststart = playnum == 0 and 1 or 0; -- 是否快速开局
  407. playnum = playnum == 0 and 4 or playnum;
  408. local roundnum = self.RoundNumRadioManager:getResult(); -- 玩牌局数
  409. local fengding = self.FengDingRadioManager:getResult(); -- 封顶番数
  410. local wanfa = self.WanFaRadioManager:getResult(); -- 自摸加番
  411. local baoziext = self.BaoZiRadioManager:getResult(); -- 豹子扩展玩法
  412. local extData = self.ExtendsionCheckBoxManager:getResult2(); -- 可选玩法
  413. local specialrule = 0;
  414. for k, v in pairs(extData) do
  415. if v > 0 and k ~= "BaoZi" then
  416. specialrule = getNumOr(specialrule, v);
  417. end
  418. end
  419. if extData["BaoZi"] > 0 then
  420. specialrule = getNumOr(specialrule, baoziext);
  421. else
  422. baoziext = 0;
  423. end
  424. local other = self.otherCheckBoxManager:getResult2()
  425. local forbidProp = other["forbidProp"]
  426. local forbidVoice = other["forbidVoice"]
  427. self.defaultValus = {
  428. zimorule = wanfa,
  429. deductRule = payMode,
  430. playnum = playnum,
  431. -- totalgamenum = roundnum,
  432. limitfan = fengding,
  433. gamerule = 1, -- 玩法
  434. isfaststart = isfaststart,
  435. specialrule = specialrule,
  436. baojiao = extData["BaoJiao"],
  437. yibangao = extData["YiBanGao"],
  438. piao = extData["Piao"],
  439. baoziext = baoziext,
  440. baozi = extData["BaoZi"],
  441. tingpai = extData["TingPai"],
  442. baseMulti = self.curJFBS,
  443. forbidProp = forbidProp,
  444. forbidVoice = forbidVoice,
  445. };
  446. -- 保存玩家的选择
  447. self:saveDefaultValues()
  448. local strGameInfo = json.encode(self.defaultValus);
  449. return roundnum, strGameInfo
  450. end
  451. return MJCreateRoomItem