|
- require("core.luaScript.Protocol.ProtocolHall")
- local CoinData = import("luaScript.Views.Coin.Data.CoinData");
- local CoinFunctions = import("core.luaScript.Views.Coin.Util.CoinFunctions")
- local CoinGameLogic = import("core.luaScript.Views.Coin.CoinGameLogic")
- local CoinEvents = import("luaScript.Views.Coin.Constant.CoinEvents");
-
- local RadioManager = import("luaScript.Tools.RadioManager");
-
- -- 主界面
- local CoinView = class("CoinView", cc.UIView)
-
- -- mGameId :游戏ID
-
- -- 当 mGameType == 0时,mGameId 表示游戏玩法
-
- function CoinView:ctor(mGameId, mGameRule)
- CoinView.super.ctor(self)
-
- self.mGameId = mGameId
- self.mGameRule = mGameRule
-
- self.curGameId = nil
- self.curGameRule = nil
-
- local ui = loadUI("res/ui/ui_coin/ui_coin_dating.ui")
- self.ui = ui
- self:addChild(ui)
-
- --默认不显示礼券说明框
- self.ui.Items.Layout_liquan_shuoming:setVisible(false)
-
- self.firstEnter = true
- end
-
- function CoinView:onEnter()
- CoinView.super.onEnter(self)
-
- self.ui.Items.ScrollView:hideAllBar()
- self.ui.Items.ScrollView_GameRule:hideAllBar()
- self.ui.Items.ScrollView_CoinGame:hideAllBar()
- self.ui.Items.Layout_Item:setVisible(false)
- self.ui.Items.CheckBox_Item:setVisible(false)
- self.ui.Items.Button_Jinbi:setVisible(false)
-
- --buton registerClick
- self.ui.Items.Button_Back:registerClick(handler(self, self.onClickClose))
-
- self.ui.Items.Button_Jinbi:registerClick(handler(self, self.onClickFreeCoin))
- self.ui.Items.Button_Fuli:registerClick(handler(self, self.onClickFuLi))
- self.ui.Items.Button_Fuli:setVisible(false)
-
- self.ui.Items.Text_1:setText("红包券是一种回馈玩家的福利,可直接提现或兑换"..PLN.CURRENCY.."。")
-
- self.ui.Items.ImageView_Card_Add:registerClick(
- function()
- self:onClickAdd(STORE_TYPE.BUY_ZUANSHI)
- end
- )
-
- -- by c.mj
- -- 房卡数量
- self.ui.Items.Text_Card:bind(
- app.user.loginInfo,
- "curCardNum",
- function()
- self.ui.Items.Text_Card:setString(tostring(app.user.loginInfo.curCardNum))
- end
- )
-
- self.ui.Items.ImageView_Gold_Add:registerClick(
- function()
- self:onClickAdd(STORE_TYPE.CHANGE_COIN)
- end
- )
-
- --金币
- self.ui.Items.Text_Gold:bind(
- app.user.loginInfo,
- "curJingbiNum",
- function()
- --超过1w的金币,后面显示文字
- local strCoin = CoinFunctions.getCoinDisplayText(app.user.loginInfo.curJingbiNum)
- self.ui.Items.Text_Gold:setString(strCoin)
- end
- )
-
- --礼券
- self.ui.Items.Button_liquan:registerClick(handler(self, self.onClickLiquan))
- self.ui.Items.Text_Liquan:bind(
- app.user.loginInfo,
- "curLiquanNum",
- function()
- --超过1w的金币,后面显示文字
- local strLiquan = CoinFunctions.getCoinDisplayText(app.user.loginInfo.curLiquanNum)
- self.ui.Items.Text_Liquan:setString(strLiquan)
- end
- )
- self.ui.Items.Layout_HongBao:setVisible(false)
- if app.config.ModuleConfig.IsSupportHongBaoKa and not isReviewVersion() then
- self.ui.Items.Layout_HongBao:setVisible(true)
- end
-
- self.ui.Items.Button_FastStart:registerClick(handler(self, self.onClickStart))
- self.ui.Items.Button_FastStart:setVisible(false)
-
- --点击非礼券说明的地方,隐藏礼券说明框
- self.ui.Items.Layout_1:registerClick(
- function()
- self.ui.Items.Layout_liquan_shuoming:setVisible(false)
- end
- )
-
- local gameData = CoinData.getInstance():getGameData();
- if gameData then
- self:initLeft()
- else
- CoinData.getInstance():requestGameServerConfig();
- end
-
- if app.config.ModuleConfig.IsSupportCoinFreeCoin then
- CoinData.getInstance():requestCoinGameActivity()
- end
-
- self.ui.Items.Layout_RightTop:requestDoLayout()
- self.ui.Items.Layout_RightTop:doLayout()
-
- self:onActivityRedPoint()
-
- self:bindEvent(app, CoinEvents.EVENT_RESPONSE_GAME_SERVER_CONFIG, handler(self, self.initLeft));
- self:bindEvent(app.coinProtocol, "onEnterCoinResponse", handler(self, self.onEnterCoinGameResponse))
- self:bindEvent(app,"onActivityRedPoint", handler(self, self.onActivityRedPoint))
-
- if isReviewVersion() then
- self.ui.Items.Button_Fuli:setVisible(false)
- self.ui.Items.Button_Jinbi:setVisible(false)
- end
- end
-
- function CoinView:initLeft()
- --显示快速开始
- self.ui.Items.Button_FastStart:setVisible(true)
- self.ruleIds = {}
- self.GameIds = {}
-
- local smallGameId = self.mGameId or -1
- local ruleList = CoinData.getInstance():getGameData().ruleList;
-
- if ruleList then
- for gameId, content in pairsByKeys(ruleList) do
- --先判断是否开启了金币场
- local gameConfig = getSubGameConfig(gameId);
- if gameConfig and gameConfig.bSingleGame then
- for gameRule,v in pairsByKeys(gameConfig.GameType) do
- if gameConfig and gameConfig.openCoinModeList then
- if gameConfig.openCoinModeList[gameRule] then --有开放这个玩法的金币场
- --存储游戏id
- table.insert(self.GameIds, tonumber(gameId) * 10000 + gameRule)
-
- if smallGameId == -1 then
- smallGameId = tonumber(gameId) * 10000 + gameRule
- end
-
- for gameRank,v in pairsByKeys(content) do
- local list = string.sub(gameRank,-1)
- local first = string.sub(gameRank,0,1)
- local gameRule = tonumber(list)
- first = tonumber(first)
- if gameRule then
- local isSame = false
- if not self.ruleIds[tonumber(gameId) * 10000 + gameRule] then
- self.ruleIds[tonumber(gameId) * 10000 + gameRule] = {}
- end
- for k,rule in ipairs(self.ruleIds[tonumber(gameId) * 10000 + gameRule]) do
- if rule == gameRule then
- isSame = true;
- break;
- end
- end
- if not isSame then
- table.insert(self.ruleIds[tonumber(gameId) * 10000 + gameRule],gameRule)
- end
- end
- end
- end
- else
- showTooltip("友情提示:openCoinModeList 未配置!")
- end
- end
- else
- --原来不改他
- if gameConfig and gameConfig.openCoinMode then
- --存储游戏id
- table.insert(self.GameIds, tonumber(gameId))
-
- if smallGameId == -1 then
- smallGameId = tonumber(gameId)
- end
-
- --过滤玩法,同一玩法可能有多个场次,但只保留一个玩法(下面的算法原来的人写应该是有问题的)
- for gameRank, v in pairsByKeys(content) do
- local list = string.sub(gameRank, -1)
- local gameRule = tonumber(list)
- if not self.ruleIds[tonumber(gameId)] then
- self.ruleIds[tonumber(gameId)] = {}
- end
-
- if self.ruleIds[tonumber(gameId)] and self.ruleIds[tonumber(gameId)][v.ruleID] ~= gameRule then
- table.insert(self.ruleIds[tonumber(gameId)], tonumber(gameRule))
- end
- end
- end
- end
-
- end
- end
-
- local gameConfig = getSubGameConfig(smallGameId);
- if gameConfig and gameConfig.bSingleGame then
- smallGameId = smallGameId * 10000 + self.mGameRule
- end
- self.curGameId = smallGameId
-
- self.gameRadioManager = nil
- self.gameRadioManager = RadioManager:new()
-
- self.ui.Items.Layout_Game:removeAllChildren()
-
- self.gameItems = {}
- for k, v in pairsByKeys(self.GameIds) do
- local realGameID = tonumber(v)
- local realGameRule = tonumber(v)
- if tonumber(v) > 10000 then
- realGameRule = math.floor(tonumber(v)%10000)
- realGameID = math.floor(tonumber(v)/10000)
- end
- local gameItem = self.ui.Items.CheckBox_Item:getCopied()
- gameItem:setVisible(true)
- gameItem.Items = getUIItems(gameItem)
- if gameItem then
- if smallGameId == tonumber(v) then
- self.curGameId = tonumber(v)
- end
- self.ui.Items.Layout_Game:addChild(gameItem)
- local nodeSelected = gameItem.Items.Layout_Sel
- local nodeUnSelected = gameItem.Items.Layout_UnSel
- local gameConfig = getSubGameConfig(realGameID)
- if gameConfig and gameConfig.bSingleGame then
- --nor
- local imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_nor.png", realGameID,realGameRule);
- gameItem.Items.ImageView_8:loadTexture(imgPath, 0);
- --sel
- imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_sel.png", realGameID,realGameRule);
- gameItem.Items.ImageView_5:loadTexture(imgPath, 0);
- else
- --nor
- local imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_nor.png", v);
- gameItem.Items.ImageView_8:loadTexture(imgPath, 0);
- --sel
- imgPath = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_sel.png", v);
- gameItem.Items.ImageView_5:loadTexture(imgPath, 0);
- end
- gameItem:setSelectedNode(nodeSelected, nodeUnSelected)
- gameItem:setSelectedState(false)
- self.gameRadioManager:addItem(gameItem, v)
- self.gameItems[v] = gameItem
- end
- end
-
- --设置默认选项
- self.gameRadioManager:setDefault(tonumber(smallGameId))
-
- self.gameRadioManager:setCallback(handler(self, self.onSelecteGame))
-
- --初始化右边
- self:initRight(smallGameId)
- end
-
- function CoinView:initRight(gameId)
- self.ruleRadioManager = nil
- self.ruleRadioManager = RadioManager:new()
- self.ui.Items.Layout_GameRule:removeAllChildren()
-
- self.ruleItems = {}
- local smallRuleId = self.mGameRule or -1
- if self.ruleIds[gameId] then
- for k, ruleID in pairsByKeys(self.ruleIds[gameId]) do
- local ruleItem = self.ui.Items.CheckBox_Rule:getCopied()
- ruleItem:setVisible(true)
- ruleItem.Items = getUIItems(ruleItem)
- if ruleItem then
- self.ui.Items.Layout_GameRule:addChild(ruleItem)
-
- local nodeSelected = ruleItem.Items.Layout_Rule_Sel
- local nodeUnSelected = ruleItem.Items.Layout_Rule_UnSel
-
- local id = tonumber(gameId)
- if id > 10000 then
- id = math.floor(id /10000)
- end
- --nor
- local norImgName = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_nor.png", id, tonumber(ruleID))
- ruleItem.Items.ImageView_12:loadTexture(norImgName, 0)
- --sel
- local selImgName = string.format("res/ui/zy_coin/game_title/jinbichang_img_%d_%d_sel.png", id, ruleID)
- ruleItem.Items.ImageView_11:loadTexture(selImgName, 0)
-
- ruleItem:setSelectedNode(nodeSelected, nodeUnSelected)
- ruleItem:setSelectedState(false)
- self.ruleRadioManager:addItem(ruleItem, tonumber(ruleID))
- self.ruleItems[tonumber(ruleID)] = ruleItem
-
- if smallRuleId == -1 then
- smallRuleId = tonumber(ruleID)
- end
- end
- end
- end
-
- self.curGameRule = -1
-
- self.ruleRadioManager:setCallback(handler(self, self.onSelecteRule))
- --设置默认选项
- self.ruleRadioManager:setDefault(tonumber(self.ruleIds[gameId][smallRuleId]))
-
- self.ui.Items.CheckBox_Item:setVisible(false)
- self.ui.Items.CheckBox_Rule:setVisible(false)
- self.ui.Items.Layout_Game:requestDoLayout()
- self.ui.Items.Layout_Game:doLayout()
- end
-
- function CoinView:onSelecteGame(gameId)
- --点击的是当前已选中的,不做处理
- if gameId == self.curGameId then
- return
- end
-
- self.curGameId = nil
-
- if self.curGameId and self.gameItems[self.curGameId] then
- self.gameItems[self.curGameId]:setSelectedState(false)
- end
-
- self.curGameId = gameId
-
- --初始化右边
- self:initRight(self.curGameId)
-
- if self.curGameId and self.gameItems[self.curGameId] then
- self.gameItems[self.curGameId]:setSelectedState(true)
- end
- end
-
- function CoinView:onSelecteRule(ruleId)
- --点击的是当前已选中的,不做处理
- if self.curGameRule == ruleId then
- return
- end
-
- if self.firstEnter then
- self.firstEnter = false
- else
- playBtnTagEffect()
- end
- --rule永远是真实的rule,gameID是有可能存在大于10000的gameID
- self:onSelecteGameRule(self.curGameId, ruleId)
- end
-
- function CoinView:onSelecteGameRule(gameId, gameRule)
- if gameId > 10000 then
- gameId = math.floor(gameId/10000)
- end
- self.curGameId = gameId
- self.curGameRule = gameRule
-
- self.ui.Items.ScrollView_CoinGame:removeAllChildren()
- local index = 0
- local ruleList = CoinData.getInstance():getGameData().ruleList or {};
- if ruleList[tonumber(gameId)] then
- for rulelevel, v in pairsByKeys(ruleList[tonumber(gameId)]) do
- local rankType = self.ui.Items.Layout_Item:getCopied()
- rankType.Items = getUIItems(rankType)
- --先隐藏该图标
- rankType.Items.ImageView_9:setVisible(false)
- local first = string.sub(rulelevel, 0, 1)
- local second = string.sub(rulelevel, -1)
- first = tonumber(first)
- second = tonumber(second)
- if second == tonumber(gameRule) then
- --修改场次背景图,level表示每个场次,例:10-初级场 20-中级场
- local levelImg = string.format("res/ui/zy_coin/dating/jinbichang_btn_level_%d0.png", first)
- rankType.Items.ImageView_Level:loadTexture(levelImg, 0)
-
- --礼券
- local liquanNum = ""
- if v.extra_info and v.extra_info.desc then
- liquanNum = v.extra_info.desc
- end
- rankType.Items.Text_liquan:setText(liquanNum)
-
- --礼券tip动画
- if not tolua.isnull(self.imgAction) then
- app.mainScene:stopAction(self.imgAction)
- end
- self.imgAction = nil
-
- local function fontAction(idx)
- local seq =
- cc.Sequence:create(
- cc.ScaleTo:create(0.16, 0.8),
- cc.ScaleTo:create(0.16, 1),
- cc.ScaleTo:create(0.16, 0.8),
- cc.ScaleTo:create(0.16, 1),
- cc.ScaleTo:create(0.16, 0.8),
- cc.ScaleTo:create(0.16, 1),
- cc.DelayTime:create(0.4 + idx),
- cc.CallFunc:create(
- function()
- idx = idx + 1
- if idx == 3 then
- idx = 0
- end
-
- local img = self.ui.Items.ScrollView_CoinGame:getChildByTag(idx)
- if img then
- img.Items.ImageView_9:runAction(fontAction(idx))
- end
- end
- )
- )
-
- self.imgAction = nil
-
- return seq
- end
-
- self.imgAction = rankType.Items.ImageView_9:runAction(fontAction(index))
-
- --底分
- rankType.Items.Text_Fen:setText(tostring(v.base_chip))
-
- --入场人数
- rankType.Items.Text_Ren:setText(tostring(v.cnt))
-
- --最低消费(金币达到此数才允许进入此场)
- rankType.Items.Text_Jinbi:setText(tostring(v.min_money) .. "准入")
-
- rankType.Items.ImageView_Level:registerClick(
- function()
- playBtnEffect()
- if
- not app.subGameManager:isInstaller(tonumber(self.curGameId)) or
- app.subGameManager:isNeedUpdate(tonumber(self.curGameId))
- then
- requestDownloadSubGame(
- tonumber(self.curGameId),
- function()
- showTooltip("下载完成")
- end,
- true
- )
- else
- CoinGameLogic.requestEnterCoinGame(self.curGameId, self.curGameRule, rulelevel, v.min_money)
- end
- end
- )
-
- rankType:setTag(index)
-
- index = index + 1
-
- self.ui.Items.ScrollView_CoinGame:addChild(rankType)
- end
- end
- end
-
- self.ui.Items.Layout_Game:requestDoLayout()
- self.ui.Items.Layout_Game:doLayout()
-
- local width = self.ui.Items.Layout_Item:getContentSize().width
- local height = self.ui.Items.Layout_Item:getContentSize().height
- self.ui.Items.ScrollView_CoinGame:setInnerContainerSize(cc.size(width * index, height))
- self.ui.Items.ScrollView_CoinGame:requestDoLayout()
- self.ui.Items.ScrollView_CoinGame:doLayout()
- end
-
- function CoinView:onClickClose()
- playBtnCloseEffect()
- self:removeFromParent()
- end
-
- function CoinView:onClickStart()
- playBtnEffect()
- if
- not app.subGameManager:isInstaller(tonumber(self.curGameId)) or
- app.subGameManager:isNeedUpdate(tonumber(self.curGameId))
- then
- requestDownloadSubGame(
- tonumber(self.curGameId),
- function()
- showTooltip("下载完成")
- end,
- true
- )
- else
- CoinGameLogic.requestEnterCoinGame(self.curGameId, self.curGameRule)
- end
- end
-
- function CoinView:onClickFuLi()
- playBtnEffect()
- showTooltip("即将上线,敬请期待!")
- end
-
- function CoinView:onClickAdd(goodType)
- playBtnEffect()
- local view = import("luaScript.Views.Main.RechargeView"):new(goodType)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
-
-
- --礼券说明
- function CoinView:onClickLiquan()
- playBtnEffect()
- self.ui.Items.Layout_liquan_shuoming:setVisible(not self.ui.Items.Layout_liquan_shuoming:isVisible())
- end
- --- CoinView:onEnterCoinGameResponse 进入金币场回复
- -- @param data = {
- -- response = {
- -- ret = 0
- -- }
- -- }
- function CoinView:onEnterCoinGameResponse (data)
- CoinGameLogic.onEnterCoinGameResponse(data);
- end
-
- function CoinView:onClickFreeCoin()
- playBtnEffect()
- if app.config.ModuleConfig.IsSupportCoinFreeCoin then
- app.msgManager:removeMsg("gold",ACTIVITY_REDPOINT.COIN_GAME_FREE_GOLD)
- self.ui.Items.ImageView_FreeCoin_Tip:setVisible(false)
- local view = import("luaScript.Views.Coin.Views.CoinFreeCoin"):new()
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- showTooltip("开发中")
- end
- end
-
- function CoinView:onActivityRedPoint(event)
- local response = app.php.activityRedPoint
- if not response then
- return;
- end
- response = response.gold
- local ret1 = response[ACTIVITY_REDPOINT.COIN_GAME_FULI] == 1
- local ret2 = response[ACTIVITY_REDPOINT.COIN_GAME_FREE_GOLD] == 1
-
- self.ui.Items.ImageView_FuLi_Tip:setVisible(ret1)
- self.ui.Items.ImageView_FreeCoin_Tip:setVisible(ret2)
- end
-
- return CoinView
|