-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitty_power_frame.lua
214 lines (188 loc) · 9.24 KB
/
kitty_power_frame.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
-- TODO: Don't use StatusBar frames. Just use textures.
local addonName, addon = ...
setfenv(1, addon)
local kittyPowerTag = function(unit)
if not _G.UnitIsConnected(unit) then return end
local colorStr, powerStr
local powerType = _G.UnitPowerType(unit)
if powerType == _G.SPELL_POWER_RAGE then
colorStr = settings.powerColors["RAGE"].colorStr
powerStr = _G.UnitPower(unit, _G.SPELL_POWER_RAGE)
else
colorStr = settings.powerColors["ENERGY"].colorStr
powerStr = _G.UnitPower(unit, _G.SPELL_POWER_ENERGY)
end
return "|c" .. colorStr .. powerStr .. "|r"
end
function createKittyPowerFrame(attributes)
local self = _G.CreateFrame("Frame", attributes.name, _G.UIParent)
self:SetPoint(attributes.point, _G[attributes.relativeTo], attributes.relativePoint,
attributes.xOffset, attributes.yOffset)
self:SetWidth(attributes.width)
self:SetHeight(attributes.height)
self:SetBackdrop(settings.unitFrameBackdrop)
self:SetBackdropBorderColor(0.0, 0.0, 0.0, 1.0)
self.tagFrame = _G.CreateFrame("Frame", nil, self)
self.tagFrame.fontString = self.tagFrame:CreateFontString(nil, nil, "NinjaKittyFontStringLeft")
self.tagFrame.fontString:SetPoint("LEFT", self.tagFrame, "LEFT", settings.fontSpacing, 0)
do
local tagFrame = self.tagFrame
tagFrame:SetPoint("TOPLEFT", self, "BOTTOMLEFT", 4, 0)
tagFrame:SetHeight(settings.fontSize + 2 * settings.fontSpacing)
tagFrame:SetBackdrop(settings.kittyPowerFrameBackdrop)
tagFrame:SetBackdropColor(settings.colors.background.r, settings.colors.background.g,
settings.colors.background.b, settings.colors.background.a)
tagFrame:SetBackdropBorderColor(0.0, 0.0, 0.0, 1.0)
end
self.healthFrame = _G.CreateFrame("Frame", nil, self)
self.healthFrame.fontString = self.healthFrame:CreateFontString(nil, nil, "NinjaKittyFontStringLeft")
self.healthFrame.fontString:SetPoint("LEFT", self.healthFrame, "LEFT", settings.fontSpacing, 0)
do
local frame = self.healthFrame
frame:SetPoint("TOPLEFT", self, "BOTTOM", 5, 0)
--frame:SetPoint("TOPRIGHT", self, "BOTTOMRIGHT", -4, 0)
frame:SetHeight(settings.fontSize + 2 * settings.fontSpacing)
frame:SetBackdrop(settings.kittyPowerFrameBackdrop)
frame:SetBackdropColor(settings.colors.background.r, settings.colors.background.g,
settings.colors.background.b, settings.colors.background.a)
frame:SetBackdropBorderColor(0.0, 0.0, 0.0, 1.0)
end
self.healthTag = PercentHealthTag:new("target", function(number)
if number and 25 <= number and number <= 50 then
self.healthFrame.fontString:SetText(number)
self.healthFrame.fontString:SetWidth(self.healthFrame.fontString:GetStringWidth())
self.healthFrame:SetWidth(self.healthFrame.fontString:GetStringWidth() + 2 * settings.fontSpacing)
self.healthFrame:Show()
else
self.healthFrame:Hide()
end
end)
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
self.backgroundStatusBar = _G.CreateFrame("StatusBar", nil, self)
do
local statusBar = self.backgroundStatusBar
statusBar:SetPoint("TOPLEFT", settings.insets.left, -settings.insets.top)
statusBar:SetPoint("BOTTOMRIGHT", -settings.insets.right, settings.insets.bottom)
statusBar:SetReverseFill(true)
statusBar:SetStatusBarTexture(settings.barTexture)
statusBar:SetStatusBarColor(settings.colors.background.r, settings.colors.background.g,
settings.colors.background.b, settings.colors.background.a)
end
self.energyStatusBar = _G.CreateFrame("StatusBar", nil, self)
do
local statusBar = self.energyStatusBar
statusBar:SetPoint("TOPLEFT", settings.insets.left, -settings.insets.top)
statusBar:SetPoint("BOTTOMRIGHT", -settings.insets.right, settings.insets.bottom)
statusBar:SetStatusBarTexture(settings.barTexture)
local energyColor = settings.powerColors["ENERGY"]
end
self.rageStatusBar = _G.CreateFrame("StatusBar", nil, self)
do
local statusBar = self.rageStatusBar
statusBar:SetPoint("TOPLEFT", settings.insets.left, -settings.insets.top)
statusBar:SetPoint("BOTTOMRIGHT", -settings.insets.right, settings.insets.bottom)
statusBar:SetStatusBarTexture(settings.barTexture)
local color = settings.powerColors["RAGE"]
statusBar:SetStatusBarColor(color.r, color.g, color.b, color.a)
end
----------------------------------------------------------------------------------------------------------------------
self:SetScript("OnEvent", function(self, event, ...)
return self[event](self, ...)
end)
function self:UNIT_MAXPOWER(unit)
local energyMax = _G.UnitPowerMax(unit, _G.SPELL_POWER_ENERGY)
local rageMax = _G.UnitPowerMax(unit, _G.SPELL_POWER_RAGE)
local energyBarMax = _G.select(2, self.energyStatusBar:GetMinMaxValues())
local rageBarMax = _G.select(2, self.rageStatusBar:GetMinMaxValues())
if energyMax and rageMax and energyBarMax and rageBarMax then
if energyMax ~= energyBarMax or rageMax ~= rageBarMax then
self.backgroundStatusBar:SetMinMaxValues(0, _G.math.max(energyMax, rageMax))
self.energyStatusBar:SetMinMaxValues(0, _G.math.max(energyMax, rageMax))
self.rageStatusBar:SetMinMaxValues(0, _G.math.max(energyMax, rageMax))
self:UNIT_POWER_FREQUENT(unit)
end
end
end
self:RegisterUnitEvent("UNIT_MAXPOWER", "player")
function self:UNIT_POWER_FREQUENT(unit)
if _G.UnitIsDeadOrGhost(unit) then
self.energyStatusBar:SetValue(0)
self.rageStatusBar:SetValue(0)
self.backgroundStatusBar:SetValue((_G.select(2, self.backgroundStatusBar:GetMinMaxValues())))
self.tagFrame:Hide()
else
local energyMax = _G.UnitPowerMax(unit, _G.SPELL_POWER_ENERGY)
local energy = _G.UnitPower(unit, _G.SPELL_POWER_ENERGY)
local rageMax = _G.UnitPowerMax(unit, _G.SPELL_POWER_RAGE)
local rage = _G.UnitPower(unit, _G.SPELL_POWER_RAGE)
self.energyStatusBar:SetValue(energy)
if _G.UnitPowerType(unit) == _G.SPELL_POWER_RAGE then
local offset = self.rageStatusBar:GetWidth() * rage / rageMax -- Rounding this doesn't work out.
self.energyStatusBar:SetPoint("TOPLEFT", settings.insets.left + offset, -settings.insets.top)
self.energyStatusBar:SetMinMaxValues(rage, energyMax)
self.rageStatusBar:SetValue(rage)
end
if _G.UnitPowerType(unit) == _G.SPELL_POWER_RAGE and energy * rageMax < rage * energyMax then
-- The filled portion of the energy bar is shorter than that of the rage bar.
self.backgroundStatusBar:SetValue(rageMax - rage)
else
self.backgroundStatusBar:SetValue(energyMax - energy)
end
if _G.UnitPowerType(unit) ~= _G.SPELL_POWER_RAGE and energy == energyMax then
self.tagFrame:Hide()
else
self.tagFrame:Show()
self.tagFrame.fontString:SetText(kittyPowerTag(unit))
self.tagFrame.fontString:SetWidth(self.tagFrame.fontString:GetStringWidth())
self.tagFrame:SetWidth(self.tagFrame.fontString:GetStringWidth() + 2 * settings.fontSpacing)
end
end
end
self:RegisterUnitEvent("UNIT_POWER_FREQUENT", "player")
function self:UNIT_DISPLAYPOWER(unit)
local energyMax = _G.UnitPowerMax(unit, _G.SPELL_POWER_ENERGY)
local color = settings.powerColors["ENERGY"]
if _G.UnitPowerType(unit) == _G.SPELL_POWER_ENERGY then
self.energyStatusBar:SetStatusBarColor(color.r, color.g, color.b, color.a)
else
self.energyStatusBar:SetStatusBarColor(color.r, color.g, color.b, 0.5)
end
if _G.UnitPowerType(unit) == _G.SPELL_POWER_RAGE then
else
self.energyStatusBar:SetPoint("TOPLEFT", settings.insets.left, -settings.insets.top)
self.energyStatusBar:SetPoint("BOTTOMRIGHT", -settings.insets.right, settings.insets.bottom)
self.energyStatusBar:SetMinMaxValues(0, energyMax)
self.rageStatusBar:SetValue(0)
end
self:UNIT_POWER_FREQUENT(unit)
end
self:RegisterUnitEvent("UNIT_DISPLAYPOWER", "player")
----------------------------------------------------------------------------------------------------------------------
-- Stuff we need to do when PLAYER_LOGIN fires.
function self:initialize()
local energyMax = _G.UnitPowerMax("player", _G.SPELL_POWER_ENERGY)
local rageMax = _G.UnitPowerMax("player", _G.SPELL_POWER_RAGE)
self.backgroundStatusBar:SetMinMaxValues(0, _G.math.max(energyMax, rageMax))
self.energyStatusBar:SetMinMaxValues(0, _G.math.max(energyMax, rageMax))
self.rageStatusBar:SetMinMaxValues(0, _G.math.max(energyMax, rageMax))
self.healthTag:enable()
end
-- Stuff we need to do when PLAYER_ENTERING_WORLD fires.
function self:update()
self:UNIT_DISPLAYPOWER("player")
self.healthTag:update()
end
function self:PLAYER_LOGIN()
self:initialize()
end
self:RegisterEvent("PLAYER_LOGIN")
function self:PLAYER_ENTERING_WORLD()
self:update()
end
self:RegisterEvent("PLAYER_ENTERING_WORLD")
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
return self
end
-- vim: tw=120 sts=2 sw=2 et