load BarPet module

This commit is contained in:
Crum
2018-05-10 23:08:55 -05:00
parent c3e499ac87
commit 9df8d2d79d
3 changed files with 409 additions and 22 deletions
+4 -5
View File
@@ -263,7 +263,7 @@ function AB:UpdateButtonSettings()
self:PositionAndSizeBar("bar"..i) self:PositionAndSizeBar("bar"..i)
end end
--self:PositionAndSizeBarPet() self:PositionAndSizeBarPet()
self:PositionAndSizeBarShapeShift() self:PositionAndSizeBarShapeShift()
end end
@@ -275,14 +275,12 @@ function AB:StyleButton(button, noBackdrop)
local hotkey = _G[name.."HotKey"] local hotkey = _G[name.."HotKey"]
local border = _G[name.."Border"] local border = _G[name.."Border"]
local macroName = _G[name.."Name"] local macroName = _G[name.."Name"]
local normal = _G[name.."NormalTexture"] local normal = button:GetNormalTexture()
local normal2 = button:GetNormalTexture()
local buttonCooldown = _G[name.."Cooldown"] local buttonCooldown = _G[name.."Cooldown"]
local color = self.db.fontColor local color = self.db.fontColor
if flash then flash:SetTexture(nil) end if flash then flash:SetTexture(nil) end
if normal then normal:SetTexture(nil) normal:Hide() normal:SetAlpha(0) end if normal then normal:SetTexture(nil) normal:Hide() normal:SetAlpha(0) end
if normal2 then normal2:SetTexture(nil) normal2:Hide() normal2:SetAlpha(0) end
if border then E:Kill(border) end if border then E:Kill(border) end
if not button.noBackdrop then if not button.noBackdrop then
@@ -485,6 +483,7 @@ function AB:Initialize()
self:CreateBar(i) self:CreateBar(i)
end end
self:CreateBarPet()
self:CreateBarShapeShift() self:CreateBarShapeShift()
self:UpdateButtonSettings() self:UpdateButtonSettings()
@@ -492,7 +491,7 @@ function AB:Initialize()
self:SecureHook("ActionButton_Update") self:SecureHook("ActionButton_Update")
self:RawHook("ActionButton_GetPagedID") self:RawHook("ActionButton_GetPagedID")
-- self:SecureHook("PetActionBar_Update", "UpdatePet") self:SecureHook("PetActionBar_Update", "UpdatePet")
if E.myclass == "WARRIOR" then if E.myclass == "WARRIOR" then
BonusActionBarFrame:Show() BonusActionBarFrame:Show()
+276
View File
@@ -0,0 +1,276 @@
local E, L, V, P, G = unpack(ElvUI); -- Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local AB = E:GetModule("ActionBars");
--Cache global variables
--Lua functions
local _G = _G
local ceil, mod = math.ceil, math.mod
--WoW API / Variables
local CreateFrame = CreateFrame
local GetBindingKey = GetBindingKey
local PetHasActionBar = PetHasActionBar
local GetPetActionInfo = GetPetActionInfo
local GetPetActionsUsable = GetPetActionsUsable
local SetDesaturation = SetDesaturation
local PetActionBar_ShowGrid = PetActionBar_ShowGrid
local PetActionBar_UpdateCooldowns = PetActionBar_UpdateCooldowns
local NUM_PET_ACTION_SLOTS = NUM_PET_ACTION_SLOTS
local bar = CreateFrame("Frame", "ElvUI_BarPet", E.UIParent)
bar:SetFrameStrata("LOW")
function AB:UpdatePet(event, unit)
if ((event == "UNIT_FLAGS" or event == "UNIT_AURA") and unit ~= "pet") then return end
if (event == "UNIT_PET" and unit ~= "player") then return end
local petActionButton, petActionIcon, petAutoCastableTexture, petAutoCastShine
local petActionsUsable = GetPetActionsUsable()
for i = 1, NUM_PET_ACTION_SLOTS do
local buttonName = "PetActionButton" .. i
petActionButton = _G[buttonName]
petActionIcon = _G[buttonName .. "Icon"]
petAutoCastableTexture = _G[buttonName .. "AutoCastable"]
petAutoCastShine = _G[buttonName .. "AutoCast"]
local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(i)
if not isToken then
petActionIcon:SetTexture(texture)
petActionButton.tooltipName = name
else
petActionIcon:SetTexture(_G[texture])
petActionButton.tooltipName = _G[name]
end
petActionButton.isToken = isToken
petActionButton.tooltipSubtext = subtext
if isActive and name ~= "PET_ACTION_FOLLOW" then
petActionButton:SetChecked(1)
else
petActionButton:SetChecked(0)
end
if autoCastAllowed then
petAutoCastableTexture:Show()
else
petAutoCastableTexture:Hide()
end
if autoCastEnabled then
petAutoCastShine:Show()
else
petAutoCastShine:Hide()
end
petActionButton:SetAlpha(1)
if texture then
if petActionsUsable then
SetDesaturation(petActionIcon, nil)
else
SetDesaturation(petActionIcon, 1)
end
petActionIcon:Show()
else
petActionIcon:Hide()
end
if not PetHasActionBar() and texture and name ~= "PET_ACTION_FOLLOW" then
SetDesaturation(petActionIcon, 1)
petActionButton:SetChecked(0)
end
end
if not PetHasActionBar() then
bar:Hide()
else
bar:Show()
end
end
function AB:PositionAndSizeBarPet()
local buttonSpacing = E:Scale(self.db["barPet"].buttonspacing)
local backdropSpacing = E:Scale((self.db["barPet"].backdropSpacing or self.db["barPet"].buttonspacing))
local buttonsPerRow = self.db["barPet"].buttonsPerRow
local numButtons = self.db["barPet"].buttons
local size = E:Scale(self.db["barPet"].buttonsize)
local point = self.db["barPet"].point
local numColumns = ceil(numButtons / buttonsPerRow)
local widthMult = self.db["barPet"].widthMult
local heightMult = self.db["barPet"].heightMult
bar.db = self.db["barPet"]
if numButtons < buttonsPerRow then
buttonsPerRow = numButtons
end
if numColumns < 1 then
numColumns = 1
end
if self.db["barPet"].backdrop then
bar.backdrop:Show()
else
bar.backdrop:Hide()
widthMult = 1
heightMult = 1
end
local barWidth = (size * (buttonsPerRow * widthMult)) + ((buttonSpacing * (buttonsPerRow - 1)) * widthMult) + (buttonSpacing * (widthMult-1)) + (backdropSpacing*2) + ((self.db["barPet"].backdrop and E.Border or E.Spacing)*2)
local barHeight = (size * (numColumns * heightMult)) + ((buttonSpacing * (numColumns - 1)) * heightMult) + (buttonSpacing * (heightMult-1)) + (backdropSpacing*2) + ((self.db["barPet"].backdrop and E.Border or E.Spacing)*2)
bar:SetWidth(barWidth)
bar:SetHeight(barHeight)
bar.mover:SetWidth(bar:GetWidth())
bar.mover:SetHeight(bar:GetHeight())
if self.db["barPet"].enabled then
bar:SetScale(1)
bar:SetAlpha(self.db["barPet"].alpha)
E:EnableMover(bar.mover:GetName())
else
bar:SetScale(0.0001)
bar:SetAlpha(0)
E:DisableMover(bar.mover:GetName())
end
local horizontalGrowth, verticalGrowth
if point == "TOPLEFT" or point == "TOPRIGHT" then
verticalGrowth = "DOWN"
else
verticalGrowth = "UP"
end
if point == "BOTTOMLEFT" or point == "TOPLEFT" then
horizontalGrowth = "RIGHT"
else
horizontalGrowth = "LEFT"
end
bar.mouseover = self.db["barPet"].mouseover
if bar.mouseover then
bar:SetAlpha(0)
else
bar:SetAlpha(self.db["barPet"].alpha)
end
if self.db["barPet"].inheritGlobalFade then
bar:SetParent(self.fadeParent)
else
bar:SetParent(E.UIParent)
end
local button, lastButton, lastColumnButton
local firstButtonSpacing = (self.db["barPet"].backdrop and (E.Border + backdropSpacing) or E.Spacing)
for i = 1, NUM_PET_ACTION_SLOTS do
button = _G["PetActionButton"..i]
lastButton = _G["PetActionButton"..i - 1]
lastColumnButton = _G["PetActionButton"..i - buttonsPerRow]
button:SetParent(bar)
button:ClearAllPoints()
button:SetWidth(size)
button:SetHeight(size)
button:Show()
if i == 1 then
local x, y
if point == "BOTTOMLEFT" then
x, y = firstButtonSpacing, firstButtonSpacing
elseif point == "TOPRIGHT" then
x, y = -firstButtonSpacing, -firstButtonSpacing
elseif point == "TOPLEFT" then
x, y = firstButtonSpacing, -firstButtonSpacing
else
x, y = -firstButtonSpacing, firstButtonSpacing
end
button:SetPoint(point, bar, point, x, y)
elseif mod((i - 1), buttonsPerRow) == 0 then
local x = 0
local y = -buttonSpacing
local buttonPoint, anchorPoint = "TOP", "BOTTOM"
if verticalGrowth == "UP" then
y = buttonSpacing
buttonPoint = "BOTTOM"
anchorPoint = "TOP"
end
button:SetPoint(buttonPoint, lastColumnButton, anchorPoint, x, y)
else
local x = buttonSpacing
local y = 0
local buttonPoint, anchorPoint = "LEFT", "RIGHT"
if horizontalGrowth == "LEFT" then
x = -buttonSpacing
buttonPoint = "RIGHT"
anchorPoint = "LEFT"
end
button:SetPoint(buttonPoint, lastButton, anchorPoint, x, y)
end
if i > numButtons then
button:SetScale(0.0001)
button:SetAlpha(0)
else
button:SetScale(1)
button:SetAlpha(1)
end
self:StyleButton(button)
end
bar:GetScript("OnSizeChanged")(bar)
end
function AB:UpdatePetBindings()
for i = 1, NUM_PET_ACTION_SLOTS do
if self.db.hotkeytext then
local key = GetBindingKey("BONUSACTIONBUTTON"..i)
_G["PetActionButton"..i.."HotKey"]:Show()
_G["PetActionButton"..i.."HotKey"]:SetText(key)
self:FixKeybindText(_G["PetActionButton"..i])
else
_G["PetActionButton"..i.."HotKey"]:Hide()
end
end
end
function AB:CreateBarPet()
E:CreateBackdrop(bar, "Default")
bar.backdrop:SetAllPoints()
if self.db["bar4"].enabled then
bar:SetPoint("RIGHT", ElvUI_Bar4, "LEFT", -4, 0)
else
bar:SetPoint("RIGHT", E.UIParent, "RIGHT", -4, 0)
end
PetActionBarFrame.showgrid = 1
PetActionBar_ShowGrid()
self:HookScript(bar, "OnEnter", "Bar_OnEnter")
self:HookScript(bar, "OnLeave", "Bar_OnLeave")
for i = 1, NUM_PET_ACTION_SLOTS do
self:HookScript(_G["PetActionButton" .. i], "OnEnter", "Button_OnEnter")
self:HookScript(_G["PetActionButton" .. i], "OnLeave", "Button_OnLeave")
end
self:RegisterEvent("SPELLS_CHANGED", "UpdatePet")
self:RegisterEvent("PLAYER_CONTROL_GAINED", "UpdatePet")
self:RegisterEvent("PLAYER_ENTERING_WORLD", "UpdatePet")
self:RegisterEvent("PLAYER_CONTROL_LOST", "UpdatePet")
self:RegisterEvent("PET_BAR_UPDATE", "UpdatePet")
self:RegisterEvent("UNIT_PET", "UpdatePet")
self:RegisterEvent("UNIT_FLAGS", "UpdatePet")
self:RegisterEvent("UNIT_AURA", "UpdatePet")
self:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED", "UpdatePet")
self:RegisterEvent("PET_BAR_UPDATE_COOLDOWN", PetActionBar_UpdateCooldowns)
E:CreateMover(bar, "ElvBar_Pet", L["Pet Bar"], nil, nil, nil,"ALL,ACTIONBARS")
self:PositionAndSizeBarPet()
self:UpdatePetBindings()
end
+129 -17
View File
@@ -201,8 +201,135 @@ local function BuildABConfig()
} }
} }
} }
group["stanceBar"] = { group["barPet"] = {
order = 6, order = 6,
name = L["Pet Bar"],
type = "group",
guiInline = false,
disabled = function() return not E.private.actionbar.enable end,
get = function(info) return E.db.actionbar["barPet"][ info[getn(info)] ] end,
set = function(info, value) E.db.actionbar["barPet"][ info[getn(info)] ] = value AB:PositionAndSizeBarPet() end,
args = {
info = {
order = 1,
type = "header",
name = L["Pet Bar"]
},
enabled = {
order = 2,
type = "toggle",
name = L["Enable"]
},
restorePosition = {
order = 3,
type = "execute",
name = L["Restore Bar"],
desc = L["Restore the actionbars default settings"],
func = function() E:CopyTable(E.db.actionbar["barPet"], P.actionbar["barPet"]) E:ResetMovers(L["Pet Bar"]) AB:PositionAndSizeBarPet() end,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
spacer = {
order = 4,
type = "description",
name = " "
},
backdrop = {
order = 5,
type = "toggle",
name = L["Backdrop"],
desc = L["Toggles the display of the actionbars backdrop."],
disabled = function() return not E.db.actionbar.barPet.enabled end
},
mouseover = {
order = 6,
type = "toggle",
name = L["Mouse Over"],
desc = L["The frame is not shown unless you mouse over the frame."],
disabled = function() return not E.db.actionbar.barPet.enabled end
},
inheritGlobalFade = {
order = 7,
type = "toggle",
name = L["Inherit Global Fade"],
desc = L["Inherit the global fade, mousing over, targetting, setting focus, losing health, entering combat will set the remove transparency. Otherwise it will use the transparency level in the general actionbar settings for global fade alpha."],
disabled = function() return not E.db.actionbar.barPet.enabled end
},
point = {
order = 8,
type = "select",
name = L["Anchor Point"],
desc = L["The first button anchors itself to this point on the bar."],
values = points,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
buttons = {
order = 8,
type = "range",
name = L["Buttons"],
desc = L["The amount of buttons to display."],
min = 1, max = NUM_PET_ACTION_SLOTS, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
buttonsPerRow = {
order = 10,
type = "range",
name = L["Buttons Per Row"],
desc = L["The amount of buttons to display per row."],
min = 1, max = NUM_PET_ACTION_SLOTS, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
buttonsize = {
order = 11,
type = "range",
name = L["Button Size"],
desc = L["The size of the action buttons."],
min = 15, max = 60, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
buttonspacing = {
order = 12,
type = "range",
name = L["Button Spacing"],
desc = L["The spacing between buttons."],
min = -1, max = 10, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
backdropSpacing = {
order = 13,
type = "range",
name = L["Backdrop Spacing"],
desc = L["The spacing between the backdrop and the buttons."],
min = 0, max = 10, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
heightMult = {
order = 14,
type = "range",
name = L["Height Multiplier"],
desc = L["Multiply the backdrops height or width by this value. This is usefull if you wish to have more than one bar behind a backdrop."],
min = 1, max = 5, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
widthMult = {
order = 15,
type = "range",
name = L["Width Multiplier"],
desc = L["Multiply the backdrops height or width by this value. This is usefull if you wish to have more than one bar behind a backdrop."],
min = 1, max = 5, step = 1,
disabled = function() return not E.db.actionbar.barPet.enabled end
},
alpha = {
order = 16,
type = "range",
isPercent = true,
name = L["Alpha"],
min = 0, max = 1, step = 0.01,
disabled = function() return not E.db.actionbar.barPet.enabled end
}
}
}
group["stanceBar"] = {
order = 7,
name = L["Stance Bar"], name = L["Stance Bar"],
type = "group", type = "group",
guiInline = false, guiInline = false,
@@ -336,26 +463,11 @@ local function BuildABConfig()
["classic"] = L["Classic"] ["classic"] = L["Classic"]
}, },
disabled = function() return not E.db.actionbar.barShapeShift.enabled end disabled = function() return not E.db.actionbar.barShapeShift.enabled end
},
visibility = {
order = 18,
type = "input",
name = L["Visibility State"],
desc = L["This works like a macro, you can run different situations to get the actionbar to show/hide differently.\n Example: '[combat] show;hide'"],
width = "full",
multiline = true,
set = function(info, value)
if value and value:match("[\n\r]") then
value = value:gsub("[\n\r]","")
end
E.db.actionbar["barShapeShift"]["visibility"] = value;
AB:UpdateButtonSettings()
end
} }
} }
} }
group["microbar"] = { group["microbar"] = {
order = 7, order = 8,
type = "group", type = "group",
name = L["Micro Bar"], name = L["Micro Bar"],
get = function(info) return E.db.actionbar.microbar[ info[getn(info)] ] end, get = function(info) return E.db.actionbar.microbar[ info[getn(info)] ] end,