|
-
- local CreateRoom_PDK_SWZ = class("CreateRoom_PDK", require("luaScript.Views.CreateRoom.CreateRoomItemBase"))
-
- --[[
- isCreateRoom和defaultValus决定了从哪里读取默认值
- isCreateRoom 为true时,从本地文件读取,defaultValus无效.
- 否则使用defaultValus的值
- defaultValus : 跟服务器strGameInfo对应的json对象
- --]]
- function CreateRoom_PDK_SWZ:ctor(defaultValus)
- CreateRoom_PDK_SWZ.super.ctor(self, defaultValus, "CreateRoom_PDK_SWZ.json")
-
- local ui = loadUI("res/ui/ui_chuangjian/pk_chuangjian_paodekuai_shiwuzhang.ui")
- self.ui = ui
- self:addChild(ui)
-
- local gameConfig = getSubGameConfig(GAME_IDS.PaoDeKuai)
- self.curPlayType = 2--玩法15张
-
- -- 局数 - 单选
- self.jsRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 人数 - 单选
- self.pcountRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 玩法 - 单选
- self.wanfaRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 规则
- self.typeCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
-
- -- 付费方式
- self.payRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 首轮出牌规则
- self.firstOutRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 两人首轮出牌规则
- self.firstOutExBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
- -- 其他选项
- self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
- -- 炸弹分
- self.bombScoreRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- self:initRadio()
-
- self:onHideCestView() -- 隐藏cest的界面
- end
-
-
- function CreateRoom_PDK_SWZ:onHideCestView()
- if self.ui.Items.Button_pay0_tips then
- self.ui.Items.Button_pay0_tips:setVisible(false)
- end
- if self.ui.Items.Button_pay1_tips then
- self.ui.Items.Button_pay1_tips:setVisible(false)
- end
- if self.ui.Items.ImageView_pay0_tips then
- self.ui.Items.ImageView_pay0_tips:setVisible(false)
- end
- if self.ui.Items.ImageView_pay1_tips then
- self.ui.Items.ImageView_pay1_tips:setVisible(false)
- end
- end
-
-
- function CreateRoom_PDK_SWZ:onShowCestView()
- if self.ui.Items.Text_pay0 then
- self.ui.Items.Text_pay0:setText("免费")
- end
- if self.ui.Items.Text_pay1 then
- self.ui.Items.Text_pay1:setText("自费")
- end
- if self.ui.Items.Button_pay0_tips then
- self.ui.Items.Button_pay0_tips:setVisible(true)
- end
- if self.ui.Items.Button_pay1_tips then
- self.ui.Items.Button_pay1_tips:setVisible(true)
- end
- if self.ui.Items.ImageView_pay0_tips then
- self.ui.Items.ImageView_pay0_tips:setVisible(false)
- end
- if self.ui.Items.Button_pay0_tips then
- self.ui.Items.Button_pay0_tips:registerClick(function()
- if self.ui.Items.ImageView_pay0_tips then
- local isVisible = not self.ui.Items.ImageView_pay0_tips:isVisible()
- self.ui.Items.ImageView_pay0_tips:setVisible(isVisible)
- end
- end)
- end
- if self.ui.Items.ImageView_pay1_tips then
- self.ui.Items.ImageView_pay1_tips:setVisible(false)
- end
- if self.ui.Items.Button_pay1_tips then
- self.ui.Items.Button_pay1_tips:registerClick(function()
- if self.ui.Items.ImageView_pay1_tips then
- local isVisible = not self.ui.Items.ImageView_pay1_tips:isVisible()
- self.ui.Items.ImageView_pay1_tips:setVisible(isVisible)
- end
- end)
- end
- end
-
-
- --根据局数获取房费
- function CreateRoom_PDK_SWZ:getCreateRoomCost(jushu)
- if self.cost then
- local costInfo = self.cost[jushu]
- if costInfo then
- local payMode = self.payRadioManager:getResult()
- if payMode == 0 then
- return costInfo[1].value or 0
- elseif payMode == 1 then
- return costInfo[2].value or 0
- end
- end
- end
- return 0
- end
-
- function CreateRoom_PDK_SWZ:setPayConfig( config )
- --[[if config and #config>0 then
- self.ui.Items.Text_FangZhu:setString(""..(config[1].value or ""))
- self.ui.Items.Text_AAPay:setString(""..(config[2].value or ""))
- end--]]
- end
-
- function CreateRoom_PDK_SWZ:initRadio()
- -- 整理不同局数对应的房卡消耗
- local payTypes={}
- local gameConfig = app.user:getGameConfig(GAME_IDS.PaoDeKuai);
-
- if gameConfig then
- local arrGameRound = toNumberArray(",")(gameConfig.gameRound)
- local arrRequireCards = toNumberArray(",")(gameConfig.requireCards)
- local arrRequireCardsAA = toNumberArray(",")(gameConfig.AArequireCards)
-
- for idx, gameRound in ipairs(arrGameRound) do
- payTypes[gameRound] =
- {
- {name="房主付费("..arrRequireCards[idx].."钻)",value=arrRequireCards[idx]},
- {name="AA付费(各"..arrRequireCardsAA[idx].."钻)",value=arrRequireCardsAA[idx]}
- }
- end
- end
- self.cost = payTypes
-
- --[[ if self.jsRadioManager then
- self.jsRadioManager:addItem(self.ui.Items.CheckBox_js_1, 10) -- (10局)
- self.jsRadioManager:addItem(self.ui.Items.CheckBox_js_2, 20) -- (20局)
-
- local defaultValue = self:getDefaultValue("totalGameNum") or 10
- self.jsRadioManager:setDefault(defaultValue)
- local callBack = function ( value )
- local config = payTypes[value] or {}
- self:setPayConfig(config)
- end
- self.jsRadioManager:setCallback(callBack)
- callBack(defaultValue)
- end --]]
-
- --人数
- if self.pcountRadioManager then
- self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2) -- (快速成局)
- self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 1) -- (3人)
- self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 0) -- (2人)
-
- local defaultValue = self:getDefaultValue("playerNum") or 2
- self.ui.Items.Layout_FirstOut:setVisible(defaultValue == 1 or defaultValue == 2)
- self.ui.Items.Layout_FirstOut_ex:setVisible(defaultValue == 0)
-
- self.pcountRadioManager:setDefault(defaultValue)
- self.pcountRadioManager:setCallback(function ( value )
- self.ui.Items.Layout_FirstOut:setVisible(value == 1 or value == 2)
- self.ui.Items.Layout_FirstOut_ex:setVisible(value == 0)
- end)
- end
-
- --玩法
- if self.wanfaRadioManager then
- self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_1, 0) -- 必须管
- self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_2, 1) -- 可不要
-
- local defaultValue = self:getDefaultValue("allowPass") or 0
-
- self.wanfaRadioManager:setDefault(defaultValue)
- end
-
- --红桃10扎鸟说明
- self.ui.Items.ImageView_zhaniao:setVisible(false)
- self.ui.Items.Button_zhaniao:registerClick(function()
- playBtnEffect()
- local isShow = self.ui.Items.ImageView_zhaniao:isVisible()
- self.ui.Items.ImageView_zhaniao:setVisible(not isShow)
- end)
- --3必带2说明
- self.ui.Items.ImageView_3dai2:setVisible(false)
- self.ui.Items.Button_3dai2:registerClick(function()
- playBtnEffect()
- local isShow = self.ui.Items.ImageView_3dai2:isVisible()
- self.ui.Items.ImageView_3dai2:setVisible(not isShow)
- end)
- --反春天说明
- self.ui.Items.ImageView_fanchuntian:setVisible(false)
- self.ui.Items.Button_fanchuntian:registerClick(function()
- playBtnEffect()
- local isShow = self.ui.Items.ImageView_fanchuntian:isVisible()
- self.ui.Items.ImageView_fanchuntian:setVisible(not isShow)
- end)
-
- if self.typeCheckBoxManager then
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_1, "tp_1", 0x0001, 0x0000) --0x0001 红桃10扎鸟
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_2, "tp_2", 0x0002, 0x0000) --0x0002 可4带3
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_3, "tp_3", 0x0004, 0x0000) --0x0004 炸弹可拆
- -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_4, "tp_4", 0x0008, 0x0000) --0x0008 3张,飞机少带接完
- -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_5, "tp_5", 0x0010, 0x0000) --0x0010 首局先出黑桃三
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_6, "tp_6", 0x0020, 0x0000) --0x0020 显示牌的张数
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_4, "tp_4", 0x0400, 0x0000) --0x0400 可4带2
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_5, "tp_5", 0x0200, 0x0000) --0x0200 3必带2
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_8, "tp_8", 0x0800, 0x0000) --0x0800 反春天
- local defaultValue = self:getDefaultValue("specialRule") or 0x0001
- if tonumber(defaultValue) == nil then
- defaultValue = 0x0001
- end
- local defaultT = {}
- if getNumBand(defaultValue, 0x0001)>0 then
- table.insert(defaultT, "tp_1")
- end
- if getNumBand(defaultValue, 0x0002)>0 then
- table.insert(defaultT, "tp_2")
- end
- if getNumBand(defaultValue, 0x0004)>0 then
- table.insert(defaultT, "tp_3")
- end
- if getNumBand(defaultValue, 0x0008)>0 then
- table.insert(defaultT, "tp_4")
- end
- if getNumBand(defaultValue, 0x00020)>0 then
- table.insert(defaultT, "tp_6")
- end
- if getNumBand(defaultValue, 0x0400)>0 then
- table.insert(defaultT, "tp_4")
- end
- if getNumBand(defaultValue, 0x0200)>0 then
- table.insert(defaultT, "tp_5")
- end
- if getNumBand(defaultValue, 0x0800)>0 then
- table.insert(defaultT, "tp_8")
- end
- self.typeCheckBoxManager:setDefault(defaultT)
- end
-
- if self.payRadioManager then
- self.payRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0)
- self.payRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1)
- local defaultValue = self:getDefaultValue("deductRule") or 0
- self.payRadioManager:setDefault(tonumber(defaultValue))
- --通知创建界面更新显示
- local function dispatchUpdateCost()
- app:dispatchEvent({name = "onChangePayMode"})
- end
- self.payRadioManager:setCallback(dispatchUpdateCost);
- end
-
- if self.firstOutRadioManager then
- self.firstOutRadioManager:addItem(self.ui.Items.CheckBox_FirstOut_1, 0x0010)
- self.firstOutRadioManager:addItem(self.ui.Items.CheckBox_FirstOut_2, 0x0040)
- local defaultValue = self:getDefaultValue("firstOutRule") or 0x0040
- self.firstOutRadioManager:setDefault(tonumber(defaultValue))
- end
-
- if self.firstOutExBoxManager then
- self.firstOutExBoxManager:addItem(self.ui.Items.CheckBox_FirstOut_ex_1, "out_tp_1", 0x0040, 0x0000) --0x0040第一手必须包含最小牌
- local defaultValue = self:getDefaultValue("firstOutRuleEx") or 0x0040
- if tonumber(defaultValue) == nil then
- defaultValue = 0x0040
- end
- local defaultT = {}
- if getNumBand(defaultValue, 0x0040)>0 then
- table.insert(defaultT, "out_tp_1")
- end
- self.firstOutExBoxManager:setDefault(defaultT)
- end
-
- self:initBombScore()
- self:initOtherCheckBoxManager()
- self:initLayoutEvent()
- self:initJiFenBeiShu()
- end
- ---
- -- 初始化炸弹分
- -- @return
- --
- function CreateRoom_PDK_SWZ:initBombScore ()
- if not self.bombScoreRadioManager then
- return
- end
- --炸弹分选择
- if self.bombScoreRadioManager then
- self.bombScoreRadioManager:addItem(self.ui.Items.CheckBox_bomb_1, 5) --5分
- self.bombScoreRadioManager:addItem(self.ui.Items.CheckBox_bomb_2, 10) --10分
- local defaultValue = self:getDefaultValue("bombScore") or 10
- self.bombScoreRadioManager:setDefault(tonumber(defaultValue))
- end
- end
- ---
- -- 初始化其他选项
- -- @return
- --
- function CreateRoom_PDK_SWZ:initOtherCheckBoxManager ()
- if not self.otherCheckBoxManager then
- return
- end
-
- -- self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)
- -- local forbidProp = self:getDefaultValue("forbidProp") or 0
- -- local defaults = {}
- -- if forbidProp > 0 then
- -- table.insert(defaults, "forbidProp")
- -- end
- -- self.otherCheckBoxManager:setDefault(defaults)
-
- self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0)--屏蔽快捷语与道具
- self.otherCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidVoice, "forbidVoice", 1, 0)--屏蔽语音
- local forbidProp = self:getDefaultValue("forbidProp") or 0
- local forbidVoice = self:getDefaultValue("forbidVoice") or 0
- local defaults = {}
- if forbidProp > 0 then
- table.insert(defaults, "forbidProp")
- end
- if forbidVoice == 1 then
- table.insert(defaults, "forbidVoice")
- end
- self.otherCheckBoxManager:setDefault(defaults)
- end
- -- 面板的点击事件,点击面板后,隐藏所有提示
- function CreateRoom_PDK_SWZ:initLayoutEvent()
- self.ui.Items.Layout_1:registerClick(function()
- local buttons = {
- {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
- {buttonName = "Button_zhaniao", tipsName = "ImageView_zhaniao"},
- {buttonName = "Button_3dai2", tipsName = "ImageView_3dai2"},
- {buttonName = "Button_fanchuntian", tipsName = "ImageView_fanchuntian"},
- };
-
- -- 隐藏其他提示信息
- for k, v in ipairs(buttons) do
- local tipsNode = self.ui.Items[v.tipsName]
- tipsNode:setVisible(false)
- end
- end)
- end
- -- 初始化积分倍数
- function CreateRoom_PDK_SWZ:initJiFenBeiShu()
- self.ui.Items.Button_jia:registerClick(handler(self, self.onClickAdd))
- self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJian))
- self.curJFBS = self:getDefaultValue("baseMulti") or 1;
- self:updateJiFenBeiShu()
- --积分倍数说明
- self.ui.Items.ImageView_JFBS:setVisible(false)
- self.ui.Items.Button_JFBS:registerClick(function()
- self.ui.Items.ImageView_JFBS:setVisible(not self.ui.Items.ImageView_JFBS:isVisible())
- end)
- end
- --更新积分倍数
- function CreateRoom_PDK_SWZ:updateJiFenBeiShu()
- self.curJFBS = self.curJFBS >= 1.0 and math.floor(self.curJFBS) or self.curJFBS;
- self.ui.Items.Text_jifen:setText(self.curJFBS)
-
- self.ui.Items.Button_jia:setEnabled(self.curJFBS ~= 100)
- self.ui.Items.Button_jian:setEnabled(self.curJFBS ~= 0.1)
- end
- --按钮加
- function CreateRoom_PDK_SWZ:onClickAdd()
- playBtnEffect()
- if not self.curJFBS then
- return
- end
- if self.curJFBS >= 1.0 then
- self.curJFBS = self.curJFBS + 1.0
- else
- self.curJFBS = self.curJFBS + 0.1
- end
- if self.curJFBS >= 100 then
- self.curJFBS = 100;
- end
- self:updateJiFenBeiShu()
- end
- --按钮减
- function CreateRoom_PDK_SWZ:onClickJian()
- playBtnEffect()
- if not self.curJFBS then
- return
- end
- if self.curJFBS <= 1.0 then
- self.curJFBS = self.curJFBS - 0.1
- else
- self.curJFBS = self.curJFBS - 1.0
- end
- if self.curJFBS <= 0.1 then
- self.curJFBS = 0.1
- end
- self:updateJiFenBeiShu()
- end
-
- function CreateRoom_PDK_SWZ:getRuleResult()
- local result = {}
- result.totalGameNum = self.jsRadioManager:getResult()--局数
- result.playerNum = self.pcountRadioManager:getResult()--玩家人数
- result.allowPass = self.wanfaRadioManager:getResult()--玩法
- result.specialRule = self.typeCheckBoxManager:getResult()--规则
- result.deductRule = self.payRadioManager:getResult()--房费0房主1aa
- result.firstOutRule = self.firstOutRadioManager:getResult()
- result.firstOutRuleEx = self.firstOutExBoxManager:getResult()
- result.bombScore = self.bombScoreRadioManager:getResult()
- local rule = 0
- local other = self.otherCheckBoxManager:getResult2()
- local forbidProp = other["forbidProp"]
- local forbidVoice = other["forbidVoice"]
- for _,v in pairs(result.specialRule) do
- rule = getNumOr(rule, v.value)
- end
- local saveRule = rule
- local ruleEx = 0
- if result.playerNum==0 then--两人没有首轮必出黑桃三
- for _,v in pairs(result.firstOutRuleEx) do
- rule = getNumOr(rule, v.value)
- ruleEx = getNumOr(rule, v.value)
- end
- else
- rule = getNumOr(rule, result.firstOutRule)--首轮出牌规则
- end
-
- local tgameInfo = {}
- tgameInfo.gamerule = self.curPlayType
- tgameInfo.playerNum = result.playerNum--0 两人 1 三人
- tgameInfo.allowPass = result.allowPass
- tgameInfo.specialRule = rule
- tgameInfo.deductRule = result.deductRule
- tgameInfo.playnum = tgameInfo.playerNum == 0 and 2 or 3
- tgameInfo.baseMulti = self.curJFBS
- tgameInfo.forbidProp = forbidProp
- tgameInfo.forbidVoice = forbidVoice
- tgameInfo.bombScore = result.bombScore
- self.defaultValus =
- {
- gameRule = self.curPlayType,
- totalGameNum = result.totalGameNum,
- playerNum = result.playerNum,
- playnum = result.playerNum == 0 and 2 or 3,
- allowPass = result.allowPass,
- specialRule = saveRule,
- deductRule = result.deductRule,
- firstOutRule = result.firstOutRule,
- firstOutRuleEx = ruleEx,
- baseMulti = self.curJFBS,
- forbidProp = forbidProp,
- forbidVoice = forbidVoice,
- bombScore = bombScore,
- }
- -- 保存玩家的选择
- self:saveDefaultValues()
- local gameInfo = json.encode(tgameInfo)
- return result.totalGameNum, gameInfo, 0
- end
-
- function CreateRoom_PDK_SWZ:onEnter()
- CreateRoom_PDK_SWZ.super.onEnter(self)
- -- 整理不同局数对应的房卡消耗
-
- end
-
- return CreateRoom_PDK_SWZ
|