|
- local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
-
- local MJCreateRoomItem=class("xzdd4r2fCreateRoomItem",CreateRoomItemBase)
-
- local SELECT_COLOR = cc.c4b(213,46,11,255)
- local NON_SELECT_COLOR = cc.c4b(21,99,97,255)
-
- function MJCreateRoomItem:ctor(defaultValues)
- MJCreateRoomItem.super.ctor(self, defaultValues, "xzddmj_room_2r.json")
- self:loadUI()
-
- self.JuShuRadioManager = import("luaScript.Tools.RadioManager"):new();
- --房费
- self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
- --人数
- self.SwapCardRadioManager = import("luaScript.Tools.RadioManager"):new();
- --封顶
- self.FengDingCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
- --自摸
- self.ZiMoCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
- --点杠
- self.DianGangCheckBoxManager = import("luaScript.Tools.RadioManager"):new();
- --玩法
- self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
- -- 方数
- self.FanShuRadioManager = import("luaScript.Tools.RadioManager"):new();
- -- 其他选项
- self.otherCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new()
-
- self:onHideCestView() -- 隐藏cest的界面
- end
-
- function MJCreateRoomItem: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 MJCreateRoomItem: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
-
- ---
- -- 加载UI
- -- @return
- --
- function MJCreateRoomItem:loadUI ()
- local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_xzdd_2r.ui");
- self.ui = ui;
- self:addChild(ui);
- end
- ---
- -- 根据局数获取房费
- -- @param jushu
- -- @return
- --
- function MJCreateRoomItem: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.roomCard or 0
- elseif payMode == 1 then
- return costInfo.roomCardAA or 0
- end
- end
- end
- return 0
- end
- ---
- -- onEnter
- -- @return
- --
- function MJCreateRoomItem:onEnter()
- MJCreateRoomItem.super.onEnter(self)
- self:initPayRadioManager()
- self:initFengDingCheckBoxManager()
- self:initZiMoCheckBoxManager()
- self:initDianGangCheckBoxManager()
- self:initWanFaCheckBoxManager()
- self:initSwapCardRadioManager()
- self:initFanShuRadioManager()
- self:initOtherCheckBoxManager()
- self:initJiFenBeiShu()
- self:initLayoutEvent()
- end
- ---
- -- 初始化房费选项
- -- @return
- --
- function MJCreateRoomItem:initPayRadioManager ()
- -- 整理不同局数对应的房卡消耗
- local payTypes={}
- local gameConfig = app.user:getGameConfig(GAME_IDS.xzddMJ2r)--app.gameId);
- 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] =
- {
- roomCard = arrRequireCards[idx],
- roomCardAA = arrRequireCardsAA[idx],
- }
- end
- end
- self.cost = payTypes
-
- -- 房费
- if self.PayRadioManager then
- self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付
- self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付
- --self.PayRadioManager:addItem(self.ui.Items.CheckBox_WinFinal, 2); -- 大赢家支付
-
- local default = self:getDefaultValue("deductRule") or 0
- self.PayRadioManager:setDefault(default)
-
- --通知创建界面更新显示
- local function dispatchUpdateCost()
- app:dispatchEvent({name = "onChangePayMode"})
- end
- self.PayRadioManager:setCallback(dispatchUpdateCost);
-
- self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
- end
- end
- ---
- -- 初始化封顶选项
- -- @return
- --
- function MJCreateRoomItem:initFengDingCheckBoxManager ()
- if self.FengDingCheckBoxManager then
- self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_3fan, 2); -- 2番
- self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_4fan, 3); -- 3番
- self.FengDingCheckBoxManager:addItem(self.ui.Items.CheckBox_5fan, 4); -- 4番
-
- local default = self:getDefaultValue("limitfan") or 4
- self.FengDingCheckBoxManager:setDefault(default)
- end
- end
- ---
- -- 初始化自摸选项
- -- @return
- --
- function MJCreateRoomItem:initZiMoCheckBoxManager ()
- if self.ZiMoCheckBoxManager then
- self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_1, 1); -- 自摸加底
- self.ZiMoCheckBoxManager:addItem(self.ui.Items.CheckBox_ZiMo_2, 2); -- 自摸加番
-
- local default = self:getDefaultValue("zimomode") or 2
- self.ZiMoCheckBoxManager:setDefault(default)
- end
- end
- ---
- -- 初始化点杠选项
- -- @return
- --
- function MJCreateRoomItem:initDianGangCheckBoxManager ()
- if self.DianGangCheckBoxManager then
- self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_1, 2); -- 自摸
- self.DianGangCheckBoxManager:addItem(self.ui.Items.CheckBox_gang_2, 1); -- 点炮
-
- local default = self:getDefaultValue("gshmode") or 2
- self.DianGangCheckBoxManager:setDefault(default)
- end
- end
- ---
- -- 初始化玩法选项
- -- @return
- --
- function MJCreateRoomItem:initWanFaCheckBoxManager ()
- if self.WanFaCheckBoxManager then
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_YaoJiu, "yj", 1, 0) -- 幺九
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_JiangDui, "jd", 1, 0) -- 将对
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TianDiHu, "tdh", 1, 0) -- 天地胡
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_MenQing, "mq", 1, 0) -- 门清
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_ZhongZhang, "zz", 1, 0) -- 中张
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_2FenQiHu, "efqh", 1, 0) -- 两分起胡
- self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_TingPaiTiShi, "ting", 1, 0) -- 听牌提示
-
- local ting = self:getDefaultValue("ting") or 1
- local yj = self:getDefaultValue("yj") or 1
- local jd = self:getDefaultValue("jd") or 1
- local tdh = self:getDefaultValue("tdh") or 1
- local mq = self:getDefaultValue("mq") or 1
- local zz = self:getDefaultValue("zz") or 1
- local efqh = self:getDefaultValue("efqh") or 0
-
- local selecteds = {}
- if ting==1 then
- table.insert(selecteds,"ting")
- end
-
- if yj == 1 then
- table.insert(selecteds, "yj")
- end
-
- if jd == 1 then
- table.insert(selecteds, "jd")
- end
-
- if tdh == 1 then
- table.insert(selecteds, "tdh")
- end
-
- if mq == 1 then
- table.insert(selecteds, "mq")
- end
-
- if zz == 1 then
- table.insert(selecteds, "zz")
- end
-
- if efqh == 1 then
- table.insert(selecteds, "efqh")
- end
-
- self.WanFaCheckBoxManager:setDefault(selecteds)
-
- self:setDefaultTextColor()
- end
- end
- ---
- -- 初始化方数选项
- -- @return
- --
- function MJCreateRoomItem:initFanShuRadioManager ()
- if self.FanShuRadioManager then
- self.FanShuRadioManager:addItem(self.ui.Items.CheckBox_FanShu2, 2); -- 两方
- self.FanShuRadioManager:addItem(self.ui.Items.CheckBox_FanShu3, 3); -- 三方
-
- local default = self:getDefaultValue("cardtype") or 2
- self.FanShuRadioManager:setDefault(default)
- end
- end
- ---
- -- 初始化其他选项
- -- @return
- --
- function MJCreateRoomItem: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
- -- 面板的点击事件,点击面板后,隐藏所有提示
- function MJCreateRoomItem:initLayoutEvent()
- self.ui.Items.Layout_1:registerClick(function()
- local buttons = {
- --{buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
- {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
- };
-
- -- 隐藏其他提示信息
- for k, v in ipairs(buttons) do
- local tipsNode = self.ui.Items[v.tipsName]
- tipsNode:setVisible(false)
- end
- end)
- end
- ---
- -- 初始化换张选项
- -- @return
- --
- function MJCreateRoomItem:initSwapCardRadioManager ()
- if not self.SwapCardRadioManager then
- return
- end
- self.SwapCardRadioManager:addItem(self.ui.Items.CheckBox_SwapCard3, 3); -- 换三张
- self.SwapCardRadioManager:addItem(self.ui.Items.CheckBox_SwapCard4, 4); -- 换四张
- self.SwapCardRadioManager:addItem(self.ui.Items.CheckBox_SwapCard0, 0); -- 换四张
-
- local default = self:getDefaultValue("swapcard") or 3
- self.SwapCardRadioManager:setDefault(default)
- end
-
- --设置选中值默认颜色
- function MJCreateRoomItem:setDefaultTextColor(radio,text)
- if radio then
- local index = radio:getResult()
- local defaultText = string.format(text.."%d",index)
- self.ui.Items[defaultText]:setTextColor(SELECT_COLOR)
- end
-
- --[[local result = self.WanFaCheckBoxManager:getResult2()
- if result.mqzz == 1 then
- self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
- end--]]
- end
-
- --点击checkBox时,改变其text的颜色
- function MJCreateRoomItem:updataTextColor(radio,text,boxType,valueTab)
- local function updataRadioTextColor()
- if boxType == "radioBox" then
- local index = radio:getResult()
- for k,value in pairs(valueTab) do
- local item = string.format(text.."%d",value)
- self.ui.Items[item]:setTextColor(NON_SELECT_COLOR)
- if value == index then
- self.ui.Items[item]:setTextColor(SELECT_COLOR)
- end
- end
- elseif boxType == "checkBox" then
- --[[local result = self.WanFaCheckBoxManager:getResult2()
- local result = self.WanFaCheckBoxManager:getResult2()
- if result.mqzz == 1 then
- self.ui.Items.Text_mqzz:setTextColor(SELECT_COLOR)
- self.ui.Items.CheckBox_BoZiMo:setVisible(true)
- else
- self.ui.Items.Text_mqzz:setTextColor(NON_SELECT_COLOR)
- self.ui.Items.CheckBox_BoZiMo:setVisible(false)
- end--]]
- end
- end
-
- radio:setCallback(updataRadioTextColor);
- end
-
- -- 初始化积分倍数
- function MJCreateRoomItem: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 MJCreateRoomItem: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 MJCreateRoomItem: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 MJCreateRoomItem: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 MJCreateRoomItem:getRuleResult()
- local game_num = self.JuShuRadioManager:getResult()
- local payMode = self.PayRadioManager:getResult()
- local playnum = 2
- local isfaststart = 0
-
- local limitfan = self.FengDingCheckBoxManager:getResult()
- local playmode = self.ZiMoCheckBoxManager:getResult()
- local gshmode = self.DianGangCheckBoxManager:getResult()
- local cardtype = self.FanShuRadioManager:getResult()
- local wanFaResult = self.WanFaCheckBoxManager:getResult2()
- local ting = wanFaResult.ting
- local yj = wanFaResult.yj
- local jd = wanFaResult.jd
- local tdh = wanFaResult.tdh
- local mq = wanFaResult.mq
- local zz = wanFaResult.zz
- local efqh = wanFaResult.efqh
-
- local other = self.otherCheckBoxManager:getResult2()
- local forbidProp = other["forbidProp"]
- local forbidVoice = other["forbidVoice"]
-
- local swapcard = self.SwapCardRadioManager:getResult()
- local efkh = efqh
-
- self.defaultValus =
- {
- gamerule = 1,
- totalgamenum = game_num,
- deductRule = payMode,
- playnum = playnum,
- isfaststart = isfaststart,
- faststart = isfaststart,
- limitfan = limitfan,
- playmode = playmode,
- gshmode = gshmode,
- ting = ting,
- yj = yj,
- jd = jd,
- tdh = tdh,
- mq = mq,
- zz = zz,
- efqh = efqh,
- cardtype = cardtype,
- baseMulti = self.curJFBS,
- forbidProp = forbidProp,
- forbidVoice = forbidVoice,
- swapcard = swapcard,
- efkh = efkh,
- }
-
- -- 保存玩家的选择
- self:saveDefaultValues()
-
- local strGameInfo = json.encode(self.defaultValus);
- return game_num, strGameInfo
- end
-
-
- return MJCreateRoomItem
|