Quantcast Hide UI automatically hide after not moving my mouse for 3 or so seconds? - Page 2 - WoWInterface
Thread Tools Display Modes
10-20-16, 10:58 PM   #21
Krainz
A Deviate Faerie Dragon
Join Date: Oct 2016
Posts: 19
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.
  Reply With Quote
10-21-16, 12:56 AM   #22
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,635
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.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 10-21-16 at 01:02 AM.
  Reply With Quote
10-21-16, 04:09 AM   #23
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
that seems like it would cause problems if you were to stop to look at the world map, or any other ui panel d:
  Reply With Quote
10-21-16, 04:47 AM   #24
tonyis3l33t
A Cyclonian
 
tonyis3l33t's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 42
Originally Posted by ObbleYeah View Post
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.

Last edited by tonyis3l33t : 10-21-16 at 05:02 AM.
  Reply With Quote
10-23-16, 02:46 PM   #25
Krainz
A Deviate Faerie Dragon
Join Date: Oct 2016
Posts: 19
It's fantastic. Truly amazing work there, tonyis3l33t.

Originally Posted by tonyis3l33t View Post
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.

Last edited by Krainz : 10-23-16 at 02:56 PM.
  Reply With Quote
10-25-16, 08:52 PM   #26
Krainz
A Deviate Faerie Dragon
Join Date: Oct 2016
Posts: 19
How do I make the uI not appear during cutscenes? (like those in Hyjal and uldum)
  Reply With Quote
10-30-16, 10:17 PM   #27
Krainz
A Deviate Faerie Dragon
Join Date: Oct 2016
Posts: 19
ALT+Z doesn't work while the addon is loaded...
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Hide UI automatically hide after not moving my mouse for 3 or so seconds?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off