-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridStatusManaBar.lua
More file actions
104 lines (82 loc) · 2.28 KB
/
Copy pathGridStatusManaBar.lua
File metadata and controls
104 lines (82 loc) · 2.28 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
--{{{ Libraries
local RL = AceLibrary("RosterLib-2.0")
local L = AceLibrary("AceLocale-2.2"):new("Grid")
local Compost = AceLibrary("Compost-2.0")
--}}}
GridStatusManaBar = GridStatus:NewModule("GridStatusManaBar")
GridStatusManaBar.menuName = L["Mana Bar"]
--{{{ AceDB defaults
GridStatusManaBar.defaultDB = {
debug = false,
unit_mana = {
enable = true,
color = { r = 0, g = 0.4, b = 1, a = 1 },
priority = 30,
range = true,
}
}
function GridStatusManaBar:OnInitialize()
self.super.OnInitialize(self)
self.deathCache = Compost:Acquire()
self:RegisterStatus("unit_mana", L["Unit Mana"])
end
function GridStatusManaBar:OnEnable()
self:RegisterEvent("Grid_UnitJoined")
self:RegisterBucketEvent("UNIT_MANA", 0.2)
end
function GridStatusManaBar:Reset()
self.super.Reset(self)
self:UpdateAllUnits()
end
function GridStatusManaBar:UpdateAllUnits()
local name, status, statusTbl
self.deathCache = Compost:Erase(self.deathCache)
for name, status, statusTbl in self.core:CachedStatusIterator("unit_mana") do
self:Grid_UnitJoined(name)
end
end
function GridStatusManaBar:UNIT_MANA(units)
local unitid
local settings = self.db.profile.unit_mana
for unitid in pairs(units) do
self:UpdateUnit(unitid)
end
end
function GridStatusManaBar:Grid_UnitJoined(name)
local unitid = RL:GetUnitIDFromName(name)
if unitid then
self:UpdateUnit(unitid, true)
self:UpdateUnit(unitid)
end
end
function GridStatusManaBar:UnitPowerColor(powerType)
GridStatusManaBar:Debug("Type ", powerType)
local color = { r = 0, g = 0.4, b = 1, a = 1 }
-- energy
if powerType == 3 then
color = { r = 0, g = 1, b = 0, a = 0.5 }
-- rage
elseif powerType == 1 then
color = { r = 1, g = 0, b = 0, a = 1 }
end
GridStatusManaBar:Debug("Color ", color)
return color
end
function GridStatusManaBar:UpdateUnit(unitid, ignoreRange)
local cur, max = UnitMana(unitid), UnitManaMax(unitid)
local name = UnitName(unitid)
local settings = self.db.profile.unit_mana
local priority = settings.priority
local powerType = UnitPowerType(unitid);
if not name then return end
if UnitIsDeadOrGhost(unitid) then
cur = 0
end
self.core:SendStatusGained(name, "unit_mana",
priority,
(not ignoreRange and settings.range and 40),
(self:UnitPowerColor(powerType) or settings.color),
nil,
cur, max,
nil)
end