更新配置相关显示等
This commit is contained in:
156
Units/Pet.lua
156
Units/Pet.lua
@@ -137,6 +137,8 @@ function SFrames.Pet:Initialize()
|
||||
self.frame.unit = "pet"
|
||||
f:Hide()
|
||||
|
||||
self:CreateCastbar()
|
||||
|
||||
SFrames:RegisterEvent("UNIT_PET", function() if arg1 == "player" then self:UpdateAll() end end)
|
||||
SFrames:RegisterEvent("PET_BAR_UPDATE", function() self:UpdateAll() end)
|
||||
SFrames:RegisterEvent("UNIT_HEALTH", function() if arg1 == "pet" then self:UpdateHealth() end end)
|
||||
@@ -785,3 +787,157 @@ function SFrames.Pet:UpdateFoodButton()
|
||||
if self.foodPanel then self.foodPanel:Hide() end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Pet Castbar
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function SFrames.Pet:CreateCastbar()
|
||||
local f = self.frame
|
||||
local cbHeight = SFrames.Config.castbarHeight
|
||||
|
||||
local cb = SFrames:CreateStatusBar(f, "SFramesPetCastbar")
|
||||
cb:SetHeight(cbHeight)
|
||||
cb:SetPoint("BOTTOMLEFT", f, "TOPLEFT", 0, 4)
|
||||
cb:SetPoint("BOTTOMRIGHT", f, "TOPRIGHT", -(cbHeight + 6), 4)
|
||||
|
||||
local cbbg = CreateFrame("Frame", nil, f)
|
||||
cbbg:SetPoint("TOPLEFT", cb, "TOPLEFT", -1, 1)
|
||||
cbbg:SetPoint("BOTTOMRIGHT", cb, "BOTTOMRIGHT", 1, -1)
|
||||
cbbg:SetFrameLevel(cb:GetFrameLevel() - 1)
|
||||
SFrames:CreateUnitBackdrop(cbbg)
|
||||
|
||||
cb.bg = cb:CreateTexture(nil, "BACKGROUND")
|
||||
cb.bg:SetAllPoints()
|
||||
cb.bg:SetTexture(SFrames:GetTexture())
|
||||
cb.bg:SetVertexColor(_A.slotBg[1], _A.slotBg[2], _A.slotBg[3], _A.slotBg[4] or 1)
|
||||
cb:SetStatusBarColor(1, 0.7, 0)
|
||||
|
||||
cb.text = SFrames:CreateFontString(cb, 10, "LEFT")
|
||||
cb.text:SetPoint("LEFT", cb, "LEFT", 4, 0)
|
||||
|
||||
cb.time = SFrames:CreateFontString(cb, 10, "RIGHT")
|
||||
cb.time:SetPoint("RIGHT", cb, "RIGHT", -4, 0)
|
||||
|
||||
cb.icon = cb:CreateTexture(nil, "ARTWORK")
|
||||
cb.icon:SetWidth(cbHeight + 2)
|
||||
cb.icon:SetHeight(cbHeight + 2)
|
||||
cb.icon:SetPoint("LEFT", cb, "RIGHT", 4, 0)
|
||||
cb.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
|
||||
|
||||
local ibg = CreateFrame("Frame", nil, f)
|
||||
ibg:SetPoint("TOPLEFT", cb.icon, "TOPLEFT", -1, 1)
|
||||
ibg:SetPoint("BOTTOMRIGHT", cb.icon, "BOTTOMRIGHT", 1, -1)
|
||||
ibg:SetFrameLevel(cb:GetFrameLevel() - 1)
|
||||
SFrames:CreateUnitBackdrop(ibg)
|
||||
|
||||
cb:Hide()
|
||||
cbbg:Hide()
|
||||
cb.icon:Hide()
|
||||
ibg:Hide()
|
||||
|
||||
f.castbar = cb
|
||||
f.castbar.cbbg = cbbg
|
||||
f.castbar.ibg = ibg
|
||||
|
||||
f.castbarUpdater = CreateFrame("Frame", nil, f)
|
||||
f.castbarUpdater:SetScript("OnUpdate", function() SFrames.Pet:CastbarOnUpdate() end)
|
||||
end
|
||||
|
||||
function SFrames.Pet:CastbarOnUpdate()
|
||||
local cb = self.frame.castbar
|
||||
if not UnitExists("pet") then
|
||||
cb:Hide()
|
||||
cb.cbbg:Hide()
|
||||
cb.icon:Hide()
|
||||
cb.ibg:Hide()
|
||||
return
|
||||
end
|
||||
|
||||
local cast, texture, startTime, endTime, channel
|
||||
|
||||
-- 1) Try native UnitCastingInfo / UnitChannelInfo (TurtleWoW extended API)
|
||||
local _UnitCastingInfo = UnitCastingInfo or (ShaguTweaks and ShaguTweaks.UnitCastingInfo)
|
||||
if _UnitCastingInfo then
|
||||
local c, _, _, tex, st, et = _UnitCastingInfo("pet")
|
||||
if c then
|
||||
cast, texture, startTime, endTime = c, tex, st, et
|
||||
end
|
||||
end
|
||||
|
||||
if not cast then
|
||||
local _UnitChannelInfo = UnitChannelInfo or (ShaguTweaks and ShaguTweaks.UnitChannelInfo)
|
||||
if _UnitChannelInfo then
|
||||
local c, _, _, tex, st, et = _UnitChannelInfo("pet")
|
||||
if c then
|
||||
cast, texture, startTime, endTime = c, tex, st, et
|
||||
channel = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- 2) Fallback: SuperWoW castdb (GUID-based)
|
||||
if not cast and SFrames.castdb and UnitGUID then
|
||||
local guid = UnitGUID("pet")
|
||||
if guid then
|
||||
local entry = SFrames.castdb[guid]
|
||||
if entry and entry.cast and entry.start and entry.casttime then
|
||||
local elapsed = GetTime() - entry.start
|
||||
local duration = entry.casttime / 1000
|
||||
if elapsed < duration + 0.5 then
|
||||
cast = entry.cast
|
||||
texture = entry.icon
|
||||
startTime = entry.start * 1000
|
||||
endTime = (entry.start + duration) * 1000
|
||||
channel = entry.channel
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if cast and startTime and endTime then
|
||||
local duration = (endTime - startTime) / 1000
|
||||
local cur = GetTime() - (startTime / 1000)
|
||||
|
||||
if channel then
|
||||
cur = duration + (startTime / 1000) - GetTime()
|
||||
end
|
||||
|
||||
if cur > duration then cur = duration end
|
||||
if cur < 0 then cur = 0 end
|
||||
|
||||
cb:SetMinMaxValues(0, duration)
|
||||
cb:SetValue(cur)
|
||||
cb.text:SetText(cast)
|
||||
cb.time:SetText(string.format("%.1f", channel and cur or math.max(duration - cur, 0)))
|
||||
|
||||
if texture then
|
||||
cb.icon:SetTexture(texture)
|
||||
end
|
||||
|
||||
cb:SetAlpha(1)
|
||||
cb.cbbg:SetAlpha(1)
|
||||
cb.icon:SetAlpha(1)
|
||||
cb.ibg:SetAlpha(1)
|
||||
|
||||
cb:Show()
|
||||
cb.cbbg:Show()
|
||||
cb.icon:Show()
|
||||
cb.ibg:Show()
|
||||
else
|
||||
if cb:IsShown() then
|
||||
local alpha = cb:GetAlpha() - 0.05
|
||||
if alpha > 0 then
|
||||
cb:SetAlpha(alpha)
|
||||
cb.cbbg:SetAlpha(alpha)
|
||||
cb.icon:SetAlpha(alpha)
|
||||
cb.ibg:SetAlpha(alpha)
|
||||
else
|
||||
cb:Hide()
|
||||
cb.cbbg:Hide()
|
||||
cb.icon:Hide()
|
||||
cb.ibg:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user