local MatchDefined = require("luaScript.Views.Match.Constant.MatchDefined") local MatchEvents = require("luaScript.Views.Match.Constant.MatchEvents") -- 主界面 local MatchMainView = class("MatchMainView", cc.UIView) function MatchMainView:ctor() MatchMainView.super.ctor(self) self.MatchRoomWaitView = "zp_hsb.luaScript.Views.Match.yxhsbMatchRoomWaitView" end function MatchMainView:onEnter() MatchMainView.super.onEnter(self) -- setShowCountAll(true) local ui = loadUI("res/ui/ui_match/ui_match_hall.ui") self.ui = ui self:addChild(ui) --初始列表 -- self.ui.Items.List_Match:setItemModel(self.ui.Items.Item_Match) -- self.ui.Items.List_Match:removeAllChildren() self.ui.Items.List_Match:getVBar():setVisible(false) self.ui.Items.List_Tag:setItemModel(self.ui.Items.Item_Tag) self.ui.Items.List_Tag:removeAllChildren() self.ui.Items.List_Tag:getVBar():setVisible(false) self.ui.Items.List_Tag:pushBackDefaultItem() self.ui.Items.Button_Back:registerClick(function() playBtnCloseEffect() self:removeFromParent() end) -- self.ui.Items.Button_Rule:registerClick(function() -- playBtnEffect() -- -- local view = import("Views.Match.MatchRule"):new() -- -- view:setAnchorPoint(cc.p(0.5, 0.5)) -- -- app:showWaitDialog(view) -- -- app:gotoView(view) -- end) -- self.ui.Items.Button_RenZheng:registerClick(function() -- playBtnEffect() -- local view = import("Views.Main.MainShiMingRenZheng"):new() -- view:setAnchorPoint(cc.p(0.5, 0.5)) -- app:showWaitDialog(view) -- end) -- self.ui.Items.Button_RenZheng:setVisible(false) -- self.ui.Items.Button_Rule:setVisible(false) --比赛场 -- self.ui.Items.Button_Match:setVisible(false) self.ui.Items.Button_Match:registerClick(handler(self , self.onClickMatch)) -- 玩家信息 self:initPlayerInfo() app.match:getListRequest(); self:bindAllEvent(); end -- function MatchMainView:onExit() -- MatchMainView.super.onExit(self) -- setShowCountAll(false) -- end function MatchMainView:bindAllEvent() self:bindEvent(app.match , MatchEvents.GET_LIST , handler(self , self.onGetListResponse)); self:bindEvent(app.match , MatchEvents.SIGN_UP_SUCCESS , handler(self , self.onSignUpSuccessResponse)); end function MatchMainView:initPlayerInfo() log("app.user.userInfo = ", app.user.userInfo) local userInfo = json.decode(app.user.userInfo); local id = tonumber(app.user.loginInfo.uid) or 0 self.ui.Items.Text_ID:setText(string.format("ID:%06d", id)) local nickname = getSubStringNickname(userInfo.nickname,self.ui.Items.Text_MingZi) self.ui.Items.Text_MingZi:setText(nickname or tostring("未知昵称")) -- 房卡数量 self.ui.Items.diamondNum:bind(app.user.loginInfo, "curCardNum", function() self.ui.Items.diamondNum:setString(tostring(app.user.loginInfo.curCardNum)) end ) local nodeHead = self.ui.Items.Image_TouXiang; local head = {} head.width = nodeHead:getContentSize().width head.height = nodeHead:getContentSize().height setPlayerHeadImage(app.user.loginInfo.uid, userInfo.headimgurl, nodeHead) end function MatchMainView:onGetListResponse() self.ui.Items.List_Match:removeAllChildren() local matchList = app.match.matchInfo.matchList or {} local function checkHasCash(configInfo) local hasCash = false; if configInfo and configInfo.rewardInfo then local data = json.decode(configInfo.rewardInfo) if data and data.rewards then for k,v in pairs(data.rewards) do for kk,vv in pairs(v) do if vv.type == 100 then hasCash = true end end end end end return hasCash; end logD("matchList:",table.tostring(matchList)) for k,v in pairs(matchList) do local hasCash = checkHasCash(v); if not isIOSReviewVersion() or not hasCash then local item=loadUI("res/ui/ui_match/ui_match_item.ui") self.ui.Items.List_Match:pushBackCustomItem(item) item.Items.Text_Title:setString(v.matchName) item.Items.Text_Info:setString(v.matchDes) if v.matchType==MatchDefined.MATCH_TYPE.FULL_OPENING then item.Items.Text_Tip:setString("人满开赛")--setVisible(false) item.Items.ImageView_Time_Bg:setVisible(false) item.Items.ImageView_Text:loadTexture("match_main_text_bm.png",cc.TextureResType.plistType) item.Items.Text_Tip:setPositionY(60) end local rewardInfo = json.decode(v.rewardInfo) for _,rewards in pairs(rewardInfo.rewards) do for _,reward in pairs(rewards) do if reward.type==MatchDefined.CURRENCY_TYPE.Money then item.Items.ImageView_Icon:loadTexture("match_main_img_hong_bao.png",cc.TextureResType.plistType) break end end end -- match_main_img_hong_bao item.Items.Text_Player_Num:setString(v.signUpCnt.."/"..v.maxMatchCnt) local cost = json.decode(v.signupInfo) local costStr="" for n,signInfos in pairs(cost.signInfo) do for _,info in pairs(signInfos) do if info.type==13 then costStr=costStr.."房卡x"..info.value elseif info.type==1 then costStr=costStr.."金币x"..info.value end end if n~=#cost.signInfo then costStr=costStr.." 或 " end end item.Items.Text_Cost:setString(costStr) item:registerClick(function() playBtnEffect() app.match.matchInfo.matchIndex=v.matchIndex local rewardInfo = json.decode(v.rewardInfo) app.match.matchInfo.rewards = rewardInfo.rewards local view = import("luaScript.Views.Match.MatchInfo"):new(v) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end) item.Items.Button_BaoMing:registerClick(function() playBtnEffect() local function btnCallbackOk() app.match:signUp(v); -- self:removeParent() -- runInNextFrame(function() -- local view = import("Views.Match.MatchRoomWaitView"):new() -- app:gotoView(view) -- end) end local function btnCallbackCancel() end if not app.subGameManager:isInstaller(tonumber(v.gameId)) or app.subGameManager:isNeedUpdate(tonumber(v.gameId)) then --未下载时提示下载 requestDownloadSubGame(tonumber(v.gameId), function () showTooltip("下载完成") end, true) return; end showConfirmDialog("确定花费["..costStr.."]报名?",btnCallbackOk,btnCallbackCancel) end) end end end function MatchMainView:onClickMatch() playBtnEffect() -- local view = import("Views.Match.MatchMainView"):new(); -- view:setAnchorPoint(cc.p(0.5, 0.5)) -- app:showWaitDialog(view) local view = import("luaScript.Views.Match.MatchRecord"):new(); view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function MatchMainView:onSignUpSuccessResponse() if self.MatchRoomWaitView then local view = import(self.MatchRoomWaitView):new() app:gotoView(view) end end -- -- 房间获取结果 -- function MatchMainView:onGetRoomListResponse(data) -- local response = data.response -- local roomList = response.roomList -- local aMax = table.nums(roomList) -- if table.nums(roomList) > 0 then -- self:updateRoomList(roomList) -- elseif table.nums(roomList) == 0 then -- self.ui.Items.mScrollView:removeAllChildren() -- self.ui.Items.mScrollView:getInnerContainer():setAutoSize(true) -- self.ui.Items.mScrollView:jumpToTopOnSizeChanged() -- end -- end return MatchMainView