|
- -- 房间设置界面
- local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
- local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
- local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
-
- local ZPRoomPlayerView = class("ZPRoomPlayerView", cc.UIView)
-
- function ZPRoomPlayerView:ctor()
- ZPRoomPlayerView.super.ctor(self);
- end
-
- function ZPRoomPlayerView:loadUI()
- local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_PlayerView.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function ZPRoomPlayerView:onEnter()
- ZPRoomPlayerView.super.onEnter(self)
-
- self:loadUI()
-
- --离线时间
- self.offLineTime = {}
- self.offLineTime[1] = 0
- self.offLineTime[2] = 0
- self.offLineTime[3] = 0
- self.offLineTime[4] = 0
- self.clockTime = 9
- self.clockTimeView = 0--闹钟所在的viewid
- --定时器
- if not self.Time then
-
- self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
- for i=1,4 do
- self.offLineTime[i] = self.offLineTime[i] + 1
- if self.offLineTime[i] > 300 then--大于5分钟,恒定显示5分钟
- self.offLineTime[i] = 300
- end
- local time = os.date("%M:%S",self.offLineTime[i])
- if self.allNodes[i] and self.allNodes[i].offLineTime then
- self.allNodes[i].offLineTime:setText(time)
- end
- end
- self.clockTime = self.clockTime - 1
- if self.clockTime < 0 then
- self.clockTime = 0
- elseif self.clockTime == 0 then
- if self.clockTimeView and self.offLineTime[self.clockTimeView] then
- --self:setNoOpTime(true,self.clockTimeView)
- end
- end
-
- self:setClockTime(self.clockTime)
- end,1.0,false)
- end
-
- self:initPlayerNodes()
- self:initChatComponent()
- ZPFuc.loadSpriteFromFile("zp_base/res/ui/zy_fangjian/anim_bao.plist")
- end
-
- function ZPRoomPlayerView:onExit()
- ZPRoomPlayerView.super.onExit(self)
- --关闭定时器
- if self.Time then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
- end
- end
-
- function ZPRoomPlayerView:initPlayerNodes()
- -- 玩家节点名称模板
- local names =
- {
- player = "Layout_player_%d", -- 头像绿圈根节点
- head = "ImageView_head_%d", -- 头像
- headBoarder = "ImageView_head_border_%d", --头像边
- name = "Text_Name_%d", -- 名字
- score = "TextBMFont_Score_%d", -- 总分数
- banker = "ImageView_banker_%d", -- 庄家
- owner = "ImageView_owner_%d", --房主
- readyState = "ImageView_ready_%d", -- 准备
- headInfo = "Layout_headInfo_%d", --个人信息点击触发框
- offLine = "ImageView_offLine_%d", --离线标志
- --其他节点
- tip = "ImageView_tip_%d", --提示操作图
- huxi = "TextBMFont_huxi_%d", --胡息
- clock = "ImageView_clock_%d", --闹钟
- txtClocl = "TextBMFont_clock_%d", --闹钟时间
- bao = "ImageView_bao_%d", --爆
- offLineTime = "Text_offLineTime_%d", --离线时间
- offLineTimeBg = "ImageView_txkYY_%d", --离线时间背景
- leftCardBg = "ImageView_LeftCardBg_%d", --剩余手牌背景
- leftCardNum = "TextBMFont_LeftCardNum_%d", --剩余手牌数量
- tuoguan = "ImageView_tuoguan_%d", --托管标志
- }
- self.allNodes = {}
- self.headSize = {}
- for i = 1,ZPDef.GameMaxPlayer do
- local nodes = {}
- --玩家根节点
- local namePlayer = string.format(names.player,i)
- local nodePlayer = self.ui.Items[namePlayer]
- nodes.player = nodePlayer
-
- --头像
- local nameHead = string.format(names.head,i)
- local nodeHead = self.ui.Items[nameHead]
- nodes.head = nodeHead
- nodeHead:setTouchEnabled(true)
- nodeHead:registerClick(function()
- self:onClickHead(i)
- end)
-
- local headBoarder = string.format(names.headBoarder,i)
- local nodeheadBoarder = self.ui.Items[headBoarder]
- nodes.headBoarder = nodeheadBoarder
-
- -- 需要记录头像的原始尺寸
- if not self.headSize.width then
- self.headSize.width = nodeHead:getContentSize().width
- self.headSize.height = nodeHead:getContentSize().height
- end
-
- --昵称
- local nickName = string.format(names.name,i)
- local nodeName = self.ui.Items[nickName]
- nodes.name = nodeName
- nodeName:setText("")
-
- --总分
- local nickScore = string.format(names.score,i)
- local nodeScore = self.ui.Items[nickScore]
- nodes.score = nodeScore
-
- --庄家
- local nameBanker = string.format(names.banker,i)
- local nodeBanker = self.ui.Items[nameBanker]
- nodes.banker = nodeBanker
- nodes.banker.pos = nodeBanker:getPosition()
-
- --房主
- local nameOwner = string.format(names.owner,i)
- local nodeOwner = self.ui.Items[nameOwner]
- nodes.owner = nodeOwner
- nodes.owner.pos = nodeOwner:getPosition()
-
- --准备
- local nameReadyState = string.format(names.readyState,i)
- local nodeReadyState = self.ui.Items[nameReadyState]
- nodes.readyState = nodeReadyState
-
- --头像信息
- local headInfo = string.format(names.headInfo,i)
- local nodeheadInfo = self.ui.Items[headInfo]
- nodes.headInfo = nodeheadInfo
-
- --离线信息
- local offLine = string.format(names.offLine,i)
- local nodeoffLine = self.ui.Items[offLine]
- nodes.offLine = nodeoffLine
-
- --tip
- local nameTip = string.format(names.tip,i)
- local nodeTip = self.ui.Items[nameTip]
- nodes.tip = nodeTip
-
- --胡息
- local nameHuxi = string.format(names.huxi,i)
- local nodeHuxi = self.ui.Items[nameHuxi]
- nodes.huxi = nodeHuxi
-
- --爆
- local nameBao = string.format(names.bao,i)
- local nodeBao = self.ui.Items[nameBao]
- nodes.bao = nodeBao
-
- --闹钟
- local nameClock = string.format(names.clock,i)
- local nodeClock = self.ui.Items[nameClock]
- nodes.clock = nodeClock
- --闹钟时间
- local nametxtClock = string.format(names.txtClocl,i)
- local nodetxtClock = self.ui.Items[nametxtClock]
- nodes.txtclock = nodetxtClock
-
- --离线时间
- local nameoffLineTime = string.format(names.offLineTime,i)
- local nodeoffLineTime = self.ui.Items[nameoffLineTime]
- nodes.offLineTime = nodeoffLineTime
-
- --离线时间背景
- local nameoffLineTimeBg = string.format(names.offLineTimeBg,i)
- local nodeoffLineTimeBg = self.ui.Items[nameoffLineTimeBg]
- nodes.offLineTimeBg = nodeoffLineTimeBg
- nodes.offLineTimeBg:setVisible(false)
-
- --剩余手牌背景
- local nameleftCardBg = string.format(names.leftCardBg,i)
- local nodeleftCardBg = self.ui.Items[nameleftCardBg]
- nodes.leftCardBg = nodeleftCardBg
-
- --剩余手牌数量
- local nameleftCardNum = string.format(names.leftCardNum,i)
- local nodeleftCardNum = self.ui.Items[nameleftCardNum]
- nodes.leftCardNum = nodeleftCardNum
-
- --托管状态
- local nametuoguan = string.format(names.tuoguan,i)
- local nodetuoguan = self.ui.Items[nametuoguan]
- nodes.tuoguan = nodetuoguan
-
- self.allNodes[i] = nodes
- end
-
- self:setAllClockVisible(false)
- self:setOwnerVisible()
- self:stopAndHideBaoAnim()
- self:setXiaoJiaFlagVis(false)
- self:hideLeftCard()--隐藏剩余牌
- --小家不显示胡数
- self.ui.Items.ImageView_hushu_2:setVisible(false)
- self.ui.Items.TextBMFont_huxi_2:setVisible(false)
- end
- ---
- -- 初始化聊天窗口
- -- @return
- --
- function ZPRoomPlayerView:initChatComponent()
- if self.chatComponentView and not tolua.isnull(self.chatComponentView) then
- return
- end
-
- local heads = {}
- for i = 1, ZPDef.GameMaxPlayer do
- heads[i] = self.allNodes[i].head
- end
-
- self.chatComponentView = import("luaScript.Views.Room.RoomChatComponentView"):new(heads, ZPDef.ChatTxt, nil)
- local voiceEnable = tonumber(loadUserInfo("voiceEnable")) or 1
- local propEnable = tonumber(loadUserInfo("propEnable")) or 1
- self.chatComponentView:setVoiceEnabled(voiceEnable==1)
- self.chatComponentView:setPropEnabled(propEnable==1)
- self:addChild(self.chatComponentView)
- end
-
- --设置小家标志显示
- function ZPRoomPlayerView:setXiaoJiaFlagVis(vis)
- self.ui.Items.ImageView_xiaojia:setVisible(vis)
- end
-
- --设置胡息归0
- function ZPRoomPlayerView:setHuXizero()
- for i = 1,ZPDef.GameMaxPlayer do
- if self.allNodes[i] and self.allNodes[i].huxi then
- self.allNodes[i].huxi:setText("0")
- end
- end
- end
-
- --初始化飘分按钮文字和飘分背景显示
- function ZPRoomPlayerView:initPlayerPiaoFenByRule()
- for i = 1,ZPDef.GameMaxPlayer do
- if self.allNodes[i] and self.allNodes[i].piaofenBg then
- self.allNodes[i].piaofenBg:setVisible(false)
- end
- end
- end
-
- --设置某个玩家飘分
- function ZPRoomPlayerView:setPlayerPiaoFen(viewId,strScore)
- if self.allNodes[viewId] and self.allNodes[viewId].piaofen then
- self.allNodes[viewId].piaofen:setText(tostring(strScore).."分")
- end
- end
-
- --设置某个玩家胡息
- function ZPRoomPlayerView:setPlayerHuXi(viewId,huxi)
- if self.allNodes[viewId] and self.allNodes[viewId].huxi then
- self.allNodes[viewId].huxi:setText(tostring(huxi))
- end
- end
-
- --设置某个玩家分数
- function ZPRoomPlayerView:setPlayerScore(viewId,strScore)
- if self.allNodes[viewId] and self.allNodes[viewId].score then
- self.allNodes[viewId].score:setText(tostring(strScore))
- end
- end
-
- --设置准备状态按钮
- function ZPRoomPlayerView:setReadyStateVisible(bVisible)
- for i = 1,ZPDef.GameMaxPlayer do
- self.allNodes[i].readyState:setVisible(bVisible)
- end
- end
-
- --设置某个玩家准备状态显示
- function ZPRoomPlayerView:setPlayerReadyState(viewId,bVisible)
- if self.allNodes[viewId] and self.allNodes[viewId].readyState then
- self.allNodes[viewId].readyState:setVisible(bVisible)
- end
- end
-
- --隐藏庄家
- function ZPRoomPlayerView:setBankerVisible()
- for i = 1,ZPDef.GameMaxPlayer do
- self.allNodes[i].banker:setVisible(false)
- end
- end
-
- --设置某个庄家Visible
- function ZPRoomPlayerView:setPlayerBankerVisible(viewId,bVisible)
- if self.allNodes[viewId] then
- self.allNodes[viewId].banker:setVisible(bVisible)
- return true
- end
- return false
- end
-
- --隐藏房主
- function ZPRoomPlayerView:setOwnerVisible()
- for i = 1,ZPDef.GameMaxPlayer do
- self.allNodes[i].owner:setVisible(false)
- end
- end
-
- --设置某个房主Visible
- function ZPRoomPlayerView:setPlayerOwnerVisible(viewId,bVisible)
- if self.allNodes[viewId] then
- self.allNodes[viewId].owner:setVisible(bVisible)
- return true
- end
- return false
- end
-
- --隐藏提示
- function ZPRoomPlayerView:setOperatorTipVisible(bVisible)
- for i = 1,ZPDef.GameMaxPlayer do
- self.allNodes[i].tip:setVisible(bVisible)
- end
- end
-
- --隐藏玩家
- function ZPRoomPlayerView:setPlayerVisible(bVisible)
- for i = 1,ZPDef.GameMaxPlayer do
- self.allNodes[i].player:setVisible(bVisible)
- end
- end
-
- --隐藏离线
- function ZPRoomPlayerView:setOffLine(bVisible)
- for i = 1,ZPDef.GameMaxPlayer do
- self.allNodes[i].offLine:setVisible(bVisible)
- end
- end
-
- --隐藏离线
- function ZPRoomPlayerView:setPlayerOffLine(bVisible,viewId)
- --[[if not viewId or viewId > ZPDef.GameMaxPlayer or not self.allNodes[viewId] then
- return
- end--]]
- if viewId and self.allNodes[viewId] then
- self.allNodes[viewId].offLine:setVisible(bVisible)
- --头像变灰
- self.allNodes[viewId].head:setGreyEnabled(bVisible)
- self.allNodes[viewId].headBoarder:setGreyEnabled(bVisible)
- if app.room.offLineTime and next(app.room.offLineTime) ~= nil then
- local nUserId = app.room:getUserIdByViewId(viewId)
- if app.room.offLineTime[nUserId] then
- self.offLineTime[viewId] = app.room.offLineTime[nUserId]
- else
- self.offLineTime[viewId] = 0
- end
- else
- self.offLineTime[viewId] = 0
- end
- if app.gameId == GAME_IDS.luzhouDaEr then--暂时泸州大贰加倒计时
- self.allNodes[viewId].offLineTimeBg:setVisible(bVisible)
- else
- self.allNodes[viewId].offLineTimeBg:setVisible(false)
- end
- end
- end
- --设置用户没有操作的时间
- function ZPRoomPlayerView:setNoOpTime(bVisible,viewId)
- if true then--app.gameId ~= GAME_IDS.luzhouDaEr then
- return
- end
- if viewId and self.allNodes[viewId] then
- if app.room.offLineTime and next(app.room.offLineTime) ~= nil then
- local nUserId = app.room:getUserIdByViewId(viewId)
- if app.room.offLineTime[nUserId] then
- self.offLineTime[viewId] = app.room.offLineTime[nUserId]
- else
- self.offLineTime[viewId] = 0
- end
- else
- self.offLineTime[viewId] = 0
- end
- if app.gameId == GAME_IDS.luzhouDaEr then--暂时泸州大贰加倒计时
- local time = os.date("%M:%S",self.offLineTime[viewId]) or "00:00"
- self.allNodes[viewId].offLineTime:setText(time)
- self.allNodes[viewId].offLineTimeBg:setVisible(bVisible)
- else
- self.allNodes[viewId].offLineTimeBg:setVisible(false)
- end
- end
- end
-
- --用户行为提示
- function ZPRoomPlayerView:showOperatorTip(viewId,mType)
- local tip = self.allNodes[viewId].tip
- local time = 1.3
- tip:setVisible(true)
-
- local count = 0
- if mType == ZPDef.OpType.OP_TYPE_CANCEL then
- tip:loadTextureFromPlist(ZPDef.TipFile.GUO)
- elseif mType == ZPDef.OpType.OP_TYPE_ANWEI then
- tip:loadTextureFromPlist(ZPDef.TipFile.ANWEI)
- elseif mType == ZPDef.OpType.OP_TYPE_CHI then
- tip:loadTextureFromPlist(ZPDef.TipFile.CHI)
- elseif mType == ZPDef.OpType.OP_TYPE_BI then
- tip:loadTextureFromPlist(ZPDef.TipFile.BIPAI)
- elseif mType == ZPDef.OpType.OP_TYPE_PENG then
- tip:loadTextureFromPlist(ZPDef.TipFile.PENG)
- elseif mType == ZPDef.OpType.OP_TYPE_MINGWEI then
- tip:loadTextureFromPlist(ZPDef.TipFile.MINGWEI)
- elseif mType == ZPDef.OpType.OP_TYPE_PAO then
- tip:loadTextureFromPlist(ZPDef.TipFile.ZHAO)
- elseif mType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
- --tip:setVisible(false)
- tip:loadTextureFromPlist(ZPDef.TipFile.ZHAO)
- elseif mType == ZPDef.OpType.OP_TYPE_TI then
- tip:loadTextureFromPlist(ZPDef.TipFile.LONG)
- elseif mType == ZPDef.OpType.OP_TYPE_HU then
- time = 2.0
- if app.room.roomInfo.huType and app.room.roomInfo.huType >= 0 then
- local name = string.format(ZPDef.TipFile.HU,app.room.roomInfo.huType)
- tip:loadTextureFromPlist(name)
- end
- elseif mType == -55 then--单独处理爆牌动画
- tip:loadTextureFromPlist(ZPDef.TipFile.BAO)
- end
- --音效
- local userInfo=app.room:getUserInfo(app.user.loginInfo.uid)
- if userInfo then
- ZPSound.PlayOperateSound(userInfo.sex,mType)
- end
-
- tip:setScale(3.0)
- local seq = cc.Sequence:create(cc.ScaleTo:create(0.2,1),cc.DelayTime:create(time),cc.CallFunc:create(function ()
- tip:setVisible(false)
- end))
- tip:runAction(seq)
-
- end
-
- -- 更新玩家基本信息 : 昵称、头像
- -- index :是玩家展示出来的座位号
- function ZPRoomPlayerView:updatePlayerInfo(index)
- logE("ZPRoomView:updatePlayerInfo() index = ", index)
-
- local nodes = self.allNodes[index]
- if not nodes then return end
- local nUserId = app.room.seatShowList[index]
- local roomInfo = app.room.roomInfo
- local memberInfo = app.room.roomInfo.memberList[nUserId]
- if nUserId and app.room:checkUserIDIsInTable(nUserId) then--memberInfo and memberInfo.userInfo then
- nodes.player:setVisible(true)
- local userInfo = json.decode(memberInfo.userInfo)
- if not userInfo then
- return
- end
-
- -- 玩家名字
- local nickname = userInfo.nickname
- nickname = getSubStringNickname(nickname)
- nodes.name:setText(tostring(nickname))
- nodes.score:setText(tostring(memberInfo.nTotalMoney))
- -- 玩家头像
- local nodeHead = nodes.head;
- --先设置默认头像
- local width = nodeHead:getContentSize().width
- setPlayerHeadImage(nUserId, userInfo.headimgurl, nodeHead)
-
- if app.room.offLineUid[tonumber(nUserId)] or (memberInfo.nOnlineStatus and memberInfo.nOnlineStatus~=1) then
- self:setPlayerOffLine(true,index)
- else
- self:setPlayerOffLine(false,index)
- end
- else
- nodes.player:setVisible(false)
- end
- end
-
- function ZPRoomPlayerView:getPlayerPosByViewId(view)
- if self.allNodes[view] and self.allNodes[view].player then
- return self.allNodes[view].player:getPosition()
- end
- end
-
- function ZPRoomPlayerView:stopAndHideBaoAnim()
- for i=1,4 do
- if self.allNodes[i] and self.allNodes[i].bao then
- self.allNodes[i].bao:setVisible(false)
- self.allNodes[i].bao:removeAllChildren()
- end
- end
- end
-
- function ZPRoomPlayerView:playBaoAnim(view)
- if self.allNodes[view] and self.allNodes[view].bao then
- self.allNodes[view].bao:setVisible(true)
- -- 加载第一张图片
- local nodeImage = cc.ImageView:createNode()
- nodeImage:loadTexture(string.format("anim_bao_%d",1))
- self.allNodes[view].bao:addChild(nodeImage)
- local baoSize = self.allNodes[view].bao:getContentSize()
- nodeImage:setPosition(cc.p(baoSize.width/2-1,baoSize.height/2-2))
-
- -- 循环修改图片
- local everyFrame = 0.1
- local indexFace = 0
- local indexMax = 7
- local action1 = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
- indexFace = indexFace + 1
- if 0 < indexFace and indexFace <= indexMax then
- else
- indexFace = 1
- end
- local name = string.format("anim_bao_%d.png",indexFace)
- if not tolua.isnull(nodeImage) then
- nodeImage:loadTexture(name, cc.TextureResType.plistType)
- end
- end))
- local action2 = cc.Repeat:create(action1, indexMax)
- nodeImage:stopAllActions()
- --nodeImage:runAction(action2)
- nodeImage:runAction(cc.RepeatForever:create(action2));
- nodeImage:setVisible(true)
- end
- end
-
- --设置所有闹钟隐藏
- function ZPRoomPlayerView:setAllClockVisible(vis)
- for i=1,4 do
- if self.allNodes[i] and self.allNodes[i].clock then
- self.allNodes[i].clock:setVisible(vis)
- end
- end
- end
- --设置闹钟可见
- function ZPRoomPlayerView:setPClockVisible(viewId,bVisible)
- self.clockTime = 9
- self.clockTimeView = viewId
- self:setClockTime(self.clockTime)
- self:setAllClockVisible(false)
- if self.allNodes[viewId] and self.allNodes[viewId].clock then
- self.allNodes[viewId].clock:setVisible(bVisible)
- end
- end
- --重置闹钟时间
- function ZPRoomPlayerView:reSetClockTime(viewId)
- if viewId == self.clockTimeView then
- self.clockTime = 9
- end
- end
- --设置闹钟时间
- function ZPRoomPlayerView:setClockTime(num)
- for i=1,4 do
- if self.allNodes[i] and self.allNodes[i].txtclock then
- self.allNodes[i].txtclock:setText(num)
- end
- end
- end
-
- --隐藏剩余牌
- function ZPRoomPlayerView:hideLeftCard()
- for i=1,4 do
- if self.allNodes[i] and self.allNodes[i].leftCardBg then
- self.allNodes[i].leftCardBg:setVisible(false)
- self.allNodes[i].leftCardNum:setVisible(false)
- end
- end
- end
-
- --设置显示剩余手牌
- function ZPRoomPlayerView:setLeftCardNum(viewId,bVisible,num)
- if app.gameId ~= GAME_IDS.luzhouDaEr then return end
- if bVisible and bVisible == true then
- if self.allNodes[viewId] and self.allNodes[viewId].leftCardNum then
- self.allNodes[viewId].leftCardBg:setVisible(bVisible)
- self.allNodes[viewId].leftCardNum:setVisible(bVisible)
- self.allNodes[viewId].leftCardNum:setText(num)
- end
- end
- end
-
- --修改剩余首牌显示
- function ZPRoomPlayerView:changeLeftCardNum(viewId,num)--在原来的基础上改变num张牌
- if self.allNodes[viewId] and self.allNodes[viewId].leftCardNum then
- local cardnum = self.allNodes[viewId].leftCardNum:getString()
- self.allNodes[viewId].leftCardNum:setText(tonumber(cardnum)+num)
- end
- end
-
- --托管标签状态显示
- function ZPRoomPlayerView:setTuoGuanFlagVisible(flag)
- flag = flag or false
- for i = 1,4 do
- if self.allNodes[i] and self.allNodes[i].tuoguan then
- self.allNodes[i].tuoguan:setVisible(flag)
- end
- end
- end
-
- function ZPRoomPlayerView:showTuoGuanByViewId(viewId,bVisible)
- if not viewId then return end
- bVisible = bVisible or false
- if self.allNodes[viewId] and self.allNodes[viewId].tuoguan then
- self.allNodes[viewId].tuoguan:setVisible(bVisible)
- end
- end
-
- function ZPRoomPlayerView:onClickHead(index)
- playBtnEffect()
- local nUserId = app.room.seatShowList[index]
- local memberInfo = app.room.roomInfo.memberList[nUserId]
- if memberInfo then
- local view = import("luaScript.Views.Room.RoomPlayerInfoViewNew"):new(nUserId, memberInfo.userInfo)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view, 0, true)
- end
- end
-
- return ZPRoomPlayerView;
|