annotate ui/Components.lua @ 55:826f8e68e045 v20

bumped interface version for 6.1 patch
author yellowfive
date Tue, 24 Feb 2015 21:49:57 -0800
parents e77e01abce98
children
rev   line source
adam@0 1 local _, AskMrRobot = ...
adam@0 2
adam@0 3 local unresolvedItemIds = {}
adam@0 4
adam@0 5 -- Create a new class that inherits from a base class
adam@0 6 function AskMrRobot.inheritsFrom( baseClass )
adam@0 7
adam@0 8 -- The following lines are equivalent to the SimpleClass example:
adam@0 9
adam@0 10 -- Create the table and metatable representing the class.
yellowfive@11 11 local new_class = { }
adam@0 12
adam@0 13 -- Note that this function uses class_mt as an upvalue, so every instance
adam@0 14 -- of the class will share the same metatable.
adam@0 15 --
adam@0 16 -- function new_class:create(o)
adam@0 17 -- o = o or {}
adam@0 18 -- setmetatable( o, class_mt )
adam@0 19 -- return o
adam@0 20 -- end
adam@0 21
adam@0 22 -- The following is the key to implementing inheritance:
adam@0 23
adam@0 24 -- The __index member of the new class's metatable references the
adam@0 25 -- base class. This implies that all methods of the base class will
adam@0 26 -- be exposed to the sub-class, and that the sub-class can override
adam@0 27 -- any of these methods.
adam@0 28 --
adam@0 29 if baseClass then
adam@0 30 setmetatable( new_class, { __index = baseClass } )
adam@0 31 end
adam@0 32
adam@0 33 return new_class
adam@0 34 end
adam@0 35
adam@0 36 local itemInfoFrame = nil;
adam@0 37
adam@0 38 local function onGetItemInfoReceived(arg1, arg2, arg3)
adam@0 39 -- since wow is awesome, it doesn't tell us *which* item id was just resolved, so we have to look at them all
adam@0 40 for itemId, callbacks in pairs(unresolvedItemIds) do
adam@0 41 -- attempt to get the item info AGAIN
adam@0 42 local a, b, c, d, e, f, g, h, i, j, k = GetItemInfo(itemId)
adam@0 43 -- if we got item info...
adam@0 44 if a then
adam@0 45 -- remove the callbacks from the list
adam@0 46 unresolvedItemIds[itemId] = nil
adam@0 47
adam@0 48 -- call each callback
adam@0 49 for i = 1, #callbacks do
adam@0 50 callbacks[i](a, b, c, d, e, f, g, h, i, j, k)
adam@0 51 end
adam@0 52 end
adam@0 53 end
adam@0 54 end
adam@0 55
adam@0 56
adam@0 57 function AskMrRobot.RegisterItemInfoCallback(itemId, callback)
adam@0 58 if not itemId then
adam@0 59 return
adam@0 60 end
adam@0 61
adam@0 62 if not itemInfoFrame then
adam@0 63 waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
adam@0 64 waitFrame:RegisterEvent("GET_ITEM_INFO_RECEIVED")
adam@0 65 waitFrame:SetScript("OnEvent", onGetItemInfoReceived);
adam@0 66 end
adam@0 67
adam@0 68
adam@0 69 -- get the list of registered callbacks for this particular item
adam@0 70 local list = unresolvedItemIds[itemId]
adam@0 71 -- if there was a list, then just add the callback to the list
adam@0 72 if list then
adam@0 73 tinsert(list, callback)
adam@0 74 else
adam@0 75 -- there wasn't a list, so make a new one with this callback
adam@0 76 unresolvedItemIds[itemId] = { callback }
adam@0 77 end
adam@0 78 end
adam@0 79
adam@0 80
adam@0 81 -- initialize the Frame class (inherit from a dummy frame)
adam@0 82 AskMrRobot.Frame = AskMrRobot.inheritsFrom(CreateFrame("Frame"))
adam@0 83
adam@0 84 -- Frame contructor
adam@0 85 function AskMrRobot.Frame:new(name, parentFrame, inheritsFrame)
adam@0 86 -- create a new frame (if one isn't supplied)
adam@0 87 local o = CreateFrame("Frame", name, parentFrame, inheritsFrame)
adam@0 88
adam@0 89 -- use the Frame class
adam@0 90 setmetatable(o, { __index = AskMrRobot.Frame })
adam@0 91
adam@0 92 -- return the instance of the Frame
adam@0 93 return o
adam@0 94 end