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.

473 lines
16 KiB

  1. local CreateRoom_PDK_SWZ = class("CreateRoom_PDK", require("luaScript.Views.CreateRoom.CreateRoomItemBase"))
  2. --[[
  3. isCreateRoom和defaultValus决定了从哪里读取默认值
  4. isCreateRoom 为true时,从本地文件读取,defaultValus无效.
  5. 否则使用defaultValus的值
  6. defaultValus : 跟服务器strGameInfo对应的json对象
  7. --]]
  8. function CreateRoom_PDK_SWZ:ctor(defaultValus)
  9. CreateRoom_PDK_SWZ.super.ctor(self, defaultValus, "CreateRoom_PDK_SWZ.json")
  10. local ui = loadUI("res/ui/ui_chuangjian/pk_chuangjian_paodekuai_shiwuzhang.ui")
  11. self.ui = ui
  12. self:addChild(ui)
  13. local gameConfig = getSubGameConfig(GAME_IDS.PaoDeKuai)
  14. self.curPlayType = 2--玩法15张
  15. -- 局数 - 单选
  16. self.jsRadioManager = import("luaScript.Tools.RadioManager"):new()
  17. -- 人数 - 单选
  18. self.pcountRadioManager = import("luaScript.Tools.RadioManager"):new()
  19. -- 玩法 - 单选
  20. self.wanfaRadioManager = import("luaScript.Tools.RadioManager"):new()
  21. -- 规则
  22. self.typeCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
  23. -- 付费方式
  24. self.payRadioManager = import("luaScript.Tools.RadioManager"):new()
  25. -- 首轮出牌规则
  26. self.firstOutRadioManager = import("luaScript.Tools.RadioManager"):new()
  27. -- 两人首轮出牌规则
  28. self.firstOutExBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  29. -- 其他选项
  30. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  31. -- 炸弹分
  32. self.bombScoreRadioManager = import("luaScript.Tools.RadioManager"):new()
  33. self:initRadio()
  34. self:onHideCestView() -- 隐藏cest的界面
  35. end
  36. function CreateRoom_PDK_SWZ:onHideCestView()
  37. if self.ui.Items.Button_pay0_tips then
  38. self.ui.Items.Button_pay0_tips:setVisible(false)
  39. end
  40. if self.ui.Items.Button_pay1_tips then
  41. self.ui.Items.Button_pay1_tips:setVisible(false)
  42. end
  43. if self.ui.Items.ImageView_pay0_tips then
  44. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  45. end
  46. if self.ui.Items.ImageView_pay1_tips then
  47. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  48. end
  49. end
  50. function CreateRoom_PDK_SWZ:onShowCestView()
  51. if self.ui.Items.Text_pay0 then
  52. self.ui.Items.Text_pay0:setText("免费")
  53. end
  54. if self.ui.Items.Text_pay1 then
  55. self.ui.Items.Text_pay1:setText("自费")
  56. end
  57. if self.ui.Items.Button_pay0_tips then
  58. self.ui.Items.Button_pay0_tips:setVisible(true)
  59. end
  60. if self.ui.Items.Button_pay1_tips then
  61. self.ui.Items.Button_pay1_tips:setVisible(true)
  62. end
  63. if self.ui.Items.ImageView_pay0_tips then
  64. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  65. end
  66. if self.ui.Items.Button_pay0_tips then
  67. self.ui.Items.Button_pay0_tips:registerClick(function()
  68. if self.ui.Items.ImageView_pay0_tips then
  69. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  70. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  71. end
  72. end)
  73. end
  74. if self.ui.Items.ImageView_pay1_tips then
  75. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  76. end
  77. if self.ui.Items.Button_pay1_tips then
  78. self.ui.Items.Button_pay1_tips:registerClick(function()
  79. if self.ui.Items.ImageView_pay1_tips then
  80. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  81. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  82. end
  83. end)
  84. end
  85. end
  86. --根据局数获取房费
  87. function CreateRoom_PDK_SWZ:getCreateRoomCost(jushu)
  88. if self.cost then
  89. local costInfo = self.cost[jushu]
  90. if costInfo then
  91. local payMode = self.payRadioManager:getResult()
  92. if payMode == 0 then
  93. return costInfo[1].value or 0
  94. elseif payMode == 1 then
  95. return costInfo[2].value or 0
  96. end
  97. end
  98. end
  99. return 0
  100. end
  101. function CreateRoom_PDK_SWZ:setPayConfig( config )
  102. --[[if config and #config>0 then
  103. self.ui.Items.Text_FangZhu:setString(""..(config[1].value or ""))
  104. self.ui.Items.Text_AAPay:setString(""..(config[2].value or ""))
  105. end--]]
  106. end
  107. function CreateRoom_PDK_SWZ:initRadio()
  108. -- 整理不同局数对应的房卡消耗
  109. local payTypes={}
  110. local gameConfig = app.user:getGameConfig(GAME_IDS.PaoDeKuai);
  111. if gameConfig then
  112. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  113. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  114. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  115. for idx, gameRound in ipairs(arrGameRound) do
  116. payTypes[gameRound] =
  117. {
  118. {name="房主付费("..arrRequireCards[idx].."钻)",value=arrRequireCards[idx]},
  119. {name="AA付费(各"..arrRequireCardsAA[idx].."钻)",value=arrRequireCardsAA[idx]}
  120. }
  121. end
  122. end
  123. self.cost = payTypes
  124. --[[ if self.jsRadioManager then
  125. self.jsRadioManager:addItem(self.ui.Items.CheckBox_js_1, 10) -- (10局)
  126. self.jsRadioManager:addItem(self.ui.Items.CheckBox_js_2, 20) -- (20局)
  127. local defaultValue = self:getDefaultValue("totalGameNum") or 10
  128. self.jsRadioManager:setDefault(defaultValue)
  129. local callBack = function ( value )
  130. local config = payTypes[value] or {}
  131. self:setPayConfig(config)
  132. end
  133. self.jsRadioManager:setCallback(callBack)
  134. callBack(defaultValue)
  135. end --]]
  136. --人数
  137. if self.pcountRadioManager then
  138. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2) -- (快速成局)
  139. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 1) -- (3人)
  140. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 0) -- (2人)
  141. local defaultValue = self:getDefaultValue("playerNum") or 2
  142. self.ui.Items.Layout_FirstOut:setVisible(defaultValue == 1 or defaultValue == 2)
  143. self.ui.Items.Layout_FirstOut_ex:setVisible(defaultValue == 0)
  144. self.pcountRadioManager:setDefault(defaultValue)
  145. self.pcountRadioManager:setCallback(function ( value )
  146. self.ui.Items.Layout_FirstOut:setVisible(value == 1 or value == 2)
  147. self.ui.Items.Layout_FirstOut_ex:setVisible(value == 0)
  148. end)
  149. end
  150. --玩法
  151. if self.wanfaRadioManager then
  152. self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_1, 0) -- 必须管
  153. self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_2, 1) -- 可不要
  154. local defaultValue = self:getDefaultValue("allowPass") or 0
  155. self.wanfaRadioManager:setDefault(defaultValue)
  156. end
  157. --红桃10扎鸟说明
  158. self.ui.Items.ImageView_zhaniao:setVisible(false)
  159. self.ui.Items.Button_zhaniao:registerClick(function()
  160. playBtnEffect()
  161. local isShow = self.ui.Items.ImageView_zhaniao:isVisible()
  162. self.ui.Items.ImageView_zhaniao:setVisible(not isShow)
  163. end)
  164. --3必带2说明
  165. self.ui.Items.ImageView_3dai2:setVisible(false)
  166. self.ui.Items.Button_3dai2:registerClick(function()
  167. playBtnEffect()
  168. local isShow = self.ui.Items.ImageView_3dai2:isVisible()
  169. self.ui.Items.ImageView_3dai2:setVisible(not isShow)
  170. end)
  171. --反春天说明
  172. self.ui.Items.ImageView_fanchuntian:setVisible(false)
  173. self.ui.Items.Button_fanchuntian:registerClick(function()
  174. playBtnEffect()
  175. local isShow = self.ui.Items.ImageView_fanchuntian:isVisible()
  176. self.ui.Items.ImageView_fanchuntian:setVisible(not isShow)
  177. end)
  178. if self.typeCheckBoxManager then
  179. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_1, "tp_1", 0x0001, 0x0000) --0x0001 红桃10扎鸟
  180. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_2, "tp_2", 0x0002, 0x0000) --0x0002 可4带3
  181. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_3, "tp_3", 0x0004, 0x0000) --0x0004 炸弹可拆
  182. -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_4, "tp_4", 0x0008, 0x0000) --0x0008 3张,飞机少带接完
  183. -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_5, "tp_5", 0x0010, 0x0000) --0x0010 首局先出黑桃三
  184. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_6, "tp_6", 0x0020, 0x0000) --0x0020 显示牌的张数
  185. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_4, "tp_4", 0x0400, 0x0000) --0x0400 可4带2
  186. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_5, "tp_5", 0x0200, 0x0000) --0x0200 3必带2
  187. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_8, "tp_8", 0x0800, 0x0000) --0x0800 反春天
  188. local defaultValue = self:getDefaultValue("specialRule") or 0x0001
  189. if tonumber(defaultValue) == nil then
  190. defaultValue = 0x0001
  191. end
  192. local defaultT = {}
  193. if getNumBand(defaultValue, 0x0001)>0 then
  194. table.insert(defaultT, "tp_1")
  195. end
  196. if getNumBand(defaultValue, 0x0002)>0 then
  197. table.insert(defaultT, "tp_2")
  198. end
  199. if getNumBand(defaultValue, 0x0004)>0 then
  200. table.insert(defaultT, "tp_3")
  201. end
  202. if getNumBand(defaultValue, 0x0008)>0 then
  203. table.insert(defaultT, "tp_4")
  204. end
  205. if getNumBand(defaultValue, 0x00020)>0 then
  206. table.insert(defaultT, "tp_6")
  207. end
  208. if getNumBand(defaultValue, 0x0400)>0 then
  209. table.insert(defaultT, "tp_4")
  210. end
  211. if getNumBand(defaultValue, 0x0200)>0 then
  212. table.insert(defaultT, "tp_5")
  213. end
  214. if getNumBand(defaultValue, 0x0800)>0 then
  215. table.insert(defaultT, "tp_8")
  216. end
  217. self.typeCheckBoxManager:setDefault(defaultT)
  218. end
  219. if self.payRadioManager then
  220. self.payRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0)
  221. self.payRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1)
  222. local defaultValue = self:getDefaultValue("deductRule") or 0
  223. self.payRadioManager:setDefault(tonumber(defaultValue))
  224. --通知创建界面更新显示
  225. local function dispatchUpdateCost()
  226. app:dispatchEvent({name = "onChangePayMode"})
  227. end
  228. self.payRadioManager:setCallback(dispatchUpdateCost);
  229. end
  230. if self.firstOutRadioManager then
  231. self.firstOutRadioManager:addItem(self.ui.Items.CheckBox_FirstOut_1, 0x0010)
  232. self.firstOutRadioManager:addItem(self.ui.Items.CheckBox_FirstOut_2, 0x0040)
  233. local defaultValue = self:getDefaultValue("firstOutRule") or 0x0040
  234. self.firstOutRadioManager:setDefault(tonumber(defaultValue))
  235. end
  236. if self.firstOutExBoxManager then
  237. self.firstOutExBoxManager:addItem(self.ui.Items.CheckBox_FirstOut_ex_1, "out_tp_1", 0x0040, 0x0000) --0x0040第一手必须包含最小牌
  238. local defaultValue = self:getDefaultValue("firstOutRuleEx") or 0x0040
  239. if tonumber(defaultValue) == nil then
  240. defaultValue = 0x0040
  241. end
  242. local defaultT = {}
  243. if getNumBand(defaultValue, 0x0040)>0 then
  244. table.insert(defaultT, "out_tp_1")
  245. end
  246. self.firstOutExBoxManager:setDefault(defaultT)
  247. end
  248. self:initBombScore()
  249. self:initOtherCheckBoxManager()
  250. self:initLayoutEvent()
  251. self:initJiFenBeiShu()
  252. end
  253. ---
  254. -- 初始化炸弹分
  255. -- @return
  256. --
  257. function CreateRoom_PDK_SWZ:initBombScore ()
  258. if not self.bombScoreRadioManager then
  259. return
  260. end
  261. --炸弹分选择
  262. if self.bombScoreRadioManager then
  263. self.bombScoreRadioManager:addItem(self.ui.Items.CheckBox_bomb_1, 5) --5分
  264. self.bombScoreRadioManager:addItem(self.ui.Items.CheckBox_bomb_2, 10) --10分
  265. local defaultValue = self:getDefaultValue("bombScore") or 10
  266. self.bombScoreRadioManager:setDefault(tonumber(defaultValue))
  267. end
  268. end
  269. ---
  270. -- 初始化其他选项
  271. -- @return
  272. --
  273. function CreateRoom_PDK_SWZ:initOtherCheckBoxManager ()
  274. if not self.otherCheckBoxManager then
  275. return
  276. end
  277. -- self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)
  278. -- local forbidProp = self:getDefaultValue("forbidProp") or 0
  279. -- local defaults = {}
  280. -- if forbidProp > 0 then
  281. -- table.insert(defaults, "forbidProp")
  282. -- end
  283. -- self.otherCheckBoxManager:setDefault(defaults)
  284. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  285. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  286. local forbidProp = self:getDefaultValue("forbidProp") or 0
  287. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  288. local defaults = {}
  289. if forbidProp > 0 then
  290. table.insert(defaults, "forbidProp")
  291. end
  292. if forbidVoice == 1 then
  293. table.insert(defaults, "forbidVoice")
  294. end
  295. self.otherCheckBoxManager:setDefault(defaults)
  296. end
  297. -- 面板的点击事件,点击面板后,隐藏所有提示
  298. function CreateRoom_PDK_SWZ:initLayoutEvent()
  299. self.ui.Items.Layout_1:registerClick(function()
  300. local buttons = {
  301. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  302. {buttonName = "Button_zhaniao", tipsName = "ImageView_zhaniao"},
  303. {buttonName = "Button_3dai2", tipsName = "ImageView_3dai2"},
  304. {buttonName = "Button_fanchuntian", tipsName = "ImageView_fanchuntian"},
  305. };
  306. -- 隐藏其他提示信息
  307. for k, v in ipairs(buttons) do
  308. local tipsNode = self.ui.Items[v.tipsName]
  309. tipsNode:setVisible(false)
  310. end
  311. end)
  312. end
  313. -- 初始化积分倍数
  314. function CreateRoom_PDK_SWZ:initJiFenBeiShu()
  315. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  316. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  317. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  318. self:updateJiFenBeiShu()
  319. --积分倍数说明
  320. self.ui.Items.ImageView_JFBS:setVisible(false)
  321. self.ui.Items.Button_JFBS:registerClick(function()
  322. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  323. end)
  324. end
  325. --更新积分倍数
  326. function CreateRoom_PDK_SWZ:updateJiFenBeiShu()
  327. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  328. self.ui.Items.Text_jifen:setText(self.curJFBS)
  329. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  330. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  331. end
  332. --按钮加
  333. function CreateRoom_PDK_SWZ:onClickAdd()
  334. playBtnEffect()
  335. if not self.curJFBS then
  336. return
  337. end
  338. if self.curJFBS >= 1.0 then
  339. self.curJFBS = self.curJFBS + 1.0
  340. else
  341. self.curJFBS = self.curJFBS + 0.1
  342. end
  343. if self.curJFBS >= 100 then
  344. self.curJFBS = 100;
  345. end
  346. self:updateJiFenBeiShu()
  347. end
  348. --按钮减
  349. function CreateRoom_PDK_SWZ:onClickJian()
  350. playBtnEffect()
  351. if not self.curJFBS then
  352. return
  353. end
  354. if self.curJFBS <= 1.0 then
  355. self.curJFBS = self.curJFBS - 0.1
  356. else
  357. self.curJFBS = self.curJFBS - 1.0
  358. end
  359. if self.curJFBS <= 0.1 then
  360. self.curJFBS = 0.1
  361. end
  362. self:updateJiFenBeiShu()
  363. end
  364. function CreateRoom_PDK_SWZ:getRuleResult()
  365. local result = {}
  366. result.totalGameNum = self.jsRadioManager:getResult()--局数
  367. result.playerNum = self.pcountRadioManager:getResult()--玩家人数
  368. result.allowPass = self.wanfaRadioManager:getResult()--玩法
  369. result.specialRule = self.typeCheckBoxManager:getResult()--规则
  370. result.deductRule = self.payRadioManager:getResult()--房费0房主1aa
  371. result.firstOutRule = self.firstOutRadioManager:getResult()
  372. result.firstOutRuleEx = self.firstOutExBoxManager:getResult()
  373. result.bombScore = self.bombScoreRadioManager:getResult()
  374. local rule = 0
  375. local other = self.otherCheckBoxManager:getResult2()
  376. local forbidProp = other["forbidProp"]
  377. local forbidVoice = other["forbidVoice"]
  378. for _,v in pairs(result.specialRule) do
  379. rule = getNumOr(rule, v.value)
  380. end
  381. local saveRule = rule
  382. local ruleEx = 0
  383. if result.playerNum==0 then--两人没有首轮必出黑桃三
  384. for _,v in pairs(result.firstOutRuleEx) do
  385. rule = getNumOr(rule, v.value)
  386. ruleEx = getNumOr(rule, v.value)
  387. end
  388. else
  389. rule = getNumOr(rule, result.firstOutRule)--首轮出牌规则
  390. end
  391. local tgameInfo = {}
  392. tgameInfo.gamerule = self.curPlayType
  393. tgameInfo.playerNum = result.playerNum--0 两人 1 三人
  394. tgameInfo.allowPass = result.allowPass
  395. tgameInfo.specialRule = rule
  396. tgameInfo.deductRule = result.deductRule
  397. tgameInfo.playnum = tgameInfo.playerNum == 0 and 2 or 3
  398. tgameInfo.baseMulti = self.curJFBS
  399. tgameInfo.forbidProp = forbidProp
  400. tgameInfo.forbidVoice = forbidVoice
  401. tgameInfo.bombScore = result.bombScore
  402. self.defaultValus =
  403. {
  404. gameRule = self.curPlayType,
  405. totalGameNum = result.totalGameNum,
  406. playerNum = result.playerNum,
  407. playnum = result.playerNum == 0 and 2 or 3,
  408. allowPass = result.allowPass,
  409. specialRule = saveRule,
  410. deductRule = result.deductRule,
  411. firstOutRule = result.firstOutRule,
  412. firstOutRuleEx = ruleEx,
  413. baseMulti = self.curJFBS,
  414. forbidProp = forbidProp,
  415. forbidVoice = forbidVoice,
  416. bombScore = bombScore,
  417. }
  418. -- 保存玩家的选择
  419. self:saveDefaultValues()
  420. local gameInfo = json.encode(tgameInfo)
  421. return result.totalGameNum, gameInfo, 0
  422. end
  423. function CreateRoom_PDK_SWZ:onEnter()
  424. CreateRoom_PDK_SWZ.super.onEnter(self)
  425. -- 整理不同局数对应的房卡消耗
  426. end
  427. return CreateRoom_PDK_SWZ