File src/ChorusUnitGroupRoleFrameTemplate.lua changed (mode: 100644) (index f2d3b33..5dd9745) |
1 |
1 |
local Chorus = Chorus |
local Chorus = Chorus |
2 |
2 |
|
|
|
3 |
|
local strtrim = strtrim |
|
4 |
|
|
3 |
5 |
local UnitExists = Chorus.test.UnitExists or UnitExists |
local UnitExists = Chorus.test.UnitExists or UnitExists |
4 |
6 |
local UnitGroupRolesAssigned = Chorus.test.UnitGroupRolesAssigned or UnitGroupRolesAssigned |
local UnitGroupRolesAssigned = Chorus.test.UnitGroupRolesAssigned or UnitGroupRolesAssigned |
5 |
7 |
local UnitIsConnected = Chorus.test.UnitIsConnected or UnitIsConnected |
local UnitIsConnected = Chorus.test.UnitIsConnected or UnitIsConnected |
6 |
8 |
|
|
7 |
9 |
local SecureButton_GetUnit = Chorus.test.SecureButton_GetUnit or SecureButton_GetUnit |
local SecureButton_GetUnit = Chorus.test.SecureButton_GetUnit or SecureButton_GetUnit |
8 |
10 |
|
|
9 |
|
--[[ FIXME Only tank role texture is ever rendered. ]]-- |
|
|
11 |
|
local fallbackRoleMap |
|
12 |
|
|
|
13 |
|
local cache = {} |
|
14 |
|
|
|
15 |
|
--[[ TODO Since `function UnitSetRole` is backported, implement mechanism to |
|
16 |
|
set it automatically, inferred from talents. ]]-- |
|
17 |
|
|
|
18 |
|
local function updateEveryRoleWidget() |
|
19 |
|
assert(cache ~= nil) |
|
20 |
|
assert('table' == type(cache)) |
|
21 |
|
|
|
22 |
|
for _, frame in pairs(cache) do |
|
23 |
|
if frame then |
|
24 |
|
local callback = frame:GetScript('OnEvent') |
|
25 |
|
if callback then |
|
26 |
|
callback(frame, 'PARTY_MEMBERS_CHANGED') |
|
27 |
|
end |
|
28 |
|
end |
|
29 |
|
end |
|
30 |
|
end |
|
31 |
|
|
|
32 |
|
--[[ |
|
33 |
|
Set fallback unit group role for given unit. |
|
34 |
|
|
|
35 |
|
When unit role is checked by role widget that this module implements, given |
|
36 |
|
role could not be determined by any other means, use the role that was assigned |
|
37 |
|
using this function. |
|
38 |
|
|
|
39 |
|
It is expected from the user to call this function manually or at least |
|
40 |
|
explicitly with a thin layer of graphical buttons. |
|
41 |
|
|
|
42 |
|
@function Chorus.UnitSetRole |
|
43 |
|
]] |
|
44 |
|
function Chorus.UnitSetRole(unitDesignation, roleDesignation) |
|
45 |
|
assert(unitDesignation ~= nil) |
|
46 |
|
assert('string' == type(unitDesignation)) |
|
47 |
|
unitDesignation = string.lower(strtrim(unitDesignation)) |
|
48 |
|
assert(string.len(unitDesignation) >= 1) |
|
49 |
|
assert(string.len(unitDesignation) <= 256) |
|
50 |
|
|
|
51 |
|
assert(roleDesignation ~= nil) |
|
52 |
|
assert('string' == type(roleDesignation)) |
|
53 |
|
roleDesignation = string.upper(strtrim(roleDesignation)) |
|
54 |
|
assert(string.len(roleDesignation) >= 1) |
|
55 |
|
assert(string.len(roleDesignation) <= 256) |
|
56 |
|
|
|
57 |
|
assert('TANK' == roleDesignation or 'HEALER' == |
|
58 |
|
roleDesignation or 'DAMAGER' == roleDesignation, |
|
59 |
|
'invalid argument: invalid enum: must be valid player ' .. |
|
60 |
|
'group role string') |
|
61 |
|
|
|
62 |
|
if not UnitExists(unitDesignation) then |
|
63 |
|
return false |
|
64 |
|
end |
|
65 |
|
|
|
66 |
|
local i = UnitGUID(unitDesignation) |
|
67 |
|
if not i then |
|
68 |
|
return false |
|
69 |
|
end |
|
70 |
|
|
|
71 |
|
fallbackRoleMap[i] = roleDesignation |
|
72 |
|
|
|
73 |
|
updateEveryRoleWidget() |
|
74 |
|
|
|
75 |
|
return true |
|
76 |
|
end |
|
77 |
|
|
|
78 |
|
do |
|
79 |
|
--[[ Backport `function UnitSetRole` from Cata back to Wrath. ]]-- |
|
80 |
|
if not UnitSetRole and 40000 > select(4, GetBuildInfo()) then |
|
81 |
|
UnitSetRole = Chorus.UnitSetRole |
|
82 |
|
end |
|
83 |
|
end |
10 |
84 |
|
|
11 |
85 |
local function getUnitGroupRoleDesignation(unitDesignation) |
local function getUnitGroupRoleDesignation(unitDesignation) |
12 |
|
local isTank, isHealer, isDamage = UnitGroupRolesAssigned(unitDesignation) |
|
|
86 |
|
assert(unitDesignation ~= nil) |
|
87 |
|
assert('string' == type(unitDesignation)) |
|
88 |
|
|
|
89 |
|
assert(fallbackRoleMap ~= nil) |
|
90 |
|
assert('table' == type(fallbackRoleMap)) |
13 |
91 |
|
|
14 |
92 |
local roleDesignation |
local roleDesignation |
15 |
93 |
|
|
16 |
|
--[[ Corner case for Interface >= 40000 version of the API. ]]-- |
|
17 |
|
--[[ TODO Query API version at runtime. There must be a function. ]]-- |
|
18 |
|
if 'string' == type(isTank) then |
|
19 |
|
roleDesignation = isTank |
|
20 |
|
elseif isTank then |
|
21 |
|
roleDesignation = 'TANK' |
|
22 |
|
elseif isHealer then |
|
23 |
|
roleDesignation = 'HEALER' |
|
24 |
|
elseif isDamage then |
|
25 |
|
roleDesignation = 'DAMAGER' |
|
|
94 |
|
local interfaceNumber = select(4, GetBuildInfo()) |
|
95 |
|
if 40000 > interfaceNumber then |
|
96 |
|
--[[ Is Wrath ]]-- |
|
97 |
|
local isTank, isHealer, isDamage = UnitGroupRolesAssigned(unitDesignation) |
|
98 |
|
|
|
99 |
|
if isTank then |
|
100 |
|
roleDesignation = 'TANK' |
|
101 |
|
elseif isHealer then |
|
102 |
|
roleDesignation = 'HEALER' |
|
103 |
|
elseif isDamage then |
|
104 |
|
roleDesignation = 'DAMAGER' |
|
105 |
|
end |
26 |
106 |
else |
else |
27 |
|
roleDesignation = nil |
|
|
107 |
|
--[[ Is Cata ]]-- |
|
108 |
|
--[[ TODO Test if the role widget implementation works on both 30300 and 40000. ]]-- |
|
109 |
|
roleDesignation = UnitGroupRolesAssigned(unitDesignation) |
|
110 |
|
end |
|
111 |
|
|
|
112 |
|
if not roleDesignation then |
|
113 |
|
local i = UnitGUID(unitDesignation) |
|
114 |
|
if i then |
|
115 |
|
roleDesignation = fallbackRoleMap[i] |
|
116 |
|
else |
|
117 |
|
roleDesignation = nil |
|
118 |
|
end |
28 |
119 |
end |
end |
29 |
120 |
|
|
30 |
121 |
return roleDesignation |
return roleDesignation |
|
... |
... |
local function eventProcessor(self) |
89 |
180 |
local unitDesignation = SecureButton_GetUnit(self) |
local unitDesignation = SecureButton_GetUnit(self) |
90 |
181 |
|
|
91 |
182 |
if not unitDesignation or not UnitExists(unitDesignation) or not |
if not unitDesignation or not UnitExists(unitDesignation) or not |
92 |
|
UnitIsConnected(unitDesignation) or not |
|
93 |
|
UnitGroupRolesAssigned(unitDesignation) then |
|
|
183 |
|
UnitIsConnected(unitDesignation) then |
94 |
184 |
self:Hide() |
self:Hide() |
95 |
185 |
return |
return |
96 |
186 |
end |
end |
|
... |
... |
local function eventProcessor(self) |
99 |
189 |
applyRole(self, roleDesignation) |
applyRole(self, roleDesignation) |
100 |
190 |
end |
end |
101 |
191 |
|
|
|
192 |
|
local function roleMapFrameMain(self) |
|
193 |
|
assert(self ~= nil) |
|
194 |
|
|
|
195 |
|
self:RegisterEvent('VARIABLES_LOADED') |
|
196 |
|
self:SetScript('OnEvent', function() |
|
197 |
|
if not ChorusUnitGroupRoleMap then |
|
198 |
|
ChorusUnitGroupRoleMap = {} |
|
199 |
|
end |
|
200 |
|
fallbackRoleMap = ChorusUnitGroupRoleMap or {} |
|
201 |
|
assert(fallbackRoleMap ~= nil) |
|
202 |
|
assert('table' == type(fallbackRoleMap)) |
|
203 |
|
end) |
|
204 |
|
end |
|
205 |
|
|
102 |
206 |
local function main(self) |
local function main(self) |
103 |
207 |
assert(self ~= nil) |
assert(self ~= nil) |
104 |
208 |
|
|
|
... |
... |
local function main(self) |
112 |
216 |
self:RegisterEvent('RAID_ROSTER_UPDATE') |
self:RegisterEvent('RAID_ROSTER_UPDATE') |
113 |
217 |
|
|
114 |
218 |
self:SetScript('OnEvent', eventProcessor) |
self:SetScript('OnEvent', eventProcessor) |
|
219 |
|
|
|
220 |
|
cache[self:GetName()] = self |
115 |
221 |
end |
end |
116 |
222 |
|
|
|
223 |
|
Chorus.unitGroupRoleMapFrameMain = function(...) |
|
224 |
|
return roleMapFrameMain(...) |
|
225 |
|
end |
117 |
226 |
Chorus.unitGroupRoleFrameMain = function(...) |
Chorus.unitGroupRoleFrameMain = function(...) |
118 |
227 |
return main(...) |
return main(...) |
119 |
228 |
end |
end |