WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Increase OOR Alpha/Fade Transparency for Raid Frames? (https://www.wowinterface.com/forums/showthread.php?t=56243)

Xancepants 05-26-18 10:43 AM

Increase OOR Alpha/Fade Transparency for Raid Frames?
 
Hello All!
Was wondering if anybody could help with a bit of Lua code that can Increase the Alpha / Fade Transparency of the Blizzard Raid Frames, for raid members that are out of the 40yd Spell Range? Found a number of addons out there that can achieve this, but am trying to avoid DL'ing addons as much as possible.


I found this bit of Lua which does work, but it keeps throwing errors for some reason?

Lua Code:
  1. --[Change Raid Frame OOR Fade/Alpha Transparency]
  2. hooksecurefunc("CompactUnitFrame_UpdateInRange",function(frame)
  3.     local inRange,checkedRange = UnitInRange(frame.displayedUnit)
  4.     if checkedRange and not inRange then
  5.         frame.background:SetAlpha(0.3)
  6.         frame:SetAlpha(0.3)
  7.     else
  8.         frame.background:SetAlpha(1)
  9.         frame:SetAlpha(1)
  10.     end
  11. end)


And here is the error that Bug Sack is logging:

802x Custom Settings\Custom Settings.lua:602: attempt to index field 'background' (a nil value)
Custom Settings\Custom Settings.lua:602: in function <Custom Settings\Custom Settings.lua:596>


Any help is appreciated, thank you in advance! :)

Ammako 05-26-18 12:19 PM

This is what Blizzard uses fwiw

lua Code:
  1. function CompactUnitFrame_UpdateInRange(frame)
  2.   if ( not frame.optionTable.fadeOutOfRange ) then
  3.     return;
  4.   end
  5.  
  6.   local inRange, checkedRange = UnitInRange(frame.displayedUnit);
  7.   if ( checkedRange and not inRange ) then  --If we weren't able to check the range for some reason, we'll just treat them as in-range (for example, enemy units)
  8.     frame:SetAlpha(0.55);
  9.   else
  10.     frame:SetAlpha(1);
  11.   end
  12. end

https://www.townlong-yak.com/framexm...tFrame.lua#648

frame.background doesn't seem to be a thing here, not sure where you got that code from but it could have been from an older version of the game and raid frames may have changed since, idk.

You can always override this by doing something like this:

lua Code:
  1. hooksecurefunc("CompactUnitFrame_UpdateInRange", function(frame)
  2.   if ( not frame.optionTable.fadeOutOfRange ) then
  3.     return;
  4.   end
  5.  
  6.   local inRange, checkedRange = UnitInRange(frame.displayedUnit);
  7.   if ( checkedRange and not inRange ) then  --If we weren't able to check the range for some reason, we'll just treat them as in-range (for example, enemy units)
  8.     frame:SetAlpha(0.3);
  9.   else
  10.     frame:SetAlpha(1);
  11.   end
  12. end)

Xrystal 05-26-18 06:45 PM

The background parentKey is in the xml file for the lua file you linked, just in case you missed it ..

Code:

  <Button name="CompactUnitFrameTemplate" frameStrata="LOW" inherits="SecureUnitButtonTemplate" virtual="true">
    <Layers>
      <Layer level="BACKGROUND">
        <Texture name="$parentBackground" parentKey="background" setAllPoints="true" ignoreParentAlpha="true"/>
      </Layer>
      <Layer level="BORDER" textureSubLevel="5">
        <Texture name="$parentMyHealPrediction" parentKey="myHealPrediction"/>
        <Texture name="$parentOtherHealPrediction" parentKey="otherHealPrediction"/>
        <Texture name="$parentTotalAbsorb" parentKey="totalAbsorb"/>
      </Layer>


Ammako 05-26-18 09:26 PM

In that case, I'm not entirely sure what causes it to return nil error.

Is there code in original Blizzard code that increases that background's alpha when OOR? because otherwise the lua function only changes the alpha for the raid frame cell itself and leaves the background untouched, either way. so that would probably be the way to go if all that was wanted was to increase the effects of what Blizzard's UI already does.

(also I don't really ever bother checking xml tbh, it was just a guess on my part since the original Blizzard code doesn't touch this, while this custom code attempts to touch it and reports a nil error :p)

Xrystal 05-27-18 12:22 AM

The only place I can see is that the fadeOutOfRange flag in the default frame options is set to true for enemy frames and false for friendly frames.

So, if the fading problem is occuring only on friendly frames then perhaps setting frame.optionTable.fadeOutOfRange flag to true on friendly frames ( or all frames to make things easier ) will fix the problem.

It is the only thing I can see that may be messing things up.

Vrul 05-27-18 05:50 AM

Not tested but based on that error you could try:
Code:

--[Change Raid Frame OOR Fade/Alpha Transparency]
hooksecurefunc("CompactUnitFrame_UpdateInRange", function(frame)
    local inRange, checkedRange = UnitInRange(frame.displayedUnit)
    local alpha = checkedRange and not inRange and 0.3 or 1
    frame:SetAlpha(alpha)
    if frame.background then
        frame.background:SetAlpha(alpha)
    end
end)



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

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