-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPanda.lua
executable file
·283 lines (216 loc) · 8.23 KB
/
Panda.lua
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
local myname, ns = ...
----------------------------
-- Localization --
----------------------------
local locale = GetLocale()
local L = setmetatable(locale == "deDE" and {
Scrolls = "Rollen",
Weapon = "Waffe",
["All Cat"] = "Alles (Cata)",
["All Wrath"] = "Alles (WotLK)",
["Enchant Boots"] = "Stiefel verzaubern",
["Enchant Bracer"] = "Armschiene verzaubern",
["Enchant Chest"] = "Brust verzaubern",
["Enchant Cloak"] = "Umhang verzaubern",
["Enchant Gloves"] = "Handschuhe verzaubern",
["Enchant Shield"] = "Schild verzaubern",
["Enchant Weapon"] = "Waffe verzaubern",
["Scroll of (.-)"] = "Rolle der (.-)n?verzauberung",
["Cat Uncommon"] = "Cata Selten",
["Cat Rare"] = "Cata Rar",
["Cat Epic"] = "Cata Episch",
["Cat Meta & JC-only"] = "Cata Meta/Juwelier",
["Cat Meta"] = "WotLK Meta",
["Wrath Uncommon"] = "WotLK Selten",
["Wrath Rare"] = "WotLK Rar",
["Wrath Epic"] = "WotLK Episch",
["Wrath Meta"] = "WotLK Meta",
["BC Epic/Meta"] = "BC Epic/Meta",
["BC Unc/Rare"] = "BC Selten/Rar",
["Minor Glyphs (by class)"] = "Geringe Glyphen (-> Klasse)",
["Minor Glyphs (by ink)"] = "Geringe Glyphen (-> Tinte)",
["Minor Inscription Research"] = "Schwache Inschriftenforschung",
["Northrend Inscription Research"] = "Inschriftenforschung von Nordend",
["Flasks (Cat)"] = "Fläschchen (Cata)",
["Elixirs (Cat)"] = "Elixire (Cata)",
["Flasks"] = "Fläschchen (pre Cata)",
["Battle Elixirs (Wrath)"] = "Kampfelixiere (WotLK)",
["Guardian Elixirs (Wrath)"] = "Wächterelixiere (WotLK)",
["Battle Elixirs (BC)"] = "Kampfelixiere (BC)",
["Guardian Elixirs (BC)"] = "Wächterelixiere (BC)",
["Transmutes (Elemental)"] = "Transmutieren (Elementar)",
["Transmutes (Gems)"] = "Transmutieren (Edelsteine)",
["Transmutes (Metals)"] = "Transmutieren (Metalle)",
["Food"] = "Essen",
["Feasts"] = "Festmahl",
["Emo food"] = "Lebt Eure Gefühle",
} or {}, {__index=function(t,i) return i end})
-------------------------------
-- Addon Namespace --
-------------------------------
local panel = ns.tekPanelAuction("PandaPanel", "Panda", true)
Panda = {panel = panel, locale = L}
local butts, lastbutt = {}
------------------------------
-- Util functions --
------------------------------
function Panda:HideTooltip() GameTooltip:Hide() end
function Panda:ShowTooltip()
if self.tiplink then
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, self.anchor or "TOPRIGHT")
GameTooltip:SetHyperlink(self.tiplink)
elseif self.id then
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, self.anchor or "TOPRIGHT")
GameTooltip:SetHyperlink("item:"..self.id)
elseif self.tiptext then
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, self.anchor or "TOPRIGHT")
GameTooltip:SetText(self.tiptext)
GameTooltip:Show()
end
end
function Panda.GS(cash)
if not cash then return end
if cash > 999999 then return "|cffffd700".. floor(cash/10000) end
cash = cash/100
local s = floor(cash%100)
local g = floor(cash/100)
if g > 0 then return string.format("|cffffd700%d.|cffc7c7cf%02d", g, s)
else return string.format("|cffc7c7cf%d", s) end
end
function Panda.G(cash)
if not cash then return end
return "|cffffd700".. floor(cash/10000)
end
--------------------------
-- Initialize --
--------------------------
panel:SetScript("OnEvent", function(self, event, addon)
if addon ~= myname then return end
PandaDBPC = PandaDBPC or {knowns = {}}
-- Upgrade from old format
if not PandaDBPC.knowns then PandaDBPC = {knowns = (PandaDBPC or {})} end
ns.db = PandaDBPC
self:UnregisterEvent("ADDON_LOADED")
self.ADDON_LOADED = nil
if IsLoggedIn() then
ns.CheckAlchy()
ns.CheckAlchy = nil
self:SetScript("OnEvent", nil)
else
self:RegisterEvent("PLAYER_LOGIN")
self:SetScript("OnEvent", function()
ns.CheckAlchy()
ns.CheckAlchy = nil
self:UnregisterEvent("PLAYER_LOGIN")
self:SetScript("OnEvent", nil)
end)
end
end)
panel:RegisterEvent("ADDON_LOADED")
panel:SetScript("OnShow", function(self)
local opentab = ns.db.lasttab or 1
butts[opentab]:SetChecked(true)
for i,f in pairs(panel.panels) do f:Hide() end
if ns.db.lastsubtab then panel.panels[opentab]:ShowPanel(ns.db.lastsubtab) end
panel.panels[opentab]:Show()
self:SetScript("OnShow", nil)
end)
panel:SetScript("OnHide", function(self)
ns.db.lastsubtab = nil
for i,f in pairs(panel.panels) do if f:IsShown() then ns.db.lasttab = i end end
for name,f in pairs(panel.panels[ns.db.lasttab].frames) do if f:IsShown() then ns.db.lastsubtab = name end end
end)
--------------------------
-- Main panel --
--------------------------
local function OnClick(self)
for i,f in pairs(panel.panels) do f:Hide() end
for i,b in pairs(butts) do b:SetChecked(false) end
panel.panels[self.i]:Show()
self:SetChecked(true)
end
for i,spellid in ipairs{7411, 25229, 45357, 2259, 2550, 76250} do
local name, _, icon = GetSpellInfo(spellid)
local butt = CreateFrame("CheckButton", nil, panel)
butt:SetWidth(32) butt:SetHeight(32)
butt:SetPoint("TOPLEFT", lastbutt or panel, lastbutt and "BOTTOMLEFT" or "TOPRIGHT", lastbutt and 0 or 2, lastbutt and -17 or -65)
butt:SetNormalTexture(icon)
butt:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight")
local tex = butt:CreateTexture(nil, "BACKGROUND")
tex:SetWidth(64) tex:SetHeight(64)
tex:SetPoint("TOPLEFT", -3, 11)
tex:SetTexture("Interface\\SpellBook\\SpellBook-SkillLineTab")
butt.tiptext, butt.i, butt.anchor = name, i
butt:SetScript("OnClick", OnClick)
butt:SetScript("OnEnter", Panda.ShowTooltip)
butt:SetScript("OnLeave", Panda.HideTooltip)
butts[i], lastbutt = butt, butt
end
lastbutt:SetNormalTexture("Interface\\ICONS\\Achievement_Character_Orc_Male_BRN")
lastbutt.tiptext = "Warlords of Draenor"
-----------------------
-- Castbar --
-----------------------
local castbar = CreateFrame("StatusBar", nil, panel)
castbar:SetSize(153, 14)
castbar:SetPoint('BOTTOMLEFT', 21, 19)
castbar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
castbar:SetStatusBarColor(1, 1, 0, 0.35)
castbar:Hide()
local width = castbar:GetWidth()
local spark = castbar:CreateTexture(nil, "OVERLAY")
spark:SetSize(20, 20)
spark:SetBlendMode("ADD")
spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
local time = castbar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
time:SetPoint("RIGHT", castbar, -5, 0)
local text = castbar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
text:SetPoint("LEFT", castbar, 5, 0)
text:SetPoint("RIGHT", time, "LEFT", -5, 0)
text:SetJustifyH("LEFT")
castbar:SetScript('OnEvent', function(self, event, unit)
if unit ~= 'player' then return end
local name, _, title, texture, starttime, endtime = UnitCastingInfo('player')
if not name then return self:Hide() end
text:SetText(title)
self:Show()
end)
castbar:RegisterEvent('UNIT_SPELLCAST_START')
castbar:RegisterEvent('UNIT_SPELLCAST_STOP')
castbar:RegisterEvent('UNIT_SPELLCAST_INTERRUPTED')
castbar:RegisterEvent('UNIT_SPELLCAST_FAILED')
castbar:SetScript('OnShow', function(self)
local name, _, title, texture, starttime, endtime = UnitCastingInfo('player')
endtime = endtime/1000
starttime = starttime/1000
local max = endtime - starttime
self:SetMinMaxValues(0, max)
self:SetValue(0)
spark:SetPoint("CENTER", self, "LEFT")
text:SetText(title)
end)
castbar:SetScript('OnUpdate', function(self)
local name, _, text, texture, starttime, endtime = UnitCastingInfo('player')
if not name then return self:Hide() end
endtime = endtime/1000
starttime = starttime/1000
local max = endtime - starttime
local duration = GetTime() - starttime
self:SetValue(duration)
spark:SetPoint("CENTER", self, "LEFT", (duration / max) * width, 0)
time:SetFormattedText("%.1f", duration)
end)
-----------------------------
-- Slash Handler --
-----------------------------
SLASH_SADPANDA1 = "/panda"
function SlashCmdList.SADPANDA() ShowUIPanel(panel) end
----------------------------------------
-- Quicklaunch registration --
----------------------------------------
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:GetDataObjectByName("Panda") or ldb:NewDataObject("Panda", {type = "launcher", icon = "Interface\\AddOns\\Panda\\icon"})
dataobj.OnClick = function() ShowUIPanel(panel) end