From 32a51aa93d3c8b4ddc4a6e74f4d1244a9825ac2e Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 21 Mar 2026 01:26:37 -0700 Subject: [PATCH] feat: add mouseover unit ID support and fire UPDATE_MOUSEOVER_UNIT/PLAYER_FOCUS_CHANGED events Add "mouseover" as a valid unit ID in resolveUnitGuid so Lua API functions like UnitName("mouseover"), UnitHealth("mouseover") etc. work for addons. Fire UPDATE_MOUSEOVER_UNIT event when the mouseover target changes, and PLAYER_FOCUS_CHANGED event when focus is set or cleared. --- include/game/game_handler.hpp | 2 +- src/addons/lua_engine.cpp | 3 ++- src/game/game_handler.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/game/game_handler.hpp b/include/game/game_handler.hpp index 7c4e0918..97dd3103 100644 --- a/include/game/game_handler.hpp +++ b/include/game/game_handler.hpp @@ -403,7 +403,7 @@ public: bool hasFocus() const { return focusGuid != 0; } // Mouseover targeting — set each frame by the nameplate renderer - void setMouseoverGuid(uint64_t guid) { mouseoverGuid_ = guid; } + void setMouseoverGuid(uint64_t guid); uint64_t getMouseoverGuid() const { return mouseoverGuid_; } // Advanced targeting diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index e75d5359..546ffcc6 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -64,6 +64,7 @@ static uint64_t resolveUnitGuid(game::GameHandler* gh, const std::string& uid) { if (uid == "player") return gh->getPlayerGuid(); if (uid == "target") return gh->getTargetGuid(); if (uid == "focus") return gh->getFocusGuid(); + if (uid == "mouseover") return gh->getMouseoverGuid(); if (uid == "pet") return gh->getPetGuid(); // party1-party4, raid1-raid40 if (uid.rfind("party", 0) == 0 && uid.size() > 5) { @@ -91,7 +92,7 @@ static uint64_t resolveUnitGuid(game::GameHandler* gh, const std::string& uid) { return 0; } -// Helper: resolve "player", "target", "focus", "pet", "partyN", "raidN" unit IDs to entity +// Helper: resolve "player", "target", "focus", "mouseover", "pet", "partyN", "raidN" unit IDs to entity static game::Unit* resolveUnit(lua_State* L, const char* unitId) { auto* gh = getGameHandler(L); if (!gh || !unitId) return nullptr; diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 47f0756f..c4b2030b 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -13534,6 +13534,7 @@ std::shared_ptr GameHandler::getTarget() const { void GameHandler::setFocus(uint64_t guid) { focusGuid = guid; + if (addonEventCallback_) addonEventCallback_("PLAYER_FOCUS_CHANGED", {}); if (guid != 0) { auto entity = entityManager.getEntity(guid); if (entity) { @@ -13559,6 +13560,14 @@ void GameHandler::clearFocus() { LOG_INFO("Focus cleared"); } focusGuid = 0; + if (addonEventCallback_) addonEventCallback_("PLAYER_FOCUS_CHANGED", {}); +} + +void GameHandler::setMouseoverGuid(uint64_t guid) { + if (mouseoverGuid_ != guid) { + mouseoverGuid_ = guid; + if (addonEventCallback_) addonEventCallback_("UPDATE_MOUSEOVER_UNIT", {}); + } } std::shared_ptr GameHandler::getFocus() const {