Thread Tools Display Modes
12-10-23, 01:35 AM   #1
Ssesmar
A Deviate Faerie Dragon
Join Date: Oct 2023
Posts: 15
minimap button created with LibDBIcon need help

I created a minimap button with LIbDBIcon-1.0 that also works. the position is saved, but it doesn't save, if you hide the button, it will be displayed again after the next login and must be deactivated again.

Lua Code:
  1. local TestMMBicon = LibStub("LibDBIcon-1.0", true)
  2. local TestMiniButton = LibStub("AceAddon-3.0"):NewAddon("TestMiniMapButton", "AceConsole-3.0")

Lua Code:
  1. SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  2. function SlashCmdList.MMBSHOW(msg, editbox)
  3.   TestMMBicon:Show("TestMiniMapButton")
  4. end
  5.  
  6. SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  7. function SlashCmdList.MMBHIDE(msg, editbox)
  8.   TestMMBicon:Hide("TestMiniMapButton")
  9. end

Lua Code:
  1. local miniButton = {
  2.   text = "TestMiniMapButton",
  3.   type = "data source",
  4.   icon = "Interface/Minimap/Vehicle-AllianceWarlockPortal",
  5.   OnTooltipShow = function(tooltip)
  6.   if not tooltip or not tooltip.AddLine then return end
  7.   tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
  8.   end,
  9.   OnClick = function(self, button)
  10.     if button == "RightButton" then
  11.       LibStub("AceConfigDialog-3.0"):Close("TestMiniMapButton")
  12.     end
  13.     if button == "LeftButton" then
  14.       LibStub("AceConfigDialog-3.0"):Open("TestMiniMapButton")
  15.     end
  16.     if IsShiftKeyDown() and button == "RightButton" then
  17.       TestMMBicon:Hide("TestMiniMapButton")
  18.     end
  19. end}

Lua Code:
  1. function TestMiniButton:OnInitialize()
  2.   self.db = LibStub("AceDB-3.0"):New("TestMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  3.   TestMMBicon:Register("TestMiniMapButton", miniButton, self.db.profile.minimap)
  4. end

for the minimap button option inside the menu:

Lua Code:
  1. function Addon:PLAYER_LOGIN()
  2. local options = {
  3.   type = "group",
  4.   name = "Test",
  5.   childGroups = "tab",
  6.   desc = "test",
  7.   get = function(info) return db[info[#info]] end,
  8.   set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "TestAddon") end,
  9.   args = {  
  10.     GeneralTab = {
  11.       type = "group",
  12.       name = "General",
  13.       desc = "General settings that apply to Azeroth / Continent / Dungeon map at the same time",
  14.       order = 0,
  15.       args = {
  16.         hideMapNotesMMB = {
  17.           type = "header",
  18.           name = "-> MiniMapButton <-",
  19.           order = 1,
  20.           },
  21.         showMMB = {
  22.           type = "execute",
  23.           name = L["show"],
  24.           desc = L["Show the minimap button on the minimap"],
  25.           order = 1.1,
  26.           width = 1.89,
  27.           get = function() return db.show["ShowMMB"] end,
  28.           func = function() TestMMBicon:Show("TestMiniMapButton") end
  29.           },  
  30.         hideMMB = {
  31.           type = "execute",
  32.           name = L["hide"],
  33.           desc = L["Hide the minimap button on the minimap"],
  34.           order = 1.2,
  35.           width = 1.89,
  36.           get = function() return db.show["HideMMB"] end,
  37.           func = function() TestMMBicon:Hide("TestMiniMapButton") end
  38.           },
  39.       }
  40.     }
  41.   }
  42. }
  43.  
  44.   HandyNotes:RegisterPluginDB("TestAddon", pluginHandler, options)
  45.   self.db = LibStub("AceDB-3.0"):New("HandyNotes_TestAddonDB", defaults, true)
  46.   db = self.db.profile
  47.   LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("TestMiniMapButton", options)
  48.   Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  49. end
  Reply With Quote
12-10-23, 08:44 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,813
I don't beleieve the library saves the settings for show/hide.

When the user runs one of the actions that shows/hides the button you have to set the .show value in the db eg.:
Lua Code:
  1. TestMMBicon:Hide("TestMiniMapButton")
  2. self.db.show = false
  3.  
  4. TestMMBicon:Show("TestMiniMapButton")
  5. self.db.show = true

When you create the MM Button you have to set its visible state to whatever was last saved in the db
Lua Code:
  1. local TestMiniButton = LibStub("AceAddon-3.0"):NewAddon("TestMiniMapButton", "AceConsole-3.0")
  2. TestMiniButton:SetShown(self.db.show) -- Assuming self.db has been initalised at this stage

You could use the buttons OnShow/OnHide scripts to do the setting of the db.show value.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-10-23, 10:20 AM   #3
Ssesmar
A Deviate Faerie Dragon
Join Date: Oct 2023
Posts: 15
i changed the code from
Lua Code:
  1. function TestMiniButton:OnInitialize()
  2.       self.db = LibStub("AceDB-3.0"):New("TestMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  3.       TestMMBicon:Register("TestMiniMapButton", miniButton, self.db.profile.minimap)
  4.     end
to

Lua Code:
  1. function TestMiniButton:OnInitialize()
  2.       self.db = LibStub("AceDB-3.0"):New("TestMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  3.       TestMMBicon:Register("TestMiniMapButton", miniButton, self.db.profile.minimap)
  4.     end
  5.  
  6.     TestMMBicon:Hide("TestMiniMapButton")
  7.     self.db.show = false
  8.      
  9.     TestMMBicon:Show("TestMiniMapButton")
  10.     self.db.show = true

the file is written in the order as stated above, so:

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

that's right?
  Reply With Quote
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,813
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
12-11-23, 01:17 AM   #5
Ssesmar
A Deviate Faerie Dragon
Join Date: Oct 2023
Posts: 15
I tried to incorporate these changes into the addon but it just doesn't work. As I said, everything is shown and hidden, these functions work perfectly. The position of the minimap button is also saved, just not the value of whether it was activated or deactivated.

Here is the original output code of my addon.
But every time I enter
Lua Code:
  1. MBicon:SetShown(MapNotesMiniButton.db.show)
, I get a error with SetShown

Lua Code:
  1. --## SavedVariables: HandyNotes_MapNotesDB
  2.  
  3. local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes", true)
  4. if not HandyNotes then return end
  5. local L = LibStub("AceLocale-3.0"):GetLocale("HandyNotes_MapNotes")
  6. local MBicon = LibStub("LibDBIcon-1.0", true)
  7. local MapNotesMiniButton = LibStub("AceAddon-3.0"):NewAddon("MNMiniMapButton", "AceConsole-3.0")
  8.  
  9. local db = { }
  10. local icons = { }
  11. local nodes = { }
  12. local minimap = { }
  13. local lfgIDs = { }
  14. local assignedIDs = { }
  15.  
  16. SLASH_INFO1, SLASH_INFO2, SLASH_INFO3, SLASH_INFO4, SLASH_INFO5, SLASH_INFO6, SLASH_INFO7, SLASH_INFO8 , SLASH_INFO09 = "/mn", "/MN", "/mapnotes", "/MAPNOTES", "/mnhelp", "/MNHELP", "/mnh", "/MNH", "/handynotes_mapnotes";
  17. function SlashCmdList.INFO(msg, editbox)
  18.   print("|cff00ccff".."------------------------------------------------------------------------------------------")
  19.   print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  20.   print("|cffffff00".. L["Chat commands:"])
  21.   print("|cffffff00                       ".. L["to open MapNotes menu: /mno, /MNO"])
  22.   print("|cffffff00                       ".. L["to close MapNotes menu: /mnc, /MNC"])
  23.   print("|cffffff00                       ".. L["to show minimapbutton: /mnb or /MNB"])
  24.   print("|cffffff00                       ".. L["to hide minimapbutton: /mnbh or /MNBH"])
  25.   print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  26.   print("|cff00ccff".."------------------------------------------------------------------------------------------")
  27. end
  28.  
  29. SLASH_OPEN1, SLASH_OPEN2 = "/mno", "/MNO";
  30. function SlashCmdList.OPEN(msg, editbox)
  31.   LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  32.   print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  33. end
  34.  
  35. SLASH_CLOSE1, SLASH_CLOSE2 = "/mnc", "/MNC";
  36. function SlashCmdList.CLOSE(msg, editbox)
  37.   LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  38.   print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  39. end
  40.  
  41. SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  42. function SlashCmdList.MMBSHOW(msg, editbox)
  43.   MBicon:Show("MNMiniMapButton")
  44.   print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"])
  45. end
  46.  
  47. SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  48. function SlashCmdList.MMBHIDE(msg, editbox)
  49.   MBicon:Hide("MNMiniMapButton")
  50.   print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  51. end
  52.  
  53. local miniButton = {
  54.   text = "MapNotes",
  55.   type = "data source",
  56.   icon = "Interface\\AddOns\\HandyNotes_MapNotes\\Images\\MN_Logo",
  57.   OnTooltipShow = function(tooltip)
  58.   if not tooltip or not tooltip.AddLine then return end
  59.   tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
  60.   end,
  61.   OnClick = function(self, button)
  62.     if button == "RightButton" then
  63.       LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  64.       print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  65.     end
  66.     if IsShiftKeyDown() and button == "RightButton" then
  67.       MBicon:Hide("MNMiniMapButton")
  68.       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  69.     end
  70.     if button == "LeftButton" then
  71.       LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  72.       print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  73.     end
  74. end}
  75.  
  76. function MapNotesMiniButton:OnInitialize()
  77.   self.db = LibStub("AceDB-3.0"):New("MNMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  78.   MBicon:Register("MNMiniMapButton", miniButton, self.db.profile.minimap)
  79. end
  80.  
  81. local function updateAssignedID()
  82.     table.wipe(assignedIDs)
  83.     for i=1,GetNumSavedInstances() do
  84.         local name, _, _, _, locked, _, _, _, _, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(i)
  85.         if (locked) then
  86.             if (not assignedIDs[name]) then
  87.             assignedIDs[name] = { }
  88.             end
  89.             assignedIDs[name][difficultyName] = encounterProgress .. "/" .. numEncounters
  90.         end
  91.     end
  92. end
  93.  
  94. local pluginHandler = { }
  95. function pluginHandler:OnEnter(uiMapId, coord)
  96.   local nodeData = nil
  97.  
  98.     if (minimap[uiMapId] and minimap[uiMapId][coord]) then
  99.       nodeData = minimap[uiMapId][coord]
  100.     end
  101.     if (nodes[uiMapId] and nodes[uiMapId][coord]) then
  102.       nodeData = nodes[uiMapId][coord]
  103.     end
  104.    
  105.     if (not nodeData) then return end
  106.    
  107.     local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
  108.     if ( self:GetCenter() > UIParent:GetCenter() ) then
  109.       tooltip:SetOwner(self, "ANCHOR_LEFT")
  110.     else
  111.         tooltip:SetOwner(self, "ANCHOR_RIGHT")
  112.     end
  113.  
  114.     if (not nodeData.name) then return end
  115.  
  116.     local instances = { strsplit("\n", nodeData.name) }
  117.    
  118.  
  119.     updateAssignedID()
  120.    
  121.     for i, v in pairs(instances) do
  122.       if (db.assignedID and (assignedIDs[v] or (lfgIDs[v] and assignedIDs[lfgIDs[v]]))) then
  123.         if (assignedIDs[v]) then
  124.           for a,b in pairs(assignedIDs[v]) do
  125.             tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  126.           end
  127.         end
  128.       if (lfgIDs[v] and assignedIDs[lfgIDs[v]]) then
  129.         for a,b in pairs(assignedIDs[lfgIDs[v]]) do
  130.           tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  131.         end
  132.       end
  133.       else
  134.         tooltip:AddLine(v, nil, nil, nil, false)
  135.       end
  136.     end
  137.     tooltip:Show()
  138. end
  139.  
  140. function pluginHandler:OnLeave(uiMapID, coord)
  141.     if self:GetParent() == WorldMapButton then
  142.       WorldMapTooltip:Hide()
  143.     else
  144.       GameTooltip:Hide()
  145.     end
  146. end
  147.  
  148. do
  149.     local tablepool = setmetatable({}, {__mode = 'k'})
  150.    
  151.     local function deepCopy(object)
  152.         local lookup_table = {}
  153.         local function _copy(object)
  154.             if type(object) ~= "table" then
  155.                 return object
  156.             elseif lookup_table[object] then
  157.                 return lookup_table[object]
  158.             end
  159.  
  160.             local new_table = {}
  161.               lookup_table[object] = new_table
  162.             for index, value in pairs(object) do
  163.                 new_table[_copy(index)] = _copy(value)
  164.             end
  165.  
  166.             return setmetatable(new_table, getmetatable(object))
  167.         end
  168.             return _copy(object)
  169.     end
  170.  
  171.     local function iter(t, prestate)
  172.         if not t then return end
  173.         local data = t.data
  174.  
  175.         local state, value = next(data, prestate)
  176.  
  177.         while value do
  178.             local alpha
  179.            
  180.             local allLocked = true
  181.             local anyLocked = false
  182.             if value.name == nil then value.name = value.id end
  183.             local instances = { strsplit("\n", value.name) }
  184.             for i, v in pairs(instances) do
  185.                 if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  186.                     allLocked = false
  187.                 else
  188.                     anyLocked = true
  189.                 end
  190.             end
  191.  
  192.             local icon = icons[value.type]
  193.             if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID) and db.assignedgray) then  
  194.                 icon = icons["Locked"]
  195.             end
  196.  
  197.             if t.minimapUpdate or value.showInZone then
  198.               return state, nil, icon, db.azerothScale, alpha
  199.             end
  200.      
  201.             state, value = next(data, state)
  202.         end
  203.         wipe(t)
  204.         tablepool[t] = true
  205.     end
  206.  
  207.  
  208.     local function iterCont(t, prestate)
  209.         if not t then return end
  210.     if not db.showContinent then return end
  211.         local zone = t.C[t.Z]
  212.         local data = nodes[zone]
  213.         local state, value
  214.         while zone do
  215.             if data then
  216.                 state, value = next(data, prestate)
  217.                 while state do
  218.                     local icon, alpha
  219.  
  220.                     icon = icons[value.type]
  221.                     local allLocked = true
  222.                     local anyLocked = false
  223.                     local instances = { strsplit("\n", value.name) }
  224.                     for i, v in pairs(instances) do
  225.                         if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  226.                             allLocked = false
  227.                         else
  228.                             anyLocked = true
  229.                         end
  230.                     end
  231.      
  232.                     if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID) and db.assignedgray) then  
  233.                         icon = icons["Locked"]
  234.                     end
  235.  
  236.                     if not value.hideOnContinent and db.showContinent then
  237.                         return state, zone, icon, db.continentScale, alpha
  238.           end
  239.                     state, value = next(data, state)
  240.                 end
  241.             end
  242.             t.Z = next(t.C, t.Z)
  243.             zone = t.C[t.Z]
  244.             data = nodes[zone]
  245.             prestate = nil
  246.         end
  247.         wipe(t)
  248.         tablepool[t] = true
  249.     end
  250.  
  251.     function pluginHandler:GetNodes2(uiMapId, isMinimapUpdate, coord)
  252.         local C = deepCopy(HandyNotes:GetContinentZoneList(uiMapId))
  253.         if C then
  254.             table.insert(C, uiMapId)
  255.             local tbl = next(tablepool) or {}
  256.             tablepool[tbl] = nil
  257.             tbl.C = C
  258.             tbl.Z = next(C)
  259.             tbl.contId = uiMapId
  260.             return iterCont, tbl, nil
  261.         else
  262.             if (nodes[uiMapId] == nil) then return iter end
  263.             local tbl = next(tablepool) or {}
  264.             tablepool[tbl] = nil
  265.             tbl.minimapUpdate = isMinimapUpdate
  266.             if (isMinimapUpdate and minimap[uiMapId]) then
  267.                 tbl.data = minimap[uiMapId]
  268.             else
  269.                 tbl.data = nodes[uiMapId]
  270.             end
  271.             return iter, tbl, nil
  272.         end
  273.     end
  274. end
  275.  
  276. local waypoints = {}
  277. local function setWaypoint(uiMapID, coord)
  278.     local dungeon = nodes[uiMapID][coord]
  279.  
  280.     local waypoint = nodes[dungeon]
  281.     if waypoint and TomTom:IsValidWaypoint(waypoint) then
  282.         return
  283.     end
  284.  
  285.     local title = dungeon.name
  286.     local x, y = HandyNotes:getXY(coord)
  287.     waypoints[dungeon] = TomTom:AddWaypoint(uiMapID, x, y, {
  288.         title = dungeon.name,
  289.         persistent = nil,
  290.         minimap = true,
  291.         world = true
  292.     })
  293. end
  294.  
  295. function pluginHandler:OnClick(button, pressed, uiMapId, coord)
  296.     if (not pressed) then return end
  297.     if IsShiftKeyDown() and (button == "RightButton" and db.tomtom and TomTom) then
  298.         setWaypoint(uiMapId, coord)
  299.         return
  300.         end
  301.     if (button == "LeftButton" and db.journal) then
  302.         if (not EncounterJournal_OpenJournal) then
  303.         UIParentLoadAddOn('Blizzard_EncounterJournal')
  304.         end
  305.         local dungeonID
  306.         if (type(nodes[uiMapId][coord].id) == "table") then
  307.             dungeonID = nodes[uiMapId][coord].id[1]
  308.         else
  309.             dungeonID = nodes[uiMapId][coord].id
  310.         end
  311.  
  312.         if (not dungeonID) then return end
  313.  
  314.         local name, _, _, _, _, _, _, link = EJ_GetInstanceInfo(dungeonID)
  315.         if not link then return end
  316.         local difficulty = string.match(link, 'journal:.-:.-:(.-)|h')
  317.         if (not dungeonID or not difficulty) then return end
  318.         EncounterJournal_OpenJournal(difficulty, dungeonID)
  319.         _G.EncounterJournal:SetScript("OnShow", BBBEncounterJournal_OnShow)
  320.     end
  321. end
  322.  
  323. local defaults = {
  324.   profile = {
  325.       show = {
  326.       },
  327.  
  328.     --1
  329.       hideAddon = false,
  330.       hideMMB = false,
  331.       showMMB = true,
  332.   },
  333. }
  334.  
  335. local Addon = CreateFrame("Frame")
  336. Addon:RegisterEvent("PLAYER_LOGIN")
  337. Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
  338.  
  339. local function updateStuff()
  340.     updateAssignedID()
  341.     HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  342. end
  343.  
  344. function Addon:PLAYER_ENTERING_WORLD()
  345.     if (not self.faction) then
  346.         self.faction = UnitFactionGroup("player")
  347.         self:PopulateTable()
  348.         self:PopulateMinimap()
  349.         self:ProcessTable()
  350.     end
  351.  
  352.         updateAssignedID()
  353.         updateStuff()
  354. end
  355.  
  356. function Addon:PLAYER_LOGIN()
  357. local options = {
  358.   type = "group",
  359.   name = "|cffff0000Map|r|cff00ccffNotes|r",
  360.   childGroups = "tab",
  361.   desc = L["Shows locations of raids, dungeons, portals ,ship and zeppelins symbols on different maps"],
  362.   get = function(info) return db[info[#info]] end,
  363.   set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes") end,
  364.   args = {  
  365.     GeneralTab = {
  366.       type = "group",
  367.       name = L["General"],
  368.       desc = L["General settings that apply to Azeroth / Continent / Dungeon map at the same time"],
  369.       order = 0,
  370.       args = {
  371.         hideMapNotesMMB = {
  372.           type = "header",
  373.           name = L["-> MiniMapButton <-"],
  374.           order = 1,
  375.           },
  376.         showMMB = {
  377.           disabled = function() return db.show["HideMapNote"] end,
  378.           type = "execute",
  379.           name = L["show"],
  380.           desc = L["Show the minimap button on the minimap"],
  381.           order = 1.1,
  382.           width = 1.89,
  383.           func = function() MBicon:Show("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"]) end,
  384.           },  
  385.         hideMMB = {
  386.           disabled = function() return db.show["HideMapNote"] end,
  387.           type = "execute",
  388.           name = L["hide"],
  389.           desc = L["Hide the minimap button on the minimap"],
  390.           order = 1.2,
  391.           width = 1.89,
  392.           func = function() MBicon:Hide("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"]) end,
  393.           },
  394.         hideMapNoteAddon = {
  395.           type = "header",
  396.           name = L["-> Hide all MapNotes symbols <-"],
  397.           order = 5,
  398.           },
  399.         hideAddon = {
  400.           type = "toggle",
  401.           name = "|cffff0000" .. L[" hide MapNotes!"] .."\n",
  402.           desc = L["Disable MapNotes, all icons will be hidden on each map and all categories will be disabled"],
  403.           order = 5.1,
  404.           get = function() return db.show["HideMapNote"] end,
  405.           set = function(info, v) db.show["HideMapNote"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  406.                 if db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cffff0000 ".. L["All MapNotes symbols have been hidden"]) else
  407.                 if not db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cff00ff00 ".. L["All set symbols have been restored"]) end end end,
  408.           },
  409.       }
  410.     }
  411.   }
  412. }
  413.  
  414.   HandyNotes:RegisterPluginDB("MapNotes", pluginHandler, options)
  415.   self.db = LibStub("AceDB-3.0"):New("HandyNotes_MapNotesDB", defaults, true)
  416.   db = self.db.profile
  417.   LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MNMiniMapButton", options)
  418.   Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  419. end
  420.  
  421. function Addon:PopulateMinimap()
  422.     local temp = { }
  423.     for k,v in pairs(nodes) do
  424.         if (minimap[k]) then
  425.             for a,b in pairs(minimap[k]) do
  426.                 temp[a] = true
  427.             end
  428.             for c,d in pairs(v) do
  429.                 if (not temp[c] and not d.hideOnMinimap) then
  430.                     minimap[k][c] = d
  431.                 end
  432.             end
  433.         end
  434.     end
  435. end
  436.  
  437. function Addon:PopulateTable()
  438.   table.wipe(nodes)
  439.   table.wipe(minimap)
  440. end
  441.  
  442. function Addon:ProcessTable()
  443.   table.wipe(lfgIDs)
  444. end
  445.  
  446. function Addon:UpdateInstanceNames(node)
  447.   local dungeonInfo = EJ_GetInstanceInfo
  448.   local id = node.id
  449.  
  450.     if (node.lfgid) then
  451.       dungeonInfo = GetLFGDungeonInfo
  452.       id = node.lfgid
  453.     end
  454.  
  455.     if (type(id) == "table") then
  456.       for i,v in pairs(node.id) do
  457.         local name = dungeonInfo(v)
  458.           self:UpdateAlter(v, name)
  459.         if (node.name) then
  460.           node.name = node.name .. "\n" .. name
  461.         else
  462.           node.name = name
  463.         end
  464.       end
  465.     elseif (id) then
  466.       node.name = dungeonInfo(id)
  467.       self:UpdateAlter(id, node.name)
  468.     end
  469. end
  470.  
  471. function Addon:FullUpdate()
  472.   self:PopulateTable()
  473.   self:PopulateMinimap()
  474.   self:ProcessTable()
  475. end
  Reply With Quote
12-11-23, 01:18 AM   #6
Ssesmar
A Deviate Faerie Dragon
Join Date: Oct 2023
Posts: 15
another try was:
Lua Code:
  1. --## SavedVariables: HandyNotes_MapNotesDB
  2.      
  3.     local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes", true)
  4.     if not HandyNotes then return end
  5.     local L = LibStub("AceLocale-3.0"):GetLocale("HandyNotes_MapNotes")
  6.     local MBicon = LibStub("LibDBIcon-1.0", true)
  7.     local MapNotesMiniButton = LibStub("AceAddon-3.0"):NewAddon("MNMiniMapButton", "AceConsole-3.0")
  8.      
  9.     local db = { }
  10.     local icons = { }
  11.     local nodes = { }
  12.     local minimap = { }
  13.     local lfgIDs = { }
  14.     local assignedIDs = { }
  15.      
  16.     SLASH_INFO1, SLASH_INFO2, SLASH_INFO3, SLASH_INFO4, SLASH_INFO5, SLASH_INFO6, SLASH_INFO7, SLASH_INFO8 , SLASH_INFO09 = "/mn", "/MN", "/mapnotes", "/MAPNOTES", "/mnhelp", "/MNHELP", "/mnh", "/MNH", "/handynotes_mapnotes";
  17.     function SlashCmdList.INFO(msg, editbox)
  18.       print("|cff00ccff".."------------------------------------------------------------------------------------------")
  19.       print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  20.       print("|cffffff00".. L["Chat commands:"])
  21.       print("|cffffff00                       ".. L["to open MapNotes menu: /mno, /MNO"])
  22.       print("|cffffff00                       ".. L["to close MapNotes menu: /mnc, /MNC"])
  23.       print("|cffffff00                       ".. L["to show minimapbutton: /mnb or /MNB"])
  24.       print("|cffffff00                       ".. L["to hide minimapbutton: /mnbh or /MNBH"])
  25.       print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  26.       print("|cff00ccff".."------------------------------------------------------------------------------------------")
  27.     end
  28.      
  29.     SLASH_OPEN1, SLASH_OPEN2 = "/mno", "/MNO";
  30.     function SlashCmdList.OPEN(msg, editbox)
  31.       LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  32.     end
  33.      
  34.     SLASH_CLOSE1, SLASH_CLOSE2 = "/mnc", "/MNC";
  35.     function SlashCmdList.CLOSE(msg, editbox)
  36.       LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  37.     end
  38.      
  39.     SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  40.     function SlashCmdList.MMBSHOW(msg, editbox)
  41.       if db.show["ShowMMB"] then MBicon:Show("MNMiniMapButton")end
  42.       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"])
  43.     end
  44.      
  45.     SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  46.     function SlashCmdList.MMBHIDE(msg, editbox)
  47.       if db.show["HideMMB"] then MBicon:Hide("MNMiniMapButton")end
  48.       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  49.     end
  50.      
  51.     local miniButton = {
  52.       text = "MNMiniMapButton",
  53.       type = "data source",
  54.       icon = "Interface\\AddOns\\HandyNotes_MapNotes\\Images\\MN_Logo",
  55.       OnTooltipShow = function(tooltip)
  56.       if not tooltip or not tooltip.AddLine then return end
  57.       tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
  58.       end,
  59.       OnClick = function(self, button)
  60.         if button == "RightButton" then
  61.           LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  62.           print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  63.         end
  64.         if button == "LeftButton" then
  65.           LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  66.           print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  67.         end
  68.         if IsShiftKeyDown() and button == "RightButton" then
  69.           if db.show["HideMMB"] then MBicon:Hide("MNMiniMapButton")end
  70.           print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  71.         end
  72.     end}
  73.      
  74.     function MapNotesMiniButton:OnInitialize()
  75.       self.db = LibStub("AceDB-3.0"):New("MNMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  76.       MBicon:Register("MNMiniMapButton", miniButton, self.db.profile.minimap)
  77.     end
  78.      
  79.     local function updateAssignedID()
  80.         table.wipe(assignedIDs)
  81.         for i=1,GetNumSavedInstances() do
  82.             local name, _, _, _, locked, _, _, _, _, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(i)
  83.             if (locked) then
  84.                 if (not assignedIDs[name]) then
  85.                 assignedIDs[name] = { }
  86.                 end
  87.                 assignedIDs[name][difficultyName] = encounterProgress .. "/" .. numEncounters
  88.             end
  89.         end
  90.     end
  91.      
  92.     local pluginHandler = { }
  93.     function pluginHandler:OnEnter(uiMapId, coord)
  94.       local nodeData = nil
  95.      
  96.         if (minimap[uiMapId] and minimap[uiMapId][coord]) then
  97.           nodeData = minimap[uiMapId][coord]
  98.         end
  99.         if (nodes[uiMapId] and nodes[uiMapId][coord]) then
  100.           nodeData = nodes[uiMapId][coord]
  101.         end
  102.        
  103.         if (not nodeData) then return end
  104.        
  105.         local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
  106.         if ( self:GetCenter() > UIParent:GetCenter() ) then
  107.           tooltip:SetOwner(self, "ANCHOR_LEFT")
  108.         else
  109.             tooltip:SetOwner(self, "ANCHOR_RIGHT")
  110.         end
  111.      
  112.         if (not nodeData.name) then return end
  113.      
  114.         local instances = { strsplit("\n", nodeData.name) }
  115.        
  116.      
  117.         updateAssignedID()
  118.        
  119.         for i, v in pairs(instances) do
  120.           if (db.assignedID and (assignedIDs[v] or (lfgIDs[v] and assignedIDs[lfgIDs[v]]))) then
  121.             if (assignedIDs[v]) then
  122.               for a,b in pairs(assignedIDs[v]) do
  123.                 tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  124.               end
  125.             end
  126.           if (lfgIDs[v] and assignedIDs[lfgIDs[v]]) then
  127.             for a,b in pairs(assignedIDs[lfgIDs[v]]) do
  128.               tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  129.             end
  130.           end
  131.           else
  132.             tooltip:AddLine(v, nil, nil, nil, false)
  133.           end
  134.         end
  135.         tooltip:Show()
  136.     end
  137.      
  138.     function pluginHandler:OnLeave(uiMapID, coord)
  139.         if self:GetParent() == WorldMapButton then
  140.           WorldMapTooltip:Hide()
  141.         else
  142.           GameTooltip:Hide()
  143.         end
  144.     end
  145.      
  146.     do
  147.         local tablepool = setmetatable({}, {__mode = 'k'})
  148.        
  149.         local function deepCopy(object)
  150.             local lookup_table = {}
  151.             local function _copy(object)
  152.                 if type(object) ~= "table" then
  153.                     return object
  154.                 elseif lookup_table[object] then
  155.                     return lookup_table[object]
  156.                 end
  157.      
  158.                 local new_table = {}
  159.                   lookup_table[object] = new_table
  160.                 for index, value in pairs(object) do
  161.                     new_table[_copy(index)] = _copy(value)
  162.                 end
  163.      
  164.                 return setmetatable(new_table, getmetatable(object))
  165.             end
  166.                 return _copy(object)
  167.         end
  168.      
  169.         local function iter(t, prestate)
  170.             if not t then return end
  171.             local data = t.data
  172.      
  173.             local state, value = next(data, prestate)
  174.      
  175.             while value do
  176.                 local alpha
  177.                
  178.                 local allLocked = true
  179.                 local anyLocked = false
  180.                 if value.name == nil then value.name = value.id end
  181.                 local instances = { strsplit("\n", value.name) }
  182.                 for i, v in pairs(instances) do
  183.                     if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  184.                         allLocked = false
  185.                     else
  186.                         anyLocked = true
  187.                     end
  188.                 end
  189.      
  190.                 local icon = icons[value.type]
  191.                 if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID) and db.assignedgray) then  
  192.                     icon = icons["Locked"]
  193.                 end
  194.      
  195.                 if t.minimapUpdate or value.showInZone then
  196.                   return state, nil, icon, db.azerothScale, alpha
  197.                 end
  198.          
  199.                 state, value = next(data, state)
  200.             end
  201.             wipe(t)
  202.             tablepool[t] = true
  203.         end
  204.      
  205.      
  206.         local function iterCont(t, prestate)
  207.             if not t then return end
  208.         if not db.showContinent then return end
  209.             local zone = t.C[t.Z]
  210.             local data = nodes[zone]
  211.             local state, value
  212.             while zone do
  213.                 if data then
  214.                     state, value = next(data, prestate)
  215.                     while state do
  216.                         local icon, alpha
  217.      
  218.                         icon = icons[value.type]
  219.                         local allLocked = true
  220.                         local anyLocked = false
  221.                         local instances = { strsplit("\n", value.name) }
  222.                         for i, v in pairs(instances) do
  223.                             if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  224.                                 allLocked = false
  225.                             else
  226.                                 anyLocked = true
  227.                             end
  228.                         end
  229.          
  230.                         if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID) and db.assignedgray) then  
  231.                             icon = icons["Locked"]
  232.                         end
  233.      
  234.                         if not value.hideOnContinent and db.showContinent then
  235.                             return state, zone, icon, db.continentScale, alpha
  236.               end
  237.                         state, value = next(data, state)
  238.                     end
  239.                 end
  240.                 t.Z = next(t.C, t.Z)
  241.                 zone = t.C[t.Z]
  242.                 data = nodes[zone]
  243.                 prestate = nil
  244.             end
  245.             wipe(t)
  246.             tablepool[t] = true
  247.         end
  248.      
  249.         function pluginHandler:GetNodes2(uiMapId, isMinimapUpdate, coord)
  250.             local C = deepCopy(HandyNotes:GetContinentZoneList(uiMapId))
  251.             if C then
  252.                 table.insert(C, uiMapId)
  253.                 local tbl = next(tablepool) or {}
  254.                 tablepool[tbl] = nil
  255.                 tbl.C = C
  256.                 tbl.Z = next(C)
  257.                 tbl.contId = uiMapId
  258.                 return iterCont, tbl, nil
  259.             else
  260.                 if (nodes[uiMapId] == nil) then return iter end
  261.                 local tbl = next(tablepool) or {}
  262.                 tablepool[tbl] = nil
  263.                 tbl.minimapUpdate = isMinimapUpdate
  264.                 if (isMinimapUpdate and minimap[uiMapId]) then
  265.                     tbl.data = minimap[uiMapId]
  266.                 else
  267.                     tbl.data = nodes[uiMapId]
  268.                 end
  269.                 return iter, tbl, nil
  270.             end
  271.         end
  272.     end
  273.      
  274.     local waypoints = {}
  275.     local function setWaypoint(uiMapID, coord)
  276.         local dungeon = nodes[uiMapID][coord]
  277.      
  278.         local waypoint = nodes[dungeon]
  279.         if waypoint and TomTom:IsValidWaypoint(waypoint) then
  280.             return
  281.         end
  282.      
  283.         local title = dungeon.name
  284.         local x, y = HandyNotes:getXY(coord)
  285.         waypoints[dungeon] = TomTom:AddWaypoint(uiMapID, x, y, {
  286.             title = dungeon.name,
  287.             persistent = nil,
  288.             minimap = true,
  289.             world = true
  290.         })
  291.     end
  292.      
  293.     function pluginHandler:OnClick(button, pressed, uiMapId, coord)
  294.         if (not pressed) then return end
  295.         if IsShiftKeyDown() and (button == "RightButton" and db.tomtom and TomTom) then
  296.             setWaypoint(uiMapId, coord)
  297.             return
  298.             end
  299.         if (button == "LeftButton" and db.journal) then
  300.             if (not EncounterJournal_OpenJournal) then
  301.             UIParentLoadAddOn('Blizzard_EncounterJournal')
  302.             end
  303.             local dungeonID
  304.             if (type(nodes[uiMapId][coord].id) == "table") then
  305.                 dungeonID = nodes[uiMapId][coord].id[1]
  306.             else
  307.                 dungeonID = nodes[uiMapId][coord].id
  308.             end
  309.      
  310.             if (not dungeonID) then return end
  311.      
  312.             local name, _, _, _, _, _, _, link = EJ_GetInstanceInfo(dungeonID)
  313.             if not link then return end
  314.             local difficulty = string.match(link, 'journal:.-:.-:(.-)|h')
  315.             if (not dungeonID or not difficulty) then return end
  316.             EncounterJournal_OpenJournal(difficulty, dungeonID)
  317.             _G.EncounterJournal:SetScript("OnShow", BBBEncounterJournal_OnShow)
  318.         end
  319.     end
  320.      
  321.     local defaults = {
  322.       profile = {
  323.           show = {
  324.           },
  325.      
  326.           hideAddon = false,
  327.           hideMMB = false,
  328.           showMMB = true,
  329.       },
  330.     }
  331.      
  332.     local Addon = CreateFrame("Frame")
  333.     Addon:RegisterEvent("PLAYER_LOGIN")
  334.     Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
  335.      
  336.     local function updateStuff()
  337.         updateAssignedID()
  338.         HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  339.     end
  340.      
  341.     function Addon:PLAYER_ENTERING_WORLD()
  342.         if (not self.faction) then
  343.             self.faction = UnitFactionGroup("player")
  344.             self:PopulateTable()
  345.             self:PopulateMinimap()
  346.             self:ProcessTable()
  347.         end
  348.      
  349.             updateAssignedID()
  350.             updateStuff()
  351.     end
  352.      
  353.     function Addon:PLAYER_LOGIN()
  354.     local options = {
  355.       type = "group",
  356.       name = "|cffff0000Map|r|cff00ccffNotes|r",
  357.       childGroups = "tab",
  358.       desc = L["Shows locations of raids, dungeons, portals ,ship and zeppelins symbols on different maps"],
  359.       get = function(info) return db[info[#info]] end,
  360.       set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes") end,
  361.       args = {  
  362.         GeneralTab = {
  363.           type = "group",
  364.           name = L["General"],
  365.           desc = L["General settings that apply to Azeroth / Continent / Dungeon map at the same time"],
  366.           order = 0,
  367.           args = {
  368.             hideMapNotesMMB = {
  369.               type = "header",
  370.               name = L["-> MiniMapButton <-"],
  371.               order = 1,
  372.               },
  373.             showMMB = {
  374.               disabled = function() return db.show["HideMapNote"] end,
  375.               type = "execute",
  376.               name = L["show"],
  377.               desc = L["Show the minimap button on the minimap"],
  378.               order = 1.1,
  379.               width = 1.89,
  380.               get = function() return db.show["ShowMMB"] end,
  381.               func = function(info, v) self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  382.                       if db.show["ShowMMB"] then MBicon:Show("MNMiniMapButton")end
  383.                       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"]) end,
  384.               },  
  385.             hideMMB = {
  386.               disabled = function() return db.show["HideMapNote"] end,
  387.               type = "execute",
  388.               name = L["hide"],
  389.               desc = L["Hide the minimap button on the minimap"],
  390.               order = 1.2,
  391.               width = 1.89,
  392.               func = function(info, v)self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  393.                       if  db.show["HideMMB"] then MBicon:Hide("MNMiniMapButton")end
  394.                       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"]) end,
  395.               },
  396.             hideMapNoteAddon = {
  397.               type = "header",
  398.               name = L["-> Hide all MapNotes symbols <-"],
  399.               order = 5,
  400.               },
  401.             hideAddon = {
  402.               type = "toggle",
  403.               name = "|cffff0000" .. L[" hide MapNotes!"] .."\n",
  404.               desc = L["Disable MapNotes, all icons will be hidden on each map and all categories will be disabled"],
  405.               order = 5.1,
  406.               get = function() return db.show["HideMapNote"] end,
  407.               set = function(info, v) db.show["HideMapNote"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  408.                     if db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cffff0000 ".. L["All MapNotes symbols have been hidden"]) else
  409.                     if not db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cff00ff00 ".. L["All set symbols have been restored"]) end end end,
  410.               },
  411.           }
  412.         }
  413.       }
  414.     }
  415.      
  416.       HandyNotes:RegisterPluginDB("MapNotes", pluginHandler, options)
  417.       self.db = LibStub("AceDB-3.0"):New("HandyNotes_MapNotesDB", defaults, true)
  418.       db = self.db.profile
  419.       LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MNMiniMapButton", options)
  420.       Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  421.     end
  422.    
  423.     function Addon:PopulateTable()
  424.       table.wipe(nodes)
  425.       table.wipe(minimap)
  426.     end
  427.    
  428.     function Addon:ProcessTable()
  429.       table.wipe(lfgIDs)
  430.     end
  431.  
  432.     function Addon:PopulateMinimap()
  433.         local temp = { }
  434.         for k,v in pairs(nodes) do
  435.             if (minimap[k]) then
  436.                 for a,b in pairs(minimap[k]) do
  437.                     temp[a] = true
  438.                 end
  439.                 for c,d in pairs(v) do
  440.                     if (not temp[c] and not d.hideOnMinimap) then
  441.                         minimap[k][c] = d
  442.                     end
  443.                 end
  444.             end
  445.         end
  446.     end
  447.      
  448.     function Addon:UpdateInstanceNames(node)
  449.       local dungeonInfo = EJ_GetInstanceInfo
  450.       local id = node.id
  451.      
  452.         if (node.lfgid) then
  453.           dungeonInfo = GetLFGDungeonInfo
  454.           id = node.lfgid
  455.         end
  456.      
  457.         if (type(id) == "table") then
  458.           for i,v in pairs(node.id) do
  459.             local name = dungeonInfo(v)
  460.               self:UpdateAlter(v, name)
  461.             if (node.name) then
  462.               node.name = node.name .. "\n" .. name
  463.             else
  464.               node.name = name
  465.             end
  466.           end
  467.         elseif (id) then
  468.           node.name = dungeonInfo(id)
  469.           self:UpdateAlter(id, node.name)
  470.         end
  471.     end
  472.      
  473.     function Addon:FullUpdate()
  474.       self:PopulateTable()
  475.       self:PopulateMinimap()
  476.       self:ProcessTable()
  477.     end
  Reply With Quote
12-11-23, 09:33 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,813
In your defaults you have
Lua Code:
  1. show = {
  2. }
  3. hideMMB = false,
  4. showMMB = true,
Using seperate variables is not is not going to work properly, you just want to know if it's to be shown/hidden.

I've added -- Changed comment to the sections I modified so the SavedVariable is updated when a minimap button show/hide action occurs and at the end of the PLAYER_LOGIN I added a check to see if the button should be hidded at login.

I removed the showMMB options entry because there should just be a Hide checkbox to toggle show/hide (The code would probably change to remove the db.show.ShowMMB = not db.show.ShowMMB because the the checkbox would actualy set the variable).

Lua Code:
  1. --## SavedVariables: HandyNotes_MapNotesDB
  2.      
  3.     local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes", true)
  4.     if not HandyNotes then return end
  5.     local L = LibStub("AceLocale-3.0"):GetLocale("HandyNotes_MapNotes")
  6.     local MBicon = LibStub("LibDBIcon-1.0", true)
  7.     local MapNotesMiniButton = LibStub("AceAddon-3.0"):NewAddon("MNMiniMapButton", "AceConsole-3.0")
  8.      
  9.     local db = { }
  10.     local icons = { }
  11.     local nodes = { }
  12.     local minimap = { }
  13.     local lfgIDs = { }
  14.     local assignedIDs = { }
  15.      
  16.     SLASH_INFO1, SLASH_INFO2, SLASH_INFO3, SLASH_INFO4, SLASH_INFO5, SLASH_INFO6, SLASH_INFO7, SLASH_INFO8 , SLASH_INFO09 = "/mn", "/MN", "/mapnotes", "/MAPNOTES", "/mnhelp", "/MNHELP", "/mnh", "/MNH", "/handynotes_mapnotes";
  17.     function SlashCmdList.INFO(msg, editbox)
  18.       print("|cff00ccff".."------------------------------------------------------------------------------------------")
  19.       print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  20.       print("|cffffff00".. L["Chat commands:"])
  21.       print("|cffffff00                      • ".. L["to open MapNotes menu: /mno, /MNO"])
  22.       print("|cffffff00                      • ".. L["to close MapNotes menu: /mnc, /MNC"])
  23.       print("|cffffff00                      • ".. L["to show minimapbutton: /mnb or /MNB"])
  24.       print("|cffffff00                      • ".. L["to hide minimapbutton: /mnbh or /MNBH"])
  25.       print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  26.       print("|cff00ccff".."------------------------------------------------------------------------------------------")
  27.     end
  28.      
  29.     SLASH_OPEN1, SLASH_OPEN2 = "/mno", "/MNO";
  30.     function SlashCmdList.OPEN(msg, editbox)
  31.       LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  32.     end
  33.      
  34.     SLASH_CLOSE1, SLASH_CLOSE2 = "/mnc", "/MNC";
  35.     function SlashCmdList.CLOSE(msg, editbox)
  36.       LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  37.     end
  38.      
  39.     SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  40.     function SlashCmdList.MMBSHOW(msg, editbox)
  41.       MBicon:Show("MNMiniMapButton") -- Changed
  42.       db.show.ShowMMB = true
  43.       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"])
  44.     end
  45.      
  46.     SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  47.     function SlashCmdList.MMBHIDE(msg, editbox)
  48.       MBicon:Hide("MNMiniMapButton") -- Changed
  49.       db.show.ShowMMB = false
  50.       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  51.     end
  52.      
  53.     local miniButton = {
  54.       text = "MNMiniMapButton",
  55.       type = "data source",
  56.       icon = "Interface\\AddOns\\HandyNotes_MapNotes\\Images\\MN_Logo",
  57.       OnTooltipShow = function(tooltip)
  58.       if not tooltip or not tooltip.AddLine then return end
  59.       tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
  60.       end,
  61.       OnClick = function(self, button)
  62.         if button == "RightButton" then
  63.           LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  64.           print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  65.         end
  66.         if button == "LeftButton" then
  67.           LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  68.           print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  69.         end
  70.         if IsShiftKeyDown() and button == "RightButton" then
  71.           MBicon:Hide("MNMiniMapButton")
  72.           db.show.ShowMMB = false
  73.           print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  74.         end
  75.     end}
  76.      
  77.     function MapNotesMiniButton:OnInitialize()
  78.       self.db = LibStub("AceDB-3.0"):New("MNMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  79.       MBicon:Register("MNMiniMapButton", miniButton, self.db.profile.minimap)
  80.     end
  81.      
  82.     local function updateAssignedID()
  83.         table.wipe(assignedIDs)
  84.         for i=1,GetNumSavedInstances() do
  85.             local name, _, _, _, locked, _, _, _, _, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(i)
  86.             if (locked) then
  87.                 if (not assignedIDs[name]) then
  88.                 assignedIDs[name] = { }
  89.                 end
  90.                 assignedIDs[name][difficultyName] = encounterProgress .. "/" .. numEncounters
  91.             end
  92.         end
  93.     end
  94.      
  95.     local pluginHandler = { }
  96.     function pluginHandler:OnEnter(uiMapId, coord)
  97.       local nodeData = nil
  98.      
  99.         if (minimap[uiMapId] and minimap[uiMapId][coord]) then
  100.           nodeData = minimap[uiMapId][coord]
  101.         end
  102.         if (nodes[uiMapId] and nodes[uiMapId][coord]) then
  103.           nodeData = nodes[uiMapId][coord]
  104.         end
  105.        
  106.         if (not nodeData) then return end
  107.        
  108.         local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
  109.         if ( self:GetCenter() > UIParent:GetCenter() ) then
  110.           tooltip:SetOwner(self, "ANCHOR_LEFT")
  111.         else
  112.             tooltip:SetOwner(self, "ANCHOR_RIGHT")
  113.         end
  114.      
  115.         if (not nodeData.name) then return end
  116.      
  117.         local instances = { strsplit("\n", nodeData.name) }
  118.        
  119.      
  120.         updateAssignedID()
  121.        
  122.         for i, v in pairs(instances) do
  123.           if (db.assignedID and (assignedIDs[v] or (lfgIDs[v] and assignedIDs[lfgIDs[v]]))) then
  124.             if (assignedIDs[v]) then
  125.               for a,b in pairs(assignedIDs[v]) do
  126.                 tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  127.               end
  128.             end
  129.           if (lfgIDs[v] and assignedIDs[lfgIDs[v]]) then
  130.             for a,b in pairs(assignedIDs[lfgIDs[v]]) do
  131.               tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  132.             end
  133.           end
  134.           else
  135.             tooltip:AddLine(v, nil, nil, nil, false)
  136.           end
  137.         end
  138.         tooltip:Show()
  139.     end
  140.      
  141.     function pluginHandler:OnLeave(uiMapID, coord)
  142.         if self:GetParent() == WorldMapButton then
  143.           WorldMapTooltip:Hide()
  144.         else
  145.           GameTooltip:Hide()
  146.         end
  147.     end
  148.      
  149.     do
  150.         local tablepool = setmetatable({}, {__mode = 'k'})
  151.        
  152.         local function deepCopy(object)
  153.             local lookup_table = {}
  154.             local function _copy(object)
  155.                 if type(object) ~= "table" then
  156.                     return object
  157.                 elseif lookup_table[object] then
  158.                     return lookup_table[object]
  159.                 end
  160.      
  161.                 local new_table = {}
  162.                   lookup_table[object] = new_table
  163.                 for index, value in pairs(object) do
  164.                     new_table[_copy(index)] = _copy(value)
  165.                 end
  166.      
  167.                 return setmetatable(new_table, getmetatable(object))
  168.             end
  169.                 return _copy(object)
  170.         end
  171.      
  172.         local function iter(t, prestate)
  173.             if not t then return end
  174.             local data = t.data
  175.      
  176.             local state, value = next(data, prestate)
  177.      
  178.             while value do
  179.                 local alpha
  180.                
  181.                 local allLocked = true
  182.                 local anyLocked = false
  183.                 if value.name == nil then value.name = value.id end
  184.                 local instances = { strsplit("\n", value.name) }
  185.                 for i, v in pairs(instances) do
  186.                     if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  187.                         allLocked = false
  188.                     else
  189.                         anyLocked = true
  190.                     end
  191.                 end
  192.      
  193.                 local icon = icons[value.type]
  194.                 if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID) and db.assignedgray) then  
  195.                     icon = icons["Locked"]
  196.                 end
  197.      
  198.                 if t.minimapUpdate or value.showInZone then
  199.                   return state, nil, icon, db.azerothScale, alpha
  200.                 end
  201.          
  202.                 state, value = next(data, state)
  203.             end
  204.             wipe(t)
  205.             tablepool[t] = true
  206.         end
  207.      
  208.      
  209.         local function iterCont(t, prestate)
  210.             if not t then return end
  211.         if not db.showContinent then return end
  212.             local zone = t.C[t.Z]
  213.             local data = nodes[zone]
  214.             local state, value
  215.             while zone do
  216.                 if data then
  217.                     state, value = next(data, prestate)
  218.                     while state do
  219.                         local icon, alpha
  220.      
  221.                         icon = icons[value.type]
  222.                         local allLocked = true
  223.                         local anyLocked = false
  224.                         local instances = { strsplit("\n", value.name) }
  225.                         for i, v in pairs(instances) do
  226.                             if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  227.                                 allLocked = false
  228.                             else
  229.                                 anyLocked = true
  230.                             end
  231.                         end
  232.          
  233.                         if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID) and db.assignedgray) then  
  234.                             icon = icons["Locked"]
  235.                         end
  236.      
  237.                         if not value.hideOnContinent and db.showContinent then
  238.                             return state, zone, icon, db.continentScale, alpha
  239.               end
  240.                         state, value = next(data, state)
  241.                     end
  242.                 end
  243.                 t.Z = next(t.C, t.Z)
  244.                 zone = t.C[t.Z]
  245.                 data = nodes[zone]
  246.                 prestate = nil
  247.             end
  248.             wipe(t)
  249.             tablepool[t] = true
  250.         end
  251.      
  252.         function pluginHandler:GetNodes2(uiMapId, isMinimapUpdate, coord)
  253.             local C = deepCopy(HandyNotes:GetContinentZoneList(uiMapId))
  254.             if C then
  255.                 table.insert(C, uiMapId)
  256.                 local tbl = next(tablepool) or {}
  257.                 tablepool[tbl] = nil
  258.                 tbl.C = C
  259.                 tbl.Z = next(C)
  260.                 tbl.contId = uiMapId
  261.                 return iterCont, tbl, nil
  262.             else
  263.                 if (nodes[uiMapId] == nil) then return iter end
  264.                 local tbl = next(tablepool) or {}
  265.                 tablepool[tbl] = nil
  266.                 tbl.minimapUpdate = isMinimapUpdate
  267.                 if (isMinimapUpdate and minimap[uiMapId]) then
  268.                     tbl.data = minimap[uiMapId]
  269.                 else
  270.                     tbl.data = nodes[uiMapId]
  271.                 end
  272.                 return iter, tbl, nil
  273.             end
  274.         end
  275.     end
  276.      
  277.     local waypoints = {}
  278.     local function setWaypoint(uiMapID, coord)
  279.         local dungeon = nodes[uiMapID][coord]
  280.      
  281.         local waypoint = nodes[dungeon]
  282.         if waypoint and TomTom:IsValidWaypoint(waypoint) then
  283.             return
  284.         end
  285.      
  286.         local title = dungeon.name
  287.         local x, y = HandyNotes:getXY(coord)
  288.         waypoints[dungeon] = TomTom:AddWaypoint(uiMapID, x, y, {
  289.             title = dungeon.name,
  290.             persistent = nil,
  291.             minimap = true,
  292.             world = true
  293.         })
  294.     end
  295.      
  296.     function pluginHandler:OnClick(button, pressed, uiMapId, coord)
  297.         if (not pressed) then return end
  298.         if IsShiftKeyDown() and (button == "RightButton" and db.tomtom and TomTom) then
  299.             setWaypoint(uiMapId, coord)
  300.             return
  301.             end
  302.         if (button == "LeftButton" and db.journal) then
  303.             if (not EncounterJournal_OpenJournal) then
  304.             UIParentLoadAddOn('Blizzard_EncounterJournal')
  305.             end
  306.             local dungeonID
  307.             if (type(nodes[uiMapId][coord].id) == "table") then
  308.                 dungeonID = nodes[uiMapId][coord].id[1]
  309.             else
  310.                 dungeonID = nodes[uiMapId][coord].id
  311.             end
  312.      
  313.             if (not dungeonID) then return end
  314.      
  315.             local name, _, _, _, _, _, _, link = EJ_GetInstanceInfo(dungeonID)
  316.             if not link then return end
  317.             local difficulty = string.match(link, 'journal:.-:.-:(.-)|h')
  318.             if (not dungeonID or not difficulty) then return end
  319.             EncounterJournal_OpenJournal(difficulty, dungeonID)
  320.             _G.EncounterJournal:SetScript("OnShow", BBBEncounterJournal_OnShow)
  321.         end
  322.     end
  323.      
  324.     local defaults = {
  325.       profile = { -- Changed
  326.           show = {
  327.             showMMB = true,
  328.           },
  329.      
  330.           hideAddon = false,
  331.       },
  332.     }
  333.      
  334.     local Addon = CreateFrame("Frame")
  335.     Addon:RegisterEvent("PLAYER_LOGIN")
  336.     Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
  337.      
  338.     local function updateStuff()
  339.         updateAssignedID()
  340.         HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  341.     end
  342.      
  343.     function Addon:PLAYER_ENTERING_WORLD()
  344.         if (not self.faction) then
  345.             self.faction = UnitFactionGroup("player")
  346.             self:PopulateTable()
  347.             self:PopulateMinimap()
  348.             self:ProcessTable()
  349.         end
  350.      
  351.             updateAssignedID()
  352.             updateStuff()
  353.     end
  354.      
  355.     function Addon:PLAYER_LOGIN()
  356.     local options = {
  357.       type = "group",
  358.       name = "|cffff0000Map|r|cff00ccffNotes|r",
  359.       childGroups = "tab",
  360.       desc = L["Shows locations of raids, dungeons, portals ,ship and zeppelins symbols on different maps"],
  361.       get = function(info) return db[info[#info]] end,
  362.       set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes") end,
  363.       args = {  
  364.         GeneralTab = {
  365.           type = "group",
  366.           name = L["General"],
  367.           desc = L["General settings that apply to Azeroth / Continent / Dungeon map at the same time"],
  368.           order = 0,
  369.           args = {
  370.             hideMapNotesMMB = {
  371.               type = "header",
  372.               name = L["-> MiniMapButton <-"],
  373.               order = 1,
  374.               },
  375.             hideMMB = { -- Changed: Remove the show and turned this into a toggle (Checkbox?)
  376.               disabled = function() return db.show["HideMapNote"] end,
  377.               type = "execute",
  378.               name = L["hide"],
  379.               desc = L["Hide the minimap button on the minimap"],
  380.               order = 1.2,
  381.               width = 1.89,
  382.               get = function() return db.show.ShowMMB end, -- Changed
  383.               func = function(info, v)self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  384.                       db.show.ShowMMB = not db.show.ShowMMB
  385.                       if db.show.ShowMMB then
  386.                         MBicon:Show("MNMiniMapButton")
  387.                       else
  388.                         MBicon:Hide("MNMiniMapButton")
  389.                       end
  390.                       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"]) end,
  391.               },
  392.             hideMapNoteAddon = {
  393.               type = "header",
  394.               name = L["-> Hide all MapNotes symbols <-"],
  395.               order = 5,
  396.               },
  397.             hideAddon = {
  398.               type = "toggle",
  399.               name = "|cffff0000" .. L["• hide MapNotes!"] .."\n",
  400.               desc = L["Disable MapNotes, all icons will be hidden on each map and all categories will be disabled"],
  401.               order = 5.1,
  402.               get = function() return db.show["HideMapNote"] end,
  403.               set = function(info, v) db.show["HideMapNote"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  404.                     if db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cffff0000 • ".. L["All MapNotes symbols have been hidden"]) else
  405.                     if not db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cff00ff00 • ".. L["All set symbols have been restored"]) end end end,
  406.               },
  407.           }
  408.         }
  409.       }
  410.     }
  411.      
  412.       HandyNotes:RegisterPluginDB("MapNotes", pluginHandler, options)
  413.       self.db = LibStub("AceDB-3.0"):New("HandyNotes_MapNotesDB", defaults, true)
  414.       db = self.db.profile
  415.       LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MNMiniMapButton", options)
  416.       Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  417.       if not db.show.ShowMMB then -- Changed
  418.         MBicon:Hide("MNMiniMapButton")
  419.       end
  420.     end
  421.    
  422.     function Addon:PopulateTable()
  423.       table.wipe(nodes)
  424.       table.wipe(minimap)
  425.     end
  426.    
  427.     function Addon:ProcessTable()
  428.       table.wipe(lfgIDs)
  429.     end
  430.  
  431.     function Addon:PopulateMinimap()
  432.         local temp = { }
  433.         for k,v in pairs(nodes) do
  434.             if (minimap[k]) then
  435.                 for a,b in pairs(minimap[k]) do
  436.                     temp[a] = true
  437.                 end
  438.                 for c,d in pairs(v) do
  439.                     if (not temp[c] and not d.hideOnMinimap) then
  440.                         minimap[k][c] = d
  441.                     end
  442.                 end
  443.             end
  444.         end
  445.     end
  446.      
  447.     function Addon:UpdateInstanceNames(node)
  448.       local dungeonInfo = EJ_GetInstanceInfo
  449.       local id = node.id
  450.      
  451.         if (node.lfgid) then
  452.           dungeonInfo = GetLFGDungeonInfo
  453.           id = node.lfgid
  454.         end
  455.      
  456.         if (type(id) == "table") then
  457.           for i,v in pairs(node.id) do
  458.             local name = dungeonInfo(v)
  459.               self:UpdateAlter(v, name)
  460.             if (node.name) then
  461.               node.name = node.name .. "\n" .. name
  462.             else
  463.               node.name = name
  464.             end
  465.           end
  466.         elseif (id) then
  467.           node.name = dungeonInfo(id)
  468.           self:UpdateAlter(id, node.name)
  469.         end
  470.     end
  471.      
  472.     function Addon:FullUpdate()
  473.       self:PopulateTable()
  474.       self:PopulateMinimap()
  475.       self:ProcessTable()
  476.     end

I didn't check anything else but I suspect where you're using things like db.show["HideMapNote"] may be suffering from the same thing because you don't seem to be save the setting when an action occurs
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-11-23 at 09:53 AM.
  Reply With Quote
12-12-23, 08:53 AM   #8
Ssesmar
A Deviate Faerie Dragon
Join Date: Oct 2023
Posts: 15
Thank you very much Fizzlemizz for your help, I have now changed the code like this. works perfectly and does exactly what it's supposed to do

Lua Code:
  1. --## SavedVariables: HandyNotes_MapNotesDB
  2.  
  3. local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes", true)
  4. if not HandyNotes then return end
  5. local L = LibStub("AceLocale-3.0"):GetLocale("HandyNotes_MapNotes")
  6. local MBicon = LibStub("LibDBIcon-1.0", true)
  7. local MapNotesMiniButton = LibStub("AceAddon-3.0"):NewAddon("MNMiniMapButton", "AceConsole-3.0")
  8.  
  9. local db = { }
  10. local icons = { }
  11. local nodes = { }
  12. local minimap = { }
  13. local lfgIDs = { }
  14. local assignedIDs = { }
  15.  
  16. SLASH_INFO1, SLASH_INFO2, SLASH_INFO3, SLASH_INFO4, SLASH_INFO5, SLASH_INFO6, SLASH_INFO7, SLASH_INFO8 , SLASH_INFO09 = "/mn", "/MN", "/mapnotes", "/MAPNOTES", "/mnhelp", "/MNHELP", "/mnh", "/MNH", "/handynotes_mapnotes";
  17. function SlashCmdList.INFO(msg, editbox)
  18.   print("|cff00ccff".."------------------------------------------------------------------------------------------")
  19.   print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  20.   print("|cffffff00".. L["Chat commands:"])
  21.   print("|cffffff00                       ".. L["to open MapNotes menu: /mno, /MNO"])
  22.   print("|cffffff00                       ".. L["to close MapNotes menu: /mnc, /MNC"])
  23.   print("|cffffff00                       ".. L["to show minimap button: /mnb or /MNB"])
  24.   print("|cffffff00                       ".. L["to hide minimap button: /mnbh or /MNBH"])
  25.   print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
  26.   print("|cff00ccff".."------------------------------------------------------------------------------------------")
  27. end
  28.  
  29. SLASH_OPEN1, SLASH_OPEN2 = "/mno", "/MNO";
  30. function SlashCmdList.OPEN(msg, editbox)
  31.   LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  32.   print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  33. end
  34.  
  35. SLASH_CLOSE1, SLASH_CLOSE2 = "/mnc", "/MNC";
  36. function SlashCmdList.CLOSE(msg, editbox)
  37.   LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  38.   print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  39. end
  40.  
  41. SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  42. function SlashCmdList.MMBSHOW(msg, editbox)
  43.   MBicon:Show("MNMiniMapButton")
  44.   db.show["HideMMB"] = false
  45.   print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"])
  46. end
  47.  
  48. SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  49. function SlashCmdList.MMBHIDE(msg, editbox)
  50.   MBicon:Hide("MNMiniMapButton")
  51.   db.show["HideMMB"] = true
  52.   print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  53. end
  54.  
  55. local miniButton = {
  56.   text = "MapNotes",
  57.   type = "data source",
  58.   icon = "Interface\\AddOns\\HandyNotes_MapNotes\\Images\\MN_Logo",
  59.   OnTooltipShow = function(tooltip)
  60.   if not tooltip or not tooltip.AddLine then return end
  61.   tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
  62.   end,
  63.   OnClick = function(self, button)
  64.     if button == "RightButton" then
  65.       LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  66.     end
  67.     if IsShiftKeyDown() and button == "RightButton" then
  68.       MBicon:Hide("MNMiniMapButton")
  69.       db.show["HideMMB"] = true
  70.       print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  71.     end
  72.     if button == "LeftButton" then
  73.       LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  74.       print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  75.     end
  76. end}
  77.  
  78. function MapNotesMiniButton:OnInitialize()
  79.   self.db = LibStub("AceDB-3.0"):New("MNMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  80.   MBicon:Register("MNMiniMapButton", miniButton, self.db.profile.minimap)
  81. end
  82.  
  83. local function updateAssignedID()
  84.     table.wipe(assignedIDs)
  85.     for i=1,GetNumSavedInstances() do
  86.         local name, _, _, _, locked, _, _, _, _, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(i)
  87.         if (locked) then
  88.             if (not assignedIDs[name]) then
  89.             assignedIDs[name] = { }
  90.             end
  91.             assignedIDs[name][difficultyName] = encounterProgress .. "/" .. numEncounters
  92.         end
  93.     end
  94. end
  95.  
  96. local pluginHandler = { }
  97. function pluginHandler:OnEnter(uiMapId, coord)
  98.   local nodeData = nil
  99.  
  100.     if (minimap[uiMapId] and minimap[uiMapId][coord]) then
  101.       nodeData = minimap[uiMapId][coord]
  102.     end
  103.     if (nodes[uiMapId] and nodes[uiMapId][coord]) then
  104.       nodeData = nodes[uiMapId][coord]
  105.     end
  106.    
  107.     if (not nodeData) then return end
  108.    
  109.     local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
  110.     if ( self:GetCenter() > UIParent:GetCenter() ) then
  111.       tooltip:SetOwner(self, "ANCHOR_LEFT")
  112.     else
  113.         tooltip:SetOwner(self, "ANCHOR_RIGHT")
  114.     end
  115.  
  116.     if (not nodeData.name) then return end
  117.  
  118.     local instances = { strsplit("\n", nodeData.name) }
  119.    
  120.  
  121.     updateAssignedID()
  122.    
  123.     for i, v in pairs(instances) do
  124.       if (db.assignedID and (assignedIDs[v] or (lfgIDs[v] and assignedIDs[lfgIDs[v]]))) then
  125.         if (assignedIDs[v]) then
  126.           for a,b in pairs(assignedIDs[v]) do
  127.             tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  128.           end
  129.         end
  130.       if (lfgIDs[v] and assignedIDs[lfgIDs[v]]) then
  131.         for a,b in pairs(assignedIDs[lfgIDs[v]]) do
  132.           tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  133.         end
  134.       end
  135.       else
  136.         tooltip:AddLine(v, nil, nil, nil, false)
  137.       end
  138.     end
  139.     tooltip:Show()
  140. end
  141.  
  142. function pluginHandler:OnLeave(uiMapID, coord)
  143.     if self:GetParent() == WorldMapButton then
  144.       WorldMapTooltip:Hide()
  145.     else
  146.       GameTooltip:Hide()
  147.     end
  148. end
  149.  
  150. do
  151.     local tablepool = setmetatable({}, {__mode = 'k'})
  152.    
  153.     local function deepCopy(object)
  154.         local lookup_table = {}
  155.         local function _copy(object)
  156.             if type(object) ~= "table" then
  157.                 return object
  158.             elseif lookup_table[object] then
  159.                 return lookup_table[object]
  160.             end
  161.  
  162.             local new_table = {}
  163.               lookup_table[object] = new_table
  164.             for index, value in pairs(object) do
  165.                 new_table[_copy(index)] = _copy(value)
  166.             end
  167.  
  168.             return setmetatable(new_table, getmetatable(object))
  169.         end
  170.             return _copy(object)
  171.     end
  172.  
  173.     local function iter(t, prestate)
  174.         if not t then return end
  175.         local data = t.data
  176.  
  177.         local state, value = next(data, prestate)
  178.  
  179.         while value do
  180.             local alpha
  181.            
  182.             local allLocked = true
  183.             local anyLocked = false
  184.             if value.name == nil then value.name = value.id end
  185.             local instances = { strsplit("\n", value.name) }
  186.             for i, v in pairs(instances) do
  187.                 if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  188.                     allLocked = false
  189.                 else
  190.                     anyLocked = true
  191.                 end
  192.             end
  193.  
  194.             local icon = icons[value.type]
  195.             if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID)) then
  196.                 icon = icons["Locked"]
  197.             end
  198.  
  199.             if t.minimapUpdate or value.showInZone then
  200.               return state, nil, icon, db.azerothScale, alpha
  201.             end
  202.      
  203.             state, value = next(data, state)
  204.         end
  205.         wipe(t)
  206.         tablepool[t] = true
  207.     end
  208.  
  209.  
  210.     local function iterCont(t, prestate)
  211.         if not t then return end
  212.     if not db.showContinent then return end
  213.         local zone = t.C[t.Z]
  214.         local data = nodes[zone]
  215.         local state, value
  216.         while zone do
  217.             if data then
  218.                 state, value = next(data, prestate)
  219.                 while state do
  220.                     local icon, alpha
  221.  
  222.                     icon = icons[value.type]
  223.                     local allLocked = true
  224.                     local anyLocked = false
  225.                     local instances = { strsplit("\n", value.name) }
  226.                     for i, v in pairs(instances) do
  227.                         if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  228.                             allLocked = false
  229.                         else
  230.                             anyLocked = true
  231.                         end
  232.                     end
  233.      
  234.                     if ((anyLocked and db.assignedgray) or (allLocked and db.assignedgray)) then  
  235.                         icon = icons["Locked"]
  236.                     end
  237.  
  238.                     if not value.hideOnContinent and db.showContinent then
  239.                         return state, zone, icon, db.continentScale, alpha
  240.           end
  241.                     state, value = next(data, state)
  242.                 end
  243.             end
  244.             t.Z = next(t.C, t.Z)
  245.             zone = t.C[t.Z]
  246.             data = nodes[zone]
  247.             prestate = nil
  248.         end
  249.         wipe(t)
  250.         tablepool[t] = true
  251.     end
  252.  
  253.     function pluginHandler:GetNodes2(uiMapId, isMinimapUpdate, coord)
  254.         local C = deepCopy(HandyNotes:GetContinentZoneList(uiMapId))
  255.         if C then
  256.             table.insert(C, uiMapId)
  257.             local tbl = next(tablepool) or {}
  258.             tablepool[tbl] = nil
  259.             tbl.C = C
  260.             tbl.Z = next(C)
  261.             tbl.contId = uiMapId
  262.             return iterCont, tbl, nil
  263.         else
  264.             if (nodes[uiMapId] == nil) then return iter end
  265.             local tbl = next(tablepool) or {}
  266.             tablepool[tbl] = nil
  267.             tbl.minimapUpdate = isMinimapUpdate
  268.             if (isMinimapUpdate and minimap[uiMapId]) then
  269.                 tbl.data = minimap[uiMapId]
  270.             else
  271.                 tbl.data = nodes[uiMapId]
  272.             end
  273.             return iter, tbl, nil
  274.         end
  275.     end
  276. end
  277.  
  278. local waypoints = {}
  279. local function setWaypoint(uiMapID, coord)
  280.     local dungeon = nodes[uiMapID][coord]
  281.  
  282.     local waypoint = nodes[dungeon]
  283.     if waypoint and TomTom:IsValidWaypoint(waypoint) then
  284.         return
  285.     end
  286.  
  287.     local title = dungeon.name
  288.     local x, y = HandyNotes:getXY(coord)
  289.     waypoints[dungeon] = TomTom:AddWaypoint(uiMapID, x, y, {
  290.         title = dungeon.name,
  291.         persistent = nil,
  292.         minimap = true,
  293.         world = true
  294.     })
  295. end
  296.  
  297. function pluginHandler:OnClick(button, pressed, uiMapId, coord)
  298.     if (not pressed) then return end
  299.     if IsShiftKeyDown() and (button == "RightButton" and db.tomtom and TomTom) then
  300.         setWaypoint(uiMapId, coord)
  301.         return
  302.         end
  303.     if (button == "LeftButton" and db.journal) then
  304.         if (not EncounterJournal_OpenJournal) then
  305.         UIParentLoadAddOn('Blizzard_EncounterJournal')
  306.         end
  307.         local dungeonID
  308.         if (type(nodes[uiMapId][coord].id) == "table") then
  309.             dungeonID = nodes[uiMapId][coord].id[1]
  310.         else
  311.             dungeonID = nodes[uiMapId][coord].id
  312.         end
  313.  
  314.         if (not dungeonID) then return end
  315.  
  316.         local name, _, _, _, _, _, _, link = EJ_GetInstanceInfo(dungeonID)
  317.         if not link then return end
  318.         local difficulty = string.match(link, 'journal:.-:.-:(.-)|h')
  319.         if (not dungeonID or not difficulty) then return end
  320.         EncounterJournal_OpenJournal(difficulty, dungeonID)
  321.         _G.EncounterJournal:SetScript("OnShow", BBBEncounterJournal_OnShow)
  322.     end
  323. end
  324.  
  325. local defaults = {
  326.   profile = {
  327.       show = {
  328.       },
  329.  
  330.     --1
  331.       hideAddon = false,
  332.       hideMMB = false,
  333.   },
  334. }
  335.  
  336. local Addon = CreateFrame("Frame")
  337. Addon:RegisterEvent("PLAYER_LOGIN")
  338. Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...)end)
  339.  
  340. local function updateStuff()
  341.   updateAssignedID()
  342.   HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  343. end
  344.  
  345. function Addon:PLAYER_ENTERING_WORLD()
  346.   if (not self.faction) then
  347.       self.faction = UnitFactionGroup("player")
  348.       self:PopulateTable()
  349.       self:PopulateMinimap()
  350.       self:ProcessTable()
  351.   end
  352.  
  353.     updateAssignedID()
  354.     updateStuff()
  355. end
  356.  
  357. function Addon:PLAYER_LOGIN()
  358.   local options = {
  359.     type = "group",
  360.     name = "|cffff0000Map|r|cff00ccffNotes|r",
  361.     childGroups = "tab",
  362.     desc = L["Shows locations of raids, dungeons, portals ,ship and zeppelins symbols on different maps"],
  363.     get = function(info) return db[info[#info]] end,
  364.     set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes") end,
  365.     args = {  
  366.       GeneralTab = {
  367.         type = "group",
  368.         name = L["General"],
  369.         desc = L["General settings that apply to Azeroth / Continent / Dungeon map at the same time"],
  370.         order = 0,
  371.         args = {
  372.           hideMapNotesMMB = {
  373.             type = "header",
  374.             name = L["Hide MapNotes / Hide Minimap Button"],
  375.             order = 1,
  376.             },
  377.           hideAddon = {
  378.             type = "toggle",
  379.             name = "|cffff0000" .. L["hide MapNotes!"] .."\n",
  380.             desc = L["Disable MapNotes, all icons will be hidden on each map and all categories will be disabled"],
  381.             order = 1.2,
  382.             get = function() return db.show["HideMapNote"] end,
  383.             set = function(info, v) db.show["HideMapNote"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  384.                   if db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cffff0000 ".. L["All MapNotes symbols have been hidden"]) else
  385.                   if not db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cff00ff00 ".. L["All set symbols have been restored"]) end end end,
  386.             },  
  387.           hideMMB = {
  388.             type = "toggle",
  389.             name = "|cffff0000" .. "" .. L["hide minimap button"],
  390.             desc = L["Hide the minimap button on the minimap"],
  391.             order = 1.3,
  392.             width = 1.89,
  393.             get = function() return db.show["HideMMB"] end,
  394.             set = function(info, v) db.show["HideMMB"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  395.               if not db.show["HideMMB"] then MBicon:Show("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"]) else
  396.               if db.show["HideMMB"] then MBicon:Hide("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"]) end end end,
  397.             },
  398.         }
  399.       }
  400.     }
  401.   }
  402.  
  403.   HandyNotes:RegisterPluginDB("MapNotes", pluginHandler, options)
  404.   self.db = LibStub("AceDB-3.0"):New("HandyNotes_MapNotesDB", defaults, true)
  405.   db = self.db.profile
  406.   LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MNMiniMapButton", options)
  407.   Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  408.   if db.show["HideMMB"] then
  409.     MBicon:Hide("MNMiniMapButton")
  410.   end
  411. end
  412.  
  413. function Addon:PopulateMinimap()
  414.     local temp = { }
  415.     for k,v in pairs(nodes) do
  416.         if (minimap[k]) then
  417.             for a,b in pairs(minimap[k]) do
  418.                 temp[a] = true
  419.             end
  420.             for c,d in pairs(v) do
  421.                 if (not temp[c] and not d.hideOnMinimap) then
  422.                     minimap[k][c] = d
  423.                 end
  424.             end
  425.         end
  426.     end
  427. end
  428.  
  429. function Addon:PopulateTable()
  430.   table.wipe(nodes)
  431.   table.wipe(minimap)
  432. end
  433.  
  434. function Addon:UpdateInstanceNames(node)
  435.   local dungeonInfo = EJ_GetInstanceInfo
  436.     local id = node.id
  437.  
  438.       if (node.lfgid) then
  439.         dungeonInfo = GetLFGDungeonInfo
  440.         id = node.lfgid
  441.       end
  442.  
  443.       if (type(id) == "table") then
  444.         for i,v in pairs(node.id) do
  445.           local name = dungeonInfo(v)
  446.             self:UpdateAlter(v, name)
  447.           if (node.name) then
  448.             node.name = node.name .. "\n" .. name
  449.           else
  450.             node.name = name
  451.           end
  452.         end
  453.       elseif (id) then
  454.         node.name = dungeonInfo(id)
  455.         self:UpdateAlter(id, node.name)
  456.       end
  457. end
  458.  
  459. function Addon:ProcessTable()
  460.   table.wipe(lfgIDs)
  461.  
  462.  
  463.   function Addon:UpdateAlter(id, name)
  464.     if (lfgIDs[id]) then
  465.       local lfgIDs1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, lfgIDs2 = GetLFGDungeonInfo(lfgIDs[id])
  466.         if (lfgIDs2 and lfgIDs1 == name) then
  467.           lfgIDs1 = lfgIDs2
  468.         end
  469.  
  470.       if (lfgIDs1) then
  471.         if (lfgIDs1 == name) then
  472.         else
  473.         lfgIDs[id] = nil
  474.         lfgIDs[name] = lfgIDs1
  475.         end
  476.       end
  477.     end
  478.   end
  479.  
  480.   for i,v in pairs(nodes) do
  481.     for j,u in pairs(v) do
  482.       self:UpdateInstanceNames(u)
  483.     end
  484.   end
  485.  
  486.   for i,v in pairs(minimap) do
  487.     for j,u in pairs(v) do
  488.       if (not u.name) then
  489.         self:UpdateInstanceNames(u)
  490.       end
  491.     end
  492.   end
  493. end
  494.  
  495. function Addon:FullUpdate()
  496.   self:PopulateTable()
  497.   self:PopulateMinimap()
  498.   self:ProcessTable()
  499. end
  Reply With Quote
12-22-23, 06:42 AM   #9
Ssesmar
A Deviate Faerie Dragon
Join Date: Oct 2023
Posts: 15
I'm trying to split my code into multiple files, this is the first time I've ever done this. If I move it to another file, the open/close chat commands work fine without any errors. There is an error in the MBSHOW/MBHIDE commands. Although the commands are executed correctly, the minimap button is displayed or hidden. But these chat commands are not saved permanently (the function) and I also get this
Code:
error:modules/chatcommands.lua:37: attempt to index field 'show' (a nil value)
here are my files:

toc:
Code:
modules\defaults.lua 
modules\mmb.lua
modules\chatcommands.lua
defaults.lua and mmb.lua working fine without errors.

chatcommands.lua:
Lua Code:
  1. local ADDON_NAME, ns = ...
  2.  
  3. local L = LibStub("AceLocale-3.0"):GetLocale(ADDON_NAME)
  4. local COLORED_ADDON_NAME = "|cffff0000Map|r|cff00ccffNotes|r"
  5. local MNMMBIcon = LibStub("LibDBIcon-1.0", true)
  6.  
  7. local db = { }
  8.  
  9. SLASH_INFO1, SLASH_INFO2, SLASH_INFO3, SLASH_INFO4, SLASH_INFO5, SLASH_INFO6, SLASH_INFO7, SLASH_INFO8 , SLASH_INFO09 = "/mn", "/MN", "/mapnotes", "/MAPNOTES", "/mnhelp", "/MNHELP", "/mnh", "/MNH", "/handynotes_mapnotes";
  10. function SlashCmdList.INFO(msg, editbox)
  11.   print("|cff00ccff".."------------------------------------------------------------------------------------------")
  12.   print("|cffffff00~~"..COLORED_ADDON_NAME .. "|cffffff00~~")
  13.   print("|cffffff00".. L["Chat commands:"])
  14.   print("|cffffff00                       ".. L["to open MapNotes menu: /mno, /MNO"])
  15.   print("|cffffff00                       ".. L["to close MapNotes menu: /mnc, /MNC"])
  16.   print("|cffffff00                       ".. L["to show minimap button: /mnb or /MNB"])
  17.   print("|cffffff00                       ".. L["to hide minimap button: /mnbh or /MNBH"])
  18.   print("|cffffff00~~"..COLORED_ADDON_NAME .. "|cffffff00~~")
  19.   print("|cff00ccff".."------------------------------------------------------------------------------------------")
  20. end
  21.  
  22. SLASH_OPEN1, SLASH_OPEN2 = "/mno", "/MNO";
  23. function SlashCmdList.OPEN(msg, editbox)
  24.   LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
  25.   print(COLORED_ADDON_NAME.."|cffffff00  ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
  26. end
  27.  
  28. SLASH_CLOSE1, SLASH_CLOSE2 = "/mnc", "/MNC";
  29. function SlashCmdList.CLOSE(msg, editbox)
  30.   LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
  31.   print(COLORED_ADDON_NAME.."|cffffff00  ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
  32. end
  33.  
  34. SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
  35. function SlashCmdList.MMBSHOW(msg, editbox)
  36.   MNMMBIcon:Show("MNMiniMapButton")
  37.   db.show.HideMMB = false
  38.   print(COLORED_ADDON_NAME .. "|cffffff00  " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"])
  39. end
  40.  
  41. SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
  42. function SlashCmdList.MMBHIDE(msg, editbox)
  43.   MNMMBIcon:Hide("MNMiniMapButton")
  44.   db.show.HideMMB = true
  45.   print(COLORED_ADDON_NAME .. "|cffffff00  " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
  46. end

and the main file:

Lua Code:
  1. local ADDON_NAME, ns = ...
  2.  
  3. local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes", true)
  4. if not HandyNotes then return end
  5.  
  6. local ADDON_NAME = "HandyNotes_MapNotes"
  7. local MapNotesMiniButton = LibStub("AceAddon-3.0"):NewAddon("MNMiniMapButton", "AceConsole-3.0")  
  8. local MNMMBIcon = LibStub("LibDBIcon-1.0", true)
  9.  
  10.  
  11. local db = { }
  12. local nodes = { }
  13. local minimap = { }
  14. local lfgIDs = { }
  15. local assignedIDs = { }
  16.  
  17.  
  18. function MapNotesMiniButton:OnInitialize()
  19.   self.db = LibStub("AceDB-3.0"):New("MNMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
  20.   MNMMBIcon:Register("MNMiniMapButton", ns.miniButton, self.db.profile.minimap)
  21. end
  22.  
  23. local function updateAssignedID()
  24.     table.wipe(assignedIDs)
  25.     for i=1,GetNumSavedInstances() do
  26.         local name, _, _, _, locked, _, _, _, _, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(i)
  27.         if (locked) then
  28.             if (not assignedIDs[name]) then
  29.             assignedIDs[name] = { }
  30.             end
  31.             assignedIDs[name][difficultyName] = encounterProgress .. "/" .. numEncounters
  32.         end
  33.     end
  34. end
  35.  
  36. local pluginHandler = { }
  37. function pluginHandler:OnEnter(uiMapId, coord)
  38.   local nodeData = nil
  39.  
  40.     if (minimap[uiMapId] and minimap[uiMapId][coord]) then
  41.       nodeData = minimap[uiMapId][coord]
  42.     end
  43.     if (nodes[uiMapId] and nodes[uiMapId][coord]) then
  44.       nodeData = nodes[uiMapId][coord]
  45.     end
  46.    
  47.     if (not nodeData) then return end
  48.    
  49.     local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
  50.     if ( self:GetCenter() > UIParent:GetCenter() ) then
  51.       tooltip:SetOwner(self, "ANCHOR_LEFT")
  52.     else
  53.         tooltip:SetOwner(self, "ANCHOR_RIGHT")
  54.     end
  55.  
  56.     if (not nodeData.name) then return end
  57.  
  58.     local instances = { strsplit("\n", nodeData.name) }
  59.    
  60.  
  61.     updateAssignedID()
  62.    
  63.     for i, v in pairs(instances) do
  64.       if (db.assignedID and (assignedIDs[v] or (lfgIDs[v] and assignedIDs[lfgIDs[v]]))) then
  65.         if (assignedIDs[v]) then
  66.           for a,b in pairs(assignedIDs[v]) do
  67.             tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  68.           end
  69.         end
  70.       if (lfgIDs[v] and assignedIDs[lfgIDs[v]]) then
  71.         for a,b in pairs(assignedIDs[lfgIDs[v]]) do
  72.           tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
  73.         end
  74.       end
  75.       else
  76.         tooltip:AddLine(v, nil, nil, nil, false)
  77.       end
  78.     end
  79.     tooltip:Show()
  80. end
  81.  
  82. function pluginHandler:OnLeave(uiMapID, coord)
  83.     if self:GetParent() == WorldMapButton then
  84.       WorldMapTooltip:Hide()
  85.     else
  86.       GameTooltip:Hide()
  87.     end
  88. end
  89.  
  90. do
  91.     local tablepool = setmetatable({}, {__mode = 'k'})
  92.    
  93.     local function deepCopy(object)
  94.         local lookup_table = {}
  95.         local function _copy(object)
  96.             if type(object) ~= "table" then
  97.                 return object
  98.             elseif lookup_table[object] then
  99.                 return lookup_table[object]
  100.             end
  101.  
  102.             local new_table = {}
  103.               lookup_table[object] = new_table
  104.             for index, value in pairs(object) do
  105.                 new_table[_copy(index)] = _copy(value)
  106.             end
  107.  
  108.             return setmetatable(new_table, getmetatable(object))
  109.         end
  110.             return _copy(object)
  111.     end
  112.  
  113.     local function iter(t, prestate)
  114.         if not t then return end
  115.         local data = t.data
  116.  
  117.         local state, value = next(data, prestate)
  118.  
  119.         while value do
  120.  
  121.       local alpha
  122.            
  123.             local allLocked = true
  124.             local anyLocked = false
  125.             if value.name == nil then value.name = value.id end
  126.             local instances = { strsplit("\n", value.name) }
  127.             for i, v in pairs(instances) do
  128.                 if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  129.                     allLocked = false
  130.                 else
  131.                     anyLocked = true
  132.                 end
  133.             end
  134.  
  135.             local icon = icons[value.type]
  136.             if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID)) then
  137.                 icon = icons["Locked"]
  138.             end
  139.  
  140.       if ((anyLocked and db.invertlockout) or (allLocked and not db.invertlockout) and db.uselockoutalpha) then
  141.                 alpha = db.mapnoteAlpha
  142.             else
  143.                 alpha = db.mapnoteAlpha
  144.             end
  145.  
  146.       if db.show.Azeroth then
  147.               return state, nil, icon, db.mapnoteScale, alpha
  148.             end
  149.             state, value = next(data, state)
  150.         end
  151.         wipe(t)
  152.         tablepool[t] = true
  153.     end
  154.  
  155.  
  156.     local function iterCont(t, prestate)
  157.         if not t then return end
  158.  
  159.     local zone = t.C[t.Z]
  160.         local data = nodes[zone]
  161.         local state, value
  162.  
  163.         while zone do
  164.             if data then
  165.                 state, value = next(data, prestate)
  166.  
  167.                 while state do
  168.           local icon, alpha
  169.  
  170.                     local allLocked = true
  171.                     local anyLocked = false
  172.           --
  173.                     local instances = { strsplit("\n", value.name) }
  174.                     for i, v in pairs(instances) do
  175.                         if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
  176.                             allLocked = false
  177.                         else
  178.                             anyLocked = true
  179.                         end
  180.                     end
  181.  
  182.           icon = icons[value.type]
  183.                     if ((anyLocked and db.assignedgray) or (allLocked and db.assignedgray)) then  
  184.                         icon = icons["Locked"]
  185.                     end
  186.           if ((anyLocked and db.invertlockout) or (allLocked and not db.invertlockout) and db.uselockoutalpha) then
  187.                         alpha = db.mapnoteAlpha
  188.                     else
  189.                         alpha = db.mapnoteAlpha
  190.                     end
  191.  
  192.                     if db.show.Continent then
  193.                         return state, zone, icon, db.mapnoteScale, alpha
  194.           end
  195.                     state, value = next(data, state)
  196.                 end
  197.             end
  198.             t.Z = next(t.C, t.Z)
  199.             zone = t.C[t.Z]
  200.             data = nodes[zone]
  201.             prestate = nil
  202.         end
  203.         wipe(t)
  204.         tablepool[t] = true
  205.     end
  206.  
  207.     function pluginHandler:GetNodes2(uiMapId, isMinimapUpdate, coord)
  208.         local C = deepCopy(HandyNotes:GetContinentZoneList(uiMapId))
  209.         if C then
  210.             table.insert(C, uiMapId)
  211.             local tbl = next(tablepool) or {}
  212.             tablepool[tbl] = nil
  213.             tbl.C = C
  214.             tbl.Z = next(C)
  215.             tbl.contId = uiMapId
  216.             return iterCont, tbl, nil
  217.         else
  218.             if (nodes[uiMapId] == nil) then return iter end
  219.             local tbl = next(tablepool) or {}
  220.             tablepool[tbl] = nil
  221.             tbl.minimapUpdate = isMinimapUpdate
  222.             if (isMinimapUpdate and minimap[uiMapId]) then
  223.                 tbl.data = minimap[uiMapId]
  224.             else
  225.                 tbl.data = nodes[uiMapId]
  226.             end
  227.             return iter, tbl, nil
  228.         end
  229.     end
  230. end
  231.  
  232. local waypoints = {}
  233. local function setWaypoint(uiMapID, coord)
  234.     local dungeon = nodes[uiMapID][coord]
  235.  
  236.     local waypoint = nodes[dungeon]
  237.     if waypoint and TomTom:IsValidWaypoint(waypoint) then
  238.         return
  239.     end
  240.  
  241.     local title = dungeon.name
  242.     local x, y = HandyNotes:getXY(coord)
  243.     waypoints[dungeon] = TomTom:AddWaypoint(uiMapID, x, y, {
  244.         title = dungeon.name,
  245.         persistent = nil,
  246.         minimap = true,
  247.         world = true
  248.     })
  249. end
  250.  
  251. function pluginHandler:OnClick(button, pressed, uiMapId, coord)
  252.     if (not pressed) then return end
  253.     if IsShiftKeyDown() and (button == "RightButton" and db.tomtom and TomTom) then
  254.         setWaypoint(uiMapId, coord)
  255.         return
  256.         end
  257.     if (button == "LeftButton" and db.journal) then
  258.         if (not EncounterJournal_OpenJournal) then
  259.         UIParentLoadAddOn('Blizzard_EncounterJournal')
  260.         end
  261.         local dungeonID
  262.         if (type(nodes[uiMapId][coord].id) == "table") then
  263.             dungeonID = nodes[uiMapId][coord].id[1]
  264.         else
  265.             dungeonID = nodes[uiMapId][coord].id
  266.         end
  267.  
  268.         if (not dungeonID) then return end
  269.  
  270.         local name, _, _, _, _, _, _, link = EJ_GetInstanceInfo(dungeonID)
  271.         if not link then return end
  272.         local difficulty = string.match(link, 'journal:.-:.-:(.-)|h')
  273.         if (not dungeonID or not difficulty) then return end
  274.         EncounterJournal_OpenJournal(difficulty, dungeonID)
  275.         _G.EncounterJournal:SetScript("OnShow", BBBEncounterJournal_OnShow)
  276.     end
  277. end
  278.  
  279. local Addon = CreateFrame("Frame")
  280. Addon:RegisterEvent("PLAYER_LOGIN")
  281. Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...)end)
  282.  
  283. local function updateStuff()
  284.   updateAssignedID()
  285.   HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
  286. end
  287.  
  288. function Addon:PLAYER_ENTERING_WORLD()
  289.   if (not self.faction) then
  290.       self.faction = UnitFactionGroup("player")
  291.       self:PopulateTable()
  292.       self:PopulateMinimap()
  293.       self:ProcessTable()
  294.   end
  295.  
  296.     updateAssignedID()
  297.     updateStuff()
  298. end
  299.  
  300. function Addon:PLAYER_LOGIN()
  301.  
  302.   HandyNotes:RegisterPluginDB("MapNotes", pluginHandler, ns.options)
  303.   self.db = LibStub("AceDB-3.0"):New(ADDON_NAME .. "DB", ns.defaults, true)
  304.   db = self.db.profile
  305.   Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
  306.   LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MNMiniMapButton", ns.options)
  307.   if db.show.HideMMB then
  308.     MNMMBIcon:Hide("MNMiniMapButton")
  309.   end
  310. end
  311.  
  312. function Addon:PopulateMinimap()
  313.     local temp = { }
  314.     for k,v in pairs(nodes) do
  315.         if (minimap[k]) then
  316.             for a,b in pairs(minimap[k]) do
  317.                 temp[a] = true
  318.             end
  319.             for c,d in pairs(v) do
  320.                 if (not temp[c] and not d.hideOnMinimap) then
  321.                     minimap[k][c] = d
  322.                 end
  323.             end
  324.         end
  325.     end
  326. end
  327.  
  328. function Addon:UpdateInstanceNames(node)
  329.   local dungeonInfo = EJ_GetInstanceInfo
  330.     local id = node.id
  331.  
  332.       if (node.lfgid) then
  333.         dungeonInfo = GetLFGDungeonInfo
  334.         id = node.lfgid
  335.       end
  336.  
  337.       if (type(id) == "table") then
  338.         for i,v in pairs(node.id) do
  339.           local name = dungeonInfo(v)
  340.             self:UpdateAlter(v, name)
  341.           if (node.name) then
  342.             node.name = node.name .. "\n" .. name
  343.           else
  344.             node.name = name
  345.           end
  346.         end
  347.       elseif (id) then
  348.         node.name = dungeonInfo(id)
  349.         self:UpdateAlter(id, node.name)
  350.       end
  351. end
  352.  
  353. function Addon:FullUpdate()
  354.   self:PopulateTable()
  355.   self:PopulateMinimap()
  356.   self:ProcessTable()
  357. end

maybe someone can help me, I'm currently stuck on how to connect
Code:
db.show.HideMMB = false
or
Code:
db.show.HideMMB = true
to the main file. So that the "show" functions work
  Reply With Quote
12-22-23, 09:35 AM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,813
In both the code files you have
Code:
local db = {}
This is creating distinctly different db variables.

In the main file add db to your ns table and get it from there in the ChatCommands.lua file.

Or use MapNotesMiniButton.db in the ChatCommands.lua file, whichever db is the right one and is available in both files either via a global or the ns table.

A quick look further and in the main file you're creating
Code:
local db = {}
and then throwing it away in PLAYER_LOGIN and replacing it with
Code:
db = self.db.profile
Where self is Addon. Which means Addon should be added to your ns table and in ChatCommands use:
Code:
local db = NS.Addon.db
or give the frame a name and use that.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-22-23 at 10:56 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » minimap button created with LibDBIcon need help

Thread Tools
Display Modes

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