I ended up downloading the entire addon to see what I can do with it. After many hours of testing I think I came up with a solution. (Modified files temporarily attached)
The first thing I ended up doing was to stop
PlayerPet:UpdatePortrait() from reloading the model if it's already being displayed. This should stop the portrait jitter. The optional
force arg forces the update to happen and is for use with the
UNIT_PORTRAIT_UPDATE event.
Lua Code:
function PlayerPet:UpdatePortrait(force)
local unit = self.frame.unit
local guid = UnitGUID(unit)
local texture = self.frame.portrait.texture.texture
local model = self.frame.portrait.model
if UnitIsVisible(unit) then
texture:Hide()
if force or guid ~= model.guid or not model:IsShown() or model:GetModel() == "" then
model:ClearModel()
model:SetUnit(unit)
model:SetPortraitZoom(1)
model:Show()
model.guid = guid
end
else
model:Hide()
SetPortraitTexture(texture, unit)
texture:Show()
end
end
While
RegisterAttributeDriver() is being used for both UnitFrames now, to keep things simple, the
OnAttributeChanged script was removed entirely. (It was firing at the wrong time anyway.)
I ended up using
UNIT_PET to synchronize the swapping of the player and pet frames. The quirk about this is the
vehicle UnitID doesn't work, but you can still access the vehicle data using the
pet UnitID. Fortunately,
UnitHasVehicleUI() does seem to return the correct state here for both entering and exiting a vehicle. None of the
UNIT_*_VEHICLE events are used anymore.
Player.lua
Lua Code:
function Player:UNIT_PET()
self.frame.unit = UnitHasVehicleUI("player") and "pet" or "player"
self:UpdateDisplay()
end
PlayerPet.lua
Lua Code:
function PlayerPet:UNIT_PET(...)
self.frame.unit = UnitHasVehicleUI("player") and "player" or "pet"
self:UpdateDisplay()
end
Edit: Attachments deleted, see later posts.