WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Initially Black Raid Frames, turn into class color when (buff) is applied. (https://www.wowinterface.com/forums/showthread.php?t=59821)

ahbe 03-11-24 12:46 PM

Initially Black Raid Frames, turn into class color when (buff) is applied.
 
Hey guys!

Trying to find the right logic and events to use for this specific action, I will continue to build onto the addon using the same logic and using colors to navigate through dispells buffs etc on raidframes.

Im not interested in vuhdo or grid thats why im attempting this myself.

Troubleshoot:

The code below turns my raid frames black initially but wont respond and change to class color when I apply power word: shield. Im using chatgpt and scanning the code for mistakes but since as a newbie i just cant find my way around this <3


------------

local frame = CreateFrame("Frame")

frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("UNIT_AURA")

frame:SetScript("OnEvent", function(self, event, unit)
if event == "PLAYER_LOGIN" then

-- Set class colors to black initially for all raid and party members

for _, colorTable in pairs(RAID_CLASS_COLORS) do
colorTable.r, colorTable.g, colorTable.b = 0, 0, 0
colorTable.colorStr = "000000"
end
elseif event == "UNIT_AURA" and (unit == "player" or UnitInParty(unit) or UnitInRaid(unit)) then
local hasPowerWordShield = false

for i = 1, 40 do
local _, _, _, _, _, _, _, _, _, spellID = UnitAura(unit, i, "HELPFUL")
if spellID and spellID == 17 then

-- Replace 17 with the actual spell ID of Power Word: Shield

hasPowerWordShield = true
break
end
end

local _, class = UnitClass(unit)
local colorTable = RAID_CLASS_COLORS[class]

if colorTable then
if hasPowerWordShield then

-- Update the class color when Power Word: Shield is applied

colorTable.r, colorTable.g, colorTable.b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
colorTable.colorStr = RAID_CLASS_COLORS[class].colorStr
else

-- Set class colors to black if Power Word: Shield is not applied

colorTable.r, colorTable.g, colorTable.b = 0, 0, 0
colorTable.colorStr = "000000"
end
end
end
end)

Fizzlemizz 03-11-24 01:41 PM

Both
Lua Code:
  1. for _, colorTable in pairs(RAID_CLASS_COLORS) do
and
Lua Code:
  1. local colorTable = RAID_CLASS_COLORS[class]
are making changes directly into the global RAID_CLASS_COLORS table. That will change the colour for everything else in the UI using RAID_CLASS_COLORS and it will always be black for everything.

All your actions in both PLAYER_LOGIN and UNIT_AURA just keep changing this global table's colours to black again and again....

Lua Code:
  1. colorTable.r, colorTable.g, colorTable.b = 0, 0, 0

is exactly the same as:

Lua Code:
  1. RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b = 0, 0, 0

and
Lua Code:
  1. colorTable.r, colorTable.g, colorTable.b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b

is exactly the same as:

Lua Code:
  1. RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b

You need to work at the point you want to set the colour of a texture and decide what you want to do with colouring.
eg:
Lua Code:
  1. local classColor = RAID_CLASS_COLORS[class]
  2. if hasPowerWordShield then
  3.     sometexture:SetVertexColor(classColor.r, classColor.g, classColor.b) -- use default
  4. else
  5.     sometexture:SetVertexColor(0, 0, 0) -- set to black
  6. end

And don't do anything at PLAYER_LOGIN

sirpucna 03-12-24 03:11 AM

i went down a similar path to you to for dark blizz frames, check out a project on curseforge called 'Blizzard Raid Frames - Debuff Highlight By slothpala' to get you started

using the above project as a base, heres my mod i did for dark frames

Code:

local restoreColor = function() end
local function updateRestoreColor()

        restoreColor = function(frame)
                blockColorUpdate[frame] = false
                frame.healthBar:SetStatusBarColor(0.192, 0.2, 0.219)
        end
end

keep in mind hooking "CompactUnitFrame_UpdateHealthColor" is quite expensive CPU wise

you will have to make other changes like converting the background to light color etc

ahbe 03-13-24 07:30 AM

Thank you! I will study a bit more and share my progress.


All times are GMT -6. The time now is 08:16 AM.

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