WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Hide UI automatically hide after not moving my mouse for 3 or so seconds? (https://www.wowinterface.com/forums/showthread.php?t=54642)

Krainz 10-20-16 10:58 PM

lua Code:
  1. local addon = CreateFrame("Frame");
  2. addon:RegisterEvent("PLAYER_LOGIN");
  3. addon:RegisterEvent("PLAYER_REGEN_DISABLED");
  4. addon:RegisterEvent("PLAYER_REGEN_ENABLED");
  5. addon:RegisterEvent("PLAYER_STARTED_MOVING");
  6. addon:RegisterEvent("PLAYER_STOPPED_MOVING");
  7.  
  8. local function wait(seconds)
  9.   local start = os.time()
  10.   repeat until os.time() > start + seconds
  11. end
  12.  
  13. addon:SetScript("OnEvent", function(self, event, ...)
  14.  
  15.     if event == "PLAYER_LOGIN"
  16.     or event == "PLAYER_REGEN_DISABLED"
  17.     or event == "PLAYER_STOPPED_MOVING" then
  18.        
  19.         if not UnitAffectingCombat("player") then
  20.             wait(3)
  21.             if not UnitAffectingCombat("player") then
  22.                 C_Timer.After(1, UIFrameFadeOut(UIParent, 3, UIParent:GetAlpha(), 0));
  23.             end;
  24.         end;
  25.     else
  26.         UIParent:SetAlpha(1);
  27.     end;
  28.    
  29.     if UnitAffectingCombat("player") then
  30.         UIParent:SetAlpha(1);
  31.     end;
  32. end);
  33.  
  34. addon:SetScript("OnUpdate", function(self, elapsed)
  35.  
  36.     local speed = GetUnitSpeed("player");
  37.     if speed ~=0 then
  38.         UIParent:SetAlpha(1);
  39.     else
  40.         if GetMouseFocus() then
  41.             if GetMouseFocus():GetName() ~= "WorldFrame" then
  42.                 UIParent:SetAlpha(1);
  43.             else
  44.                 if not UnitAffectingCombat("player") then
  45.                     wait(3)
  46.                     if not UnitAffectingCombat("player") then
  47.                         C_Timer.After(1, UIFrameFadeOut(UIParent, 3, UIParent:GetAlpha(), 0))
  48.                     end;
  49.                 end;
  50.             end;
  51.         end;
  52.     end;
  53.    
  54.     if UnitName("mouseover") then
  55.         UIParent:SetAlpha(1);
  56.     end;
  57. end);

And in the end I basically tried inserting a wait() function that just basically didn't work out in the end. That code doesn't work and does nothing when I log in.

zork 10-21-16 12:56 AM

Why don't you just call a c_timer.after every 3 seconds and check if the mouse cursor position has changed inbetween. Ontop it should be possible to get the player facing direction and coordinates. You can check that too. If both are the same you can hide the ui if not you reset the c_timer.

ObbleYeah 10-21-16 04:09 AM

that seems like it would cause problems if you were to stop to look at the world map, or any other ui panel d:

tonyis3l33t 10-21-16 04:47 AM

Quote:

Originally Posted by ObbleYeah (Post 320104)
that seems like it would cause problems if you were to stop to look at the world map, or any other ui panel d:

Those can all be fixed with a big If statement.

Lua Code:
  1. if UnitAffectingCombat("Player")
  2.     or InCombatLockdown()
  3.     or ChatFrame1EditBox:IsShown()
  4.     or WorldMapFrame:IsShown()
  5.     or MailFrame:IsShown()
  6.     or GossipFrame:IsShown()
  7.     or GameTooltipTextLeft1:GetText()
  8.     or UnitCastingInfo("Player")
  9.     or UnitChannelInfo("Player")
  10.     or UnitExists("Target") then
  11.         addon:FadeIn();
  12.     end;

I ended up liking what this looked like the more I worked on it, and now prefer it over my daftFrameFade (which fades frames individually) since using UIParent will "support" all addons. So I threw it up as daftUIFade. Note this one doesn't do the show-while-moving, the show-while-mouselooking, or the hide-after-not-moving-mouse stuff.

Krainz 10-23-16 02:46 PM

It's fantastic. Truly amazing work there, tonyis3l33t.

Quote:

Originally Posted by tonyis3l33t (Post 320106)
Note this one doesn't do the show-while-moving, the show-while-mouselooking, or the hide-after-not-moving-mouse stuff.

I tried implementing that by expanding the big if statement and merging it with MunkDev's code:

lua Code:
  1. addon.timer = 0
  2. addon:SetScript("OnUpdate", function(self, elapsed)
  3.         self.timer = self.timer + elapsed
  4.         local speed = GetUnitSpeed("player");
  5.         local x, y = GetCursorPosition();
  6.         if self.x ~= x
  7.         or self.y ~= y
  8.         or UnitAffectingCombat("Player")
  9.         or InCombatLockdown()
  10.         or speed ~=0
  11.         or UnitName("mouseover")
  12.         or ChatFrame1EditBox:IsShown()
  13.         or WorldMapFrame:IsShown()
  14.         or MailFrame:IsShown()
  15.         or GossipFrame:IsShown()
  16.         or GameTooltipTextLeft1:GetText()
  17.         or UnitCastingInfo("Player")
  18.         or UnitChannelInfo("Player")
  19.         or UnitExists("Target") then
  20.             addon:FadeIn();
  21.         elseif not IsMouselooking() then
  22.             self.timer = 0
  23.             addon:FadeOut();
  24.         end;
  25.         if self.timer > 5 then
  26.             -- check mouse looking here since the cursor position is static while
  27.             -- holding down right mouse button, also check that you're not mousing
  28.             -- over a frame since that may not be desirable either
  29.             if not IsMouselooking() and GetMouseFocus() == WorldFrame then
  30.                 self.x = x
  31.                 self.y = y
  32.             end
  33.            
  34.             self.timer = 0
  35.         end
  36. end)

Needs more testing though.

Krainz 10-25-16 08:52 PM

How do I make the uI not appear during cutscenes? (like those in Hyjal and uldum)

Krainz 10-30-16 10:17 PM

ALT+Z doesn't work while the addon is loaded...


All times are GMT -6. The time now is 01:36 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI