2026.1.9 uiliveroom 聊天 礼物

This commit is contained in:
kongweiqiang 2026-01-09 18:22:44 +08:00
parent 0c5d5783f3
commit 7d9159a6c0
5 changed files with 136 additions and 65 deletions

View File

@ -5923,7 +5923,7 @@ MonoBehaviour:
mPadding: 15
mInitCreateCount: 0
mStartPosOffset: 0
mArrangeType: 1
mArrangeType: 0
mSupportScrollBar: 1
mItemSnapEnable: 0
mViewPortSnapPivot: {x: 0, y: 0}
@ -17994,7 +17994,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
@ -31704,7 +31704,7 @@ MonoBehaviour:
- UnityEngine.UI.ScrollRect
- SuperScrollView.LoopListView
- UINode
values: 000000000100
values: 000000010100
depObjs:
- {fileID: 4869549245558198530}
activeType: 0
@ -31722,7 +31722,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
@ -31752,7 +31752,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Content: {fileID: 1177608465212238478}
m_Horizontal: 0
m_Vertical: 1
m_Vertical: 0
m_MovementType: 1
m_Elasticity: 0.1
m_Inertia: 1
@ -31787,7 +31787,7 @@ MonoBehaviour:
mInitCreateCount: 0
mStartPosOffset: 0
mArrangeType: 0
mSupportScrollBar: 1
mSupportScrollBar: 0
mItemSnapEnable: 0
mViewPortSnapPivot: {x: 0, y: 0}
mItemSnapPivot: {x: 0, y: 0}

View File

@ -404,7 +404,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "\u793C\u7269\u540D\u79F0"
m_text:
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: ff9a33292f9ee2e4bb6b5beaa43eb505, type: 2}
m_sharedMaterial: {fileID: 21889736603187208, guid: ff9a33292f9ee2e4bb6b5beaa43eb505,
@ -540,7 +540,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 80de9912dc40c4244a2b78ff98f753bb, type: 3}
m_Type: 0
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4

View File

@ -15,7 +15,10 @@ function LiveRoomData:RegisterNetEvents()
self.data["stage_timer_sec"] = data.stage_timer_sec
self.data["stage_sec"] = data.stage_sec
self.data["rank"] = data.rank
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_JOIN_ACK)
self.data["gift_records"] = data.gift_records
self.data["chat_records"]=data.chat_datas
--LogWarning("tzy_chat_records: " .. Inspect(data))
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_JOIN_ACK,data.room_id)
LogError("SC_LIVE_ROOM_JOIN_ACK: join room_id=" .. data.room_id)
end
end)
@ -40,17 +43,19 @@ function LiveRoomData:RegisterNetEvents()
local idx = self.data.chatDataSN % CONST_MAX_CHAT_DATA_NUM + 1
self.data.chatData = self.data.chatData or {}
self.data.chatData[idx] = data["chat_data"]
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_CHAT_NTF, data.room_id)
--LogWarning("tzy_chat_ntf: ".. Inspect(data))
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_CHAT_NTF, data)
end)
--输入框 发送礼物
ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LIVE_ROOM_SEND_GIFT_ACK, function(data)
LogWarning("tzy_send_gift: " .. Inspect(data))
--LogWarning("tzy_send_gift: " .. Inspect(data))
end)
--收到礼物 回调
ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LIVE_ROOM_SEND_GIFT_NTF, function(data)
LogWarning("tzy_send_gift_ntf: " .. Inspect(data))
--LogWarning("tzy_send_gift_ntf: " .. Inspect(data))
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_SEND_GIFT_NTF, data)
end)
ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LIVE_ROOM_GIFT_RANK_ACK, function(data)
@ -110,13 +115,13 @@ function LiveRoomData:RegisterNetEvents()
--获取 进行中 数据
ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LIVE_ROOM_SHOW_DATA_NTF, function(data)
LogWarning("tzy_SC_LIVE_ROOM_SHOW_DATA_NTF: " .. Inspect(data))
--LogWarning("tzy_show: " .. Inspect(data))
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_SHOW_DATA_NTF, data)
end)
--获取 结果 数据
ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_LIVE_ROOM_RESULT_NTF, function(data)
LogWarning("tzy_SC_LIVE_ROOM_RESULT_NTF: " .. Inspect(data))
--LogWarning("tzy_result: " .. Inspect(data))
ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SC_LIVE_ROOM_RESULT_NTF, data)
end)
end

View File

@ -806,6 +806,7 @@
---@class LiveRoomItem__Generate_giftRank_sv_r_gift
---@field public gameObject UnityEngine.GameObject
---@field public scrollRect UnityEngine.UI.ScrollRect
---@field public loopListView SuperScrollView.LoopListView
---@class LiveRoomItem__Generate_giftRank_btn_month
@ -1479,6 +1480,8 @@ function LiveRoomItemView:InitGenerate__24(Root, data)
end
self.giftRank.sv_r_gift = tmp
tmp.scrollRect = tmp:GetComponent(Enum.TypeInfo.ScrollRect)
tmp.loopListView = tmp:GetComponent(Enum.TypeInfo.LoopListView)
end

View File

@ -14,7 +14,7 @@ local LIVEROOM_TYPE_BID = 5
local LIVEROOM_NUM = 5
local chatdata = {}
local uid2info = {}
@ -22,9 +22,23 @@ local liveRoomCfg = ManagerContainer.CfgMgr:GetLiveRoomCfg()
local talkCfg = ManagerContainer.CfgMgr:GetLiveRoomTalkCfg()
local giftCfg = ManagerContainer.CfgMgr:GetLiveRoomGiftCfg()
local chat_Records = {
[1] = {},
[2] = {},
[3] = {},
[4] = {},
[5] = {}
}
local gift_Records={
[1]={},
[2]={},
[3]={},
[4]={},
[5]={}
}
--region 生命周期
@ -54,8 +68,13 @@ end
function UILiveRoomView:AddEventListener()
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_JOIN_ACK, function()
--Join ack
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_JOIN_ACK,
function(id)
LogWarning("tzy_join_ack")
self:RefreshRoom()
self:ResetReceiveGift_OnJoin(id)
self:ResetChat_OnJoin(id)
end)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_LEAVE_ACK, function()
@ -79,9 +98,13 @@ function UILiveRoomView:AddEventListener()
self:ReadyPad_Head(itemlua, data.ready_player_info_list)
end)
--聊天 回调
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_CHAT_NTF,
function(room_id)
self:RefreshChatData(room_id)
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()
@ -98,14 +121,7 @@ function UILiveRoomView:AddEventListener()
function(data)
LogWarning("tzy_talk_ntf: " .. Inspect(data))
local info={}
for k, v in string.gmatch(data.talk_params, "([^;:]+):([^;]+)") do
-- 尝试将值转换为数字,如果失败则保留字符串
local num = tonumber(v)
info[k] = num or v
end
LogWarning("tzy_talk_ntf_info: ".. Inspect(info))
local info=self:String2Table(data.talk_params)
local itemlua = self:GetCurrPageLua()
self:Set_Streamer_Animation(data.room_id, info.act)
@ -133,6 +149,16 @@ function UILiveRoomView:AddEventListener()
self:Result_Game(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)
end
function UILiveRoomView:RemoveEventListener()
@ -225,10 +251,12 @@ function UILiveRoomView:GetLiveRoomItem(loopview, index)
local roomType = index2 + 1
self:InitReceiveGift(itemlua, roomType)
self:InitChat(itemlua, roomType)
self:ConfigRoom(itemlua, roomType)
self:SwitchRoom(itemlua)
self:InitChat(itemlua, roomType)
self:InitReceiveGift(itemlua, roomType)
self:SetReadyPad(itemlua, roomType)
self:SetShowPad(itemlua, roomType)
@ -265,6 +293,7 @@ function UILiveRoomView:SwitchRoom(liveRoomItemLua)
local oldRoomId = data["room_id"]
if oldRoomId then
ManagerContainer.DataMgr.LiveRoomData:LeaveReq(oldRoomId)
end
-- 加入新房间
ManagerContainer.DataMgr.LiveRoomData:JoinReq(roomType)
@ -479,7 +508,17 @@ end
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
@ -554,10 +593,25 @@ end
--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)
@ -566,14 +620,14 @@ function UILiveRoomView:InitChat(itemlua, room_id)
--表情
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)
@ -591,34 +645,35 @@ function UILiveRoomView:InitChat(itemlua, room_id)
end
function UILiveRoomView:GenChatItem(loopview, index, room_id)
local idx = 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
--LogWarning("InitChat2: " .. tostring(idx))
local id=index+1
if chatdata[idx] and chatdata[idx][index + 1] then
local chat = chatdata[idx][index + 1]
--LogWarning("chat" .. Inspect(chat))
local name = tostring(chat.player_info.nickname)
local vip = tostring(chat.player_info.vip_level)
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)
if name == "" then name = "初心者" end
local level = tostring(chat.player_info.level)
local content = chat.chat_content
local level = tostring(data.player_info.level)
local content = data.chat_content
itemlua.text_vip.text.text = vip
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)
@ -634,11 +689,6 @@ function UILiveRoomView:GenChatItem(loopview, index, room_id)
itemlua.rectTransform.sizeDelta = Vector2(1020, 85 * (linecount + 1))
end
--itemlua.contentSizeFitter:SetLayoutHorizontal()
--itemlua.contentSizeFitter:SetLayoutVertical()
end
return item
end
@ -651,7 +701,7 @@ function UILiveRoomView:GenRandomChatContent(room_id)
ManagerContainer.DataMgr.LiveRoomData:ChatReq(room_id)
end
chatdata[idx] = data
chat_Records[idx] = data
end
function UILiveRoomView:Btn_Send_Chat(itemlua, room_id)
@ -663,18 +713,7 @@ function UILiveRoomView:Btn_Send_Chat(itemlua, room_id)
itemlua.inputBar.inputfield_chat.tMP_InputField.text = ""
end
function UILiveRoomView:RefreshChatData(room_id)
--LogWarning("聊天回调: room_id: " .. room_id .. " talk_id: " .. talk_id .. " talk_params: " .. Inspect(talk_params))
local data = ManagerContainer.DataMgr.LiveRoomData:GetChatData()
--LogWarning("聊天回调: " .. Inspect(data))
chatdata[room_id] = data
--LogWarning("聊天回调 RefreshChatData: " .. Inspect(data))
local itemlua = self:GetCurrPageLua()
itemlua.sv_chat.loopListView:SetListItemCount(#data)
itemlua.sv_chat.loopListView:RefreshAllShownItem()
end
--endregion 房间 聊天 聊天
@ -773,7 +812,20 @@ end
--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
@ -806,8 +858,8 @@ function UILiveRoomView:InitReceiveGift(itemlua, room_id)
}
local curdata
loopview:InitListView(0, function(loopview, index) return self:Gen_Receive_Gift(loopview, index, curdata) end)
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()
@ -827,12 +879,23 @@ function UILiveRoomView:InitReceiveGift(itemlua, room_id)
end)
end
function UILiveRoomView:Gen_Receive_Gift(loopview, index, data)
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
itemlua.text_name.text.text = data[index + 1].name
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