Originally Posted by Othgar
So then would there be a script that could hide a panel when you're not moving, but show the panel when you are moving? I was thinking of this earlier for a minimap mod, but couldn't come up with a way to do it. Closest I got was
Code:
if movementspeed == 0 then
hide
else show
but I've said it before and I'll say it again....I suck with lua...for now
|
Yeah, that's doable.
Code:
local FrameToHide = Minimap
local MovementTimer = CreateFrame("Frame")
MovementTimer.UpdateInterval = 0.1
MovementTimer.ToggleDelay = 1
MovementTimer.Elapsed = 0
MovementTimer.StoppedElapsed = 0
MovementTimer.LastPosition = {x = 0, y = 0}
MovementTimer:Show()
MovementTimer:SetScript("OnUpdate", function(self, elapsed)
MovementTimer.Elapsed = MovementTimer.Elapsed + elapsed
if MovementTimer.Elapsed >= MovementTimer.UpdateInterval then
local x, y = GetPlayerMapPosition("Player")
if x == MovementTimer.LastPosition.x and y == MovementTimer.LastPosition.y then
MovementTimer.StoppedElapsed = MovementTimer.StoppedElapsed + MovementTimer.Elapsed
if MovementTimer.StoppedElapsed >= MovementTimer.ToggleDelay then
FrameToHide:Hide()
end
else
MovementTimer.StoppedElapsed = 0
if not FrameToHide:IsShown() then FrameToHide:Show() end
end
MovementTimer.LastPosition.x = x
MovementTimer.LastPosition.y = y
MovementTimer.Elapsed = 0
end
end)
If you want to hide a kgPanel with this code, then you'll need to create another kgPanel with this code in it's OnLoad section. And, instead of the top line
local FrameToHide = Minimap, use
local FrameToHide = kgPanels:FetchFrame("my panel") where mypanel is what you named the panel you want to hide in kgPanels.
Reason you need another panel, is that when you hide a frame, it's OnUpdate scripts no longer work.
Adjust
MovementTimer.ToggleDelay to your liking. It's how long in seconds after you stop to hide the Minimap.