Quantcast I have a question about setting color for addons - ESOUI
Thread Tools Display Modes
11/06/14, 04:06 PM   #1
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I have a question about setting color for addons

This may seem easy to most but it's one thing I'm actually struggling to understand. I am trying to set the font color of my addon with a function. I'm building a clock with addon menus using LibAddonMenu 2.0. I set my color in defaults. Here is what it looks like.

Lua Code:
  1. local SV
  2. local defaults = {
  3.     ["clock"] = {
  4.         ["offsetx"] = 0,
  5.         ["offsety"] = 0,
  6.         ["point"] = CENTER,
  7.         ["relPoint"] = CENTER,
  8.         ["CLOCK_FONT"] = ZoFontBookScroll,
  9.         ["CLOCK_COLOR"] = {0, 1, 0, 1},
  10.     },
  11. }

Then I call the function which I'm not sure what I need to put here for the LibAddonMenu 2.0.

Lua Code:
  1. local function SetColor(_sColor)
  2.     TicTockclock:SetColor(I'm trying to connect this to my Color Picker in LibAddonMenu 2.0)
  3. end

I try to save the variable. I've been told I'm not calling all 4 arguments. I'm not sure exactly what that means and if someone can really deeply explain I would appreciate this.

Lua Code:
  1. if SV.clock.CLOCK_COLOR ~= {0, 1, 0, 1} then
  2.             TicTockclock:SetColor(SV.clock.CLOCK_COLOR)
  3.         end

Then I will have to call it into the LibAddonMenu 2.0 which from my font I thought I would need to call it like this.

Lua Code:
  1. [4] = {
  2.         type = "colorpicker",
  3.         name = "TicTock Color",
  4.         tooltip = "You can pick the color of your TicTock.",
  5.         getFunc = function() return SV["CLOCK_COLOR"] end--(alpha is optional)
  6.         setFunc = function(r,g,b,a) print(r, g, b, a) end--(alpha is optional)
  7.         width = "half", --or "half" (optional)
  8.     },

Now if you need to see my entire code here is the lua and the xml I think my txt is just fine but I'll put that as well. If someone wants to use my code as a tutorial feel free to do so I don't mind my code being shared on this one, I'm still learning myself and it would be nice to see another great tutorial out there.

lua

Lua Code:
  1. local SV
  2. local defaults = {
  3.     ["clock"] = {
  4.         ["offsetx"] = 0,
  5.         ["offsety"] = 0,
  6.         ["point"] = CENTER,
  7.         ["relPoint"] = CENTER,
  8.         ["CLOCK_FONT"] = ZoFontBookScroll,
  9.         ["CLOCK_COLOR"] = {0, 1, 0, 1},
  10.     },
  11. }
  12.  
  13. --Colors for quick use.
  14. local colorRed          = "|cFF0000"    -- Red
  15. local colorYellow       = "|cFFFF00"    -- yellow
  16. local colorGreen        = "|c00FF00"    -- green
  17. local colorMagenta      = "|cFF00FF"    -- Magenta
  18. local colorDrkOrange    = "|cFFA500"    -- Dark Orange
  19.  
  20. --This is a font tabel so that you can pull the different fonts up within the LibAddonMenu 2.0
  21. local tFontTable = {
  22.     fontList = {
  23.         "Boss Font",
  24.         "Book Paper",
  25.         "Alert",
  26.         "Book Scroll",
  27.     },
  28.     fontName = {
  29.         ["Boss Font"]   = "ZoFontBossName",
  30.         ["Book Paper"]  = "ZoFontBookPaper",
  31.         ["Alert"]       = "ZoFontAlert",
  32.         ["Book Scroll"] = "ZoFontBookScroll",
  33.     },
  34. }
  35.  
  36. --This is the function which sets the font.
  37. local function SetFont(_sFont)
  38.     TicTockclock:SetFont(tFontTable.fontName[_sFont])
  39. end
  40.  
  41. --[[local function SetColor(_sColor)
  42.     TicTockclock:SetColor(I'm trying to connect this to my Color Picker in LibAddonMenu 2.0)
  43. end]]--
  44.  
  45. --This is the LibAddonMenu 2.0 that I'm using for TicTock.
  46. local panelData = {
  47.     type = "panel",
  48.     name = "TicTock Menu",
  49.     displayName = "TicTock Menu",
  50.     author = "Zireko",
  51.     version = "1.0",
  52.     slashCommand = "/tictock",
  53.     registerForRefresh = true,
  54.     registerForDefaults = true,
  55. }
  56.  
  57. local optionsTable = {
  58.     [1] = {
  59.         type = "header",
  60.         name = "Settings",
  61.         width = "full", --or "half" (optional)     
  62.     },
  63.     [2] = {
  64.         type = "description",
  65.         --title = "My Title",   --(optional)
  66.         title = nil,    --(optional)
  67.         text = "Here you can set the type of color,font, or text you like for TicTock",
  68.         width = "full", --or "half" (optional)
  69.     },
  70.     [3] = {
  71.         type = "dropdown",
  72.         name = "Choose Your Font",
  73.         tooltip = "Pick the font for your TicTock.",
  74.         choices = tFontTable.fontList,
  75.         default = "Font 4",
  76.         getFunc = function() return SV["CLOCK_FONT"] end,
  77.         setFunc = function(sValue) SV["CLOCK_FONT"] = sValue
  78.         SetFont(sValue)
  79.         end,   
  80.         width = "half", --or "half" (optional)
  81.     },
  82.     [4] = {
  83.         type = "colorpicker",
  84.         name = "TicTock Color",
  85.         tooltip = "You can pick the color of your TicTock.",
  86.         getFunc = function() return SV["CLOCK_COLOR"] end--(alpha is optional)
  87.         setFunc = function(r,g,b,a) print(r, g, b, a) end--(alpha is optional)
  88.         width = "half", --or "half" (optional)
  89.     },
  90.     [5] = {
  91.         type = "slider",
  92.         name = "Text Size",
  93.         tooltip = "This will pic the size of the text for TicTock",
  94.         min = 0,
  95.         max = 20,
  96.         step = 1,   --(optional)
  97.         getFunc = function() return 3 end,
  98.         setFunc = function(value) d(value) end,
  99.         width = "half", --or "half" (optional)
  100.         default = 5,    --(optional)
  101.     },
  102. }
  103.  
  104. local LAM = LibStub("LibAddonMenu-2.0")
  105. LAM:RegisterAddonPanel("TicTock Menu", panelData)
  106. LAM:RegisterOptionControls("TicTock Menu", optionsTable)
  107.  
  108. --This will be my clock function, I'll play around to see if I can get it to work.
  109. local timeString = ZO_FormatClockTime()
  110.  
  111. local function ClockRockT()
  112.     TicTockclock:SetText(timeString)
  113. end
  114.  
  115.  
  116. --save window position
  117. local function OnMoveStop(self)
  118.     local valid, point, _, relPoint, offsetx, offsety = self:GetAnchor(0)
  119.     if valid then
  120.         SV.clock.point = point
  121.         SV.clock.relPoint = relPoint
  122.         SV.clock.offsetx = offsetx
  123.         SV.clock.offsety = offsety
  124.     end
  125. end
  126.  
  127. local function OnAddOnLoaded(eventCode, addon)
  128.     if addon == "TicTock" then
  129.         EVENT_MANAGER:RegisterForUpdate("ClockCount", 1000, function() TicTockclock:SetText(ZO_FormatClockTime()) end)
  130.         EVENT_MANAGER:UnregisterForEvent("TicTock", EVENT_ADD_ON_LOADED)
  131.  
  132.         SV = ZO_SavedVars:New("Tic_Variables", 2, nil, defaults)
  133.        
  134.         if SV.clock.CLOCK_FONT ~= ZoFontBookScroll then
  135.             TicTockclock:SetFont(SV.clock.CLOCK_FONT)
  136.         end
  137.        
  138.         if SV.clock.CLOCK_COLOR ~= {0, 1, 0, 1} then
  139.             TicTockclock:SetColor(SV.clock.CLOCK_COLOR)
  140.         end
  141.  
  142.         TicTock:SetAnchor(SV.clock.point, nil, SV.clock.relPoint, SV.clock.offsetx, SV.clock.offsety)
  143.  
  144.         TicTock:SetHandler("OnMoveStop", OnMoveStop)
  145.  
  146.         --SLASH_COMMANDS["/qlb"] = function()
  147.             --TicTockBook:ToggleHidden()
  148.         --end
  149.        
  150.  
  151.         ClockRockT()
  152.         --Zoneclock()
  153.     end
  154. end
  155.  
  156. EVENT_MANAGER:RegisterForEvent("TicTock", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
  157. --EVENT_MANAGER:RegisterForEvent("TicTock", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)

xml

Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="TicTock" clampedToScreen="true" mouseEnabled="true" movable="true" resizeToFitDescendents="true">
  4.             <Controls>
  5.                 <Label name="$(parent)clock" font="ZoFontBookScroll" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="CENTER" horizontalAlignment="CENTER">
  6.                     <Anchor point="CENTER" />
  7.                 </Label>
  8.             </Controls>
  9.         </TopLevelControl>
  10.     </Controls>
  11. </GuiXml>

txt

Lua Code:
  1. ## APIVersion: 100010
  2. ## Title: TicTock
  3. ## Version: 1.0
  4. ## Author: Zireko
  5. ## Description: This is a simple clock so you can keep an eye on the time while you're in ESO.
  6. ## OptionalDependsOn: LibAddonMenu-2.0
  7. ## SavedVariables: Tic_Variables
  8.  
  9.  
  10. Libs/LibStub/LibStub.lua
  11.  
  12. Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua
  13.  
  14. Libs/LibAddonMenu-2.0/controls/panel.lua
  15. Libs/LibAddonMenu-2.0/controls/submenu.lua
  16. Libs/LibAddonMenu-2.0/controls/button.lua
  17. Libs/LibAddonMenu-2.0/controls/checkbox.lua
  18. Libs/LibAddonMenu-2.0/controls/colorpicker.lua
  19. Libs/LibAddonMenu-2.0/controls/custom.lua
  20. Libs/LibAddonMenu-2.0/controls/description.lua
  21. Libs/LibAddonMenu-2.0/controls/dropdown.lua
  22. Libs/LibAddonMenu-2.0/controls/editbox.lua
  23. Libs/LibAddonMenu-2.0/controls/header.lua
  24. Libs/LibAddonMenu-2.0/controls/slider.lua
  25. Libs/LibAddonMenu-2.0/controls/texture.lua
  26.  
  27. TicTock.xml
  28. TicTock.lua

Also noticed that my font doesn't save. So if you reload the addon aka reload ui it sets back to the default font. I could use help there as well. As for the last part that I'm working on it the size and I just want to scale that with SetScale on the slider in LibAddonMenu 2.0. All help is welcome and thank you in advanced for all the help. Also please keep in mind I am new to code so please explain in as much detail as you can thank you again.

Last edited by zireko : 11/06/14 at 04:16 PM. Reason: Forgot to add this info at the end.
  Reply With Quote
11/06/14, 05:55 PM   #2
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 648
I sent you a PM with answers about those problems.
  Reply With Quote
11/06/14, 06:25 PM   #3
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
Okies, thank you. I'll look it over and see if I can figure everything out.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » I have a question about setting color for addons

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