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

121 lines
2.6 KiB
Lua

local uiCtrl = require_ex('UI/Panels/Base/UICtrl')
local PANEL_ID = PanelId.MouseIconHint
MouseIconHintCtrl = HL.Class('MouseIconHintCtrl', uiCtrl.UICtrl)
MouseIconHintCtrl.s_messages = HL.StaticField(HL.Table) << {
[MessageConst.CHANGE_MOUSE_ICON_HINT] = 'ChangeMouseIconHint',
[MessageConst.SHOW_HYPERLINK_TIPS] = 'ShowHyperlinkHoverIcon',
[MessageConst.HIDE_HYPERLINK_TIPS] = 'HideHyperlinkHoverIcon',
}
MouseIconHintCtrl.m_iconInfos = HL.Field(HL.Table)
MouseIconHintCtrl.m_nextPriority = HL.Field(HL.Number) << 0
MouseIconHintCtrl.OnCreate = HL.Override(HL.Any) << function(self, arg)
self.m_iconInfos = {}
self:_UpdateIcon()
end
MouseIconHintCtrl.OnClose = HL.Override() << function(self)
end
MouseIconHintCtrl.ChangeMouseIconHint = HL.Method(HL.Table) << function(self, args)
local name = args.name
local type = args.type
if type == UIConst.MOUSE_ICON_HINT.Default then
self.m_iconInfos[name] = nil
else
local oldInfo = self.m_iconInfos[name]
if oldInfo and oldInfo.type == type then
return
end
self.m_iconInfos[name] = {
name = name,
type = type,
hotspotPos = args.hotspotPos,
priority = self.m_nextPriority,
}
self.m_nextPriority = self.m_nextPriority + 1
end
self:_UpdateIcon()
end
MouseIconHintCtrl._UpdateIcon = HL.Method() << function(self)
local maxPriority = -1
local maxPriorityInfo
for _, v in pairs(self.m_iconInfos) do
if v.priority > maxPriority then
maxPriority = v.priority
maxPriorityInfo = v
end
end
local texName
local hotspotPos
if maxPriorityInfo then
texName = maxPriorityInfo.type
hotspotPos = maxPriorityInfo.hotspotPos or Vector2.zero
else
texName = UIConst.MOUSE_ICON_HINT.Default
hotspotPos = Vector2.zero
end
local tex = self.loader:LoadTexture(string.format("Assets/Beyond/DynamicAssets/Gameplay/UI/Textures/Mouse/%s.png", texName))
Unity.Cursor.SetCursor(tex, hotspotPos, Unity.CursorMode.Auto)
end
MouseIconHintCtrl.ShowHyperlinkHoverIcon = HL.Method(HL.Any) << function(self, _)
self:ChangeMouseIconHint({
name = "HyperlinkHover",
type = UIConst.MOUSE_ICON_HINT.Magnifier,
hotspotPos = Vector2(16, 16),
})
end
MouseIconHintCtrl.HideHyperlinkHoverIcon = HL.Method() << function(self)
self:ChangeMouseIconHint({
name = "HyperlinkHover",
type = UIConst.MOUSE_ICON_HINT.Default,
})
end
HL.Commit(MouseIconHintCtrl)