Logo

index : nswa

WoW addon which removes annoyances and adds QoL (for me)

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/nswa.git/html/nswa_which_dungeon.lua blob: 58eead9ca3f39c22396d607d8d64031cd713c734 [raw] [clear marker]

        
0
1
2-- Code for reference
3-- - When in a LFG group, get the ID first via `_, id = C_LFGList.GetActiveEntryInfo()`
4-- - Use the same id in `info = C_LFGList.GetActivityInfoTable(id)`
5-- - Then you have things like `info.name, info.mapID`
6
7
8local N = nswa
9
10-- TODO: Instead of having multiple frames, just put it in one or two frames and filter by event
11local frame = CreateFrame("Frame", "FrameActivity", UIParent)
12local frame_player = CreateFrame("Frame")
13local frame_lfg = CreateFrame("Frame")
14local frame_group = CreateFrame("Frame")
15
16local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
17
18local was_in_group = false
19local activity_label_is_moving = true
20local is_shown = false
21local text_label = "init"
22
23local INSTACE_TYPES_TO_CHECK = {
24 party = true,
25 raid = true,
26 pvp = true,
27 arena = true,
28 scenario = true,
29}
30
31
32--
33-- Local functions
34--
35
36
37local function move_enable()
38 text:SetText("MOVING")
39 frame:Show()
40 frame:EnableMouse(true)
41 frame:SetMovable(true)
42end
43
44local function move_disable()
45 if not is_shown then
46 frame:Hide()
47 end
48
49 text:SetText(text_label)
50 frame:EnableMouse(false)
51 frame:SetMovable(false)
52end
53
54function N.move_activity_label()
55 if activity_label_is_moving then
56 move_enable()
57 else
58 move_disable()
59 end
60
61 activity_label_is_moving = not activity_label_is_moving
62end
63
64local function activity_get_try()
65 local active_entry_info = C_LFGList.GetActiveEntryInfo()
66 if active_entry_info == nil then
67 return nil
68 end
69
70 local _, first_id = next(active_entry_info.activity_ids)
71 if first_id == nil then
72 return nil
73 end
74
75 local activity_info = C_LFGList.GetActivityInfoTable(first_id)
76 if activity_info == nil then
77 return nil
78 end
79
80 return activity_info.fullName, activity_info.mapID
81end
82
83local function activity_get()
84 local delay = 1
85 local max_tries = 3
86 local tries = 0
87
88 local function try_once()
89 tries = tries + 1
90
91 local name, map_id = activity_get_try()
92 if name ~= nil and map_id ~= nil then
93 return name, map_id
94 end
95
96 if tries < max_tries then
97 C_Timer.After(delay, try_once)
98 else
99 return "error", ""
100 end
101 end
102
103 return try_once()
104end
105
106local function activity_text_update(message)
107 if text == nil then
108 print("activity_text_update: nil")
109 return
110 end
111
112 text_label = message
113 is_shown = true
114 text:SetText(message)
115 frame:Show()
116end
117
118local function activity_text_destroy()
119 if text == nil then
120 print("activity_text_destroy: nil")
121 return
122 end
123
124 text_label = ""
125 is_shown = false
126 text:SetText("")
127 frame:Hide()
128end
129
130local function frames_unregister()
131 frame_lfg:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED")
132end
133
134local function lfg_info_get(callback)
135 frame_lfg:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED")
136 frame_lfg:SetScript("OnEvent", function(self, event, search_result_id)
137 local search_result_data = C_LFGList.GetSearchResultInfo(search_result_id)
138 local activity_ids = search_result_data.activityIDs
139
140 if not activity_ids then return end
141
142 local activity_id = activity_ids[1]
143 assert(activity_id, "activity_id")
144
145 local activity_info = C_LFGList.GetActivityInfoTable(activity_id)
146 local ai = activity_info
147 assert(ai, "activity_info")
148
149 callback(ai.fullName, ai.mapID)
150 frames_unregister()
151 end)
152end
153
154local function dispatch_lfg_info(activity_name, map_id)
155 activity_text_update(activity_name)
156 N.portals_info_create(map_id)
157end
158
159--
160-- Public functions
161--
162
163function N.destroy_activity_frame()
164 activity_text_destroy()
165 N.portals_info_destroy()
166 frames_unregister()
167end
168
169function N.init_activity_frame()
170 local DB = nswa_db
171
172 --
173 -- Init hook for activity info
174 --
175
176 LFGListInviteDialog:HookScript("OnShow", function(self)
177 lfg_info_get(function(activity_name, map_id)
178 dispatch_lfg_info(activity_name, map_id)
179 end)
180 end)
181
182 LFGListInviteDialog.DeclineButton:HookScript("OnClick", function(self)
183 N.destroy_activity_frame()
184 end)
185
186 --
187 -- Events
188 --
189 frame_player:RegisterEvent("PLAYER_ENTERING_WORLD")
190 frame_group:RegisterEvent("GROUP_ROSTER_UPDATE");
191
192 frame_player:SetScript("OnEvent", function(self, event, ...)
193 C_Timer.After(1, function()
194 local in_instance, instance_type = IsInInstance()
195
196 if in_instance and INSTACE_TYPES_TO_CHECK[instance_type] then
197 N.destroy_activity_frame()
198 end
199 end)
200 end)
201
202 frame_group:SetScript("OnEvent", function(self, event, ...)
203 C_Timer.After(0.5, function()
204 if not IsInGroup() and not IsInRaid() then
205 N.destroy_activity_frame()
206 end
207 end)
208 end)
209
210 --
211 -- Save / Restore position of info text
212 --
213
214 frame:SetSize(300, 50)
215 frame:RegisterForDrag("LeftButton")
216 frame:SetClampedToScreen(true)
217 is_shown = false
218 frame:Hide()
219
220 if DB.activity_state.pos.point then
221 frame:SetPoint(
222 DB.activity_state.pos.point,
223 UIParent,
224 DB.activity_state.pos.relPoint,
225 DB.activity_state.pos.x,
226 DB.activity_state.pos.y
227 )
228 else
229 frame:SetPoint("CENTER")
230 end
231
232 text:SetFont("Fonts\\FRIZQT__.TTF", 24)
233 text:SetTextColor(0, 1, 0)
234 text:SetPoint("CENTER")
235 text:SetText(text_label)
236
237 frame:SetScript("OnDragStop", function(self)
238 self:StopMovingOrSizing()
239 local point, _, relPoint, x, y = self:GetPoint()
240 DB.activity_state.pos.point = point
241 DB.activity_state.pos.relPoint = relPoint
242 DB.activity_state.pos.x = x
243 DB.activity_state.pos.y = y
244 -- DevTools_Dump(DB.activity_state)
245 end)
246
247 frame:SetScript("OnDragStart", function(self)
248 self:StartMoving()
249 end)
250
251 frame:SetScript("OnEvent", frame.OnEvent)
252end
253
254
255
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit