2021-05-17 16:49:54 +02:00
|
|
|
local string_gsub, floor, pairs = string.gsub, math.floor, pairs
|
2021-05-22 13:42:47 +02:00
|
|
|
local CreateFrame, SetPortraitTexture = CreateFrame, SetPortraitTexture
|
2021-05-17 16:49:54 +02:00
|
|
|
local UnitHealthMax, UnitHealth, UnitGUID = UnitHealthMax, UnitHealth, UnitGUID
|
|
|
|
|
|
|
|
local Gladdy = LibStub("Gladdy")
|
|
|
|
local L = Gladdy.L
|
|
|
|
local Pets = Gladdy:NewModule("Pets", nil, {
|
|
|
|
petEnabled = true,
|
2021-05-22 13:42:47 +02:00
|
|
|
petWidth = 128,
|
2021-05-17 16:49:54 +02:00
|
|
|
petHeight = 20,
|
|
|
|
petPortraitEnabled = true,
|
|
|
|
petPortraitBorderStyle = "Interface\\AddOns\\Gladdy\\Images\\Border_rounded_blp",
|
|
|
|
petHealthBarFont = "DorisPP",
|
|
|
|
petHealthBarHeight = 60,
|
|
|
|
petHealthBarTexture = "Smooth",
|
|
|
|
petHealthBarBorderStyle = "Gladdy Tooltip round",
|
|
|
|
petHealthBarBorderSize = 9,
|
|
|
|
petHealthBarBorderColor = { r = 0, g = 0, b = 0, a = 1 },
|
|
|
|
petHealthBarColor = { r = 0, g = 1, b = 0, a = 1 },
|
|
|
|
petHealthBarBgColor = { r = 0, g = 0, b = 0, a = 0.4 },
|
|
|
|
petHealthBarFontColor = { r = 1, g = 1, b = 1, a = 1 },
|
|
|
|
petHealthBarFontSize = 12,
|
|
|
|
petHealthPercentage = true,
|
2021-05-22 13:42:47 +02:00
|
|
|
petXOffset = 1,
|
|
|
|
petYOffset = -62,
|
2021-09-24 16:40:36 +02:00
|
|
|
petGroup = false,
|
|
|
|
petMargin = 1,
|
2022-01-12 20:21:53 +01:00
|
|
|
petFrameStrata = "MEDIUM",
|
|
|
|
petFrameLevel = 5,
|
2021-05-17 16:49:54 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
function Pets:Initialize()
|
|
|
|
self.frames = {}
|
2022-02-15 22:59:21 +01:00
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self:RegisterMessage("JOINED_ARENA")
|
|
|
|
self:RegisterMessage("PET_SPOTTED")
|
|
|
|
self:RegisterMessage("PET_DESTROYED")
|
|
|
|
self:RegisterMessage("PET_STEALTH")
|
|
|
|
self:RegisterMessage("ENEMY_SPOTTED")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:UpdateFrameOnce()
|
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self:RegisterMessage("JOINED_ARENA")
|
|
|
|
self:RegisterMessage("PET_SPOTTED")
|
|
|
|
self:RegisterMessage("PET_DESTROYED")
|
|
|
|
self:RegisterMessage("PET_STEALTH")
|
|
|
|
self:RegisterMessage("ENEMY_SPOTTED")
|
|
|
|
else
|
|
|
|
self:UnregisterAllMessages()
|
|
|
|
end
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:JOINED_ARENA()
|
2021-07-29 15:53:34 +02:00
|
|
|
for _,v in pairs(self.frames) do
|
2021-05-17 16:49:54 +02:00
|
|
|
v.healthBar:SetAlpha(0)
|
|
|
|
end
|
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self:RegisterEvent("UNIT_PET")
|
2021-07-29 15:53:34 +02:00
|
|
|
self:SetScript("OnEvent", function(_, event, unitId)
|
2021-05-17 16:49:54 +02:00
|
|
|
if event == "UNIT_PET" then
|
|
|
|
local unit = Gladdy.guids[UnitGUID(unitId)]
|
|
|
|
if unit then
|
|
|
|
Pets:CheckUnitPet(unit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:ResetUnit(unitId)
|
|
|
|
local unit = string_gsub(unitId, "%d$", "pet%1")
|
|
|
|
local petFrame = self.frames[unit]
|
|
|
|
if (not petFrame) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
petFrame.healthBar:SetAlpha(0)
|
|
|
|
petFrame.healthBar:SetScript("OnUpdate", nil)
|
|
|
|
self:UnregisterEvent("UNIT_PET")
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:PET_SPOTTED(unit)
|
2022-01-11 00:03:36 +01:00
|
|
|
Gladdy.guids[UnitGUID(unit)] = unit
|
2021-05-17 16:49:54 +02:00
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self.frames[unit].healthBar:SetAlpha(1)
|
2022-01-12 23:07:23 +01:00
|
|
|
self.frames[unit].healthBar.hp:SetStatusBarColor(Gladdy:SetColor(Gladdy.db.petHealthBarColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
self.frames[unit].healthBar:SetScript("OnUpdate", function(self)
|
|
|
|
self.hp:SetValue(UnitHealth(self.unit))
|
|
|
|
Pets:SetHealthText(self, UnitHealth(unit), UnitHealthMax(unit))
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:PET_DESTROYED(unit)
|
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self.frames[unit].healthBar:SetAlpha(0)
|
|
|
|
self.frames[unit].healthBar:SetScript("OnUpdate", nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:PET_STEALTH(unit)
|
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self.frames[unit].healthBar.hp:SetStatusBarColor(0.66, 0.66, 0.66, 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:ENEMY_SPOTTED(unit)
|
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
self:CheckUnitPet(unit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:CheckUnitPet(unitId)
|
|
|
|
local unit = string_gsub(unitId, "%d$", "pet%1")
|
|
|
|
local petFrame = self.frames[unit]
|
|
|
|
if (not petFrame) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if ( UnitGUID(unit)) then
|
|
|
|
petFrame.healthBar:SetAlpha(1)
|
|
|
|
petFrame.healthBar.hp:SetMinMaxValues(0, UnitHealthMax(unit))
|
|
|
|
petFrame.healthBar.hp:SetValue(UnitHealth(unit))
|
|
|
|
Pets:SetHealthText(petFrame.healthBar, UnitHealth(unit), UnitHealthMax(unit))
|
|
|
|
petFrame.healthBar:SetScript("OnUpdate", function(self)
|
|
|
|
self.hp:SetValue(UnitHealth(self.unit))
|
|
|
|
Pets:SetHealthText(self, UnitHealth(unit), UnitHealthMax(unit))
|
|
|
|
end)
|
|
|
|
else
|
|
|
|
petFrame.healthBar:SetAlpha(0)
|
|
|
|
petFrame.healthBar:SetScript("OnUpdate", nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:Test(unitId)
|
|
|
|
if Gladdy.db.petEnabled then
|
|
|
|
local unit = string_gsub(unitId, "%d$", "pet%1")
|
|
|
|
local petFrame = self.frames[unit]
|
|
|
|
if (not petFrame) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
petFrame.healthBar:SetAlpha(1)
|
|
|
|
petFrame.healthBar.hp:SetMinMaxValues(0, 6200)
|
|
|
|
petFrame.healthBar.hp:SetValue(2000)
|
|
|
|
Pets:SetHealthText(petFrame.healthBar, 2000, 6200)
|
2021-05-22 13:42:47 +02:00
|
|
|
SetPortraitTexture(petFrame.healthBar.portrait, "player")
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:CreateFrame(unitId)
|
|
|
|
local unit = string_gsub(unitId, "%d$", "pet%1")
|
|
|
|
if self.frames[unit] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local button = CreateFrame("Frame", "GladdyButtonFramePet" .. unit, Gladdy.frame)
|
2021-09-24 15:51:24 +02:00
|
|
|
button:SetMovable(true)
|
2021-05-17 16:49:54 +02:00
|
|
|
--button:SetAlpha(0)
|
|
|
|
button:SetPoint("LEFT", Gladdy.buttons[unitId].healthBar, "RIGHT", Gladdy.db.petXOffset, Gladdy.db.petYOffset)
|
|
|
|
|
2021-06-20 00:50:06 +02:00
|
|
|
local secure = CreateFrame("Button", "GladdyButton" .. unit, button, "SecureActionButtonTemplate, SecureHandlerEnterLeaveTemplate")
|
2021-05-17 16:49:54 +02:00
|
|
|
secure:RegisterForClicks("AnyUp")
|
2021-06-20 00:50:06 +02:00
|
|
|
secure:RegisterForClicks("AnyDown")
|
2021-05-17 16:49:54 +02:00
|
|
|
secure:SetAttribute("*type1", "target")
|
|
|
|
secure:SetAttribute("*type2", "focus")
|
|
|
|
secure:SetAttribute("unit", unit)
|
|
|
|
secure:SetAllPoints(button)
|
|
|
|
|
|
|
|
button.unit = unit
|
|
|
|
button.secure = secure
|
|
|
|
|
|
|
|
local healthBar = CreateFrame("Frame", nil, button, BackdropTemplateMixin and "BackdropTemplate")
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar:SetBackdrop({ edgeFile = Gladdy:SMFetch("border", "petHealthBarBorderStyle"),
|
2021-05-17 16:49:54 +02:00
|
|
|
edgeSize = Gladdy.db.petHealthBarBorderSize })
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar:SetBackdropBorderColor(Gladdy:SetColor(Gladdy.db.petHealthBarBorderColor))
|
2022-01-12 20:21:53 +01:00
|
|
|
healthBar:SetFrameStrata(Gladdy.db.petFrameStrata)
|
|
|
|
healthBar:SetFrameLevel(Gladdy.db.petFrameLevel)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar:SetAllPoints(button)
|
|
|
|
healthBar:SetAlpha(0)
|
|
|
|
|
2021-06-15 09:06:50 +02:00
|
|
|
healthBar.portrait = healthBar:CreateTexture(nil, "BACKGROUND")
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.portrait:SetPoint("LEFT", healthBar, "RIGHT")
|
|
|
|
healthBar.portrait:SetTexCoord(0.1, 0.9, 0.1, 0.9)
|
|
|
|
SetPortraitTexture(healthBar.portrait, "player")
|
|
|
|
healthBar.portrait.border = healthBar:CreateTexture(nil, "OVERLAY")
|
|
|
|
healthBar.portrait.border:SetAllPoints(healthBar.portrait)
|
|
|
|
healthBar.portrait.border:SetTexture(Gladdy.db.classIconBorderStyle)
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.portrait.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.petHealthBarBorderColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
healthBar.hp = CreateFrame("StatusBar", nil, healthBar)
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.hp:SetStatusBarTexture(Gladdy:SMFetch("statusbar", "petHealthBarTexture"))
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.hp:SetStatusBarColor(Gladdy:SetColor(Gladdy.db.petHealthBarColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.hp:SetMinMaxValues(0, 100)
|
2022-01-12 20:21:53 +01:00
|
|
|
healthBar.hp:SetFrameStrata(Gladdy.db.petFrameStrata)
|
|
|
|
healthBar.hp:SetFrameLevel(Gladdy.db.petFrameLevel - 1)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.hp:SetAllPoints(healthBar)
|
|
|
|
|
|
|
|
healthBar.bg = healthBar.hp:CreateTexture(nil, "BACKGROUND")
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.bg:SetTexture(Gladdy:SMFetch("statusbar", "petHealthBarTexture"))
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.bg:ClearAllPoints()
|
|
|
|
healthBar.bg:SetAllPoints(healthBar.hp)
|
|
|
|
healthBar.bg:SetAlpha(1)
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.bg:SetVertexColor(Gladdy:SetColor(Gladdy.db.petHealthBarBgColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
|
|
|
|
healthBar.nameText = healthBar:CreateFontString(nil, "LOW", "GameFontNormalSmall")
|
|
|
|
if (Gladdy.db.petHealthBarFontSize < 1) then
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.nameText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), 1)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.nameText:Hide()
|
|
|
|
else
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.nameText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), Gladdy.db.petHealthBarFontSize)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.nameText:Show()
|
|
|
|
end
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.nameText:SetTextColor(Gladdy:SetColor(Gladdy.db.petHealthBarFontColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.nameText:SetShadowOffset(1, -1)
|
|
|
|
healthBar.nameText:SetShadowColor(0, 0, 0, 1)
|
|
|
|
healthBar.nameText:SetJustifyH("CENTER")
|
|
|
|
healthBar.nameText:SetPoint("LEFT", 5, 0)
|
|
|
|
|
|
|
|
healthBar.healthText = healthBar:CreateFontString(nil, "LOW")
|
|
|
|
if (Gladdy.db.petHealthBarFontSize < 1) then
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.healthText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), 1)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.healthText:Hide()
|
|
|
|
else
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.healthText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), Gladdy.db.petHealthBarFontSize)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.healthText:Hide()
|
|
|
|
end
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.healthText:SetTextColor(Gladdy:SetColor(Gladdy.db.petHealthBarFontColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.healthText:SetShadowOffset(1, -1)
|
|
|
|
healthBar.healthText:SetShadowColor(0, 0, 0, 1)
|
|
|
|
healthBar.healthText:SetJustifyH("CENTER")
|
|
|
|
healthBar.healthText:SetPoint("RIGHT", -5, 0)
|
|
|
|
|
|
|
|
healthBar.unit = unit
|
|
|
|
button.healthBar = healthBar
|
|
|
|
|
|
|
|
healthBar:RegisterUnitEvent("UNIT_HEALTH", unit)
|
|
|
|
healthBar:RegisterUnitEvent("UNIT_MAXHEALTH", unit)
|
|
|
|
healthBar:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", unit)
|
|
|
|
healthBar:RegisterUnitEvent("UNIT_NAME_UPDATE", unit)
|
|
|
|
healthBar:SetScript("OnEvent", Pets.OnEvent)
|
|
|
|
|
|
|
|
button:SetWidth(Gladdy.db.petWidth)
|
|
|
|
button:SetHeight(Gladdy.db.petHeight)
|
|
|
|
|
|
|
|
self.frames[unit] = button
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets.OnEvent(self, event, unit)
|
|
|
|
if event == "UNIT_PORTRAIT_UPDATE" then
|
|
|
|
SetPortraitTexture(self.portrait, unit)
|
|
|
|
end
|
|
|
|
local health = UnitHealth(unit)
|
|
|
|
local healthMax = UnitHealthMax(unit)
|
|
|
|
self.hp:SetMinMaxValues(0, healthMax)
|
|
|
|
self.hp:SetValue(health)
|
|
|
|
Pets:SetHealthText(self, health, healthMax)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:UpdateFrame(unitId)
|
|
|
|
local unit = string_gsub(unitId, "%d$", "pet%1")
|
|
|
|
local healthBar = self.frames[unit].healthBar
|
|
|
|
if (not healthBar) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-01-12 20:21:53 +01:00
|
|
|
healthBar:SetFrameStrata(Gladdy.db.petFrameStrata)
|
|
|
|
healthBar:SetFrameLevel(Gladdy.db.petFrameLevel)
|
|
|
|
healthBar.hp:SetFrameStrata(Gladdy.db.petFrameStrata)
|
|
|
|
healthBar.hp:SetFrameLevel(Gladdy.db.petFrameLevel - 1)
|
|
|
|
|
2021-05-17 16:49:54 +02:00
|
|
|
if not Gladdy.db.petEnabled then
|
|
|
|
self.frames[unit]:Hide()
|
|
|
|
else
|
|
|
|
self.frames[unit]:Show()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.frames[unit]:SetWidth(Gladdy.db.petWidth)
|
|
|
|
self.frames[unit]:SetHeight(Gladdy.db.petHeight)
|
2022-01-11 00:29:17 +01:00
|
|
|
|
|
|
|
Gladdy:SetPosition(self.frames[unit], unitId, "petXOffset", "petYOffset", Pets:LegacySetPosition(unit, unitId), Pets)
|
|
|
|
|
2021-09-24 16:40:36 +02:00
|
|
|
if (Gladdy.db.petGroup) then
|
|
|
|
if (unit == "arenapet1") then
|
2022-01-11 00:29:17 +01:00
|
|
|
self.frames[unit]:ClearAllPoints()
|
|
|
|
self.frames[unit]:SetPoint("TOPLEFT", Gladdy.buttons[unitId].healthBar, "TOPLEFT", Gladdy.db.petXOffset, Gladdy.db.petYOffset)
|
2021-09-24 16:40:36 +02:00
|
|
|
else
|
|
|
|
local previousPet = "arenapet" .. string_gsub(unit, "arenapet", "") - 1
|
|
|
|
self.frames[unit]:ClearAllPoints()
|
|
|
|
self.frames[unit]:SetPoint("TOPLEFT", self.frames[previousPet], "BOTTOMLEFT", 0, - Gladdy.db.petMargin)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.frames[unit]:ClearAllPoints()
|
2022-01-11 00:29:17 +01:00
|
|
|
self.frames[unit]:SetPoint("TOPLEFT", Gladdy.buttons[unitId].healthBar, "TOPLEFT", Gladdy.db.petXOffset, Gladdy.db.petYOffset)
|
2021-09-24 16:40:36 +02:00
|
|
|
end
|
2021-05-17 16:49:54 +02:00
|
|
|
|
|
|
|
healthBar.portrait:SetHeight(Gladdy.db.petHeight)
|
|
|
|
healthBar.portrait:SetWidth(Gladdy.db.petHeight)
|
|
|
|
if not Gladdy.db.petPortraitEnabled then
|
|
|
|
healthBar.portrait:Hide()
|
|
|
|
healthBar.portrait.border:Hide()
|
|
|
|
else
|
|
|
|
healthBar.portrait:Show()
|
|
|
|
healthBar.portrait.border:Show()
|
|
|
|
end
|
|
|
|
healthBar.portrait.border:SetTexture(Gladdy.db.petPortraitBorderStyle)
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.portrait.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.petHealthBarBorderColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.bg:SetTexture(Gladdy:SMFetch("statusbar", "petHealthBarTexture"))
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.bg:SetVertexColor(Gladdy:SetColor(Gladdy.db.petHealthBarBgColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar:SetBackdrop({ edgeFile = Gladdy:SMFetch("border", "petHealthBarBorderStyle"),
|
2021-05-17 16:49:54 +02:00
|
|
|
edgeSize = Gladdy.db.petHealthBarBorderSize })
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar:SetBackdropBorderColor(Gladdy:SetColor(Gladdy.db.petHealthBarBorderColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.hp:SetStatusBarTexture(Gladdy:SMFetch("statusbar", "petHealthBarTexture"))
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.hp:SetStatusBarColor(Gladdy:SetColor(Gladdy.db.petHealthBarColor))
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.hp:ClearAllPoints()
|
|
|
|
healthBar.hp:SetPoint("TOPLEFT", healthBar, "TOPLEFT", (Gladdy.db.petHealthBarBorderSize/Gladdy.db.statusbarBorderOffset), -(Gladdy.db.petHealthBarBorderSize/Gladdy.db.statusbarBorderOffset))
|
|
|
|
healthBar.hp:SetPoint("BOTTOMRIGHT", healthBar, "BOTTOMRIGHT", -(Gladdy.db.petHealthBarBorderSize/Gladdy.db.statusbarBorderOffset), (Gladdy.db.petHealthBarBorderSize/Gladdy.db.statusbarBorderOffset))
|
|
|
|
|
|
|
|
if (Gladdy.db.petHealthBarFontSize < 1) then
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.nameText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), 1)
|
|
|
|
healthBar.healthText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), 1)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.nameText:Hide()
|
|
|
|
healthBar.healthText:Hide()
|
|
|
|
else
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.nameText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), Gladdy.db.petHealthBarFontSize)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.nameText:Show()
|
2021-09-14 23:55:17 +02:00
|
|
|
healthBar.healthText:SetFont(Gladdy:SMFetch("font", "petHealthBarFont"), Gladdy.db.petHealthBarFontSize)
|
2021-05-17 16:49:54 +02:00
|
|
|
healthBar.healthText:Show()
|
|
|
|
end
|
2022-01-12 23:07:23 +01:00
|
|
|
healthBar.nameText:SetTextColor(Gladdy:SetColor(Gladdy.db.petHealthBarFontColor))
|
|
|
|
healthBar.healthText:SetTextColor(Gladdy:SetColor(Gladdy.db.petHealthBarFontColor))
|
2021-09-24 15:51:24 +02:00
|
|
|
if (unit == "arenapet1") then
|
2021-09-25 14:03:57 +02:00
|
|
|
Gladdy:CreateMover(self.frames[unit], "petXOffset", "petYOffset", L["Pets"], {"TOPLEFT", "TOPLEFT"})
|
2021-09-24 15:51:24 +02:00
|
|
|
end
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:SetHealthText(healthBar, health, healthMax)
|
|
|
|
|
|
|
|
local healthText = ""
|
|
|
|
if healthMax ~= 0 then
|
|
|
|
local healthPercentage = floor(health * 100 / healthMax)
|
|
|
|
|
|
|
|
if (Gladdy.db.petHealthPercentage) then
|
|
|
|
healthText = ("%d%%"):format(healthPercentage)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
healthText = "DEAD"
|
|
|
|
end
|
|
|
|
|
|
|
|
healthBar.healthText:SetText(healthText)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function option(params)
|
|
|
|
local defaults = {
|
|
|
|
get = function(info)
|
|
|
|
local key = info.arg or info[#info]
|
|
|
|
return Gladdy.dbi.profile[key]
|
|
|
|
end,
|
|
|
|
set = function(info, value)
|
|
|
|
local key = info.arg or info[#info]
|
|
|
|
Gladdy.dbi.profile[key] = value
|
|
|
|
Gladdy.options.args.Pets.args.group.args.border.args.petHealthBarBorderSize.max = Gladdy.db.petHeight/2
|
|
|
|
if Gladdy.db.petHealthBarBorderSize > Gladdy.db.petHeight/2 then
|
|
|
|
Gladdy.db.petHealthBarBorderSize = Gladdy.db.petHeight/2
|
|
|
|
end
|
|
|
|
Gladdy:UpdateFrame()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v in pairs(params) do
|
|
|
|
defaults[k] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
return defaults
|
|
|
|
end
|
|
|
|
|
|
|
|
function Pets:GetOptions()
|
|
|
|
return {
|
2021-05-24 12:41:21 +02:00
|
|
|
header = {
|
2021-05-17 16:49:54 +02:00
|
|
|
type = "header",
|
2021-05-24 12:41:21 +02:00
|
|
|
name = L["Pets"],
|
2021-05-17 16:49:54 +02:00
|
|
|
order = 2,
|
|
|
|
},
|
|
|
|
petEnabled = Gladdy:option({
|
|
|
|
type = "toggle",
|
2021-05-24 12:41:21 +02:00
|
|
|
name = L["Enabled"],
|
|
|
|
desc = L["Enables Pets module"],
|
2021-05-17 16:49:54 +02:00
|
|
|
order = 3,
|
|
|
|
}),
|
|
|
|
group = {
|
|
|
|
type = "group",
|
|
|
|
childGroups = "tree",
|
2021-05-24 12:41:21 +02:00
|
|
|
name = L["Frame"],
|
2021-05-17 16:49:54 +02:00
|
|
|
order = 3,
|
2022-02-15 22:59:21 +01:00
|
|
|
disabled = function() return not Gladdy.db.petEnabled end,
|
2021-05-17 16:49:54 +02:00
|
|
|
args = {
|
|
|
|
general = {
|
|
|
|
type = "group",
|
|
|
|
name = L["General"],
|
|
|
|
order = 1,
|
|
|
|
args = {
|
|
|
|
headerAuras = {
|
|
|
|
type = "header",
|
|
|
|
name = L["General"],
|
|
|
|
order = 1,
|
|
|
|
},
|
|
|
|
petHeight = option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Bar height"],
|
|
|
|
desc = L["Height of the bar"],
|
|
|
|
order = 3,
|
|
|
|
min = 10,
|
|
|
|
max = 100,
|
|
|
|
step = 1,
|
2021-06-15 09:06:50 +02:00
|
|
|
width = "full",
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
|
|
|
petWidth = option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Bar width"],
|
|
|
|
desc = L["Width of the bar"],
|
|
|
|
order = 4,
|
|
|
|
min = 10,
|
2021-05-22 13:42:47 +02:00
|
|
|
max = 300,
|
2021-05-17 16:49:54 +02:00
|
|
|
step = 1,
|
2021-06-15 09:06:50 +02:00
|
|
|
width = "full",
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
2021-09-24 16:40:36 +02:00
|
|
|
petGroup = option({
|
|
|
|
type = "toggle",
|
|
|
|
name = L["Group Pets"],
|
|
|
|
order = 5,
|
|
|
|
}),
|
|
|
|
petMargin = option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Margin"],
|
|
|
|
desc = L["Height of the bar"],
|
|
|
|
order = 6,
|
|
|
|
disabled = function()
|
|
|
|
return not Gladdy.db.petGroup
|
|
|
|
end,
|
|
|
|
min = 0,
|
|
|
|
max = 50,
|
|
|
|
step = .1,
|
|
|
|
}),
|
2021-05-17 16:49:54 +02:00
|
|
|
petHealthBarTexture = option({
|
|
|
|
type = "select",
|
|
|
|
name = L["Bar texture"],
|
|
|
|
desc = L["Texture of the bar"],
|
2021-09-24 16:40:36 +02:00
|
|
|
order = 7,
|
2021-05-17 16:49:54 +02:00
|
|
|
dialogControl = "LSM30_Statusbar",
|
|
|
|
values = AceGUIWidgetLSMlists.statusbar,
|
|
|
|
}),
|
|
|
|
petHealthBarColor = Gladdy:colorOption({
|
|
|
|
type = "color",
|
|
|
|
name = L["Health color"],
|
|
|
|
desc = L["Color of the status bar"],
|
2021-09-24 16:40:36 +02:00
|
|
|
order = 8,
|
2021-05-17 16:49:54 +02:00
|
|
|
hasAlpha = true,
|
|
|
|
}),
|
|
|
|
petHealthBarBgColor = Gladdy:colorOption({
|
|
|
|
type = "color",
|
|
|
|
name = L["Background color"],
|
|
|
|
desc = L["Color of the status bar background"],
|
2021-09-24 16:40:36 +02:00
|
|
|
order = 9,
|
2021-05-17 16:49:54 +02:00
|
|
|
hasAlpha = true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
portrait = {
|
|
|
|
type = "group",
|
|
|
|
name = L["Portrait"],
|
|
|
|
order = 2,
|
|
|
|
args = {
|
|
|
|
headerAuras = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Portrait"],
|
|
|
|
order = 1,
|
|
|
|
},
|
|
|
|
petPortraitEnabled = Gladdy:option({
|
|
|
|
type = "toggle",
|
|
|
|
name = L["Enabled"],
|
|
|
|
order = 2,
|
|
|
|
}),
|
|
|
|
petPortraitBorderStyle = Gladdy:option({
|
|
|
|
type = "select",
|
|
|
|
name = L["Border style"],
|
|
|
|
order = 3,
|
|
|
|
values = Gladdy:GetIconStyles()
|
|
|
|
}),
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
font = {
|
|
|
|
type = "group",
|
|
|
|
name = L["Font"],
|
|
|
|
order = 3,
|
|
|
|
args = {
|
|
|
|
header = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Font"],
|
|
|
|
order = 1,
|
|
|
|
},
|
|
|
|
petHealthBarFont = option({
|
|
|
|
type = "select",
|
|
|
|
name = L["Font"],
|
|
|
|
desc = L["Font of the bar"],
|
|
|
|
order = 11,
|
|
|
|
dialogControl = "LSM30_Font",
|
|
|
|
values = AceGUIWidgetLSMlists.font,
|
|
|
|
}),
|
|
|
|
petHealthBarFontColor = Gladdy:colorOption({
|
|
|
|
type = "color",
|
|
|
|
name = L["Font color"],
|
|
|
|
desc = L["Color of the text"],
|
|
|
|
order = 12,
|
|
|
|
hasAlpha = true,
|
|
|
|
}),
|
|
|
|
petHealthBarFontSize = option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Font size"],
|
|
|
|
desc = L["Size of the text"],
|
|
|
|
order = 13,
|
|
|
|
min = 0,
|
|
|
|
max = 20,
|
2021-06-15 09:06:50 +02:00
|
|
|
width = "full",
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
border = {
|
|
|
|
type = "group",
|
|
|
|
name = L["Border"],
|
|
|
|
order = 4,
|
|
|
|
args = {
|
|
|
|
header = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Border"],
|
|
|
|
order = 1,
|
|
|
|
},
|
|
|
|
petHealthBarBorderStyle = option({
|
|
|
|
type = "select",
|
|
|
|
name = L["Border style"],
|
|
|
|
order = 21,
|
|
|
|
dialogControl = "LSM30_Border",
|
|
|
|
values = AceGUIWidgetLSMlists.border,
|
|
|
|
}),
|
|
|
|
petHealthBarBorderSize = option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Border size"],
|
|
|
|
desc = L["Size of the border"],
|
|
|
|
order = 22,
|
|
|
|
min = 0.5,
|
|
|
|
max = Gladdy.db.petHeight/2,
|
|
|
|
step = 0.5,
|
2021-06-15 09:06:50 +02:00
|
|
|
width = "full",
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
|
|
|
petHealthBarBorderColor = Gladdy:colorOption({
|
|
|
|
type = "color",
|
|
|
|
name = L["Border color"],
|
|
|
|
desc = L["Color of the border"],
|
|
|
|
order = 23,
|
|
|
|
hasAlpha = true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
position = {
|
|
|
|
type = "group",
|
|
|
|
name = L["Position"],
|
|
|
|
order = 5,
|
|
|
|
args = {
|
2021-05-18 16:35:02 +02:00
|
|
|
header = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Position"],
|
|
|
|
order = 1,
|
|
|
|
},
|
2021-05-17 16:49:54 +02:00
|
|
|
petXOffset = Gladdy:option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Horizontal offset"],
|
|
|
|
order = 22,
|
2021-05-18 16:35:02 +02:00
|
|
|
min = -600,
|
|
|
|
max = 600,
|
2021-05-17 16:49:54 +02:00
|
|
|
step = 0.1,
|
2021-06-15 09:06:50 +02:00
|
|
|
width = "full",
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
|
|
|
petYOffset = Gladdy:option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Vertical offset"],
|
|
|
|
order = 23,
|
2021-05-18 16:35:02 +02:00
|
|
|
min = -600,
|
|
|
|
max = 600,
|
2021-05-17 16:49:54 +02:00
|
|
|
step = 0.1,
|
2021-06-15 09:06:50 +02:00
|
|
|
width = "full",
|
2021-05-17 16:49:54 +02:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
},
|
2022-01-12 20:21:53 +01:00
|
|
|
frameStrata = {
|
|
|
|
type = "group",
|
|
|
|
name = L["Frame Strata and Level"],
|
|
|
|
order = 6,
|
|
|
|
args = {
|
|
|
|
headerAuraLevel = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Frame Strata and Level"],
|
|
|
|
order = 1,
|
|
|
|
},
|
|
|
|
petFrameStrata = Gladdy:option({
|
|
|
|
type = "select",
|
|
|
|
name = L["Frame Strata"],
|
|
|
|
order = 2,
|
|
|
|
values = Gladdy.frameStrata,
|
|
|
|
sorting = Gladdy.frameStrataSorting,
|
|
|
|
width = "full",
|
|
|
|
}),
|
|
|
|
petFrameLevel = Gladdy:option({
|
|
|
|
type = "range",
|
|
|
|
name = L["Frame Level"],
|
|
|
|
min = 1,
|
|
|
|
max = 500,
|
|
|
|
step = 1,
|
|
|
|
order = 3,
|
|
|
|
width = "full",
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
2021-05-17 16:49:54 +02:00
|
|
|
healthValues = {
|
|
|
|
type = "group",
|
|
|
|
name = L["Health Values"],
|
2022-01-12 20:21:53 +01:00
|
|
|
order = 7,
|
2021-05-17 16:49:54 +02:00
|
|
|
args = {
|
|
|
|
header = {
|
|
|
|
type = "header",
|
|
|
|
name = L["Health Values"],
|
|
|
|
order = 1,
|
|
|
|
},
|
|
|
|
petHealthPercentage = option({
|
|
|
|
type = "toggle",
|
|
|
|
name = L["Show health percentage"],
|
|
|
|
desc = L["Show health percentage on the health bar"],
|
|
|
|
order = 33,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-01-11 00:29:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
-- LAGACY HANDLER
|
|
|
|
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
function Pets:LegacySetPosition(unit, unitId)
|
|
|
|
if Gladdy.db.newLayout then
|
|
|
|
return Gladdy.db.newLayout
|
|
|
|
end
|
|
|
|
self.frames[unit]:ClearAllPoints()
|
|
|
|
self.frames[unit]:SetPoint("LEFT", Gladdy.buttons[unitId].healthBar, "RIGHT", Gladdy.db.petXOffset, Gladdy.db.petYOffset)
|
|
|
|
if (Gladdy.db.petGroup) then
|
|
|
|
if (unit == "arenapet1") then
|
|
|
|
self.frames[unit]:SetPoint("LEFT", Gladdy.buttons[unitId].healthBar, "RIGHT", Gladdy.db.petXOffset, Gladdy.db.petYOffset)
|
|
|
|
else
|
|
|
|
local previousPet = "arenapet" .. string_gsub(unit, "arenapet", "") - 1
|
|
|
|
self.frames[unit]:ClearAllPoints()
|
|
|
|
self.frames[unit]:SetPoint("TOPLEFT", self.frames[previousPet], "BOTTOMLEFT", 0, - Gladdy.db.petMargin)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.frames[unit]:ClearAllPoints()
|
|
|
|
self.frames[unit]:SetPoint("LEFT", Gladdy.buttons[unitId].healthBar, "RIGHT", Gladdy.db.petXOffset, Gladdy.db.petYOffset)
|
|
|
|
end
|
|
|
|
return Gladdy.db.newLayout
|
2021-05-17 16:49:54 +02:00
|
|
|
end
|