|
- local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
- local MJRoomPlayerView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomPlayerView")
- local yibinmajiangRoomPlayerView = class("yibinmajiangRoomPlayerView", MJRoomPlayerView)
-
- function yibinmajiangRoomPlayerView:ctor()
- yibinmajiangRoomPlayerView.super.ctor(self);
- end
-
- function yibinmajiangRoomPlayerView:loadUI()
- local ui = loadUI("mj_yibinmajiang/res/ui_fangjian/mj_yibinmajiang_playerView.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function yibinmajiangRoomPlayerView:onEnter()
- self:loadUI()
-
- self:init()
- end
-
-
- function yibinmajiangRoomPlayerView:init()
- local names =
- {
- player = "Layout_player_%d", -- 头像绿圈根节点
- head = "ImageView_head_%d", -- 头像
- -- headBoarder = "ImageView_head_border_%d", --头像边
- name = "Text_Name_%d", -- 名字
- score = "Text_Score_%d", -- 总分数
- banker = "ImageView_banker_%d", -- 庄家
- readyState = "ImageView_ready_%d", -- 准备
- headInfo = "Layout_PlayerInfo_%d", --个人信息点击触发框
- offLine = "ImageView_offLine_%d", --离线标志
- --其他节点
- arrow = "ImageView_arrow_%d", -- 指示器
- tip = "ImageView_tip_%d", --提示操作图
- huxi = "Text_huxi_%d", --胡息
- qihu = "ImageView_qihu_%d", --弃胡
- -- bao = "ImageView_bao_%d", --爆
- piao = "ImageView_piao_%d", --飘
- -- baoAnim = "Layout_baoAnim_%d", --爆牌特效
- hu = "ImageView_hu_%d", --胡牌
- viewOrder = "ImageView_ViewId_%d", -- 座位
- dingque = "ImageView_DingQue_%d", -- 定缺
- hutype = 'ImageView_huType_%d', -- 胡牌类型
- huindex = 'ImageView_huIndex_%d', -- 胡牌顺序
- }
-
- self.allNodes = {}
- self.headSize = {}
- for i = 1,4 do--LHQ_GAME_CONST.LHQ_GAME_CONST_PLAYER do
- local nodes = {}
- --玩家根节点
- local namePlayer = string.format(names.player,i)
- local nodePlayer = self.ui.Items[namePlayer]
- -- nodePlayer:setVisible(false)
- 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)
-
- -- 需要记录头像的原始尺寸
- 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]
- nodeBanker:setVisible(false)
- nodes.banker = nodeBanker
-
- --准备
- 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
-
- --指示器
- -- local nameArrow = string.format(names.arrow,i)
- -- local nodeArrow = self.ui.Items[nameArrow]
- -- nodes.arrow = nodeArrow
-
- --tip
- local nameTip = string.format(names.tip,i)
- local nodeTip = self.ui.Items[nameTip]
- nodes.tip = nodeTip
-
- --huxi
- local nameHuxi = string.format(names.huxi,i)
- local nodeHuxi = self.ui.Items[nameHuxi]
- nodes.huxi = nodeHuxi
-
- --弃胡
- local nameQiHu = string.format(names.qihu,i)
- local nodeQiHu = self.ui.Items[nameQiHu]
- nodeQiHu:setVisible(false)
- nodes.qihu = nodeQiHu
-
- --飘
- local namePiao = string.format(names.piao,i)
- local nodePiao = self.ui.Items[namePiao]
- nodePiao:setVisible(false)
- nodes.piao = nodePiao
-
- --爆
- -- local nameBao = string.format(names.bao,i)
- -- local nodeBao = self.ui.Items[nameBao]
- -- nodeBao:setVisible(false)
- -- nodes.bao = nodeBao
-
- --胡
- local nameHu = string.format(names.hu,i)
- local nodeHu = self.ui.Items[nameHu]
- nodeHu:setVisible(false)
- nodes.hu = nodeHu
-
- --座位
- local nameViewOrder = string.format(names.viewOrder, i);
- local nodeViewOrder = self.ui.Items[nameViewOrder]
- nodes.viewOrder = nodeViewOrder
-
- -- 定缺
- local nameDingQue = string.format(names.dingque, i);
- local nodeDingQue = self.ui.Items[nameDingQue]
- nodes.dingque = nodeDingQue
-
- -- 胡牌类型
- local nameHuType = string.format(names.hutype, i);
- local nodeHuType = self.ui.Items[nameHuType]
- nodes.hutype = nodeHuType
-
- -- 胡牌顺序
- local nameHuIndex = string.format(names.huindex, i);
- local nodeHuIndex = self.ui.Items[nameHuIndex]
- nodes.huindex = nodeHuIndex
-
- --报牌动画
- -- local nameBaoAnim = string.format(names.baoAnim, i);
- -- local nodeBaoAnim = self.ui.Items[nameBaoAnim];
- -- nodeBaoAnim:setVisible(false);
- -- nodeBaoAnim:setScale(0.9);
- -- nodes.baoAnim = nodeBaoAnim;
-
- self.allNodes[i] = nodes
- end
-
- self:initChatComponent()
-
- self.PropAniManager = import("luaScript.Tools.PropAniPlayer"):new(self.ui)
-
- --发送道具
- self:bindEvent(app.room,"showProp" , handler(self , self.showProp));
-
- self:bindEvent(app , MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable))
- end
-
- function yibinmajiangRoomPlayerView:initChatComponent()
- yibinmajiangRoomPlayerView.super.initChatComponent(self);
-
- local voiceEnable = tonumber(loadUserInfo("voiceEnable")) or 1
- local propEnable = tonumber(loadUserInfo("propEnable")) or 1
- self.chatComponentView:setVoiceEnabled(voiceEnable==1)
- self.chatComponentView:setPropEnabled(propEnable==1)
- end
-
- function yibinmajiangRoomPlayerView:onChangeChatEnable()
- if not self.chatComponentView or tolua.isnull(self.chatComponentView) then
- return
- end
- local voiceEnable = tonumber(loadUserInfo("voiceEnable")) or 1
- local propEnable = tonumber(loadUserInfo("propEnable")) or 1
- self.chatComponentView:setVoiceEnabled(voiceEnable==1)
- self.chatComponentView:setPropEnabled(propEnable==1)
- end
-
- function yibinmajiangRoomPlayerView:updatePlayerInfo( index )
- yibinmajiangRoomPlayerView.super.updatePlayerInfo(self, index);
-
- local nodes = self.allNodes[index];
- local nUserId = app.room.seatShowList[index];
- local roomInfo = app.room.roomInfo;
- local memberInfo = app.room.roomInfo.memberList[nUserId];
- if not memberInfo then
- return ;
- end
-
- local seat = memberInfo.nSeatId;
-
- -- 更新座位
- if nodes.viewOrder then
- nodes.viewOrder:loadTexture(string.format("mj_yibinmajiang/res/zy_fangjian/player/yibinmajiang_seat_%d.png", (seat + 1)), 0);
- end
- end
-
- -- 显示飘标志
- function yibinmajiangRoomPlayerView:showPiao(viewId,bVisible)
- if self.allNodes[viewId] and self.allNodes[viewId].piao then
- self.allNodes[viewId].piao:setVisible(bVisible)
- else
- logE("yibinmajiangRoomPlayerView:showPiao ->viewId is not exit"..viewId)
- end
- end
-
- -- 清理所有飘标志
- function yibinmajiangRoomPlayerView:clearAllPiao()
- for i=1,4 do
- if self.allNodes[i] and self.allNodes[i].piao then
- self.allNodes[i].piao:setVisible(false)
- end
- end
- end
-
- function yibinmajiangRoomPlayerView:showHu( viewId, bVisible )
- if self.allNodes[viewId] and self.allNodes[viewId].hu then
- self.allNodes[viewId].hu:setVisible(bVisible);
- end
-
- if bVisible and self.allNodes[viewId] and self.allNodes[viewId].bao then
- self.allNodes[viewId].bao:setVisible(false);
- end
- end
-
- -- 显示桌面胡标记(1胡2胡3胡)
- function yibinmajiangRoomPlayerView:showHuFlag(viewId, bVisible)
- local userId = app.room:getUserIdByViewId(viewId)
- local memberInfo = app.room.roomInfo.memberList[userId]
- local huType = memberInfo.huType
- local huIndex = memberInfo.huIndex
- if huType > 0 and huIndex > 0 then
- -- 胡牌类型
- local huTypeTable = {
- [MJDefine.MJGameHuType.HU_ZIMO] = 'mj/res/ui/zy_fangjian/operate/mj_effect_zimo.png',
- [MJDefine.MJGameHuType.HU_DIANPAO] = 'mj/res/ui/zy_fangjian/operate/mj_effect_jiepao.png',
- [MJDefine.MJGameHuType.HU_QIANGGANG] = 'mj/res/ui/zy_fangjian/operate/mj_effect_hupai.png',
- }
-
- local huTypeImg = 'mj/res/ui/zy_fangjian/operate/mj_effect_hupai.png'
- huTypeImg = huTypeTable[huType] and huTypeTable[huType] or huTypeImg
- self.allNodes[viewId].hutype:loadTexture(huTypeImg)
-
- -- 胡牌顺序
- local huIndexTable = {
- [1] = 'mj/res/ui/zy_fangjian/operate/mj_effect_num1.png',
- [2] = 'mj/res/ui/zy_fangjian/operate/mj_effect_num2.png',
- [3] = 'mj/res/ui/zy_fangjian/operate/mj_effect_num3.png',
- }
-
- local huIndexImg = 'mj/res/ui/zy_fangjian/operate/mj_effect_num1.png'
- huIndexImg = huIndexTable[huIndex] and huIndexTable[huIndex] or huIndexImg
- self.allNodes[viewId].huindex:loadTexture(huIndexImg)
-
- -- index是type的子类,所以直接显示父类即可
- self.allNodes[viewId].hutype:setVisible(true)
- end
- end
-
- function yibinmajiangRoomPlayerView:clearHu( )
- for i=1,4 do
- if self.allNodes[i] and self.allNodes[i].hu then
- self.allNodes[i].hu:setVisible(false)
- self.allNodes[i].hutype:setVisible(false)
- end
- end
- end
-
- function yibinmajiangRoomPlayerView:refreshPlayerScore (scoreInfo)
- for k, v in ipairs(scoreInfo) do
- if self.allNodes[v.viewId] and self.allNodes[v.viewId].score then
- self.allNodes[v.viewId].score:setString(v.totalScore);
- end
- end
-
- end
-
- -- 获得定缺图的世界坐标
- function yibinmajiangRoomPlayerView:getDingQuePos()
- local temp = {}
- for i = 1, 4 do
- if self.allNodes[i] and self.allNodes[i].dingque then
- local pos = self.allNodes[i].dingque:getPosition()
- local worldPos = self.allNodes[i].dingque:getParent():convertToWorldSpace(self.allNodes[i].dingque:getPosition())
- temp[i] = worldPos
- end
- end
-
- return temp
- end
-
- -- 显示定缺
- function yibinmajiangRoomPlayerView:showDingQue(viewId, queValue)
- -- 4个一起显示
- -- for i = 1, 4 do
- -- if self.allNodes[i] and self.allNodes[i].dingque then
- -- self.allNodes[i].dingque:setVisible(true)
- -- end
- -- end
-
- -- 单独显示
- if self.allNodes[viewId] and self.allNodes[viewId].dingque then
- local temp = {
- [0] = 'wan',
- [1] = 'tong',
- [2] = 'tiao',
- }
-
- local texturePath = string.format('mj_yibinmajiang/res/zy_fangjian/player/yibinmajiang_dingque_%s.png', temp[queValue])
- self.allNodes[viewId].dingque:loadTexture(texturePath)
- self.allNodes[viewId].dingque:setVisible(true)
- end
- end
-
- -- 隐藏定缺
- function yibinmajiangRoomPlayerView:clearDingQue(viewId)
- if viewId then
- if self.allNodes[viewId] and self.allNodes[viewId].dingque then
- self.allNodes[viewId].dingque:setVisible(false)
- end
- return
- end
-
- for i = 1, 4 do
- if self.allNodes[i] and self.allNodes[i].dingque then
- self.allNodes[i].dingque:setVisible(false)
- end
- end
- end
-
- return yibinmajiangRoomPlayerView
|