View Single Post
12-10-23, 11:00 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,897
I mean't that in your original code wherever you had
Code:
TestMMBicon:Hide("TestMiniMapButton")
you needed to add
Code:
self.db.show = false
and wherever you had
Code:
TestMMBicon:Show("TestMiniMapButton")
you needed to add
Code:
self.db.show = true
Probably a bit more like:
Lua Code:
  1. local TestMMBicon = LibStub("LibDBIcon-1.0", true)
  2. local TestMiniButton = LibStub("AceAddon-3.0"):NewAddon("TestMiniMapButton", "AceConsole-3.0")
  3.  
  4. SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  5. function SlashCmdList.MMBSHOW(msg, editbox)
  6.   TestMMBicon:Show("TestMiniMapButton")
  7.   TestMiniButton.db.show = true -- Added
  8. end
  9.  
  10.  
  11. SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  12. function SlashCmdList.MMBHIDE(msg, editbox)
  13.   TestMMBicon:Hide("TestMiniMapButton")
  14.   TestMiniButton.db.show = false -- Added
  15. end
  16.  
  17.  
  18. local miniButton = {
  19.   text = "TestMiniMapButton",
  20.   type = "data source",
  21.   icon = "Interface/Minimap/Vehicle-AllianceWarlockPortal",
  22.   OnTooltipShow = function(tooltip)
  23.   if not tooltip or not tooltip.AddLine then return end
  24.   tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
  25.   end,
  26.   OnClick = function(self, button)
  27.     if button == "RightButton" then
  28.       LibStub("AceConfigDialog-3.0"):Close("TestMiniMapButton")
  29.     end
  30.     if button == "LeftButton" then
  31.       LibStub("AceConfigDialog-3.0"):Open("TestMiniMapButton")
  32.     end
  33.     if IsShiftKeyDown() and button == "RightButton" then
  34.       TestMMBicon:Hide("TestMiniMapButton")
  35.     end
  36. end}
  37.  
  38.  
  39. function TestMiniButton:OnInitialize()
  40.   self.db = LibStub("AceDB-3.0"):New("TestMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  41.   TestMMBicon:Register("TestMiniMapButton", miniButton, self.db.profile.minimap)
  42. end
  43.  
  44.  
  45. function Addon:PLAYER_LOGIN()
  46. local options = {
  47.   type = "group",
  48.   name = "Test",
  49.   childGroups = "tab",
  50.   desc = "test",
  51.   get = function(info) return db[info[#info]] end,
  52.   set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "TestAddon") end,
  53.   args = {  
  54.     GeneralTab = {
  55.       type = "group",
  56.       name = "General",
  57.       desc = "General settings that apply to Azeroth / Continent / Dungeon map at the same time",
  58.       order = 0,
  59.       args = {
  60.         hideMapNotesMMB = {
  61.           type = "header",
  62.           name = "-> MiniMapButton <-",
  63.           order = 1,
  64.           },
  65.         showMMB = {
  66.           type = "execute",
  67.           name = L["show"],
  68.           desc = L["Show the minimap button on the minimap"],
  69.           order = 1.1,
  70.           width = 1.89,
  71.           get = function() return db.show["ShowMMB"] end,
  72.           func = function()
  73.             TestMMBicon:Show("TestMiniMapButton")
  74.             TestMiniButton.db.show = true -- Added
  75.           end
  76.           },  
  77.         hideMMB = {
  78.           type = "execute",
  79.           name = L["hide"],
  80.           desc = L["Hide the minimap button on the minimap"],
  81.           order = 1.2,
  82.           width = 1.89,
  83.           get = function() return db.show["HideMMB"] end,
  84.           func = function()
  85.             TestMMBicon:Hide("TestMiniMapButton")
  86.             TestMiniButton.db.show = false -- Added
  87.           end
  88.           },
  89.       }
  90.     }
  91.   }
  92. }
  93.  
  94.   HandyNotes:RegisterPluginDB("TestAddon", pluginHandler, options)
  95.   self.db = LibStub("AceDB-3.0"):New("HandyNotes_TestAddonDB", defaults, true)
  96.   db = self.db.profile
  97.   LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TestMiniMapButton", options)
  98.   Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  99. end

EDIT: Because Ace doesn't have a SetShown method.
At PLAYER_LOGIN you would add:
Code:
if not db.show then
      TestMMBicon:Hide("TestMiniMapButton")
end
to set the initial state of the button when the user logs in to what was last saved in the db.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-10-23 at 03:03 PM.
  Reply With Quote