local playerDetailView = import(".playerDetailView") local PlayerInfoView = { _view = nil, _main_view = nil, _tex_player_name = nil, _tex_player_id = nil, _tex_score = nil, _ctr_offline = nil, _ctr_bank = nil, _ctr_room_owner = nil, _ctr_mask_voice = nil, _btn_head = nil, _biaoqing = nil, _chat = nil, _player = nil, __runwait_voice = nil, _isHideIpAdds = false } local M = PlayerInfoView function M.new(view, main_view, isHideIpAdds) local self = {} setmetatable(self, { __index = PlayerInfoView }) self._view = view self._main_view = main_view self._isHideIpAdds = isHideIpAdds self.isShowTGTimer = false self.currentTime = 0 self.totalTime = 0 --self.isShow = fasle self:init() return self end function M:init() local view = self._view UIPackage.AddPackage('base/chat/ui/Chat') self._tex_player_name = view:GetChild('name') -- self._tex_score = view:GetChild('text_jifen') self._biaoqing = view:GetChild('face') self._chat = view:GetChild('chat') self._ctr_read = view:GetController('read') self._ctr_offline = view:GetController('offline') self._btn_head = view:GetChild('btn_head') self._ctr_bank = view:GetController('bank') self._ctr_room_owner = view:GetController('room_owner') self._ctr_mask_voice = view:GetController('mask_voice') self._ctr_dismiss_room = view:GetController('dismiss_room') self._ctr_site = view:GetController('site') self._list_scoreAnimation = self._view:GetChild("list_scoreAnimation") self.cScore = self._view:GetController("cScore") self.PlayerTGTips = view:GetChild('tuoguanTips') if self.PlayerTGTips and self.PlayerTGTips.displayObject.gameObject then self.PlayerTGTips.displayObject.gameObject:SetActive(false) end end function M:IsShowTGTips(isShow, time) --printlog("isShowisShowisShow==== ",isShow," time ",time) if time == nil then time = 0 end self.isShowTGTimer = isShow if self.PlayerTGTips and self.PlayerTGTips.displayObject.gameObject then self.PlayerTGTips.displayObject.gameObject:SetActive(isShow) end self.currentTime = 0 if isShow then if self.PlayerTGTips then self.PlayerTGTips.text = "开启托管剩余时间" .. time .. "s" end self.totalTime = time TimerManager.AddTimer(self.OnUpdate, self) else TimerManager.RemoveTimer(self.OnUpdate, self) end end function M:OnUpdate() --printlog("OnUpdate=====================") if self.isShowTGTimer then self.currentTime = self.currentTime + Time.deltaTime if self.currentTime >= 1 then self.currentTime = 0 self.totalTime = self.totalTime - 1 --printlog("当前计时器===>>>",self.totalTime) if self.PlayerTGTips then self.PlayerTGTips.text = "开启托管剩余时间" .. self.totalTime .. "s" end if self.totalTime <= 0 then self.isShowTGTimer = false if self.PlayerTGTips and self.PlayerTGTips.displayObject.gameObject then self.PlayerTGTips.displayObject.gameObject:SetActive(false) end end end if self.muShiPlayerUpdate then self:muShiPlayerUpdate() end end end function M:FillData(player) self._player = player if player == nil then return end local isHidden = false local room = DataManager.CurrenRoom if room and room.playback ~= true and room.room_config and room.room_config.isHidden then isHidden = room.room_config.isHidden == 1 end if isHidden == false then ImageLoad.Load(player.self_user.head_url, self._btn_head._iconObject) self._btn_head.onClick:Set( function() --local headView = HeadView.new(self._main_view._root_view, player.self_user, self._isHideIpAdds) --headView:Show() local _playerDetailView = playerDetailView.New() _playerDetailView:Show(player) end ) else local ctr = self._btn_head:GetController("hidden") if ctr then ctr.selectedIndex = 1 end end -- print("============================playinfoview") pt(player) if isHidden --and player.self_user.account_id ~= room.self_player.self_user.account_id then if player.orgSeat and player.orgSeat > 0 then self._tex_player_name.text = "玩家" .. player.orgSeat else self._tex_player_name.text = "玩家" .. player.seat player.orgSeat = membe_clone(player.seat) end if self._tex_player_id then self._tex_player_id.text = "" end else self._tex_player_name.text = player.self_user.nick_name if self._tex_player_id then self._tex_player_id.text = "ID:" .. player.self_user.account_id end end self._ctr_room_owner.selectedIndex = room.owner_id == player.self_user.account_id and 1 or 0 if (DataManager.CurrenRoom.self_player ~= player) then self._ctr_offline.selectedIndex = player.line_state == 0 and 1 or 0 end -- self:UpdateScore() self:Ready(player.ready) if player.entrust and player ~= room.self_player then self:MarkTuoguan() end end function M:UpdateScore(score) if not score then score = self._player.total_score -- local room = DataManager.CurrenRoom -- if room:checkHpNonnegative() then -- if self._player.cur_hp then -- -- -- print(self._player.total_hp) -- -- if self._player.total_hp then -- -- score = d2ad(self._player.total_hp).."/"..d2ad(self._player.cur_hp) -- -- else -- score = d2ad(self._player.cur_hp) -- -- end -- end -- end end -- self._tex_score.text = tostring(score) end function M:SetStartType(peopleNum, seat) if peopleNum == 2 then if seat == 1 then self._ctr_site.selectedIndex = 1 else self._ctr_site.selectedIndex = 2 self._tex_player_name = 154 end elseif peopleNum == 3 then self._ctr_site.selectedIndex = 2 + seat elseif peopleNum == 4 then self._ctr_site.selectedIndex = 5 + seat else self._ctr_site.selectedIndex = 0 end end function M:DismissRoom(state) state = state or false self._ctr_dismiss_room.selectedIndex = state == true and 1 or 0 end function M:UpdateLineState(state) self._ctr_offline.selectedIndex = state == 0 and 1 or 0 end function M:Ready(isread) print("lingmengReady") self._ctr_read.selectedIndex = isread and 1 or 0 end function M:MarkBank(isbank) self._ctr_bank.selectedIndex = isbank and 1 or 0 end -- 表情 语音 function M:ShowInteraction(type, str) if type == 3 then Voice.DownLoad( str, function(clip) print("lingmeng ShowInteraction") if (clip) then print("lingmeng ShowInteraction1") self:ShowMaskVoice(clip.length) GameApplication.Instance:PlayVoice(clip) print("lingmeng ShowInteraction2") end end ) elseif type == 4 then self:SetChat(str) elseif type == 2 then local chat_index = tonumber(str) self._main_view:PlayChatSound(self._player.self_user.sex, chat_index) local language, index = self._main_view:GetChatMsgLanguage(chat_index) if language ~= 0 then local msgs = self._main_view['Fix_Msg_Chat' .. language + 1] self:SetChat(msgs[index]) else self:SetChat(self._main_view.Fix_Msg_Chat[chat_index]) end elseif type == 1 then self:SetBiaoqing('ui://Chat/' .. str) end end function M:SetBiaoqing(url) if (self.__runwait_biaoqing ~= nil) then if self._biaoqing.numChildren > 0 then self._biaoqing:RemoveChildAt(0, true) end coroutine.stop(self.__runwait_biaoqing) end self._biaoqing.alpha = 1 local bq = UIPackage.CreateObjectFromURL(url) self._biaoqing:AddChild(bq) bq:Center() -- self._biaoqing:GetChild("n1").icon = url self.__runwait_biaoqing = nil self.__runwait_biaoqing = coroutine.start(self.__WaitBiaoqing, self) end function M:__WaitBiaoqing() coroutine.wait(2) self._biaoqing.alpha = 0 -- self._biaoqing:GetChild("n1").icon = nil self._biaoqing:GetChildAt(0):Dispose() end function M:SetChat(msg) -- body self._chat.alpha = 1 self._chat:GetChild('title').text = msg if (self.__runwait_chat ~= nil) then coroutine.stop(self.__runwait_chat) end self.__runwait_chat = nil self.__runwait_chat = coroutine.start(self.__WaitChat, self) end function M:__WaitChat() coroutine.wait(2) self._chat.alpha = 0 self._chat:GetChild('title').text = '' end function M:ShowMaskVoice(time, mask) mask = mask or true GameApplication.Instance.StopMusic = GameApplication.Instance.StopMusic + 1 if (mask) then self._ctr_mask_voice.selectedIndex = 1 end if (self.__runwait_voice ~= nil) then coroutine.stop(self.__runwait_voice) GameApplication.Instance.StopMusic = GameApplication.Instance.StopMusic - 1 end self.__runwait_voice = nil self.__runwait_voice = coroutine.start(self.__WaitMaskVoice, self, time) end function M:__WaitMaskVoice(time) coroutine.wait(time) self._ctr_mask_voice.selectedIndex = 0 self.__runwait_voice = nil GameApplication.Instance.StopMusic = GameApplication.Instance.StopMusic - 1 end function M:GetHeadCenter() local btn_head = self._view:GetChild('btn_head') local pt = Vector2(btn_head.x + 1 / 2 * btn_head.width, btn_head.y + 1 / 2 * btn_head.height) return pt end -- 添加、移除托管标记 function M:MarkTuoguan() local com_tuoguan = UIPackage.CreateObjectFromURL('ui://Common/com_tuoguan') self:AddMarkToHead(com_tuoguan, 'mark_tuoguan') end function M:UnmarkTuoguan() self:RemoveMarkFromHead('mark_tuoguan') end -- 动态的往头像上加载组件 function M:AddMarkToHead(com, key) if key then if self[key] then self[key]:Dispose() end self[key] = com end self._view:AddChild(com) com.touchable = false com.xy = self:GetHeadCenter() end -- 动态移除组件 function M:RemoveMarkFromHead(key) if self[key] then self[key]:Dispose() self[key] = nil end end function M:Destroy() self.isShowTGTimer = false TimerManager.RemoveTimer(self.OnUpdate, self) self.OnUpdate = nil self.muShiPlayerUpdate = nil end function M:ScoreAnimation(score) local imgPath = "ui://Main_Majiang/score" local symbol = "ui://Main_Majiang/score+" if score < 0 then imgPath = "ui://Main_Majiang/nscore" symbol = "ui://Main_Majiang/nscore-" score = score * -1 end local imgs = {} for i = 1, score do imgs[#imgs + 1] = imgPath .. score % 10 score = math.floor(score / 10) if score <= 0 then break end end self._list_scoreAnimation.itemRenderer = function(index, obj) local loader = obj:GetChild("n1") loader.url = imgs[#imgs - index] end self._list_scoreAnimation.numItems = #imgs --local obj = self._list_scoreAnimation:AddItemFromPool() local obj = self._list_scoreAnimation:GetFromPool("ui://v0j9abjyuans1b1") self._list_scoreAnimation:AddChildAt(obj, 0) local loader = obj:GetChild("n1") loader.url = symbol self.cScore.selectedIndex = 1 local Rxy = self._list_scoreAnimation.xy self._list_scoreAnimation:TweenMove(Vector2.New( self._list_scoreAnimation.x, self._list_scoreAnimation.y - 100 ), 2):OnComplete(function() self._list_scoreAnimation.xy = Rxy self.cScore.selectedIndex = 0 self._list_scoreAnimation:TweenFade(0, 4):OnComplete(function() self._list_scoreAnimation:TweenFade(1, 1) end) end) end return M