-
Notifications
You must be signed in to change notification settings - Fork 99
Creating modules
A few basic events are included in SUF by default to make it easier for modules to be written, in order to get module events you first have to register your module with SUF, you do that using ShadowUF:RegisterModule:
| Arg | Type | Description |
| module | table | The table that contains all of your functions/events for the module. |
| key | string | The used to identify the module, this should be the same as your configuration key if you include the name field. |
| name | string/nil | Optional, if you’re registering this as a configuration then this is the text that shows up in the visibility panel. |
| isBar | true/false/nil | Optional, indicates that this module includes a bar inside the unit frames, and needs to be positioned/sized. |
If your module includes functionality that should always be enabled, then you do not need to pass the name or isBar options. The key you pass will be used as your configuration key inside the units table, and will be checked against things such as visibility and if it’s enabled or not.
The below code is an example of a simple module that will fade unit frames while out of combat to set alpha, then change it to another alpha when in combat, includes configuration to enable the module per unit, as well as being able to set the alpha to use specifically.
local Fader = {}
ShadowUF:RegisterModule(Fader, "fader", "Combat fader")
-- Defaults were loaded, but haven't been initialized, add ours to the list.
function Fader:OnDefaultsSet()
for _, unit in pairs(ShadowUF.units) do
ShadowUF.defaults.profile.units[unit].fader = {enabled = true, inCombat = 1.0, outCombat = 0.60}
end
end
-- Configuration has been loaded, but it hasn't been shown yet. Inject our custom options into the units table.
function Fader:OnConfigurationLoad()
ShadowUF.Config.unitTable.args.general.args.combatFader = {
order = 3,
type = "group",
inline = true,
name = "Combat fader",
args = {
fader = {
order = 0,
type = "toggle",
name = "Enable combat fader",
arg = "fader.enabled",
},
combatAlpha = {
order = 1,
type = "range",
name = "Combat alpha",
min = 0, max = 1.0, step = 0.1,
arg = "fader.inCombat",
isPercent = true,
},
inactiveAlpha = {
order = 2,
type = "range",
name = "Inactive alpha",
min = 0, max = 1.0, step = 0.1,
arg = "fader.outCombat",
isPercent = true,
},
},
}
end
-- Fader module was enabled, either because units[frame.unitType].fader.enabled is true, or because it has been enabled through visibility
function Fader:OnEnable(frame)
frame:RegisterNormalEvent("PLAYER_REGEN_ENABLED", self, "Update")
frame:RegisterNormalEvent("PLAYER_REGEN_DISABLED", self, "Update")
frame:RegisterUpdateFunc(self, "Update")
end
-- Fader module was disabled, either because units[frame.unitType].fader.enabled is false, or because it was disabled through visibility
function Fader:OnDisable(frame)
frame:UnregisterAll(self)
frame:SetAlpha(1.0)
end
-- Frame has been updated either PLAYER_REGEN_ENABLED or PLAYER_REGEN_DISABLED fired, we might also have had a full update triggered
function Fader:Update(frame)
-- The reason why you use frame.unitType instead of frame.unit, is because all configuration is saved by the unitType, this prevents there being
-- separate configuration for party1-4, raid1-40, it's all in party or raid
if( InCombatLockdown() ) then
frame:SetAlpha(ShadowUF.db.profile.units[frame.unitType].fader.inCombat)
else
frame:SetAlpha(ShadowUF.db.profile.units[frame.unitType].fader.outCombat)
end
end