-- local MJSelectRadioCompnent = require("luaScript.Views.CreateRoom.Compnent.MJSelectRadioCompnent") -- local MJGroupCompnent = require("luaScript.Views.CreateRoom.Compnent.MJGroupCompnent") -- local MJCheckBoxCompnent = require("luaScript.Views.CreateRoom.Compnent.MJCheckBoxCompnent") -- local MJWanFa=MJFramework.ImportWanFa("MaJiang.MJWanFa") local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase") local MJCreateRoomItem=class("yibinmajiangCreateRoomItem", 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, "yibinmajiang_room.json") local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_yibinmajiang.ui"); self.ui = ui; self:addChild(ui); -- 房费 self.PayRadioManager = import("luaScript.Tools.RadioManager"):new(); -- 人数 self.PlayerNumRadioManager = import("luaScript.Tools.RadioManager"):new(); -- 封顶 self.FengDingRadioManager = import("luaScript.Tools.RadioManager"):new(); -- 飘 self.PiaoRadioManager = import("luaScript.Tools.RadioManager"):new(); -- 听用 self.TingYongRadioManager = import("luaScript.Tools.RadioManager"):new(); -- 11听用多的规则 self.TingYong11MoreCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new(); -- 胡牌 self.HuPaiRadioManager = import("luaScript.Tools.RadioManager"):new(); --玩法 self.WanFaCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):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:initPlayTips() self:initLayoutEvent() self:initPayRadioManager() self:initPlayerNumRadioManager() self:initFengDingRadioManager() self:initPiaoRadioManager() self:initTingYongManager() self:initTingYong11MoreCheckBoxManager() self:initHuPaiRadioManager() self:initWanFaCheckBoxManager() self:initLayoutEvent() self:initJiFenBeiShu() self:initOtherCheckBoxManager() 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) 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 --[[/** * 父类调用 * 根据局数获取房费 * @param jushu * @return */--]] function MJCreateRoomItem:getCreateRoomCost(jushu) local payTypes = self:getPayTypes(); if not payTypes then return 0 end local payInfo = payTypes[jushu] if not payInfo then return 0 end local payMode = self.PayRadioManager:getResult() if payMode == 0 then return payInfo.roomCard or 0 elseif payMode == 1 then return payInfo.roomCardAA or 0 end end --- --[[/** * 整理不同局数对应的房卡消耗 * @param * @return */--]] function MJCreateRoomItem:getPayTypes( ) local payTypes={} local gameConfig = app.user:getGameConfig(GAME_IDS.yibinmajiang)--app.gameId); if not gameConfig then return end 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 return payTypes; end --[[/** * 初始化帮助信息 * @return */--]] function MJCreateRoomItem:initPlayTips() local buttons = { {buttonName = "Button_QuickStartTips", tipsName = "ImageView_QuickStartTips"}, {buttonName = "Button_2FanQiHu", tipsName = "ImageView_2FanQiHu"}, {buttonName = "Button_TianHuManGuan", tipsName = "ImageView_TianHuManGuan"}, {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"}, }; -- 点击其中一个,隐藏其他提示信息 local hideOtherTips = function (buttonName) for k, v in ipairs(buttons) do local btnNode = self.ui.Items[v.buttonName]; local tipsNode = self.ui.Items[v.tipsName]; if v.buttonName ~= buttonName then tipsNode:setVisible(false); end end end -- 注册问号按钮事件 for k, v in ipairs(buttons) do local btnNode = self.ui.Items[v.buttonName]; local tipsNode = self.ui.Items[v.tipsName]; -- 按钮点击事件 tipsNode:setVisible(false); btnNode:registerClick(handler(self, function (obj) local isVisible = tipsNode:isVisible(); tipsNode:setVisible(not isVisible); hideOtherTips(v.buttonName); end)); -- 图片面板点击事件 tipsNode:registerClick(handler(self, function (obj) tipsNode:setVisible(false); end)); tipsNode:setTouchEnabled(true); end end -- 面板的点击事件,点击面板后,隐藏所有提示 function MJCreateRoomItem:initLayoutEvent() self.ui.Items.Layout_1:registerClick(function() local buttons = { {buttonName = "Button_QuickStartTips", tipsName = "ImageView_QuickStartTips"}, {buttonName = "Button_2FanQiHu", tipsName = "ImageView_2FanQiHu"}, {buttonName = "Button_TianHuManGuan", tipsName = "ImageView_TianHuManGuan"}, {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:initPayRadioManager () if not self.PayRadioManager then return end self.PayRadioManager:addItem(self.ui.Items.CheckBox_FangZhu, 0); -- 房主支付 self.PayRadioManager:addItem(self.ui.Items.CheckBox_AAPay, 1); -- AA支付 local default = self:getDefaultValue("deductRule") or 0 self.PayRadioManager:setDefault(default) self.PayRadioManager:setCallback(function () -- 通知创建界面更新显示 app:dispatchEvent({name = "onChangePayMode"}) end); end --[[/** * 初始化人数选项 * @return */--]] function MJCreateRoomItem:initPlayerNumRadioManager () if not self.PlayerNumRadioManager then return end self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_0, 0); self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_2, 2); self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_3, 3); self.PlayerNumRadioManager:addItem(self.ui.Items.CheckBox_PlayerNum_4, 4); local defaultValue = self:getDefaultValue("playnum") or 4 local isfaststart = self:getDefaultValue("isfaststart") or 0 if isfaststart==1 then defaultValue = 0; end self.PlayerNumRadioManager:setDefault(defaultValue); end --[[/** * 初始化封顶选项 * @return */--]] function MJCreateRoomItem:initFengDingRadioManager () if not self.FengDingRadioManager then return end self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_5fan, 5); self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_6fan, 6); local defaultValue = self:getDefaultValue("limitfan") or 5 self.FengDingRadioManager:setDefault(defaultValue); end --[[/** * 初始化飘选项 * @return */--]] function MJCreateRoomItem:initPiaoRadioManager () if not self.PiaoRadioManager then return end self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_0, 0); -- 不飘 self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_1, 1); -- 随飘 self.PiaoRadioManager:addItem(self.ui.Items.CheckBox_Piao_2, 2); -- 定飘 local defaultValue = self:getDefaultValue("piaomode") or 0; self.PiaoRadioManager:setDefault(defaultValue); end --[[/** * 初始化听用选项 * @return */--]] function MJCreateRoomItem:initTingYongManager () if not self.TingYongRadioManager then return end self.TingYongRadioManager:addItem(self.ui.Items.CheckBox_tingyong_1, 4) self.TingYongRadioManager:addItem(self.ui.Items.CheckBox_tingyong_2, 8) self.TingYongRadioManager:addItem(self.ui.Items.CheckBox_tingyong_3, 11) local defaultValue = self:getDefaultValue("jingnum") or 8 self.TingYongRadioManager:setDefault(defaultValue); local function refreshTingYongWanFaItems(value) if value == 11 then self.ui.Items.Layout_TingYong_11:setVisible(true) else self.ui.Items.Layout_TingYong_11:setVisible(false) end self.ui.Items.Layout_1:requestDoLayout() self.ui.Items.Layout_1:doLayout() end self.TingYongRadioManager:setCallback(function (value) refreshTingYongWanFaItems(value) end) refreshTingYongWanFaItems(defaultValue) end --[[/** * 初始化11听用多玩法选项 * @return */--]] function MJCreateRoomItem:initTingYong11MoreCheckBoxManager() if not self.TingYong11MoreCheckBoxManager then return end local checkbox = self.TingYong11MoreCheckBoxManager checkbox:addItem(self.ui.Items.CheckBox_2FanQiHu, "fan2qihu", 0x01, 0) checkbox:addItem(self.ui.Items.CheckBox_Jia3Fan, "jia3fan", 0x02, 0) local jingelevenrule = self:getDefaultValue("jingelevenrule") or 0 local defaultValues = {} if jingelevenrule ~= 0 then if getNumBand(jingelevenrule, 0x01) > 0 then table.insert(defaultValues, "fan2qihu") end if getNumBand(jingelevenrule, 0x02) > 0 then table.insert(defaultValues, "jia3fan") end end checkbox:setDefault(defaultValues) end --[[/** * 初始化胡牌选项 * @return */--]] function MJCreateRoomItem:initHuPaiRadioManager () if not self.HuPaiRadioManager then return end self.HuPaiRadioManager:addItem(self.ui.Items.CheckBox_DianPaoHu, 2) self.HuPaiRadioManager:addItem(self.ui.Items.CheckBox_ZiMouHu, 1) local defaultValue = self:getDefaultValue("humode") or 1 self.HuPaiRadioManager:setDefault(defaultValue) end --[[/** * 初始化玩法选项 * @return */--]] function MJCreateRoomItem:initWanFaCheckBoxManager () if not self.WanFaCheckBoxManager then return end local checkbox = self.WanFaCheckBoxManager checkbox:addItem(self.ui.Items.CheckBox_DingQue, "dingque", 0x01, 0) checkbox:addItem(self.ui.Items.CheckBox_TianHuManGuan, "tianhumanguan", 0x02, 0) local specialrule = self:getDefaultValue("specialrule") or 0 local defaultValues = {} if specialrule ~= 0 then if getNumBand(specialrule, 0x01) > 0 then table.insert(defaultValues, "dingque") end if getNumBand(specialrule, 0x02) > 0 then table.insert(defaultValues, "tianhumanguan") end end checkbox:setDefault(defaultValues) end -- 获取结果 function MJCreateRoomItem:getRuleResult() local payMode = self.PayRadioManager:getResult() -- 房费 local playnum = self.PlayerNumRadioManager:getResult() -- 人数 local isfaststart = (playnum == 0) and 1 or 0 -- 是否快开 playnum = (playnum == 0) and 4 or playnum -- 人数 local limitfan = self.FengDingRadioManager:getResult() -- 封顶 local piaomode = self.PiaoRadioManager:getResult() -- 飘 local jingnum = self.TingYongRadioManager:getResult() -- 听用 -- 11听用规则 local tingyongmore = self.TingYong11MoreCheckBoxManager:getResult2() local jingelevenrule = 0 if jingnum == 11 then for k, v in pairs(tingyongmore or {}) do jingelevenrule = getNumOr(jingelevenrule, v); end else jingelevenrule = 0 end -- 胡牌模式 local humode = self.HuPaiRadioManager:getResult() -- 玩法规则 local specialrule = 0 local wanfaRule = self.WanFaCheckBoxManager:getResult2() for k, v in pairs(wanfaRule or {}) do specialrule = getNumOr(specialrule, v) end local other = self.otherCheckBoxManager:getResult2() local forbidProp = other["forbidProp"] local forbidVoice = other["forbidVoice"] self.defaultValus = { gamerule = 1, -- 使用的规则,这个与GameType一致 deductRule = payMode, -- 支付 playnum = playnum, -- 人数 limitfan = limitfan, -- 封顶(番数) piaomode = piaomode, -- 漂 jingnum = jingnum, -- 听用数 jingelevenrule = jingelevenrule, -- 11听用复选规则 humode = humode, -- 胡牌模式 specialrule = specialrule, -- 玩法规则 isfaststart = isfaststart, -- 是否快开 tingpai = 1, -- 听牌 baseMulti = self.curJFBS, forbidProp = forbidProp, forbidVoice = forbidVoice, }; -- 保存玩家的选择 self:saveDefaultValues() local strGameInfo = json.encode(self.defaultValus); return game_num, strGameInfo end return MJCreateRoomItem