View Single Post
04/10/14, 11:24 AM   #1
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Problem Creating Map Pins ... Still

Still trying to fathom how the map pins appear on the map but so far I haven't figured it out. Perhaps someone with access to the extra information can point out where I am going wrong. I've been looking at Shinni's code as a guide and have slowly rewritten what I thought was how it should be done but as the screenshot shows no pin on the map. So I must be missing something somewhere.

Here is the code I have running at the moment. I have deliberately used the PlayerActivatedEvent instead of AddonLoaded so that I can debug my way through it. I know you probably can't give us too much information on this but a nudge into what is missing to make it work would be great.

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

Name:	Screenshot_20140410_181239.jpg
Views:	559
Size:	312.0 KB
ID:	116  
  Reply With Quote