Files
Endfield-Data/LuaScripts/UI/Panels/FriendBusinessCardRoot/FriendBusinessCardRootCtrl.lua
2025-12-02 20:37:18 +07:00

138 lines
3.3 KiB
Lua

local uiCtrl = require_ex('UI/Panels/Base/UICtrl')
local PANEL_ID = PanelId.FriendBusinessCardRoot
FriendBusinessCardRootCtrl = HL.Class('FriendBusinessCardRootCtrl', uiCtrl.UICtrl)
FriendBusinessCardRootCtrl.s_messages = HL.StaticField(HL.Table) << {
[MessageConst.ON_FRIEND_BUSINESS_INFO_CHANGE] = 'OnFriendBusinessInfoChange',
}
FriendBusinessCardRootCtrl.m_roleId = HL.Field(HL.Number) << 0
FriendBusinessCardRootCtrl.m_panel = HL.Field(HL.Userdata)
FriendBusinessCardRootCtrl.m_businessCard = HL.Field(HL.Forward('FriendBusinessCard'))
FriendBusinessCardRootCtrl.m_businessCardId = HL.Field(HL.String) << ''
FriendBusinessCardRootCtrl.OnCreate = HL.Override(HL.Any) << function(self, arg)
if arg and arg.roleId then
self.m_roleId = arg.roleId
else
self.m_roleId = GameInstance.player.roleId
end
self:_UpdateCardInfo()
end
FriendBusinessCardRootCtrl.OnPhaseRefresh = HL.Override(HL.Any) << function(self, args)
self:OnFriendBusinessInfoChange()
end
FriendBusinessCardRootCtrl._UpdateCardInfo = HL.Method() << function(self)
local success , friendInfo = GameInstance.player.friendSystem:TryGetFriendInfo(self.m_roleId)
if not success then
logger.error('FriendBusinessCardRootCtrl.OnCreate: Failed to get friend info for roleId: ' .. self.m_roleId)
friendInfo = GameInstance.player.friendSystem.SelfInfo
end
local businessCardId = friendInfo.businessCardTopicId
if self.m_businessCardId == businessCardId then
self.m_businessCard:InitFriendBusinessCard(self.m_roleId)
return
end
if self.m_panel then
self.view.controllerHintPlaceholder:InitControllerHintPlaceholder({
})
CSUtils.ClearUIComponents(self.m_panel)
GameObject.DestroyImmediate(self.m_panel)
self.m_phase:SetTabBlockState(false)
end
self.m_businessCardId = businessCardId
local success, cfg = Tables.businessCardTopicTable:TryGetValue(businessCardId)
if not success then
logger.error('FriendBusinessCardRootCtrl.OnCreate: Failed to get business card config for id: ' .. businessCardId)
return
end
local path = string.format(UIConst.UI_BUSINESS_CARD_PREFAB_PATH , cfg.panelPrefab)
local prefab = self:LoadGameObject(path)
self.m_panel = CSUtils.CreateObject(prefab, self.view.cardRoot)
self.m_businessCard = Utils.wrapLuaNode(self.m_panel)
self.m_businessCard:InitFriendBusinessCard(self.m_roleId)
self.m_businessCard.view.rightBottomBtn.onIsFocusedChange:RemoveAllListeners()
self.m_businessCard.view.rightBottomBtn.onIsFocusedChange:AddListener(function(isFocused)
self.m_phase:SetTabBlockState(isFocused)
end)
self.animationWrapper = self.m_businessCard.view.animationWrapper
self.m_businessCard.view.animationWrapper:PlayInAnimation()
if self.m_phase then
self.m_phase:_BindControllerHintPlaceHolder()
end
end
FriendBusinessCardRootCtrl.OnFriendBusinessInfoChange = HL.Method() << function(self)
self:_UpdateCardInfo()
end
FriendBusinessCardRootCtrl.OnShow = HL.Override() << function(self)
self.m_businessCard:InitFriendBusinessCard(self.m_roleId)
self.m_businessCard.view.animationWrapper:PlayInAnimation()
end
HL.Commit(FriendBusinessCardRootCtrl)