-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridStatusName.lua
More file actions
104 lines (91 loc) · 2.41 KB
/
GridStatusName.lua
File metadata and controls
104 lines (91 loc) · 2.41 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")
--}}}
GridStatusName = GridStatus:NewModule("GridStatusName")
GridStatusName.menuName = "Unit Name"
--{{{ AceDB defaults
GridStatusName.defaultDB = {
debug = false,
unit_name = {
text = "Unit Name",
enable = true,
color = { r = 1, g = 1, b = 1, a = 1 },
priority = 1,
letters = 8,
class = true,
},
}
--}}}
GridStatusName.options = false
--{{{ additional options
local nameOptions = {
["letters"] = {
type = 'range',
name = L["Letters"],
desc = L["Number of unit name letters."],
get = function() return GridStatusName.db.profile.unit_name.letters end,
set = function(v)
GridStatusName.db.profile.unit_name.letters = v
GridStatusName:UpdateAllUnits()
end,
min = 0,
max = 8,
step = 1,
isPercent = false,
order = 120,
},
["class"] = {
type = 'toggle',
name = L["Color by class"],
desc = L["Color by class"],
get = function() return GridStatusName.db.profile.unit_name.class end,
set = function()
GridStatusName.db.profile.unit_name.class = not GridStatusName.db.profile.unit_name.class
GridStatusName:UpdateAllUnits()
end,
order = 150,
},
["range"] = false, -- this module doesnt need a range filter, so lets remove the option
-- unfortunately it doesnt work anyway. sigh.
}
--}}}
function GridStatusName:OnInitialize()
self.super.OnInitialize(self)
self:RegisterStatus("unit_name", L["Unit Name"], nameOptions, true)
end
function GridStatusName:OnEnable()
self:RegisterEvent("Grid_UnitChanged", "UpdateUnit")
self:RegisterEvent("Grid_UnitJoined", "UpdateUnit")
self:UpdateAllUnits()
end
function GridStatusName:Reset()
self.super.Reset(self)
self:UpdateAllUnits()
end
function GridStatusName:UpdateUnit(name, unitid)
local settings = self.db.profile.unit_name
-- set text
local text = ""
if settings.letters >= 1 then
text = string.sub(name, 1, settings.letters)
end
-- set color
local color = settings.color
if settings.class then
local u = RL:GetUnitObjectFromName(name)
color = RAID_CLASS_COLORS[u.class]
color.a = 1
end
self.core:SendStatusGained(name, "unit_name",
settings.priority,
nil,
color,
text)
end
function GridStatusName:UpdateAllUnits()
local name, status, statusTbl
for name, status, statusTbl in self.core:CachedStatusIterator("unit_name") do
self:UpdateUnit(name)
end
end