View Single Post
04-15-24, 02:30 AM   #25
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,950
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:
  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: TestAddonSettingsData, TestAddonSettingsData_MinimapIcon
  11. ## SavedVariablesPerCharacter:
  12.  
  13. SettingsPanel.lua
  14. MinimapButton.lua
  15. 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:
  1. local addonName, addon = ...
  2.  
  3. -- Main Addon SavedVariable Table
  4. TestAddonSettingsData = TestAddonSettingsData or {}
  5.  
  6. -- Minimap Icon SavedVariable Table
  7. TestAddonSettingsData_MinimapIcon = TestAddonSettingsData_MinimapIcon or {}
  8.  
  9. -- Initialise Minimap Icon values
  10. -- Use settings panel to allow player to change these
  11. -- When you move the minimap icon around the minimap the ldb library updates the respective MinimapIcon saved variable table
  12. -- The MinimapIcon Saved Variable Data has to be its own table, not a sub table
  13. TestAddonSettingsData_MinimapIcon.hide = false
  14. TestAddonSettingsData_MinimapIcon.lock = false            
  15. TestAddonSettingsData_MinimapIcon.minimapPos = 120
  16. TestAddonSettingsData_MinimapIcon.radius = 80
  17.  
  18. -- Make sure library exists
  19. local ldb = LibStub:GetLibrary("LibDataBroker-1.1", true)
  20. if not ldb then return end
  21.  
  22. -- Create Plugin
  23. local plugin = ldb:NewDataObject(addonName, {
  24.     type = "data source",
  25.     text = addonName,
  26.     icon = "Interface\\BUTTONS\\UI-GroupLoot-Dice-Up", -- Replace with path to your icon
  27. })
  28.  
  29. -- Handle OnClick functionality
  30. function plugin.OnClick(self, button)
  31.     if button == "LeftButton" then
  32.         Settings.OpenToCategory(addon.category:GetID()) -- Open or close the options panel
  33.     end
  34. end
  35.  
  36. -- Handle OnTooltipShow functionality
  37. function plugin.OnTooltipShow(tooltip)
  38.     tooltip:SetText(addonName)
  39.     tooltip:AddLine("Click to open options")
  40.     tooltip:Show()
  41. end
  42.    
  43. -- Initialise Minimap Icon on Player Login    
  44. local f = CreateFrame("Frame")
  45. f:SetScript("OnEvent", function()
  46.     local icon = LibStub("LibDBIcon-1.0", true)
  47.     if not icon then return end
  48.     icon:Register(addonName, plugin, TestAddonSettingsData_MinimapIcon)
  49. end)
  50. f:RegisterEvent("PLAYER_LOGIN")

Anyway, after these changes, the minimap button now retains its location successfully.
__________________


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-15-24 at 03:01 AM.
  Reply With Quote