+ button.cd:Hide();
+ button.count:Hide();
+ button.hotkey:Hide();
+ button.text:Hide();
+ button.glow:Hide();
+ button:SetChecked(false);
+ end
+end
+
+local function updateHotkeys(button)
+ local key = GetBindingKey(format("CLICK %s:LeftButton", button:GetName()));
+ if key and key ~= "" then
+ -- from LibKeyBound-1.0
+ key = key:upper();
+ key = key:gsub(" ", "");
+ key = key:gsub("ALT%-", "a");
+ key = key:gsub("CTRL%-", "c");
+ key = key:gsub("SHIFT%-", "s");
+ key = key:gsub("NUMPAD", "n");
+ button.hotkey:SetText(key);
+ button.hotkey.shown = true;
+ button.hotkey:Show();
+ else
+ button.hotkey.shown = nil;
+ button.hotkey:Hide();
+ end
+end
+
+local mainbartoggle = "[overridebar][possessbar][shapeshift]possess;";
+mainbartoggle = mainbartoggle.."[bonusbar:1,stealth:1]bonusbar2;"; -- prowl
+mainbartoggle = mainbartoggle.."[bonusbar:1]bonusbar1;[bonusbar:2]bonusbar2;"; -- cat form, unused
+mainbartoggle = mainbartoggle.."[bonusbar:3]bonusbar3;[bonusbar:4]bonusbar4;"; -- bear form, moonkin form
+mainbartoggle = mainbartoggle.."normal";
+local function setupSnippets(secure, slot)
+ -- FrameXML/SecureHandlers.lua has arguments and return value
+ -- args: self, button, kind, value, ... (kind, value, ... from GetCursorInfo())
+ -- returns: kind, target, detail
+ -- or: "clear", kind, target, detail
+ -- used for Pickup* functions
+ -- some of these snippets based on LibActionButton-1.0
+ secure:SetAttribute("_ondragstart", [=[
+ return "action", self:GetAttribute("action");
+ ]=]);
+ secure:SetAttribute("_onreceivedrag", [=[
+ if not kind or not value then return nil end
+ return "action", self:GetAttribute("action");
+ ]=]);
+ -- pre-wrapper can pass a message to post-wrapper
+ secure:WrapScript(secure, "OnDragStart", [=[
+ local kind, value = GetActionInfo(self:GetAttribute("action"));
+ return "message", format("%s|%s", tostring(kind), tostring(value));
+ ]=], [=[
+ local kind, value = GetActionInfo(self:GetAttribute("action"));
+ if message ~= format("%s|%s", tostring(kind), tostring(value)) then
+ self:CallMethod("ActionChanged");
+ end
+ ]=]);
+ secure:WrapScript(secure, "OnReceiveDrag", [=[
+ local kind, value = GetActionInfo(self:GetAttribute("action"));
+ return "message", format("%s|%s", tostring(kind), tostring(value));
+ ]=], [=[
+ local kind, value = GetActionInfo(self:GetAttribute("action"));
+ if message ~= format("%s|%s", tostring(kind), tostring(value)) then
+ self:CallMethod("ActionChanged");
+ end
+ ]=]);
+ function secure:UpdateState()
+ return updateState(self, self.slot);
+ end
+ secure:WrapScript(secure, "OnClick", [=[
+ local kind, value = GetActionInfo(self:GetAttribute("action"));
+ return nil, format("%s|%s", tostring(kind), tostring(value));
+ ]=], [=[
+ local kind, value = GetActionInfo(self:GetAttribute("action"));
+ if message ~= format("%s|%s", tostring(kind), tostring(value)) then
+ self:CallMethod("ActionChanged");
+ else
+ self:CallMethod("UpdateState");
+ end
+ ]=]);
+ if slot < 13 then
+ -- first action bar has possible states based on vehicle/possess etc.
+ secure:SetAttribute("origaction", slot);
+ secure:SetAttribute("_onstate-possess", [=[
+ local oldslot = self:GetAttribute("action");
+ if newstate == "possess" then
+ local slot;
+ if HasVehicleActionBar() then
+ slot = (GetVehicleBarIndex()-1)*12+self:GetAttribute("origaction");
+ elseif HasOverrideActionBar() then
+ slot = (GetOverrideBarIndex()-1)*12+self:GetAttribute("origaction");
+ elseif HasTempShapeshiftActionBar() then
+ slot = (GetTempShapeshiftBarIndex()-1)*12+self:GetAttribute("origaction");
+ else
+ -- something wrong, just revert to normal
+ print("Possess bar index not found");
+ slot = self:GetAttribute("origaction");
+ end
+ self:SetAttribute("action", slot);
+ elseif newstate == "bonusbar1" then
+ self:SetAttribute("action", 72+self:GetAttribute("origaction"));
+ elseif newstate == "bonusbar2" then
+ self:SetAttribute("action", 84+self:GetAttribute("origaction"));
+ elseif newstate == "bonusbar3" then
+ self:SetAttribute("action", 96+self:GetAttribute("origaction"));
+ elseif newstate == "bonusbar4" then
+ --self:SetAttribute("action", 108+self:GetAttribute("origaction"));
+ -- moonkin form, don't change actionbar
+ self:SetAttribute("action", self:GetAttribute("origaction"));
+ else
+ self:SetAttribute("action", self:GetAttribute("origaction"));
+ end
+ self:CallMethod("ActionChanged", oldslot);
+ ]=]);
+ RegisterStateDriver(secure, "possess", mainbartoggle);
+ else
+ function secure:ShowButton() if HasAction(slot) then activeButtons[slot] = self end end
+ function secure:HideButton() activeButtons[slot] = nil end
+ -- all other action bar are hidden if with overridebar or vehicleui (not shapeshift, possessbar)
+ -- default Bartender4 options
+ secure:SetAttribute("_onstate-possess", [=[
+ if newstate == "possess" then
+ self:Hide();
+ self:CallMethod("HideButton");
+ else
+ self:Show();
+ self:CallMethod("ShowButton");
+ end
+ ]=]);
+ RegisterStateDriver(secure, "possess", "[overridebar][vehicleui] possess; normal");