Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

350 lignes
11 KiB

  1. local CreateRoom_xichong = class("CreateRoom_xichong", require("luaScript.Views.CreateRoom.CreateRoomItemBase"))
  2. --[[
  3. isCreateRoom和defaultValus决定了从哪里读取默认值
  4. isCreateRoom 为true时,从本地文件读取,defaultValus无效.
  5. 否则使用defaultValus的值
  6. defaultValus : 跟服务器strGameInfo对应的json对象
  7. --]]
  8. function CreateRoom_xichong:ctor(defaultValues)
  9. CreateRoom_xichong.super.ctor(self, defaultValues, "CreateRoom_xichong.json");
  10. local ui = loadUI("res/ui/ui_chuangjian/zp_chuangjian_xichongkaokao.ui");
  11. self.ui = ui;
  12. self:addChild(ui);
  13. self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
  14. self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
  15. self.PiaoRadioManager = import("luaScript.Tools.RadioManager"):new();
  16. self.FanshuManager = import("luaScript.Tools.RadioManager"):new();
  17. -- 人数 - 单选
  18. self.pcountRadioManager = import("luaScript.Tools.RadioManager"):new()
  19. -- 发牌方数
  20. self.WanfaManager = import("luaScript.Tools.CheckBoxManager"):new()
  21. -- 其他选项
  22. self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
  23. self:onHideCestView() -- 隐藏cest的界面
  24. end
  25. function CreateRoom_xichong:onHideCestView()
  26. if self.ui.Items.Button_pay0_tips then
  27. self.ui.Items.Button_pay0_tips:setVisible(false)
  28. end
  29. if self.ui.Items.Button_pay1_tips then
  30. self.ui.Items.Button_pay1_tips:setVisible(false)
  31. end
  32. if self.ui.Items.ImageView_pay0_tips then
  33. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  34. end
  35. if self.ui.Items.ImageView_pay1_tips then
  36. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  37. end
  38. end
  39. function CreateRoom_xichong:onShowCestView()
  40. if self.ui.Items.Text_pay0 then
  41. self.ui.Items.Text_pay0:setText("免费")
  42. end
  43. if self.ui.Items.Text_pay1 then
  44. self.ui.Items.Text_pay1:setText("自费")
  45. end
  46. if self.ui.Items.Button_pay0_tips then
  47. self.ui.Items.Button_pay0_tips:setVisible(true)
  48. end
  49. if self.ui.Items.Button_pay1_tips then
  50. self.ui.Items.Button_pay1_tips:setVisible(true)
  51. end
  52. if self.ui.Items.ImageView_pay0_tips then
  53. self.ui.Items.ImageView_pay0_tips:setVisible(false)
  54. end
  55. if self.ui.Items.Button_pay0_tips then
  56. self.ui.Items.Button_pay0_tips:registerClick(function()
  57. if self.ui.Items.ImageView_pay0_tips then
  58. local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
  59. self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
  60. end
  61. end)
  62. end
  63. if self.ui.Items.ImageView_pay1_tips then
  64. self.ui.Items.ImageView_pay1_tips:setVisible(false)
  65. end
  66. if self.ui.Items.Button_pay1_tips then
  67. self.ui.Items.Button_pay1_tips:registerClick(function()
  68. if self.ui.Items.ImageView_pay1_tips then
  69. local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
  70. self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
  71. end
  72. end)
  73. end
  74. end
  75. --根据局数获取房费
  76. function CreateRoom_xichong:getCreateRoomCost(jushu)
  77. if self.cost then
  78. local costInfo = self.cost[jushu]
  79. if costInfo then
  80. local payMode = self.PayRadioManager:getResult()
  81. if payMode == 0 then
  82. return costInfo.requireCards or 0
  83. elseif payMode == 1 then
  84. return costInfo.requireCardsAA or 0
  85. end
  86. end
  87. end
  88. return 0
  89. end
  90. function CreateRoom_xichong:onEnter()
  91. CreateRoom_xichong.super.onEnter(self)
  92. -- 整理不同局数对应的房卡消耗
  93. local ttCost = {}
  94. local gameConfig = app.user:getGameConfig(GAME_IDS.xichongkk);
  95. if gameConfig then
  96. local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
  97. local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
  98. local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
  99. for idx, gameRound in ipairs(arrGameRound) do
  100. ttCost[gameRound] =
  101. {
  102. requireCards = arrRequireCards[idx],
  103. requireCardsAA = arrRequireCardsAA[idx],
  104. }
  105. end
  106. end
  107. self.cost = ttCost
  108. -- 玩家选择局数后,更新房卡消耗
  109. local function updateCost(gameRound)
  110. local costInfo = ttCost[gameRound]
  111. if costInfo then
  112. self.ui.Items.Text_FangZhu:setText(tostring(costInfo.requireCards or 0))
  113. self.ui.Items.Text_AAPay:setText(tostring(costInfo.requireCardsAA or 0))
  114. end
  115. end
  116. -- 房费 deductRule
  117. if self.PayRadioManager then
  118. self.PayRadioManager:addItem(self.ui.Items.CheckBox_4, 1); -- AA支付
  119. self.PayRadioManager:addItem(self.ui.Items.CheckBox_5, 0); -- 房主支付
  120. -- 设置默认数据
  121. local defaultValue = self:getDefaultValue("deductRule") or 0
  122. self.PayRadioManager:setDefault(tonumber(defaultValue));
  123. --通知创建界面更新显示
  124. local function dispatchUpdateCost()
  125. app:dispatchEvent({name = "onChangePayMode"})
  126. end
  127. self.PayRadioManager:setCallback(dispatchUpdateCost);
  128. end
  129. -- 漂
  130. if self.PiaoRadioManager then
  131. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_6, 1); -- 随漂
  132. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_7, 0); -- 不飘
  133. self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_16, 2);-- 定飘
  134. -- 设置默认数据
  135. local defaultValue = self:getDefaultValue("Piaorule") or 1
  136. self.PiaoRadioManager:setDefault(tonumber(defaultValue));
  137. end
  138. --快速成局说明
  139. self.ui.Items.ImageView_2:setVisible(false)
  140. self.ui.Items.Button_KSCJ:registerClick(function()
  141. playBtnEffect()
  142. self.ui.Items.ImageView_2:setVisible(not self.ui.Items.ImageView_2:isVisible())
  143. end)
  144. --特殊玩法
  145. if self.WanfaManager then
  146. self.WanfaManager:addItem(self.ui.Items.CheckBox_8, "shibalan",0x0001, 0); -- 十八烂
  147. self.WanfaManager:addItem(self.ui.Items.CheckBox_9, "kewanjiao", 0x0002, 0); -- 可弯叫
  148. self.WanfaManager:addItem(self.ui.Items.CheckBox_13, "zhanshanwanfa", 0x0004, 0); -- 可弯叫
  149. -- 设置默认状态
  150. local defaultValue = self:getDefaultValue("specialRule") or 1
  151. local selecteds = {}
  152. if getNumBand(defaultValue, 0x0001)>0 then
  153. table.insert(selecteds, "shibalan")
  154. end
  155. if getNumBand(defaultValue, 0x0002)>0 then
  156. table.insert(selecteds, "kewanjiao")
  157. end
  158. if getNumBand(defaultValue, 0x0004)>0 then
  159. table.insert(selecteds, "zhanshanwanfa")
  160. end
  161. self.WanfaManager:setDefault(selecteds);
  162. end
  163. self.ui.Items.CheckBox_11:setVisible(false)
  164. self.ui.Items.CheckBox_12:setVisible(false)
  165. -- 玩法 specialRule
  166. if self.FanshuManager then
  167. self.FanshuManager:addItem(self.ui.Items.CheckBox_10, 3); -- 限3番
  168. --self.FanshuManager:addItem(self.ui.Items.CheckBox_11, 4); -- 限4番
  169. --self.FanshuManager:addItem(self.ui.Items.CheckBox_12, 0); -- 不封顶
  170. -- 设置默认数据
  171. local defaultValue = self:getDefaultValue("highLimit") or 3
  172. self.FanshuManager:setDefault(tonumber(defaultValue));
  173. end
  174. -- 人数
  175. self.hadHideFangShu = false
  176. if self.pcountRadioManager then
  177. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 3) -- (3人)
  178. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 4) -- (4人)
  179. self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, -1) -- (快速成局)
  180. local defaultValue = self:getDefaultValue("playnum") or -1
  181. local startMode = self:getDefaultValue("startMode") or 0
  182. if startMode == 1 then
  183. defaultValue = -1
  184. end
  185. self.pcountRadioManager:setDefault(defaultValue)
  186. end
  187. self:initOtherCheckBoxManager()
  188. self:initLayoutEvent()
  189. self:initJiFenBeiShu()
  190. end
  191. ---
  192. -- 初始化其他选项
  193. -- @return
  194. --
  195. function CreateRoom_xichong:initOtherCheckBoxManager ()
  196. if not self.otherCheckBoxManager then
  197. return
  198. end
  199. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)
  200. self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidChat, "forbidVoice", 1, 0)
  201. local forbidProp = self:getDefaultValue("forbidProp") or 0
  202. local forbidVoice = self:getDefaultValue("forbidVoice") or 0
  203. local defaults = {}
  204. if forbidProp > 0 then
  205. table.insert(defaults, "forbidProp")
  206. end
  207. if forbidVoice == 1 then
  208. table.insert(defaults, "forbidVoice")
  209. end
  210. end
  211. -- 面板的点击事件,点击面板后,隐藏所有提示
  212. function CreateRoom_xichong:initLayoutEvent()
  213. self.ui.Items.Layout_3:registerClick(function()
  214. local buttons = {
  215. {buttonName = "Button_JFBS", tipsName = "ImageView_2"},
  216. {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
  217. };
  218. -- 隐藏其他提示信息
  219. for k, v in ipairs(buttons) do
  220. local tipsNode = self.ui.Items[v.tipsName]
  221. tipsNode:setVisible(false)
  222. end
  223. end)
  224. end
  225. -- 初始化积分倍数
  226. function CreateRoom_xichong:initJiFenBeiShu()
  227. self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
  228. self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
  229. self.curJFBS = self:getDefaultValue("baseMulti") or 1;
  230. self:updateJiFenBeiShu()
  231. --积分倍数说明
  232. self.ui.Items.ImageView_JFBS:setVisible(false)
  233. self.ui.Items.Button_JFBS:registerClick(function()
  234. self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
  235. end)
  236. end
  237. --更新积分倍数
  238. function CreateRoom_xichong:updateJiFenBeiShu()
  239. self.ui.Items.Text_jifen:setText(self.curJFBS)
  240. self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
  241. self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 1)
  242. end
  243. --按钮加
  244. function CreateRoom_xichong:onClickAdd()
  245. playBtnEffect()
  246. if not self.curJFBS then
  247. return
  248. end
  249. self.curJFBS = self.curJFBS + 1
  250. if self.curJFBS >= 100 then
  251. self.curJFBS = 100;
  252. end
  253. self:updateJiFenBeiShu()
  254. end
  255. --按钮减
  256. function CreateRoom_xichong:onClickJian()
  257. playBtnEffect()
  258. if not self.curJFBS then
  259. return
  260. end
  261. self.curJFBS = self.curJFBS - 1
  262. if self.curJFBS <= 0 then
  263. self.curJFBS = 1
  264. end
  265. self:updateJiFenBeiShu()
  266. end
  267. function CreateRoom_xichong:getRuleResult()
  268. local game_num = self.JuShuRadioManager:getResult()
  269. local payMode = self.PayRadioManager:getResult()
  270. local highLimit = self.FanshuManager:getResult();
  271. local wanFaResult = self.WanfaManager:getResult2();
  272. local playnum = self.pcountRadioManager:getResult()--玩家人数
  273. local Piaorule = self.PiaoRadioManager:getResult()
  274. local startMode = 0
  275. if playnum == -1 then--选择的是快速组局
  276. --playnum = 4
  277. startMode = 1
  278. end
  279. local specialrule = 0
  280. for k, v in pairs(wanFaResult) do
  281. if v > 0 then
  282. specialrule = getNumOr(specialrule, v);
  283. end
  284. end
  285. local other = self.otherCheckBoxManager:getResult2()
  286. local forbidProp = other["forbidProp"]
  287. local forbidVoice = other["forbidVoice"]
  288. self.defaultValus =
  289. {
  290. gamerule = 1;
  291. --jushu = jushu;
  292. game_num = game_num,
  293. --biHu = 1;
  294. deductRule = payMode,
  295. areaNo = app.user.areano,
  296. startMode = startMode,
  297. playnum = playnum,
  298. specialRule = specialrule,
  299. highLimit = highLimit,
  300. Piaorule = Piaorule,
  301. baseMulti = self.curJFBS,
  302. forbidProp = forbidProp,
  303. forbidVoice = forbidVoice,
  304. }
  305. -- 保存玩家的选择
  306. self:saveDefaultValues()
  307. local strGameInfo = json.encode(self.defaultValus)
  308. return game_num, strGameInfo
  309. end
  310. return CreateRoom_xichong