comparison ui/Components.lua @ 0:ec731d2fe6ba

Version 1.2.12.0
author Adam tegen <adam.tegen@gmail.com>
date Tue, 20 May 2014 21:43:23 -0500
parents
children ece9167c0d1c
comparison
equal deleted inserted replaced
-1:000000000000 0:ec731d2fe6ba
1 local _, AskMrRobot = ...
2
3 local unresolvedItemIds = {}
4
5 -- Create a new class that inherits from a base class
6 function AskMrRobot.inheritsFrom( baseClass )
7
8 -- The following lines are equivalent to the SimpleClass example:
9
10 -- Create the table and metatable representing the class.
11 local new_class = {}
12
13 -- Note that this function uses class_mt as an upvalue, so every instance
14 -- of the class will share the same metatable.
15 --
16 -- function new_class:create(o)
17 -- o = o or {}
18 -- setmetatable( o, class_mt )
19 -- return o
20 -- end
21
22 -- The following is the key to implementing inheritance:
23
24 -- The __index member of the new class's metatable references the
25 -- base class. This implies that all methods of the base class will
26 -- be exposed to the sub-class, and that the sub-class can override
27 -- any of these methods.
28 --
29 if baseClass then
30 setmetatable( new_class, { __index = baseClass } )
31 end
32
33 return new_class
34 end
35
36 local itemInfoFrame = nil;
37
38 local function onGetItemInfoReceived(arg1, arg2, arg3)
39 -- since wow is awesome, it doesn't tell us *which* item id was just resolved, so we have to look at them all
40 for itemId, callbacks in pairs(unresolvedItemIds) do
41 -- attempt to get the item info AGAIN
42 local a, b, c, d, e, f, g, h, i, j, k = GetItemInfo(itemId)
43 -- if we got item info...
44 if a then
45 -- remove the callbacks from the list
46 unresolvedItemIds[itemId] = nil
47
48 -- call each callback
49 for i = 1, #callbacks do
50 callbacks[i](a, b, c, d, e, f, g, h, i, j, k)
51 end
52 end
53 end
54 end
55
56
57 function AskMrRobot.RegisterItemInfoCallback(itemId, callback)
58 if not itemId then
59 return
60 end
61
62 if not itemInfoFrame then
63 waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
64 waitFrame:RegisterEvent("GET_ITEM_INFO_RECEIVED")
65 waitFrame:SetScript("OnEvent", onGetItemInfoReceived);
66 end
67
68
69 -- get the list of registered callbacks for this particular item
70 local list = unresolvedItemIds[itemId]
71 -- if there was a list, then just add the callback to the list
72 if list then
73 tinsert(list, callback)
74 else
75 -- there wasn't a list, so make a new one with this callback
76 unresolvedItemIds[itemId] = { callback }
77 end
78 end
79
80 function AskMrRobot.getItemIdFromLink(item)
81 if not item then return 0 end
82 local id = tonumber (item:match ("item:(%d+):%d+:%d+:%d+:%d+:%d+:%-?%d+:%-?%d+:%d+:%d+"))
83 return (id and id ~= 0 and id or 0)
84 end
85
86 -- initialize the Frame class (inherit from a dummy frame)
87 AskMrRobot.Frame = AskMrRobot.inheritsFrom(CreateFrame("Frame"))
88
89 -- Frame contructor
90 function AskMrRobot.Frame:new(name, parentFrame, inheritsFrame)
91 -- create a new frame (if one isn't supplied)
92 local o = CreateFrame("Frame", name, parentFrame, inheritsFrame)
93
94 -- use the Frame class
95 setmetatable(o, { __index = AskMrRobot.Frame })
96
97 -- return the instance of the Frame
98 return o
99 end
100
101 local MAINHAND = nil
102 local OFFHAND = nil
103
104 AskMrRobot.slotNames = {"HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot", "ChestSlot", "ShirtSlot", "TabardSlot", "WristSlot", "HandsSlot", "WaistSlot", "LegsSlot", "FeetSlot", "Finger0Slot", "Finger1Slot", "Trinket0Slot", "Trinket1Slot", "MainHandSlot", "SecondaryHandSlot", "AmmoSlot" };
105 AskMrRobot.OptimizationSlots = {}
106 AskMrRobot.slotIdToSlotNum = {}
107 AskMrRobot.slotIds = {};
108 for slotNum = 1, #AskMrRobot.slotNames do
109 local slotId = GetInventorySlotInfo(AskMrRobot.slotNames[slotNum])
110 AskMrRobot.slotIds[slotNum] = slotId
111 AskMrRobot.slotIdToSlotNum[slotId] = slotNum
112 local slotName = AskMrRobot.slotNames[slotNum]
113 if slotName == "MainHandSlot" then
114 MAINHAND = slotNum
115 end
116 if slotName == "SecondaryHandSlot" then
117 OFFHAND = slotNum
118 end
119 if slotName ~= "TabardSlot" and slotName ~= "AmmoSlot" and slotName ~= "ShirtSlot" then
120 AskMrRobot.OptimizationSlots[slotNum] = true
121 end
122
123 end
124
125 AskMrRobot.sortedSlots = {[MAINHAND] = 1, [OFFHAND] = 2}
126
127 local i = 3
128 for slotNum = 1, #AskMrRobot.slotNames do
129 if slotNum ~= MAINHAND and slotNum ~= OFFHAND then
130 AskMrRobot.sortedSlots[slotNum] = i
131 i = i + 1
132 end
133 end
134
135
136 -- initialize the Frame class (inherit from a dummy frame)
137 AskMrRobot.FontString = AskMrRobot.inheritsFrom(AskMrRobot.Frame:new():CreateFontString(nil, "ARTWORK", "GameFontNormal"))
138
139 -- Frame contructor
140 function AskMrRobot.FontString:new(parentFrame, name, layer, style, fontSize)
141
142 local o = parentFrame:CreateFontString(name, layer, style) -- create a new frame (if one isn't supplied)
143
144 -- use the fontstring class
145 setmetatable(o, { __index = AskMrRobot.FontString })
146
147 if fontSize then
148 o:SetFontSize(fontSize)
149 end
150
151 return o
152 end
153
154 function AskMrRobot.FontString:SetFontSize(fontSize)
155 local file, _, flags = self:GetFont()
156 self:SetFont(file, fontSize, flags)
157 end
158
159 function AskMrRobot.SetFontSize(fontString, fontSize)
160 local file, _, flags = fontString:GetFont()
161 fontString:SetFont(file, fontSize, flags)
162 end