ro-webgl/Assets/Lua/UI/UILiveRoom/UILiveRoomView.lua

2087 lines
60 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local UILiveRoomView = require("UILiveRoom/UILiveRoomView_Generate")
local IconItemCtr = require("Common/IconItemCtr")
local LIVEROOM_STAGE_NULL = 0
local LIVEROOM_STAGE_IDLE = 1
local LIVEROOM_STAGE_READY = 2
local LIVEROOM_STAGE_SHOW = 3
local LIVEROOM_STAGE_RESULT = 4
local LIVEROOM_TYPE_CARD = 1
local LIVEROOM_TYPE_SELL = 2
local LIVEROOM_TYPE_ANSWER = 3
local LIVEROOM_TYPE_GAME = 4
local LIVEROOM_TYPE_BID = 5
local LIVEROOM_NUM = 5
local uid2info = {}
local liveRoomCfg = ManagerContainer.CfgMgr:GetLiveRoomCfg()
local talkCfg = ManagerContainer.CfgMgr:GetLiveRoomTalkCfg()
local giftCfg = ManagerContainer.CfgMgr:GetLiveRoomGiftCfg()
local sellCfg = ManagerContainer.CfgMgr:GetLiveRoomSellCfg()
local bidCfg = ManagerContainer.CfgMgr:GetLiveRoomBidCfg()
local questionCfg = ManagerContainer.CfgMgr:GetLiveRoomQuestionCfg()
local chat_Records = {
[1] = {},
[2] = {},
[3] = {},
[4] = {},
[5] = {}
}
local gift_Records = {
[1] = {},
[2] = {},
[3] = {},
[4] = {},
[5] = {}
}
--region 生命周期
function UILiveRoomView:OnAwake(data)
self.controller = require("UILiveRoom/UILiveRoomCtr"):new()
self.controller:Init(self)
self.controller:SetData(data)
end
function UILiveRoomView:FillContent(data, uiBase)
self.uiBase = uiBase
local gameObject = self.uiBase:GetRoot()
if gameObject ~= nil then
self.gameObject = gameObject
self.transform = gameObject.transform
end
self:InitGenerate(self.transform, data)
self:Init()
end
function UILiveRoomView:Init()
self:LoadRes()
self.upSafeOffset = UnityEngine.Screen.height - UnityEngine.Screen.safeArea.yMax
end
function UILiveRoomView:AddEventListener()
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
--Join ack
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_JOIN_ACK,
function(data)
LogWarning("tzy_join_ack")
self:RefreshRoom()
self:ResetReceiveGift_OnJoin(data.room_id)
self:ResetChat_OnJoin(data.room_id)
if data.room_type == LIVEROOM_TYPE_SELL or data.room_type == LIVEROOM_TYPE_BID then
local cfgid = tonumber(string.split(data.room_state, ":")[2]) or nil
if cfgid then
self:SetReadyItem(data.room_id, cfgid)
end
end
end)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_LEAVE_ACK, function()
end)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_GET_READY_ACK,
function(error)
self:RefreshRoom()
end)
--准备 数据
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_GET_READY_NTF,
function(data)
self.answer_player_list = {}
self.game_player_list = {}
for k, v in pairs(data.ready_player_info_list) do
local info = { uid = v.uid, head_id = v.head_id, name = v.nickname, level = v.level }
uid2info[v.uid] = info
self.answer_player_list[v.uid] = info
self.game_player_list[v.uid] = info
end
LogWarning("tzy_ready_ntf: " .. Inspect(data))
self:RefreshRoom()
local itemlua = self:GetCurrPageLua()
self:ReadyPad_Head(itemlua, data.ready_player_info_list)
end)
--聊天 回调
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_CHAT_NTF,
function(data)
LogWarning("tzy_chat_ntf: " .. Inspect(data))
local room_id = data.room_id
chat_Records[room_id][#chat_Records[room_id] + 1] = data.chat_data
self:Refresh_ChatRecords(room_id)
end)
--阶段变更
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_STAGE_NTF, function(data)
LogWarning("tzy_stage_ntf: " .. Inspect(data))
self:OnStageChanged(data)
self:RefreshRoom()
end)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_CMD_PLAY_NTF, function()
self:RefreshRoom()
end)
--主播 动作、说话
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_CMD_TALK_NTF,
function(data)
LogWarning("tzy_talk_ntf: " .. Inspect(data))
local info = self:String2Table(data.talk_params)
local itemlua = self:GetCurrPageLua()
self:Set_Streamer_Animation(data.room_id, info.act)
self:Set_Streamer_Talk(data.talk_id, info.talk)
end)
--进行中 数据
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_SHOW_DATA_NTF,
function(data)
LogWarning("tzy_show_: " .. Inspect(data))
local itemlua = self:GetCurrPageLua()
if data.room_id == LIVEROOM_TYPE_CARD then
elseif data.room_id == LIVEROOM_TYPE_SELL then
--self:Show_Sell_Cfg(itemlua, data.show_data_list[1].key)
self:Show_Sell_Progress(itemlua, data.show_data_list[1])
elseif data.room_id == LIVEROOM_TYPE_ANSWER then
self:Show_Answer_Result(itemlua, data)
elseif data.room_id == LIVEROOM_TYPE_GAME then
if self.game_player_list[data.uid] == nil then
self:Show_Game_View(itemlua, data.show_data_list)
end
elseif data.room_id == LIVEROOM_TYPE_BID then
if data.show_data_list and data.show_data_list[1] then
self:Show_Bid_Rank(itemlua, data)
end
end
end)
--结算 数据
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_RESULT_NTF,
function(data)
LogWarning("tzy_result_: " .. Inspect(data))
local itemlua = self:GetCurrPageLua()
if data.room_id == LIVEROOM_TYPE_CARD then
self:Result_Card(itemlua, data)
elseif data.room_id == LIVEROOM_TYPE_SELL then
self:Result_Sell(itemlua, data)
elseif data.room_id == LIVEROOM_TYPE_ANSWER then
self:Result_Answer(itemlua, data)
elseif data.room_id == LIVEROOM_TYPE_GAME then
self:Result_Game(itemlua, data)
elseif data.room_id == LIVEROOM_TYPE_BID then
self:Result_Bid(itemlua, data)
end
end)
--收到礼物
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_SEND_GIFT_NTF,
function(data)
local room_id = data.room_id
LogWarning("tzy_收到礼物: " .. Inspect(data))
gift_Records[room_id][#gift_Records[room_id] + 1] = data.send_gift_info
self:Refresh_GiftRecords(room_id)
end)
--submit
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_SHOW_SUBMIT_ACK,
function(data)
LogWarning("tzy_submit_ack: " .. Inspect(data))
if data.submit_result and data.submit_result[1] then
local info = data.submit_result[1]
LogWarning("tzy_submit_ack: " .. Inspect(info))
if info.value ~= 0 and info.value2 ~= 0 and info.str_val ~= "" then
local itemlua = self:GetCurrPageLua()
self:Show_Bid_Submit(itemlua, info.value2, info.value, info.str_val)
end
end
end)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_ADD_HEART_ACK,
function(data)
local heart = data.heart
local itemlua = self:GetCurrPageLua()
self:RefreshHeart(itemlua)
end)
end
function UILiveRoomView:RemoveEventListener()
ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
end
function UILiveRoomView:AddUIEventListener()
-- local roomType = 1
-- self.uiBase:AddButtonUniqueEventListener(self.testBtn.button, self, function()
-- self:SwitchRoom(roomType)
-- roomType = roomType + 1
-- if roomType > LIVEROOM_TYPE_GAME then
-- roomType = 1
-- end
-- end)
end
function UILiveRoomView:OnHide()
end
function UILiveRoomView:OnShow(data)
self.controller:SetData(data)
end
function UILiveRoomView:OnClose()
end
function UILiveRoomView:OnDispose()
self.controller:OnDispose()
end
--endregion 生命周期
--初始化时调用加载资源
function UILiveRoomView:LoadRes()
ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.LIVEROOM_RES_STREAMER_LOAD_OK, self, self.OnStreamerGoLoaded)
self.res = {}
local partResPaths = { "Streamer_1", "Streamer_2", "Streamer_3", "Streamer_4", "Streamer_5", "Game_FlappyBird" }
local seqId = ManagerContainer.ResMgr:LoadAssetGameObjects(Constants.StreamerPath, ELoadType.OTHER, function(objs)
for i = 1, #partResPaths do
local k = partResPaths[i]
local obj = objs[i - 1]
self.res[k] = obj
end
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.LIVEROOM_RES_STREAMER_LOAD_OK, objs)
end, unpack(partResPaths))
end
--加载完成时
function UILiveRoomView:OnStreamerGoLoaded(objs)
ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.LIVEROOM_RES_STREAMER_LOAD_OK, self,
self.OnStreamerGoLoaded)
self:InitRoom()
self:SetRoomCount(LIVEROOM_NUM)
ManagerContainer.LuaTimerMgr:AddTimer(500, 1, nil, function()
self.sv_room.loopListView:MovePanelToItemIndex(0, 0)
end, nil)
end
--region 房间 listview相关
--初始化房间loopview
function UILiveRoomView:InitRoom()
if self.sv_room.loopListView.ListViewInited == false then
self.sv_room.loopListView:InitListView(-1,
function(loopview, index) return self:GetLiveRoomItem(loopview, index) end)
end
end
--设置房间总数并刷新内容
function UILiveRoomView:SetRoomCount(count)
self.roomCount = count
self.sv_room.loopListView:RefreshAllShownItem()
end
--生成房间
function UILiveRoomView:GetLiveRoomItem(loopview, index)
LogError("GetLiveRoomItem: " .. tostring(index))
local index2 = index % self.roomCount
local item = loopview:NewListViewItem("LiveRoomItem")
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "LiveRoomItem", item.gameObject)
local go = item.gameObject
go.name = "LiveRoomItem_" .. index2
--根据loopview大小重设房间大小
local rect = go:GetComponent(Enum.TypeInfo.RectTransform)
local loopviewRect = loopview:GetComponent(Enum.TypeInfo.RectTransform)
rect.sizeDelta = Vector2(loopviewRect.rect.width, loopviewRect.rect.height)
local roomType = index2 + 1
self:InitReceiveGift(itemlua, roomType)
self:InitChat(itemlua, roomType)
self:ConfigRoom(itemlua, roomType)
self:SwitchRoom(itemlua)
self:SetReadyPad(itemlua, roomType)
self:SetShowPad(itemlua, roomType)
self:SetResultPad(itemlua, roomType)
return item
end
--endregion 房间 listview相关
--region 房间 配置相关
--获取当前页面
function UILiveRoomView:GetCurrPageLua()
local pageId = self.sv_room.loopListView.CurSnapNearestItemIndex
local item = self.sv_room.loopListView:GetShownItemByItemIndex(pageId)
local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "LiveRoomItem", item.gameObject)
return itemlua
end
--延时向服务器发送请求:退出旧房间,加入新房间
function UILiveRoomView:SwitchRoom(liveRoomItemLua)
if self.switchRoomWaitTimer then
ManagerContainer.LuaTimerMgr:RemoveTimer(self.switchRoomWaitTimer)
self.switchRoomWaitTimer = nil
end
self.switchRoomWaitTimer = ManagerContainer.LuaTimerMgr:AddLuaTimer(300, 1, function()
local pageId = self.sv_room.loopListView.CurSnapNearestItemIndex
local roomType = pageId % self.roomCount + 1
LogError("SwitchRoom: roomType=" .. roomType)
-- 退出当前房间
local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
local oldRoomId = data["room_id"]
if oldRoomId then
ManagerContainer.DataMgr.LiveRoomData:LeaveReq(oldRoomId)
end
-- 加入新房间
ManagerContainer.DataMgr.LiveRoomData:JoinReq(roomType)
end)
end
--配置当前房间
function UILiveRoomView:ConfigRoom(itemLua, roomType)
local itemCount = LIVEROOM_NUM
--销毁所有房间的某些资源()
self.gameGos = self.gameGos or {}
for k, v in pairs(self.gameGos) do
CommonUtil.DestroyGO(v)
end
self.gameGos = {}
self.streamerGos = self.streamerGos or {}
for k, v in pairs(self.streamerGos) do
CommonUtil.DestroyGO(v)
end
self.streamerGos = {}
--从json读数据Assets\Lua\Config\LiveRoomCfg.lua
local liveRoomCfg = ManagerContainer.CfgMgr:GetLiveRoomCfg()
local roomCfg = liveRoomCfg[roomType]
itemLua.roomTitleBar.roomName.text.text = roomCfg["RoomDesp"]
itemLua.roomTitleBar.streamerHead.nickname.text.text = roomCfg["RoomDesp"]
--[[
CommonUtil.LoadIcon(self, "PlayerHeads/" .. roomCfg["StreamerHead"], function(sprite)
itemLua.roomTitleBar.streamerHead.headImg.image.sprite = sprite
end)
CommonUtil.LoadIcon(self, "LiveRoomBg/LiveRoomBg_" .. roomType, function(sprite)
itemLua.roomBg.bg.image.sprite = sprite
end)
]]
self:LoadIcon_SetSprite(itemLua.roomTitleBar.streamerHead.headImg, "PlayerHeads/" .. roomCfg["StreamerHead"])
self:LoadIcon_SetSprite(itemLua.roomBg.bg, "LiveRoomBg/LiveRoomBg_" .. roomType)
--[[
--从文件设置rect
local readyPadRect = itemLua.readyPad.rectTransform
readyPadRect.sizeDelta = Vector2(readyPadRect.sizeDelta.x, roomCfg["ReadyPadHeight"])
readyPadRect.anchoredPosition = Vector2(0, roomCfg["ReadyPadOffset"])
local showPadRect = itemLua.showPad.rectTransform
showPadRect.sizeDelta = Vector2(showPadRect.sizeDelta.x, roomCfg["ShowPadHeight"])
showPadRect.anchoredPosition = Vector2(0, roomCfg["ShowPadOffset"])
local resultPadRect = itemLua.resultPad.rectTransform
resultPadRect.sizeDelta = Vector2(resultPadRect.sizeDelta.x, roomCfg["ResultPadHeight"])
resultPadRect.anchoredPosition = Vector2(0, roomCfg["ResultPadOffset"])
]]
itemLua.idlePad:SetActive(false)
itemLua.readyPad:SetActive(false)
itemLua.showPad:SetActive(false)
itemLua.resultPad:SetActive(false)
--事件挂载
self.uiBase:AddButtonUniqueEventListener(itemLua.roomTitleBar.closeBtn.button, self, self.OnCloseBtn)
end
--按钮关闭uiliveroom
function UILiveRoomView:OnCloseBtn()
if self.currStageTimer then
ManagerContainer.LuaTimerMgr:RemoveTimer(self.currStageTimer)
self.currStageTimer = nil
end
local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
local oldRoomId = data["room_id"]
if oldRoomId then
ManagerContainer.DataMgr.LiveRoomData:LeaveReq(oldRoomId)
end
ManagerContainer.DataMgr.LiveRoomData:Clear()
if self.sv_room.loopListView.ListViewInited then
self.sv_room.loopListView:Dispose()
end
self:UIClose()
end
function UILiveRoomView:OnStageChanged(data)
--LogWarning("tzy_OnStageChanged")
local room_id = data.room_id
local stage = data.stage
local itemlua = self:GetCurrPageLua()
--LogWarning("tzy_OnStage" .. itemlua.gameObject.name)
if stage == LIVEROOM_STAGE_IDLE then
elseif stage == LIVEROOM_STAGE_READY then
self:ReadyPad_Head(itemlua, nil)
itemlua.readyPad.readyitem:SetActive(false)
if room_id == LIVEROOM_TYPE_SELL or room_id == LIVEROOM_TYPE_BID then
local cfgid = tonumber(string.split(data.stage_params, ":")[2]) or nil
if cfgid then
self:SetReadyItem(data.room_id, cfgid)
if room_id == LIVEROOM_TYPE_SELL then
self:Show_Sell_Cfg(itemlua, cfgid)
elseif room_id == LIVEROOM_TYPE_BID then
self:Show_Bid_Cfg(itemlua, cfgid)
end
end
end
elseif stage == LIVEROOM_STAGE_SHOW then --Show
if room_id == LIVEROOM_TYPE_CARD then
elseif room_id == LIVEROOM_TYPE_SELL then
local cfgid = tonumber(string.split(data.stage_params, ":")[2]) or nil
if cfgid then
--self:Show_Sell_Cfg(itemlua, cfgid)
end
elseif room_id == LIVEROOM_TYPE_ANSWER then
if self.answer_player_list[data.uid] ~= nil then
if data.stage_params then
local str = string.split(data.stage_params, ";")
local cfgid = tonumber(string.split(str[1], ":")[2])
local opt_sort1 = string.split(string.split(str[2], ":")[2], "-")
local opt_sort2 = {}
for i = 1, #opt_sort1 do
opt_sort2[i] = tonumber(opt_sort1[i])
end
LogWarning("tzy_opt_sort: " .. cfgid .. " " .. Inspect(opt_sort2))
self:Show_Answer_Cfg(itemlua, cfgid, opt_sort2)
end
end
elseif room_id == LIVEROOM_TYPE_GAME then
--循环发送游戏分数
if not self.showpad_game_timer or self.showpad_game_timer == nil then
self.showpad_game_timer = ManagerContainer.LuaTimerMgr:AddLuaTimer(1000, -1, function()
--LogWarning("tzy_test_timer")
self:Show_SendGameScore(room_id)
end)
end
elseif room_id == LIVEROOM_TYPE_BID then
local cfgid = tonumber(string.split(data.stage_params, ":")[2]) or nil
if cfgid then
--self:Show_Bid_Cfg(itemlua, cfgid)
self:Result_Bid_Cfg(itemlua, cfgid)
end
end
elseif stage == LIVEROOM_STAGE_RESULT then
--停止发送游戏分数
if self.showpad_game_timer then
ManagerContainer.LuaTimerMgr:RemoveTimer(self.showpad_game_timer)
self.showpad_game_timer = nil
end
end
end
--刷新房间
--[[
事件:
SC_LIVE_ROOM_JOIN_ACK 加入房间请求
SC_LIVE_ROOM_GET_READY_ACK 准备请求
SC_LIVE_ROOM_GET_READY_NTF 准备回调
SC_LIVE_ROOM_STAGE_NTF 阶段回调
SC_LIVE_ROOM_CMD_PLAY_NTF 播放回调
]]
function UILiveRoomView:RefreshRoom()
LogError("------------------ RefreshRoom ------------------")
local itemLua = self:GetCurrPageLua()
itemLua.idlePad:SetActive(false)
itemLua.readyPad:SetActive(false)
itemLua.showPad:SetActive(false)
itemLua.resultPad:SetActive(false)
itemLua.bg_talk:SetActive(false)
--itemLua.roomBg.bg:SetActive(true)
local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
local room_id = data["room_id"]
local room_type = data["room_type"]
local stage = data["stage"]
local is_ready = data["is_ready"]
local stage_sec = data["stage_sec"] or 0
local ready_player_info_list = data["ready_player_info_list"] or {}
self:InitTopBar(itemLua, room_id)
self:LoadStreamer(itemLua, room_type)
self:ResetStageTimer(stage_sec)
if stage == LIVEROOM_STAGE_IDLE then
itemLua.idlePad:SetActive(true)
elseif stage == LIVEROOM_STAGE_READY then
itemLua.readyPad:SetActive(true)
itemLua.readyPad.readyBtn:SetActive(not is_ready)
elseif stage == LIVEROOM_STAGE_SHOW then
itemLua.showPad:SetActive(true)
if is_ready then
-- 自己参与模式
if room_type == LIVEROOM_TYPE_GAME then
-- 加载游戏
self.gameGos = self.gameGos or {}
if not self.gameGos[room_type] then
local prefab = self.res["Game_FlappyBird"]
local game = CommonUtil.Instantiate(prefab, itemLua.showPad.transform)
local rectTransform = game:GetComponent(Enum.TypeInfo.RectTransform)
rectTransform.localRotation = Quaternion.identity
rectTransform.localScale = Vector3(1, 1, 1)
rectTransform.anchorMin = Vector2(0, 0)
rectTransform.anchorMax = Vector2(1.0, 1.0)
rectTransform.pivot = Vector2(0.5, 0.5)
rectTransform.anchoredPosition = Vector3(0, 0, 0)
rectTransform.sizeDelta = Vector2(0, 0)
self.gameGos[room_type] = game
end
end
else
-- 观战模式
end
elseif stage == LIVEROOM_STAGE_RESULT then
itemLua.resultPad:SetActive(true)
if room_type == LIVEROOM_TYPE_GAME then
-- 删除游戏物体
if self.gameGos and self.gameGos[room_type] then
CommonUtil.DestroyGO(self.gameGos[room_type])
self.gameGos[room_type] = nil
end
end
end
self:RefreshHeart(itemLua)
end
function UILiveRoomView:RefreshHeart(itemlua)
local liveRoomData = ManagerContainer.DataMgr.LiveRoomData:GetData()
itemlua.roomTitleBar.text_sign.text.text = liveRoomData.heart
end
--加载模型
function UILiveRoomView:LoadStreamer(itemLua, roomType)
if not roomType then return end
local liveRoomCfg = ManagerContainer.CfgMgr:GetLiveRoomCfg()
local roomCfg = liveRoomCfg[roomType]
if self.streamerGos[roomType] then
--CommonUtil.DestroyGO(itemLua.streamerGo)
--itemLua.streamerGo = nil
return
end
local prefabName = "Streamer_" .. roomType
local streamerPrefab = self.res[prefabName]
local streamerGo = CommonUtil.Instantiate(streamerPrefab, itemLua.liveStreamer.transform)
local rectTransform = streamerGo:GetComponent(Enum.TypeInfo.RectTransform)
rectTransform.localRotation = Quaternion.identity
rectTransform.localScale = Vector3(roomCfg["StreamerScale"], roomCfg["StreamerScale"], roomCfg["StreamerScale"])
--rectTransform.anchorMin = Vector2(0, 0)
--rectTransform.anchorMax = Vector2(1.0, 1.0)
rectTransform.pivot = Vector2(0.5, 0.5)
rectTransform.anchoredPosition = Vector2(roomCfg["StreamerOffset"][1], roomCfg["StreamerOffset"][2])
--rectTransform.sizeDelta = Vector2(0, 0)
self.streamerGos = self.streamerGos or {}
self.streamerGos[roomType] = streamerGo
end
--endregion 房间 配置相关
function UILiveRoomView:String2Table(str)
local t1 = string.split(str, ";")
local data = {}
for i = 1, #t1 do
local t2 = string.split(t1[i], ":")
local num = tonumber(t2[2])
data[t2[1]] = num or t2[2]
end
--LogWarning("tzy_String2Table: ".. Inspect(data))
return data
end
--工具 LoadIcon
function UILiveRoomView:LoadIcon_SetSprite(go, path)
CommonUtil.LoadIcon(self, path, function(sprite)
go.image.sprite = sprite
end)
end
--工具 点击IconItem
function UILiveRoomView:OnClickIconItem(btn, params)
local logicData = params[0]
ManagerContainer.LuaUIMgr:OpenTips(logicData)
end
--region 房间 顶部
function UILiveRoomView:InitTopBar(itemlua, room_id)
local liveRoomData = ManagerContainer.DataMgr.LiveRoomData:GetData()
local roomname, name, sign, head, audhead1, audhead2, audhead3, audcount, notice
roomname = itemlua.roomTitleBar.roomName.text
name = itemlua.roomTitleBar.streamerHead.nickname.text
sign = itemlua.roomTitleBar.text_sign.text
head = itemlua.roomTitleBar.streamerHead.headImg.image
itemlua.roomTitleBar.audiencehead1:SetActive(false)
itemlua.roomTitleBar.audiencehead2:SetActive(false)
itemlua.roomTitleBar.audiencehead3:SetActive(false)
audhead1 = itemlua.roomTitleBar.audiencehead1.head_img.image
audhead2 = itemlua.roomTitleBar.audiencehead2.head_img.image
audhead3 = itemlua.roomTitleBar.audiencehead3.head_img.image
audcount = itemlua.roomTitleBar.text_audiencecount.text
audcount.text = ""..liveRoomData["room_user_num"]
for i=1, #liveRoomData["room_user_heads"] do
local headId = liveRoomData["room_user_heads"][i]
itemlua.roomTitleBar["audiencehead"..i]:SetActive(true)
CommonUtil.LoadIcon(self, "PlayerHeads/player_head_"..headId, function(sprite)
itemlua.roomTitleBar["audiencehead"..i].head_img.image.sprite = sprite
end)
end
notice = itemlua.roomTitleBar.text_notice.text.text
end
--endregion 房间 顶部
--region 房间 主播说话、动作
function UILiveRoomView:Set_Streamer_Animation(room_id, act)
if self.streamerGos == nil or self.streamerGos[room_id] == nil then return end
local streamer = self.streamerGos[room_id]:GetComponent(Enum.TypeInfo.SkeletonGraphic)
local cfg = liveRoomCfg[room_id]["StreamerActs"]
local name = cfg[act][1]
local time = cfg[act][2]
if name == "Stand" then return end
LogWarning("tzy_act: " .. name .. " time: " .. time)
streamer.AnimationState:SetAnimation(0, name, false)
if not self.streamer_act_timer or self.streamer_act_timer == nil then
self.streamer_act_timer = ManagerContainer.LuaTimerMgr:AddLuaTimer(time * 1000, 1, function()
streamer.AnimationState:SetAnimation(0, "Stand", true)
ManagerContainer.LuaTimerMgr:RemoveTimer(self.streamer_act_timer)
self.streamer_act_timer = nil
end)
end
end
function UILiveRoomView:Set_Streamer_Talk(talk, talk_params)
local talk_str = talkCfg[talk].Params2[talk_params]
local itemlua = self:GetCurrPageLua()
itemlua.bg_talk:SetActive(true)
itemlua.bg_talk.text_talk.text.text = talk_str
end
--endregion 房间 主播说话、动作
--region 房间 聊天 聊天
function UILiveRoomView:ResetChat_OnJoin(room_id)
chat_Records[room_id] = ManagerContainer.DataMgr.LiveRoomData:GetData().chat_records
LogWarning("tzy_chat_Records1: " .. Inspect(chat_Records))
self:Refresh_ChatRecords(room_id)
end
function UILiveRoomView:Refresh_ChatRecords(room_id)
LogWarning("tzy_chat_Records2: " .. Inspect(chat_Records[room_id]))
local itemlua = self:GetCurrPageLua()
local count = #chat_Records[room_id]
itemlua.sv_chat.loopListView:SetListItemCount(count)
itemlua.sv_chat.loopListView:RefreshAllShownItem()
itemlua.sv_chat.loopListView:MovePanelToItemIndex(count - 1, 0)
end
function UILiveRoomView:InitChat(itemlua, room_id)
local idx = room_id
itemlua.sv_chat.loopListView:Dispose()
itemlua.sv_chat.loopListView:InitListView(0,
function(loopview, Index) return self:GenChatItem(loopview, Index, idx) end)
self.uiBase:AddButtonUniqueEventListener(itemlua.inputBar.btn_send_chat.button, self,
function() self:Btn_Send_Chat(itemlua, idx) end)
--表情
itemlua.inputBar.sv_emoji.loopGridView:Dispose()
itemlua.inputBar.sv_emoji.loopGridView:InitGridView(80,
function(loopview, index, row, col)
return self:Gen_Emoji(loopview, index, row, col, idx)
end, nil)
--礼物
itemlua.inputBar.sv_gift.loopGridView:Dispose()
itemlua.inputBar.sv_gift.loopGridView:InitGridView(0,
function(loopview, index, row, col)
return self:Gen_Gift(loopview, index, row, col, idx)
end, nil)
itemlua.inputBar.sv_gift.loopGridView:SetListItemCount(#giftCfg)
self.uiBase:AddButtonUniqueEventListener(itemlua.inputBar.btn_send_emoji.button, self,
function() self:Btn_Send_Emoji(itemlua) end)
self.uiBase:AddButtonUniqueEventListener(itemlua.inputBar.btn_send_gift.button, self,
function() self:Btn_Send_Gift(itemlua) end)
self.uiBase:AddButtonUniqueEventListener(itemlua.inputBar.btn_send_like.button, self,
function() ManagerContainer.DataMgr.LiveRoomData:AddHeart() end)
itemlua.inputBar.sv_emoji:SetActive(false)
itemlua.inputBar.sv_gift:SetActive(false)
end
function UILiveRoomView:GenChatItem(loopview, index, room_id)
if index < 0 then return nil end
local item = loopview:NewListViewItem("LiveRoomChatItem")
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "LiveRoomChatItem", item.gameObject)
local go = item.gameObject
go.name = "LiveRoomChatItem_" .. index
local id = index + 1
local data = chat_Records[room_id][id]
if not data then return nil end
local name = tostring(data.player_info.nickname)
local vip = tostring(data.player_info.vip_level or 0)
if name == "" then name = "穿越者" end
local level = tostring(data.player_info.level)
local content = data.chat_content
itemlua.text_vip.text.text = vip or "0"
itemlua.text_name.text.text = name .. ":" --.. ".Lv" .. level .. ":"
--设置大小
local c_sizename = StringUtil.GetTMTextWidth(itemlua.text_name.text, name .. ":")
itemlua.text_name.rectTransform.sizeDelta = Vector2(c_sizename, 50)
itemlua.rect1.rectTransform.sizeDelta = Vector2(112 + 20 + c_sizename, 85)
local c_sizeother = 47 + 112 + 20 + c_sizename
local c_sizeMax = 1020 - c_sizeother
itemlua.text_chat.text.text = content
local c_size = StringUtil.GetTMTextWidth(itemlua.text_chat.text, content)
local linecount = math.floor(c_size / c_sizeMax)
--LogWarning("c_sizeMax:" .. c_sizeMax .. " c_size:" .. c_size .. " linecount:" .. linecount)
if linecount == 0 then
itemlua.text_chat.rectTransform.sizeDelta = Vector2(c_size, 85)
itemlua.rectTransform.sizeDelta = Vector2(c_sizeother + c_size, 85)
end
if linecount > 0 then
itemlua.text_chat.rectTransform.sizeDelta = Vector2(c_sizeMax, 85 * (linecount + 1))
itemlua.rectTransform.sizeDelta = Vector2(1020, 85 * (linecount + 1))
end
return item
end
function UILiveRoomView:GenRandomChatContent(room_id)
local idx = room_id
--local size=math.random(2,10)
local data = {}
for i = 1, idx do
--data[i] = "测试消息 随机数: " .. tostring(idx) .. " " .. tostring(i) .. " " .. tostring(math.random(1, 100))
ManagerContainer.DataMgr.LiveRoomData:ChatReq(room_id)
end
chat_Records[idx] = data
end
function UILiveRoomView:Btn_Send_Chat(itemlua, room_id)
local idx = room_id
local text = itemlua.inputBar.inputfield_chat.tMP_InputField.text
if text ~= "" then
ManagerContainer.DataMgr.LiveRoomData:ChatReq(idx, text)
end
itemlua.inputBar.inputfield_chat.tMP_InputField.text = ""
end
--endregion 房间 聊天 聊天
--region 房间 聊天 发表情
--start 425 end 504 total 80
function UILiveRoomView:Btn_Send_Emoji(itemlua)
itemlua.inputBar.sv_gift:SetActive(false)
if itemlua.inputBar.sv_emoji.gameObject.activeSelf then
itemlua.inputBar.sv_emoji:SetActive(false)
else
itemlua.inputBar.sv_emoji:SetActive(true)
end
end
function UILiveRoomView:Gen_Emoji(loopview, index, row, col, room_id)
local item = loopview:NewListViewItem("LiveRoomEmojiItem")
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "LiveRoomEmojiItem", item.gameObject)
local go = item.gameObject
local start = 425
local id = start + index
go.name = "LiveRoomEmojiItem" .. index
itemlua.emoji.text.text = "<sprite=" .. id .. ">"
self.uiBase:AddButtonUniqueEventListener(itemlua.btn.button, self,
function()
self:OnEmojiClick(room_id, id)
end)
return item
end
function UILiveRoomView:OnEmojiClick(room_id, idx)
local itemlua = self:GetCurrPageLua()
local str = "<sprite=" .. idx .. ">"
--此处复制到聊天框
itemlua.inputBar.inputfield_chat.tMP_InputField.text = itemlua.inputBar.inputfield_chat.tMP_InputField.text .. str
itemlua.inputBar.sv_emoji:SetActive(false)
end
--endregion 房间 聊天 发表情
--region 房间 聊天 发礼物
function UILiveRoomView:Btn_Send_Gift(itemlua)
itemlua.inputBar.sv_emoji:SetActive(false)
if itemlua.inputBar.sv_gift.gameObject.activeSelf then
itemlua.inputBar.sv_gift:SetActive(false)
else
itemlua.inputBar.sv_gift:SetActive(true)
end
end
function UILiveRoomView:Gen_Gift(loopview, index, row, col, room_id)
local item = loopview:NewListViewItem("LiveRoomGiftItem")
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "LiveRoomGiftItem", item.gameObject)
local go = item.gameObject
local id = index + 1
go.name = "LiveRoomGiftItem" .. id
local info = giftCfg[id]
--LogWarning("info: " .. Inspect(info))
--设置价格
local cost_str = string.split(info.Price, ":")[2] .. "游戏币"
--LogWarning("cost_str: " .. Inspect(cost_str))
itemlua.text_price_off.text.text = cost_str
itemlua.text_price_on.text.text = cost_str
itemlua.text_name.text.text = info.Name
--设置图标
local iconpath = "LiveRoomGift/" .. info.Icon
self:LoadIcon_SetSprite(itemlua.img_gift, iconpath)
self.uiBase:AddButtonUniqueEventListener(itemlua.btn_send.button, self,
function()
self:OnGiftClick(room_id, id)
itemlua.rect_send:SetActive(false)
end)
return item
end
function UILiveRoomView:OnGiftClick(room_id, idx)
local itemlua = self:GetCurrPageLua()
itemlua.inputBar.sv_gift:SetActive(false)
ManagerContainer.DataMgr.LiveRoomData:SendGiftReq(room_id, idx)
end
--endregion 房间 聊天 发礼物
--region 房间 收礼物
function UILiveRoomView:ResetReceiveGift_OnJoin(room_id)
gift_Records[room_id] = ManagerContainer.DataMgr.LiveRoomData:GetData().gift_records
self:Refresh_GiftRecords(room_id)
end
function UILiveRoomView:Refresh_GiftRecords(room_id)
LogWarning("tzy_gift_records: " .. Inspect(gift_Records[room_id]))
local itemlua = self:GetCurrPageLua()
local count = #gift_Records[room_id]
itemlua.giftRank.sv_r_gift.loopListView:SetListItemCount(count)
itemlua.giftRank.sv_r_gift.loopListView:RefreshAllShownItem()
itemlua.giftRank.sv_r_gift.loopListView:MovePanelToItemIndex(count - 1, 0)
itemlua.giftRank.sv_r_gift.scrollRect.vertical = false
end
function UILiveRoomView:InitReceiveGift(itemlua, room_id)
local btn_hour = itemlua.giftRank.btn_hour.button
local btn_day = itemlua.giftRank.btn_day.button
local btn_month = itemlua.giftRank.btn_month.button
local loopview = itemlua.giftRank.sv_r_gift.loopListView
local testgift_hour = {
{ name = "小时1" },
{ name = "小时2" }
}
local testgift_day = {
{ name = "日1" },
{ name = "日2" },
{ name = "日3" },
{ name = "日4" },
}
local testgift_month = {
{ name = "月1" },
{ name = "月2" },
{ name = "月3" },
{ name = "月4" },
{ name = "月5" },
{ name = "月6" },
}
local curdata
loopview:Dispose()
loopview:InitListView(0, function(loopview, index) return self:Gen_Receive_Gift(loopview, index, room_id) end)
self.uiBase:AddButtonUniqueEventListener(btn_hour, self, function()
curdata = testgift_hour
loopview:SetListItemCount(#curdata)
loopview:RefreshAllShownItem()
end)
self.uiBase:AddButtonUniqueEventListener(btn_day, self, function()
curdata = testgift_day
loopview:SetListItemCount(#curdata)
loopview:RefreshAllShownItem()
end)
self.uiBase:AddButtonUniqueEventListener(btn_month, self, function()
curdata = testgift_month
loopview:SetListItemCount(#curdata)
loopview:RefreshAllShownItem()
end)
end
function UILiveRoomView:Gen_Receive_Gift(loopview, index, room_id)
if index < 0 then return nil end
local item = loopview:NewListViewItem("LiveRoomReceiveGiftItem")
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "LiveRoomReceiveGiftItem", item.gameObject)
local go = item.gameObject
go.name = "LiveRoomReceiveGiftItem" .. index
local id = index + 1
local data = gift_Records[room_id][id]
if not data then return item end
local gift_id = giftCfg[self:String2Table(data.data).gift].Icon
local iconpath = "LiveRoomGift/" .. gift_id
local name = data.nickname
itemlua.text_name.text.text = name
self:LoadIcon_SetSprite(itemlua.img_gift, iconpath)
return item
end
--endregion 房间 收礼物
--region 房间 准备
function UILiveRoomView:SetReadyPad(itemlua, room_id)
local room_type = room_id
local title
local readybtn = itemlua.readyPad.readyBtn.button
local card = itemlua.readyPad.card_bg
self.uiBase:AddButtonUniqueEventListener(readybtn, self, function() self:OnReadyBtn(room_id) end)
card:SetActive(false)
local heads = {
[1] = itemlua.readyPad.head1,
[2] = itemlua.readyPad.head2,
[3] = itemlua.readyPad.head3,
[4] = itemlua.readyPad.head4,
[5] = itemlua.readyPad.head5,
[6] = itemlua.readyPad.head6,
[7] = itemlua.readyPad.head7,
[8] = itemlua.readyPad.head8,
[9] = itemlua.readyPad.head9,
[10] = itemlua.readyPad.head10,
}
for i = 1, 10 do
heads[i]:SetActive(false)
heads[i].head_img:SetActive(false)
--self:LoadIcon_SetSprite(heads[i], "NpcHeads/npc_head_" .. i)
end
if room_type == LIVEROOM_TYPE_CARD then
title = "抽卡准备中"
card:SetActive(true)
for i = 1, 5 do heads[i]:SetActive(true) end
elseif room_type == LIVEROOM_TYPE_SELL then
title = "售卖准备中"
for i = 1, 5 do heads[i]:SetActive(true) end
elseif room_type == LIVEROOM_TYPE_ANSWER then
title = "答题准备中"
for i = 1, 5 do heads[i]:SetActive(true) end
elseif room_type == LIVEROOM_TYPE_GAME then
title = "游戏准备中"
for i = 1, 10 do heads[i]:SetActive(true) end
elseif room_type == LIVEROOM_TYPE_BID then
title = "拍卖准备中"
for i = 1, 5 do heads[i]:SetActive(true) end
end
itemlua.readyPad.text_title.text.text = title
itemlua.readyPad.readyitem:SetActive(false)
end
--回调事件,获取准备玩家的数据
function UILiveRoomView:ReadyPad_Head(itemlua, data)
local heads = {
[1] = itemlua.readyPad.head1.head_img,
[2] = itemlua.readyPad.head2.head_img,
[3] = itemlua.readyPad.head3.head_img,
[4] = itemlua.readyPad.head4.head_img,
[5] = itemlua.readyPad.head5.head_img,
[6] = itemlua.readyPad.head6.head_img,
[7] = itemlua.readyPad.head7.head_img,
[8] = itemlua.readyPad.head8.head_img,
[9] = itemlua.readyPad.head9.head_img,
[10] = itemlua.readyPad.head10.head_img,
}
if data ~= nil then
for i = 1, 10 do
if i <= #data then
local headpath = "PlayerHeads/player_head_" .. (data[i].head_id or 1)
self:LoadIcon_SetSprite(heads[i], headpath)
heads[i].gameObject:SetActive(true)
else
heads[i].gameObject:SetActive(false)
end
end
else
for i = 1, 10 do
heads[i].gameObject:SetActive(false)
end
end
end
--按钮,发送准备请求
function UILiveRoomView:OnReadyBtn(room_id)
--local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
--local room_id = data["room_id"]
ManagerContainer.DataMgr.LiveRoomData:GetReadyReq(room_id)
end
function UILiveRoomView:SetReadyItem(room_id, cfgid)
local itemlua = self:GetCurrPageLua()
if room_id == LIVEROOM_TYPE_SELL then
self:SetReadyItem_Sell(itemlua, cfgid)
elseif room_id == LIVEROOM_TYPE_BID then
self:SetReadyItem_Bid(itemlua, cfgid)
end
end
function UILiveRoomView:SetReadyItem_Sell(itemlua, id)
local readyitem = itemlua.readyPad.readyitem
local data = sellCfg[id] or {}
readyitem.title_bid:SetActive(false)
readyitem.title_sell:SetActive(false)
if data then
readyitem:SetActive(true)
readyitem.bg.image.sprite = readyitem.bg.switchSprite:GetSprite("bg_sell")
readyitem.title_sell:SetActive(true)
local name, coin1, coin2
name = data.Name
coin1 = string.split(data.Price, ":")[2]
coin2 = string.split(data.CutPrice, ":")[2]
readyitem.text_name.text.text = name
readyitem.text_info1.text.text = "原价: " .. coin1 .. "金币"
readyitem.text_info2.text.text = "秒杀价: " .. coin2 .. "金币"
for i = 1, 3 do
if data.Items[i] then
local info = {
cfgId = data.Items[i][1],
num = data.Items[i][2]
}
IconItemCtr:SetData(self, readyitem["item" .. i], info, Enum.ItemIEnterType.Bag, self,
self.OnClickIconItem)
else
readyitem["item" .. i]:SetActive(false)
end
end
else
readyitem:SetActive(false)
end
end
function UILiveRoomView:SetReadyItem_Bid(itemlua, id)
local readyitem = itemlua.readyPad.readyitem
local data = bidCfg[id] or {}
readyitem.title_bid:SetActive(false)
readyitem.title_sell:SetActive(false)
if data then
readyitem:SetActive(true)
readyitem.bg.image.sprite = readyitem.bg.switchSprite:GetSprite("bg_bid")
readyitem.title_bid:SetActive(true)
local name, coin1, coin2
name = data.Name
coin1 = string.split(data.Price, ":")[2]
coin2 = data.AddPrice
readyitem.text_name.text.text = name
readyitem.text_info1.text.text = "底价: " .. coin1 .. "金币"
readyitem.text_info2.text.text = "每次加价: ≥" .. coin2 .. "金币"
for i = 1, 3 do
if data.Items[i] then
local info = {
cfgId = data.Items[i][1],
num = data.Items[i][2]
}
IconItemCtr:SetData(self, readyitem["item" .. i], info, Enum.ItemIEnterType.Bag, self,
self.OnClickIconItem)
else
readyitem["item" .. i]:SetActive(false)
end
end
else
readyitem:SetActive(false)
end
end
--endregion 房间 准备
--region 房间 进行中
function UILiveRoomView:SetShowPad(itemlua, room_id)
local room_type = room_id
itemlua.showPad.rect_card:SetActive(false)
itemlua.showPad.rect_sell:SetActive(false)
itemlua.showPad.rect_answer:SetActive(false)
itemlua.showPad.rect_game:SetActive(false)
itemlua.showPad.rect_bid:SetActive(false)
if room_type == LIVEROOM_TYPE_CARD then
elseif room_type == LIVEROOM_TYPE_SELL then
elseif room_type == LIVEROOM_TYPE_ANSWER then
elseif room_type == LIVEROOM_TYPE_GAME then
--self:Show_Game_View(itemlua, nil)
elseif room_type == LIVEROOM_TYPE_BID then
end
end
function UILiveRoomView:Show_SendGameScore(room_id)
local uid = ManagerContainer.DataMgr.UserData:GetUserId()
local score = ManagerContainer.LuaGameMgr.FunnyGameScore
local submit_data = { { key = uid, value = tostring(score) } };
ManagerContainer.DataMgr.LiveRoomData:SubmitReq(room_id, submit_data)
end
--进行中 游戏
function UILiveRoomView:Show_Game_View(itemlua, data)
local r_game = itemlua.showPad.rect_game
r_game:SetActive(true)
local title = r_game.text_title
title.text.text = "小游戏实时分数"
local view_items = {
[1] = r_game.item1,
[2] = r_game.item2,
[3] = r_game.item3,
[4] = r_game.item4,
[5] = r_game.item5,
[6] = r_game.item6,
[7] = r_game.item7,
[8] = r_game.item8,
[9] = r_game.item9,
}
local scroedata
if data ~= nil then
scroedata = data or {}
--LogWarning("tzy_Show_Game_View_scroedata: " .. Inspect(scroedata))
for i = 1, 9 do
if i <= #scroedata then
local info = uid2info[scroedata[i].key]
--LogWarning("tzy_Show_Game_View_info: ".. Inspect(info))
local headpath = "PlayerHeads/player_head_" .. (info.head_id or 1)
self:LoadIcon_SetSprite(view_items[i].head_img, headpath)
view_items[i].head_img:SetActive(true)
view_items[i].text_name.text.text = info.name
view_items[i].text_score.text.text = scroedata[i].value
else
view_items[i].head_img:SetActive(false)
view_items[i].text_name.text.text = ""
view_items[i].text_score.text.text = ""
end
end
else
for i = 1, 9 do
view_items[i].head_img:SetActive(false)
view_items[i].text_name.text.text = ""
view_items[i].text_score.text.text = ""
end
end
end
--进行中 出售 仅配置 进度条默认0
function UILiveRoomView:Show_Sell_Cfg(itemlua, cfgid)
local r_sell = itemlua.showPad.rect_sell
r_sell:SetActive(true)
local items_go = {
[1] = r_sell.rect.item1,
[2] = r_sell.rect.item2,
[3] = r_sell.rect.item3,
}
local cfgdata = sellCfg[cfgid]
--LogWarning("tzy_sell 1: " .. data.key .. " " .. Inspect(data))
--LogWarning("tzy_sell 2: " .. Inspect(sellCfg))
LogWarning("tzy_sell 3: " .. Inspect(cfgdata))
local price_old = string.split(cfgdata.Price, ":")[2]
local price_new = string.split(cfgdata.CutPrice, ":")[2]
--名称
r_sell.text_name.text.text = cfgdata.Name
--购买数量进度条
local percent = 0 / cfgdata.SellNum
r_sell.bar_sellnum.slider.value = 0.08 + percent * 0.93
r_sell.text_sellnum1.text.text = "已抢" .. math.floor(percent * 100) .. "% "
r_sell.text_sellnum2.text.text = "已抢" .. math.floor(percent * 100) .. "% "
--价格
r_sell.text_coin_old.text.text = "原价" .. price_old .. "金币"
r_sell.text_coin_old.contentSizeFitter:SetLayoutHorizontal()
r_sell.text_coin_new.text.text = "秒杀价 <size={45}>" .. price_new .. "金币</size>"
--购买按钮
self.uiBase:AddButtonUniqueEventListener(r_sell.btn_buy.button, self, function()
--点击购买后逻辑
local coin = ManagerContainer.DataMgr.UserData:GetOwnCoin()
if coin < tonumber(price_new) then
--金币不足逻辑
return
end
local uid = ManagerContainer.DataMgr.UserData:GetUserId()
local submit_data = { { key = uid, value = "" } };
ManagerContainer.DataMgr.LiveRoomData:SubmitReq(LIVEROOM_TYPE_SELL, submit_data)
end)
--礼包大图 r_sell.rect.img_gift.image.sprite
--礼包iconitem
for i = 1, 3 do
if cfgdata.Items and cfgdata.Items[i] then
local info = {
cfgId = cfgdata.Items[i][1],
num = cfgdata.Items[i][2]
}
IconItemCtr:SetData(self, items_go[i], info, Enum.ItemIEnterType.Bag, self,
self.OnClickIconItem)
items_go[i]:SetActive(true)
else
items_go[i]:SetActive(false)
end
end
end
function UILiveRoomView:Show_Sell_Progress(itemlua, data)
local r_sell = itemlua.showPad.rect_sell
local cfgdata = sellCfg[data.key]
--购买数量进度条
local percent = data.value / cfgdata.SellNum
r_sell.bar_sellnum.slider.value = 0.08 + percent * 0.93
r_sell.text_sellnum1.text.text= "已抢".. math.floor(percent * 100).. "% "
r_sell.text_sellnum2.text.text= "已抢".. math.floor(percent * 100).. "% "
end
--进行中 竞拍 仅配置
function UILiveRoomView:Show_Bid_Cfg(itemlua, cfgid)
local r_bid = itemlua.showPad.rect_bid
r_bid:SetActive(true)
local items_go = {
[1] = r_bid.rect.item1,
[2] = r_bid.rect.item2,
[3] = r_bid.rect.item3,
}
local cfgdata = bidCfg[cfgid]
self.bid_price_base = tonumber(string.split(cfgdata.Price, ":")[2])
self.bid_price_add = cfgdata.AddPrice
self.bid_price_cur = self.bid_price_base
self.bid_price_curmax = 0
--名称
r_bid.text_name.text.text = cfgdata.Name
--竞拍
r_bid.text_bid1.text.text = "<size=45><color=#FF594F>" .. 0 .. "</color></size>金币"
r_bid.text_bid2.text.text = "<size=45><color=#FF594F>" .. 0 .. "</color></size>金币"
r_bid.text_num.text.text = self.bid_price_cur
for i = 1, 3 do
if cfgdata.Items and cfgdata.Items[i] then
local info = {
cfgId = cfgdata.Items[i][1],
num = cfgdata.Items[i][2]
}
IconItemCtr:SetData(self, items_go[i], info, Enum.ItemIEnterType.Bag, self,
self.OnClickIconItem)
items_go[i]:SetActive(true)
else
items_go[i]:SetActive(false)
end
end
--sub按钮
self.uiBase:AddButtonUniqueEventListener(r_bid.btn_sub.button, self, function()
self.bid_price_cur = self.bid_price_cur - self.bid_price_add
if self.bid_price_cur < self.bid_price_base then
self.bid_price_cur = self.bid_price_base
end
r_bid.text_num.text.text = tostring(self.bid_price_cur)
end)
--add按钮
self.uiBase:AddButtonUniqueEventListener(r_bid.btn_add.button, self, function()
self.bid_price_cur = self.bid_price_cur + self.bid_price_add
r_bid.text_num.text.text = tostring(self.bid_price_cur)
end)
--购买按钮
self.uiBase:AddButtonUniqueEventListener(r_bid.btn_buy.button, self, function()
--点击购买后逻辑
local coin = ManagerContainer.DataMgr.UserData:GetOwnCoin()
if coin < self.bid_price_cur then
--金币不足逻辑
return
end
local uid = ManagerContainer.DataMgr.UserData:GetUserId()
--LogWarning("tzy_show bid_price_cur1: " .. self.bid_price_cur)
local value = "" .. self.bid_price_cur
local submit_data = { { key = uid, value = value } };
ManagerContainer.DataMgr.LiveRoomData:SubmitReq(LIVEROOM_TYPE_BID, submit_data)
--LogWarning("tzy_show bid_price_cur2: " .. self.bid_price_cur)
end)
self.bid_rank = {}
r_bid.sv_bid.loopListView:Dispose()
r_bid.sv_bid.loopListView:InitListView(0,
function(loopview, index) return self:Gen_Bid_Rank_Item(loopview, index) end)
end
function UILiveRoomView:Gen_Bid_Rank_Item(loopview, index)
if index < 0 then return nil end
local item = loopview:NewListViewItem("LiveRoomBidRankItem")
local itemlua = CommonUtil.BindGridViewItem2Lua(self, "LiveRoomBidRankItem", item.gameObject)
local go = item.gameObject
go.name = "LiveRoomBidRankItem" .. index
local info = self.bid_rank[index + 1]
local headpath = "PlayerHeads/player_head_" .. info.head_id
self:LoadIcon_SetSprite(itemlua.head_img, headpath)
itemlua.text_name.text.text = info.name
itemlua.text_coin.text.text = "<size=35><color=#FF594F>" .. info.price .. "</color></size>金币"
return item
end
--列表和当前最高价格
function UILiveRoomView:Show_Bid_Rank(itemlua, data)
LogWarning("tzy_show_bid_rank: " .. Inspect(data))
local r_bid = itemlua.showPad.rect_bid
if data.show_data_list and data.show_data_list[1] then
local str_val = data.show_data_list[1].str_val
local head_id = string.split(string.split(str_val, ";")[1], ":")[2]
local name = string.split(string.split(str_val, ";")[2], ":")[2]
local info = {
head_id = head_id,
name = name,
price = data.show_data_list[1].value,
}
table.insert(self.bid_rank, 1, info)
LogWarning("tzy_show_bid_rank: " .. Inspect(self.bid_rank))
end
if #self.bid_rank > 10 then
r_bid.sv_bid.loopListView:SetListItemCount(10)
else
r_bid.sv_bid.loopListView:SetListItemCount(#self.bid_rank)
end
end
--个人最高
function UILiveRoomView:Show_Bid_Submit(itemlua, selfvalue, maxvalue, maxinfo)
local r_bid = itemlua.showPad.rect_bid
if selfvalue > self.bid_price_curmax then
self.bid_price_curmax = selfvalue
end
local price1 = maxvalue
local price2 = self.bid_price_curmax
local head_id = string.split(string.split(maxinfo, ";")[1], ":")[2]
local name = string.split(string.split(maxinfo, ";")[2], ":")[2]
r_bid.text_bid1.text.text = "" .. name .. "】<size=45><color=#FF594F>" .. price1 .. "</color></size>金币"
r_bid.text_bid2.text.text = "<size=45><color=#FF594F>" .. price2 .. "</color></size>金币"
end
function UILiveRoomView:Show_Answer_Cfg(itemlua, cfgid, opt_sort)
local r_answer = itemlua.showPad.rect_answer
local cfgdata = questionCfg[cfgid]
r_answer:SetActive(true)
r_answer.answer:SetActive(true)
r_answer.result:SetActive(false)
--题目左图 layout =1
local top1 = {
item = r_answer.top1,
img = r_answer.top1.img_q,
text = r_answer.top1.text_q,
}
--题目上图 layout =2
local top2 = {
item = r_answer.top2,
img = r_answer.top2.img_q,
text = r_answer.top2.text_q,
}
--题目文字 layout =3
local top3 = {
item = r_answer.top3,
text = r_answer.top3.text_q,
}
--选项 图片 .image .switchSprite .button .img.sprite
local op1 = {
[1] = r_answer.options1.item1,
[2] = r_answer.options1.item2,
[3] = r_answer.options1.item3,
[4] = r_answer.options1.item4
}
--选项 文字 .image .switchSprite .button .text.text
local op2 = {
[1] = r_answer.options2.item1,
[2] = r_answer.options2.item2,
[3] = r_answer.options2.item3,
[4] = r_answer.options2.item4
}
top1.item:SetActive(false)
top2.item:SetActive(false)
top3.item:SetActive(false)
r_answer.options1:SetActive(false)
r_answer.options2:SetActive(false)
if cfgdata.Layout == 1 then
top1.item:SetActive(true)
top1.text.text.text = cfgdata.Question
--local imgpath = "QuestionHeads/question_head_" .. cfgid
local imgpath = "LiveRoomQuestion/" .. cfgdata.QuestionPic
self:LoadIcon_SetSprite(top1.img, imgpath)
top1.img.image:SetNativeSize()
elseif cfgdata.Layout == 2 then
top2.item:SetActive(true)
top2.text.text.text = cfgdata.Question
--local imgpath = "QuestionHeads/question_head_" .. cfgid
local imgpath = "LiveRoomQuestion/" .. cfgdata.QuestionPic
self:LoadIcon_SetSprite(top2.img, imgpath)
top2.img.image:SetNativeSize()
elseif cfgdata.Layout == 3 then
top3.item:SetActive(true)
top3.text.text.text = cfgdata.Question
end
if cfgdata.Type == 1 then
r_answer.options1:SetActive(true)
for i = 1, 4 do
self:Show_Answer_SetOption(op1[i], 1, opt_sort[i], cfgid)
end
elseif cfgdata.Type == 2 then
r_answer.options2:SetActive(true)
for i = 1, 4 do
self:Show_Answer_SetOption(op2[i], 2, opt_sort[i], cfgid)
end
end
end
--s
function UILiveRoomView:Show_Answer_SetOption(item, type, index, cfgid)
--LogWarning("tzy_show_answer_: "..Inspect(item))
local data = questionCfg[cfgid]
--图片
if type == 1 then
--local imgpath=data["Option"..index.."Pic"]
local imgpath = "LiveRoomQuestion/" .. data["Option" .. index .. "Pic"]
self:LoadIcon_SetSprite(item.img, imgpath)
item.img.image:SetNativeSize()
--文字
elseif type == 2 then
local text = data["Option" .. index]
item.text.text.text = text
end
--点击
self.uiBase:AddButtonUniqueEventListener(item.button, self, function()
local value = "" .. index
local submit_data = { { key = cfgid, value = value } };
ManagerContainer.DataMgr.LiveRoomData:SubmitReq(LIVEROOM_TYPE_ANSWER, submit_data)
end)
end
function UILiveRoomView:Show_Answer_Result(itemlua, data)
local r_answer = itemlua.showPad.rect_answer.result
r_answer:SetActive(false)
local heads = {
[1] = r_answer.head1,
[2] = r_answer.head2,
[3] = r_answer.head3,
[4] = r_answer.head4,
[5] = r_answer.head5,
[6] = r_answer.head6,
[7] = r_answer.head7,
[8] = r_answer.head8,
[9] = r_answer.head9,
[10] = r_answer.head10,
}
if data ~= nil and #data.show_data_list > 0 then
r_answer:SetActive(true)
itemlua.showPad.rect_answer.answer:SetActive(false)
for i = 1, 10 do
if i <= #data.show_data_list then
local info = data.show_data_list[i]
heads[i]:SetActive(true)
--mark
heads[i].img_true:SetActive(false)
heads[i].img_false:SetActive(false)
if info.value == 1 then
heads[i].img_true:SetActive(true)
else
heads[i].img_false:SetActive(true)
end
local headpath = "PlayerHeads/player_head_" .. (uid2info[info.key].head_id or 1)
local name = uid2info[info.key].name or "初心者"
heads[i].text_name.text.text = name
self:LoadIcon_SetSprite(heads[i].img_head, headpath)
else
heads[i]:SetActive(false)
end
end
else
for i = 1, 10 do
heads[i]:SetActive(false)
end
end
end
--endregion 房间 进行中
--region 房间 结算
function UILiveRoomView:SetResultPad(itemlua, room_id)
local room_type = room_id
itemlua.resultPad.rect_card:SetActive(false)
itemlua.resultPad.rect_sell:SetActive(false)
itemlua.resultPad.rect_answer:SetActive(false)
itemlua.resultPad.rect_game:SetActive(false)
itemlua.resultPad.rect_bid:SetActive(false)
if room_type == LIVEROOM_TYPE_CARD then
self:Result_Card(itemlua, nil)
elseif room_type == LIVEROOM_TYPE_SELL then
self:Result_Sell(itemlua, nil)
elseif room_type == LIVEROOM_TYPE_ANSWER then
self:Result_Answer(itemlua, nil)
elseif room_type == LIVEROOM_TYPE_GAME then
self:Result_Game(itemlua, nil)
elseif room_type == LIVEROOM_TYPE_BID then
self:Result_Bid(itemlua, nil)
end
end
--结算 抽卡
function UILiveRoomView:Result_Card(itemlua, data)
local r_card = itemlua.resultPad.rect_card
r_card:SetActive(true)
local title = r_card.text_title
title.text.text = "测试抽卡结算信息"
local items = {
[1] = r_card.carditem1,
[2] = r_card.carditem2,
[3] = r_card.carditem3,
[4] = r_card.carditem4,
[5] = r_card.carditem5
}
local result_list
if data ~= nil then
result_list = data.player_reward_list or {}
for i = 1, 5 do
if i <= #result_list then
self:Result_Card_SetItem(items[i], result_list[i], i)
items[i]:SetActive(true)
else
self:Result_Card_SetItem(items[i], nil, i)
items[i]:SetActive(false)
end
end
else
for i = 1, 5 do
self:Result_Card_SetItem(items[i], nil, i)
items[i]:SetActive(false)
end
end
-- 先将所有25个物体的位置设置为x=1000
for row = 1, 5 do
for col = 1, 5 do
local item = items[row]["item" .. col]
local c = item.gameObject:GetComponent(Enum.TypeInfo.CanvasGroup)
c.alpha = 0
end
end
--动画
local seq = DG.Tweening.DOTween.Sequence() --:SetId("seq1"):Pause();
local seq_distance = 900
local seq_time = 0.12
for i = 1, 5 do
local t1 = items[1]["item" .. i]
local t1c = t1.gameObject:GetComponent(Enum.TypeInfo.CanvasGroup)
seq:Append(t1c:DOFade(1, 0))
seq:Append(t1.transform:DOLocalMoveX(seq_distance, seq_time):From())
local t2 = items[2]["item" .. i]
local t2c = t2.gameObject:GetComponent(Enum.TypeInfo.CanvasGroup)
seq:Append(t2c:DOFade(1, 0))
seq:Append(t2.transform:DOLocalMoveX(seq_distance, seq_time):From())
local t3 = items[3]["item" .. i]
local t3c = t3.gameObject:GetComponent(Enum.TypeInfo.CanvasGroup)
seq:Append(t3c:DOFade(1, 0))
seq:Append(t3.transform:DOLocalMoveX(seq_distance, seq_time):From())
local t4 = items[4]["item" .. i]
local t4c = t4.gameObject:GetComponent(Enum.TypeInfo.CanvasGroup)
seq:Append(t4c:DOFade(1, 0))
seq:Append(t4.transform:DOLocalMoveX(seq_distance, seq_time):From())
local t5 = items[5]["item" .. i]
local t5c = t5.gameObject:GetComponent(Enum.TypeInfo.CanvasGroup)
seq:Append(t5c:DOFade(1, 0))
seq:Append(t5.transform:DOLocalMoveX(seq_distance, seq_time):From())
seq:AppendInterval(0.15)
end
--DG.Tweening.DOTween.Play("seq1");
end
function UILiveRoomView:Result_Card_SetItem(itemlua, data, index)
local name = itemlua.text_name
local head = itemlua.head
local items = {
[1] = itemlua.item1,
[2] = itemlua.item2,
[3] = itemlua.item3,
[4] = itemlua.item4,
[5] = itemlua.item5,
}
-- 解析字符串格式的data
local reward_list = {}
if data ~= nil then
name.text.text = uid2info[data.key].name
local headpath = "PlayerHeads/player_head_" .. (uid2info[data.key].head_id or 1)
self:LoadIcon_SetSprite(head, headpath)
local reward_strs = string.split(data.str_val, ";")
for i, reward_str in ipairs(reward_strs) do
local cfgId, num = string.match(reward_str, "(%d+):(%d+)")
if cfgId and num then
reward_list[i] = {
cfgId = tonumber(cfgId),
num = tonumber(num)
}
end
end
--LogWarning("tzy_Result_Card_SetItem: " .. Inspect(reward_list))
for i = 1, 5 do
local reward = { cfgId = reward_list[i].cfgId, num = reward_list[i].num }
IconItemCtr:SetData(self, items[i], reward, Enum.ItemIEnterType.Bag, self,
self.OnClickIconItem)
end
end
end
--结算 出售
function UILiveRoomView:Result_Sell(itemlua, data)
local r_sell = itemlua.resultPad.rect_sell
r_sell:SetActive(true)
local heads = {
[1] = r_sell.head1,
[2] = r_sell.head2,
[3] = r_sell.head3,
[4] = r_sell.head4,
[5] = r_sell.head5,
[6] = r_sell.head6,
[7] = r_sell.head7,
[8] = r_sell.head8,
[9] = r_sell.head9,
[10] = r_sell.head10,
}
if data ~= nil then
local result_list = data.player_result_list or {}
for i = 1, 10 do
if i <= #result_list then
heads[i].text_name.text.text = result_list[i].nickname
local headpath = "PlayerHeads/player_head_" .. (result_list[i].head_id or 1)
self:LoadIcon_SetSprite(heads[i].img_head, headpath)
heads[i]:SetActive(true)
else
heads[i]:SetActive(false)
end
end
else
for i = 1, 10 do
heads[i]:SetActive(false)
end
end
end
--结算 答题
function UILiveRoomView:Result_Answer(itemlua, data)
local r_answer = itemlua.resultPad.rect_answer
r_answer:SetActive(true)
local heads = {
[1] = r_answer.head1,
[2] = r_answer.head2,
[3] = r_answer.head3,
[4] = r_answer.head4,
[5] = r_answer.head5,
[6] = r_answer.head6,
[7] = r_answer.head7,
[8] = r_answer.head8,
[9] = r_answer.head9,
[10] = r_answer.head10,
}
if data ~= nil then
r_answer:SetActive(true)
for i = 1, 10 do
if i <= #data.player_result_list then
local info = data.player_result_list[i]
heads[i]:SetActive(true)
--mark
heads[i].img_true:SetActive(false)
heads[i].img_false:SetActive(false)
if info.data == "1" then
heads[i].img_true:SetActive(true)
else
heads[i].img_false:SetActive(true)
end
local headpath = "PlayerHeads/player_head_" .. (uid2info[info.uid].head_id or 1)
local name = uid2info[info.uid].name or "初心者"
heads[i].text_name.text.text = name
self:LoadIcon_SetSprite(heads[i].img_head, headpath)
else
heads[i]:SetActive(false)
end
end
else
for i = 1, 10 do
heads[i]:SetActive(false)
end
end
end
--结算 游戏
function UILiveRoomView:Result_Game(itemlua, data)
local r_game = itemlua.resultPad.rect_game
r_game:SetActive(true)
local title = r_game.text_title
title.text.text = "小游戏结算信息"
local rank = r_game.rank
local rank_head = {
[1] = rank.head1.head_img,
[2] = rank.head2.head_img,
[3] = rank.head3.head_img,
[4] = rank.head4.head_img,
[5] = rank.head5.head_img,
[6] = rank.head6.head_img,
}
local rank_name = {
[1] = rank.name1,
[2] = rank.name2,
[3] = rank.name3,
[4] = rank.name4,
[5] = rank.name5,
[6] = rank.name6,
}
for i = 1, 6 do
self:LoadIcon_SetSprite(rank_head[i], "NpcHeads/npc_head_" .. i)
rank_name[i].text.text = "测试名称" .. i
end
local result_list, reward_list
if data ~= nil then
result_list = data.player_result_list or {}
reward_list = data.player_reward_list or {}
for i = 1, 3 do
if i <= #result_list then
local info = result_list[i]
local headpath = "PlayerHeads/player_head_" .. (info.head_id or 1)
self:LoadIcon_SetSprite(rank_head[i], headpath)
rank_head[i]:SetActive(true)
rank_name[i].text.text = info.nickname
self:LoadIcon_SetSprite(rank_head[i + 3], headpath)
rank_head[i + 3]:SetActive(true)
local rank_str
if i==1 then rank_str="S"
elseif i==2 then rank_str="A"
elseif i==3 then rank_str="B" end
rank_name[i + 3].text.text = ""..info.nickname.."】获得"..rank_str.."级奖励"
else
rank_head[i]:SetActive(false)
rank_name[i].text.text = ""
rank_head[i + 3]:SetActive(false)
rank_name[i + 3].text.text = ""
end
end
else
for i = 1, 6 do
rank_head[i]:SetActive(false)
rank_name[i].text.text = ""
end
end
end
--结算 拍卖
function UILiveRoomView:Result_Bid(itemlua, data)
local r_bid = itemlua.resultPad.rect_bid
r_bid:SetActive(true)
local heads = {
[1] = r_bid.head1,
[2] = r_bid.head2,
[3] = r_bid.head3,
[4] = r_bid.head4,
[5] = r_bid.head5,
}
if data ~= nil then
local result_list = data.player_result_list or {}
--价格
local price = string.split(string.split(result_list[1].data, ";")[1], ":")[2]
r_bid.text1.text.text = "以<size=45><color=#FF594F>" .. price .. "</color></size>金币的价格获得"
--头像
for i = 1, 5 do
if i <= #result_list then
heads[i].text_name.text.text = result_list[i].nickname
local headpath = "PlayerHeads/player_head_" .. (result_list[i].head_id or 1)
self:LoadIcon_SetSprite(heads[i].img_head, headpath)
heads[i]:SetActive(true)
else
heads[i]:SetActive(false)
end
end
else
for i = 1, 5 do
heads[i]:SetActive(false)
end
end
end
--结算 拍卖 仅配置
function UILiveRoomView:Result_Bid_Cfg(itemlua, cfgid)
local r_bid = itemlua.resultPad.rect_bid
local items_go = {
[1] = r_bid.item1,
[2] = r_bid.item2,
[3] = r_bid.item3,
}
local cfgdata = bidCfg[cfgid]
--名称
r_bid.text2.text.text = cfgdata.Name
for i = 1, 3 do
if cfgdata.Items and cfgdata.Items[i] then
local info = {
cfgId = cfgdata.Items[i][1],
num = cfgdata.Items[i][2]
}
IconItemCtr:SetData(self, items_go[i], info, Enum.ItemIEnterType.Bag, self,
self.OnClickIconItem)
items_go[i]:SetActive(true)
else
items_go[i]:SetActive(false)
end
end
end
--endregion 房间 结算
--region 计时器相关
local istimerhide=false
function UILiveRoomView:ResetStageTimer(timerVal)
self.currStageTimerVal = timerVal
if self.currStageTimer then
ManagerContainer.LuaTimerMgr:RemoveTimer(self.currStageTimer)
self.currStageTimer = nil
end
self:RefreshStageTimer(timerVal)
self.currStageTimer = ManagerContainer.LuaTimerMgr:AddTimer(1000, self.currStageTimerVal, self, self
.OnStageTimerTick, nil)
end
function UILiveRoomView:OnStageTimerTick()
self.currStageTimerVal = self.currStageTimerVal - 1
self:RefreshStageTimer(self.currStageTimerVal)
end
function UILiveRoomView:RefreshStageTimer(timerVal)
local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
local stage = data["stage"]
local itemLua = self:GetCurrPageLua()
local name
if stage == LIVEROOM_STAGE_IDLE then
name = "等待中"
elseif stage == LIVEROOM_STAGE_READY then
name = "准备中"
elseif stage == LIVEROOM_STAGE_SHOW then
name = "进行中"
elseif stage == LIVEROOM_STAGE_RESULT then
name = "结算中"
end
itemLua.timer.text_name.text.text = name
itemLua.timer.text_time.text.text = tostring(timerVal)
end
--endregion 计时器相关
return UILiveRoomView