View Single Post
10-13-16, 11:28 PM   #9
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
I would suggest doing something like this if you want to use the cursor position:
Lua Code:
  1. local frame = CreateFrame("Frame")
  2. local GetCursorPosition, IsMouselooking = GetCursorPosition, IsMouselooking
  3. local GetMouseFocus = GetMouseFocus
  4. local UIParent, WorldFrame = UIParent, WorldFrame
  5.  
  6. frame.timer = 0
  7. frame:SetScript("OnUpdate", function(self, elapsed)
  8.         self.timer = self.timer + elapsed
  9.         local x, y = GetCursorPosition()
  10.         if self.x ~= x or self.y ~= y then
  11.             UIParent:SetAlpha(UIParent:GetAlpha()+elapsed)
  12.         elseif not IsMouselooking() then
  13.             self.timer = 0
  14.             UIParent:SetAlpha(UIParent:GetAlpha()-elapsed)
  15.         end
  16.         if self.timer > 3 then
  17.             -- check mouse looking here since the cursor position is static while
  18.             -- holding down right mouse button, also check that you're not mousing
  19.             -- over a frame since that may not be desirable either
  20.             if not IsMouselooking() and GetMouseFocus() == WorldFrame then
  21.                 self.x = x
  22.                 self.y = y
  23.             end
  24.            
  25.             self.timer = 0
  26.         end
  27. end)

This will fade out the UIParent smoothly instead of hiding/showing it, which isn't something you can do without causing problems. A lot of secure frames, from addons and Blizzard alike, are children of UIParent, and this would break stuff if you were to insecurely attempt to hide the frame in combat.

The performance dent is negligible with localized shortcuts to the global functions used in this script and you're only operating on simple true/false statements anyway. You don't have to worry about performance with such a small script.
__________________
  Reply With Quote