vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 BPetButton
3 A Pet Action Button
4 Should work exactly like the normal pet action buttons, but with a modified appearance
5 --]]
6  
7 local function ReuseAndRename(oldName, newName, newParent)
8 local button = getglobal(oldName);
9 setglobal(newName, button);
10  
11 button:SetParent(newParent);
12 button:SetAlpha(newParent:GetAlpha());
13 button:SetFrameLevel(0);
14 getglobal(button:GetName() .. "Icon"):SetTexCoord(0.06, 0.94, 0.06, 0.94);
15  
16 return button;
17 end
18  
19 BPetButton = {
20 --[[ Constructor ]]--
21  
22 Create = function(id, parent)
23 local name = "BPetActionButton" .. id;
24  
25 local button;
26 if BongosSets.dontReuse then
27 button = BBasicActionButton.Create(id, name, parent, 30);
28 button:SetID(id)
29  
30 local autoCastable = button:CreateTexture(name .. "AutoCastable", "OVERLAY");
31 autoCastable:SetTexture("Interface\\Buttons\\UI-AutoCastableOverlay");
32 autoCastable:SetWidth(58);
33 autoCastable:SetHeight(58);
34 autoCastable:SetPoint("CENTER", button);
35 autoCastable:Hide();
36  
37 local autoCast = CreateFrame("Model", name .. "AutoCast", button)
38 autoCast:SetModel("Interface\\Buttons\\UI-AutoCastButton.mdx");
39 autoCast:SetScale(1.2)
40 autoCast:SetSequence(0);
41 autoCast:SetSequenceTime(0, 0);
42 autoCast:Hide();
43  
44 local normalTexture = button:CreateTexture(name .. "NormalTexture2");
45 normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot2");
46 normalTexture:SetWidth(54);
47 normalTexture:SetHeight(54);
48 normalTexture:SetPoint("CENTER", button, "CENTER", 0, -1);
49 button:SetNormalTexture(normalTexture);
50 else
51 button = ReuseAndRename("PetActionButton" .. id, name, parent)
52 end
53  
54 getglobal(button:GetName() .. "AutoCastable"):SetPoint("CENTER", button, "CENTER", 0, -1);
55  
56 local autoCast = getglobal(button:GetName() .. "AutoCast");
57 autoCast:SetPoint("TOPLEFT", button, "TOPLEFT", -0.5, -1);
58 autoCast:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", 0.5, -1.5);
59  
60 if not BActionSets_HotkeysShown() then
61 getglobal(button:GetName() .. "HotKey"):Hide();
62 end
63  
64 BPetButton.UpdateHotkey(button);
65 BPetButton.SetScripts(button);
66  
67 return button;
68 end,
69  
70 SetScripts = function(button)
71 button:RegisterForDrag("LeftButton", "RightButton");
72 button:RegisterForClicks("LeftButtonUp", "RightButtonUp");
73  
74 button:SetScript("OnLoad", nil);
75 button:SetScript("OnEvent", nil);
76 button:SetScript("OnDragStart", BPetButton.OnDragStart);
77 button:SetScript("OnClick", BPetButton.OnClick);
78 button:SetScript("OnDragStart", BPetButton.OnDragStart);
79 button:SetScript("OnReceiveDrag", BPetButton.OnReceiveDrag);
80 button:SetScript("OnEnter", BPetButton.OnEnter);
81 end,
82  
83 --[[ OnX Functions ]]--
84  
85 OnClick = function()
86 this:SetChecked(0);
87 if BActionSets_IsQuickMoveKeyDown() or bg_showGridPet then
88 PickupPetAction(this:GetID());
89 else
90 if arg1 == "LeftButton" then
91 CastPetAction(this:GetID());
92 else
93 TogglePetAutocast(this:GetID());
94 end
95 end
96 end,
97  
98 OnDragStart = function()
99 if not BActionSets_ButtonsLocked() or BActionSets_IsQuickMoveKeyDown() or bg_showGridPet then
100 this:SetChecked(0);
101 PickupPetAction(this:GetID());
102 end
103 end,
104  
105 OnReceiveDrag = function()
106 if BActionSets_IsQuickMoveKeyDown() or bg_showGridPet then
107 this:SetChecked(0);
108 PickupPetAction(this:GetID());
109 end
110 end,
111  
112 OnEnter = function()
113 if BActionSets_TooltipsShown() then
114 PetActionButton_OnEnter();
115 end
116 end,
117  
118 OnLeave = PetActionButton_OnLeave,
119  
120 --[[ Update Functions ]]--
121  
122 Update = function(button)
123 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(button:GetID());
124  
125 button.isToken = isToken;
126 button.tooltipSubtext = subtext;
127 button:SetChecked(isActive);
128  
129 if name then
130 button:Show();
131 elseif not(bg_showGridPet or BActionSets_ShowGrid()) then
132 button:Hide();
133 end
134  
135 local icon = getglobal(button:GetName() .. "Icon");
136  
137 if texture then
138 if GetPetActionsUsable() then
139 SetDesaturation(icon, false);
140 else
141 SetDesaturation(icon, true);
142 end
143 icon:Show();
144 button:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
145 getglobal(button:GetName().."NormalTexture2"):SetVertexColor(1, 1, 1, 1);
146 else
147 icon:Hide();
148 button:SetNormalTexture("Interface\\Buttons\\UI-Quickslot");
149 getglobal(button:GetName().."NormalTexture2"):SetVertexColor(1, 1, 1, 0.5);
150 end
151  
152 if not isToken then
153 icon:SetTexture(texture);
154 button.tooltipName = name;
155 else
156 icon:SetTexture(getglobal(texture));
157 button.tooltipName = getglobal(name);
158 end
159  
160 local autoCastTexture = getglobal(button:GetName() .. "AutoCastable");
161 if autoCastAllowed then
162 autoCastTexture:Show();
163 else
164 autoCastTexture:Hide();
165 end
166  
167 local autoCastModel = getglobal(button:GetName() .. "AutoCast");
168 if autoCastEnabled then
169 autoCastModel:Show();
170 else
171 autoCastModel:Hide();
172 end
173 end,
174  
175 UpdateCooldown = function(button)
176 local start, duration, enable = GetPetActionCooldown(button:GetID());
177 CooldownFrame_SetTimer(getglobal(button:GetName() .. "Cooldown"), start, duration, enable);
178 end,
179  
180 UpdateHotkey = function(button)
181 BBasicActionButton.UpdateHotkey(button, "BONUSACTIONBUTTON");
182 end,
183  
184 ShowGrid = function(button)
185 button:Show();
186 end,
187  
188 HideGrid = function(button)
189 if not GetPetActionInfo(button:GetID()) then
190 button:Hide();
191 end
192 end,
193  
194 Hide = function(button)
195 button:Hide();
196 end,
197 }