-
-
Notifications
You must be signed in to change notification settings - Fork 4
Getting Started
After including Poncho and LibStub in your add-on, you can retrieve the class constructor by calling:
local CreateClass = LibStub('Poncho-1.0')
The CreateClass
method works much alike CreateFrame
, except it accepts a final optional argument:
CreateClass(frameType, className, defaultParent, xmlTemplates, parentClass)
Defines the frameType of all frames belonging to this class, exactly as in CreateFrame.
Defines the global name of the class, so:
local MyClass = CreateClass('Frame', 'Banana')
local FirstBanana = MyClass()
Is the same as:
local MyClass = CreateClass('Frame', 'Banana')
local FirstBanana = Banana()
The global name of the frames is handled internally by Poncho, and depends on the name of the class.
Defines the default parent of the frames, which will be used unless explicitly set when creating the frame (see below).
Defines the xmlTemplates of all frames belonging to this class, exactly as in CreateFrame.
Defines another Poncho class which this class will inherit from.
Creating frames is done by calling the class object itself:
local MyClass = CreateClass('Frame')
local FirstFrame = MyClass()
Frames can then be dealloc trough the Release
method:
MyFrame:Release()
On most object oriented languages, when creating classes, programmers may set two special methods: a constructor and a destructor. As it is not possible to actually destroy Frames in World of Warcraft, there are 3 special events available:
Called a single time for each frame - when it is truly created.
Called when a frame is "released" by the user, and placed on a "wait to be used again" pile.
Called each time the frame is requested by the user. Which means:
- When is created, after
OnCreate
. - Whenever is pulled from the "wait" pile.
A final example of a simple class implementation. Any button belonging to this class will print a number when clicked, which is incremented as long as the button is acquired (active).
local Counter = LibStub('Poncho-1.0')('Button')
-- Construct / Destruct events
function Counter:OnCreate()
self:SetScript('OnClick', self.Print)
end
function Counter:OnAcquire()
self.count = 0
self:SetScript('OnUpdate', self.Increment)
end
function Counter:OnRelease()
self:SetScript('OnUpdate', nil)
end
-- Script
function Counter:Print()
print(self.count)
end
function Counter:Increment()
self.count = self.count + 1
end
local MyButtonCounter = Counter(Minimap) -- parents it to the minimap
This is the Poncho-2.0 wiki. Wiki Home