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.

501 lines
17 KiB

  1. local CreateRoom_PDK = 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:ctor(defaultValus)
  9. CreateRoom_PDK.super.ctor(self, defaultValus, "CreateRoom_PDK.json")
  10. local ui = loadUI("res/ui/ui_chuangjian/pk_chuangjian_paodekuai.ui")
  11. self.ui = ui
  12. self:addChild(ui)
  13. local gameConfig = getSubGameConfig(GAME_IDS.PaoDeKuai)
  14. self.curPlayType = 1--经典玩法16张
  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. -- 其他选项
  34. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  35. self:initRadio()
  36. self:onHideCestView() -- 隐藏cest的界面
  37. end
  38. function CreateRoom_PDK:onHideCestView()
  39. if self.ui.Items.Button_pay0_tips then
  40. self.ui.Items.Button_pay0_tips:setVisible(false)
  41. end
  42. if self.ui.Items.Button_pay1_tips then
  43. self.ui.Items.Button_pay1_tips:setVisible(false)
  44. end
  45. if self.ui.Items.ImageView_pay0_tips then
  46. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  47. end
  48. if self.ui.Items.ImageView_pay1_tips then
  49. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  50. end
  51. end
  52. function CreateRoom_PDK:onShowCestView()
  53. if self.ui.Items.Text_pay0 then
  54. self.ui.Items.Text_pay0:setText("免费")
  55. end
  56. if self.ui.Items.Text_pay1 then
  57. self.ui.Items.Text_pay1:setText("自费")
  58. end
  59. if self.ui.Items.Button_pay0_tips then
  60. self.ui.Items.Button_pay0_tips:setVisible(true)
  61. end
  62. if self.ui.Items.Button_pay1_tips then
  63. self.ui.Items.Button_pay1_tips:setVisible(true)
  64. end
  65. if self.ui.Items.ImageView_pay0_tips then
  66. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  67. end
  68. if self.ui.Items.Button_pay0_tips then
  69. self.ui.Items.Button_pay0_tips:registerClick(function()
  70. if self.ui.Items.ImageView_pay0_tips then
  71. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  72. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  73. end
  74. end)
  75. end
  76. if self.ui.Items.ImageView_pay1_tips then
  77. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  78. end
  79. if self.ui.Items.Button_pay1_tips then
  80. self.ui.Items.Button_pay1_tips:registerClick(function()
  81. if self.ui.Items.ImageView_pay1_tips then
  82. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  83. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  84. end
  85. end)
  86. end
  87. end
  88. --根据局数获取房费
  89. function CreateRoom_PDK:getCreateRoomCost(jushu)
  90. if self.cost then
  91. local costInfo = self.cost[jushu]
  92. if costInfo then
  93. local payMode = self.payRadioManager:getResult()
  94. if payMode == 0 then
  95. return costInfo[1].value or 0
  96. elseif payMode == 1 then
  97. return costInfo[2].value or 0
  98. end
  99. end
  100. end
  101. return 0
  102. end
  103. function CreateRoom_PDK:setPayConfig( config )
  104. --消耗房卡移到创建按钮上面
  105. --[[ if config and #config>0 then
  106. self.ui.Items.Text_FangZhu:setString(""..(config[1].value or ""))
  107. self.ui.Items.Text_AAPay:setString(""..(config[2].value or ""))
  108. end--]]
  109. end
  110. function CreateRoom_PDK:initRadio()
  111. -- 整理不同局数对应的房卡消耗
  112. local payTypes={}
  113. local gameConfig = app.user:getGameConfig(GAME_IDS.PaoDeKuai);
  114. if gameConfig then
  115. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  116. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  117. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  118. for idx, gameRound in ipairs(arrGameRound) do
  119. payTypes[gameRound] =
  120. {
  121. {name="房主付费("..arrRequireCards[idx].."钻)",value=arrRequireCards[idx]},
  122. {name="AA付费(各"..arrRequireCardsAA[idx].."钻)",value=arrRequireCardsAA[idx]}
  123. }
  124. end
  125. end
  126. self.cost = payTypes
  127. --[[--局数
  128. if self.jsRadioManager then
  129. self.jsRadioManager:addItem(self.ui.Items.CheckBox_js_1, 10) -- (10局)
  130. self.jsRadioManager:addItem(self.ui.Items.CheckBox_js_2, 20) -- (20局)
  131. local defaultValue = self:getDefaultValue("totalGameNum") or 10
  132. self.jsRadioManager:setDefault(defaultValue)
  133. local callBack = function ( value )
  134. local config = payTypes[value] or {}
  135. self:setPayConfig(config)
  136. end
  137. self.jsRadioManager:setCallback(callBack)
  138. callBack(defaultValue)
  139. end --]]
  140. --人数
  141. if self.pcountRadioManager then
  142. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2) -- (快速成局)
  143. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 1) -- (3人)
  144. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 0) -- (2人)
  145. local defaultValue = self:getDefaultValue("playerNum") or 2
  146. self.ui.Items.Layout_FirstOut:setVisible(defaultValue == 1 or defaultValue == 2)
  147. self.ui.Items.Layout_FirstOut_ex:setVisible(defaultValue == 0)
  148. self.pcountRadioManager:setDefault(defaultValue)
  149. self.pcountRadioManager:setCallback(function ( value )
  150. self.ui.Items.Layout_FirstOut:setVisible(value == 1 or value == 2)
  151. self.ui.Items.Layout_FirstOut_ex:setVisible(value == 0)
  152. end)
  153. end
  154. --玩法
  155. if self.wanfaRadioManager then
  156. self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_1, 0) -- 必须管
  157. self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_2, 1) -- 可不要
  158. local defaultValue = self:getDefaultValue("allowPass") or 0
  159. self.wanfaRadioManager:setDefault(defaultValue)
  160. end
  161. --红桃10扎鸟说明
  162. self.ui.Items.ImageView_zhaniao:setVisible(false)
  163. self.ui.Items.Button_zhaniao:registerClick(function()
  164. playBtnEffect()
  165. local isShow = self.ui.Items.ImageView_zhaniao:isVisible()
  166. self.ui.Items.ImageView_zhaniao:setVisible(not isShow)
  167. end)
  168. --3必带2说明
  169. self.ui.Items.ImageView_3dai2:setVisible(false)
  170. self.ui.Items.Button_3dai2:registerClick(function()
  171. playBtnEffect()
  172. local isShow = self.ui.Items.ImageView_3dai2:isVisible()
  173. self.ui.Items.ImageView_3dai2:setVisible(not isShow)
  174. end)
  175. --反春天说明
  176. self.ui.Items.ImageView_fanchuntian:setVisible(false)
  177. self.ui.Items.Button_fanchuntian:registerClick(function()
  178. playBtnEffect()
  179. local isShow = self.ui.Items.ImageView_fanchuntian:isVisible()
  180. self.ui.Items.ImageView_fanchuntian:setVisible(not isShow)
  181. end)
  182. --规则
  183. if self.typeCheckBoxManager then
  184. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_1, "tp_1", 0x0001, 0x0000) --0x0001 红桃10扎鸟
  185. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_2, "tp_2", 0x0002, 0x0000) --0x0002 可4带3
  186. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_3, "tp_3", 0x0004, 0x0000) --0x0004 炸弹可拆
  187. --self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_4, "tp_4", 0x0008, 0x0000) --0x0008 3张,飞机少带接完
  188. -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_5, "tp_5", 0x0010, 0x0000) --0x0010 首局先出黑桃三
  189. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_6, "tp_6", 0x0020, 0x0000) --0x0020 显示牌的张数
  190. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_7, "tp_7", 0x0080, 0x0000) --0x0080 AAA为炸弹
  191. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_4, "tp_4", 0x0400, 0x0000) --0x0400 可4带2
  192. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_5, "tp_5", 0x0200, 0x0000) --0x0200 3必带2
  193. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_8, "tp_8", 0x0800, 0x0000) --0x0800 反春天
  194. local defaultValue = self:getDefaultValue("specialRule") or 0x0001
  195. if tonumber(defaultValue) == nil then
  196. defaultValue = 0x0001
  197. end
  198. local defaultT = {}
  199. if getNumBand(defaultValue, 0x0001)>0 then
  200. table.insert(defaultT, "tp_1")
  201. end
  202. if getNumBand(defaultValue, 0x0002)>0 then
  203. table.insert(defaultT, "tp_2")
  204. end
  205. if getNumBand(defaultValue, 0x0004)>0 then
  206. table.insert(defaultT, "tp_3")
  207. end
  208. if getNumBand(defaultValue, 0x0008)>0 then
  209. table.insert(defaultT, "tp_4")
  210. end
  211. if getNumBand(defaultValue, 0x0020)>0 then
  212. table.insert(defaultT, "tp_6")
  213. end
  214. if getNumBand(defaultValue, 0x0080)>0 then
  215. table.insert(defaultT, "tp_7")
  216. end
  217. if getNumBand(defaultValue, 0x0400)>0 then
  218. table.insert(defaultT, "tp_4")
  219. end
  220. if getNumBand(defaultValue, 0x0200)>0 then
  221. table.insert(defaultT, "tp_5")
  222. end
  223. if getNumBand(defaultValue, 0x0800)>0 then
  224. table.insert(defaultT, "tp_8")
  225. end
  226. self.typeCheckBoxManager:setDefault(defaultT)
  227. end
  228. --房费
  229. if self.payRadioManager then
  230. self.payRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0)
  231. self.payRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1)
  232. local defaultValue = self:getDefaultValue("deductRule") or 0
  233. self.payRadioManager:setDefault(tonumber(defaultValue))
  234. --通知创建界面更新显示
  235. local function dispatchUpdateCost()
  236. app:dispatchEvent({name = "onChangePayMode"})
  237. end
  238. self.payRadioManager:setCallback(dispatchUpdateCost);
  239. end
  240. --首局选择
  241. if self.firstOutRadioManager then
  242. self.firstOutRadioManager:addItem(self.ui.Items.CheckBox_FirstOut_1, 0x0010) --首局先出黑桃三
  243. self.firstOutRadioManager:addItem(self.ui.Items.CheckBox_FirstOut_2, 0x0040) --第一手牌必须包含最小牌
  244. local defaultValue = self:getDefaultValue("firstOutRule") or 0x0040
  245. self.firstOutRadioManager:setDefault(tonumber(defaultValue))
  246. end
  247. --首局选择
  248. if self.firstOutExBoxManager then
  249. self.firstOutExBoxManager:addItem(self.ui.Items.CheckBox_FirstOut_ex_1, "out_tp_1", 0x0040, 0x0000) --0x0040第一手必须包含最小牌
  250. local defaultValue = self:getDefaultValue("firstOutRuleEx") or 0x0040
  251. if tonumber(defaultValue) == nil then
  252. defaultValue = 0x0040
  253. end
  254. local defaultT = {}
  255. if getNumBand(defaultValue, 0x0040)>0 then
  256. table.insert(defaultT, "out_tp_1")
  257. end
  258. self.firstOutExBoxManager:setDefault(defaultT)
  259. end
  260. self:initBombScore()
  261. -- self:initOtherCheckBoxManager()
  262. self:initLayoutEvent()
  263. self:initJiFenBeiShu()
  264. end
  265. ---
  266. -- 初始化炸弹分
  267. -- @return
  268. --
  269. function CreateRoom_PDK:initBombScore ()
  270. if not self.bombScoreRadioManager then
  271. return
  272. end
  273. --炸弹分选择
  274. if self.bombScoreRadioManager then
  275. self.bombScoreRadioManager:addItem(self.ui.Items.CheckBox_bomb_1, 5) --5分
  276. self.bombScoreRadioManager:addItem(self.ui.Items.CheckBox_bomb_2, 10) --10分
  277. local defaultValue = self:getDefaultValue("bombScore") or 10
  278. self.bombScoreRadioManager:setDefault(tonumber(defaultValue))
  279. end
  280. end
  281. ---
  282. -- 初始化其他选项
  283. -- @return
  284. --
  285. -- function CreateRoom_PDK:initOtherCheckBoxManager ()
  286. -- if not self.otherCheckBoxManager then
  287. -- return
  288. -- end
  289. -- self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)
  290. -- local forbidProp = self:getDefaultValue("forbidProp") or 0
  291. -- local defaults = {}
  292. -- if forbidProp > 0 then
  293. -- table.insert(defaults, "forbidProp")
  294. -- end
  295. -- self.otherCheckBoxManager:setDefault(defaults)
  296. -- end
  297. -- 面板的点击事件,点击面板后,隐藏所有提示
  298. function CreateRoom_PDK: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: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: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: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: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: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 other = self.otherCheckBoxManager:getResult2()
  375. local forbidProp = other["forbidProp"]
  376. local forbidVoice = other["forbidVoice"]
  377. local rule = 0
  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 other = self.otherCheckBoxManager:getResult2()
  392. local forbidProp = other["forbidProp"]
  393. local tgameInfo = {}
  394. tgameInfo.gamerule = self.curPlayType
  395. tgameInfo.playerNum = result.playerNum--0 两人 1 三人
  396. tgameInfo.allowPass = result.allowPass
  397. tgameInfo.specialRule = rule
  398. tgameInfo.deductRule = result.deductRule
  399. tgameInfo.playnum = tgameInfo.playerNum == 0 and 2 or 3
  400. tgameInfo.baseMulti = self.curJFBS
  401. tgameInfo.forbidProp = forbidProp
  402. tgameInfo.forbidVoice = forbidVoice
  403. tgameInfo.bombScore = result.bombScore
  404. self.defaultValus =
  405. {
  406. gameRule = self.curPlayType,
  407. totalGameNum = result.totalGameNum,
  408. playerNum = result.playerNum,
  409. playnum = result.playerNum == 0 and 2 or 3,
  410. allowPass = result.allowPass,
  411. specialRule = saveRule,
  412. deductRule = result.deductRule,
  413. firstOutRule = result.firstOutRule,
  414. firstOutRuleEx = ruleEx,
  415. baseMulti = self.curJFBS,
  416. forbidProp = forbidProp,
  417. forbidVoice = forbidVoice,
  418. -- bombScore = bombScore, -- todo lwq 这是谁写的
  419. bombScore = result.bombScore, -- todo lwq
  420. }
  421. -- 保存玩家的选择
  422. self:saveDefaultValues()
  423. local gameInfo = json.encode(tgameInfo)
  424. return result.totalGameNum, gameInfo, 0
  425. end
  426. function CreateRoom_PDK:onEnter()
  427. CreateRoom_PDK.super.onEnter(self)
  428. -- 整理不同局数对应的房卡消耗
  429. self:initOtherCheckBoxManager();
  430. end
  431. ---
  432. -- 初始化其他选项
  433. -- @return
  434. --
  435. function CreateRoom_PDK:initOtherCheckBoxManager ()
  436. if not self.otherCheckBoxManager then
  437. return
  438. end
  439. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  440. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  441. local forbidProp = self:getDefaultValue("forbidProp") or 0
  442. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  443. local defaults = {}
  444. if forbidProp > 0 then
  445. table.insert(defaults, "forbidProp")
  446. end
  447. if forbidVoice == 1 then
  448. table.insert(defaults, "forbidVoice")
  449. end
  450. self.otherCheckBoxManager:setDefault(defaults)
  451. end
  452. return CreateRoom_PDK