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