Thread Tools Display Modes
12-16-13, 10:08 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Need help - color wheel with wowace

Hi everyone, I have been working on trying to make in-game options for my UI and its all going well. I have never used wowace before this but I am having great difficulty with color wheels. I keep leaving it and coming back to it but I honestly do not know where to start. I have looked at other addons using "type = "color", but they all use very different methods, always with 2 functions for getting and setting the colors.

I was hoping someone may know how to set this up or guide me in the right direction. I have a table of class colors in my "MayronUI.db.profile.ClassColors" table and want to get each color for the options below. This is all in the Core.lua file and is on GitHub if you want to look at it:

https://github.com/Mayron/MayronUI

I am not sure which part you need to look at so I provided the link but if I can help anymore then let me know.

Thank you!

EDIT: I am referring to the code below:

Core.lua - lines 93-106:
Lua Code:
  1. ClassColors = {
  2.     CustomColor = {0.1, 0.1, 0.1},
  3.     DeathKnight = {0.77, 0.12, 0.23},
  4.     Druid = {1.00, 0.49, 0.04},
  5.     Hunter = {0.67, 0.83, 0.45},
  6.     Mage = {0.41, 0.80, 0.94},
  7.     Monk = {0, 1, 0.59},
  8.     Paladin = {0.96, 0.55, 0.73},
  9.     Priest = {1.00, 1.00, 1.00},
  10.     Rogue = {1.00, 0.96, 0.41},
  11.     Shaman = {0.0, 0.44, 0.87},
  12.     Wrlock = {0.58, 0.51, 0.79},
  13.     Warrior = {0.78, 0.61, 0.43},
  14. },

Core.lua - lines 547-633 which contains options to use the color wheel to alter the class colors for the specified class type. I hope that all makes sense.

Example:
Lua Code:
  1. Druid = {
  2.     order = 6,
  3.     type = "color",
  4.     name = "Druid",
  5.     get = GetColor, -- Need a function for this to link it with ClassColors table for the Druid class.
  6.     set = SetColor, -- Need a function for this to link it with ClassColors table for the Druid class.
  7.     arg = "Druid",
  8. },


EDIT: Also the variables mentioned in Core.lua are set-up in BottomUI.lua which could be problematic but so far no bugs have shown up which is odd. But that is a story for another day hehe

Last edited by Mayron : 12-16-13 at 12:06 PM.
  Reply With Quote
12-16-13, 12:07 PM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
One way you could easily do this is to just add support for Class Colors by Phanx. oUF has a very nice example on how to implement it. I don't see why you wouldn't do that, as a lot of other AddOns have also included support for it.

Otherwise, just implement eleven entries along the lines of:

lua Code:
  1. DEATHKNIGHT = {
  2.         type = "color",
  3.         order = 1,
  4.         name = L["Deathknight"],
  5.         get = function(info)
  6.             local t = db.colours.DEATHKNIGHT
  7.             return t.r, t.g, t.b
  8.         end,
  9.         set = function(info, r, g, b)
  10.             local t = db.colours.DEATHKNIGHT
  11.             t.r, t.g, t.b = r, g, b
  12.             MUI:UpdateAllStatusbars()
  13.         end,
  14.     },
  15.     MAGE = {
  16.         type = "color",
  17.         order = 2,
  18.         name = L["Mage"],
  19.         get = function(info)
  20.             local t = db.colours.MAGE
  21.             return t.r, t.g, t.b
  22.         end,
  23.         set = function(info, r, g, b)
  24.             local t = db.colours.MAGE
  25.             t.r, t.g, t.b = r, g, b
  26.             MUI:UpdateAllStatusbars()
  27.         end,
  28.     },

You could also iterate over RAID_CLASS_COLORS to add colouring options dynamicly.

I found a snippet you might find interesting here: http://www.wowace.com/addons/ace3/pa...lback-handling

Last edited by ravagernl : 12-16-13 at 12:23 PM.
  Reply With Quote
12-16-13, 02:57 PM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you for the reply. The code you entered did not work unfortunately but while trying to get it to work I will look into the links you provided so thanks.

I changed my DeathKnight table to:
Lua Code:
  1. DeathKnight = {
  2.     order = 5,
  3.     type = "color",
  4.     name = "Death Knight",
  5.     desc = "Alters the panel colors for the Death Knight class.",
  6.     get = function(info)
  7.         local t = MayronUI.db.profile.ClassColors.DeathKnight
  8.         return t.r, t.g, t.b
  9.     end,
  10.     set = function(info, r, g, b)
  11.         local t = MayronUI.db.profile.ClassColors.DeathKnight
  12.         t.r, t.g, t.b = r, g, b
  13.         --MUI:UpdateAllStatusbars()
  14.     end,
  15. },

But when I try this in-game it does not get the color values as it shows a black box and has no effect.
I know the set box will not work as I commented out the placeholder but I want the get function to work before I proceed. The set part is the easiest.
  Reply With Quote
12-16-13, 03:04 PM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Ok I got it to work:

I had to change each value in the table to:
DeathKnight = {r = 0.77, g = 0.12, b = 0.23},
rather than:
DeathKnight = {0.77, 0.12, 0.23},

I assumed it would get each value without having to label them. Silly me :P
  Reply With Quote
12-16-13, 04:49 PM   #5
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Never mind, figured it out

Last edited by Mayron : 12-16-13 at 04:57 PM.
  Reply With Quote
12-16-13, 06:03 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ravagernl View Post
One way you could easily do this is to just add support for Class Colors by Phanx. oUF has a very nice example on how to implement it. I don't see why you wouldn't do that, as a lot of other AddOns have also included support for it.
oUF is not a good example, as it may fail on non-NTFS filesystems where addons are not loaded alphabetically, or where someone is using a third-party implementation of the CUSTOM_CLASS_COLORS standard (I know at least one UI creator wrote their own implementation). You should just do what it says in the ClassColors documentation.

But yes, you should just support CUSTOM_CLASS_COLORS instead of writing your own. Otherwise if users want to change, for example, the dark blue shaman color to the old teal color while using your UI, they have to change it twice (or more) -- once for your custom UI, and once in ClassColors, or more times in every individual addon if they aren't using ClassColors. That was the whole reason I wrote it -- so you can just change the colors once, and they are applied everywhere. You can either just bundle ClassColors itself, or write your own implementation of the standard; I'd suggest just bundling the existing addon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-16-13, 07:16 PM   #7
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Phanx View Post
But yes, you should just support CUSTOM_CLASS_COLORS instead of writing your own. Otherwise if users want to change, for example, the dark blue shaman color to the old teal color while using your UI, they have to change it twice (or more) -- once for your custom UI, and once in ClassColors, or more times in every individual addon if they aren't using ClassColors. That was the whole reason I wrote it -- so you can just change the colors once, and they are applied everywhere. You can either just bundle ClassColors itself, or write your own implementation of the standard; I'd suggest just bundling the existing addon.
You make a very good point. I will try to figure out how to use it then. Thank you for your work
I did notice that with how I have it setup by writing my own, it does not change other addons, only mine. I assume if other addons use your class color code then it should change there's as well? That would be nice.
  Reply With Quote
12-16-13, 09:01 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yep. It does two things:

(1) Creates a "copy" of the RAID_CLASS_COLORS table named CUSTOM_CLASS_COLORS that has the same structure of subtables and values, so for basic usage, the only change addons need to make is replacing RAID_CLASS_COLORS[class] with (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class] in their code.

(2) Fires callbacks to notify addons when a class color has been changed, so addons can update class-colored objects right away (instead of only picking up on the change the next time the UI is loaded) and can update any internal color caches they use.

If you want to have class color options in your own options area, in addition to or instead of the regular Class Colors options panel, you can leave the class color bits in your options table, but change the values in CUSTOM_CLASS_COLORS instead of MayronUI.db.profile.ClassColors, and tweak your getter and setter functions to work with the different table structure { r = R, g = G, b = Z, colorStr = ffRRGGBB } instead of { R, G, B }. (Also if you do this, you need to either include the ClassColors addon in your download package, or write your own implemenation of the CUSTOM_CLASS_COLORS table and callbacks; see ClassColors.lua for an example.)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-17-13, 08:46 AM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Also, I hope your example code that lists the default colours you want to use is a local table. Naming a global table "Death Knight", "Mage", etc, is a TERRIBLE idea that is guaranteed to fail.
  Reply With Quote
12-17-13, 09:20 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
Also, I hope your example code that lists the default colours you want to use is a local table. Naming a global table "Death Knight", "Mage", etc, is a TERRIBLE idea that is guaranteed to fail.
What? Nothing (s)he posted has been a local or a global table... they are obviously keys in a larger (defaults or AceOptions) table whose values are also tables. Note the commas after the closing } brackets.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-18-13, 08:13 AM   #11
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Phanx View Post
What? Nothing (s)he posted has been a local or a global table... they are obviously keys in a larger (defaults or AceOptions) table whose values are also tables. Note the commas after the closing } brackets.
I figure as much, but just wanted to make sure!
  Reply With Quote
12-18-13, 10:38 AM   #12
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Phanx View Post
oUF is not a good example, as it may fail on non-NTFS filesystems where addons are not loaded alphabetically, or where someone is using a third-party implementation of the CUSTOM_CLASS_COLORS standard (I know at least one UI creator wrote their own implementation). You should just do what it says in the ClassColors documentation.
oUF will reinitialize the oUF.colors.class table after the CUSTOM_CLASS_COLORS global is defined (lines 39 - 52 of colors.lua). This way oUF also doesn't have to add !ClassColors to OptDeps(if you were to add AddonLoader support you'd destroy LOD functionality of !ClassColors).

So I don't see how non-NTFS filesystems cause issues if oUF is loaded before Class Colors

Last edited by ravagernl : 12-18-13 at 10:43 AM.
  Reply With Quote
12-18-13, 03:49 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ravagernl View Post
oUF will reinitialize the oUF.colors.class table after the CUSTOM_CLASS_COLORS global is defined (lines 39 - 52 of colors.lua). This way oUF also doesn't have to add !ClassColors to OptDeps(if you were to add AddonLoader support you'd destroy LOD functionality of !ClassColors).
That's new, but it should really just register for PLAYER_LOGIN like it says in the API documentation, as !ClassColors is not (and will never be) LOD for exactly that reason.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-19-13, 05:15 AM   #14
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Been travelling so could not reply but thank you phanx for the explanation and more. That sounds like the optimal choice. I will definitely add this especially as it seems easy to do which is always a big plus for me hehe. Thank you as well for developing this great developer addOn
  Reply With Quote
12-21-13, 04:00 PM   #15
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Phanx View Post
and tweak your getter and setter functions to work with the different table structure { r = R, g = G, b = Z, colorStr = ffRRGGBB } instead of { R, G, B }. (Also if you do this, you need to either include the ClassColors addon in your download package, or write your own implemenation of the CUSTOM_CLASS_COLORS table and callbacks; see ClassColors.lua for an example.)
I will simply just place the !ClassColors in the addOns folder as writing my own is far too much for me to handle since I'm new to using wowace and that is far beyond me. I just got time to work on trying to implement this but I must be doing a lot wrong and no idea why. I have gone back to using the original get and set functions as I need to continue with the rest of the GUI that I am writing. I got confused when trying to add "{ r = R, g = G, b = Z, colorStr = ffRRGGBB }" to it which shows how bad I am with this. The set and get functions currently look like this:

Lua Code:
  1. local function GetColor(info, arg)
  2.     local t = CUSTOM_CLASS_COLORS[info.arg]
  3.     return t.r, t.g, t.b
  4. end
  5. local function SetColor(info, r, g, b, arg)
  6.     local t = CUSTOM_CLASS_COLORS[info.arg]
  7.     t.r, t.g, t.b = r, g, b
  8.     mui_SetClass_BottomUI()
  9.     mui_SetClass_ChatBox()
  10.     mui_SetClass_SideBars()
  11.     mui_SetClass_Map()
  12. end

Which I know is completely wrong as I need to switch around a lot :/
  Reply With Quote
12-21-13, 09:52 PM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That looks fine, except you also need to set the hex color:

Code:
local function SetColor(info, r, g, b, arg)
    local t = CUSTOM_CLASS_COLORS[info.arg]
    t.r, t.g, t.b = r, g, b
    t.colorStr = format("ff%02x%02x%02x", r * 255, g * 255, b * 255)
Also, I've realized there's currently no way for changes made by an addon to propigate to other addons, so I'm adding a new method for this. As soon as it's done, you'll also need to add a call to this method in your set function, after you've set the color:

Code:
local function SetColor(info, r, g, b, arg)
    local t = CUSTOM_CLASS_COLORS[info.arg]
    t.r, t.g, t.b = r, g, b
    t.colorStr = format("ff%02x%02x%02x", r * 255, g * 255, b * 255)
    CUSTOM_CLASS_COLORS:NotifyChanges()
You should also just call NotifyChanges instead of calling any of your own update functions, since you should be registering for a callback from CUSTOM_CLASS_COLORS when a color changes, and calling your update functions then:

Code:
-- Add this anywhere:
function MyAddon:OnColorsChanged()
    -- Update all the class-colored parts of your addon here.
    mui_SetClass_BottomUI()
    mui_SetClass_ChatBox()
    mui_SetClass_SideBars()
    mui_SetClass_Map()
end

-- Add this in your PLAYER_LOGIN handler, or OnEnable function if you're using AceAddon:
CUSTOM_CLASS_COLORS:RegisterCallback(MyAddon, "OnColorsChanged")
Edit:
The NotifyChanges method has been added.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-21-13 at 11:38 PM.
  Reply With Quote
12-22-13, 09:34 AM   #17
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you very much. I had to alter a few things around with my own addOn but then I got it to work.

After adding the CUSTOM_CLASS_COLORS:RegisterCallback(MayronUI, "OnColorsChanged") line I got a new lua message:

Message: Interface\AddOns\!ClassColors\ClassColors.lua:78: Bad argument #1 to :RegisterCallback (string or function expected)

I managed to fix this by arranging the arguments the other way:

CUSTOM_CLASS_COLORS:RegisterCallback("OnColorsChanged", MayronUI)

The issue though that I now face is this does not work:
CUSTOM_CLASS_COLORS:NotifyChanges()

It seems that NotifyChanges just does not register as a correct Method.

EDIT:

I noticed you just updated the ClassColors addon to include this. When you said:

Originally Posted by Phanx
Edit:
The NotifyChanges method has been added.
I thought you meant added to the code you linked me in this thread. Not actually the ClassColors addon. Not sure which one you meant, a little ambiguous haha.
Ah well I shall retry!

Last edited by Mayron : 12-22-13 at 10:22 AM.
  Reply With Quote
12-22-13, 10:20 AM   #18
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
OK so everything works great now!
I love your addOn, such a great idea

It is a shame that other addOns I am using in my UI Pack do not use CUSTOM_CLASS_COLORS. I noticed that many other addons change with the colors wheels like you mentioned which is great. SLDataText and Shadowed Unit Frames do not but I managed to modify SLDataText by just swapping RAID_CLASS_COLORS with CUSTOM_CLASS_COLORS and that works after Reloading the UI. SUF is slightly more difficult so I will leave that.

Thanks again!

EDIT: I was wondering if there is an easy way to hide the ClassColors addOn's GUI which you created as I made one in my configuration menu for my UI and I would rather have it all in one place so user's will not be confused. If not then no worries.

Last edited by Mayron : 12-22-13 at 10:54 AM.
  Reply With Quote
12-23-13, 01:21 AM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Not tested, but something like this probably works to remove an options panel:

Code:
local panelName = GetAddOnMetadata("!ClassColors", "Title")
local categories = INTERFACEOPTIONS_ADDONCATEGORIES
for i = 1, #categories do
    if categories[i].name == panelName then
        tremove(categories, i)
        break
    end
end
Edit:
For ShadowedUF, you should be able to get it to work with something like this:
Code:
for class, color in pairs(CUSTOM_CLASS_COLORS) do
	local t = ShadowUF.db.profile.classColors[class]
	t.r, t.g, t.b = color.r, color.g, color.b
	ShadowUF.Layout:Reload()
end
You'd need to run that in your OnEnable to set the right colors on load, and in your OnColorsChanged to update them when colors are changed.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-23-13 at 01:27 AM.
  Reply With Quote
12-23-13, 07:05 AM   #20
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you! The SUF code works. Very happy about that

I added it to the GetColor function which seems to be a bad idea as it causes the color wheel to respond very slowly when altering the colors due to having to run the for loop over and over again. Not sure where else to place it though.

EDIT: I placed the code for the SUF color alterations in the PLAYER_LOGIN event to solve that issue but of course requires a reload but that is fine. And the code to remove the GUI for !ClassColors also works perfectly. Thank you very much

Last edited by Mayron : 12-23-13 at 07:44 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help - color wheel with wowace

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