ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Setting Colors (https://www.esoui.com/forums/showthread.php?t=9482)

NyghtStar 11/23/20 08:16 PM

Setting Colors
 
I've just started looking into writing addons and came across an issue that perplexed me and I am hoping one of you can shed some light into the issue.

I simply want to set the color of a status bar to a mint green shade
rgb: 200,255,210 or hex: #c8ffd2

In the XML I Have:
Code:

       
<StatusBar name="$(parent)_StatusBar" layer="0" level="1">
    <Dimensions x="100" y="10" />
    <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="0" offsetY="0"/>
    <Limits min="0" max="100" />
</StatusBar>

If I use:
Code:

       
<StatusBar name="$(parent)_StatusBar" layer="0" level="1" color="c8ffd2" alpha="1">
    <Dimensions x="100" y="10" />
    <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="0" offsetY="0"/>
    <Limits min="0" max="100" />
</StatusBar>

it works just fine. BUT....

in the LUA I want to change the status bar color depending on events.
when I try to set the color back to the mint green, it shows as all white

Code:

Nyght_Status_Window_StatusBar:SetColor(200, 255, 210, 1.0)
I have tried setting it to all red
Code:

Nyght_Status_Window_StatusBar:SetColor(255, 0, 0, 1.0)
and it works, same for all green or all blue

I even set it to yellow with no problem
Code:

Nyght_Status_Window_StatusBar:SetColor(255, 255, 0, 1.0)
From this state though, I change the third value from anything but 0, I get all white, even using just a 1
Code:

Nyght_Status_Window_StatusBar:SetColor(255, 255, 1, 1.0)

I did notice, that if I used a lower alpha value in the XML
Code:

       
<StatusBar name="$(parent)_StatusBar" layer="0" level="1" color="c8ffd2" alpha="0.5">...

That the alpha value of the LUA would only be based off that 0.5
(IE.
Code:

Nyght_Status_Window_StatusBar:SetColor(255, 255, 0, 1.0)
shows yellow half transparent)

Is there something similar I am missing with the color, or why the blue color isn't working as I would expect?

Thanks for any insight to this issue.

Nyght

Rhyono 11/23/20 09:51 PM

It's percentages in the lua. Do X/255 if you want to write it out in an easy to read rgb fashion.

Sharlikran 11/23/20 11:13 PM

I'm not sure how to address your question specifically but just keep in mind that some routines like that don't want numbers they want a table and it has to be keyed and then you unpack it. The keys are r=255, g= 255,b=255a=255. There are no decimals that I am aware of for the alpha but I haven't looked at the source in a while.

andy.s 11/24/20 02:27 AM

ESO "RGB" is between 0 and 1, not 0 and 255:

Code:

-- Convert FFFFFF to 1, 1, 1
function Hex2RGB(hex)
    hex = hex:gsub("#", "")
    return tonumber("0x" .. hex:sub(1, 2)) / 255, tonumber("0x" .. hex:sub(3, 4)) / 255, tonumber("0x" .. hex:sub(5, 6)) / 255
end

-- Convert 1, 1, 1 to FFFFFF
function RGB2Hex(r, g, b)
    return string.format("%.2x%.2x%.2x", zo_round(r * 255), zo_round(g * 255), zo_round(b * 255))
end


sirinsidiator 11/24/20 04:26 AM

For Lua code you should just rely on the ZO_ColorDef class which handles all the tedious stuff:

Lua Code:
  1. -- declare your color once in your initialization code
  2. local MINT_GREEN = ZO_ColorDef:New("c8ffd2")
  3.  
  4. -- assign it to the control whenever you need it
  5. Nyght_Status_Window_StatusBar:SetColor(MINT_GREEN:UnpackRGBA())

NyghtStar 11/24/20 05:02 AM

thanks everyone - I knew it had to be something simple


All times are GMT -6. The time now is 04:40 AM.

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