View Single Post
04-13-24, 06:34 AM   #18
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
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:
  1. ## Interface: 100207
  2. ## Title: TestAddonSettings
  3. ## Author: Xrystal (c) 2024  All Rights Reserved
  4. ## Version: 0.0.1.001
  5. ## Notes: Testing Addon Settings
  6. ## RequiredDeps:
  7. ## OptionalDeps:
  8. ## DefaultState: Enabled
  9. ## LoadOnDemand: 0
  10. ## SavedVariables: TestingAddonSettingsData
  11. ## SavedVariablesPerCharacter:
  12.  
  13. SettingsPanel.lua
  14. 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:
  1. local addonName, addon = ...
  2.  
  3. -- Create a function to add options to the Interface Options Addons panel
  4. local function AddAddonOptions()
  5.    
  6.     -- Create Panel with unique frame name
  7.     local panel = CreateFrame("Frame", "ZTVOptionsPanel", UIParent)
  8.    
  9.     -- Give it a more friendly display name
  10.     panel.name = "ZamestoTV: Gold"
  11.  
  12.     -- Create a checkbox for QuestCompletionFrame with unique name
  13.     local completionCheckBox = CreateFrame("CheckButton", "ZTV_QuestCompletionFrameCheckbox", panel, "InterfaceOptionsCheckButtonTemplate")
  14.     completionCheckBox:SetPoint("TOPLEFT", 16, -16)
  15.     completionCheckBox.Text:SetText("Enable Quest Completion Frame") -- Replace with your desired default text
  16.     completionCheckBox.tooltipText = "Enable the Quest Completion Frame" -- Replace with your desired default tooltip text
  17.  
  18.     -- If QuestCompletionFrame is your own frame I would suggest giving it a unique name like adding ZTV_ infront like I did above
  19.     completionCheckBox:SetScript("OnClick", function(self)
  20.         local isChecked = self:GetChecked()
  21.         -- Handle the checkbox state change here
  22.         if isChecked then
  23.             -- Checkbox is checked, enable QuestCompletionFrame
  24.             QuestCompletionFrame:Show()
  25.         else
  26.             -- Checkbox is unchecked, disable QuestCompletionFrame
  27.             QuestCompletionFrame:Hide()
  28.         end
  29.     end)
  30.  
  31.     -- Create a checkbox for ZAMTimer777 frame
  32.     local timerCheckBox = CreateFrame("CheckButton", "ZAMTimer777Checkbox", panel, "InterfaceOptionsCheckButtonTemplate")
  33.     timerCheckBox:SetPoint("TOPLEFT", completionCheckBox, "BOTTOMLEFT", 0, -8)
  34.     timerCheckBox.Text:SetText("Enable ZAMTimer777 Frame") -- Replace with your desired default text
  35.     timerCheckBox.tooltipText = "Enable the ZAMTimer777 Frame" -- Replace with your desired default tooltip text
  36.  
  37.     timerCheckBox:SetScript("OnClick", function(self)
  38.         local isChecked = self:GetChecked()
  39.         -- Handle the checkbox state change here
  40.         if isChecked then
  41.             -- Checkbox is checked, enable ZAMTimer777 frame
  42.             ZAMTimer777:Show()
  43.         else
  44.             -- Checkbox is unchecked, disable ZAMTimer777 frame
  45.             ZAMTimer777:Hide()
  46.         end
  47.     end)
  48.  
  49.     -- Add the panel to the Interface Options Addons category
  50.     -- InterfaceOptions_AddCategory(panel)  -- this is the old way
  51.    
  52.     -- Use the new way to register this set up as a Canvas Layout ( which gives similar layout control back to the addon creator )
  53.     -- Notice I have added this to the addon wide data table to ensure other files have access to this category value.
  54.     -- Also notice that I have given the category a link to the addonName.  This should be what shows up on the list of addons.
  55.     -- You MIGHT be able to use panel.name though
  56.     addon.category = Settings.RegisterCanvasLayoutCategory(panel, addonName)
  57.     Settings.RegisterAddOnCategory(addon.category)
  58.  
  59.     -- Handle language localization
  60.     local locale = GetLocale()
  61.     if locale == "deDE" then
  62.         -- German localization
  63.         completionCheckBox.Text:SetText("Aufgabenliste: Ein-/Ausblenden")
  64.         completionCheckBox.tooltipText = "Aufgabenliste: Ein-/Ausblenden"
  65.         timerCheckBox.Text:SetText("Timer: Ein-/Ausblenden")
  66.         timerCheckBox.tooltipText = "Timer: Ein-/Ausblenden"
  67.         panel.name = "ZamestoTV: Gold"
  68.     elseif locale == "enUS" then
  69.         -- English localization
  70.         completionCheckBox.Text:SetText("To Do List: Show/Hide")
  71.         completionCheckBox.tooltipText = "To Do List: Show/Hide"
  72.         timerCheckBox.Text:SetText("Timer: Show/Hide")
  73.         timerCheckBox.tooltipText = "Timer: Show/Hide"
  74.         panel.name = "ZamestoTV: Gold"
  75.     end
  76. end
  77.  
  78. -- Register the addon-specific options when the player logs in
  79. local frame = CreateFrame("FRAME")
  80. frame:RegisterEvent("PLAYER_LOGIN")
  81. frame:SetScript("OnEvent", function()
  82.     AddAddonOptions()
  83. 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:
  1. local addonName, addon = ...
  2.  
  3. -- Check if the addon object is already registered
  4. if not LibStub("LibDBIcon-1.0", true):GetMinimapButton(addonName) then
  5.     -- Create the minimap icon
  6.     local icon = LibStub("LibDBIcon-1.0")
  7.     local minimapIcon = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, {
  8.         type = "data source",
  9.         text = addonName,
  10.         icon = "Interface\\BUTTONS\\UI-GroupLoot-Dice-Up", -- Replace with path to your icon
  11.         OnClick = function(_, button)
  12.             if button == "LeftButton" then
  13.                 Settings.OpenToCategory(addon.category:GetID()) -- Open or close the options panel
  14.             end
  15.         end,
  16.         OnTooltipShow = function(tooltip)
  17.             tooltip:SetText(addonName)
  18.             tooltip:AddLine("Click to open options")
  19.             tooltip:Show()
  20.         end,
  21.     })
  22.  
  23.     -- Register the minimap icon
  24.     icon:Register(addonName, minimapIcon, TestingAddonSettingsData) -- Replace MyAddonDB with your saved variables table name
  25. end
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote