Handling Game Events - GoldpawsStuff/DiabolicUI GitHub Wiki
DiabolicUI2 is based mostly on Ace3, but we're not using AceEvent-3.0. Instead we're using a custom event handler named LibMoreEvents-1.0 inspired by oUF's event handling.
The main benefit of LibMoreEvents-1.0, is simply put that we can register more events. Multiple callbacks can be registered for the same event in the same module, and it also accepts both module method names and functions as input values.
Also note that this only handles actual game events, and is unrelated to the custom callback system.
-- @param eventname
-- <string> the name of the game event to listen for
-- @param callback
-- <string, function>
-- if string, will call self["method"](self, eventname, ...) where 'self' is your module
-- if function, will calll method(self, eventname, ...) where 'self' is your module
--
-- @usage
local MyModule = DiabolicUI2:NewModule("MyModule", "LibMoreEvents-1.0")
MyModule.OnInitialize = function(self)
self:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEvent")
end
MyModule.OnEvent = function(self, event, ...)
if (event == "PLAYER_ENTERING_WORLD") then
-- Do something
end
end-- @param eventname
-- <string> the name of the game event to listen for
-- @param callback
-- <string, function> a previously registered callback for the event
--
-- @usage
local MyModule = DiabolicUI2:NewModule("MyModule", "LibMoreEvents-1.0")
MyModule.OnInitialize = function(self)
self:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEvent")
end
MyModule.OnEvent = function(self, event, ...)
if (event == "PLAYER_ENTERING_WORLD") then
-- Unregister the event.
self:UnregisterEvent("PLAYER_ENTERING_WORLD", "OnEvent")
end
end