Okay. These are all the files I needed to make it work. Remember order in the toc is important with separate files.
TOC File - Remember to change Title/Author/Version/SavedVariables/Notes to suit your addon
Lua Code:
## Interface: 100207
## Title: TestAddonSettings
## Author: Xrystal (c) 2024 All Rights Reserved
## Version: 0.0.1.001
## Notes: Testing Addon Settings
## RequiredDeps:
## OptionalDeps:
## DefaultState: Enabled
## LoadOnDemand: 0
## SavedVariables: TestingAddonSettingsData
## SavedVariablesPerCharacter:
SettingsPanel.lua
MinimapButton.lua
SettingsPanel.lua - Remember to use unique frame names if you need to use frame names.
I have made some notes in here.
This has to be loaded before your MinimapButton tries to reference it.
Lua Code:
local addonName, addon = ...
-- Create a function to add options to the Interface Options Addons panel
local function AddAddonOptions()
-- Create Panel with unique frame name
local panel = CreateFrame("Frame", "ZTVOptionsPanel", UIParent)
-- Give it a more friendly display name
panel.name = "ZamestoTV: Gold"
-- Create a checkbox for QuestCompletionFrame with unique name
local completionCheckBox = CreateFrame("CheckButton", "ZTV_QuestCompletionFrameCheckbox", panel, "InterfaceOptionsCheckButtonTemplate")
completionCheckBox:SetPoint("TOPLEFT", 16, -16)
completionCheckBox.Text:SetText("Enable Quest Completion Frame") -- Replace with your desired default text
completionCheckBox.tooltipText = "Enable the Quest Completion Frame" -- Replace with your desired default tooltip text
-- If QuestCompletionFrame is your own frame I would suggest giving it a unique name like adding ZTV_ infront like I did above
completionCheckBox:SetScript("OnClick", function(self)
local isChecked = self:GetChecked()
-- Handle the checkbox state change here
if isChecked then
-- Checkbox is checked, enable QuestCompletionFrame
QuestCompletionFrame:Show()
else
-- Checkbox is unchecked, disable QuestCompletionFrame
QuestCompletionFrame:Hide()
end
end)
-- Create a checkbox for ZAMTimer777 frame
local timerCheckBox = CreateFrame("CheckButton", "ZAMTimer777Checkbox", panel, "InterfaceOptionsCheckButtonTemplate")
timerCheckBox:SetPoint("TOPLEFT", completionCheckBox, "BOTTOMLEFT", 0, -8)
timerCheckBox.Text:SetText("Enable ZAMTimer777 Frame") -- Replace with your desired default text
timerCheckBox.tooltipText = "Enable the ZAMTimer777 Frame" -- Replace with your desired default tooltip text
timerCheckBox:SetScript("OnClick", function(self)
local isChecked = self:GetChecked()
-- Handle the checkbox state change here
if isChecked then
-- Checkbox is checked, enable ZAMTimer777 frame
ZAMTimer777:Show()
else
-- Checkbox is unchecked, disable ZAMTimer777 frame
ZAMTimer777:Hide()
end
end)
-- Add the panel to the Interface Options Addons category
-- InterfaceOptions_AddCategory(panel) -- this is the old way
-- Use the new way to register this set up as a Canvas Layout ( which gives similar layout control back to the addon creator )
-- Notice I have added this to the addon wide data table to ensure other files have access to this category value.
-- Also notice that I have given the category a link to the addonName. This should be what shows up on the list of addons.
-- You MIGHT be able to use panel.name though
addon.category = Settings.RegisterCanvasLayoutCategory(panel, addonName)
Settings.RegisterAddOnCategory(addon.category)
-- Handle language localization
local locale = GetLocale()
if locale == "deDE" then
-- German localization
completionCheckBox.Text:SetText("Aufgabenliste: Ein-/Ausblenden")
completionCheckBox.tooltipText = "Aufgabenliste: Ein-/Ausblenden"
timerCheckBox.Text:SetText("Timer: Ein-/Ausblenden")
timerCheckBox.tooltipText = "Timer: Ein-/Ausblenden"
panel.name = "ZamestoTV: Gold"
elseif locale == "enUS" then
-- English localization
completionCheckBox.Text:SetText("To Do List: Show/Hide")
completionCheckBox.tooltipText = "To Do List: Show/Hide"
timerCheckBox.Text:SetText("Timer: Show/Hide")
timerCheckBox.tooltipText = "Timer: Show/Hide"
panel.name = "ZamestoTV: Gold"
end
end
-- Register the addon-specific options when the player logs in
local frame = CreateFrame("FRAME")
frame:RegisterEvent("PLAYER_LOGIN")
frame:SetScript("OnEvent", function()
AddAddonOptions()
end)
MinimapButton.lua - Didn't have to change much here - just where the category value was stored and the name of the SavedVariables table which isn't used in your code but needs to be set up and the icon I used on the minimap button.
Lua Code:
local addonName, addon = ...
-- Check if the addon object is already registered
if not LibStub("LibDBIcon-1.0", true):GetMinimapButton(addonName) then
-- Create the minimap icon
local icon = LibStub("LibDBIcon-1.0")
local minimapIcon = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, {
type = "data source",
text = addonName,
icon = "Interface\\BUTTONS\\UI-GroupLoot-Dice-Up", -- Replace with path to your icon
OnClick = function(_, button)
if button == "LeftButton" then
Settings.OpenToCategory(addon.category:GetID()) -- Open or close the options panel
end
end,
OnTooltipShow = function(tooltip)
tooltip:SetText(addonName)
tooltip:AddLine("Click to open options")
tooltip:Show()
end,
})
-- Register the minimap icon
icon:Register(addonName, minimapIcon, TestingAddonSettingsData) -- Replace MyAddonDB with your saved variables table name
end