-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDifficultBulletinBoard.lua
More file actions
516 lines (444 loc) · 18.9 KB
/
DifficultBulletinBoard.lua
File metadata and controls
516 lines (444 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
-- Create main addon namespace
DBB2 = CreateFrame("Frame", nil, UIParent)
DBB2:RegisterEvent("ADDON_LOADED")
DBB2:RegisterEvent("PLAYER_ENTERING_WORLD")
DBB2:RegisterEvent("CHAT_MSG_CHANNEL")
DBB2:RegisterEvent("CHAT_MSG_GUILD")
DBB2:RegisterEvent("CHAT_MSG_SAY")
DBB2:RegisterEvent("CHAT_MSG_YELL")
DBB2:RegisterEvent("CHAT_MSG_PARTY")
DBB2:RegisterEvent("CHAT_MSG_WHISPER")
DBB2:RegisterEvent("CHAT_MSG_SYSTEM")
DBB2:RegisterEvent("UPDATE_INSTANCE_INFO")
DBB2:RegisterEvent("CHAT_MSG_HARDCORE") -- Turtle WoW hardcore chat
DBB2:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE") -- Channel join/leave notifications
DBB2:RegisterEvent("PARTY_MEMBERS_CHANGED") -- Party join/leave for notification clearing
DBB2:RegisterEvent("RAID_ROSTER_UPDATE") -- Raid join/leave for notification clearing
-- Initialize saved variables
DBB2_Config = {}
-- Initialize addon tables
DBB2.messages = {}
DBB2.modules = {}
DBB2.api = {} -- Initialize API table
DBB2.pendingMessages = {} -- Queue for messages to display after login
-- Store minimap button angle
if not DBB2_Config.minimapAngle then
DBB2_Config.minimapAngle = 45
end
-- Backdrop definitions
DBB2.backdrop = {
bgFile = "Interface\\BUTTONS\\WHITE8X8",
tile = false,
tileSize = 0,
edgeFile = "Interface\\BUTTONS\\WHITE8X8",
edgeSize = 1,
insets = {left = -1, right = -1, top = -1, bottom = -1},
}
DBB2.backdrop_shadow = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 8,
insets = {left = 0, right = 0, top = 0, bottom = 0},
}
-- Helper function to create backdrop
-- useFixedBg: if true, uses the default dark charcoal instead of configurable color
function DBB2:CreateBackdrop(frame, inset, legacy, transp, useFixedBg)
local border = 1
-- Use configurable background color (with fallback to default dark charcoal)
-- Unless useFixedBg is true, then always use the default
local br, bg, bb, ba
if useFixedBg then
br, bg, bb, ba = 0.08, 0.08, 0.10, 0.85
else
local bgColor = DBB2_Config.backgroundColor or {r = 0.08, g = 0.08, b = 0.10, a = 0.85}
br, bg, bb, ba = bgColor.r, bgColor.g, bgColor.b, bgColor.a or 0.85
end
local er, eg, eb, ea = 0.25, 0.25, 0.25, 1 -- Border: subtle gray
-- Override transparency if specified
if transp and transp < ba then ba = transp end
if not frame.backdrop then
local b = CreateFrame("Frame", nil, frame)
local level = frame:GetFrameLevel()
if level < 1 then
b:SetFrameLevel(level)
else
b:SetFrameLevel(level - 1)
end
frame.backdrop = b
end
frame.backdrop:SetPoint("TOPLEFT", frame, "TOPLEFT", -border, border)
frame.backdrop:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", border, -border)
frame.backdrop:SetBackdrop(DBB2.backdrop)
frame.backdrop:SetBackdropColor(br, bg, bb, ba)
frame.backdrop:SetBackdropBorderColor(er, eg, eb, ea)
end
-- Helper function to create shadow
function DBB2:CreateBackdropShadow(frame)
if frame.backdrop_shadow then return end
local anchor = frame.backdrop or frame
frame.backdrop_shadow = CreateFrame("Frame", nil, anchor)
frame.backdrop_shadow:SetFrameStrata("BACKGROUND")
frame.backdrop_shadow:SetFrameLevel(1)
frame.backdrop_shadow:SetPoint("TOPLEFT", anchor, "TOPLEFT", -5, 5)
frame.backdrop_shadow:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 5, -5)
frame.backdrop_shadow:SetBackdrop(DBB2.backdrop_shadow)
frame.backdrop_shadow:SetBackdropBorderColor(0, 0, 0, 0.8)
end
-- Helper function to queue a message for display after login
-- Used by modules that run during ADDON_LOADED when chat frame may not be ready
function DBB2:QueueMessage(msg)
table.insert(DBB2.pendingMessages, msg)
end
-- Event handler
DBB2:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == "DifficultBulletinBoard" then
-- Initialize config with defaults if needed
DBB2_Config = DBB2_Config or {}
if not DBB2_Config.initialized then
DBB2_Config.initialized = true
DBB2_Config.version = "1.0.0"
DBB2_Config.position = {}
DBB2_Config.fontOffset = 0 -- Font size offset (-6 to +6)
DBB2_Config.highlightColor = {r = 0.667, g = 0.655, b = 0.8, a = 1} -- Default highlight color (#aaa7cc)
DBB2_Config.backgroundColor = {r = 0.08, g = 0.08, b = 0.10, a = 0.85} -- Default background color (dark charcoal)
DBB2_Config.spamFilterSeconds = 150 -- Duplicate message filter time
DBB2_Config.messageExpireMinutes = 15 -- Auto-remove messages older than X minutes (0 = disabled)
DBB2_Config.hideFromChat = 0 -- Hide captured messages from chat (0=off, 1=selected, 2=all)
DBB2_Config.maxMessagesPerCategory = 5 -- Max messages shown per category (0 = unlimited)
DBB2_Config.scrollSpeed = 55 -- Scroll speed (pixels per wheel tick)
DBB2_Config.defaultTab = 0 -- Default tab (0=Logs, 1=Groups, 2=Professions, 3=Hardcore)
DBB2_Config.showCurrentTime = true -- Show current time above timestamps
DBB2_Config.timeDisplayMode = 2 -- Time format (0=timestamp, 1=relative, 2=elapsed)
DBB2_Config.showLevelFilteredGroups = false -- Level filter for groups tab
DBB2_Config.showGroupLevelRanges = true -- Show recommended dungeon level ranges in Groups tab
DBB2_Config.notificationSound = 1 -- Notification sound (0=off, 1=on)
DBB2_Config.clearNotificationsOnGroupJoin = true -- Clear notifications when joining group
DBB2_Config.autoJoinChannels = true -- Auto-join World and LFG channels
DBB2_Config.minimapAngle = 45 -- Minimap button angle
DBB2_Config.minimapFreeMode = false -- Minimap button free positioning mode
DBB2_Config.clampToScreen = true -- Prevent dragging frames off-screen
DBB2_Config.closeOnEscape = true -- Allow the Escape key to close the main window
end
-- Ensure fontOffset exists for existing configs and is within safe bounds
if DBB2_Config.fontOffset == nil or type(DBB2_Config.fontOffset) ~= "number" then
DBB2_Config.fontOffset = 0
end
-- Clamp fontOffset to safe range (-6 to +6) to prevent crashes
if DBB2_Config.fontOffset < -6 then
DBB2_Config.fontOffset = -6
elseif DBB2_Config.fontOffset > 6 then
DBB2_Config.fontOffset = 6
end
-- Ensure highlightColor exists for existing configs
if DBB2_Config.highlightColor == nil then
DBB2_Config.highlightColor = {r = 0.667, g = 0.655, b = 0.8, a = 1}
end
-- Ensure backgroundColor exists for existing configs
if DBB2_Config.backgroundColor == nil then
DBB2_Config.backgroundColor = {r = 0.08, g = 0.08, b = 0.10, a = 0.85}
end
-- Ensure spamFilterSeconds exists for existing configs
if DBB2_Config.spamFilterSeconds == nil then
DBB2_Config.spamFilterSeconds = 150
end
-- Ensure maxMessagesPerCategory exists for existing configs
if DBB2_Config.maxMessagesPerCategory == nil then
DBB2_Config.maxMessagesPerCategory = 5
end
-- Ensure messageExpireMinutes exists for existing configs
if DBB2_Config.messageExpireMinutes == nil then
DBB2_Config.messageExpireMinutes = 15
end
-- Ensure hideFromChat exists for existing configs (migrate boolean to number)
if DBB2_Config.hideFromChat == nil then
DBB2_Config.hideFromChat = 0
elseif DBB2_Config.hideFromChat == true then
DBB2_Config.hideFromChat = 1
elseif DBB2_Config.hideFromChat == false then
DBB2_Config.hideFromChat = 0
end
-- Ensure scrollSpeed exists for existing configs
if DBB2_Config.scrollSpeed == nil then
DBB2_Config.scrollSpeed = 55
end
-- Ensure showLevelFilteredGroups exists for existing configs (default off)
if DBB2_Config.showLevelFilteredGroups == nil then
DBB2_Config.showLevelFilteredGroups = false
end
-- Ensure showGroupLevelRanges exists for existing configs (default on)
if DBB2_Config.showGroupLevelRanges == nil then
DBB2_Config.showGroupLevelRanges = true
end
-- Ensure autoJoinChannels exists for existing configs (default on)
if DBB2_Config.autoJoinChannels == nil then
DBB2_Config.autoJoinChannels = true
end
-- Ensure defaultTab exists for existing configs (default 0 = Logs)
if DBB2_Config.defaultTab == nil then
DBB2_Config.defaultTab = 0
end
-- Ensure showCurrentTime exists for existing configs (default on)
if DBB2_Config.showCurrentTime == nil then
DBB2_Config.showCurrentTime = true
end
-- Ensure timeDisplayMode exists for existing configs (default elapsed)
if DBB2_Config.timeDisplayMode == nil then
DBB2_Config.timeDisplayMode = 2
end
-- Ensure notificationSound exists for existing configs (default on)
if DBB2_Config.notificationSound == nil then
DBB2_Config.notificationSound = 1
end
-- Ensure clearNotificationsOnGroupJoin exists for existing configs (default on)
if DBB2_Config.clearNotificationsOnGroupJoin == nil then
DBB2_Config.clearNotificationsOnGroupJoin = true
end
-- Ensure minimap button position fields exist for existing configs
if DBB2_Config.minimapAngle == nil then
DBB2_Config.minimapAngle = 45
end
if DBB2_Config.minimapFreeMode == nil then
DBB2_Config.minimapFreeMode = false
end
-- minimapFreePos can be nil (means not in free mode)
-- Ensure clampToScreen exists for existing configs (default on)
if DBB2_Config.clampToScreen == nil then
DBB2_Config.clampToScreen = true
end
-- Ensure closeOnEscape exists for existing configs (default on)
if DBB2_Config.closeOnEscape == nil then
DBB2_Config.closeOnEscape = true
end
-- Load modules (use ipairs to preserve load order from TOC file)
for i, module in ipairs(DBB2.modules) do
if module then
module()
end
end
-- Initialize notification state (session-only, all off by default)
DBB2.api.InitNotificationState()
-- Setup chat filter hook for hiding captured messages
DBB2.api.SetupChatFilter()
-- Initialize lockout tracking
DBB2.api.InitLockouts()
-- Initialize channel monitoring config
DBB2.api.InitChannelConfig()
DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccDifficult|cffffffffBulletinBoard |cff555555v" .. (GetAddOnMetadata("DifficultBulletinBoard", "Version") or "?") .. "|r loaded. Click minimap button to open.")
end
if event == "PLAYER_ENTERING_WORLD" then
-- Display any queued messages from module initialization
if table.getn(DBB2.pendingMessages) > 0 then
for _, msg in ipairs(DBB2.pendingMessages) do
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
DBB2.pendingMessages = {}
end
-- Clear hardcore detection cache to force fresh detection on each login/switch
DBB2_Config.isHardcoreCharacter = nil
local isHardcore = DBB2.api.DetectHardcoreCharacter()
-- For hardcore characters, apply defaults ONLY if user hasn't customized channels yet
-- Once user makes any change, their preferences are saved like normal characters
if isHardcore and not DBB2_Config.hardcoreChannelsInitialized then
DBB2_Config.hardcoreChannelsInitialized = true
DBB2.api.SetChannelMonitored("World", false)
DBB2.api.SetChannelMonitored("LookingForGroup", false)
DBB2.api.SetChannelMonitored("General", false)
DBB2.api.SetChannelMonitored("Trade", false)
DBB2.api.SetChannelMonitored("Say", false)
DBB2.api.SetChannelMonitored("Yell", false)
DBB2.api.SetChannelMonitored("Whisper", false)
DBB2.api.SetChannelMonitored("Party", false)
DBB2.api.SetChannelMonitored("LocalDefense", false)
DBB2.api.SetChannelMonitored("WorldDefense", false)
DBB2.api.SetChannelMonitored("GuildRecruitment", false)
end
-- Rebuild channel config panel if it exists (updates states)
if DBB2.gui and DBB2.gui.configTabs and DBB2.gui.configTabs.panels then
local channelsPanel = DBB2.gui.configTabs.panels["Channels"]
if channelsPanel and channelsPanel.RebuildChannelCheckboxes then
channelsPanel.RebuildChannelCheckboxes()
end
end
-- Auto-join required channels (World, LookingForGroup) if not already joined
-- Use a small delay to ensure channel system is ready
if not DBB2._autoJoinScheduled then
DBB2._autoJoinScheduled = true
-- Create a frame for the delayed call
local delayFrame = CreateFrame("Frame")
delayFrame.elapsed = 0
delayFrame:SetScript("OnUpdate", function()
this.elapsed = this.elapsed + arg1
if this.elapsed >= 2 then -- 2 second delay
DBB2.api.AutoJoinRequiredChannels()
this:SetScript("OnUpdate", nil)
this:Hide()
end
end)
end
end
if event == "CHAT_MSG_CHANNEL" or event == "CHAT_MSG_GUILD" then
-- Capture chat messages using API
local message = arg1
local sender = arg2
local channel = arg9 or "Guild"
-- For Guild messages, check if Guild channel is monitored
if event == "CHAT_MSG_GUILD" then
if not DBB2.api.IsChannelMonitored("Guild") then
return -- Guild channel not monitored, ignore
end
end
-- For channel messages, only capture from whitelisted LFG-relevant channels
-- This automatically filters out addon channels like TTRP, XTENSIONXTOOLTIP, etc.
if event == "CHAT_MSG_CHANNEL" then
if not DBB2.api.IsChannelWhitelisted(channel) then
return -- Not an LFG channel, ignore
end
-- Ignore World channel when hardcore is active
local lowerChannel = string.lower(channel or "")
if DBB2.api.IsHardcoreChatActive() and lowerChannel == "world" then
return
end
end
DBB2.api.AddMessage(message, sender, channel, event)
end
if event == "CHAT_MSG_SAY" or event == "CHAT_MSG_YELL" or event == "CHAT_MSG_PARTY" or event == "CHAT_MSG_WHISPER" then
-- Capture Say, Yell, Party, Whisper messages
local message = arg1
local sender = arg2
local channel
if event == "CHAT_MSG_SAY" then
channel = "Say"
elseif event == "CHAT_MSG_YELL" then
channel = "Yell"
elseif event == "CHAT_MSG_WHISPER" then
channel = "Whisper"
else
channel = "Party"
end
-- Check if this channel is monitored
if not DBB2.api.IsChannelMonitored(channel) then
return
end
DBB2.api.AddMessage(message, sender, channel, event)
end
if event == "CHAT_MSG_HARDCORE" then
-- Turtle WoW hardcore chat messages
local message = arg1
local sender = arg2
-- Check if Hardcore channel is monitored
if not DBB2.api.IsChannelMonitored("Hardcore") then
return -- Hardcore channel not monitored, ignore
end
-- Mark hardcore chat as active (enables auto-switch from World)
if not DBB2.api.IsHardcoreChatActive() then
DBB2.api.SetHardcoreChatActive()
end
DBB2.api.AddMessage(message, sender, "Hardcore", event)
end
if event == "CHAT_MSG_SYSTEM" then
-- Capture system messages (hardcore deaths, level ups, etc.)
local message = arg1
-- System messages don't have a sender, use "System" as placeholder
local sender = "System"
local channel = "System"
DBB2.api.AddMessage(message, sender, channel, event)
end
if event == "UPDATE_INSTANCE_INFO" then
DBB2.api.UpdateLockouts()
end
if event == "CHAT_MSG_CHANNEL_NOTICE" then
-- Channel join/leave notification - refresh channel list if panel exists
-- arg1 = notice type (e.g. "YOU_JOINED", "YOU_LEFT")
-- arg9 = channel name
if DBB2.gui and DBB2.gui.configTabs and DBB2.gui.configTabs.panels then
local channelsPanel = DBB2.gui.configTabs.panels["Channels"]
if channelsPanel and channelsPanel.RebuildChannelCheckboxes then
channelsPanel.RebuildChannelCheckboxes()
end
end
end
if event == "PARTY_MEMBERS_CHANGED" or event == "RAID_ROSTER_UPDATE" then
-- Disable all category notifications when joining a group (if enabled)
if DBB2_Config.clearNotificationsOnGroupJoin then
-- Check if in a party or raid
if GetNumPartyMembers() > 0 or GetNumRaidMembers() > 0 then
DBB2.api.DisableAllNotifications()
end
end
end
end)
-- Register module function
function DBB2:RegisterModule(name, func)
if DBB2.modules[name] then return end
DBB2.modules[name] = func
table.insert(DBB2.modules, func)
end
-- Cache tables for scaled values (populated on first call, constant per session)
DBB2._fontCache = {}
DBB2._scaledCache = {}
-- [ GetEffectiveFontOffset ]
-- Converts the UI font offset step into the actual font-size delta.
-- Each visible step is 0.5 font size to allow finer adjustments while
-- keeping the saved/configured slider values at whole numbers.
-- return: [number] actual font size delta
function DBB2:GetEffectiveFontOffset()
local offset = DBB2_Config.fontOffset
if type(offset) ~= "number" then offset = 0 end
if offset < -6 then offset = -6 end
if offset > 6 then offset = 6 end
return offset * 0.5
end
-- Get font size with offset applied (cached)
-- 'baseSize' [number] the base font size
-- return: [number] font size with offset applied (minimum 6, maximum 24)
-- Note: WoW 1.12.1 has internal font size limits. Large fonts can cause crashes.
function DBB2:GetFontSize(baseSize)
if self._fontCache[baseSize] then
return self._fontCache[baseSize]
end
local size = baseSize + DBB2:GetEffectiveFontOffset()
-- Clamp between 6 and 24 to prevent crashes in WoW 1.12.1
-- Using conservative limits as vanilla WoW has strict font rendering constraints
if size < 6 then size = 6 end
if size > 24 then size = 24 end
self._fontCache[baseSize] = size
return size
end
-- [ GetScaleFactor ]
-- Returns a scale factor based on font offset for scaling UI element widths/heights
-- return: [number] scale factor (1.0 at offset 0, increases with positive offset)
function DBB2:GetScaleFactor()
local effectiveOffset = DBB2:GetEffectiveFontOffset()
-- Scale by ~10% per actual font size increase (UI step of +6 = 1.3x scale)
return 1 + (effectiveOffset * 0.1)
end
-- [ ScaleSize ]
-- Scales a base size value according to font offset (cached)
-- 'baseSize' [number] the base size value
-- return: [number] scaled size (minimum 1 to prevent zero/negative dimensions)
function DBB2:ScaleSize(baseSize)
if self._scaledCache[baseSize] then
return self._scaledCache[baseSize]
end
local scaled = math.floor(baseSize * DBB2:GetScaleFactor() + 0.5)
-- Ensure minimum size of 1 to prevent invalid frame dimensions
if scaled < 1 then scaled = 1 end
self._scaledCache[baseSize] = scaled
return scaled
end
-- Get highlight color
-- return: [r, g, b, a] highlight color components
function DBB2:GetHighlightColor()
local c = DBB2_Config.highlightColor or {r = 0.2, g = 1, b = 0.8, a = 1}
return c.r, c.g, c.b, c.a
end
-- Slash command to toggle GUI
SLASH_DBB1 = "/dbb"
SlashCmdList["DBB"] = function(msg)
if DBB2.gui then
if DBB2.gui:IsShown() then
DBB2.gui:Hide()
else
DBB2.gui:Show()
end
end
end