View Single Post
10-16-16, 04:16 AM   #12
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
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:
  1. frame.timer = 0
  2. frame:SetScript("OnUpdate", function(self, elapsed)
  3.         self.timer = self.timer + elapsed
  4.         local x, y = GetCursorPosition()
  5.         if event == "PLAYER_REGEN_ENABLED" then
  6.             if event == "PLAYER_STOPPED_MOVING" then
  7.                 if self.x ~= x or self.y ~= y then
  8.                     UIParent:SetAlpha(1)
  9.                     -- UIParent:SetAlpha(UIParent:GetAlpha()+elapsed)
  10.                 elseif not IsMouselooking() then
  11.                     self.timer = 0
  12.                     UIParent:SetAlpha(UIParent:GetAlpha()-elapsed)
  13.                 end
  14.                 if self.timer > 3 then
  15.                     -- check mouse looking here since the cursor position is static while
  16.                     -- holding down right mouse button, also check that you're not mousing
  17.                     -- over a frame since that may not be desirable either
  18.                     if not IsMouselooking() and GetMouseFocus() == WorldFrame then
  19.                         self.x = x
  20.                         self.y = y
  21.                     end
  22.                    
  23.                     self.timer = 0
  24.                 end
  25.             else if player started moving
  26.                 if event == "PLAYER_STARTED_MOVING" then
  27.                     UIParent:SetAlpha(1)
  28.                 end
  29.             end
  30.         end
  31. 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:
  1. local frame = CreateFrame("Frame")
  2. local GetCursorPosition, IsMouselooking = GetCursorPosition, IsMouselooking
  3. local GetMouseFocus = GetMouseFocus
  4. local UIParent, WorldFrame = UIParent, WorldFrame
  5. local ihide = 1
  6.  
  7.  
  8. frame:RegisterEvent("PLAYER_STOPPED_MOVING")
  9. frame:RegisterEvent("PLAYER_STARTED_MOVING")
  10. frame:RegisterEvent("PLAYER_REGEN_DISABLED")
  11. frame.timer = 0
  12.  
  13.  
  14. frame:SetScript("OnEvent", function(self, event)
  15.     if event == "PLAYER_STOPPED_MOVING" then
  16.         if event == "PLAYER_REGEN_ENABLED" then
  17.             ihide = 1
  18.         end
  19.         if event == "PLAYER_REGEN_DISABLED" then
  20.             ihide = 0
  21.         end
  22.     end
  23.     if event == "PLAYER_STARTED_MOVING" then
  24.         ihide = 0
  25.         UIParent:SetAlpha(1)
  26.     end
  27.     if event == "PLAYER_REGEN_DISABLED" then
  28.         ihide = 0
  29.     end
  30.    
  31. end)
  32.  
  33.  
  34. frame:SetScript("OnUpdate", function(self, elapsed)
  35.         self.timer = self.timer + elapsed
  36.         local x, y = GetCursorPosition()
  37.         if self.x ~= x or self.y ~= y then
  38.             UIParent:SetAlpha(1)
  39.             ihide = 0
  40.             -- UIParent:SetAlpha(UIParent:GetAlpha()+elapsed)
  41.         elseif not IsMouselooking() then
  42.             if ihide > 0 then
  43.                 self.timer = 0
  44.                 UIParent:SetAlpha(UIParent:GetAlpha()-elapsed)
  45.             end
  46.         end
  47.         if self.timer > 3 then
  48.             -- check mouse looking here since the cursor position is static while
  49.             -- holding down right mouse button, also check that you're not mousing
  50.             -- over a frame since that may not be desirable either
  51.             if not IsMouselooking() and GetMouseFocus() == WorldFrame then
  52.                 self.x = x
  53.                 self.y = y
  54.             end
  55.            
  56.             self.timer = 0
  57.         end
  58. end)
  59.  
  60. function HelloWorld(self)
  61.         print("Immersive Hide loaded.");
  62. end

How can I make this idea work?

Last edited by Krainz : 10-16-16 at 10:40 PM.
  Reply With Quote