Loading...

Desaturate Action Bars Icons

1
Hi, I hope this is the right place to post this
My issue is that I'm trying to make my action bars icons desaturate when a spell is on cooldown
I've used this code from a post I've found on reddit and it works fine on the default UI but doesn't on ElvUI:

Code: Select all

local frame = CreateFrame("Frame")
frame.timer = 0;

function greyOut(button)
	local name = button:GetName();
	local action = button.action;
	local Icon = _G[name.."Icon"];
	local start, duration, _ = GetActionCooldown(action);

	if ( duration >= 1.5 ) then
	    Icon:SetDesaturated(true);
	else
		Icon:SetDesaturated(false);
	end;
end;

function onUpdate(self, elapsed)
  	self.timer = self.timer + elapsed; -- throtteling

	if self.timer >= 0.1 then
		for i=1, 12 do
			local button = _G["ActionButton"..i];
			greyOut(button);

			button = _G["MultiBarBottomLeftButton"..i];
			greyOut(button);

			button = _G["MultiBarBottomRightButton"..i];
			greyOut(button);

			button = _G["MultiBarRightButton"..i];
			greyOut(button);

			button = _G["MultiBarLeftButton"..i];
			greyOut(button);

			last = 0;
		end
	end
end;

frame:HookScript("OnUpdate", onUpdate);
I've tried to change the action bar names to ElvUI's ("ElvUI_Bar1Button" etc) but it doesn't work either
When I create a weakaura to desaturate a single button when the action is on cooldown it works, but it would be tedious to do WAs for each button, each class & spec :/
Could I get some help to make this work for ElvUI, if possible, please?
Thank you!

Desaturate Action Bars Icons

2
This is what I do to grab the buttons:

Code: Select all

-- actionbars
for i = 1, 6 do
	for k = 1, 12 do
		local buttonBars = {_G['ElvUI_Bar'..i..'Button'..k]}
		for _, button in pairs(buttonBars) do
			-- do stuff, in your case: greyOut(button);
		end
	end
end

-- pet bar
for i = 1, NUM_PET_ACTION_SLOTS do
	local petButtons = {_G['PetActionButton'..i]}
	for _, button in pairs(petButtons) do
		-- do stuff, in your case: greyOut(button);
	end
end
[mention]Serenlulz[/mention] I also moved your topic from ElvUI Technical Support. Fits better here :)
Everything I do is guareanteed 100% miskrake free

Desaturate Action Bars Icons

3
Hello again and thank you for your help!
So I tried to use your code to grab the action bars like this:

Code: Select all

local frame = CreateFrame("Frame")
frame.timer = 0;

function greyOut(button)
	local name = button:GetName();
	local action = button.action;
	local Icon = _G[name.."Icon"];
	local start, duration, _ = GetActionCooldown(action);

	if ( duration >= 1.5 ) then
	    Icon:SetDesaturated(true);
	else
		Icon:SetDesaturated(false);
	end;
end;

function onUpdate(self, elapsed)
  	self.timer = self.timer + elapsed; -- throtteling

	if self.timer >= 0.1 then
		-- actionbars
for i = 1, 6 do
	for k = 1, 12 do
		local buttonBars = {_G['ElvUI_Bar'..i..'Button'..k]}
		for _, button in pairs(buttonBars) do
			greyOut(button);
		end
	end
end

-- pet bar
for i = 1, NUM_PET_ACTION_SLOTS do
	local petButtons = {_G['PetActionButton'..i]}
	for _, button in pairs(petButtons) do
		greyOut(button);
	    end
    end
end
end;

frame:HookScript("OnUpdate", onUpdate);
but now I get this LUA error:

Code: Select all

8365x iGreyOut\core.lua:8: Usage: GetActionCooldown(slot)
[C]: in function `GetActionCooldown'
iGreyOut\core.lua:8: in function `greyOut'
iGreyOut\core.lua:23: in function <iGreyOut\core.lua:17>

Locals:
(*temporary) = nil
What did I do wrong? >.<

Desaturate Action Bars Icons

5
I would strongly recommend against using an OnUpdate script to handle this, as it executes excessively.

I also realize that there is probably no other way to do this right now, so I am adding a callback that can be used instead. Hang tight.

Desaturate Action Bars Icons

6
Okay I have now added the callback to our LibActionButton library instance, which allows us to register for that callback event and react to it. This is the code I came up with:

Code: Select all

local E unpack(ElvUI)
local AB = E:GetModule("ActionBars")
local LAB = LibStub("LibActionButton-1.0-ElvUI")
local GetTime = GetTime

--This brings back the colors
local function UpdateIcon(button)
	button.icon:SetDesaturated(false)
	button.nextUpdate = nil
end

--This function desaturates the icon and calculates when it should bring back color
--It then asks ElvUI to call our UpdateIcon function when that time has passed 
local function OnCooldownUpdate(event, button, start, duration)
	local cdLeft = start + duration - GetTime()

	--Only update if we are not already tracking this one
	if not button.nextUpdate and cdLeft > 1.5 then
		button.icon:SetDesaturated(true)

		--Calculate next update we need
		button.nextUpdate = duration - 1.5
		E:Delay(button.nextUpdate, UpdateIcon, button)
	end
end
LAB.RegisterCallback(AB, "OnCooldownUpdate", OnCooldownUpdate)
In order for the above code to work you either need to install the dev version or wait until next release. You can get the dev version here: https://git.tukui.org/elvui/elvui/repos ... rchive.zip

Desaturate Action Bars Icons

7
Hello and thank you for helping me!
The code you posted above works fine, though sometimes the icon goes back to colored when the spell is still on cooldown :/ (I am using the dev version of ElvUI you linked above)
Also, I would like to know if it's possible to make the icon stay desaturated until the cooldown reaches 0 if the base cooldown is higher than 1.5 sec (unlike now where it goes back to colored when less than 1.5 sec is left on the CD)
Aggain, thank you for your support and happy holidays!

Desaturate Action Bars Icons

8
I coded it like that because your original code had that value in there, haha. Only giving the colors back when it is off the cooldown is much easier yes.
I see why the color comes back, but I need to modify the library further to fix that. I'm not sure when I will have the time for this, but I will post here again when I have something to share.

When I have fixed the issue then this is the code you need (you can still use it now, but color will still re-appear at random):

Code: Select all

local E unpack(ElvUI)
local AB = E:GetModule("ActionBars")
local LAB = LibStub("LibActionButton-1.0-ElvUI")

local function OnCooldownUpdate(event, button, start, duration, enable, modRate)
	if start and duration > 1.5 then
		button.saturationLocked = true
		button.icon:SetDesaturated(true)
	else
		button.icon:SetDesaturated(false)
	end
end
LAB.RegisterCallback(AB, "OnCooldownUpdate", OnCooldownUpdate)
Edit: I updated the code slightly, it should now work with the latest dev version. You still get it here: https://git.tukui.org/elvui/elvui/repos ... rchive.zip
Last edited by Deleted User 52 on Sat Dec 23, 2017 2:27 pm, edited 1 time in total.