View Single Post
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