|
- -- 快速成局界面
- local ZPRoomQuickStartView = class("ZPRoomQuickStartView", cc.UIView)
-
- local function getUserNameById(userId)
- local userInfo = app.room:getUserInfo(userId)
- if not userInfo then return end
- local userName = userInfo.nickname or tostring(userId)
-
- return userName
- end
-
- function ZPRoomQuickStartView:ctor(initiateUserId)
- ZPRoomQuickStartView.super.ctor(self);
- self.m_initiateUserId = initiateUserId
- self.itemList = {}
- end
-
- function ZPRoomQuickStartView:onEnter()
- ZPRoomQuickStartView.super.onEnter(self)
- local ui = loadUI("res/ui/ui_fangjian/ui_fangjian_quickstart.ui");
- self.ui = ui;
- self:addChild(ui);
-
- --谁申请快速开始
- local initiateUserName = getUserNameById(self.m_initiateUserId)
- initiateUserName = getSubStringNickname(initiateUserName,self.ui.Items.Text)
- self.ui.Items.Text:setText("["..initiateUserName.."]")
-
- -- 同意
- self.ui.Items.Button_1:registerClick(handler(self , self.onClickAgree))
-
- -- 拒绝
- self.ui.Items.Button_2:registerClick(handler(self , self.onClickRefuse))
-
-
- local layout = self.ui.Items.Layout_3
- layout:removeAllChildren()
-
- --桌子有坐下的人
- for nUserId, memberInfo in pairsByKeys(app.room.roomInfo.memberList) do
- local item = import("zp_base.luaScript.Views.Room.ZPRoomQuickStartItem"):new(nUserId, 0)
- layout:addChild(item.ui)
- self.itemList[nUserId] = item
- end
-
- self:bindEvent(app.room , "onQuickStartResponse" , handler(self , self.onQuickStartResponse));
- self:bindEvent(app.room , "onGameOverResponse" , handler(self , self.onGameOverResponse));
-
- self:updateButton()
-
- local nLeftTime = app.room.nleftStartGameTimeout
- local timer = nLeftTime or 60
- local nTotalTime = app.room.nStartGameToTalTime
- local totalTime = nTotalTime or 60
- if self.ui.Items.LoadingBar then
- self.ui.Items.LoadingBar:setPercent(timer/totalTime * 100)
- end
-
- self.ui.Items.Text_3:setString("")
- self.ui.Items.time:setText(tostring(totalTime))
- --self.ui.Items.time:setText(tostring(timer))--数字跟着倒计时
-
- self.loadingBarTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
- timer = timer - 1
- if timer < 0 then
- self:removeView()
- return
- end
- if tolua.isnull(self.ui.Items.Text_3) then
- if self.loadingBarTimer then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.loadingBarTimer)
- self.loadingBarTimer = nil
- end
- return
- end
- if timer <= 0 then
- self.ui.Items.Text_3:setText(tostring(0))--数字跟着倒计时
- else
- self.ui.Items.Text_3:setText(tostring(timer))--数字跟着倒计时
- end
- if self.ui.Items.LoadingBar then
- self.ui.Items.LoadingBar:setPercent(timer/totalTime * 100)
- end
- end,1.0,false)
- end
-
- function ZPRoomQuickStartView:updateButton()
- local myUserId = app.room.roomInfo.nUserId
- if (app.room.quickStartInfo[myUserId] and app.room.quickStartInfo[myUserId] ~= 0) or self.m_initiateUserId == myUserId then
- -- 我已经选择过了或者我是发起申请的那个
- self.ui.Items.Button_1:setVisible(false)
- self.ui.Items.Button_2:setVisible(false)
- else
- -- 我还没选择
- self.ui.Items.Button_1:setVisible(true)
- self.ui.Items.Button_2:setVisible(true)
- end
-
- if app.room.isOnLooker then
- self.ui.Items.Button_1:setVisible(false)
- self.ui.Items.Button_2:setVisible(false)
- end
- end
-
- -- 同意
- function ZPRoomQuickStartView:onClickAgree()
- app.room:requestQuickStart(2)
- end
-
- -- 拒绝
- function ZPRoomQuickStartView:onClickRefuse()
- app.room:requestQuickStart(3)
- end
-
- function ZPRoomQuickStartView:onQuickStartResponse(event)
- self:updateButton()
- for id,op in pairs(app.room.quickStartInfo) do
- local item = self.itemList[id]
- if item then
- item:updateStatus();
- end
- end
-
- -- 房间内的人全都回复过了
- local isReplyNum = 0
- local isNoRefuse = true
- for _, operateType in pairs(app.room.quickStartInfo) do
-
- if operateType == 1 or operateType == 2 or operateType == 3 then
- isReplyNum = isReplyNum + 1
- if operateType == 3 then
- isNoRefuse = false
- local refuseUserName = getUserNameById(_)--"~@&111"--
- --showTooltip(refuseUserName.."拒绝了立即开局!")
- self:runDelay(1, function()
- if not tolua.isnull(self) then
- self:removeView()
- end
- end )
- end
- end
- end
-
- if isReplyNum >= app.room:getActualPlayerNum() and isNoRefuse then
- if not tolua.isnull(self) then
- self:removeView()
- end
- end
- end
-
- function ZPRoomQuickStartView:onGameOverResponse(event)
- self:removeView()
- end
-
- function ZPRoomQuickStartView:removeView()
- if self.loadingBarTimer then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.loadingBarTimer)
- self.loadingBarTimer = nil
- end
- self:removeFromParent()
- end
-
- return ZPRoomQuickStartView;
|