hengyang_client/lua_probject/base_project/Game/View/LobbyView.lua

449 lines
15 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
--大厅View对象
--author--
local JoinRoomView = import(".Lobby.JoinRoomView")
local LobbySettingView = import(".Lobby.LobbySettingView")
local LobbyShopView = import(".Lobby.LobbyShopView")
local LobbyAuthenticateView = import(".Lobby.LobbyAuthenticateView")
local LobbyMessagesView = import(".Lobby.LobbyMessagesView")
local LobbyRecordView = import(".Lobby.LobbyRecordView")
local LobbyPlayerInfoView = import(".Lobby.LobbyPlayerInfoView")
local CreatePlayView = import(".Family.CreatePlayView")
2025-09-17 19:51:05 +08:00
local DiamondRecord = import(".Lobby.DiamondRecord")
local GamePlayDetail = import(".Lobby.GamePlayDetail")
2025-04-01 10:48:36 +08:00
local CreateRoomView = import(".Lobby.CreateRoomView")
local RankView = import(".Lobby.RankView")
local GroupMainView = import(".NewGroup.GroupMainView")
local NoticeView = import(".Lobby.NoticeView")
local HeadView = import(".Lobby.LobbyHeadView")
local PhoneBindView = import(".Lobby.PhoneBindView")
local RealAddressView = import(".Lobby.RealAddressView")
local LobbyHeadView = import(".Lobby.LobbyHeadView")
2025-10-16 16:26:09 +08:00
local LobbyGiftDiamond = import(".Lobby.LobbyGiftDiamond")
2025-10-17 18:30:44 +08:00
local LobbyService = import(".Lobby.LobbyService")
2025-04-01 10:48:36 +08:00
LobbyView = {}
local M = {}
function LobbyView.new()
2025-04-11 12:49:08 +08:00
-- -- print("new lobbyView!!!!")
2025-04-01 10:48:36 +08:00
setmetatable(M, { __index = BaseView })
local self = setmetatable({}, { __index = M })
self.class = "LobbyView"
UIPackage.AddPackage("base/lobby/ui/Lobby")
self.lobby_pause_time = 0
self._full = true
self:InitView("ui://Lobby/Main_New")
-- self._close_destroy = false
return self
end
function M:InitView(url)
2025-04-11 12:49:08 +08:00
-- -- print("init lobbyView!!!!")
2025-04-01 10:48:36 +08:00
BaseView.InitView(self, url)
self._full_offset = false
local view = self._view
2025-12-18 20:23:31 +08:00
-- local btn_joinroom = self._view:GetChild("btn_join")
-- btn_joinroom.onClick:Add(handler(self, self.OnJoinRoomAction))
2025-04-01 10:48:36 +08:00
local btn_setting = self._view:GetChild("btn_setting")
btn_setting.onClick:Set(handler(self, function()
local settingView = LobbySettingView.new()
settingView:Show()
end))
2025-12-18 20:23:31 +08:00
-- local btn_shop = self._view:GetChild("btn_shop")
-- btn_shop.onClick:Add(handler(self, function()
-- local shopView = LobbyShopView.new(function()
-- ViewUtil.ErrorTip(-1, "该功能还会开放,敬请期待")
-- -- self:ShowPlayerInfo(1, DataManager.SelfUser.diamo, 1)
-- end)
-- shopView:Show()
-- end))
-- local btn_authenticate = self._view:GetChild("btn_authenticate")
-- btn_authenticate.onClick:Add(handler(self, function()
-- local authenticateView = LobbyAuthenticateView.new()
-- -- ViewUtil.ErrorTip(-1, "该功能还会开放,敬请期待")
-- end))
-- local btn_notice = self._view:GetChild("btn_notice")
-- btn_notice.onClick:Set(function()
-- local diamondRecord = DiamondRecord.New(self._root_view)
-- -- noticeView:FillData(DataManager.SelfUser.notices.data)
-- diamondRecord:Show()
-- end)
2025-04-01 10:48:36 +08:00
2025-12-18 20:23:31 +08:00
-- local btn_record = self._view:GetChild("btn_record")
-- btn_record.onClick:Add(handler(self, function()
-- local lobbyRecordView = LobbyRecordView.new(self, true)
-- lobbyRecordView:Show()
-- end))
-- btn_record.displayObject.gameObject:SetActive(true)
-- local btn_gamePlay = self._view:GetChild("btn_gamePlay")
-- btn_gamePlay.onClick:Add(function()
-- local gamePlayDetail = GamePlayDetail.New()
-- gamePlayDetail:Show()
-- end)
2025-04-01 10:48:36 +08:00
2025-12-18 20:23:31 +08:00
-- local btn_more = self._view:GetChild("btn_more")
-- btn_more.onClick:Add(function()
-- ViewUtil.ErrorTip(self._view, "该功能还会开放,敬请期待")
-- end)
2025-04-01 10:48:36 +08:00
2025-09-13 22:45:23 +08:00
local clickTime = 0
2025-04-01 10:48:36 +08:00
local btn_family = self._view:GetChild("btn_family")
btn_family.onClick:Add(function()
2025-07-04 19:36:00 +08:00
local user = DataManager.SelfUser
if user.group_id ~= 0 then
self:ReconnectRoom(user.group_id)
return
2025-07-04 19:36:00 +08:00
end
2025-04-01 10:48:36 +08:00
ControllerManager.ChangeController(NewGroupController)
2025-12-18 20:23:31 +08:00
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GroupList(function(res)
end)
2025-04-01 10:48:36 +08:00
ViewManager.ChangeView(ViewManager.View_Family)
end)
2025-12-18 20:23:31 +08:00
-- local createRoomBtn = self._view:GetChild("btn_createRoom")
-- createRoomBtn.touchable = true
-- createRoomBtn.onClick:Set(function()
-- local _createRoomView = CreateRoomView.new(1)
-- _createRoomView.onCeateRoom = function()
-- ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id)
2025-04-10 11:19:20 +08:00
-- end
2025-12-18 20:23:31 +08:00
-- _createRoomView:Show()
2025-04-10 11:19:20 +08:00
-- end)
2025-04-01 10:48:36 +08:00
2025-12-18 20:23:31 +08:00
-- local btn_card = self._view:GetChild("btn_card")
-- btn_card.onClick:Add(function()
-- btn_card.touchable = false
-- btn_card:GetChild('n6').grayed = true
-- self:GetPlayerInfoData()
-- coroutine.start(function()
-- coroutine.wait(3)
-- btn_card.touchable = true
-- btn_card:GetChild('n6').grayed = false
-- end)
2025-04-01 10:48:36 +08:00
-- end)
2025-12-18 20:23:31 +08:00
-- local btn_customerService = self._view:GetChild("btn_customerService")
-- btn_customerService.onClick:Add(function()
-- local lobbyService = LobbyService.new()
-- -- lobbyService:Show()
-- end)
2025-04-01 10:48:36 +08:00
2025-12-18 20:23:31 +08:00
-- local btn_invite = self._view:GetChild("btn_invite")
-- btn_invite.onClick:Add(function()
-- GameApplication.Instance:CopyToClipboard(DataManager.DownLink or "暂无链接")
-- local _curren_msg = MsgWindow.new(self._root_view, "下载地址已复制,请到浏览器粘贴", MsgWindow.MsgMode.OnlyOk)
-- _curren_msg:Show()
-- end)
2025-04-01 10:48:36 +08:00
local btn_head = view:GetChild("btn_head")
2025-09-13 22:45:23 +08:00
ImageLoad.Load(DataManager.SelfUser.head_url, btn_head._iconObject, "Lobby", function()
printlog("load Callback")
self._flag_loadImageSucces = true
end)
2025-12-18 20:23:31 +08:00
-- btn_head.onClick:Set(function()
-- local lobbyPlayerInfoView = LobbyPlayerInfoView.new(DataManager.SelfUser, function()
-- ImageLoad.Load(DataManager.SelfUser.head_url, btn_head._iconObject)
-- end)
-- end)
2025-04-01 10:48:36 +08:00
2025-12-18 20:23:31 +08:00
-- local btn_teamwork = view:GetChild("btn_teamwork")
-- btn_teamwork.onClick:Set(function()
-- local lobbyHeadView = LobbyHeadView.new(DataManager.SelfUser, DataManager.SelfUser.agent, function()
-- ImageLoad.Load(DataManager.SelfUser.head_url, btn_head._iconObject)
-- end)
-- lobbyHeadView:Show()
-- end)
2025-04-01 10:48:36 +08:00
2025-07-23 15:40:53 +08:00
view:GetChild("tex_name").emojies = EmojiDitc.EmojiesDitc
2025-08-05 20:29:11 +08:00
view:GetChild("tex_name").text = Utils.TextOmit(DataManager.SelfUser.nick_name, 6, "...")
2025-10-16 16:26:09 +08:00
view:GetChild("tex_id").text = string.format("ID:%s", tostring(DataManager.SelfUser.account_id))
2025-04-01 10:48:36 +08:00
2025-12-18 20:23:31 +08:00
-- view:GetChild("btn_card").text = tostring(DataManager.SelfUser.diamo)
-- local btn_exit = self._view:GetChild("btn_exit")
-- btn_exit.onClick:Set(handler(self, function()
-- local _curren_msg = MsgWindow.new(self._root_view, '确认退出游戏', MsgWindow.MsgMode.OkAndCancel)
-- _curren_msg.onOk:Add(function()
-- Application.Quit()
-- end)
-- _curren_msg:Show()
-- end))
-- local message = self._view:GetChild("c_message")
-- self._message = message:GetChild("message")
-- self._tex_message = message:GetChild("text")
-- self:__GetMessage()
-- local btn_giftDiamond = self._view:GetChild('btn_giftDiamond')
-- if btn_giftDiamond then
-- btn_giftDiamond.visible = DataManager.SelfUser.type == 1
-- btn_giftDiamond.onClick:Set(function()
-- local lobbyGiftDiamond = LobbyGiftDiamond.new(nil, function()
-- view:GetChild("btn_card").text = tostring(DataManager.SelfUser.diamo)
2025-04-01 10:48:36 +08:00
-- end)
2025-12-18 20:23:31 +08:00
-- lobbyGiftDiamond:Show()
-- end)
-- end
--在大厅的时候就拉去一次亲友圈列表
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GroupList(function(res)
end)
2025-04-01 10:48:36 +08:00
end
function M:OnJoinRoomAction(context)
local joinRoomView = JoinRoomView.new(self._root_view)
joinRoomView:Show()
end
function M:__show_service()
local _buy_win = BaseWindow.new("ui://Lobby/Win_service", self._root_view)
_buy_win._close_destroy = true
_buy_win:Show()
local sview = _buy_win._view
local btn_copy = sview:GetChild("btn_copy")
btn_copy.onClick:Set(function()
GameApplication.Instance:CopyToClipboard("xbkf888108") --湘北
-- GameApplication.Instance:CopyToClipboard("ttwmq008")--fb
_buy_win:Destroy()
end)
end
function M:__GetMessage(data)
2025-08-15 15:55:21 +08:00
print("on GetMessage~~~~~~~~~~~~~~~~~~~~~~~~~~~")
2025-04-01 10:48:36 +08:00
if not data or not data.notice_list then
self._mesList = ""
else
local message = self._view:GetChild("com_message")
message.visible = true
local mesl = {}
for i = 1, #data.notice_list do
2025-08-23 16:07:53 +08:00
mesl[i] = data.notice_list[i] --.informContent
2025-04-01 10:48:36 +08:00
end
self._mesList = mesl
2025-08-15 19:35:15 +08:00
DataManager.GameNotice = mesl
2025-04-01 10:48:36 +08:00
end
self:__moveMsg(0)
end
function M:__PopMsg(index)
local num = #self._mesList
index = index + 1
if index > num then index = 1 end
local str = tostring(self._mesList[index])
if str == nil or str == "nil" then str = "" end
return index, string.gsub(str, "\r", "")
end
function M:__moveMsg(index)
2025-04-11 12:49:08 +08:00
-- -- print("on moveMsg!!!!!!!!!!!!!!!!!!!!!!!!!")
2025-04-01 10:48:36 +08:00
if not self._tex_message then return end
index, self._tex_message.text = self:__PopMsg(index)
self._tex_message.x = self._message.width
if self._mesTw then
TweenUtils.Kill(self._mesTw)
end
local change = -self._message.width * 2
local dd = self._tex_message.width / self._message.width
if dd < 1 then dd = 1 end
self._mesTw = TweenUtils.TweenFloat(0, 1 * dd, 10 * dd, function(value)
self._tex_message.x = self._message.width + (change * value)
end)
TweenUtils.OnComplete(self._mesTw, function()
self._mesTw = nil
if (#self._mesList == 0) then
self:__GetMessage()
else
self:__PopMsg(index)
self:__moveMsg(index)
end
end)
end
function M:__ShowShare()
local pop_share = self._view:GetChild("pop_share")
local shareUrl = GetGameInfo("invite_link") .. "?uid=" .. DataManager.SelfUser.account_id
2025-04-11 12:49:08 +08:00
---- print("shareUrl=================")
---- print(shareUrl)
2025-04-01 10:48:36 +08:00
local btn_wx_session = pop_share:GetChild("btn_wx_session")
btn_wx_session.onClick:Add(function()
shareQRCodePicture(shareUrl, 0)
end)
local btn_wx_line = pop_share:GetChild("btn_wx_line").asButton
btn_wx_line.onClick:Add(function()
shareQRCodePicture(shareUrl, 1)
end)
end
function M:OnUpdate()
local roomid = GameApplication.Instance:GetRoomID()
if roomid and string.len(roomid) > 1 then
ControllerManager.WebClient:clearActionQueue()
local joinRoomView = JoinRoomView.new(self._root_view)
joinRoomView:JoinRoom(roomid)
end
end
function M:Close()
BaseView.Close(self)
UpdateBeat:Remove(self.OnUpdate, self)
coroutine.stopAll()
if self._mesTw then
TweenUtils.Kill(self._mesTw)
end
BaseWindow.DestroyAll()
DSTweenManager.ClearTween()
end
function M:Destroy()
UpdateBeat:Remove(self.OnUpdate, self)
if self._mesTw then
TweenUtils.Kill(self._mesTw)
end
self._tex_message = nil
coroutine.stopAll()
BaseView.Destroy(self)
BaseWindow.DestroyAll()
DSTweenManager.ClearTween()
end
function M:Show()
2025-04-11 12:49:08 +08:00
---- print("on lobbyView show~~~~~~")
2025-04-01 10:48:36 +08:00
BaseView.Show(self)
ViewUtil.PlaySoundBg()
UpdateBeat:Add(self.OnUpdate, self)
-- 旧重连
--[[
2025-04-01 10:48:36 +08:00
-- 如果在圈子内的房间显示tip
local user = DataManager.SelfUser
local tem = user.notices
if user.group_id ~= 0 then
self:ReconnectRoom(user.group_id)
2025-04-01 10:48:36 +08:00
local msg_tip = MsgWindow.new(self._root_view, "还在圈子的房间中,现在重连吗?", MsgWindow.MsgMode.OkAndCancel)
msg_tip.onOk:Add(function()
self:ReconnectRoom(user.group_id)
2025-04-01 10:48:36 +08:00
end)
msg_tip:Show()
tem.auto_show = false
else
end
]]
2025-04-01 10:48:36 +08:00
2025-08-15 15:55:21 +08:00
local lobbyCtr1 = ControllerManager.GetController(LoddyController)
lobbyCtr1:UpdateNotice(DataManager.SelfUser.account_id, function(result, data)
-- local data1 = {}
-- data1.notice_list = {}
-- data1.notice_list[1] = "ccccccccccccccccccccccccccc"
if result then
self:__GetMessage(data)
end
end)
--self:GetPlayerInfoData()
2025-04-01 10:48:36 +08:00
-- 获取GPS坐标
if not DataManager.SelfUser.location or DataManager.SelfUser.location:Location2String() == "" then
get_gps()
end
if self.groupMainView and self.groupMainView._groupInfoView then
self.groupMainView._groupInfoView:hidePipei()
end
self:GetPlayerInfoData()
2025-04-01 10:48:36 +08:00
end
function M:GetPlayerInfoData()
local loddyCtr1 = ControllerManager.GetController(LoddyController)
loddyCtr1:UpdatePlayerInfo(function(result, data)
if result then
self:ShowPlayerInfo(data.raffle, data.diamo, data.newMail)
if data.group_id ~= 0 then
2025-09-13 22:45:23 +08:00
-- 重连,确保头像加载成功才能重连
2025-09-17 19:51:05 +08:00
self:ReconnectRoom(data.groupId)
end
2025-04-01 10:48:36 +08:00
end
end)
end
function M:ShowPlayerInfo(raffle, diamo, newMail)
2025-12-18 20:23:31 +08:00
self._view:GetChild("btn_card").text = diamo or 0
2025-04-01 10:48:36 +08:00
end
function M:OnApplicationPause()
ControllerManager.WebClient:clearActionQueue()
-- 切后台时间
if DataManager.SelfUser.cur_group then
self.lobby_pause_time = os.time()
DataManager.SelfUser.cur_group.pause = true
end
end
function M:OnApplicationActive()
ControllerManager.WebClient:clearActionQueue()
self:GetPlayerInfoData()
-- 切后台太久牌友圈重连
if DataManager.SelfUser.cur_group then
DataManager.SelfUser.cur_group.pause = false
if os.time() - self.lobby_pause_time > 15 then
self.lobby_pause_time = os.time()
DataManager.SelfUser.cur_group:Reconnect()
end
end
end
-----------------------lingmeng----------------------------
function M:ReconnectRoom(groupId)
local roomId = DataManager.SelfUser.room_id
print("===============================ReconnectRoom", roomId, 1)
if roomId and #roomId > 0 then
local roomCtr = ControllerManager.GetController(RoomController)
roomCtr:PublicJoinRoom(
Protocol.WEB_FG_JOIN_ROOM,
roomId,
false,
function(response)
if (response.ReturnCode == -1) then
ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, 'response.ReturnCode == -1')
RestartGame()
return
end
if response.ReturnCode ~= 0 then
ViewUtil.ErrorMsg(self._root_view, response.ReturnCode, '进入房间失败')
2025-08-23 16:07:53 +08:00
FamilyView.lastId = groupId
2025-10-14 20:44:57 +08:00
ViewManager.ChangeView(ViewManager.View_Lobby)
return
else
2025-08-23 16:07:53 +08:00
FamilyView.lastId = groupId
2025-09-03 16:52:14 +08:00
DataManager.SelfUser.room_id = ""
ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id)
end
end,
groupId
)
end
end
-----------------------------------------------------------