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.
This commit is contained in:
Kelsi 2026-03-21 01:26:37 -07:00
parent 22798d1c76
commit 32a51aa93d
3 changed files with 12 additions and 2 deletions

View file

@ -403,7 +403,7 @@ public:
bool hasFocus() const { return focusGuid != 0; } bool hasFocus() const { return focusGuid != 0; }
// Mouseover targeting — set each frame by the nameplate renderer // 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_; } uint64_t getMouseoverGuid() const { return mouseoverGuid_; }
// Advanced targeting // Advanced targeting

View file

@ -64,6 +64,7 @@ static uint64_t resolveUnitGuid(game::GameHandler* gh, const std::string& uid) {
if (uid == "player") return gh->getPlayerGuid(); if (uid == "player") return gh->getPlayerGuid();
if (uid == "target") return gh->getTargetGuid(); if (uid == "target") return gh->getTargetGuid();
if (uid == "focus") return gh->getFocusGuid(); if (uid == "focus") return gh->getFocusGuid();
if (uid == "mouseover") return gh->getMouseoverGuid();
if (uid == "pet") return gh->getPetGuid(); if (uid == "pet") return gh->getPetGuid();
// party1-party4, raid1-raid40 // party1-party4, raid1-raid40
if (uid.rfind("party", 0) == 0 && uid.size() > 5) { 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; 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) { static game::Unit* resolveUnit(lua_State* L, const char* unitId) {
auto* gh = getGameHandler(L); auto* gh = getGameHandler(L);
if (!gh || !unitId) return nullptr; if (!gh || !unitId) return nullptr;

View file

@ -13534,6 +13534,7 @@ std::shared_ptr<Entity> GameHandler::getTarget() const {
void GameHandler::setFocus(uint64_t guid) { void GameHandler::setFocus(uint64_t guid) {
focusGuid = guid; focusGuid = guid;
if (addonEventCallback_) addonEventCallback_("PLAYER_FOCUS_CHANGED", {});
if (guid != 0) { if (guid != 0) {
auto entity = entityManager.getEntity(guid); auto entity = entityManager.getEntity(guid);
if (entity) { if (entity) {
@ -13559,6 +13560,14 @@ void GameHandler::clearFocus() {
LOG_INFO("Focus cleared"); LOG_INFO("Focus cleared");
} }
focusGuid = 0; 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<Entity> GameHandler::getFocus() const { std::shared_ptr<Entity> GameHandler::getFocus() const {