|
- local Functions = require("pk_erdoudizhu.luaScript.Functions_ERDouDiZhu")
-
- -- 房间设置界面
- local RoomPlayerView_ERDouDiZhu = class("RoomPlayerView_ERDouDiZhu", cc.UIView)
-
- function RoomPlayerView_ERDouDiZhu:ctor()
- RoomPlayerView_ERDouDiZhu.super.ctor(self)
- end
-
- function RoomPlayerView_ERDouDiZhu:onEnter()
- RoomPlayerView_ERDouDiZhu.super.onEnter(self)
- local ui = loadUI("pk_erdoudizhu/res/ui/ui_fangjian/doudizhu_ui_PlayerView.ui")
- self:addChild(ui)
- self.ui = ui
-
- --默认隐藏玩家头像
- for i = 1, 4 do
- local player = self.ui.Items["Layout_Player_" .. i]
- if player then
- player:setVisible(false)
- end
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:getPlayerData(type, viewId)
- local player = self.ui.Items["Layout_Player_" .. viewId]
-
- if player then
- if type == "sex" then
- return player.userInfo.sex
- end
- end
-
- return nil
- end
-
- --刷新玩家
- function RoomPlayerView_ERDouDiZhu:updatePlayer(playerInfo, viewId)
- if playerInfo then
- self:initPlayer(playerInfo, viewId)
- else
- for _,v in pairs(app.room.roomInfo.memberList) do
- self:initPlayer(v, app.room:getViewIdByUserId(v.nUserId))
- end
- end
- end
-
- --更新玩家信息
- function RoomPlayerView_ERDouDiZhu:initPlayer(playerInfo, viewId)
- logE("RoomPlayerView_ERDouDiZhu initPlayer viewId : " .. viewId)
- logE("RoomPlayerView_ERDouDiZhu initPlayer playerInfo : " .. table.tostring(playerInfo))
-
- local player = self.ui.Items["Layout_Player_" .. viewId]
- if player then
- player:setVisible(true)
- local userInfo = json.decode(playerInfo.userInfo)
-
- player.playerInfo = playerInfo
- player.userInfo = userInfo
-
- --头像
- local head = self.ui.Items["Image_Head_" .. viewId]
- setDefaultHeadImg(userInfo.sex, playerInfo.nUserId, head, head:getContentSize().width)
- setPlayerHeadImage(playerInfo.nUserId, userInfo.headimgurl, head)
-
- --名字
- local nickname = userInfo.nickname or "error"
- self.ui.Items["Text_Name_" .. viewId]:setText(nickname)
-
- --分数
- local nTotalScore = playerInfo.nTotalScore or 0
- self.ui.Items["Text_Score_" .. viewId]:setText(nTotalScore)
-
- --庄家
- local nBankerId = app.room.roomInfo.nBankerId or 0
- self.ui.Items["Image_Banker_" .. viewId]:setVisible(nBankerId == playerInfo.nUserId)
-
- --离线 (0:离线、1:在线)
- local nOnlineStatus = playerInfo.nOnlineStatus or 1
- self.ui.Items["Image_OffLine_" .. viewId]:setVisible(nOnlineStatus == 0)
- --头像变灰
- self:setHeadGreyEnabled(nOnlineStatus == 0, viewId)
-
- --准备 (0:未准备、1:已准备)
- local nPlayerFlag = playerInfo.nPlayerFlag or 0
- self.ui.Items["Image_Ready_" .. viewId]:setVisible(nPlayerFlag == 1)
-
- --加倍
- local askBei = playerInfo.askBei or 0
- self.ui.Items["Image_AskBei_" .. viewId]:setVisible(askBei == 1)
-
- --闹钟
- self.ui.Items["Image_Clock_" .. viewId]:setVisible(false)
-
- --请让我再想想
- self.ui.Items["Image_Pop_" .. viewId]:setVisible(false)
-
- -- 头像框
- self.ui.Items["Image_HeadMask_" .. viewId]:setVisible(false)
-
- -- 托管
- self.ui.Items['ImageView_tuoguan_' .. viewId]:setVisible(false)
-
- --剩余牌
- local leftNumText = self.ui.Items["Text_LeftNum_" .. viewId]
- local leftNumImage = self.ui.Items["Image_LeftNum_" .. viewId]
- if leftNumText then
- leftNumText:setVisible(false)
- end
- if leftNumImage then
- leftNumImage:setVisible(false)
- end
- end
- end
-
- --隐藏玩家
- function RoomPlayerView_ERDouDiZhu:hidePlayer(viewId)
- local player = self.ui.Items["Layout_Player_" .. viewId]
-
- logE("RoomPlayerView_ERDouDiZhu hidePlayer viewId : " .. viewId)
-
- if player then
- player:setVisible(false)
- end
- end
-
- --刷新分数
- function RoomPlayerView_ERDouDiZhu:updateScore(viewId, totalScore)
- local score = self.ui.Items["Text_Score_" .. viewId]
-
- logE("RoomPlayerView_ERDouDiZhu updateScore viewId : " .. viewId)
-
- if score then
- score:setText("" .. totalScore)
- end
- end
-
- --显隐剩余牌
- function RoomPlayerView_ERDouDiZhu:setLeftNumVisible(bVisible, viewId, num)
- --房间规则
- local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
-
- --是否是回放
- if app.room.roomInfo.isRecord then
- return
- end
-
- -- 剩余牌
- local isNotShowLeftNumCard = false
-
- logE("RoomPlayerView_ERDouDiZhu setReadyVisible bVisible : " .. (bVisible and 1 or 0))
- logE("RoomPlayerView_ERDouDiZhu setReadyVisible viewId : " .. (viewId and viewId or -1))
- logE("RoomPlayerView_ERDouDiZhu setReadyVisible num : " .. (num and num or -1))
-
- if not isNotShowLeftNumCard then
- -- 显示剩余牌
- if viewId == -1 then
- for i = 1, 4 do
- local leftNumText = self.ui.Items["Text_LeftNum_" .. i]
- local leftNumImage = self.ui.Items["Image_LeftNum_" .. i]
- if leftNumText then
- leftNumText:setVisible(bVisible)
- if bVisible then
- leftNumText:setText("" .. num)
- end
- end
- if leftNumImage then
- leftNumImage:setVisible(bVisible)
- end
- end
- else
- local leftNumText = self.ui.Items["Text_LeftNum_" .. viewId]
- local leftNumImage = self.ui.Items["Image_LeftNum_" .. viewId]
- if leftNumText then
- leftNumText:setVisible(bVisible)
- if bVisible then
- leftNumText:setText("" .. num)
- end
- end
- if leftNumImage then
- leftNumImage:setVisible(bVisible)
- end
- end
- end
-
- -- 显示闹钟
- if viewId == -1 then
- self:cleanAllBaoJing()
- else
- if num == 1 or num == 2 then
- self:showBaoJingAni(viewId)
- Functions.playLastNumVoice(num, self:getPlayerData('sex', viewId))
- else
- self:showBaoJingAni(viewId, true)
- end
- end
- end
-
- --显隐准备
- function RoomPlayerView_ERDouDiZhu:setReadyVisible(bVisible, viewId)
- local ready = self.ui.Items["Image_Ready_" .. viewId]
-
- logE("RoomPlayerView_ERDouDiZhu showReady viewId : " .. viewId)
-
- if ready then
- ready:setVisible(bVisible)
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:getChatViewPos()
- local headInfos = {}
- for i = 1, 4 do
- local head = self.ui.Items["Image_Head_" .. i]
- local player = self.ui.Items["Layout_Player_" .. i]
- if head and player then
- table.insert(headInfos, {headPos = cc.pAdd(cc.pAdd(player:getPosition(), head:getPosition()), cc.p(0, 0))})
- end
- end
- return headInfos
- end
-
- function RoomPlayerView_ERDouDiZhu:setOffLineVisible(bVisible, viewId)
- local offLine = self.ui.Items["Image_OffLine_" .. viewId]
- if offLine then
- offLine:setVisible(bVisible)
- --头像变灰
- self:setHeadGreyEnabled(bVisible, viewId)
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:setHeadGreyEnabled(bVisible, viewId)
- local head = self.ui.Items["Image_Head_" .. viewId]
- local headMask = self.ui.Items["Image_HeadMask_" .. viewId]
- if head and headMask then
- head:setGreyEnabled(bVisible)
- headMask:setGreyEnabled(bVisible)
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:bankerAni(viewId)
- local banker = self.ui.Items["Image_Banker_" .. viewId]
- if banker then
- banker:stopAllActions()
- banker:runAction(
- cc.Sequence:create(
- cc.ScaleTo(0, 2)
- )
- )
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:setBankerVisible(bVisible, viewId)
- local banker = self.ui.Items["Image_Banker_" .. viewId]
- if banker then
- banker:setVisible(bVisible)
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:setClockVisibel(bVisible, viewId, times, endFunc)
- local clock = self.ui.Items["Image_Clock_" .. viewId]
- if clock then
- clock:setVisible(bVisible)
- local imagePop = self.ui.Items["Image_Pop_" .. viewId]
- if imagePop then
- imagePop:setVisible(false)
- end
- local time = self.ui.Items["Text_Clock_" .. viewId]
- time:stopAllActions()
- if bVisible then
- local timesEx = times
- time:runAction(
- cc.RepeatForever:create(
- cc.Sequence:create(
- cc.CallFunc:create(function()
- time:setText("" .. timesEx)
- timesEx = timesEx - 1
- if timesEx < 5 then
- -- imagePop:setVisible(true)
- if timesEx < 0 then
- time:stopAllActions()
-
- if endFunc then
- endFunc(viewId)
- end
- end
- end
- end),
- cc.DelayTime:create(1.0)
- )
- )
- )
- end
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:setTipsVisible(tipsType, bVisible, viewId, data)
- --显示锚点设置
- local anchorPont = {
- [1] = cc.p(1, 0.5),
- [2] = cc.p(0.5, 0.5),
- [3] = cc.p(0, 0.5),
- [4] = cc.p(0.5, 0.5),
- }
-
- local tipsFunc = {}
-
- --叫分
- tipsFunc["tips_jiaofen"] = function(nodeParent)
- local tips = nodeParent["tips_jiaofen"]
- if tips then
- tips:removeFromParent()
- nodeParent["tips_jiaofen"] = nil
- end
- if bVisible then
- local tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_fen%d.png", data.askLoard))
- if tipsEx then
- tipsEx:setAnchorPoint(anchorPont[viewId])
- nodeParent["tips_jiaofen"] = tipsEx
- nodeParent:addChild(tipsEx)
- end
- end
- end
-
- -- 叫地主
- tipsFunc["tips_jiaodizhu"] = function(nodeParent)
- local tips = nodeParent["tips_jiaodizhu"]
- if tips then
- tips:removeFromParent()
- nodeParent["tips_jiaodizhu"] = nil
- end
- if bVisible then
- local tipsEx = nil
- if data.askLoard ~= 0 then
- tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_jiao.png"))
- else
- tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_fen0.png"))
- end
- if tipsEx then
- tipsEx:setAnchorPoint(anchorPont[viewId])
- nodeParent["tips_jiaodizhu"] = tipsEx
- nodeParent:addChild(tipsEx)
- end
- end
- end
-
- -- 抢地主
- tipsFunc["tips_qiangdizhu"] = function(nodeParent)
- local tips = nodeParent["tips_qiangdizhu"]
- if tips then
- tips:removeFromParent()
- nodeParent["tips_qiangdizhu"] = nil
- end
- if bVisible then
- local tipsEx = nil
- if data.opType ~= 0 then
- tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_qiang.png"))
- end
- if tipsEx then
- tipsEx:setAnchorPoint(anchorPont[viewId])
- nodeParent["tips_qiangdizhu"] = tipsEx
- nodeParent:addChild(tipsEx)
- end
- end
- end
-
- --加倍
- tipsFunc["tips_jiabei"] = function(nodeParent)
- local tips = nodeParent["tips_jiabei"]
- if tips then
- tips:removeFromParent()
- nodeParent["tips_jiabei"] = nil
- end
- if bVisible then
- local tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_bei%d.png", data.askBei))
- if tipsEx then
- tipsEx:setAnchorPoint(anchorPont[viewId])
- nodeParent["tips_jiabei"] = tipsEx
- nodeParent:addChild(tipsEx)
- end
- self:setAskBeiVisible(data.askBei == 1, viewId)
- end
- end
-
- --要不起,不出
- tipsFunc["tips_yaobuqi"] = function(nodeParent)
- local tips = nodeParent["tips_yaobuqi"]
- if tips then
- tips:removeFromParent()
- nodeParent["tips_yaobuqi"] = nil
- end
- if bVisible then
- local tipsEx = cc.Sprite:create(string.format("pk_erdoudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_tips_yaobuqi.png"))
- if tipsEx then
- tipsEx:setAnchorPoint(anchorPont[viewId])
- nodeParent["tips_yaobuqi"] = tipsEx
- nodeParent:addChild(tipsEx)
- end
- end
- end
-
- --显隐对应的提示
- local tipsNode = self.ui.Items["Layout_Tips_" .. viewId]
- if tipsNode then
- local tipsFuncEx = tipsFunc["" .. tipsType]
- if tipsFuncEx then
- tipsFuncEx(tipsNode)
- end
- end
- end
-
- -- 隐藏非传的内容文本
- function RoomPlayerView_ERDouDiZhu:setTipsVisibleExcept(tab, viewId)
- if not tab then
- tab = {}
- end
-
- local temp = {
- tips_jiaofen = true,
- tips_jiaodizhu = true,
- tips_qiangdizhu = true,
- tips_jiabei = true,
- tips_yaobuqi = true,
- }
-
- for i, v in pairs(tab) do
- temp[v] = false
- end
-
- for i, v in pairs(temp) do
- if v then
- self:setTipsVisible(i, false, viewId)
- end
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:setAskBeiVisible(bVisible, viewId)
- local askBei = self.ui.Items["Image_AskBei_" .. viewId]
- if askBei then
- askBei:setVisible(bVisible)
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:showBaoJingAni(viewId, clean)
- local nodeLayout = self.ui.Items['Layout_baojing_'..viewId]
- nodeLayout:removeAllChildren()
-
- if clean then
- return
- end
-
- --不需要报警器
- do
- return
- end
-
- --ani
- local img = cc.ImageView:createNode()
- img:loadTextureFromPlist("ddz_baojing_bg.png")
- nodeLayout:addChild(img)
- img:setPosition(cc.p(nodeLayout:getContentSize().width/2,nodeLayout:getContentSize().height/2))
-
- --light
- local light = cc.ImageView:createNode("ddz_baojing_bg.png")
- nodeLayout:addChild(light)
- light:setPosition(cc.p(nodeLayout:getContentSize().width/2,nodeLayout:getContentSize().height/2))
-
- local indexFace = 0;
- --每隔多少秒切换一张图片
- local everyFrame = 0.01
- local seq = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function ()
- indexFace = indexFace + 1
- if 0 < indexFace and indexFace <= 8 then
- local name = string.format("ddz_baojing_%d.png",indexFace)
- light:loadTextureFromPlist(name)
- else
- indexFace = 0
- end
- end))
- local act = cc.RepeatForever:create(seq)
- light:runAction(act)
-
- -- 经过几面后,移除警报动画
- local removeDelayTime = 1.5
- local function removeCallBack()
- nodeLayout:stopAllActions()
- nodeLayout:removeAllChildren()
- end
- schedule(nodeLayout, removeCallBack, removeDelayTime)
- end
-
- function RoomPlayerView_ERDouDiZhu:cleanAllBaoJing()
- for i = 1, 4 do
- local nodeLayout = self.ui.Items['Layout_baojing_'..i]
- nodeLayout:removeAllChildren()
- end
- end
-
- function RoomPlayerView_ERDouDiZhu:showTuoGuanByViewId(viewId, isShow)
- local nodeImg = self.ui.Items['ImageView_tuoguan_' .. viewId]
- if nodeImg then
- nodeImg:setVisible(isShow)
- end
- end
-
- return RoomPlayerView_ERDouDiZhu
|