Well my test addon doesn't save it .. but, testing bugsack and it does. So something in its code must be saving it in some form.
edit: Okay figured it out ..
Files Changed:
TestAddonSettings.toc
File changed to have 2 saved variable tables, one for the addon data and one for the minimap icon data
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: TestAddonSettingsData, TestAddonSettingsData_MinimapIcon
## SavedVariablesPerCharacter:
SettingsPanel.lua
MinimapButton.lua
Code.lua
MinimapButton.lua
-- Redesigned file to match bugsacks segmented approach ( in case that was the solution ). It looks tidier though so kept it
-- Made sure Saved Variable tables were initialised with default values
-- MinimapButton's saved variable data was put in its own table, not a sub table same as bugsack
-- The MinimapButton was also initialised on player login - of course this would be when the saved variables would have been loaded up - this might have been all we needed to do.
Lua Code:
local addonName, addon = ...
-- Main Addon SavedVariable Table
TestAddonSettingsData = TestAddonSettingsData or {}
-- Minimap Icon SavedVariable Table
TestAddonSettingsData_MinimapIcon = TestAddonSettingsData_MinimapIcon or {}
-- Initialise Minimap Icon values
-- Use settings panel to allow player to change these
-- When you move the minimap icon around the minimap the ldb library updates the respective MinimapIcon saved variable table
-- The MinimapIcon Saved Variable Data has to be its own table, not a sub table
TestAddonSettingsData_MinimapIcon.hide = false
TestAddonSettingsData_MinimapIcon.lock = false
TestAddonSettingsData_MinimapIcon.minimapPos = 120
TestAddonSettingsData_MinimapIcon.radius = 80
-- Make sure library exists
local ldb = LibStub:GetLibrary("LibDataBroker-1.1", true)
if not ldb then return end
-- Create Plugin
local plugin = ldb:NewDataObject(addonName, {
type = "data source",
text = addonName,
icon = "Interface\\BUTTONS\\UI-GroupLoot-Dice-Up", -- Replace with path to your icon
})
-- Handle OnClick functionality
function plugin.OnClick(self, button)
if button == "LeftButton" then
Settings.OpenToCategory(addon.category:GetID()) -- Open or close the options panel
end
end
-- Handle OnTooltipShow functionality
function plugin.OnTooltipShow(tooltip)
tooltip:SetText(addonName)
tooltip:AddLine("Click to open options")
tooltip:Show()
end
-- Initialise Minimap Icon on Player Login
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function()
local icon = LibStub("LibDBIcon-1.0", true)
if not icon then return end
icon:Register(addonName, plugin, TestAddonSettingsData_MinimapIcon)
end)
f:RegisterEvent("PLAYER_LOGIN")
Anyway, after these changes, the minimap button now retains its location successfully.