Thread Tools Display Modes
04-11-24, 05:13 AM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Button on the minimap

Hi all. I created a button on the minimap. But I can’t get it to open another LUA file.

the button itself (triggered by LMB).

Lua Code:
  1. local addonName, addon = ...
  2. local addonName = "MyAddon"
  3. local L = {} -- Localization table (if needed)
  4.  
  5. -- Check if the addon object is already registered
  6. if not LibStub("LibDBIcon-1.0", true):GetMinimapButton(addonName) then
  7.     -- Create the minimap icon
  8.     local icon = LibStub("LibDBIcon-1.0")
  9.     local minimapIcon = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, {
  10.         type = "data source",
  11.         text = addonName,
  12.         icon = "Interface\\AddOns\\TEST_ADDON\\Icons\\goblin", -- Replace with path to your icon
  13.         OnClick = function(_, button)
  14.             if button == "LeftButton" then
  15.                 MyAddonOptionsPanel_Toggle() -- Open or close the options panel
  16.             end
  17.         end,
  18.         OnTooltipShow = function(tooltip)
  19.             tooltip:SetText(addonName)
  20.             tooltip:AddLine("Click to open options")
  21.             tooltip:Show()
  22.         end,
  23.     })
  24.  
  25.     -- Register the minimap icon
  26.     icon:Register(addonName, minimapIcon, MyAddonOptionsPanelDB) -- Replace MyAddonDB with your saved variables table name
  27. end
  28.  
  29. -- Define the function to toggle the options panel
  30. function MyAddonOptionsPanel_Toggle()
  31.     -- Add code to open or close the options panel here
  32.     print("Toggle options panel")
  33. end


The frame that the button should open

Lua Code:
  1. local panel = CreateFrame("Frame", "MyAddonOptionsPanel", InterfaceOptionsFrame)
  Reply With Quote
04-11-24, 06:11 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Your toggle function only displays text in the chat frame - did you check to see if it appeared ?
Lua Code:
  1. function MyAddonOptionsPanel_Toggle()
  2.     -- Add code to open or close the options panel here
  3.     print("Toggle options panel")
  4. end

If that text appeared then it is working, you just need to add your code to manage the opening and closing of the panel.
__________________


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
04-11-24, 07:51 AM   #3
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Originally Posted by Xrystal View Post
Your toggle function only displays text in the chat frame - did you check to see if it appeared ?
Lua Code:
  1. function MyAddonOptionsPanel_Toggle()
  2.     -- Add code to open or close the options panel here
  3.     print("Toggle options panel")
  4. end

If that text appeared then it is working, you just need to add your code to manage the opening and closing of the panel.
Hello. Yes, the inscription "Toggle options panel" appears. How to add? I'm new to writing addons for wow.
  Reply With Quote
04-11-24, 10:37 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
I've personally not used the Wow Options system, but I would try to use the example in the wiki page below. If you were aiming to have a panel inside the wow options screen like several addons have done before .. you might want to see how close you are to the example in there.

https://warcraft.wiki.gg/wiki/Using_...s_Addons_panel

Take note of the known bug mentioned in the small print at the bottom.
__________________


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
04-11-24, 11:50 PM   #5
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113


You gave an example of creating a panel. I was looking for how to open it through the “icon on the minimap”.
  Reply With Quote
04-12-24, 03:09 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Okay.

Which one of these were you hoping to implement ? Each one will involve different set up and calls to show up.

1. Display Panel in pre Dragonflight InterfaceOptionsFrame

Use example in https://warcraft.wiki.gg/wiki/Using_...s_Addons_panel to make sure your panel is correctly set up to work with the Interface Options Addons Panel system. And then use

`InterfaceOptionsFrame_OpenToCategory(panel)` to open the frame when you click your button ( you might have to call it twice for it to work as per the comment in the small print at the bottom. It will have a close button to close it again - no need to toggle.


2. Display your own custom panel on the main screen like any other frame you create.

In this case, make sure your frame has a background/backdrop and any other controls it needs. And then you can use the following function to toggle your panel to show or hide based on its current status when you click your button.

Example Code:
Lua Code:
  1. local function TogglePanel(panel)
  2.     if panel:IsShown() then
  3.        panel:Hide()
  4.    else
  5.       panel:Show()
  6.    end
  7. end function

But you would have to change this
Lua Code:
  1. local panel = CreateFrame("Frame", "MyAddonOptionsPanel", InterfaceOptionsFrame)
  2. -- Rest of your panel creation code

To this
Lua Code:
  1. local panel = CreateFrame("Frame", "MyAddonOptionsPanel",UIParent)
  2. -- Rest of your panel creation code

3. Have your panel show up as part of the Dragonflight SettingsPanel

https://warcraft.wiki.gg/wiki/Patch_10.0.0/API_changes gives you some sort of example on how to set up your frame to be part of the settings panel. But not an example on how to jump to your panel.

There is a similar Settings.OpenToCategory() function which Fizzle points to in https://www.wowinterface.com/forums/...11&postcount=2 but it only goes to the AddOns tab and not a particular AddOns panel.
__________________


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
04-12-24, 04:47 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Just copied the Dragonflight Settings example and tested a button click to open and Fizzles code works. It won't go straight to your addon page, but it will go to the addon page list section.

This was the code I used:
Lua Code:
  1. local addonName, addonNS = ...
  2.  
  3. XSettings_PanelTest_SavedVariables = {}
  4. local function OnSettingChanged(_, setting, value)
  5.     local variable = setting:GetVariable()
  6.     XSettings_PanelTest_SavedVariables[variable] = value
  7. end
  8.  
  9. local category = Settings.RegisterVerticalLayoutCategory("XSettings_PanelTest")
  10.  
  11. do
  12.     local variable = "toggle"
  13.     local name = "Test Checkbox"
  14.     local tooltip = "This is a tooltip for the checkbox."
  15.     local defaultValue = false
  16.  
  17.     local setting = Settings.RegisterAddOnSetting(category, name, variable, type(defaultValue), defaultValue)
  18.     Settings.CreateCheckBox(category, setting, tooltip)
  19.     Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
  20. end
  21.  
  22. do
  23.     local variable = "slider"
  24.     local name = "Test Slider"
  25.     local tooltip = "This is a tooltip for the slider."
  26.     local defaultValue = 180
  27.     local minValue = 90
  28.     local maxValue = 360
  29.     local step = 10
  30.  
  31.     local setting = Settings.RegisterAddOnSetting(category, name, variable, type(defaultValue), defaultValue)
  32.     local options = Settings.CreateSliderOptions(minValue, maxValue, step)
  33.     options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right);
  34.     Settings.CreateSlider(category, setting, options, tooltip)
  35.     Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
  36. end
  37.  
  38. do
  39.     local variable = "selection"
  40.     local defaultValue = 2  -- Corresponds to "Option 2" below.
  41.     local name = "Test Dropdown"
  42.     local tooltip = "This is a tooltip for the dropdown."
  43.  
  44.     local function GetOptions()
  45.         local container = Settings.CreateControlTextContainer()
  46.         container:Add(1, "Option 1")
  47.         container:Add(2, "Option 2")
  48.         container:Add(3, "Option 3")
  49.         return container:GetData()
  50.     end
  51.  
  52.     local setting = Settings.RegisterAddOnSetting(category, name, variable, type(defaultValue), defaultValue)
  53.     Settings.CreateDropDown(category, setting, GetOptions, tooltip)
  54.     Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
  55. end
  56.  
  57. Settings.RegisterAddOnCategory(category)
  58.  
  59.  
  60. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  61. btn:SetPoint("CENTER")
  62. btn:SetSize(100, 40)
  63. btn:SetText("Click me")
  64. btn:SetScript("OnClick", function(self, button, down)
  65.     Settings.OpenToCategory()  
  66.     SettingsPanel.AddOnsTab:Click()
  67. end)
  68. btn:RegisterForClicks("AnyDown", "AnyUp")
__________________


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
04-12-24, 04:47 AM   #8
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
I need the settings menu for my addon to open.
How it works for me now (a menu with game settings opens)

How I want it to work (my addon settings should open)


Here is my final code
Lua Code:
  1. local addonName, addon = ...
  2. local addonName = "MyAddon"
  3. local L = {} -- Localization table (if needed)
  4.  
  5. -- Check if the addon object is already registered
  6. if not LibStub("LibDBIcon-1.0", true):GetMinimapButton(addonName) then
  7.     -- Create the minimap icon
  8.     local icon = LibStub("LibDBIcon-1.0")
  9.     local minimapIcon = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, {
  10.         type = "data source",
  11.         text = addonName,
  12.         icon = "Interface\\AddOns\\ZamestoTV_GoldFarm\\Icons\\goblin", -- Replace with path to your icon
  13.         OnClick = function(_, button)
  14.             if button == "LeftButton" then
  15.                 MyAddonOptionsPanel_Toggle() -- Open or close the options panel
  16.             end
  17.         end,
  18.         OnTooltipShow = function(tooltip)
  19.             tooltip:SetText(addonName)
  20.             tooltip:AddLine("Click to open options")
  21.             tooltip:Show()
  22.         end,
  23.     })
  24.  
  25.     -- Register the minimap icon
  26.     icon:Register(addonName, minimapIcon, MyAddonOptionsPanelDB) -- Replace MyAddonDB with your saved variables table name
  27. end
  28.  
  29. -- Define the function to toggle the options panel
  30. function MyAddonOptionsPanel_Toggle()
  31.     -- Add code to open or close the options panel here
  32.     InterfaceOptionsFrame_OpenToCategory("MyAddonOptionsPanel") -- Open options panel to a specific category
  33.     print("Toggle options panel")
  34. end
  35.  
  36. -- Define the function to toggle the panel visibility
  37. local function TogglePanel(panel)
  38.     if panel:IsShown() then
  39.         panel:Hide()
  40.     else
  41.         panel:Show()
  42.     end
  43. end

Last edited by Hubb777 : 04-12-24 at 07:14 AM.
  Reply With Quote
04-12-24, 07:22 AM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Yes, my last example, 2 lines in the OnClick script will open the settings panel to the addon list page. There doesn't seem to be a way addons can open to their own section of the settings by code. Maybe it is protected and needs the user to select the item in the list.


Where is the code where you set up your settings/options page ?

You might still have stuff missing to make it work.

And how you have done it will determine whether you need to use
Lua Code:
  1. InterfaceOptions_OpenToCategory("AddonName")
or
Lua Code:
  1. Settings.OpenToCategory(category:GetID())

As a reminder:
This link gives you an example on how to use the OLD InterfaceOptionsFrame way of adding a settings page. And includes the example on how to show the page on request.
https://warcraft.wiki.gg/wiki/Using_...s_Addons_panel

This post from 2 years ago talks through a few problems people have had getting it to work. It might help you.
https://www.wowinterface.com/forums/...ad.php?t=57172



Bear in mind that the
Lua Code:
  1. InterfaceOptionsFrame_OpenToCategory("MyAddonOptionsPanel")
line is deprecated in Dragonflight and will be removed eventually.

Instead it is replaced with
Lua Code:
  1. Settings.OpenToCategory()

So, you might want to consider using the new Settings functionality added in Dragonflight. This will save you having to figure it out again later when it stops working when the functionality is removed.

But you have to set up your settings page to work with Blizzards Settings ( my last block of code gives an example of how one of those ways works - Vertical Display - and the link below also includes the Canvas route and that is the closest to the old InterfaceOptions way).

As a reminder:
https://warcraft.wiki.gg/wiki/Patch_...s#Settings_API Gives you an example of how to set that up ( my last code block is a copy of this with a button to click it open added.

You can then use the following to open up the settings frame and show the addon page ( finally managed to get it work with my example with the following in the OnClick function.
Lua Code:
  1. Settings.OpenToCategory(category:GetID())

category is set up when you create your settings panel and connect it to the settings system.


So .. depending on how you have created your panel, will determine which version you use and whether it will work or not.
__________________


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

Last edited by Xrystal : 04-12-24 at 09:04 AM.
  Reply With Quote
04-12-24, 10:02 PM   #10
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Looks like I didn't succeed =(

I added this to the code of the panel that I want to open:
Lua Code:
  1. local category = Settings.RegisterCanvasLayoutCategory(panel, "MyAddonOptionsPanel")
  2.     Settings.RegisterAddOnCategory(category)

I also changed the button code on the minimap
Lua Code:
  1. local addonName, addon = ...
  2. -- Create the minimap icon
  3. local addonName = "MyAddon"
  4. local LDB = LibStub("LibDataBroker-1.1")
  5. local minimapIcon = LibStub("LibDBIcon-1.0")
  6.  
  7. -- Create a data broker object for the addon
  8. local dataBroker = LDB:NewDataObject(addonName, {
  9.     type = "data source",
  10.     icon = "Interface\\AddOns\\ZamestoTV_GoldFarm\\Icons\\goblin", -- Replace with your addon's icon path
  11.     OnClick = function(self, button)
  12.         if button == "LeftButton" then
  13.             local categoryID = MyAddonOptionsPanel:GetID() -- Replace with your addon's options panel ID
  14.             Settings.OpenToCategory(categoryID)
  15.         end
  16.     end,
  17. })
  18.  
  19. -- Register the data broker with the minimap icon
  20. minimapIcon:Register(addonName, dataBroker, {
  21.     hide = false,
  22.     minimapPos = 180, -- Set the position on the minimap (in degrees)
  23. })
  24.  
  25. -- Add a function to set the category ID for opening
  26. function addon:SetOptionsPanelCategory(categoryID)
  27.     MyAddonOptionsPanel:SetID(categoryID)
  28. end

As a result, the button works without changes (using the example with the pictures above)

Last edited by Hubb777 : 04-12-24 at 10:49 PM.
  Reply With Quote
04-13-24, 01:28 AM   #11
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
So is it working as you wanted or not ?

Is it opening to your addon's settings panel ?
Is it showing all the controls you set up for it ?
Is it saving the settings between play sessions ( if you wanted it to do that )
__________________


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
04-13-24, 04:06 AM   #12
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
How I have it now (and how it was before): I click on the “icon on the minimap” and the “game settings” open (see picture below)

How I want: When I click the “icon on the minimap”, the settings of my addon “MyAddonOptionsPanel” open. (see picture below)
  Reply With Quote
04-13-24, 04:19 AM   #13
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Your code must still be missing something which is why I asked to see the code where you create your settings panel. How you create that will determine how you display it.
__________________


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
04-13-24, 04:40 AM   #14
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
I would suggest you try creating a simple addon that just shows a settings panel, using the example code on the wiki.gg page I linked. Once you have seen how that works, you can add your addon's functionality.

It was what I did to figure out how it worked so I could explain it to you.
__________________


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
04-13-24, 05:13 AM   #15
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Originally Posted by Xrystal View Post
Your code must still be missing something which is why I asked to see the code where you create your settings panel. How you create that will determine how you display it.
Sorry. Looks like I didn't see it. Here is the panel code.

Lua Code:
  1. local addonName, addon = ...
  2. -- Create a function to add options to the Interface Options Addons panel
  3. local function AddAddonOptions()
  4.     local panel = CreateFrame("Frame", "MyAddonOptionsPanel", UIParent)
  5.     panel.name = "ZamestoTV: Gold" -- Replace "MyAddon" with your addon's name
  6.  
  7.     -- Create a checkbox for QuestCompletionFrame
  8.     local completionCheckBox = CreateFrame("CheckButton", "QuestCompletionFrameCheckbox", panel, "InterfaceOptionsCheckButtonTemplate")
  9.     completionCheckBox:SetPoint("TOPLEFT", 16, -16)
  10.     completionCheckBox.Text:SetText("Enable Quest Completion Frame") -- Replace with your desired default text
  11.     completionCheckBox.tooltipText = "Enable the Quest Completion Frame" -- Replace with your desired default tooltip text
  12.  
  13.     completionCheckBox:SetScript("OnClick", function(self)
  14.         local isChecked = self:GetChecked()
  15.         -- Handle the checkbox state change here
  16.         if isChecked then
  17.             -- Checkbox is checked, enable QuestCompletionFrame
  18.             QuestCompletionFrame:Show()
  19.         else
  20.             -- Checkbox is unchecked, disable QuestCompletionFrame
  21.             QuestCompletionFrame:Hide()
  22.         end
  23.     end)
  24.  
  25.     -- Create a checkbox for ZAMTimer777 frame
  26.     local timerCheckBox = CreateFrame("CheckButton", "ZAMTimer777Checkbox", panel, "InterfaceOptionsCheckButtonTemplate")
  27.     timerCheckBox:SetPoint("TOPLEFT", completionCheckBox, "BOTTOMLEFT", 0, -8)
  28.     timerCheckBox.Text:SetText("Enable ZAMTimer777 Frame") -- Replace with your desired default text
  29.     timerCheckBox.tooltipText = "Enable the ZAMTimer777 Frame" -- Replace with your desired default tooltip text
  30.  
  31.     timerCheckBox:SetScript("OnClick", function(self)
  32.         local isChecked = self:GetChecked()
  33.         -- Handle the checkbox state change here
  34.         if isChecked then
  35.             -- Checkbox is checked, enable ZAMTimer777 frame
  36.             ZAMTimer777:Show()
  37.         else
  38.             -- Checkbox is unchecked, disable ZAMTimer777 frame
  39.             ZAMTimer777:Hide()
  40.         end
  41.     end)
  42.  
  43.     -- Add the panel to the Interface Options Addons category
  44.     InterfaceOptions_AddCategory(panel)
  45.  
  46.     -- Handle language localization
  47.     local locale = GetLocale()
  48.     if locale == "deDE" then
  49.         -- German localization
  50.         completionCheckBox.Text:SetText("Aufgabenliste: Ein-/Ausblenden")
  51.         completionCheckBox.tooltipText = "Aufgabenliste: Ein-/Ausblenden"
  52.         timerCheckBox.Text:SetText("Timer: Ein-/Ausblenden")
  53.         timerCheckBox.tooltipText = "Timer: Ein-/Ausblenden"
  54.         panel.name = "ZamestoTV: Gold"
  55.     elseif locale == "enUS" then
  56.         -- English localization
  57.         completionCheckBox.Text:SetText("To Do List: Show/Hide")
  58.         completionCheckBox.tooltipText = "To Do List: Show/Hide"
  59.         timerCheckBox.Text:SetText("Timer: Show/Hide")
  60.         timerCheckBox.tooltipText = "Timer: Show/Hide"
  61.         panel.name = "ZamestoTV: Gold"
  62.     end
  63. end
  64.  
  65. -- Register the addon-specific options when the player logs in
  66. local frame = CreateFrame("FRAME")
  67. frame:RegisterEvent("PLAYER_LOGIN")
  68. frame:SetScript("OnEvent", function()
  69.     AddAddonOptions()
  70. end)

I'm new to writing LUA, but I was advised to use ChatGPT (with the help of it I was able to create the panel code and the "icons on the minimap" code)

Last edited by Hubb777 : 04-13-24 at 05:15 AM.
  Reply With Quote
04-13-24, 05:50 AM   #16
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
That's understandable.

ChatGPT may not be wise enough to realise new addons are probably best to use new functions rather than ones that will be gone by the next expansion.

Looking at your code I can see you have mixed and matched the two ways ( new and old ) which explains why it doesn't quite work as you expected.

Let me rig up a version of this panel frame that should work.
__________________


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
04-13-24, 06:12 AM   #17
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
Originally Posted by Xrystal View Post

Let me rig up a version of this panel frame that should work.
It would be fantastic.
  Reply With Quote
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,935
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
04-13-24, 06:38 AM   #19
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Remember the code I attached just has the addon settings panel and the minimap button code. The rest of your addon code will need to be added to the toc file if you use my version of the code as the base of the addon. Or vice versa if you pull in my version of the code to your addon. Remember to remove or comment out the old code the new code is replacing so there isn't any conflict.

Edit:
Also, this was tested on the ptr 10.2.7 so we know this code will work with the next patch.
__________________


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
04-13-24, 07:00 AM   #20
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 113
yes it works. Thank you very much
As I understand it, this part of the code in the “panel” answers: the panel will open through the minimap icon yes/no? Right?
Lua Code:
  1. addon.category = Settings.RegisterCanvasLayoutCategory(panel, addonName)
  2.     Settings.RegisterAddOnCategory(addon.category)
Is this part of the code in the “minimap icon” code?
Lua Code:
  1. OnClick = function(_, button)
  2.             if button == "LeftButton" then
  3.                 Settings.OpenToCategory(addon.category:GetID()) -- Open or close the options panel
  4.             end
  5.         end,
Can I add these parts to my other addon and everything will work there too? Or am I missing something?
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Button on the minimap


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