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:
local SV local defaults = { ["clock"] = { ["offsetx"] = 0, ["offsety"] = 0, ["point"] = CENTER, ["relPoint"] = CENTER, ["CLOCK_FONT"] = ZoFontBookScroll, ["CLOCK_COLOR"] = {0, 1, 0, 1}, }, }
Then I call the function which I'm not sure what I need to put here for the LibAddonMenu 2.0.
Lua Code:
local function SetColor(_sColor) TicTockclock:SetColor(I'm trying to connect this to my Color Picker in LibAddonMenu 2.0) 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:
if SV.clock.CLOCK_COLOR ~= {0, 1, 0, 1} then TicTockclock:SetColor(SV.clock.CLOCK_COLOR) 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:
[4] = { type = "colorpicker", name = "TicTock Color", tooltip = "You can pick the color of your TicTock.", getFunc = function() return SV["CLOCK_COLOR"] end, --(alpha is optional) setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional) width = "half", --or "half" (optional) },
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:
local SV local defaults = { ["clock"] = { ["offsetx"] = 0, ["offsety"] = 0, ["point"] = CENTER, ["relPoint"] = CENTER, ["CLOCK_FONT"] = ZoFontBookScroll, ["CLOCK_COLOR"] = {0, 1, 0, 1}, }, } --Colors for quick use. local colorRed = "|cFF0000" -- Red local colorYellow = "|cFFFF00" -- yellow local colorGreen = "|c00FF00" -- green local colorMagenta = "|cFF00FF" -- Magenta local colorDrkOrange = "|cFFA500" -- Dark Orange --This is a font tabel so that you can pull the different fonts up within the LibAddonMenu 2.0 local tFontTable = { fontList = { "Boss Font", "Book Paper", "Alert", "Book Scroll", }, fontName = { ["Boss Font"] = "ZoFontBossName", ["Book Paper"] = "ZoFontBookPaper", ["Alert"] = "ZoFontAlert", ["Book Scroll"] = "ZoFontBookScroll", }, } --This is the function which sets the font. local function SetFont(_sFont) TicTockclock:SetFont(tFontTable.fontName[_sFont]) end --[[local function SetColor(_sColor) TicTockclock:SetColor(I'm trying to connect this to my Color Picker in LibAddonMenu 2.0) end]]-- --This is the LibAddonMenu 2.0 that I'm using for TicTock. local panelData = { type = "panel", name = "TicTock Menu", displayName = "TicTock Menu", author = "Zireko", version = "1.0", slashCommand = "/tictock", registerForRefresh = true, registerForDefaults = true, } local optionsTable = { [1] = { type = "header", name = "Settings", width = "full", --or "half" (optional) }, [2] = { type = "description", --title = "My Title", --(optional) title = nil, --(optional) text = "Here you can set the type of color,font, or text you like for TicTock", width = "full", --or "half" (optional) }, [3] = { type = "dropdown", name = "Choose Your Font", tooltip = "Pick the font for your TicTock.", choices = tFontTable.fontList, default = "Font 4", getFunc = function() return SV["CLOCK_FONT"] end, setFunc = function(sValue) SV["CLOCK_FONT"] = sValue SetFont(sValue) end, width = "half", --or "half" (optional) }, [4] = { type = "colorpicker", name = "TicTock Color", tooltip = "You can pick the color of your TicTock.", getFunc = function() return SV["CLOCK_COLOR"] end, --(alpha is optional) setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional) width = "half", --or "half" (optional) }, [5] = { type = "slider", name = "Text Size", tooltip = "This will pic the size of the text for TicTock", min = 0, max = 20, step = 1, --(optional) getFunc = function() return 3 end, setFunc = function(value) d(value) end, width = "half", --or "half" (optional) default = 5, --(optional) }, } local LAM = LibStub("LibAddonMenu-2.0") LAM:RegisterAddonPanel("TicTock Menu", panelData) LAM:RegisterOptionControls("TicTock Menu", optionsTable) --This will be my clock function, I'll play around to see if I can get it to work. local timeString = ZO_FormatClockTime() local function ClockRockT() TicTockclock:SetText(timeString) end --save window position local function OnMoveStop(self) local valid, point, _, relPoint, offsetx, offsety = self:GetAnchor(0) if valid then SV.clock.point = point SV.clock.relPoint = relPoint SV.clock.offsetx = offsetx SV.clock.offsety = offsety end end local function OnAddOnLoaded(eventCode, addon) if addon == "TicTock" then EVENT_MANAGER:RegisterForUpdate("ClockCount", 1000, function() TicTockclock:SetText(ZO_FormatClockTime()) end) EVENT_MANAGER:UnregisterForEvent("TicTock", EVENT_ADD_ON_LOADED) SV = ZO_SavedVars:New("Tic_Variables", 2, nil, defaults) if SV.clock.CLOCK_FONT ~= ZoFontBookScroll then TicTockclock:SetFont(SV.clock.CLOCK_FONT) end if SV.clock.CLOCK_COLOR ~= {0, 1, 0, 1} then TicTockclock:SetColor(SV.clock.CLOCK_COLOR) end TicTock:SetAnchor(SV.clock.point, nil, SV.clock.relPoint, SV.clock.offsetx, SV.clock.offsety) TicTock:SetHandler("OnMoveStop", OnMoveStop) --SLASH_COMMANDS["/qlb"] = function() --TicTockBook:ToggleHidden() --end ClockRockT() --Zoneclock() end end EVENT_MANAGER:RegisterForEvent("TicTock", EVENT_ADD_ON_LOADED, OnAddOnLoaded) --EVENT_MANAGER:RegisterForEvent("TicTock", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
xml
Lua Code:
<GuiXml> <Controls> <TopLevelControl name="TicTock" clampedToScreen="true" mouseEnabled="true" movable="true" resizeToFitDescendents="true"> <Controls> <Label name="$(parent)clock" font="ZoFontBookScroll" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="CENTER" horizontalAlignment="CENTER"> <Anchor point="CENTER" /> </Label> </Controls> </TopLevelControl> </Controls> </GuiXml>
txt
Lua Code:
## APIVersion: 100010 ## Title: TicTock ## Version: 1.0 ## Author: Zireko ## Description: This is a simple clock so you can keep an eye on the time while you're in ESO. ## OptionalDependsOn: LibAddonMenu-2.0 ## SavedVariables: Tic_Variables Libs/LibStub/LibStub.lua Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua Libs/LibAddonMenu-2.0/controls/panel.lua Libs/LibAddonMenu-2.0/controls/submenu.lua Libs/LibAddonMenu-2.0/controls/button.lua Libs/LibAddonMenu-2.0/controls/checkbox.lua Libs/LibAddonMenu-2.0/controls/colorpicker.lua Libs/LibAddonMenu-2.0/controls/custom.lua Libs/LibAddonMenu-2.0/controls/description.lua Libs/LibAddonMenu-2.0/controls/dropdown.lua Libs/LibAddonMenu-2.0/controls/editbox.lua Libs/LibAddonMenu-2.0/controls/header.lua Libs/LibAddonMenu-2.0/controls/slider.lua Libs/LibAddonMenu-2.0/controls/texture.lua TicTock.xml 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.
|