Thread Tools Display Modes
05-26-18, 10:43 AM   #1
Xancepants
A Deviate Faerie Dragon
Join Date: Oct 2014
Posts: 17
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!

Last edited by Xancepants : 05-26-18 at 10:50 AM. Reason: Added Error Log
  Reply With Quote
05-26-18, 12:19 PM   #2
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
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)
  Reply With Quote
05-26-18, 06:45 PM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
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>
__________________
  Reply With Quote
05-26-18, 09:26 PM   #4
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
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 )
  Reply With Quote
05-27-18, 12:22 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
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.
__________________
  Reply With Quote
05-27-18, 05:50 AM   #6
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
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)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Increase OOR Alpha/Fade Transparency for Raid Frames?

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