forked from KasVital/Addons-for-Vanilla-1.12.1-CFM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMH3_Blizzard.lua
235 lines (201 loc) · 7.08 KB
/
MH3_Blizzard.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
--[[
MobHealth3: Blizzard Frames!
"I don't need no flashy unit frame mods!" "Sage isn't flashy!" "Shhh, you!"
By Neronix of Hellscream EU
Some code by KamuiGT
Based on code from MobHealth2
--]]
if not MobHealth3 then error("<MH3 Blizzard Frames> MobHealth3 isn't loaded! Are you SURE you have MobHealth3 installed?"); return; end
MH3Blizz = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceConsole-2.0")
local L = AceLibrary("AceLocale-2.0"):new("MH3Blizz")
local waterfall = AceLibrary("Waterfall-1.0")
--[[
File-scope local vars
--]]
local htext, ptext
--[[
Init/Enable methods
--]]
function MH3Blizz:OnInitialize()
MH3BlizzConfig = MH3BlizzConfig or {
healthX = 0,
healthY = 0,
powerX = 0,
powerY = 0,
healthAbs = true,
healthPerc = true,
powerAbs = true,
powerPerc = true,
}
-- Create frame and fontstrings
local frame = CreateFrame("frame", "MobHealth3BlizzardFrame", TargetFrame)
htext = frame:CreateFontString("MobHealth3BlizzardHealthText", "ARTWORK")
htext:SetFontObject(GameFontNormalSmall)
htext:SetHeight(32)
htext:SetPoint("TOP", TargetFrameHealthBar, "BOTTOM", MH3BlizzConfig.healthX-2, MH3BlizzConfig.healthY+22)
htext:SetTextColor(1, 1, 1, 1)
ptext = frame:CreateFontString("MobHealth3BlizzardPowerText", "ARTWORK")
ptext:SetFontObject(GameFontNormalSmall)
ptext:SetHeight(32)
ptext:SetPoint("TOP", TargetFrameManaBar, "BOTTOM", MH3BlizzConfig.powerX-2, MH3BlizzConfig.powerY+22)
ptext:SetTextColor(1, 1, 1, 1)
self.options = {
type = "group",
args = {
abshealth = {
name = L"Show absolute health",
desc = L"Toggles showing absolute health on the target frame",
type = "toggle",
get = function() return MH3BlizzConfig.healthAbs end,
set = function(val)
MH3BlizzConfig.healthAbs = val
self:HealthUpdate()
end,
},
perchealth = {
name = L"Show health percentage",
desc = L"Toggles showing percentage health on the target frame",
type = "toggle",
get = function() return MH3BlizzConfig.healthPerc end,
set = function(val)
MH3BlizzConfig.healthPerc = val
self:HealthUpdate()
end,
},
abspower = {
name = L"Show absolute power",
desc = L"Toggles showing absolute mana/energy/rage on the target frame",
type = "toggle",
get = function() return MH3BlizzConfig.powerAbs end,
set = function(val)
MH3BlizzConfig.powerAbs = val
self:PowerUpdate()
end,
},
percpower = {
name = L"Show power percentage",
desc = L"Toggles showing percentage mana/energy/rage on the target frame",
type = "toggle",
get = function() return MH3BlizzConfig.powerPerc end,
set = function(val)
MH3BlizzConfig.powerPerc = val
self:PowerUpdate()
end,
},
healthx = {
name = L"Health X offset",
desc = L"Adjusts the X offset of the health text",
type = "text",
usage = "<number>",
get = function() return MH3BlizzConfig.healthX end,
set = function(val)
MH3BlizzConfig.healthX = tonumber(val)
htext:SetPoint("TOP", TargetFrameHealthBar, "BOTTOM", MH3BlizzConfig.healthX-2, MH3BlizzConfig.healthY+22)
end,
},
healthy = {
name = L"Health Y offset",
desc = L"Adjusts the Y offset of the health text",
type = "text",
usage = "<number>",
get = function() return MH3BlizzConfig.healthY end,
set = function(val)
MH3BlizzConfig.healthY = tonumber(val)
htext:SetPoint("TOP", TargetFrameHealthBar, "BOTTOM", MH3BlizzConfig.healthX-2, MH3BlizzConfig.healthY+22)
end,
},
powerx = {
name = L"Power X offset",
desc = L"Adjusts the X offset of the power text",
type = "text",
usage = "<number>",
get = function() return MH3BlizzConfig.powerX end,
set = function(val)
MH3BlizzConfig.powerX = tonumber(val)
ptext:SetPoint("TOP", TargetFrameManaBar, "BOTTOM", MH3BlizzConfig.powerX-2, MH3BlizzConfig.powerY+22)
end,
},
powery = {
name = L"Power Y offset",
desc = L"Adjusts the Y offset of the power text",
type = "text",
usage = "<number>",
get = function() return MH3BlizzConfig.powerY end,
set = function(val)
MH3BlizzConfig.powerY = tonumber(val)
ptext:SetPoint("TOP", TargetFrameManaBar, "BOTTOM", MH3BlizzConfig.powerX-2, MH3BlizzConfig.powerY+22)
end,
},
},
}
self:RegisterChatCommand({"/mh3bcl", "/mh3blizzcl"}, self.options)
self:RegisterChatCommand({ "/mh3b", "/mh3blizz"}, function() waterfall:Open('MH3Blizz') end)
waterfall:Register('MH3Blizz', 'aceOptions', self.options, 'title','MH3Blizz 1.2. Revision: 12749','colorR', 0.8, 'colorG', 0.6, 'colorB', 0.7)
-- WARNING WARNING WARNING
-- BIG DIRTY HACK AHEAD
TargetDeadText:SetText()
-- Ok, it wasn't even big, nor was it actually a hack
end
function MH3Blizz:OnEnable()
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("UNIT_MANA")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
end
--[[
Event handlers
--]]
function MH3Blizz:UNIT_HEALTH()
if arg1 == "target" then self:HealthUpdate() end
end
function MH3Blizz:UNIT_MANA()
if arg1 == "target" then self:PowerUpdate() end
end
function MH3Blizz:PLAYER_TARGET_CHANGED()
if UnitExists("target") then
self:HealthUpdate()
self:PowerUpdate()
end
end
--[[
Updaters
--]]
function MH3Blizz:HealthUpdate()
local cur, max = MobHealth3:GetUnitHealth("target", UnitHealth("target"), UnitHealthMax("target"))
local absText, percText = "", ""
-- Set absolute text
if MH3BlizzConfig.healthAbs then
if max == 100 then
-- Do nothing!
elseif max > 999999 then
-- Display numbers in K notation
absText = string.format("%dK/%dK", cur/1000, max/1000)
else
absText = string.format("%d/%d", cur, max)
end
end
-- Set percentage text
if MH3BlizzConfig.healthPerc then
percText = string.format("(%d%%)", max == 100 and cur or math.floor(cur/max*100 + 0.5))
end
htext:SetText(absText.." "..percText)
end
function MH3Blizz:PowerUpdate()
local cur, max = UnitMana("target"), UnitManaMax("target")
-- No power? No text!
if max == 0 then ptext:SetText(); return; end
local absText, percText = "", ""
-- Set absolute text
if MH3BlizzConfig.powerAbs then
if max > 999999 then
-- Display numbers in K notation
absText = string.format("%dK/%dK", cur/1000, max/1000)
else
absText = string.format("%d/%d", cur, max)
end
end
-- Set percentage text
if MH3BlizzConfig.powerPerc then
percText = string.format("(%d%%)", max == 100 and cur or math.floor(cur/max*100 + 0.5))
end
ptext:SetText(absText.." "..percText)
end