|
- -- local MJSelectRadioCompnent = require("Views.CreateRoom.Compnent.MJSelectRadioCompnent")
- -- local MJGroupCompnent = require("Views.CreateRoom.Compnent.MJGroupCompnent")
- -- local MJCheckBoxCompnent = require("Views.CreateRoom.Compnent.MJCheckBoxCompnent")
- -- local MJWanFa=MJFramework.ImportWanFa("MaJiang.MJWanFa")
- local CreateRoomItemBase=require("luaScript.Views.CreateRoom.CreateRoomItemBase")
-
- local MJCreateRoomItem=class("luzhouguiCreateRoomItem",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, "neijiangmj_room.json")
- local ui = loadUI("res/ui/ui_chuangjian/mj_createroom_neijiang.ui");
- self.ui = ui;
- self:addChild(ui);
-
- --房费
- self.PayRadioManager = import("luaScript.Tools.RadioManager"):new();
- --人数
- self.PlayCountRadioManager = import("luaScript.Tools.RadioManager"):new();
- -- 局数
- self.RoundNumRadioManager = import("luaScript.Tools.RadioManager"):new();
- --封顶
- self.FengDingRadioManager = import("luaScript.Tools.RadioManager"):new();
- --玩法
- self.WanFaRadioManager = import("luaScript.Tools.RadioManager"):new();
- --可选
- self.ExtendsionCheckBoxManager = import("luaScript.Tools.CheckBoxManager"):new();
- -- 豹子可选
- self.BaoZiRadioManager = 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
-
- --根据局数获取房费
- 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:onEnter()
- MJCreateRoomItem.super.onEnter(self)
-
- -- 整理不同局数对应的房卡消耗
- local payTypes={}
- local gameConfig = app.user:getGameConfig(GAME_IDS.NeiJiangMJ)--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
-
- self:initPayRadioManager();
- self:initPlayCountRadioManager();
- -- self:initRoundNumRadioManager();
- self:initFengDingRadioManager();
- self:initWanFaRadioManager();
- self:initExtendsionCheckBoxManager();
- self:initBaoZiRadioManager();
- self:initLayoutEvent()
- self:initOtherCheckBoxManager()
- self:initJiFenBeiShu()
- end
-
- -- 面板的点击事件,点击面板后,隐藏所有提示
- function MJCreateRoomItem:initLayoutEvent()
- self.ui.Items.Layout_1:registerClick(function()
- local buttons = {
- {buttonName = "Button_JFBS", tipsName = "ImageView_JFBS"},
- {buttonName = "Button_KSCJ", tipsName = "ImageView_KSCJ"},
- };
-
- -- 隐藏其他提示信息
- for k, v in ipairs(buttons) do
- local tipsNode = self.ui.Items[v.tipsName]
- tipsNode:setVisible(false)
- end
- 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: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:initPayRadioManager ( )
- if self.PayRadioManager then
- 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)
-
- --通知创建界面更新显示
- local function dispatchUpdateCost()
- app:dispatchEvent({name = "onChangePayMode"})
- end
- self.PayRadioManager:setCallback(dispatchUpdateCost);
-
- -- self:setDefaultTextColor(self.PayRadioManager,"Text_pay")
- end
- end
- --[[
- -- 初始化人数选项
- --]]
- function MJCreateRoomItem:initPlayCountRadioManager ( )
- if self.PlayCountRadioManager then
- self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_4, 0); -- 快速开局
- self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_3, 4); -- 满4人开
- self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_2, 3); -- 满3人开
- self.PlayCountRadioManager:addItem(self.ui.Items.CheckBox_playerCount_1, 2); -- 满2人开
-
- local defaultValue = self:getDefaultValue("playnum") or 0
- local isfaststart = self:getDefaultValue("isfaststart") or 1
-
- if isfaststart==1 then
- self.PlayCountRadioManager:setDefault(0);
- else
- self.PlayCountRadioManager:setDefault(defaultValue);
- end
- -- self:setDefaultTextColor(self.PlayCountRadioManager, "Text_player")
- -- self:updataTextColor(self.PlayCountRadioManager, "Text_player","radioBox",{0,4,3,2})
- end
-
- --快速成局说明
- self.ui.Items.ImageView_KSCJ:setVisible(false)
- self.ui.Items.Button_KSCJ:registerClick(function()
- self.ui.Items.ImageView_KSCJ:setVisible(not self.ui.Items.ImageView_KSCJ:isVisible())
- end)
- end
- --[[
- -- 初始化局数
- --]]
- function MJCreateRoomItem:initRoundNumRadioManager( )
- -- 玩家选择局数后,更新房卡消耗
- local function updateCost(gameRound)
- local costInfo = payTypes[gameRound]
- if costInfo then
- self.ui.Items.Text_FangZhu:setText(tostring(costInfo.requireCards or 0))
- self.ui.Items.Text_AAPay:setText(tostring(costInfo.requireCardsAA or 0))
- end
- end
-
- if self.RoundNumRadioManager then
- self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round4, 4); -- 4 局
- self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round8, 8); -- 8 局
- self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round12, 12); -- 12 局
- self.RoundNumRadioManager:addItem(self.ui.Items.CheckBox_Round16, 16); -- 16 局
-
- local defaultValue = self:getDefaultValue("totalgamenum") or 4;
-
- self.RoundNumRadioManager:setDefault(defaultValue);
-
- --self.RoundNumRadioManager:setCallback(updateCost);
- --updateCost(defaultValue)
- end
- end
- --[[
- -- 初始化封顶选项
- --]]
- function MJCreateRoomItem:initFengDingRadioManager ()
- -- 封顶
- if self.FengDingRadioManager then
- self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_Fan3, 3); -- 封顶3番
- self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_Fan4, 4); -- 封顶4番
- self.FengDingRadioManager:addItem(self.ui.Items.CheckBox_Fan5, 5); -- 封顶5番
-
- local default = self:getDefaultValue("limitfan") or 6
- self.FengDingRadioManager:setDefault(default)
-
- -- self:setDefaultTextColor(self.FengDingRadioManager,"Text_limit")
- -- self:updataTextColor(self.FengDingRadioManager,"Text_limit","radioBox",{3,4,5})
- end
- end
- --[[
- -- 初始化可选选项
- --]]
- function MJCreateRoomItem:initExtendsionCheckBoxManager ( )
- if self.ExtendsionCheckBoxManager then
- self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_BaoJiao, "BaoJiao", 0x0001, 0); -- 报叫
- self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_YiBanGao, "YiBanGao", 0x0100, 0); -- 一般高
- self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_BaoZi, "BaoZi", 1, 0); -- 豹子,前端的值,不传给后端
- self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_Piao, "Piao", 0x0080, 0); -- 飘
- self.ExtendsionCheckBoxManager:addItem(self.ui.Items.CheckBox_TingPai, "TingPai", 0x0200, 0); -- 听牌提示
-
- local selectedValue = {};
- local baojiaoValue = self:getDefaultValue("baojiao") or 0;
- if baojiaoValue > 0 then
- table.insert(selectedValue, "BaoJiao");
- end
-
- local yibangaoValue = self:getDefaultValue("yibangao") or 0;
- if yibangaoValue > 0 then
- table.insert(selectedValue, "YiBanGao");
- end
-
- local baoziValue = self:getDefaultValue("baozi") or 0;
- if baoziValue > 0 then
- table.insert(selectedValue, "BaoZi");
- end
- self.ui.Items.CheckBox_BaoZiExt1:setVisible(baoziValue > 0);
- self.ui.Items.CheckBox_BaoZiExt2:setVisible(baoziValue > 0);
-
- local piaoValue = self:getDefaultValue("piao") or 0;
- if piaoValue > 0 then
- table.insert(selectedValue, "Piao");
- end
-
- local tingpaiValue = self:getDefaultValue("tingpai") or 0;
- if tingpaiValue > 0 then
- table.insert(selectedValue, "TingPai");
- end
-
- self.ExtendsionCheckBoxManager:setDefault(selectedValue)
-
- self.ExtendsionCheckBoxManager:setCallback(function (value)
- local result = self.ExtendsionCheckBoxManager:getResult2();
- self.ui.Items.CheckBox_BaoZiExt1:setVisible(result["BaoZi"] > 0);
- self.ui.Items.CheckBox_BaoZiExt2:setVisible(result["BaoZi"] > 0);
- end);
-
- -- self:setDefaultTextColor(self.ExtendsionCheckBoxManager,"Text_gui")
- -- self:updataTextColor(self.ExtendsionCheckBoxManager,"Text_gui","checkBox",{0x0001,8,0x0002,12,12,0x0040,0x0080})
- end
- end
- --[[
- -- 初始化豹子扩展选项
- --]]
- function MJCreateRoomItem:initBaoZiRadioManager ()
- if self.BaoZiRadioManager then
- self.BaoZiRadioManager:addItem(self.ui.Items.CheckBox_BaoZiExt1, 0x0002); -- 骰子相同做豹子
- self.BaoZiRadioManager:addItem(self.ui.Items.CheckBox_BaoZiExt2, 0x0040); -- 骰子相加双数做豹子
-
- local defaultValue = self:getDefaultValue("baoziext") or 0
- self.BaoZiRadioManager:setDefault(defaultValue);
- end
- end
- --[[
- -- 初始化玩法选项
- --]]
- function MJCreateRoomItem:initWanFaRadioManager ( )
- if self.WanFaRadioManager then
- self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_ZiMoBuJia, 0); -- 自摸不加
- self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_ZiMoJiaFan, 1); -- 自摸加番
- self.WanFaRadioManager:addItem(self.ui.Items.CheckBox_ZiMoJiaDi, 2); -- 自摸加底
-
- local defaultValue = self:getDefaultValue("zimorule") or 0
- self.WanFaRadioManager:setDefault(defaultValue);
-
- -- self:setDefaultTextColor()
- -- self:updataTextColor(self.WanFaRadioManager,"","radioBox",{})
- end
- 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.WanFaRadioManager:getResult2()
- if result.baojiao == 1 then
- self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
- end
-
- if result.xiqian == 1 then
- self.ui.Items.Text_XiQian: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.WanFaRadioManager:getResult2()
- if result.baojiao == 1 then
- self.ui.Items.Text_BaoJiao:setTextColor(SELECT_COLOR)
- else
- self.ui.Items.Text_BaoJiao:setTextColor(NON_SELECT_COLOR)
- end
-
- if result.xiqian == 1 then
- self.ui.Items.Text_XiQian:setTextColor(SELECT_COLOR)
- else
- self.ui.Items.Text_XiQian:setTextColor(NON_SELECT_COLOR)
- end
- end
- end
-
- radio:setCallback(updataRadioTextColor);
- end
-
-
- function MJCreateRoomItem:getRuleResult()
- local payMode = self.PayRadioManager:getResult(); -- 支付模式
- local playnum = self.PlayCountRadioManager:getResult(); -- 玩牌人数, 0表示快速开局
- local isfaststart = playnum == 0 and 1 or 0; -- 是否快速开局
- playnum = playnum == 0 and 4 or playnum;
-
- local roundnum = self.RoundNumRadioManager:getResult(); -- 玩牌局数
- local fengding = self.FengDingRadioManager:getResult(); -- 封顶番数
- local wanfa = self.WanFaRadioManager:getResult(); -- 自摸加番
- local baoziext = self.BaoZiRadioManager:getResult(); -- 豹子扩展玩法
- local extData = self.ExtendsionCheckBoxManager:getResult2(); -- 可选玩法
- local specialrule = 0;
- for k, v in pairs(extData) do
- if v > 0 and k ~= "BaoZi" then
- specialrule = getNumOr(specialrule, v);
- end
- end
- if extData["BaoZi"] > 0 then
- specialrule = getNumOr(specialrule, baoziext);
- else
- baoziext = 0;
- end
-
- local other = self.otherCheckBoxManager:getResult2()
- local forbidProp = other["forbidProp"]
- local forbidVoice = other["forbidVoice"]
-
- self.defaultValus = {
- zimorule = wanfa,
- deductRule = payMode,
- playnum = playnum,
- -- totalgamenum = roundnum,
- limitfan = fengding,
- gamerule = 1, -- 玩法
- isfaststart = isfaststart,
- specialrule = specialrule,
- baojiao = extData["BaoJiao"],
- yibangao = extData["YiBanGao"],
- piao = extData["Piao"],
- baoziext = baoziext,
- baozi = extData["BaoZi"],
- tingpai = extData["TingPai"],
- baseMulti = self.curJFBS,
- forbidProp = forbidProp,
- forbidVoice = forbidVoice,
- };
-
- -- 保存玩家的选择
- self:saveDefaultValues()
-
- local strGameInfo = json.encode(self.defaultValus);
- return roundnum, strGameInfo
-
- end
-
-
- return MJCreateRoomItem
|