|
-
- local CreateRoom_PDK_hejiang = class("CreateRoom_PDK_hejiang", require("luaScript.Views.CreateRoom.CreateRoomItemBase"))
-
- --[[
- isCreateRoom和defaultValus决定了从哪里读取默认值
- isCreateRoom 为true时,从本地文件读取,defaultValus无效.
- 否则使用defaultValus的值
- defaultValus : 跟服务器strGameInfo对应的json对象
- --]]
- function CreateRoom_PDK_hejiang:ctor(defaultValus)
- CreateRoom_PDK_hejiang.super.ctor(self, defaultValus, "CreateRoom_PDK_hejiang.json")
-
- local ui = loadUI("res/ui/ui_chuangjian/pk_chuangjian_hejiangpdk.ui")
- self.ui = ui
- self:addChild(ui)
-
- local gameConfig = getSubGameConfig(GAME_IDS.hejiangPaoDeKuai)
- self.curPlayType = 0
-
- -- 局数 - 单选
- 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.tieYiXianCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
-
- -- 颗数选择
- self.KeShuRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 末手选择
- self.moShouRadioManager = import("luaScript.Tools.RadioManager"):new()
-
- -- 其他选项
- self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
-
- self:initRadio()
-
- self:onHideCestView() -- 隐藏cest的界面
- end
-
-
- function CreateRoom_PDK_hejiang: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_hejiang: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_hejiang: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_hejiang: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_hejiang:initRadio()
- -- 整理不同局数对应的房卡消耗
- local payTypes={}
- local gameConfig = app.user:getGameConfig(GAME_IDS.hejiangPaoDeKuai);
-
- 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, 1) -- (快速成局)
- self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 4) -- (4人)
- self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 3) -- (3人)
- self.pcountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 2) -- (2人)
-
- local defaultValue = self:getDefaultValue("playnum") or 1--默认快速成局
- self.pcountRadioManager:setDefault(defaultValue)
- local callBack = function ( value )
- if value == 2 then
- self.ui.Items.CheckBox_type_2:setVisible(false)
- self.ui.Items.Button_JPQ:setVisible(false)
- self.ui.Items.ImageView_5:setVisible(false)
- else
- self.ui.Items.CheckBox_type_2:setVisible(true)
- self.ui.Items.Button_JPQ:setVisible(true)
- end
- end
- self.pcountRadioManager:setCallback(callBack)
- callBack(defaultValue)
- end
-
- --玩法
- if self.wanfaRadioManager then
- self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_1, 0) -- 无鬼
- self.wanfaRadioManager:addItem(self.ui.Items.CheckBox_wanfa_2, 2) -- 两鬼
-
- local defaultValue = self:getDefaultValue("jokerCount") or 0
-
- self.wanfaRadioManager:setDefault(defaultValue)
- local callBack = function ( value )
- if value == 0 then
- self.ui.Items.Layout_content_3:setVisible(true)
- else
- self.ui.Items.Layout_content_3:setVisible(false)
- end
- end
- self.wanfaRadioManager:setCallback(callBack)
- callBack(defaultValue)
- end
-
- --快速成局说明
- self.ui.Items.ImageView_3:setVisible(false)
- self.ui.Items.Button_KSCJ:registerClick(function()
- playBtnEffect()
- self.ui.Items.ImageView_3:setVisible(not self.ui.Items.ImageView_3:isVisible())
- end)
- --记牌器说明
- self.ui.Items.ImageView_5:setVisible(false)
- self.ui.Items.Button_JPQ:registerClick(function()
- playBtnEffect()
- self.ui.Items.ImageView_5:setVisible(not self.ui.Items.ImageView_5:isVisible())
- end)
-
- --规则
- if self.typeCheckBoxManager then
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_2, "tp_1", 0x0001, 0x0000) --0x0001 记牌器
- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_type_1, "tp_2", 0x0002, 0x0000) --0x8888 有大必打
- -- self.typeCheckBoxManager:addItem(self.ui.Items.CheckBox_ForbidProp, "forbidProp", 1, 0) --0x8888 有大必打
- local defaultValue = self:getDefaultValue("specialRule") or 0x0002
- if tonumber(defaultValue) == nil then
- defaultValue = 0x0002
- 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
-
- -- local forbidProp = self:getDefaultValue("forbidProp")
- -- if forbidProp and tonumber(forbidProp) == 1 then
- -- table.insert(defaultT, "forbidProp")
- -- end
-
- self.typeCheckBoxManager:setDefault(defaultT)
- end
-
- --铁一线规则
- if self.tieYiXianCheckBoxManager then
- local values =
- {
- [1] = {selectValue = 0x0001, unselectValue = 0x0000},--铁一线规则
- }
- self.tieYiXianCheckBoxManager:addItem(self.ui.Items.CheckBox_type_3, 1, values[1].selectValue, values[1].unselectValue) --0x0001 铁一线规则
- local defaultValue = self:getDefaultValue("tieyixian") or 0x0001
- if tonumber(defaultValue) == nil then
- defaultValue = 0x0001
- end
- -- 设置默认状态
- local ttSelected = {}
- for k,v in pairs(values) do
- if getNumBand(defaultValue, v.selectValue) > 0 then
- table.insert(ttSelected, k)
- end
- end
- self.tieYiXianCheckBoxManager:setDefault(ttSelected);
- 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.KeShuRadioManager then
- self.KeShuRadioManager:addItem(self.ui.Items.CheckBox_6, 1); -- 1/2/4/6颗
- self.KeShuRadioManager:addItem(self.ui.Items.CheckBox_7, 2); -- 2/4/6/8颗
- self.KeShuRadioManager:addItem(self.ui.Items.CheckBox_14, 3); -- 3/5/10/15颗
-
- -- 设置默认数据
- local defaultValue = self:getDefaultValue("keCount") or 1
- self.KeShuRadioManager:setDefault(tonumber(defaultValue));
- end
-
- -- 末手规则
- if self.moShouRadioManager then
- self.moShouRadioManager:addItem(self.ui.Items.CheckBox_moshou_1, 1); -- 可出
- self.moShouRadioManager:addItem(self.ui.Items.CheckBox_moshou_2, 0); -- 不可出
-
- -- 设置默认数据
- local defaultValue = self:getDefaultValue("endsandaiyi") or 0
- self.moShouRadioManager:setDefault(tonumber(defaultValue));
- end
-
- self:initLayoutEvent()
- self:initJiFenBeiShu()
- end
-
- -- 面板的点击事件,点击面板后,隐藏所有提示
- function CreateRoom_PDK_hejiang:initLayoutEvent()
- self.ui.Items.Layout_1:registerClick(function()
- local buttons = {
- {buttonName = "Button_KSCJ", tipsName = "ImageView_3"},
- {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
- {buttonName = "Button_JPQ", tipsName = "ImageView_5"},
- };
-
- -- 隐藏其他提示信息
- for k, v in ipairs(buttons) do
- local tipsNode = self.ui.Items[v.tipsName]
- tipsNode:setVisible(false)
- end
- end)
- end
- -- 初始化积分倍数
- function CreateRoom_PDK_hejiang: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_hejiang: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_hejiang: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_hejiang: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_hejiang:getRuleResult()
- local result = {}
- result.totalGameNum = self.jsRadioManager:getResult()--局数
- result.playnum = self.pcountRadioManager:getResult()--玩家人数
- result.specialRule = self.typeCheckBoxManager:getResult()--规则
- result.deductRule = self.payRadioManager:getResult()--房费0房主1aa
- result.jokerCount = self.wanfaRadioManager:getResult()--带鬼数
- result.keCount = self.KeShuRadioManager:getResult()--颗数
- result.tieyixian = self.tieYiXianCheckBoxManager:getResult2();
- result.endsandaiyi = self.moShouRadioManager:getResult()--末手三带一
- result.allowPass = 1
- local rule = 0
- local forbidProp = 0
- local other = self.otherCheckBoxManager:getResult2()
- local forbidProp = other["forbidProp"]
- local forbidVoice = other["forbidVoice"]
-
- for key,v in pairs(result.specialRule) do
- if key == "forbidProp" then
- -- forbidProp = v.value
- else
- if v.value == 1 and result.playnum == 2 then
- else
- rule = getNumOr(rule, v.value)
- end
- if getNumBand(v.value, 0x0002)>0 then
- result.allowPass = 0
- end
- end
- end
- local tieyixian = 0;
- for k,v in pairs(result.tieyixian) do
- if k == 1 then
- tieyixian = v
- end
- end
- if result.jokerCount == 2 then
- tieyixian = 0
- end
- local saveRule = rule
-
- local tgameInfo = {}
- tgameInfo.gamerule = self.curPlayType
- tgameInfo.playnum = result.playnum--0 两人 1 三人
- tgameInfo.allowPass = result.allowPass
- tgameInfo.specialRule = rule
- tgameInfo.jokerCount = result.jokerCount
- tgameInfo.keCount = result.keCount
- tgameInfo.deductRule = result.deductRule
- tgameInfo.tieyixian = tieyixian
- tgameInfo.endsandaiyi = result.endsandaiyi
- tgameInfo.baseMulti = self.curJFBS
- tgameInfo.forbidProp = forbidProp
- tgameInfo.forbidVoice = forbidVoice
- self.defaultValus =
- {
- gameRule = self.curPlayType,
- totalGameNum = result.totalGameNum,
- playnum = result.playnum,
- allowPass = result.allowPass,
- specialRule = saveRule,
- deductRule = result.deductRule,
- jokerCount = result.jokerCount,
- keCount = result.keCount,
- tieyixian = tieyixian,
- endsandaiyi = result.endsandaiyi,
- baseMulti = self.curJFBS,
- forbidProp = forbidProp,
- forbidVoice = forbidVoice,
- }
- -- 保存玩家的选择
- self:saveDefaultValues()
- local gameInfo = json.encode(tgameInfo)
- return result.totalGameNum, gameInfo, 0
- end
-
- function CreateRoom_PDK_hejiang:onEnter()
- CreateRoom_PDK_hejiang.super.onEnter(self)
- -- 整理不同局数对应的房卡消耗
- self:initOtherCheckBoxManager();
- end
-
-
- ---
- -- 初始化其他选项
- -- @return
- --
- function CreateRoom_PDK_hejiang:initOtherCheckBoxManager ()
- if not self.otherCheckBoxManager then
- return
- end
-
- 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
-
-
-
- return CreateRoom_PDK_hejiang
|