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 CoinDuiHuan = class("CoinDuiHuan", cc.UIView) function CoinDuiHuan:ctor(gameID, level) CoinDuiHuan.super.ctor(self) self.gameID = gameID self.level = level; end function CoinDuiHuan:onEnter() CoinDuiHuan.super.onEnter(self) local ui = loadUI("res/ui/ui_coin/ui_exchange.ui") self.ui = ui self:addChild(ui) self.ui.Items.Button_close:registerClick(handler(self, self.onBtnCloseClicked)); self.ui.Items.Button_DuiHuan:registerClick(handler(self, self.onBtnDuiHuanClicked)); self:updateView() self:bindEvent(app.phpShop , "getShopInfoSuccessed" , handler(self , self.updateView)); self:bindEvent(app.phpShop , "exchangeCoinSuccess" , handler(self , self.onDuiHuanCoin)); end --- CoinDuiHuan:onBtnCloseClicked 点击关闭按钮 function CoinDuiHuan:onBtnCloseClicked () playBtnEffect() self:removeFromParent() end --- CoinDuiHuan:onBtnDuiHuanClicked 点击兑换按钮 function CoinDuiHuan:onBtnDuiHuanClicked () playBtnEffect() if self.id and self.price and self.number then CoinFunctions.exchangeCoinFromDiamond(self.id,self.price,self.number,true) else logD("self.id:",self.id) logD("self.price:",self.price) logD("self.number:",self.number) showTooltip("此次兑换失败!请在商店购买!") end end function CoinDuiHuan:updateView() if app.phpShop.shopData then local tt = {} for k,v in pairs(app.phpShop.shopData) do if tonumber(v.type) == STORE_TYPE.CHANGE_COIN then tt[v.order] = v; end end local gameData = CoinData.getInstance():getGameData(); if not gameData then logD("CoinDuiHuan:updateView", "金币场数据不存在"); return; end local gameCoinInfo = gameData.ruleList[tonumber(self.gameID)] if not gameCoinInfo then logD("CoinDuiHuan:updateView", "游戏金币场数据不存在"); return ; end local coin = nil; if gameCoinInfo[tostring(self.level)] then --当前场次最低金币数 coin = gameCoinInfo[tostring(self.level)].min_money end if not coin then return ; end for k,v in pairs(tt) do if coin <= v.number then local fileName = "ddStore_"..v.id..".png" local fullPath = cc.FileUtils:getInstance():getWritablePath()..fileName if cc.FileSystem:fileExists(fullPath) then local texture = loadTextureFromFile(fileName,false) self.ui.Items.ImageView_Coin:setTexture2(texture); end self.ui.Items.TextBMFont:setText("x"..v.number) self.ui.Items.Text_1:setText(v.price..PLN.CURRENCY_UNIT..PLN.CURRENCY) self.id = v.id; self.price = v.price; self.number = v.number; break end end else app.phpShop:getShopInfo(); end end function CoinDuiHuan:onDuiHuanCoin(data) if not data then return; end local response = data.response; local id = response.id local gold = response.gold --金币 local card = response.card --钻石 local coupons = response.coupons --礼券 local fileName = "res/ui/zy_dating/chongzhi/chongzhi_img_icon.png" local info = {} if gold and not coupons then --只有金币变化,说明是用钻石兑换金币 logD("CoinDuiHuan:onDuiHuanCoin zuanshi curJingbiNum = "..table.tostring(app.user.loginInfo.curJingbiNum)) if tonumber(response.lastCoinNum) > tonumber(gold) then info.coin = response.lastCoinNum - gold; else info.coin = gold - response.lastCoinNum; end app.user.loginInfo.curJingbiNum = gold elseif gold and coupons then --礼券和金币同时变化,说明是用礼券兑换了金币 logD("CoinDuiHuan:onDuiHuanCoin liquan curJingbiNum = "..table.tostring(app.user.loginInfo.curJingbiNum)) if tonumber(response.lastCoinNum) > tonumber(gold) then info.coin = response.lastCoinNum - gold; else info.coin = gold - response.lastCoinNum; end app.user.loginInfo.curJingbiNum = gold app.user.loginInfo.curLiquanNum = coupons elseif not gold and coupons then --礼券变化,但金币没变化,表示兑换的是钻石 logD("CoinDuiHuan:onDuiHuanCoin curCardNum = "..table.tostring(app.user.loginInfo.curCardNum)) fileName = "res/ui/zy_tongyong/zy_icon/icon_zuanshi.png" info.coupons = app.user.loginInfo.curLiquanNum - coupons; app.user.loginInfo.curLiquanNum = coupons info.card = card - response.lastCardNum end info.fileName = fileName local view = import("luaScript.Views.Coin.RoomJiangLi"):new(info); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) -- 刷新钻石和金币数量 app.user.loginInfo.curCardNum = card --如果是房间内,更新房间内数据 if app.room then app.coinProtocolPhp:requestCoinGameActivity() end self:removeFromParent() end return CoinDuiHuan