annotate ui/Components.lua @ 15:218628cb4a29 v1.2.16.0

removed test button from combat log tab
author yellowfive
date Thu, 10 Jul 2014 15:31:17 -0700
parents ece9167c0d1c
children e77e01abce98
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 function AskMrRobot.getItemIdFromLink(item)
adam@0 81 if not item then return 0 end
adam@0 82 local id = tonumber (item:match ("item:(%d+):%d+:%d+:%d+:%d+:%d+:%-?%d+:%-?%d+:%d+:%d+"))
adam@0 83 return (id and id ~= 0 and id or 0)
adam@0 84 end
adam@0 85
adam@0 86 -- initialize the Frame class (inherit from a dummy frame)
adam@0 87 AskMrRobot.Frame = AskMrRobot.inheritsFrom(CreateFrame("Frame"))
adam@0 88
adam@0 89 -- Frame contructor
adam@0 90 function AskMrRobot.Frame:new(name, parentFrame, inheritsFrame)
adam@0 91 -- create a new frame (if one isn't supplied)
adam@0 92 local o = CreateFrame("Frame", name, parentFrame, inheritsFrame)
adam@0 93
adam@0 94 -- use the Frame class
adam@0 95 setmetatable(o, { __index = AskMrRobot.Frame })
adam@0 96
adam@0 97 -- return the instance of the Frame
adam@0 98 return o
adam@0 99 end
adam@0 100
adam@0 101 local MAINHAND = nil
adam@0 102 local OFFHAND = nil
adam@0 103
adam@0 104 AskMrRobot.slotNames = {"HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot", "ChestSlot", "ShirtSlot", "TabardSlot", "WristSlot", "HandsSlot", "WaistSlot", "LegsSlot", "FeetSlot", "Finger0Slot", "Finger1Slot", "Trinket0Slot", "Trinket1Slot", "MainHandSlot", "SecondaryHandSlot", "AmmoSlot" };
adam@0 105 AskMrRobot.OptimizationSlots = {}
adam@0 106 AskMrRobot.slotIdToSlotNum = {}
adam@0 107 AskMrRobot.slotIds = {};
adam@0 108 for slotNum = 1, #AskMrRobot.slotNames do
adam@0 109 local slotId = GetInventorySlotInfo(AskMrRobot.slotNames[slotNum])
adam@0 110 AskMrRobot.slotIds[slotNum] = slotId
adam@0 111 AskMrRobot.slotIdToSlotNum[slotId] = slotNum
adam@0 112 local slotName = AskMrRobot.slotNames[slotNum]
adam@0 113 if slotName == "MainHandSlot" then
adam@0 114 MAINHAND = slotNum
adam@0 115 end
adam@0 116 if slotName == "SecondaryHandSlot" then
adam@0 117 OFFHAND = slotNum
adam@0 118 end
adam@0 119 if slotName ~= "TabardSlot" and slotName ~= "AmmoSlot" and slotName ~= "ShirtSlot" then
adam@0 120 AskMrRobot.OptimizationSlots[slotNum] = true
adam@0 121 end
adam@0 122
adam@0 123 end
adam@0 124
adam@0 125 AskMrRobot.sortedSlots = {[MAINHAND] = 1, [OFFHAND] = 2}
adam@0 126
adam@0 127 local i = 3
adam@0 128 for slotNum = 1, #AskMrRobot.slotNames do
adam@0 129 if slotNum ~= MAINHAND and slotNum ~= OFFHAND then
adam@0 130 AskMrRobot.sortedSlots[slotNum] = i
adam@0 131 i = i + 1
adam@0 132 end
yellowfive@11 133 end