-- Code for reference -- - When in a LFG group, get the ID first via `_, id = C_LFGList.GetActiveEntryInfo()` -- - Use the same id in `info = C_LFGList.GetActivityInfoTable(id)` -- - Then you have things like `info.name, info.mapID` local N = nswa -- TODO: Instead of having multiple frames, just put it in one or two frames and filter by event local frame = CreateFrame("Frame", "FrameActivity", UIParent) local frame_player = CreateFrame("Frame") local frame_lfg = CreateFrame("Frame") local frame_group = CreateFrame("Frame") local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") local was_in_group = false local activity_label_is_moving = true local is_shown = false local text_label = "init" local INSTACE_TYPES_TO_CHECK = { party = true, raid = true, pvp = true, arena = true, scenario = true, } -- -- Local functions -- local function move_enable() text:SetText("MOVING") frame:Show() frame:EnableMouse(true) frame:SetMovable(true) end local function move_disable() if not is_shown then frame:Hide() end text:SetText(text_label) frame:EnableMouse(false) frame:SetMovable(false) end function N.move_activity_label() if activity_label_is_moving then move_enable() else move_disable() end activity_label_is_moving = not activity_label_is_moving end local function activity_get_try() local active_entry_info = C_LFGList.GetActiveEntryInfo() if active_entry_info == nil then return nil end local _, first_id = next(active_entry_info.activity_ids) if first_id == nil then return nil end local activity_info = C_LFGList.GetActivityInfoTable(first_id) if activity_info == nil then return nil end return activity_info.fullName, activity_info.mapID end local function activity_get() local delay = 1 local max_tries = 3 local tries = 0 local function try_once() tries = tries + 1 local name, map_id = activity_get_try() if name ~= nil and map_id ~= nil then return name, map_id end if tries < max_tries then C_Timer.After(delay, try_once) else return "error", "" end end return try_once() end local function activity_text_update(message) if text == nil then print("activity_text_update: nil") return end text_label = message is_shown = true text:SetText(message) frame:Show() end local function activity_text_destroy() if text == nil then print("activity_text_destroy: nil") return end text_label = "" is_shown = false text:SetText("") frame:Hide() end local function frames_unregister() frame_lfg:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED") end local function lfg_info_get(callback) frame_lfg:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED") frame_lfg:SetScript("OnEvent", function(self, event, search_result_id) local search_result_data = C_LFGList.GetSearchResultInfo(search_result_id) local activity_ids = search_result_data.activityIDs if not activity_ids then return end local activity_id = activity_ids[1] assert(activity_id, "activity_id") local activity_info = C_LFGList.GetActivityInfoTable(activity_id) local ai = activity_info assert(ai, "activity_info") callback(ai.fullName, ai.mapID) frames_unregister() end) end local function dispatch_lfg_info(activity_name, map_id) activity_text_update(activity_name) N.portals_info_create(map_id) end -- -- Public functions -- function N.destroy_activity_frame() activity_text_destroy() N.portals_info_destroy() frames_unregister() end function N.init_activity_frame() local DB = nswa_db -- -- Init hook for activity info -- LFGListInviteDialog:HookScript("OnShow", function(self) lfg_info_get(function(activity_name, map_id) dispatch_lfg_info(activity_name, map_id) end) end) LFGListInviteDialog.DeclineButton:HookScript("OnClick", function(self) N.destroy_activity_frame() end) -- -- Events -- frame_player:RegisterEvent("PLAYER_ENTERING_WORLD") frame_group:RegisterEvent("GROUP_ROSTER_UPDATE"); frame_player:SetScript("OnEvent", function(self, event, ...) C_Timer.After(1, function() local in_instance, instance_type = IsInInstance() if in_instance and INSTACE_TYPES_TO_CHECK[instance_type] then N.destroy_activity_frame() end end) end) frame_group:SetScript("OnEvent", function(self, event, ...) C_Timer.After(0.5, function() if not IsInGroup() and not IsInRaid() then N.destroy_activity_frame() end end) end) -- -- Save / Restore position of info text -- frame:SetSize(300, 50) frame:RegisterForDrag("LeftButton") frame:SetClampedToScreen(true) is_shown = false frame:Hide() if DB.activity_state.pos.point then frame:SetPoint( DB.activity_state.pos.point, UIParent, DB.activity_state.pos.relPoint, DB.activity_state.pos.x, DB.activity_state.pos.y ) else frame:SetPoint("CENTER") end text:SetFont("Fonts\\FRIZQT__.TTF", 24) text:SetTextColor(0, 1, 0) text:SetPoint("CENTER") text:SetText(text_label) frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() local point, _, relPoint, x, y = self:GetPoint() DB.activity_state.pos.point = point DB.activity_state.pos.relPoint = relPoint DB.activity_state.pos.x = x DB.activity_state.pos.y = y -- DevTools_Dump(DB.activity_state) end) frame:SetScript("OnDragStart", function(self) self:StartMoving() end) frame:SetScript("OnEvent", frame.OnEvent) end