--- 红中麻将 local RadioManager = require("luaScript.Tools.RadioManager"); local CheckBoxManager = require("luaScript.Tools.CheckBoxManager"); local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase") local MJCreateRoomItem=class("hongzhongCreateRoomItem",CreateRoomItemBase) function MJCreateRoomItem:ctor(defaultValues) MJCreateRoomItem.super.ctor(self, defaultValues, "hongzhong_room.json"); local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_hongzhong.ui"); self.ui = ui; self:addChild(ui); self:initCreateRoomCost(); -- 支付方式 self.PayRadioManager = RadioManager:new(); -- 人数 self.PlayerCountRadioManager = RadioManager:new(); -- 胡牌 self.HuTypeRadioManager = RadioManager:new(); -- 玩法 self.WanFaCheckBoxManager = CheckBoxManager:new(); -- 红中 self.HongZhongRadioManager = RadioManager:new(); -- 分数 self.FenShuRadioManager = RadioManager:new(); -- 托管 self.HostingCheckBoxManager = CheckBoxManager:new(); -- 抓鸟 self.ZhuaNiaoRadioManager = RadioManager:new(); -- 鸟分 self.NiaoFenRadioManager = 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 function MJCreateRoomItem:onEnter(...) MJCreateRoomItem.super.onEnter(self, ...); self:initPayRadioManager(); self:initPlayerCountRadioManager(); self:initHuTypeRadioManager(); self:initWanFaCheckBoxManager(); self:initHongZhongRadioManager(); self:initFenShuRadioManager(); self:initZhuaNiaoRadioManager(); self:initNiaoFenRadioManager(); self:initHostingCheckBoxManager(); self:initOtherCheckBoxManager(); self:initJiFenBeiShu(); end function MJCreateRoomItem:initCreateRoomCost () -- 整理不同局数对应的房卡消耗 local payTypes={} local gameConfig = app.user:getGameConfig(GAME_IDS.HongZhong)--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 end 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 function MJCreateRoomItem:initPayRadioManager () if not self.PayRadioManager then return ; end self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); self.PayRadioManager:addItem(self.ui.Items.CheckBox_AA, 1); local defaultValue = self:getDefaultValue("deductRule") or 0 self.PayRadioManager:setDefault(tonumber(defaultValue)) self.PayRadioManager:setCallback(function () playBtnEffect() app:dispatchEvent({name = "onChangePayMode"}) end) end function MJCreateRoomItem:initPlayerCountRadioManager() if not self.PlayerCountRadioManager then return ; end self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_0, 4); self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 0); self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 1); self.PlayerCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 2); local defaultValue = self:getDefaultValue("playnum") or 2; local isfaststart = self:getDefaultValue("isfaststart") or 1 if isfaststart == 1 then defaultValue = 4 end self.PlayerCountRadioManager:setDefault(tonumber(defaultValue)); self.ui.Items.ImageView_2:setVisible(false) self.ui.Items.Button_KSCJ:registerClick(function() local isVisible = not self.ui.Items.ImageView_2:isVisible() self.ui.Items.ImageView_2:setVisible(isVisible) end) end function MJCreateRoomItem:initHuTypeRadioManager() if not self.HuTypeRadioManager then return ; end self.HuTypeRadioManager:addItem(self.ui.Items.CheckBox_ZiMoHu, 1); self.HuTypeRadioManager:addItem(self.ui.Items.CheckBox_DianPaoHu, 2); self.HuTypeRadioManager:setCallback(function (value) self.ui.Items.CheckBox_HongZhonBuJiePao:setEnabled(value == 2); self.ui.Items.CheckBox_WuHongZhong:setEnabled(value ~= 2); self.ui.Items.CheckBox_ZiMo2:setEnabled(value == 1); self.ui.Items.CheckBox_ZiMo5:setEnabled(value == 1); if value ~= 2 then self.ui.Items.CheckBox_HongZhonBuJiePao:setSelectedState(false); else self.ui.Items.CheckBox_WuHongZhong:setSelectedState(false); end end); local defaultValue = self:getDefaultValue("playmode") or 1; if defaultValue == 3 then defaultValue = 2; end self.HuTypeRadioManager:setDefault(defaultValue); end function MJCreateRoomItem:initWanFaCheckBoxManager() if not self.WanFaCheckBoxManager then return ; end self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_HongZhonBuJiePao, "hongzhonbujiepao", 3, 0); self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_Piao, "piaotype", 1, 0); self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_DaiQiangGangPao, "canqiangganghu", 1, 0); self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_QiDuiHu, "extrahutype", 1, 0); self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_WuHongZhong, "noredaddniao", 1, 0); self.WanFaCheckBoxManager:addItem(self.ui.Items.CheckBox_BuKePeng, "embarpeng", 1, 0); -- canqiangganghu = self.checkQiangGangCompnent.isSelect and MJWanFa.canqiangganghu[2].value or MJWanFa.canqiangganghu[1].value, -- noredaddniao = self.checkWuHongZhongCompnent.isSelect and MJWanFa.noredaddniao[2].value or MJWanFa.noredaddniao[1].value, -- embarpeng = self.checkPengCompnent.isSelect and MJWanFa.embarpeng[2].value or MJWanFa.embarpeng[1].value, -- piaotype = self.checkPiaoFenCompnent:getValue(),-- and MJWanFa.piaotype[2].value or MJWanFa.piaotype[1].value, local defaultValues = {}; local playmode = self:getDefaultValue("playmode") or 1; if playmode == 3 then table.insert(defaultValues, "hongzhonbujiepao"); end local piaotype = self:getDefaultValue("piaotype") or 1; if piaotype > 0 then table.insert(defaultValues, "piaotype"); end local canqiangganghu = self:getDefaultValue("canqiangganghu") or 1; if canqiangganghu > 0 then table.insert(defaultValues, "canqiangganghu"); end local extrahutype = self:getDefaultValue("extrahutype") or 1; if extrahutype > 0 then table.insert(defaultValues, "extrahutype"); end local noredaddniao = self:getDefaultValue("noredaddniao") or 1; if noredaddniao > 0 then table.insert(defaultValues, "noredaddniao"); end local embarpeng = self:getDefaultValue("embarpeng") or 1; if embarpeng > 0 then table.insert(defaultValues, "embarpeng"); end self.WanFaCheckBoxManager:setDefault(defaultValues); end --- MJCreateRoomItem:HongZhongRadioManager 红中 function MJCreateRoomItem:initHongZhongRadioManager() if not self.HongZhongRadioManager then return ; end self.HongZhongRadioManager:addItem(self.ui.Items.CheckBox_HongZhong, 4); self.HongZhongRadioManager:addItem(self.ui.Items.CheckBox_8HongZhong, 8); local defaultValue = self:getDefaultValue("redsize") or 4; self.HongZhongRadioManager:setDefault(defaultValue); end -- MJCreateRoomItem:FenShuRadioManager 分数 function MJCreateRoomItem:initFenShuRadioManager() if not self.FenShuRadioManager then return ; end self.FenShuRadioManager:addItem(self.ui.Items.CheckBox_ZiMo2, 2); self.FenShuRadioManager:addItem(self.ui.Items.CheckBox_ZiMo5, 5); local defaultValue = self:getDefaultValue("zimoscore") or 2; self.FenShuRadioManager:setDefault(defaultValue); end --- MJCreateRoomItem:ZhuaNiaoRadioManager 抓鸟 function MJCreateRoomItem:initZhuaNiaoRadioManager() if not self.ZhuaNiaoRadioManager then return ; end self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_BuZhuaNiao, 0); self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_YiMaQuanZhong, 1); self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_Zhua2Niao, 2); self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_Zhua4Niao, 4); self.ZhuaNiaoRadioManager:addItem(self.ui.Items.CheckBox_Zhua6Niao, 6); self.ZhuaNiaoRadioManager:setCallback(function (value) self.ui.Items.CheckBox_Niao1:setEnabled(value > 0); self.ui.Items.CheckBox_Niao2:setEnabled(value > 0); self.ui.Items.CheckBox_WuHongZhong:setEnabled(value ~= 0) if value == 0 then self.ui.Items.CheckBox_WuHongZhong:setSelectedState(false) end end); local defaultValue = self:getDefaultValue("niaonumber") or 4; self.ZhuaNiaoRadioManager:setDefault(defaultValue); end --- MJCreateRoomItem:NiaoFenRadioManager 鸟分 function MJCreateRoomItem:initNiaoFenRadioManager() if not self.NiaoFenRadioManager then return ; end self.NiaoFenRadioManager:addItem(self.ui.Items.CheckBox_Niao1, 1); self.NiaoFenRadioManager:addItem(self.ui.Items.CheckBox_Niao2, 2); local defaultValue = self:getDefaultValue("niaopoint") or 2; self.NiaoFenRadioManager:setDefault(defaultValue); end function MJCreateRoomItem:initHostingCheckBoxManager() if not self.HostingCheckBoxManager then return ; end self.HostingCheckBoxManager:addItem(self.ui.Items.CheckBox_type_6, "hosting", 1, 0); self.HostingCheckBoxManager:setCallback(function () local values = self.HostingCheckBoxManager:getResult2(); self.ui.Items.Slider_hosttime:setEnabled(values["hosting"] > 0); end); local defaultValues = {}; local hosting = self:getDefaultValue("hosting") or 0; if hosting > 0 then table.insert(defaultValues, "hosting"); end self.HostingCheckBoxManager:setDefault(defaultValues); self.ui.Items.Slider_hosttime:setEnabled(hosting > 0); local hostMin, hostMax = 30, 240 local slider = self.ui.Items.Slider_hosttime; local txtSeconds = self.ui.Items.Text_hosting_time; slider:addEventListener(function ( sender, eventType) if eventType == 0 then local per = sender:getPercent() self.hostingtime = math.floor(hostMin + (hostMax-hostMin)/100 * per) txtSeconds:setString(string.format("%d", self.hostingtime)) end end) -- default self.hostingtime = self:getDefaultValue("hostingtime") or 60 if self.hostingtime < 30 then self.hostingtime = 60 end txtSeconds:setString(string.format("%d", tonumber(self.hostingtime))) local lastPer = (self.hostingtime - hostMin) / (hostMax - hostMin) * 100 slider:setPercent(lastPer) 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: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) -- self.ui.Items.Layout_JiFenBeiShu:setVisible(false) 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 deductRule = self.PayRadioManager:getResult(); -- 人数 local playnum = self.PlayerCountRadioManager:getResult(); -- 是否快速开局 local isfaststart = playnum == 4 and 1 or 0; -- 鸟分 local niaopoint = self.NiaoFenRadioManager:getResult(); -- 抓鸟 local niaonumber = self.ZhuaNiaoRadioManager:getResult(); -- 分数 local zimoscore = self.FenShuRadioManager:getResult(); -- 胡牌类型 local playmode = self.HuTypeRadioManager:getResult(); -- 红中 local redsize = self.HongZhongRadioManager:getResult(); local wanfaValues = self.WanFaCheckBoxManager:getResult2(); local extrahutype = wanfaValues["extrahutype"]; local canqiangganghu = wanfaValues["canqiangganghu"]; local noredaddniao = wanfaValues["noredaddniao"]; local embarpeng = wanfaValues["embarpeng"]; local piaotype = wanfaValues["piaotype"]; for k, v in pairs(wanfaValues or {}) do if k == "hongzhonbujiepao" and v > 0 then playmode = 3; end end local hostingValues = self.HostingCheckBoxManager:getResult2(); hosting = hostingValues["hosting"] or 0; if playmode == 2 or playmode == 3 then zimoscore = nil; end local other = self.otherCheckBoxManager:getResult2() local forbidProp = other["forbidProp"] local forbidVoice = other["forbidVoice"] self.defaultValus={ gamerule = 1, playmode = playmode, deductRule = deductRule, playnum = playnum, isfaststart = isfaststart, niaopoint = niaopoint, niaonumber = niaonumber, zimoscore = zimoscore, redsize = redsize, extrahutype = extrahutype, canqiangganghu = canqiangganghu, noredaddniao = noredaddniao, embarpeng = embarpeng, piaotype = piaotype, hosting = hosting, hostingtime = self.hostingtime or 60, isHongZhong = 1, baseMulti = self.curJFBS, forbidProp = forbidProp, forbidVoice = forbidVoice, } -- 保存玩家的选择 self:saveDefaultValues() return 0, json.encode(self.defaultValus); end return MJCreateRoomItem