File src/ChorusPetFrameTemplate.lua changed (mode: 100644) (index b9070f2..4cb3dac) |
... |
... |
local ChorusPetFrameSecureHandler = ChorusPetFrameSecureHandler |
4 |
4 |
local strtrim = strtrim |
local strtrim = strtrim |
5 |
5 |
|
|
6 |
6 |
local CreateFrame = CreateFrame |
local CreateFrame = CreateFrame |
7 |
|
local SecureCmdOptionParse = SecureCmdOptionParse |
|
8 |
7 |
|
|
9 |
|
local function petButtonFactory(petFrame, petButtonTemplate) |
|
|
8 |
|
local function petButtonFactory(petFrame, petButtonTemplate, secureHandler, secureScriptBody) |
10 |
9 |
assert(petFrame ~= nil) |
assert(petFrame ~= nil) |
11 |
10 |
|
|
12 |
11 |
if not petButtonTemplate then |
if not petButtonTemplate then |
13 |
12 |
petButtonTemplate = 'ChorusPetButtonTemplate' |
petButtonTemplate = 'ChorusPetButtonTemplate' |
14 |
13 |
end |
end |
15 |
14 |
|
|
|
15 |
|
assert(secureHandler ~= nil) |
|
16 |
|
|
|
17 |
|
assert(secureScriptBody ~= nil) |
|
18 |
|
|
16 |
19 |
assert(petButtonTemplate ~= nil) |
assert(petButtonTemplate ~= nil) |
17 |
20 |
assert('string' == type(petButtonTemplate)) |
assert('string' == type(petButtonTemplate)) |
18 |
21 |
petButtonTemplate = strtrim(petButtonTemplate) |
petButtonTemplate = strtrim(petButtonTemplate) |
|
... |
... |
local function petButtonFactory(petFrame, petButtonTemplate) |
39 |
42 |
local u = 'raidpet' .. tostring(i) |
local u = 'raidpet' .. tostring(i) |
40 |
43 |
b:SetAttribute('unit', u) |
b:SetAttribute('unit', u) |
41 |
44 |
b:SetID(i) |
b:SetID(i) |
42 |
|
end |
|
43 |
|
end |
|
44 |
45 |
|
|
45 |
|
local function petFrameSecureCmdFactory() |
|
46 |
|
local secureCmd = '' |
|
|
46 |
|
assert(b:IsProtected()) |
47 |
47 |
|
|
48 |
|
secureCmd = '[@party1pet,exists] party1pet; ' .. secureCmd |
|
49 |
|
secureCmd = '[@party2pet,exists] party2pet; ' .. secureCmd |
|
50 |
|
secureCmd = '[@party3pet,exists] party3pet; ' .. secureCmd |
|
51 |
|
secureCmd = '[@party4pet,exists] party4pet; ' .. secureCmd |
|
|
48 |
|
local secureCmd = string.format('[@%s,exists] 1; [@%s,noexists] 0;', u, u) |
|
49 |
|
--print(secureCmd, '|', SecureCmdOptionParse(secureCmd)) |
|
50 |
|
RegisterStateDriver(b, 'unitexists', secureCmd) |
52 |
51 |
|
|
53 |
|
local i = 0 |
|
54 |
|
local MAX_RAID_MEMBERS = MAX_RAID_MEMBERS or 40; |
|
55 |
|
while(i < MAX_RAID_MEMBERS) do |
|
56 |
|
i = i + 1 |
|
57 |
|
secureCmd = string.format('[@raidpet%d,exists] raidpet%d; ', i, i) .. secureCmd |
|
|
52 |
|
secureHandler:WrapScript(b, 'OnAttributeChanged', secureScriptBody) |
58 |
53 |
end |
end |
59 |
|
|
|
60 |
|
return secureCmd |
|
61 |
|
end |
|
62 |
|
|
|
63 |
|
function Chorus.unpepe() |
|
64 |
|
local secureCmd = petFrameSecureCmdFactory() |
|
65 |
|
print('SecureCmdOptionParse', SecureCmdOptionParse(secureCmd)) |
|
66 |
|
end |
|
67 |
|
|
|
68 |
|
function Chorus.opopo() |
|
69 |
|
local secureCmd = petFrameSecureCmdFactory() |
|
70 |
|
print('SecureCmdOptionParse', secureCmd) |
|
71 |
54 |
end |
end |
72 |
55 |
|
|
73 |
56 |
function Chorus.petFrameMain(petFrame) |
function Chorus.petFrameMain(petFrame) |
74 |
57 |
assert(petFrame ~= nil) |
assert(petFrame ~= nil) |
75 |
|
print('pipirwa1') |
|
76 |
|
|
|
77 |
|
petButtonFactory(petFrame) |
|
78 |
58 |
|
|
79 |
59 |
petFrame:RegisterEvent('PARTY_CONVERTED_TO_RAID') |
petFrame:RegisterEvent('PARTY_CONVERTED_TO_RAID') |
80 |
60 |
petFrame:RegisterEvent('PARTY_MEMBERS_CHANGED') |
petFrame:RegisterEvent('PARTY_MEMBERS_CHANGED') |
|
... |
... |
function Chorus.petFrameMain(petFrame) |
88 |
68 |
Wrap state listener for buttons instead. |
Wrap state listener for buttons instead. |
89 |
69 |
]] |
]] |
90 |
70 |
|
|
91 |
|
local secureCmd = petFrameSecureCmdFactory() |
|
92 |
|
RegisterStateDriver(secureHandler, 'raidpet', secureCmd) |
|
|
71 |
|
--[[-- @fixme Replace hardcoded button dimensions. |
|
72 |
|
]] |
93 |
73 |
|
|
94 |
74 |
local secureScriptBody = [[ |
local secureScriptBody = [[ |
95 |
|
print(self:GetName(), owner:GetName(), name, value) |
|
|
75 |
|
-- When attribute changed, given it was not 'unitexists', exit. |
|
76 |
|
-- When script executed explicitly, ignore the check and continue. |
|
77 |
|
-- WARNING: Filtering by attribute change is required. Otherwise it may crash the game. |
|
78 |
|
if name and name ~= 'state-unitexists' then |
|
79 |
|
return |
|
80 |
|
end |
96 |
81 |
|
|
97 |
|
local petFrame = self:GetFrameRef('ChorusPetFrame') |
|
|
82 |
|
local petFrame = owner:GetFrameRef('ChorusPetFrame') |
|
83 |
|
if not petFrame then |
|
84 |
|
print('ChorusPetFrameTemplate.lua: could not find pet frame') |
|
85 |
|
return |
|
86 |
|
end |
98 |
87 |
|
|
99 |
88 |
local buttonWidth = 64 |
local buttonWidth = 64 |
100 |
89 |
local buttonHeight = 16 |
local buttonHeight = 16 |
101 |
90 |
|
|
102 |
|
local i = 0 |
|
103 |
91 |
local column = 0 |
local column = 0 |
104 |
92 |
local row = 0 |
local row = 0 |
|
93 |
|
|
|
94 |
|
local i = 0 |
105 |
95 |
local t = newtable() |
local t = newtable() |
106 |
96 |
petFrame:GetChildList(t) |
petFrame:GetChildList(t) |
107 |
|
while(i < #t) do |
|
|
97 |
|
while (i < #t) do |
108 |
98 |
i = i + 1 |
i = i + 1 |
|
99 |
|
|
109 |
100 |
local b = t[i] |
local b = t[i] |
|
101 |
|
if not b then |
|
102 |
|
print('ChorusPetFrameTemplate.lua: empty child') |
|
103 |
|
return |
|
104 |
|
end |
|
105 |
|
|
110 |
106 |
local u = b:GetAttribute('unit') |
local u = b:GetAttribute('unit') |
111 |
107 |
if UnitExists(u) then |
if UnitExists(u) then |
112 |
|
local x = buttonWidth * column |
|
113 |
|
local y = buttonHeight * row |
|
114 |
|
-- Relative point is required. |
|
115 |
|
-- Relative frame must be protected also. |
|
116 |
|
b:SetPoint('BOTTOMLEFT', petFrame, 'BOTTOMLEFT', x, y) |
|
|
108 |
|
-- WARNING: Toggling visibility triggers attribute change. |
117 |
109 |
b:Show() |
b:Show() |
118 |
|
print(b:GetName(), u, x, y) |
|
|
110 |
|
|
|
111 |
|
local x = column * buttonWidth |
|
112 |
|
local y = row * buttonHeight |
|
113 |
|
b:SetPoint('BOTTOMLEFT', petFrame, 'BOTTOMLEFT', x, y) |
119 |
114 |
column = column + 1 |
column = column + 1 |
120 |
115 |
if column >= 5 then |
if column >= 5 then |
121 |
116 |
column = 0 |
column = 0 |
|
... |
... |
function Chorus.petFrameMain(petFrame) |
127 |
122 |
end |
end |
128 |
123 |
]] |
]] |
129 |
124 |
|
|
130 |
|
secureHandler:WrapScript(secureHandler, 'OnAttributeChanged', secureScriptBody) |
|
|
125 |
|
petButtonFactory(petFrame, 'ChorusPetButtonTemplate', secureHandler, secureScriptBody) |
131 |
126 |
|
|
132 |
|
--[[ Initialize frames at login. ]]-- |
|
|
127 |
|
--[[ Initialize frames at login. Only works out of combat. ]]-- |
133 |
128 |
secureHandler:Execute(secureScriptBody) |
secureHandler:Execute(secureScriptBody) |
134 |
|
|
|
135 |
|
print('pipirwa2') |
|
136 |
129 |
end |
end |