hengyang_client/lua_probject/base_project/Game/View/Lobby/LobbyHeadView.lua

168 lines
5.2 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
-- 玩家信息窗口(大厅点击头像进入)
local RealAddressView = import(".RealAddressView")
local PhoneBindView = import(".PhoneBindView")
local PhonePasswordView = import(".PhonePasswordView")
local WeChatView = import(".WeChatView")
local UserEditView = import(".UserEditView")
local LobbyHeadView = {}
local M = LobbyHeadView
2025-11-06 17:37:53 +08:00
function LobbyHeadView.new(user, agent, callback)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
2025-04-01 10:48:36 +08:00
self.class = "LobbyHeadView"
self._user = user
self._agent = agent
--self._full = true
self._full_offset = false
self._animation = false
self._put_map = false
2025-11-06 17:37:53 +08:00
self._new_hide = false
self._queue = false
2025-04-01 10:48:36 +08:00
self.callback = callback
self:init("ui://Lobby/UserInfo")
return self
end
function M:fill_item(item_name, title, callback)
local item = self.user_info:GetChild(item_name)
local btn_opt = item:GetChild("btn_opt")
local ctr_c1 = item:GetController("c1")
if title then
item.text = title
ctr_c1.selectedIndex = 1
end
2025-11-06 17:37:53 +08:00
btn_opt.onClick:Set(function()
2025-04-01 10:48:36 +08:00
callback()
end)
end
function M:fill_user_info()
local real_info = self._user.real_info
2025-11-06 17:37:53 +08:00
self:fill_item("item_real", real_info and real_info.name or nil, function()
local real_view = RealAddressView.new(0, function()
2025-04-01 10:48:36 +08:00
self:fill_user_info()
end)
real_view:Show()
end)
local address = self._user.address
2025-11-06 17:37:53 +08:00
self:fill_item("item_address", address, function()
local real_view = RealAddressView.new(1, function()
2025-04-01 10:48:36 +08:00
self:fill_user_info()
end)
real_view:Show()
end)
local phone = self._user.phone
2025-11-06 17:37:53 +08:00
self:fill_item("item_phone", phone and ViewUtil.phone_hide(phone) or nil, function()
local phone_view = PhoneBindView.new(function()
2025-04-01 10:48:36 +08:00
self:fill_user_info()
end)
phone_view:Show()
end)
local password = self._user.password
2025-11-06 17:37:53 +08:00
self:fill_item("item_password", password, function()
2025-04-01 10:48:36 +08:00
-- if not phone then
-- ViewUtil.ShowTips("请绑定手机号")
-- return
-- end
local pw_view = PhonePasswordView.new(function()
self:fill_user_info()
end)
pw_view:Show()
end)
local invitation = self._user.invitation
local item_invte = self.user_info:GetChild("item_invte")
local ctr_invte = item_invte:GetController("c1")
ctr_invte.selectedIndex = invitation
2025-11-06 17:37:53 +08:00
ctr_invte.onChanged:Set(function()
ViewUtil.ShowModalWait2()
2025-04-01 10:48:36 +08:00
local loddyctr = ControllerManager.GetController(LoddyController)
local _data = {}
2025-11-06 17:37:53 +08:00
_data.type = 5
2025-04-01 10:48:36 +08:00
_data.invitation = ctr_invte.selectedIndex
2025-11-06 17:37:53 +08:00
loddyctr:UpdateUserInfo(_data, function(res)
ViewUtil.CloseModalWait2()
if (res.ReturnCode == 0) then
2025-04-01 10:48:36 +08:00
DataManager.SelfUser.invitation = ctr_invte.selectedIndex
else
2025-11-06 17:37:53 +08:00
ViewUtil.ErrorTip(res.ReturnCode, "提交失败")
2025-04-01 10:48:36 +08:00
end
end)
end)
2025-11-06 17:37:53 +08:00
2025-04-01 10:48:36 +08:00
local acc = self._user.acc
2025-11-06 17:37:53 +08:00
self:fill_item("item_wx", acc and "(绑定:" .. self._user.nick_name .. ")" or "", function()
2025-04-01 10:48:36 +08:00
local wx_view = WeChatView.new(function()
self:fill_user_info()
end)
wx_view:Show()
end)
local _btn_logout = self._view:GetChild('btn_logout')
_btn_logout.onClick:Set(function()
local _curren_msg = MsgWindow.new(self._root_view, '您是否退出当前账号?', MsgWindow.MsgMode.OkAndCancel)
_curren_msg.onOk:Add(function()
PlayerPrefs.DeleteKey('session_id')
PlayerPrefs.Save()
RestartGame()
end)
_curren_msg:Show()
end)
end
function M:ChangeToLogin()
2025-11-06 17:37:53 +08:00
local _curren_msg = MsgWindow.new(self._root_view, '您是否退出当前账号?', MsgWindow.MsgMode.OkAndCancel)
_curren_msg.onOk:Add(function()
PlayerPrefs.DeleteKey('session_id')
PlayerPrefs.Save()
RestartGame()
end)
_curren_msg:Show()
2025-04-01 10:48:36 +08:00
end
function M:init(url)
2025-11-06 17:37:53 +08:00
BaseWindow.init(self, url)
2025-04-01 10:48:36 +08:00
self._close_destroy = true
self._close_zone = true
2025-11-06 17:37:53 +08:00
local view = self._view
2025-04-01 10:48:36 +08:00
local ctr_nav = view:GetController("nav")
--ctr_nav.selectedIndex = self._agent and 1 or 0
local ct_state = view:GetController("state")
view:GetChild("tex_nickname").text = self._user.nick_name
local str_playerid = self._user.account_id
2025-11-06 17:37:53 +08:00
view:GetChild("tex_id").text = "ID:" .. str_playerid
2025-04-01 10:48:36 +08:00
local btn_head = view:GetChild("btn_head")
ImageLoad.Load(self._user.head_url, btn_head._iconObject)
btn_head.onClick:Set(function()
local user_edit_view = UserEditView.new(function()
view:GetChild("tex_nickname").text = self._user.nick_name
ImageLoad.Load(self._user.head_url, btn_head._iconObject)
self.callback()
end)
user_edit_view:Show()
end)
local ctr_load = view:GetController("load")
local loddyCtr1 = ControllerManager.GetController(LoddyController)
loddyCtr1:GetUserInfo(function(res)
if res.ReturnCode == 0 then
ctr_load.selectedIndex = 1
self:fill_user_info()
end
end)
self.user_info = view:GetChild("user_info")
end
2025-11-06 17:37:53 +08:00
return M