ESOUI SVN EsoHeadMarkers

[/] [trunk/] [EsoheadMarkers/] [CustomMapPins/] [CustomMapPins.lua] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 Shinni-694
-- mappins helper by Shinni
2 Shinni-694
 
3 Shinni-694
CustomMapPins = ZO_Object:Subclass()
4 Shinni-694
 
5 Shinni-694
function CustomMapPins:New( ... )
6 Shinni-694
        local result = ZO_Object.New( self )
7 Shinni-694
        result:Initialize( ... )
8 Shinni-694
        return result
9 Shinni-694
end
10 Shinni-694
 
11 Shinni-694
function CustomMapPins:Initialize( ... )
12 Shinni-694
        self.defaultIcon = "EsoUI/Art/MapPins/hostile_pin.dds"
13 Shinni-694
        self.pins = {}
14 Shinni-694
end
15 Shinni-694
 
16 Shinni-694
-- redraws the pins for the given pinType (removes them, if the pinType is disabled)
17 Shinni-694
-- redraws all pinTypes if parameter ommited
18 Shinni-694
function CustomMapPins:RefreshPins( pinType )
19 Shinni-694
        ZO_WorldMap_RefreshCustomPinsOfType( _G[pinType] )
20 Shinni-694
end
21 Shinni-694
 
22 Shinni-694
-- removes the pin with given pintype and tag
23 Shinni-694
-- you may want to call refreshPins after removing pins
24 Shinni-694
function CustomMapPins:RemovePin( pinType, pinTag )
25 Shinni-694
        self.pins[pinType][pinTag] = nil
26 Shinni-694
end
27 Shinni-694
 
28 Shinni-694
-- creates a pin of pinType on the given location (subzone, locx, locy).
29 Shinni-694
-- pinType will be created with the default icon if undefined
30 Shinni-694
-- radius may be omitted/nil if it's a real pin instead of an area
31 Shinni-694
-- pinTag should be an uniqe identifier but can be ommited
32 Shinni-694
-- after adding your pins you want to call RefreshPins, so the pins are actually drawn to the map
33 Shinni-694
function CustomMapPins:CreatePin( pinType, subzone, locx, locy, radius, pinTag )
34 Shinni-694
        if not self.pins[pinType] then
35 Shinni-694
                self:CreatePinType( pinType )
36 Shinni-694
        end
37 Shinni-694
 
38 Shinni-694
        --create default pinTag if no parameter given
39 Shinni-694
        if not pinTag then
40 Shinni-694
                pinTag = { pinType, subzone, locx, locy }
41 Shinni-694
        end
42 Shinni-694
 
43 Shinni-694
        self.pins[pinType][pinTag] = { zone = subzone, x = locx, y = locy, radius = radius }
44 Shinni-694
end
45 Shinni-694
 
46 Shinni-694
-- creates a new pinType
47 Shinni-694
-- eg:
48 Shinni-694
-- CreatePinType( "Jute", { level = 20, texture = "MyAddon/That_nice_icon_esohead_is_using_for_their_map.dds" } , "delicous Jute... gather me now!" )
49 Shinni-694
-- attributes for pinLayoutData:
50 Shinni-694
-- level (priority of the tag; player has 160, groupmembers 130, quest 110, keeps 30)
51 Shinni-694
-- texture: quote:
52 Shinni-694
--      "How the texturing data works:
53 Shinni-694
--      The texture can come from a string or a callback function
54 Shinni-694
--      If it's a callback function it must return first the base icon texture, and second the pin's pulseTexture"
55 Shinni-694
-- size, minSize, isAnimated, insetX, insetY
56 Shinni-694
function CustomMapPins:CreatePinType( pinType, pinLayoutData, pinTooltipCreator, addCallback )
57 Shinni-694
        --simple tooltip, showing only the given string
58 Shinni-694
        if type(pinTooltipCreator) == "string" then
59 Shinni-694
                local tooltip = pinTooltipCreator
60 Shinni-694
                pinTooltipCreator = { creator = function(pin) InformationTooltip:AddLine(tooltip) end, tooltip = InformationTooltip }
61 Shinni-694
        end
62 Shinni-694
 
63 Shinni-694
        --use default pin icon and move pins of this type behind all other pins (level 20)
64 Shinni-694
        if not pinLayoutData then
65 Shinni-694
                pinLayoutData = { level = 20, texture = self.defaultIcon }
66 Shinni-694
        end
67 Shinni-694
 
68 Shinni-694
        if not addCallback then
69 Shinni-694
                addCallback = function( g_mapPinManager )
70 Shinni-694
                        for pinTag, pin in pairs(self.pins[pinType]) do
71 Shinni-694
                                --only draw pin, if player is on the correct map
72 Shinni-694
                                if pin.zone == GetMapName() then
73 Shinni-694
                                        if pin.radius then
74 Shinni-694
                                                g_mapPinManager:CreatePin( _G[pinType], pinTag, pin.x, pin.y, pin.radius )
75 Shinni-694
                                        else
76 Shinni-694
                                                g_mapPinManager:CreatePin( _G[pinType], pinTag, pin.x, pin.y )
77 Shinni-694
                                        end
78 Shinni-694
                                end
79 Shinni-694
                        end
80 Shinni-694
                end
81 Shinni-694
 
82 Shinni-694
        end
83 Shinni-694
 
84 Shinni-694
        ZO_WorldMap_AddCustomPin(
85 Shinni-694
                pinType,
86 Shinni-694
                -- this function is called everytime, the customs pins of the given pinType are to be drawn (map update because of zone/area change or RefreshPins call)
87 Shinni-694
                addCallback,
88 Shinni-694
                nil, -- a function to be called, when the map is resized... no need when using default pins
89 Shinni-694
                pinLayoutData,
90 Shinni-694
                pinTooltipCreator
91 Shinni-694
        )
92 Shinni-694
        self.pins[pinType] = {}
93 Shinni-694
        --enable this pinTag by default
94 Shinni-694
        self:enablePins( pinType, true)
95 Shinni-694
end
96 Shinni-694
 
97 Shinni-694
-- en-/disables the given pinType
98 Shinni-694
-- this function allows the implementation of filters
99 Shinni-694
function CustomMapPins:enablePins( pinType, enable )
100 Shinni-694
        ZO_WorldMap_SetCustomPinEnabled( _G[pinType], enable )
101 Shinni-694
end