-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathEnhancedRaidFrames.lua
157 lines (134 loc) · 6.7 KB
/
EnhancedRaidFrames.lua
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
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2024 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)
--- EnhancedRaidFrames is the main addon object for the Enhanced Raid Frames add-on.
---@class EnhancedRaidFrames : AceAddon-3.0 @The main addon object for the Enhanced Raid Frames add-on
_G.EnhancedRaidFrames = LibStub("AceAddon-3.0"):NewAddon("EnhancedRaidFrames", "AceTimer-3.0", "AceHook-3.0",
"AceEvent-3.0", "AceBucket-3.0", "AceConsole-3.0", "AceSerializer-3.0")
-- Create a local handle to our addon table
---@type EnhancedRaidFrames
local EnhancedRaidFrames = _G.EnhancedRaidFrames
-- Import libraries
local L = LibStub("AceLocale-3.0"):GetLocale("EnhancedRaidFrames")
local AceDBOptions = LibStub("AceDBOptions-3.0")
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceDB = LibStub("AceDB-3.0")
-------------------------------------------------------------------------
-------------------------------------------------------------------------
--- Called directly after the addon is fully loaded.
--- We do initialization tasks here, such as loading our saved variables or setting up slash commands.
function EnhancedRaidFrames:OnInitialize()
-- Set up our database
self:InitializeDatabase()
-- Run our database migration if necessary
self:MigrateDatabase()
-- Setup config panels in the Blizzard interface options
self:InitializeConfigPanels()
-- Register callbacks for profile switching
self.db.RegisterCallback(self, "OnProfileChanged", function()
self:MigrateDatabase()
self:RefreshConfig()
end)
self.db.RegisterCallback(self, "OnProfileCopied", function()
self:MigrateDatabase()
self:RefreshConfig()
end)
self.db.RegisterCallback(self, "OnProfileReset", function()
self:MigrateDatabase()
self:RefreshConfig()
end)
end
--- Called during the PLAYER_LOGIN event when most of the data provided by the game is already present.
--- We perform more startup tasks here, such as registering events, hooking functions, creating frames, or getting
--- information from the game that wasn't yet available during :OnInitialize()
function EnhancedRaidFrames:OnEnable()
-- Populate our starting config values
self:RefreshConfig()
-- Run a full update of all auras for a starting point
self:UpdateAllAuras()
-- (THROTTLED) Force a full update of all group member's auras when the group roster changes
self:RegisterBucketEvent("GROUP_ROSTER_UPDATE", 1, function() -- 1 second throttle to avoid lagging the game
self:UpdateAllAuras()
end)
-- Force a full update of all stock aura visibilities, target markers, and ranges when the group roster changes
self:RegisterEvent("GROUP_ROSTER_UPDATE", function()
self:UpdateAllStockAuraVisibility()
self:UpdateAllTargetMarkers()
end)
-- Force a full update of all frames when a raid target icon changes
self:RegisterEvent("RAID_TARGET_UPDATE", function()
self:UpdateAllTargetMarkers()
end)
-- Hook our UpdateInRange function to the default CompactUnitFrame_UpdateInRange function.
-- Using SecureHook ensures that our function will run 'after' the default function, which is what we want.
self:SecureHook("CompactUnitFrame_UpdateInRange", function(frame)
self:UpdateInRange(frame)
end)
-- Register our slash command to open the config panel
self:RegisterChatCommand("erf", function()
Settings.OpenToCategory("Enhanced Raid Frames")
end)
end
--- Called when our addon is manually being disabled during a running session.
--- We primarily use this to unhook scripts, unregister events, or hide frames that we created.
function EnhancedRaidFrames:OnDisable()
-- Empty --
end
-------------------------------------------------------------------------
-------------------------------------------------------------------------
--- Create a table containing our default database values
function EnhancedRaidFrames:InitializeDatabase()
-- Set up database defaults
local defaults = self:CreateDefaults()
-- Create database object
self.db = AceDB:New("EnhancedRaidFramesDB", defaults) --EnhancedRaidFramesDB is our saved variable table
-- Enhance database and profile options using LibDualSpec
if not self.isWoWClassicEra then
-- Not available in Classic Era
-- Enhance the database object with per spec profile features
LibStub("LibDualSpec-1.0"):EnhanceDatabase(self.db, "EnhancedRaidFrames")
-- Enhance the profile options table with per spec profile features
LibStub("LibDualSpec-1.0"):EnhanceOptions(AceDBOptions:GetOptionsTable(self.db), self.db)
end
end
--- Set up our configuration panels and add them to the Blizzard interface options
function EnhancedRaidFrames:InitializeConfigPanels()
-- Build our config panels
AceConfigRegistry:RegisterOptionsTable("Enhanced Raid Frames", self:CreateGeneralOptions())
AceConfigRegistry:RegisterOptionsTable("ERF Indicator Options", self:CreateIndicatorOptions())
AceConfigRegistry:RegisterOptionsTable("ERF Target Marker Options", self:CreateIconOptions())
AceConfigRegistry:RegisterOptionsTable("ERF Profiles", AceDBOptions:GetOptionsTable(self.db))
AceConfigRegistry:RegisterOptionsTable("ERF Import Export Profile Options", self:CreateProfileImportExportOptions())
-- Add to config panels to in-game interface options
AceConfigDialog:AddToBlizOptions("Enhanced Raid Frames", "Enhanced Raid Frames")
AceConfigDialog:AddToBlizOptions("ERF Indicator Options", L["Indicator Options"], "Enhanced Raid Frames")
AceConfigDialog:AddToBlizOptions("ERF Target Marker Options", L["Target Marker Options"], "Enhanced Raid Frames")
AceConfigDialog:AddToBlizOptions("ERF Profiles", L["Profiles"], "Enhanced Raid Frames")
AceConfigDialog:AddToBlizOptions("ERF Import Export Profile Options",
(L["Profile"] .. " " .. L["Import"] .. "/" .. L["Export"]), "Enhanced Raid Frames")
end
--- Refresh everything that is affected by changes to the configuration
function EnhancedRaidFrames:RefreshConfig()
self:GenerateAuraStrings()
self:UpdateAllAuras() -- Update all auras to reflect new settings
self:UpdateScale()
if CompactRaidFrameContainer and CompactRaidFrameContainer.ApplyToFrames then
-- 10.0 refactored CompactRaidFrameContainer with new functionality
CompactRaidFrameContainer:ApplyToFrames("normal", function(frame)
self:UpdateIndicators(frame, true)
self:UpdateBackgroundAlpha(frame)
self:UpdateInRange(frame)
self:UpdateTargetMarker(frame, true)
self:UpdateStockAuraVisibility(frame)
end)
else
CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", function(frame)
self:UpdateIndicators(frame, true)
self:UpdateBackgroundAlpha(frame)
self:UpdateInRange(frame)
self:UpdateTargetMarker(frame, true)
self:UpdateStockAuraVisibility(frame)
end)
end
end