local function SetFacing(self, deltaX)

self.deltaX = self.deltaX + (deltaX * 0.01)

self:SetFacing(self.deltaX)

end

local function SetPosition(self, x, y, z)

self.x = self.x + (x * 0.1)

self.y = self.y + (y * 0.01)

self.z = self.z + (z * 0.01)

self:SetPosition(self.x, self.y, self.z)

end

local f = CreateFrame("Button", nil, TargetFrame, "UIPanelButtonTemplate")

f:SetSize(50, 20)

f:SetPoint("BOTTOMLEFT", TargetFrameNameBackground, "TOPLEFT")

f:SetText("Show")

f:SetScript("OnClick", function(self, button)

local Shown = not self.Model:IsShown()

self.Model:SetShown(Shown)

self:SetText(Shown and "Hide" or "Show")

end)

f.Model = CreateFrame("PlayerModel", nil, UIParent)

f.Model:Hide()

f.Model:SetSize(200, 200)

f.Model:SetPoint("CENTER", 200, 80)

f.Model:EnableMouse(true)

f.Model.deltaX = 0

f.Model.x, f.Model.y, f.Model.z = 0, 0, 0

f.Model:SetMovable(true)

f.Model:SetResizable(true)

f.Model:RegisterForDrag("LeftButton")

f.Model.Texture = f.Model:CreateTexture()

f.Model.Texture:Hide()

f.Model.Texture:SetAllPoints()

f.Model.Texture:SetTexture("Interface/BUTTONS/WHITE8X8")

f.Model.Texture:SetVertexColor(0.2, 0.4, 0.7, 0.2)

f.Model:SetScript("OnDragStart", function(self, ...)

if not self.UnLock then return end

if IsAltKeyDown() then

self:StartSizing("BOTTOMRIGHT")

else

self:StartMoving()

end

end)

f.Model:SetScript("OnDragStop", function(self)

self:StopMovingOrSizing()

self.ButtonDown = nil

end)

f.Model:SetScript("OnEvent", function(self, event, ...)

if event == "PLAYER_TARGET_CHANGED" then

self.Reset:GetScript("OnClick")(self.Reset)

else

self:SetUnit("target")

end

end)

f.Model:RegisterEvent("PLAYER_TARGET_CHANGED")

f.Model:RegisterUnitEvent("UNIT_MODEL_CHANGED", target)

f.Model:SetScript("OnMouseDown", function(self, button)

if self.UnLock then return end

self.ButtonDown = button

end)

f.Model:SetScript("OnMouseUp", function(self, button)

self.ButtonDown = nil

end)

f.Model:SetScript("OnMouseWheel", function(self, delta)

SetPosition(self, delta, 0, 0)

end)

f.Model:SetScript("OnUpdate", function(self, elapsed)

if self.ButtonDown then

if self.ButtonDown == "LeftButton" then

if self.UnLock then return end

local deltaX, deltaY = GetScaledCursorDelta()

SetFacing(self, deltaX)

elseif self.ButtonDown == "RightButton" then

local x, y, z = GetScaledCursorDelta()

SetPosition(self, 0, x, y)

end

end

end)

f.Model.Reset = CreateFrame("Button", nil, f.Model, "UIPanelButtonTemplate")

f.Model.Reset:SetSize(60, 20)

f.Model.Reset:SetPoint("BOTTOMLEFT", f.Model, "TOPLEFT")

f.Model.Reset:SetText("Reset")

f.Model.Reset:SetScript("OnClick", function(self)

local parent = self:GetParent()

parent.zoom = 0

parent.deltaX = 0

parent.x, parent.y, parent.z = 0, 0, 0

SetFacing(parent, 0)

SetPosition(parent, 0, 0, 0)

parent:SetUnit("target")

end)

f.Model.Lock = CreateFrame("Button", nil, f.Model, "UIPanelButtonTemplate")

f.Model.Lock:SetSize(60, 20)

f.Model.Lock:SetPoint("BOTTOM", f.Model, "TOP")

f.Model.Lock:SetText("Unlock")

f.Model.Lock:SetScript("OnClick", function(self)

self:GetParent().UnLock = not self:GetParent().UnLock

self:SetText(self:GetParent().UnLock and "Lock" or "Unlock")

end)

f.Model.Close = CreateFrame("Button", nil, f.Model)

f.Model.Close:SetSize(22, 22)

f.Model.Close:SetPoint("BOTTOMRIGHT", f.Model, "TOPRIGHT")

f.Model.Close:SetNormalTexture("Interface/Buttons/UI-Panel-MinimizeButton-Up")

f.Model.Close:SetPushedTexture("Interface/Buttons/UI-Panel-MinimizeButton-Down")

f.Model.Close:SetHighlightTexture("Interface/Buttons/UI-Panel-MinimizeButton-Highlight", "ADD")

f.Model.Close:SetScript("OnClick", function(self)

PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)

f:GetScript("OnClick")(f) -- Call the target frame button's click handler

end)

f.Model.Background = CreateFrame("Button", nil, f.Model, "UIPanelButtonTemplate")

f.Model.Background:SetSize(40, 20)

f.Model.Background:SetPoint("RIGHT", f.Model.Close, "LEFT", -5, 0)

f.Model.Background:SetText("Bg")

f.Model.Background:SetScript("OnClick", function(self)

local parent = self:GetParent()

parent.Texture:SetShown(not parent.Texture:IsShown())

end)