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

161 lines
4.7 KiB
Lua

local UILiveRoomView = require("UILiveRoom/UILiveRoomView_Generate")
local LIVEROOM_TYPE_CARD = 1
local LIVEROOM_TYPE_SELL = 2
local LIVEROOM_TYPE_ANSWER = 3
local LIVEROOM_TYPE_GAME = 4
local LIVEROOM_NUM = 4
--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:InitRoom()
self:SetRoomCount(LIVEROOM_NUM)
self.upSafeOffset = UnityEngine.Screen.height - UnityEngine.Screen.safeArea.yMax
end
function UILiveRoomView:AddEventListener()
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_JOIN_ACK, function()
self:RefreshRoom()
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_CMD_TALK_NTF,
function(room_id, talk_id, talk_params)
--LogError("SC_LIVE_ROOM_STREAMER_TALK_NTF: talk_id=" .. talk_id)
end)
ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SC_LIVE_ROOM_STAGE_NTF, function()
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
function UILiveRoomView:OnCloseBtn()
self:UIClose()
end
--endregion 生命周期
--region 房间
function UILiveRoomView:InitRoom()
self.sv_room.loopListView:InitListView(-1,
function(loopview, index) return self:GetLiveRoomItem(loopview, index) end
)
end
function UILiveRoomView:GetLiveRoomItem(loopview, 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
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:ConfigRoom(itemlua, roomType)
self:SwitchRoom(itemlua)
return item
end
function UILiveRoomView:SetRoomCount(count)
self.roomCount = count
self.sv_room.loopListView:RefreshAllShownItem()
end
--endregion 房间
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 item = self.sv_room.loopListView:GetShownItemByItemIndex(pageId)
local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "LiveRoomItem", item.gameObject)
local roomType = pageId % self.roomCount + 1
LogError("SwitchRoom: roomType="..roomType)
self.currRoomLua = itemlua
-- 退出当前房间
local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
local oldRoomId = data["room_id"]
if oldRoomId then
self.controller:LeaveReq(oldRoomId)
end
-- 加入新房间
self.controller:JoinReq(roomType)
end)
end
function UILiveRoomView:ConfigRoom(itemLua, roomType)
local liveRoomCfg = ManagerContainer.CfgMgr:GetLiveRoomCfg()
local roomCfg = liveRoomCfg[roomType]
itemLua.roomTitleBar.roomName.text.text = roomCfg["RoomDesp"]
itemLua.roomTitleBar.streamerHead.nickname.text.text = roomCfg["Streamer"]
CommonUtil.LoadIcon(self, "PlayerHeads/"..roomCfg["StreamerHead"], function (sprite)
itemLua.roomTitleBar.streamerHead.headImg.image.sprite = sprite
end)
self.uiBase:AddButtonUniqueEventListener(itemLua.roomTitleBar.closeBtn.button, self, self.OnCloseBtn)
end
function UILiveRoomView:RefreshRoom()
local data = ManagerContainer.DataMgr.LiveRoomData:GetData()
local roomType = data["room_type"]
end
return UILiveRoomView