View Single Post
04/10/14, 07:54 PM   #4
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Hmm,

Still not working for me ..

1. Made sure ZO_WorldMap functions used _G[pinType]
2. Made sure pinType was prefixed with something to make it unique
3. Draw Callback function now uses pinManager parameter and cycles through the pinData table and calls pinManager:CreatePin with the data it holds, and removes the RefreshCustomPins function so it doesn't get into that loop ( yes it has happened before, had to crash out a few times ).
4. Set Resize Callback function to nil for the time being
5. Pin Layout table now just has texture, level and size values
6. Added tooltip value to tag/key table to use in the tooltip part of the AddCustomPin function.

Obviously something else is missing in my code somewhere or in the wrong place.

Don't think I missed anything, and did find a few bits of code with the wrong name that clearly isn't being used at present and didn't pick up on it. Here's the updated code with the above changes, minus the code that has been commented out. From your explanation I thought these changes would resolve it but there must be something else. I have tried both MapName and GetUnitZone functions as they sometimes return different values, just in case that was the reason.

My understanding of the functionality is as follows:

1. Subclass an appropriate object ( I have tried both ZO_WorldMapPins and ZO_Object )
2. New the subclassed variable into the usable variable
3. Initialise the pin types including a callback function,texture,tooltip etc and a call to the customised AddCustomPin function to add your data via ZO_WorldMap_AddCustomPin
4. Callback function to cycle through the pin data and create the individual pins at the stored location using the pin manager passed to the function whenever the map is redrawn
5. While still in the initialisation stage initialise the equivalent filters use your customised SetCustomPinEnabled and RefreshCustomPins functions to enable and refresh your pins using the ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType]) and ZO_WorldMap_SetCustomPinEnabled(_G[pinType]) functions.
6. Not got as far as seeing how the RemovePins function works to know where that fits in.

Did I miss anything out ? I hate it when something so apparently simple causes me no end of problems. Especially when I took this week off in the hopes of getting this fixed and catching up with the levelling by actually playing.

Lua Code:
  1. -- Values used often so created variables for them
  2. local addonName = "XrysMapPins"
  3. local addonVersion = "1.0.0"
  4. local addonPrefix = "XMP"
  5.  
  6. -- References to System and Manager objects
  7. local ChatMsg = CHAT_SYSTEM
  8. local EventMgr = EVENT_MANAGER
  9. local WindowMgr = WINDOW_MANAGER
  10.  
  11. --------------------------------------------------------------
  12. local TradeSkillNames = {}
  13. local TradeSkills = {}
  14.  
  15. local function InitTradeSkillInfo()
  16.     local skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_ALCHEMY)
  17.     local skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  18.     local abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  19.     TradeSkills[CRAFTING_TYPE_ALCHEMY] = { Name = skillName, Icon = abilityIcon }
  20.  
  21.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_BLACKSMITHING)
  22.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  23.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  24.     TradeSkills[CRAFTING_TYPE_BLACKSMITHING] =  { Name = skillName, Icon = abilityIcon }
  25.  
  26.  
  27.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_CLOTHIER)
  28.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  29.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  30.     TradeSkills[CRAFTING_TYPE_CLOTHIER] =   { Name = skillName, Icon = abilityIcon }
  31.  
  32.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_ENCHANTING)
  33.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  34.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  35.     TradeSkills[CRAFTING_TYPE_ENCHANTING] =     { Name = skillName, Icon = abilityIcon }
  36.  
  37.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_PROVISIONING)
  38.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  39.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  40.     TradeSkills[CRAFTING_TYPE_PROVISIONING] =   { Name = skillName, Icon = abilityIcon }
  41.    
  42.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_WOODWORKING)
  43.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  44.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  45.     TradeSkills[CRAFTING_TYPE_WOODWORKING] =    { Name = skillName, Icon = abilityIcon }
  46.  
  47.     for i,v in ipairs(TradeSkills) do
  48.         table.insert(TradeSkillNames,v.Name)
  49.     end
  50. end
  51. --------------------------------------------------------------
  52.  
  53. --------------------------------------------------------------
  54. local CustomMapPins = ZO_WorldMapPins:Subclass()
  55.  
  56. function CustomMapPins:New(...)
  57.     local pinObject = ZO_WorldMapPins.New(self)
  58.     pinObject:Initialise(...)
  59.     return pinObject
  60. end
  61.  
  62. function CustomMapPins:Initialise(...)
  63.  
  64.     --Default Values
  65.     self.Type = addonPrefix.."_Unspecified"
  66.     self.Name = "Unspecified"
  67.     self.TradeSkill = CRAFTING_TYPE_INVALID
  68.     self.ItemType = ITEMTYPE_NONE
  69.     self.Icon = "EsoUI/Art/MapPins/hostile_pin.dds"
  70.     self.Size = 16
  71.     self.Level = 20
  72.  
  73.     -- Useful data
  74.     self.Info = {}
  75.  
  76.     -- Pin Data
  77.     self.Data = {}
  78.  
  79.     -- Layout Data
  80.     self.Layout = { level = self.Level, texture = self.Icon, size = self.Size }
  81. end
  82.  
  83. function CustomMapPins:List(...)
  84.     local pinType, pinZone = ...
  85.     ChatMsg:AddMessage("Pin Data currently available for type "..pinType.." in zone "..pinZone)
  86.     if not self.Data[pinType] then return end
  87.     if not self.Data[pinType][pinZone] then return end
  88.     for i,v in pairs(self.Data[pinType][pinZone]) do
  89.         ChatMsg:AddMessage(v.zone.." "..tostring(v.x)..", "..tostring(v.y))
  90.     end
  91. end
  92.  
  93. function CustomMapPins:CreatePin(...)
  94.     local pinType, pinKey, pinZone, pinX, pinY, pinRadius = ...
  95.     self.Data[pinType] = self.Data[pinType] or {}
  96.     self.Data[pinType][pinZone] = self.Data[pinType][pinZone] or {}
  97.     table.insert(self.Data[pinType][pinZone],{
  98.         ["key"] = pinKey,
  99.         ["zone"] = pinZone,
  100.         ["x"] = pinX,
  101.         ["y"] = pinY,
  102.         ["radius"] = pinRadius
  103.     })
  104. end
  105.  
  106.  
  107. function CustomMapPins:AddCustomPin(...)
  108.     local pinType, drawCallback, resizeCallback, pinLayout, pinTooltipCreator, pinID = ...
  109.  
  110.     self.Info[pinID] = self.Info[pinID] or {}
  111.     table.insert(self.Info[pinID], {
  112.         ["Type"] = pinType,
  113.         ["Name"] = TradeSkills[pinID].Name,
  114.         ["Icon"] = TradeSkills[pinID].Icon
  115.         })
  116.  
  117.     ZO_WorldMap_AddCustomPin(pinType, drawCallback, resizeCallback, pinLayout, pinTooltipCreator)
  118.  
  119.     WORLD_MAP_FILTERS.pvePanel:AddPinFilterCheckBox(5, function() self:RefreshCustomPins(pinType) end)     
  120.     WORLD_MAP_FILTERS.pvePanel.lastControl.label:SetText(GetString("SI_MAPFILTER",5).." ("..TradeSkills[pinID].Name..")")
  121.     WORLD_MAP_FILTERS.pvePanel.lastControl:SetState(1)
  122.     self:SetCustomPinEnabled( pinType, true )
  123.     self:RefreshCustomPins(pinType)
  124. end
  125.  
  126. function CustomMapPins:RemovePins(...)
  127.     local pinType = ...
  128.     self.Data[pinType] = {}
  129.     self:RefreshCustomPins(pinType)
  130. end
  131.  
  132. function CustomMapPins:RefreshCustomPins(pinType)
  133.     ZO_WorldMap_RefreshCustomPinsOfType(_G[pinType])
  134. end
  135.  
  136. function CustomMapPins:SetCustomPinEnabled(pinType)
  137.     ZO_WorldMap_SetCustomPinEnabled(_G[pinType])
  138. end
  139.  
  140. function CustomMapPins:IsCustomPinEnabled(pinType)
  141.     return ZO_WorldMap_IsCustomPinEnabled(_G[pinType])
  142. end
  143.  
  144. function CustomMapPins:IsPinGroupShown(pinType)
  145.     return ZO_WorldMap_IsPinGroupShown(_G[pinType])
  146. end
  147.  
  148. local XMPins = CustomMapPins:New()
  149. --------------------------------------------------------------
  150.  
  151. -----------------------------------------------------------------------
  152. local function CreateTopLevelWindow(name)
  153.     local tlw = WindowMgr:CreateTopLevelWindow(name)
  154.     tlw:SetMovable(true)
  155.     tlw:SetMouseEnabled(true)
  156.     tlw:SetDimensions(200,100)
  157.     tlw:SetAnchor(CENTER)
  158.  
  159.     tlw.BackGround = WindowMgr:CreateControlFromVirtual(nil,tlw,"ZO_DefaultBackdrop")
  160.     tlw.BackGround:SetAnchorFill(tlw)
  161.     tlw.BackGround:SetAlpha(0.8)
  162.     tlw.BackGround:SetHidden(false)
  163.  
  164.     return tlw
  165. end
  166.  
  167. local function CreateDropDown(name,parent,data,selected,callback)
  168.     local combo = WindowMgr:CreateControlFromVirtual(parent:GetName()..name,parent,"ZO_StatsDropdownRow")
  169.     combo:SetAnchor(CENTER)
  170.     combo:SetResizeToFitDescendents(true)
  171.  
  172.     combo.selected = combo.name
  173.  
  174.     combo.dropdown = combo.dropdown
  175.     combo.dropdown:SetFont("ZoFontBookScroll")
  176.     if selected then combo.dropdown:SetSelectedItem(selected) end
  177.  
  178.     combo.dropdown.SetSelectedIndex = function(self,value)
  179.         self.SelectedIndex = nil
  180.         for i = 1,#data do
  181.             if data[i] == value then
  182.                 self.SelectedIndex = i
  183.                 break
  184.             end
  185.         end
  186.     end
  187.  
  188.     combo.dropdown.GetSelectedIndex = function(self)
  189.         return self.SelectedIndex
  190.     end
  191.  
  192.     combo.dropdown.OnSelect = function(self,value)
  193.         self:SetSelectedItem(value)
  194.         self:SetSelectedIndex(value)
  195.         if callback then callback(value) end
  196.     end
  197.  
  198.     for i = 1,#data do
  199.         local entry = combo.dropdown:CreateItemEntry(data[i],combo.dropdown.OnSelect)
  200.         combo.dropdown:AddItem(entry)
  201.     end
  202.  
  203.     combo.GetSelectedInfo = function(self)
  204.         return self.dropdown:GetSelectedItem(),self.dropdown:GetSelectedIndex()
  205.     end
  206.  
  207.     combo:SetHidden(false)
  208.     return combo
  209. end
  210.  
  211. local function CreateButton(name,parent,text,callback)
  212.     local button = WindowMgr:CreateControlFromVirtual(parent:GetName()..name,parent,"ZO_DefaultButton")
  213.     button:SetAnchor(BOTTOMLEFT)
  214.     button:SetHandler("OnClicked",
  215.         function(self)
  216.             if callback then callback() end
  217.         end)
  218.     button:SetHidden(false)
  219.     return button
  220. end
  221.  
  222. local function InitUI()
  223.     local testTLW = CreateTopLevelWindow("XrysMapPins_TLW")
  224.     testTLW:SetDimensions(200,400)
  225.  
  226.     local MapPinCombo = CreateDropDown("MapPinTypes",testTLW,TradeSkillNames,nil,function(value) end)
  227.     MapPinCombo:SetDimensions(150,50)
  228.     MapPinCombo:SetAnchor(TOP)
  229.  
  230.     local PinTexture = WindowMgr:CreateControl(nil,testTLW,CT_TEXTURE)
  231.     PinTexture:SetDimensions(200,200)
  232.     PinTexture:SetAnchor(CENTER)
  233.     PinTexture:SetHidden(false)
  234.  
  235.     local PutMapPinButton = CreateButton("MapPinButton",testTLW,nil, function(value)
  236.         local pinType,pinID = MapPinCombo:GetSelectedInfo()
  237.         pinType = addonPrefix.."_"..pinType
  238.         PinTexture:SetTexture(TradeSkills[pinID].Icon)
  239.         SetMapToPlayerLocation()
  240.         local pinZone = GetMapName()
  241.         local pinX,pinY,pinHeading = GetMapPlayerPosition("player")    
  242.         local pinTooltip = TradeSkills[pinID].Name
  243.         local pinTag = { ["id"] = pinID, ["type"] = pinType, ["zone"] = pinZone, ["x"] = pinX, ["y"] = pinY, ["tooltip"] = pinTooltip }
  244.         XMPins:CreatePin(pinType, pinTag, pinZone, pinX, pinY, nil)
  245.         XMPins:RefreshCustomPins(pinType)
  246.         XMPins:List(pinType,pinZone)
  247.     end )
  248.     PutMapPinButton:SetAnchor(BOTTOM)
  249.     PutMapPinButton:SetDimensions(50,50)
  250. end
  251. ------------------------------------------------------------------------
  252.  
  253. local function InitPinTypes()
  254.     for i,v in ipairs(TradeSkills) do
  255.         local pinType = addonPrefix.."_"..v.Name
  256.         local pinID = i
  257.         local drawCallback = function(pinManager)
  258.             SetMapToPlayerLocation()
  259.             local pinZone = GetMapName()
  260.             local harvestData = self.Data[pinType][pinZone]
  261.             for i,v in pairs(harvestData) do
  262.                 pinManager:CreatePin(_G[pinType], v.key, v.zone, v.x, v.y, v.radius)
  263.             end
  264.         end
  265.         local resizeCallback = nil --function(width,height) XMPins:RefreshCustomPins(pinType) end      
  266.         local pinLayoutData = {}
  267.         for i,v in pairs(XMPins.Layout) do
  268.             pinLayoutData[i] = v
  269.         end
  270.         pinLayoutData.texture = TradeSkills[pinID].Icon
  271.         local pinTooltipCreator = { creator = function(pin) InformationTooltip:AddLine(pin.key.tooltip) end, tooltip = InformationTooltip }
  272.         XMPins:AddCustomPin(pinType,drawCallback,resizeCallback,pinLayoutData,pinTooltipCreator,pinID)
  273.     end
  274. end
  275.  
  276. local function PlayerActivated(eventID)
  277.     EventMgr:UnregisterForEvent(addonName,eventID)
  278.     ChatMsg:AddMessage(string.format("%s %s Loaded",addonName,addonVersion))
  279.     InitTradeSkillInfo()
  280.     InitUI()
  281.     InitPinTypes()
  282. end
  283.  
  284. -- Our Addon is loaded so we can start work
  285. local function AddOnLoaded(eventID,addon)
  286.     if addon ~= addonName then return end
  287.     EventMgr:UnregisterForEvent(addonName,eventID)
  288.     EventMgr:RegisterForEvent( addonName ,EVENT_PLAYER_ACTIVATED , PlayerActivated )
  289. end
  290.  
  291. -- Track addons loading
  292. EventMgr:RegisterForEvent( addonName ,EVENT_ADD_ON_LOADED , AddOnLoaded )
  Reply With Quote