Quantcast
Setting Colors - ESOUI
Thread Tools Display Modes
11/23/20, 08:16 PM   #1
NyghtStar
Join Date: Nov 2020
Posts: 2
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
  Reply With Quote
11/23/20, 09:51 PM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 658
It's percentages in the lua. Do X/255 if you want to write it out in an easy to read rgb fashion.
  Reply With Quote
11/23/20, 11:13 PM   #3
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
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.
__________________
Admin for TES5Edit, occasional LOOT masterlist contributor, and Wrye Bash contributor. I also maintain special Fallout 3 and Fallout NV versions of Wrye Flash.
  Reply With Quote
11/24/20, 02:27 AM   #4
andy.s
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 24
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

Last edited by andy.s : 11/24/20 at 02:30 AM.
  Reply With Quote
11/24/20, 04:26 AM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,455
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())
__________________
https://www.imperialtradingcompany.eu/ - My Addons - The Vault (Early updates and experimental projects) - My patreon - My blog
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
11/24/20, 05:02 AM   #6
NyghtStar
Join Date: Nov 2020
Posts: 2
thanks everyone - I knew it had to be something simple
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Setting Colors

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