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.

485 lines
15 KiB

  1. local CreateRoom_PDK_hejiang = class("CreateRoom_PDK_hejiang", require("luaScript.Views.CreateRoom.CreateRoomItemBase"))
  2. --[[
  3. isCreateRoom和defaultValus决定了从哪里读取默认值
  4. isCreateRoom 为true时,从本地文件读取,defaultValus无效.
  5. 否则使用defaultValus的值
  6. defaultValus : 跟服务器strGameInfo对应的json对象
  7. --]]
  8. function CreateRoom_PDK_hejiang:ctor(defaultValus)
  9. CreateRoom_PDK_hejiang.super.ctor(self, defaultValus, "CreateRoom_PDK_hejiang.json")
  10. local ui = loadUI("res/ui/ui_chuangjian/pk_chuangjian_hejiangpdk.ui")
  11. self.ui = ui
  12. self:addChild(ui)
  13. local gameConfig = getSubGameConfig(GAME_IDS.hejiangPaoDeKuai)
  14. self.curPlayType = 0
  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.tieYiXianCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  29. -- 颗数选择
  30. self.KeShuRadioManager = import("luaScript.Tools.RadioManager"):new()
  31. -- 末手选择
  32. self.moShouRadioManager = 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_hejiang: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_hejiang: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_hejiang: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_hejiang: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_hejiang:initRadio()
  111. -- 整理不同局数对应的房卡消耗
  112. local payTypes={}
  113. local gameConfig = app.user:getGameConfig(GAME_IDS.hejiangPaoDeKuai);
  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, 1) -- (快速成局)
  143. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 4) -- (4人)
  144. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 3) -- (3人)
  145. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 2) -- (2人)
  146. local defaultValue = self:getDefaultValue("playnum") or 1--默认快速成局
  147. self.pcountRadioManager:setDefault(defaultValue)
  148. local callBack = function ( value )
  149. if value == 2 then
  150. self.ui.Items.CheckBox_type_2:setVisible(false)
  151. self.ui.Items.Button_JPQ:setVisible(false)
  152. self.ui.Items.ImageView_5:setVisible(false)
  153. else
  154. self.ui.Items.CheckBox_type_2:setVisible(true)
  155. self.ui.Items.Button_JPQ:setVisible(true)
  156. end
  157. end
  158. self.pcountRadioManager:setCallback(callBack)
  159. callBack(defaultValue)
  160. end
  161. --玩法
  162. if self.wanfaRadioManager then
  163. self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_1, 0) -- 无鬼
  164. self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_2, 2) -- 两鬼
  165. local defaultValue = self:getDefaultValue("jokerCount") or 0
  166. self.wanfaRadioManager:setDefault(defaultValue)
  167. local callBack = function ( value )
  168. if value == 0 then
  169. self.ui.Items.Layout_content_3:setVisible(true)
  170. else
  171. self.ui.Items.Layout_content_3:setVisible(false)
  172. end
  173. end
  174. self.wanfaRadioManager:setCallback(callBack)
  175. callBack(defaultValue)
  176. end
  177. --快速成局说明
  178. self.ui.Items.ImageView_3:setVisible(false)
  179. self.ui.Items.Button_KSCJ:registerClick(function()
  180. playBtnEffect()
  181. self.ui.Items.ImageView_3:setVisible(not self.ui.Items.ImageView_3:isVisible())
  182. end)
  183. --记牌器说明
  184. self.ui.Items.ImageView_5:setVisible(false)
  185. self.ui.Items.Button_JPQ:registerClick(function()
  186. playBtnEffect()
  187. self.ui.Items.ImageView_5:setVisible(not self.ui.Items.ImageView_5:isVisible())
  188. end)
  189. --规则
  190. if self.typeCheckBoxManager then
  191. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_2, "tp_1", 0x0001, 0x0000) --0x0001 记牌器
  192. self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_1, "tp_2", 0x0002, 0x0000) --0x8888 有大必打
  193. -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0) --0x8888 有大必打
  194. local defaultValue = self:getDefaultValue("specialRule") or 0x0002
  195. if tonumber(defaultValue) == nil then
  196. defaultValue = 0x0002
  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. -- local forbidProp = self:getDefaultValue("forbidProp")
  206. -- if forbidProp and tonumber(forbidProp) == 1 then
  207. -- table.insert(defaultT, "forbidProp")
  208. -- end
  209. self.typeCheckBoxManager:setDefault(defaultT)
  210. end
  211. --铁一线规则
  212. if self.tieYiXianCheckBoxManager then
  213. local values =
  214. {
  215. [1] = {selectValue = 0x0001, unselectValue = 0x0000},--铁一线规则
  216. }
  217. self.tieYiXianCheckBoxManager:addItem(self.ui.Items.CheckBox_type_3, 1, values[1].selectValue, values[1].unselectValue) --0x0001 铁一线规则
  218. local defaultValue = self:getDefaultValue("tieyixian") or 0x0001
  219. if tonumber(defaultValue) == nil then
  220. defaultValue = 0x0001
  221. end
  222. -- 设置默认状态
  223. local ttSelected = {}
  224. for k,v in pairs(values) do
  225. if getNumBand(defaultValue, v.selectValue) > 0 then
  226. table.insert(ttSelected, k)
  227. end
  228. end
  229. self.tieYiXianCheckBoxManager:setDefault(ttSelected);
  230. end
  231. --房费
  232. if self.payRadioManager then
  233. self.payRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0)
  234. self.payRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1)
  235. local defaultValue = self:getDefaultValue("deductRule") or 0
  236. self.payRadioManager:setDefault(tonumber(defaultValue))
  237. --通知创建界面更新显示
  238. local function dispatchUpdateCost()
  239. app:dispatchEvent({name = "onChangePayMode"})
  240. end
  241. self.payRadioManager:setCallback(dispatchUpdateCost);
  242. end
  243. -- 颗数
  244. if self.KeShuRadioManager then
  245. self.KeShuRadioManager:addItem(self.ui.Items.CheckBox_6, 1); -- 1/2/4/6颗
  246. self.KeShuRadioManager:addItem(self.ui.Items.CheckBox_7, 2); -- 2/4/6/8颗
  247. self.KeShuRadioManager:addItem(self.ui.Items.CheckBox_14, 3); -- 3/5/10/15颗
  248. -- 设置默认数据
  249. local defaultValue = self:getDefaultValue("keCount") or 1
  250. self.KeShuRadioManager:setDefault(tonumber(defaultValue));
  251. end
  252. -- 末手规则
  253. if self.moShouRadioManager then
  254. self.moShouRadioManager:addItem(self.ui.Items.CheckBox_moshou_1, 1); -- 可出
  255. self.moShouRadioManager:addItem(self.ui.Items.CheckBox_moshou_2, 0); -- 不可出
  256. -- 设置默认数据
  257. local defaultValue = self:getDefaultValue("endsandaiyi") or 0
  258. self.moShouRadioManager:setDefault(tonumber(defaultValue));
  259. end
  260. self:initLayoutEvent()
  261. self:initJiFenBeiShu()
  262. end
  263. -- 面板的点击事件,点击面板后,隐藏所有提示
  264. function CreateRoom_PDK_hejiang:initLayoutEvent()
  265. self.ui.Items.Layout_1:registerClick(function()
  266. local buttons = {
  267. {buttonName = "Button_KSCJ", tipsName = "ImageView_3"},
  268. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  269. {buttonName = "Button_JPQ", tipsName = "ImageView_5"},
  270. };
  271. -- 隐藏其他提示信息
  272. for k, v in ipairs(buttons) do
  273. local tipsNode = self.ui.Items[v.tipsName]
  274. tipsNode:setVisible(false)
  275. end
  276. end)
  277. end
  278. -- 初始化积分倍数
  279. function CreateRoom_PDK_hejiang:initJiFenBeiShu()
  280. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  281. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  282. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  283. self:updateJiFenBeiShu()
  284. --积分倍数说明
  285. self.ui.Items.ImageView_JFBS:setVisible(false)
  286. self.ui.Items.Button_JFBS:registerClick(function()
  287. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  288. end)
  289. end
  290. --更新积分倍数
  291. function CreateRoom_PDK_hejiang:updateJiFenBeiShu()
  292. self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
  293. self.ui.Items.Text_jifen:setText(self.curJFBS)
  294. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  295. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
  296. end
  297. --按钮加
  298. function CreateRoom_PDK_hejiang:onClickAdd()
  299. playBtnEffect()
  300. if not self.curJFBS then
  301. return
  302. end
  303. if self.curJFBS >= 1.0 then
  304. self.curJFBS = self.curJFBS + 1.0
  305. else
  306. self.curJFBS = self.curJFBS + 0.1
  307. end
  308. if self.curJFBS >= 100 then
  309. self.curJFBS = 100;
  310. end
  311. self:updateJiFenBeiShu()
  312. end
  313. --按钮减
  314. function CreateRoom_PDK_hejiang:onClickJian()
  315. playBtnEffect()
  316. if not self.curJFBS then
  317. return
  318. end
  319. if self.curJFBS <= 1.0 then
  320. self.curJFBS = self.curJFBS - 0.1
  321. else
  322. self.curJFBS = self.curJFBS - 1.0
  323. end
  324. if self.curJFBS <= 0.1 then
  325. self.curJFBS = 0.1
  326. end
  327. self:updateJiFenBeiShu()
  328. end
  329. function CreateRoom_PDK_hejiang:getRuleResult()
  330. local result = {}
  331. result.totalGameNum = self.jsRadioManager:getResult()--局数
  332. result.playnum = self.pcountRadioManager:getResult()--玩家人数
  333. result.specialRule = self.typeCheckBoxManager:getResult()--规则
  334. result.deductRule = self.payRadioManager:getResult()--房费0房主1aa
  335. result.jokerCount = self.wanfaRadioManager:getResult()--带鬼数
  336. result.keCount = self.KeShuRadioManager:getResult()--颗数
  337. result.tieyixian = self.tieYiXianCheckBoxManager:getResult2();
  338. result.endsandaiyi = self.moShouRadioManager:getResult()--末手三带一
  339. result.allowPass = 1
  340. local rule = 0
  341. local forbidProp = 0
  342. local other = self.otherCheckBoxManager:getResult2()
  343. local forbidProp = other["forbidProp"]
  344. local forbidVoice = other["forbidVoice"]
  345. for key,v in pairs(result.specialRule) do
  346. if key == "forbidProp" then
  347. -- forbidProp = v.value
  348. else
  349. if v.value == 1 and result.playnum == 2 then
  350. else
  351. rule = getNumOr(rule, v.value)
  352. end
  353. if getNumBand(v.value, 0x0002)>0 then
  354. result.allowPass = 0
  355. end
  356. end
  357. end
  358. local tieyixian = 0;
  359. for k,v in pairs(result.tieyixian) do
  360. if k == 1 then
  361. tieyixian = v
  362. end
  363. end
  364. if result.jokerCount == 2 then
  365. tieyixian = 0
  366. end
  367. local saveRule = rule
  368. local tgameInfo = {}
  369. tgameInfo.gamerule = self.curPlayType
  370. tgameInfo.playnum = result.playnum--0 两人 1 三人
  371. tgameInfo.allowPass = result.allowPass
  372. tgameInfo.specialRule = rule
  373. tgameInfo.jokerCount = result.jokerCount
  374. tgameInfo.keCount = result.keCount
  375. tgameInfo.deductRule = result.deductRule
  376. tgameInfo.tieyixian = tieyixian
  377. tgameInfo.endsandaiyi = result.endsandaiyi
  378. tgameInfo.baseMulti = self.curJFBS
  379. tgameInfo.forbidProp = forbidProp
  380. tgameInfo.forbidVoice = forbidVoice
  381. self.defaultValus =
  382. {
  383. gameRule = self.curPlayType,
  384. totalGameNum = result.totalGameNum,
  385. playnum = result.playnum,
  386. allowPass = result.allowPass,
  387. specialRule = saveRule,
  388. deductRule = result.deductRule,
  389. jokerCount = result.jokerCount,
  390. keCount = result.keCount,
  391. tieyixian = tieyixian,
  392. endsandaiyi = result.endsandaiyi,
  393. baseMulti = self.curJFBS,
  394. forbidProp = forbidProp,
  395. forbidVoice = forbidVoice,
  396. }
  397. -- 保存玩家的选择
  398. self:saveDefaultValues()
  399. local gameInfo = json.encode(tgameInfo)
  400. return result.totalGameNum, gameInfo, 0
  401. end
  402. function CreateRoom_PDK_hejiang:onEnter()
  403. CreateRoom_PDK_hejiang.super.onEnter(self)
  404. -- 整理不同局数对应的房卡消耗
  405. self:initOtherCheckBoxManager();
  406. end
  407. ---
  408. -- 初始化其他选项
  409. -- @return
  410. --
  411. function CreateRoom_PDK_hejiang:initOtherCheckBoxManager ()
  412. if not self.otherCheckBoxManager then
  413. return
  414. end
  415. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
  416. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
  417. local forbidProp = self:getDefaultValue("forbidProp") or 0
  418. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  419. local defaults = {}
  420. if forbidProp > 0 then
  421. table.insert(defaults, "forbidProp")
  422. end
  423. if forbidVoice == 1 then
  424. table.insert(defaults, "forbidVoice")
  425. end
  426. self.otherCheckBoxManager:setDefault(defaults)
  427. end
  428. return CreateRoom_PDK_hejiang