--## SavedVariables: HandyNotes_MapNotesDB
local HandyNotes = LibStub("AceAddon-3.0"):GetAddon("HandyNotes", true)
if not HandyNotes then return end
local L = LibStub("AceLocale-3.0"):GetLocale("HandyNotes_MapNotes")
local MBicon = LibStub("LibDBIcon-1.0", true)
local MapNotesMiniButton = LibStub("AceAddon-3.0"):NewAddon("MNMiniMapButton", "AceConsole-3.0")
local db = { }
local icons = { }
local nodes = { }
local minimap = { }
local lfgIDs = { }
local assignedIDs = { }
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";
function SlashCmdList.INFO(msg, editbox)
print("|cff00ccff".."------------------------------------------------------------------------------------------")
print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
print("|cffffff00".. L["Chat commands:"])
print("|cffffff00 • ".. L["to open MapNotes menu: /mno, /MNO"])
print("|cffffff00 • ".. L["to close MapNotes menu: /mnc, /MNC"])
print("|cffffff00 • ".. L["to show minimap button: /mnb or /MNB"])
print("|cffffff00 • ".. L["to hide minimap button: /mnbh or /MNBH"])
print("|cffffff00~~".."|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00~~")
print("|cff00ccff".."------------------------------------------------------------------------------------------")
end
SLASH_OPEN1, SLASH_OPEN2 = "/mno", "/MNO";
function SlashCmdList.OPEN(msg, editbox)
LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
end
SLASH_CLOSE1, SLASH_CLOSE2 = "/mnc", "/MNC";
function SlashCmdList.CLOSE(msg, editbox)
LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cffff0000" .. L["is deactivated"])
end
SLASH_MMBSHOW1, SLASH_MMBSHOW2 = "/mnb", "/MNB";
function SlashCmdList.MMBSHOW(msg, editbox)
MBicon:Show("MNMiniMapButton")
db.show["HideMMB"] = false
print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"])
end
SLASH_MMBHIDE1, SLASH_MMBHIDE2 = "/mnbh", "/MNBH";
function SlashCmdList.MMBHIDE(msg, editbox)
MBicon:Hide("MNMiniMapButton")
db.show["HideMMB"] = true
print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
end
local miniButton = {
text = "MapNotes",
type = "data source",
icon = "Interface\\AddOns\\HandyNotes_MapNotes\\Images\\MN_Logo",
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:AddLine("|cffff0000Map|r|cff00ccffNotes|r")
end,
OnClick = function(self, button)
if button == "RightButton" then
LibStub("AceConfigDialog-3.0"):Close("MNMiniMapButton")
end
if IsShiftKeyDown() and button == "RightButton" then
MBicon:Hide("MNMiniMapButton")
db.show["HideMMB"] = true
print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"])
end
if button == "LeftButton" then
LibStub("AceConfigDialog-3.0"):Open("MNMiniMapButton")
print("|cffff0000Map|r|cff00ccffNotes|r".."|cffffff00 • ".. L["MapNotes menu window"], "|cff00ff00" .. L["is activated"])
end
end}
function MapNotesMiniButton:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MNMiniMapButtonDB", { profile = { minimap = { hide = false, }, }, })
MBicon:Register("MNMiniMapButton", miniButton, self.db.profile.minimap)
end
local function updateAssignedID()
table.wipe(assignedIDs)
for i=1,GetNumSavedInstances() do
local name, _, _, _, locked, _, _, _, _, difficultyName, numEncounters, encounterProgress = GetSavedInstanceInfo(i)
if (locked) then
if (not assignedIDs[name]) then
assignedIDs[name] = { }
end
assignedIDs[name][difficultyName] = encounterProgress .. "/" .. numEncounters
end
end
end
local pluginHandler = { }
function pluginHandler:OnEnter(uiMapId, coord)
local nodeData = nil
if (minimap[uiMapId] and minimap[uiMapId][coord]) then
nodeData = minimap[uiMapId][coord]
end
if (nodes[uiMapId] and nodes[uiMapId][coord]) then
nodeData = nodes[uiMapId][coord]
end
if (not nodeData) then return end
local tooltip = self:GetParent() == WorldMapButton and WorldMapTooltip or GameTooltip
if ( self:GetCenter() > UIParent:GetCenter() ) then
tooltip:SetOwner(self, "ANCHOR_LEFT")
else
tooltip:SetOwner(self, "ANCHOR_RIGHT")
end
if (not nodeData.name) then return end
local instances = { strsplit("\n", nodeData.name) }
updateAssignedID()
for i, v in pairs(instances) do
if (db.assignedID and (assignedIDs[v] or (lfgIDs[v] and assignedIDs[lfgIDs[v]]))) then
if (assignedIDs[v]) then
for a,b in pairs(assignedIDs[v]) do
tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
end
end
if (lfgIDs[v] and assignedIDs[lfgIDs[v]]) then
for a,b in pairs(assignedIDs[lfgIDs[v]]) do
tooltip:AddDoubleLine(v, a .. " " .. b, 1, 1, 1, 1, 1, 1)
end
end
else
tooltip:AddLine(v, nil, nil, nil, false)
end
end
tooltip:Show()
end
function pluginHandler:OnLeave(uiMapID, coord)
if self:GetParent() == WorldMapButton then
WorldMapTooltip:Hide()
else
GameTooltip:Hide()
end
end
do
local tablepool = setmetatable({}, {__mode = 'k'})
local function deepCopy(object)
local lookup_table = {}
local function _copy(object)
if type(object) ~= "table" then
return object
elseif lookup_table[object] then
return lookup_table[object]
end
local new_table = {}
lookup_table[object] = new_table
for index, value in pairs(object) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(object))
end
return _copy(object)
end
local function iter(t, prestate)
if not t then return end
local data = t.data
local state, value = next(data, prestate)
while value do
local alpha
local allLocked = true
local anyLocked = false
if value.name == nil then value.name = value.id end
local instances = { strsplit("\n", value.name) }
for i, v in pairs(instances) do
if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
allLocked = false
else
anyLocked = true
end
end
local icon = icons[value.type]
if ((anyLocked and db.graymultipleID) or (allLocked and not db.graymultipleID)) then
icon = icons["Locked"]
end
if t.minimapUpdate or value.showInZone then
return state, nil, icon, db.azerothScale, alpha
end
state, value = next(data, state)
end
wipe(t)
tablepool[t] = true
end
local function iterCont(t, prestate)
if not t then return end
if not db.showContinent then return end
local zone = t.C[t.Z]
local data = nodes[zone]
local state, value
while zone do
if data then
state, value = next(data, prestate)
while state do
local icon, alpha
icon = icons[value.type]
local allLocked = true
local anyLocked = false
local instances = { strsplit("\n", value.name) }
for i, v in pairs(instances) do
if (not assignedIDs[v] and not assignedIDs[lfgIDs[v]]) then
allLocked = false
else
anyLocked = true
end
end
if ((anyLocked and db.assignedgray) or (allLocked and db.assignedgray)) then
icon = icons["Locked"]
end
if not value.hideOnContinent and db.showContinent then
return state, zone, icon, db.continentScale, alpha
end
state, value = next(data, state)
end
end
t.Z = next(t.C, t.Z)
zone = t.C[t.Z]
data = nodes[zone]
prestate = nil
end
wipe(t)
tablepool[t] = true
end
function pluginHandler:GetNodes2(uiMapId, isMinimapUpdate, coord)
local C = deepCopy(HandyNotes:GetContinentZoneList(uiMapId))
if C then
table.insert(C, uiMapId)
local tbl = next(tablepool) or {}
tablepool[tbl] = nil
tbl.C = C
tbl.Z = next(C)
tbl.contId = uiMapId
return iterCont, tbl, nil
else
if (nodes[uiMapId] == nil) then return iter end
local tbl = next(tablepool) or {}
tablepool[tbl] = nil
tbl.minimapUpdate = isMinimapUpdate
if (isMinimapUpdate and minimap[uiMapId]) then
tbl.data = minimap[uiMapId]
else
tbl.data = nodes[uiMapId]
end
return iter, tbl, nil
end
end
end
local waypoints = {}
local function setWaypoint(uiMapID, coord)
local dungeon = nodes[uiMapID][coord]
local waypoint = nodes[dungeon]
if waypoint and TomTom:IsValidWaypoint(waypoint) then
return
end
local title = dungeon.name
local x, y = HandyNotes:getXY(coord)
waypoints[dungeon] = TomTom:AddWaypoint(uiMapID, x, y, {
title = dungeon.name,
persistent = nil,
minimap = true,
world = true
})
end
function pluginHandler:OnClick(button, pressed, uiMapId, coord)
if (not pressed) then return end
if IsShiftKeyDown() and (button == "RightButton" and db.tomtom and TomTom) then
setWaypoint(uiMapId, coord)
return
end
if (button == "LeftButton" and db.journal) then
if (not EncounterJournal_OpenJournal) then
UIParentLoadAddOn('Blizzard_EncounterJournal')
end
local dungeonID
if (type(nodes[uiMapId][coord].id) == "table") then
dungeonID = nodes[uiMapId][coord].id[1]
else
dungeonID = nodes[uiMapId][coord].id
end
if (not dungeonID) then return end
local name, _, _, _, _, _, _, link = EJ_GetInstanceInfo(dungeonID)
if not link then return end
local difficulty = string.match(link, 'journal:.-:.-:(.-)|h')
if (not dungeonID or not difficulty) then return end
EncounterJournal_OpenJournal(difficulty, dungeonID)
_G.EncounterJournal:SetScript("OnShow", BBBEncounterJournal_OnShow)
end
end
local defaults = {
profile = {
show = {
},
--1
hideAddon = false,
hideMMB = false,
},
}
local Addon = CreateFrame("Frame")
Addon:RegisterEvent("PLAYER_LOGIN")
Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...)end)
local function updateStuff()
updateAssignedID()
HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
end
function Addon:PLAYER_ENTERING_WORLD()
if (not self.faction) then
self.faction = UnitFactionGroup("player")
self:PopulateTable()
self:PopulateMinimap()
self:ProcessTable()
end
updateAssignedID()
updateStuff()
end
function Addon:PLAYER_LOGIN()
local options = {
type = "group",
name = "|cffff0000Map|r|cff00ccffNotes|r",
childGroups = "tab",
desc = L["Shows locations of raids, dungeons, portals ,ship and zeppelins symbols on different maps"],
get = function(info) return db[info[#info]] end,
set = function(info, v) db[info[#info]] = v HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes") end,
args = {
GeneralTab = {
type = "group",
name = L["General"],
desc = L["General settings that apply to Azeroth / Continent / Dungeon map at the same time"],
order = 0,
args = {
hideMapNotesMMB = {
type = "header",
name = L["Hide MapNotes / Hide Minimap Button"],
order = 1,
},
hideAddon = {
type = "toggle",
name = "|cffff0000" .. L["hide MapNotes!"] .."\n",
desc = L["Disable MapNotes, all icons will be hidden on each map and all categories will be disabled"],
order = 1.2,
get = function() return db.show["HideMapNote"] end,
set = function(info, v) db.show["HideMapNote"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
if db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cffff0000 • ".. L["All MapNotes symbols have been hidden"]) else
if not db.show["HideMapNote"] then print("|cffff0000Map|r|cff00ccffNotes|r".."|cff00ff00 • ".. L["All set symbols have been restored"]) end end end,
},
hideMMB = {
type = "toggle",
name = "|cffff0000" .. "" .. L["hide minimap button"],
desc = L["Hide the minimap button on the minimap"],
order = 1.3,
width = 1.89,
get = function() return db.show["HideMMB"] end,
set = function(info, v) db.show["HideMMB"] = v self:FullUpdate() HandyNotes:SendMessage("HandyNotes_NotifyUpdate", "MapNotes")
if not db.show["HideMMB"] then MBicon:Show("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cff00ff00" .. L["is activated"]) else
if db.show["HideMMB"] then MBicon:Hide("MNMiniMapButton") print("|cffff0000Map|r|cff00ccffNotes|r" .. "|cffffff00 • " .. L["-> MiniMapButton <-"], "|cffff0000" .. L["is deactivated"]) end end end,
},
}
}
}
}
HandyNotes:RegisterPluginDB("MapNotes", pluginHandler, options)
self.db = LibStub("AceDB-3.0"):New("HandyNotes_MapNotesDB", defaults, true)
db = self.db.profile
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MNMiniMapButton", options)
Addon:RegisterEvent("PLAYER_ENTERING_WORLD")
if db.show["HideMMB"] then
MBicon:Hide("MNMiniMapButton")
end
end
function Addon:PopulateMinimap()
local temp = { }
for k,v in pairs(nodes) do
if (minimap[k]) then
for a,b in pairs(minimap[k]) do
temp[a] = true
end
for c,d in pairs(v) do
if (not temp[c] and not d.hideOnMinimap) then
minimap[k][c] = d
end
end
end
end
end
function Addon:PopulateTable()
table.wipe(nodes)
table.wipe(minimap)
end
function Addon:UpdateInstanceNames(node)
local dungeonInfo = EJ_GetInstanceInfo
local id = node.id
if (node.lfgid) then
dungeonInfo = GetLFGDungeonInfo
id = node.lfgid
end
if (type(id) == "table") then
for i,v in pairs(node.id) do
local name = dungeonInfo(v)
self:UpdateAlter(v, name)
if (node.name) then
node.name = node.name .. "\n" .. name
else
node.name = name
end
end
elseif (id) then
node.name = dungeonInfo(id)
self:UpdateAlter(id, node.name)
end
end
function Addon:ProcessTable()
table.wipe(lfgIDs)
function Addon:UpdateAlter(id, name)
if (lfgIDs[id]) then
local lfgIDs1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, lfgIDs2 = GetLFGDungeonInfo(lfgIDs[id])
if (lfgIDs2 and lfgIDs1 == name) then
lfgIDs1 = lfgIDs2
end
if (lfgIDs1) then
if (lfgIDs1 == name) then
else
lfgIDs[id] = nil
lfgIDs[name] = lfgIDs1
end
end
end
end
for i,v in pairs(nodes) do
for j,u in pairs(v) do
self:UpdateInstanceNames(u)
end
end
for i,v in pairs(minimap) do
for j,u in pairs(v) do
if (not u.name) then
self:UpdateInstanceNames(u)
end
end
end
end
function Addon:FullUpdate()
self:PopulateTable()
self:PopulateMinimap()
self:ProcessTable()
end