Thread Tools Display Modes
04/13/15, 07:10 AM   #1
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Need a little help with adding color to pin text

I could use a little help with adding color to pin texts.
My current uses an outdated system and looks like this:
Lua Code:
  1. pinTag = {zo_strformat(savedVariables.pinTextcolorCodes.questgiverrgb..Name)}
savedVariables.pinTextcolorCodes.questgiverrgb = "|cffaa00"

The new format uses the ZO_ColorDef system, so now I am saving the pin color using this code:
Lua Code:
  1. setFunc = function(r, g, b, a)
  2.     savedVariables.pinTextureQuestsUndone.textcolor = {r, g, b, a}
  3. end,
which saves the pin text color in this format (extracted from SavedVariables):
Code:
                    ["textcolor"] = 
                    {
                        [1] = 0.0431372561,
                        [2] = 0.6000000238,
                        [3] = 0,
                        [4] = 1,
                    },
but how do I implement that in my pin texts? I have tried to look at bot hthe API pages and even snooped in several addons, but none of them seem to give me the solution.

Last edited by SnowmanDK : 04/13/15 at 07:19 AM.
  Reply With Quote
04/13/15, 07:40 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Lua Code:
  1. color = ZO_ColorDef:New("AARRGGBB") -- hex
  2. color = ZO_ColorDef:New("RRGGBB") -- hex
  3. color = ZO_ColorDef:New(r, g, b)
  4. color = ZO_ColorDef:New(r, g, b, a)
  5. color = ZO_ColorDef:New(unpack({r, g, b, a})) -- <--- your table here
  6.  
  7. text = color:Colorize("Text")
You can look at Fisherman lines 624+
I used the string representation, but table should work too.

And line 837 for adding color to string.

Thanks for Destinations!

CU

Edit 1:
^^ This is why Garkin is our Grand Master

Last edited by votan : 04/13/15 at 07:59 AM.
  Reply With Quote
04/13/15, 07:45 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by SnowmanDK View Post
I could use a little help with adding color to pin texts.
My current uses an outdated system and looks like this:
Lua Code:
  1. pinTag = {zo_strformat(savedVariables.pinTextcolorCodes.questgiverrgb..Name)}
savedVariables.pinTextcolorCodes.questgiverrgb = "|cffaa00"

The new format uses the ZO_ColorDef system, so now I am saving the pin color using this code:
Lua Code:
  1. setFunc = function(r, g, b, a)
  2.     savedVariables.pinTextureQuestsUndone.textcolor = {r, g, b, a}
  3. end,
but how do I implement that in my pin texts? I have tried to look at bot hthe API pages and even snooped in several addons, but none of them seem to give me the solution.
Do you want to stick with your current codes ("|cRRGGBB") or do you want to convert colors to tables?

Current color codes:
Lua Code:
  1. --define local references to ZO_ColorDef objects at the start of the file:
  2. local COLOR_QUEST_GIVER
  3.  
  4. --assign actual object in OnAddonLoaded, after you load saved variables:
  5. COLOR_QUEST_GIVER = ZO_ColorDef:New(savedVariables.pinTextcolorCodes.questgiverrgb:gsub("^|c", ""))
  6.  
  7. --Settings menu looks like this:
  8. {
  9.     type = "colorpicker",
  10.     name = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER),
  11.     tooltip = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER_TT),
  12.     getFunc = function() return COLOR_QUEST_GIVER:UnpackRGBA() end,
  13.     setFunc = function(r, g, b, a)
  14.         COLOR_QUEST_GIVER:SetRGBA(r, g, b, a)
  15.         savedVariables.pinTextcolorCodes.questgiverrgb = "|c" .. COLOR_QUEST_GIVER:ToHex()
  16.         LMP:RefreshPins(PINS_QUESTGIVER)
  17.     end,
  18.     default = ZO:ColorDef:New(defaults.pinTextcolorCodes.questgiverrgb:gsub("^|c", "")),
  19. },

Tables:
Lua Code:
  1. --define local references to ZO_ColorDef objects at the start of the file:
  2. local COLOR_QUEST_GIVER
  3.  
  4. --assign actual object in OnAddonLoaded, after you load saved variables:
  5. COLOR_QUEST_GIVER = ZO_ColorDef:New(unpack(savedVariables.pinTextcolorCodes.questgiverrgb))
  6.  
  7. --Settings menu looks like this:
  8. {
  9.     type = "colorpicker",
  10.     name = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER),
  11.     tooltip = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER_TT),
  12.     getFunc = function() return COLOR_QUEST_GIVER:UnpackRGBA() end,
  13.     setFunc = function(r, g, b, a)
  14.         COLOR_QUEST_GIVER:SetRGBA(r, g, b, a)
  15.         savedVariables.pinTextcolorCodes.questgiverrgb = {r, g, b, a}
  16.         LMP:RefreshPins(PINS_QUESTGIVER)
  17.     end,
  18.     default = ZO_ColorDef:New(unpack(defaults.pinTextcolorCodes.questgiverrgb)),
  19. },
  20.  
  21. --and your pinTag:
  22. pinTag = {COLOR_QUEST_GIVER:Colorize(zo_strformat("<<1>>", Name))}
  23. --I have no idea if you need zo_strformat to remove special characters in there, but I have added it just in case.
  Reply With Quote
04/13/15, 11:04 AM   #4
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Those old ("|cRRGGBB") codes are out
I have done the following so far:
For the pins them self (This is already working as it should):
Lua Code:
  1. QuestssubmenuControls:insert({ -- Undone Quest pin color
  2.         type = "colorpicker",
  3.         name = GetString(QUEST_SETTINGS_UNDONE_PIN_COLOR),
  4.         tooltip = GetString(QUEST_SETTINGS_UNDONE_PIN_COLOR_TT),
  5.         getFunc = function() return unpack(savedVariables.pinTextureQuestsUndone.tint) end,
  6.         setFunc = function(r, g, b, a)
  7.             savedVariables.pinTextureQuestsUndone.tint = {r, g, b, a}
  8.             QuestsUndonePreview:SetColor(r, g, b, a)
  9.             LMP:SetLayoutKey(PINS_QUESTS_UNDONE, "tint", ZO_ColorDef:New(r, g, b, a))
  10.             LMP:RefreshPins(PINS_QUESTS_UNDONE)
  11.         end,
  12.         disabled = function() return not savedVariables.filters[PINS_QUESTS_UNDONE] end,
  13.         default = {r = defaults.pinTextureQuestsUndone.tint[1], g = defaults.pinTextureQuestsUndone.tint[2], b = defaults.pinTextureQuestsUndone.tint[3], a = defaults.pinTextureQuestsUndone.tint[4]}
  14.     })
I have done this in settings for pin text:
Lua Code:
  1. QuestssubmenuControls:insert({ -- Undone Quest pin text color
  2.         type = "colorpicker",
  3.         name = GetString(QUEST_SETTINGS_UNDONE_PINTEXT_COLOR),
  4.         tooltip = GetString(QUEST_SETTINGS_UNDONE_PINTEXT_COLOR_TT),
  5.         getFunc = function() return unpack(savedVariables.pinTextureQuestsUndone.textcolor) end,
  6.         setFunc = function(r, g, b, a)
  7.             savedVariables.pinTextureQuestsUndone.textcolor = {r, g, b, a}
  8.             LMP:RefreshPins(PINS_QUESTS_UNDONE)
  9.         end,
  10.         disabled = function() return not savedVariables.filters[PINS_QUESTS_UNDONE] end,
  11.         default = {r = defaults.pinTextureQuestsUndone.textcolor[1], g = defaults.pinTextureQuestsUndone.textcolor[2], b = defaults.pinTextureQuestsUndone.textcolor[3], a = defaults.pinTextureQuestsUndone.textcolor[4]}
  12.     })
but have problems implementing that into my pins.
OLD pin code is this:
Lua Code:
  1. pinTag = {zo_strformat(savedVariables.pinTextcolorCodes.questdonergb..Name)}
  2.             table.insert(pinTag, 2, zo_strformat(savedVariables.pinTextcolorCodes.questdonergb.."["..NPC.."]"))
I tried your pin code:
Lua Code:
  1. pinTag = {savedVariables.pinTextureQuestsUndone.textcolor:Colorize(zo_strformat("<<1>>", Name))}
but it throws a "function expected instead of nil" error.
Originally Posted by Garkin View Post
Do you want to stick with your current codes ("|cRRGGBB") or do you want to convert colors to tables?

Current color codes:
Lua Code:
  1. --define local references to ZO_ColorDef objects at the start of the file:
  2. local COLOR_QUEST_GIVER
  3.  
  4. --assign actual object in OnAddonLoaded, after you load saved variables:
  5. COLOR_QUEST_GIVER = ZO_ColorDef:New(savedVariables.pinTextcolorCodes.questgiverrgb:gsub("^|c", ""))
  6.  
  7. --Settings menu looks like this:
  8. {
  9.     type = "colorpicker",
  10.     name = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER),
  11.     tooltip = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER_TT),
  12.     getFunc = function() return COLOR_QUEST_GIVER:UnpackRGBA() end,
  13.     setFunc = function(r, g, b, a)
  14.         COLOR_QUEST_GIVER:SetRGBA(r, g, b, a)
  15.         savedVariables.pinTextcolorCodes.questgiverrgb = "|c" .. COLOR_QUEST_GIVER:ToHex()
  16.         LMP:RefreshPins(PINS_QUESTGIVER)
  17.     end,
  18.     default = ZO:ColorDef:New(defaults.pinTextcolorCodes.questgiverrgb:gsub("^|c", "")),
  19. },

Tables:
Lua Code:
  1. --define local references to ZO_ColorDef objects at the start of the file:
  2. local COLOR_QUEST_GIVER
  3.  
  4. --assign actual object in OnAddonLoaded, after you load saved variables:
  5. COLOR_QUEST_GIVER = ZO_ColorDef:New(unpack(savedVariables.pinTextcolorCodes.questgiverrgb))
  6.  
  7. --Settings menu looks like this:
  8. {
  9.     type = "colorpicker",
  10.     name = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER),
  11.     tooltip = GetString(PINTEXT_COLOR_SETTINGS_QUESTGIVER_TT),
  12.     getFunc = function() return COLOR_QUEST_GIVER:UnpackRGBA() end,
  13.     setFunc = function(r, g, b, a)
  14.         COLOR_QUEST_GIVER:SetRGBA(r, g, b, a)
  15.         savedVariables.pinTextcolorCodes.questgiverrgb = {r, g, b, a}
  16.         LMP:RefreshPins(PINS_QUESTGIVER)
  17.     end,
  18.     default = ZO_ColorDef:New(unpack(defaults.pinTextcolorCodes.questgiverrgb)),
  19. },
  20.  
  21. --and your pinTag:
  22. pinTag = {COLOR_QUEST_GIVER:Colorize(zo_strformat("<<1>>", Name))}
  23. --I have no idea if you need zo_strformat to remove special characters in there, but I have added it just in case.
  Reply With Quote
04/13/15, 11:12 AM   #5
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Well I ended up experimenting with a mix of yours and Garkin's solutions and finally came up with something that works
OLD code:
Lua Code:
  1. pinTag = {zo_strformat(savedVariables.pinTextcolorCodes.questgiverrgb..Name)}
NEW code:
Lua Code:
  1. pinTag = {ZO_ColorDef:New(unpack(savedVariables.pinTextureQuestsUndone.textcolor)):Colorize(zo_strformat("<<1>>", Name))}
Thanks to both of you for inspiration and guidance
Originally Posted by votan View Post
Lua Code:
  1. color = ZO_ColorDef:New("AARRGGBB") -- hex
  2. color = ZO_ColorDef:New("RRGGBB") -- hex
  3. color = ZO_ColorDef:New(r, g, b)
  4. color = ZO_ColorDef:New(r, g, b, a)
  5. color = ZO_ColorDef:New(unpack({r, g, b, a})) -- <--- your table here
  6.  
  7. text = color:Colorize("Text")
You can look at Fisherman lines 624+
I used the string representation, but table should work too.

And line 837 for adding color to string.

Thanks for Destinations!

CU

Edit 1:
^^ This is why Garkin is our Grand Master

Last edited by SnowmanDK : 04/13/15 at 11:16 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Need a little help with adding color to pin text


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