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