-- Values used often so created variables for them
local addonName = "XrysMapPins"
local addonVersion = "1.0.0"
-- References to System and Manager objects
local ChatMsg = CHAT_SYSTEM
local EventMgr = EVENT_MANAGER
local WindowMgr = WINDOW_MANAGER
----------[[ TradeSkill Info ]]----------------
local TradeSkillNames = {}
local TradeSkills = {}
local function InitTradeSkillInfo()
local skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_ALCHEMY)
local skillName,skillRank = GetSkillLineInfo(skillType, skillIndex)
local abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
TradeSkills[CRAFTING_TYPE_ALCHEMY] = { Name = skillName, Icon = abilityIcon }
skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_BLACKSMITHING)
skillName,skillRank = GetSkillLineInfo(skillType, skillIndex)
abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
TradeSkills[CRAFTING_TYPE_BLACKSMITHING] = { Name = skillName, Icon = abilityIcon }
skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_CLOTHIER)
skillName,skillRank = GetSkillLineInfo(skillType, skillIndex)
abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
TradeSkills[CRAFTING_TYPE_CLOTHIER] = { Name = skillName, Icon = abilityIcon }
skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_ENCHANTING)
skillName,skillRank = GetSkillLineInfo(skillType, skillIndex)
abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
TradeSkills[CRAFTING_TYPE_ENCHANTING] = { Name = skillName, Icon = abilityIcon }
skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_PROVISIONING)
skillName,skillRank = GetSkillLineInfo(skillType, skillIndex)
abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
TradeSkills[CRAFTING_TYPE_PROVISIONING] = { Name = skillName, Icon = abilityIcon }
skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_WOODWORKING)
skillName,skillRank = GetSkillLineInfo(skillType, skillIndex)
abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
TradeSkills[CRAFTING_TYPE_WOODWORKING] = { Name = skillName, Icon = abilityIcon }
for i,v in ipairs(TradeSkills) do
table.insert(TradeSkillNames,v.Name)
end
end
--------------------------------------------------------------
-----------[[ Custom Map Pin Stuff ]]---------------------
local CustomMapPins = ZO_WorldMapPins:Subclass()
function CustomMapPins:New(...)
local pinObject = ZO_WorldMapPins.New(self)
pinObject:Initialise(...)
return pinObject
end
function CustomMapPins:Initialise(...)
--Default Values
self.Type = "unspecified"
self.Name = "Unspecified"
self.TradeSkill = CRAFTING_TYPE_INVALID
self.ItemType = ITEMTYPE_NONE
self.Icon = "EsoUI/Art/MapPins/hostile_pin.dds"
self.Size = 16
self.MinSize = 10
self.Level = 20
self.IsAnimated = false
self.InsetX = 0
self.InsetY = 0
-- Useful data
self.Info = {}
-- [pinID]
-- Type
-- Name
-- Icon
-- Pin Data
self.Data = {}
--[pinType][zone]
-- key
-- zone
-- x
-- y
-- radius
-- Layout Data
self.Layout = {
level = self.Level, texture = self.Icon, size = self.Size, minSize = self.MinSize,
isAnimated = self.IsAnimated, insetX = self.InsetX, insetY = self.InsetY
}
end
function CustomMapPins:List(...)
local pinType, pinZone = ...
ChatMsg:AddMessage("Pin Data currently available for type "..pinType.." in zone "..pinZone)
if not self.Data[pinType] then return end
if not self.Data[pinType][pinZone] then return end
for i,v in pairs(self.Data[pinType][pinZone]) do
ChatMsg:AddMessage(v.zone.." "..tostring(v.x)..", "..tostring(v.y))
end
end
--[[ No special function for this part so assumed it is dealt with by ZO_WorldMapPins version
function CustomMapPins:CreateCustomPinType(...)
end
--]]
function CustomMapPins:CreatePin(...)
local pinType, pinKey, pinZone, pinX, pinY, pinRadius = ...
self.Data[pinType] = self.Data[pinType] or {}
self.Data[pinType][pinZone] = self.Data[pinType][pinZone] or {}
table.insert(self.Data[pinType][pinZone],{
["key"] = pinKey,
["zone"] = pinZone,
["x"] = pinX,
["y"] = pinY,
["radius"] = pinRadius
})
end
function CustomMapPins:AddCustomPin(...)
local pinType, drawCallback, resizeCallback, pinLayout, pinTooltipCreator, pinID = ...
self.Info[pinID] = self.Info[pinID] or {}
table.insert(self.Info[pinID], {
["Type"] = pinType,
["Name"] = TradeSkills[pinID].Name,
["Icon"] = TradeSkills[pinID].Icon
})
ZO_WorldMap_AddCustomPin(pinType, drawCallback, resizeCallback, pinLayout, pinTooltipCreator)
WORLD_MAP_FILTERS.pvePanel:AddPinFilterCheckBox(5, function() self:RefreshPins(pinType) end)
WORLD_MAP_FILTERS.pvePanel.lastControl.label:SetText(GetString("SI_MAPFILTER",5).." ("..TradeSkills[pinID].Name..")")
WORLD_MAP_FILTERS.pvePanel.lastControl:SetState(1)
self:SetCustomPinEnabled( pinType, true )
self:RefreshCustomPins(pinType)
end
--[[ No special function for this part so assumed it is dealt with by ZO_WorldMapPins version
function CustomMapPins:FindPin(...)
end
--]]
--[[ No special function for this part so assumed it is dealt with by ZO_WorldMapPins version
function CustomMapPins:MapPinLookupToPinKey(...)
end
--]]
function CustomMapPins:RefreshCustomPins(...)
ZO_WorldMap_RefreshCustomPinsOfType( ... )
end
function CustomMapPins:RemovePins(...)
local pinType = ...
self.Data[pinType] = {}
self:RefreshPins(pinType)
end
function CustomMapPins:SetCustomPinEnabled(...)
ZO_WorldMap_SetCustomPinEnabled( ... )
end
--[[ No special function for this part so assumed it is dealt with by ZO_WorldMapPins version
function CustomMapPins:UpdatePinsForMapSizeChange(...)
end
--]]
function CustomMapPins:IsCustomPinEnabled(...)
return ZO_WorldMap_IsCustomPinEnabled(...)
end
function CustomMapPins:IsPinGroupShown(...)
return ZO_WorldMap_IsPinGroupShown(...)
end
local XMPins = CustomMapPins:New()
--------------------------------------------------------------
------------------------[[ UI Stuff ]]------------------------
local function CreateTopLevelWindow(name)
local tlw = WindowMgr:CreateTopLevelWindow(name)
tlw:SetMovable(true)
tlw:SetMouseEnabled(true)
tlw:SetDimensions(200,100)
tlw:SetAnchor(CENTER)
tlw.BackGround = WindowMgr:CreateControlFromVirtual(nil,tlw,"ZO_DefaultBackdrop")
tlw.BackGround:SetAnchorFill(tlw)
tlw.BackGround:SetAlpha(0.8)
tlw.BackGround:SetHidden(false)
return tlw
end
local function CreateDropDown(name,parent,data,selected,callback)
local combo = WindowMgr:CreateControlFromVirtual(parent:GetName()..name,parent,"ZO_StatsDropdownRow")
combo:SetAnchor(CENTER)
combo:SetResizeToFitDescendents(true)
combo.selected = combo.name
combo.dropdown = combo.dropdown
combo.dropdown:SetFont("ZoFontBookScroll")
if selected then combo.dropdown:SetSelectedItem(selected) end
combo.dropdown.SetSelectedIndex = function(self,value)
self.SelectedIndex = nil
for i = 1,#data do
if data[i] == value then
self.SelectedIndex = i
break
end
end
end
combo.dropdown.GetSelectedIndex = function(self)
return self.SelectedIndex
end
combo.dropdown.OnSelect = function(self,value)
self:SetSelectedItem(value)
self:SetSelectedIndex(value)
if callback then callback(value) end
end
for i = 1,#data do
local entry = combo.dropdown:CreateItemEntry(data[i],combo.dropdown.OnSelect)
combo.dropdown:AddItem(entry)
end
combo.GetSelectedInfo = function(self)
return self.dropdown:GetSelectedItem(),self.dropdown:GetSelectedIndex()
end
combo:SetHidden(false)
return combo
end
local function CreateButton(name,parent,text,callback)
local button = WindowMgr:CreateControlFromVirtual(parent:GetName()..name,parent,"ZO_DefaultButton")
button:SetAnchor(BOTTOMLEFT)
button:SetHandler("OnClicked",
function(self)
if callback then callback() end
end)
button:SetHidden(false)
return button
end
local function InitUI()
local testTLW = CreateTopLevelWindow("XrysMapPins_TLW")
testTLW:SetDimensions(200,400)
local MapPinCombo = CreateDropDown("MapPinTypes",testTLW,TradeSkillNames,nil,function(value) end)
MapPinCombo:SetDimensions(150,50)
MapPinCombo:SetAnchor(TOP)
local PinTexture = WindowMgr:CreateControl(nil,testTLW,CT_TEXTURE)
PinTexture:SetDimensions(200,200)
PinTexture:SetAnchor(CENTER)
PinTexture:SetHidden(false)
local PutMapPinButton = CreateButton("MapPinButton",testTLW,nil, function(value)
local pinType,pinID = MapPinCombo:GetSelectedInfo()
PinTexture:SetTexture(TradeSkills[pinID].Icon)
SetMapToPlayerLocation()
local pinZone = GetMapName()
local pinX,pinY,pinHeading = GetMapPlayerPosition("player")
local pinTag = { ["id"] = pinID, ["type"] = pinType, ["zone"] = pinZone, ["x"] = pinX, ["y"] = pinY }
XMPins:CreatePin(pinType, pinTag, pinZone, pinX, pinY, nil)
XMPins:RefreshCustomPins(pinType)
XMPins:List(pinType,pinZone)
end )
PutMapPinButton:SetAnchor(BOTTOM)
PutMapPinButton:SetDimensions(50,50)
end
------------------------------------------------------------------------
local function InitPinTypes()
for i,v in ipairs(TradeSkills) do
local pinType = v.Name
local pinID = i
local drawCallback = function() XMPins:RefreshCustomPins(pinType) end
local resizeCallback = function() XMPins:RefreshCustomPins(pinType) end
local pinLayoutData = {}
for i,v in pairs(XMPins.Layout) do
pinLayoutData[i] = v
end
pinLayoutData.texture = TradeSkills[pinID].Icon
local pinTooltipCreator = { creator = function(pin) InformationTooltip:AddLine(TradeSkills[pinID].skillName) end, tooltip = InformationTooltip }
XMPins:AddCustomPin(pinType,drawCallback,resizeCallback,pinLayoutData,pinTooltipCreator,pinID)
end
end
local function PlayerActivated(eventID)
EventMgr:UnregisterForEvent(addonName,eventID)
ChatMsg:AddMessage(string.format("%s %s Loaded",addonName,addonVersion))
InitTradeSkillInfo()
InitUI()
InitPinTypes()
end
-- Our Addon is loaded so we can start work
local function AddOnLoaded(eventID,addon)
if addon ~= addonName then return end
EventMgr:UnregisterForEvent(addonName,eventID)
InitSavedVariables()
EventMgr:RegisterForEvent( addonName ,EVENT_PLAYER_ACTIVATED , PlayerActivated )
end
-- Track addons loading
EventMgr:RegisterForEvent( addonName ,EVENT_ADD_ON_LOADED , AddOnLoaded )