public
Description: WoW Addon - Addon quicklaunch bar
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/quickie.git
quickie / Quickie.lua
100644 170 lines (121 sloc) 5.181 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
----------------------
-- Locals --
----------------------
 
local L = setmetatable({}, {__index=function(t,i) return i end})
local defaults, defaultsPC, db, dbpc = {}, {}
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local BUTTONSIZE, EDGE, GAP = 32, 5, 2
 
 
------------------------------
-- Util Functions --
------------------------------
 
local function Print(...) ChatFrame1:AddMessage(string.join(" ", "|cFF33FF99Quickie|r:", ...)) end
 
local debugf = tekDebug and tekDebug:GetFrame("Quickie")
local function Debug(...) if debugf then debugf:AddMessage(string.join(", ", ...)) end end
 
 
-------------------------------
-- Container frame --
-------------------------------
 
local container = CreateFrame("Button", nil, UIParent)
container:SetWidth(EDGE*2) container:SetHeight(BUTTONSIZE + EDGE*2)
container:SetPoint("RIGHT", UIParent, "LEFT", EDGE, 0)
 
container:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = {left = EDGE, right = EDGE, top = EDGE, bottom = EDGE},
tile = true, tileSize = 16,
})
container:SetBackdropColor(0.09, 0.09, 0.19, 0.5)
container:SetBackdropBorderColor(1, 1, 0.5, 0.5)
 
 
local hideelapsed = 0
local function OnUpdate(self, elapsed)
hideelapsed = hideelapsed + elapsed
if hideelapsed < 2 then return end
 
self:ClearAllPoints()
self:SetPoint("RIGHT", UIParent, "LEFT", EDGE, 0)
self:SetScript("OnUpdate", nil)
end
 
 
local function containerOnEnter()
container:SetScript("OnUpdate", nil)
container:ClearAllPoints()
container:SetPoint("LEFT", UIParent, "LEFT", -EDGE, 0)
end
 
 
local function containerOnLeave()
hideelapsed = 0
container:SetScript("OnUpdate", OnUpdate)
end
 
 
container:SetScript("OnEnter", containerOnEnter)
container:SetScript("OnLeave", containerOnLeave)
 
 
-----------------------------
-- Block factory --
-----------------------------
 
local function GetTipAnchor(frame)
local x,y = frame:GetCenter()
if not x or not y then return "TOPLEFT", "BOTTOMLEFT" end
local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or ""
local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
end
 
 
local function OnEnter(self, ...)
containerOnEnter()
 
if self.dataobj.OnEnter then self.dataobj.OnEnter(self, ...)
else
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint(GetTipAnchor(self))
GameTooltip:ClearLines()
 
local name, title, notes = GetAddOnInfo(self.dataobj.tocname or self.doname)
if name then
GameTooltip:AddLine(title or name)
GameTooltip:AddLine(notes)
else
GameTooltip:AddLine(self.dataobj.label or self.doname)
end
 
GameTooltip:Show()
end
end
 
 
local function OnLeave(self, ...)
containerOnLeave()
if self.dataobj.OnLeave then self.dataobj.OnLeave(self, ...)
else GameTooltip:Hide() end
end
 
 
local function IconChanged(self, event, name, key, value, dataobj)
self.texture:SetTexture(value)
end
 
 
local function OnClickChanged(self, event, name, key, value, dataobj)
self:SetScript("OnClick", value)
end
 
 
local frames, lastframe = {}
function container:NewDataobject(event, name, dataobj)
dataobj = dataobj or ldb:GetDataObjectByName(name)
if not dataobj.launcher then return end
 
local frame = CreateFrame("Button", nil, container)
frame:SetWidth(BUTTONSIZE) frame:SetHeight(BUTTONSIZE)
frame:SetPoint("LEFT", lastframe or container, lastframe and "RIGHT" or "LEFT", lastframe and GAP or EDGE, 0)
container:SetWidth(container:GetWidth() + BUTTONSIZE + (lastframe and GAP or 0))
frame.doname, frame.dataobj, frame.IconChanged, frame.OnClickChanged = name, dataobj, IconChanged, OnClickChanged
 
frame:SetScript("OnEnter", OnEnter)
frame:SetScript("OnLeave", OnLeave)
frame:SetScript("OnClick", dataobj.OnClick)
 
frame.texture = frame:CreateTexture()
frame.texture:SetAllPoints()
frame.texture:SetTexture(dataobj.icon)
 
ldb.RegisterCallback(frame, "LibDataBroker_AttributeChanged_"..name.."_icon", "IconChanged")
ldb.RegisterCallback(frame, "LibDataBroker_AttributeChanged_"..name.."_OnClick", "OnClickChanged")
 
frames[name], lastframe = frame, frame
end
 
 
for name,dataobj in ldb:DataObjectIterator() do if dataobj.launcher then container:NewDataobject(nil, name, dataobj) end end
ldb.RegisterCallback(container, "LibDataBroker_DataObjectCreated", "NewDataobject")
ldb.RegisterCallback(container, "LibDataBroker_AttributeChanged__launcher", function(event, name, key, value, dataobj)
if value and not frames[name] then container:NewDataobject(nil, name, dataobj) end
end)
 
 
---------------------------
-- About panel --
---------------------------
 
local about = LibStub("tekKonfig-AboutPanel").new(nil, "Quickie")
 
 
----------------------------------------
-- Quicklaunch registration --
----------------------------------------
 
local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Quickie", {
launcher = true,
icon = "Interface\\Icons\\Ability_Hunter_Readiness",
OnClick = function() InterfaceOptionsFrame_OpenToFrame(about) end,
})