Yup, exactly what I wanted. Thank you very much!
Now slightly off topic, is it possible to also code a short "fade from black" after every loading screen? For immersive purposes.
If needed I'll open another topic for that.
EDIT:
So I coded this:
Lua Code:
frame.timer = 0
frame:SetScript("OnUpdate", function(self, elapsed)
self.timer = self.timer + elapsed
local x, y = GetCursorPosition()
if event == "PLAYER_REGEN_ENABLED" then
if event == "PLAYER_STOPPED_MOVING" then
if self.x ~= x or self.y ~= y then
UIParent:SetAlpha(1)
-- UIParent:SetAlpha(UIParent:GetAlpha()+elapsed)
elseif not IsMouselooking() then
self.timer = 0
UIParent:SetAlpha(UIParent:GetAlpha()-elapsed)
end
if self.timer > 3 then
-- check mouse looking here since the cursor position is static while
-- holding down right mouse button, also check that you're not mousing
-- over a frame since that may not be desirable either
if not IsMouselooking() and GetMouseFocus() == WorldFrame then
self.x = x
self.y = y
end
self.timer = 0
end
else if player started moving
if event == "PLAYER_STARTED_MOVING" then
UIParent:SetAlpha(1)
end
end
end
end)
It's basically:
if player is not in combat and
if player is not moving
hide UI
Added to the '3 seconds without moving the mouse' code.
But it's not working. What did I do wrong?
Alternatively, I'm trying to do this through a variable checking way. It would would set a variable (ihide) to 1 whenever I'd want the UI to hide, and to 0 whenever I wouldn't want it to hide (combat, when the character is moving).
Still, it doesn't work. Why?
lua Code:
local frame = CreateFrame("Frame")
local GetCursorPosition, IsMouselooking = GetCursorPosition, IsMouselooking
local GetMouseFocus = GetMouseFocus
local UIParent, WorldFrame = UIParent, WorldFrame
local ihide = 1
frame:RegisterEvent("PLAYER_STOPPED_MOVING")
frame:RegisterEvent("PLAYER_STARTED_MOVING")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame.timer = 0
frame:SetScript("OnEvent", function(self, event)
if event == "PLAYER_STOPPED_MOVING" then
if event == "PLAYER_REGEN_ENABLED" then
ihide = 1
end
if event == "PLAYER_REGEN_DISABLED" then
ihide = 0
end
end
if event == "PLAYER_STARTED_MOVING" then
ihide = 0
UIParent:SetAlpha(1)
end
if event == "PLAYER_REGEN_DISABLED" then
ihide = 0
end
end)
frame:SetScript("OnUpdate", function(self, elapsed)
self.timer = self.timer + elapsed
local x, y = GetCursorPosition()
if self.x ~= x or self.y ~= y then
UIParent:SetAlpha(1)
ihide = 0
-- UIParent:SetAlpha(UIParent:GetAlpha()+elapsed)
elseif not IsMouselooking() then
if ihide > 0 then
self.timer = 0
UIParent:SetAlpha(UIParent:GetAlpha()-elapsed)
end
end
if self.timer > 3 then
-- check mouse looking here since the cursor position is static while
-- holding down right mouse button, also check that you're not mousing
-- over a frame since that may not be desirable either
if not IsMouselooking() and GetMouseFocus() == WorldFrame then
self.x = x
self.y = y
end
self.timer = 0
end
end)
function HelloWorld(self)
print("Immersive Hide loaded.");
end
How can I make this idea work?