Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 39 | Taonnor-14572 | local LIB_IDENTIFIER = "LibMapPing" |
2 | 61 | Taonnor-14572 | local lib = LibStub:NewLibrary(LIB_IDENTIFIER, 6) |
3 | 39 | Taonnor-14572 | |
4 | Taonnor-14572 | if not lib then |
|
5 | Taonnor-14572 | return -- already loaded and no upgrade necessary |
|
6 | Taonnor-14572 | end |
|
7 | Taonnor-14572 | ||
8 | Taonnor-14572 | local function Log(message, ...) |
|
9 | Taonnor-14572 | df("[%s] %s", LIB_IDENTIFIER, message:format(...)) |
|
10 | Taonnor-14572 | end |
|
11 | Taonnor-14572 | ||
12 | Taonnor-14572 | local MAP_PIN_TYPE_PLAYER_WAYPOINT = MAP_PIN_TYPE_PLAYER_WAYPOINT |
|
13 | Taonnor-14572 | local MAP_PIN_TYPE_PING = MAP_PIN_TYPE_PING |
|
14 | Taonnor-14572 | local MAP_PIN_TYPE_RALLY_POINT = MAP_PIN_TYPE_RALLY_POINT |
|
15 | Taonnor-14572 | ||
16 | Taonnor-14572 | local MAP_PIN_TAG_PLAYER_WAYPOINT = "waypoint" |
|
17 | Taonnor-14572 | local MAP_PIN_TAG_RALLY_POINT = "rally" |
|
18 | Taonnor-14572 | local PING_CATEGORY = "pings" |
|
19 | Taonnor-14572 | ||
20 | Taonnor-14572 | local PING_EVENT_WATCHDOG_TIME = 400 -- ms |
|
21 | Taonnor-14572 | ||
22 | Taonnor-14572 | local MAP_PIN_TAG = { |
|
23 | Taonnor-14572 | [MAP_PIN_TYPE_PLAYER_WAYPOINT] = MAP_PIN_TAG_PLAYER_WAYPOINT, |
|
24 | Taonnor-14572 | --[MAP_PIN_TYPE_PING] = group pings have individual tags for each member |
|
25 | Taonnor-14572 | [MAP_PIN_TYPE_RALLY_POINT] = MAP_PIN_TAG_RALLY_POINT, |
|
26 | Taonnor-14572 | } |
|
27 | Taonnor-14572 | ||
28 | Taonnor-14572 | local originalPingMap, originalRemovePlayerWaypoint, originalRemoveRallyPoint |
|
29 | Taonnor-14572 | local GET_MAP_PING_FUNCTION = {} -- is initialized in Load() |
|
30 | Taonnor-14572 | local REMOVE_MAP_PING_FUNCTION = {} -- also initialized in Load() |
|
31 | Taonnor-14572 | ||
32 | Taonnor-14572 | --- MapPingState is an enumeration of the possible states of a map ping. |
|
33 | Taonnor-14572 | lib.MAP_PING_NOT_SET = 0 --- There is no ping. |
|
34 | Taonnor-14572 | lib.MAP_PING_NOT_SET_PENDING = 1 --- The ping has been removed, but EVENT_MAP_PING has not been processed. |
|
35 | Taonnor-14572 | lib.MAP_PING_SET_PENDING = 2 --- A ping was added, but EVENT_MAP_PING has not been processed. |
|
36 | Taonnor-14572 | lib.MAP_PING_SET = 3 --- There is a ping. |
|
37 | Taonnor-14572 | ||
38 | Taonnor-14572 | lib.mutePing = lib.mutePing or {} |
|
39 | Taonnor-14572 | lib.suppressPing = lib.suppressPing or {} |
|
40 | Taonnor-14572 | lib.pingState = lib.pingState or {} |
|
41 | Taonnor-14572 | lib.pendingPing = lib.pendingPing or {} |
|
42 | Taonnor-14572 | lib.cm = lib.cm or ZO_CallbackObject:New() |
|
43 | Taonnor-14572 | local g_mapPinManager = lib.mapPinManager |
|
44 | Taonnor-14572 | ||
45 | Taonnor-14572 | local function GetPingTagFromType(pingType) |
|
46 | Taonnor-14572 | return MAP_PIN_TAG[pingType] or GetGroupUnitTagByIndex(GetGroupIndexByUnitTag("player")) or "" |
|
47 | Taonnor-14572 | end |
|
48 | Taonnor-14572 | ||
49 | Taonnor-14572 | local function GetKey(pingType, pingTag) |
|
50 | Taonnor-14572 | pingTag = pingTag or GetPingTagFromType(pingType) |
|
51 | Taonnor-14572 | return string.format("%d_%s", pingType, pingTag) |
|
52 | Taonnor-14572 | end |
|
53 | Taonnor-14572 | ||
54 | Taonnor-14572 | -- TODO keep an eye on worldmap.lua for changes |
|
55 | Taonnor-14572 | local function HandleMapPing(eventCode, pingEventType, pingType, pingTag, x, y, isPingOwner) |
|
56 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
57 | 61 | Taonnor-14572 | local data = lib.pendingPing[key] |
58 | Taonnor-14572 | if data and data[1] == pingEventType then |
|
59 | Taonnor-14572 | lib.pendingPing[key] = nil |
|
60 | Taonnor-14572 | end |
|
61 | 39 | Taonnor-14572 | if(pingEventType == PING_EVENT_ADDED) then |
62 | Taonnor-14572 | lib.cm:FireCallbacks("BeforePingAdded", pingType, pingTag, x, y, isPingOwner) |
|
63 | Taonnor-14572 | lib.pingState[key] = lib.MAP_PING_SET |
|
64 | Taonnor-14572 | g_mapPinManager:RemovePins(PING_CATEGORY, pingType, pingTag) |
|
65 | Taonnor-14572 | if(not lib:IsPingSuppressed(pingType, pingTag)) then |
|
66 | Taonnor-14572 | g_mapPinManager:CreatePin(pingType, pingTag, x, y) |
|
67 | Taonnor-14572 | if(isPingOwner and not lib:IsPingMuted(pingType, pingTag)) then |
|
68 | Taonnor-14572 | PlaySound(SOUNDS.MAP_PING) |
|
69 | Taonnor-14572 | end |
|
70 | Taonnor-14572 | end |
|
71 | Taonnor-14572 | lib.cm:FireCallbacks("AfterPingAdded", pingType, pingTag, x, y, isPingOwner) |
|
72 | Taonnor-14572 | elseif(pingEventType == PING_EVENT_REMOVED) then |
|
73 | Taonnor-14572 | lib.cm:FireCallbacks("BeforePingRemoved", pingType, pingTag, x, y, isPingOwner) |
|
74 | Taonnor-14572 | lib.pingState[key] = lib.MAP_PING_NOT_SET |
|
75 | Taonnor-14572 | g_mapPinManager:RemovePins(PING_CATEGORY, pingType, pingTag) |
|
76 | Taonnor-14572 | if (isPingOwner and not lib:IsPingSuppressed(pingType, pingTag) and not lib:IsPingMuted(pingType, pingTag)) then |
|
77 | Taonnor-14572 | PlaySound(SOUNDS.MAP_PING_REMOVE) |
|
78 | Taonnor-14572 | end |
|
79 | Taonnor-14572 | lib.cm:FireCallbacks("AfterPingRemoved", pingType, pingTag, x, y, isPingOwner) |
|
80 | Taonnor-14572 | end |
|
81 | Taonnor-14572 | end |
|
82 | Taonnor-14572 | ||
83 | Taonnor-14572 | local function HandleMapPingEventNotFired() |
|
84 | Taonnor-14572 | EVENT_MANAGER:UnregisterForUpdate(LIB_IDENTIFIER) |
|
85 | Taonnor-14572 | for key, data in pairs(lib.pendingPing) do |
|
86 | 61 | Taonnor-14572 | local pingEventType, pingType, x, y, zoneIndex = unpack(data) |
87 | 39 | Taonnor-14572 | local pingTag = GetPingTagFromType(pingType) |
88 | 61 | Taonnor-14572 | -- The event is delayed and thus may not match the current map anymore. |
89 | Taonnor-14572 | if GetCurrentMapZoneIndex() ~= zoneIndex then |
|
90 | Taonnor-14572 | -- The coords do not match the current map. Do not draw a pin. |
|
91 | Taonnor-14572 | lib:SuppressPing(pingType, pingTag) -- Will be set to zero afterwards, see below. |
|
92 | Taonnor-14572 | end |
|
93 | 39 | Taonnor-14572 | HandleMapPing(0, pingEventType, pingType, pingTag, x, y, true) |
94 | Taonnor-14572 | lib.pendingPing[key] = nil |
|
95 | Taonnor-14572 | lib.mutePing[key] = 0 |
|
96 | Taonnor-14572 | lib.suppressPing[key] = 0 |
|
97 | Taonnor-14572 | end |
|
98 | Taonnor-14572 | end |
|
99 | Taonnor-14572 | ||
100 | Taonnor-14572 | local function ResetEventWatchdog(key, ...) |
|
101 | Taonnor-14572 | lib.pendingPing[key] = {...} |
|
102 | Taonnor-14572 | EVENT_MANAGER:UnregisterForUpdate(LIB_IDENTIFIER) |
|
103 | Taonnor-14572 | EVENT_MANAGER:RegisterForUpdate(LIB_IDENTIFIER, PING_EVENT_WATCHDOG_TIME, HandleMapPingEventNotFired) |
|
104 | Taonnor-14572 | end |
|
105 | Taonnor-14572 | ||
106 | Taonnor-14572 | local function CustomPingMap(pingType, mapType, x, y) |
|
107 | Taonnor-14572 | if(pingType == MAP_PIN_TYPE_PING and not IsUnitGrouped("player")) then return end |
|
108 | Taonnor-14572 | local key = GetKey(pingType) |
|
109 | Taonnor-14572 | lib.pingState[key] = lib.MAP_PING_SET_PENDING |
|
110 | 61 | Taonnor-14572 | ResetEventWatchdog(key, PING_EVENT_ADDED, pingType, x, y, GetCurrentMapZoneIndex()) |
111 | Taonnor-14572 | return originalPingMap(pingType, mapType, x, y) |
|
112 | 39 | Taonnor-14572 | end |
113 | Taonnor-14572 | ||
114 | Taonnor-14572 | local function CustomGetMapPlayerWaypoint() |
|
115 | Taonnor-14572 | if(lib:IsPingSuppressed(MAP_PIN_TYPE_PLAYER_WAYPOINT, MAP_PIN_TAG_PLAYER_WAYPOINT)) then |
|
116 | Taonnor-14572 | return 0, 0 |
|
117 | Taonnor-14572 | end |
|
118 | Taonnor-14572 | return GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_PLAYER_WAYPOINT]() |
|
119 | Taonnor-14572 | end |
|
120 | Taonnor-14572 | ||
121 | Taonnor-14572 | local function CustomGetMapPing(pingTag) |
|
122 | Taonnor-14572 | if(lib:IsPingSuppressed(MAP_PIN_TYPE_PING, pingTag)) then |
|
123 | Taonnor-14572 | return 0, 0 |
|
124 | Taonnor-14572 | end |
|
125 | Taonnor-14572 | return GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_PING](pingTag) |
|
126 | Taonnor-14572 | end |
|
127 | Taonnor-14572 | ||
128 | Taonnor-14572 | local function CustomGetMapRallyPoint() |
|
129 | Taonnor-14572 | if(lib:IsPingSuppressed(MAP_PIN_TYPE_RALLY_POINT, MAP_PIN_TAG_RALLY_POINT)) then |
|
130 | Taonnor-14572 | return 0, 0 |
|
131 | Taonnor-14572 | end |
|
132 | Taonnor-14572 | return GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_RALLY_POINT]() |
|
133 | Taonnor-14572 | end |
|
134 | Taonnor-14572 | ||
135 | Taonnor-14572 | local function CustomRemovePlayerWaypoint() |
|
136 | Taonnor-14572 | local key = GetKey(MAP_PIN_TYPE_PLAYER_WAYPOINT, MAP_PIN_TAG_PLAYER_WAYPOINT) |
|
137 | Taonnor-14572 | lib.pingState[key] = lib.MAP_PING_NOT_SET_PENDING |
|
138 | 61 | Taonnor-14572 | ResetEventWatchdog(key, PING_EVENT_REMOVED, MAP_PIN_TYPE_PLAYER_WAYPOINT, 0, 0, GetCurrentMapZoneIndex()) |
139 | Taonnor-14572 | return originalRemovePlayerWaypoint() |
|
140 | 39 | Taonnor-14572 | end |
141 | Taonnor-14572 | ||
142 | Taonnor-14572 | local function CustomRemoveMapPing() |
|
143 | Taonnor-14572 | -- there is no such function for group pings, but we can set it to 0, 0 which effectively hides it |
|
144 | Taonnor-14572 | PingMap(MAP_PIN_TYPE_PING, MAP_TYPE_LOCATION_CENTERED, 0, 0) |
|
145 | Taonnor-14572 | end |
|
146 | Taonnor-14572 | ||
147 | Taonnor-14572 | local function CustomRemoveRallyPoint() |
|
148 | Taonnor-14572 | local key = GetKey(MAP_PIN_TYPE_RALLY_POINT, MAP_PIN_TAG_RALLY_POINT) |
|
149 | Taonnor-14572 | lib.pingState[key] = lib.MAP_PING_NOT_SET_PENDING |
|
150 | Taonnor-14572 | ResetEventWatchdog(key, PING_EVENT_REMOVED, MAP_PIN_TYPE_RALLY_POINT, 0, 0) |
|
151 | Taonnor-14572 | originalRemoveRallyPoint() |
|
152 | Taonnor-14572 | end |
|
153 | Taonnor-14572 | ||
154 | Taonnor-14572 | --- Wrapper for PingMap. |
|
155 | Taonnor-14572 | --- pingType is one of the three possible MapDisplayPinType for map pings (MAP_PIN_TYPE_PLAYER_WAYPOINT, MAP_PIN_TYPE_PING or MAP_PIN_TYPE_RALLY_POINT). |
|
156 | Taonnor-14572 | --- mapType is usually MAP_TYPE_LOCATION_CENTERED. |
|
157 | Taonnor-14572 | --- x and y are the normalized coordinates on the current map. |
|
158 | Taonnor-14572 | function lib:SetMapPing(pingType, mapType, x, y) |
|
159 | Taonnor-14572 | PingMap(pingType, mapType, x, y) |
|
160 | Taonnor-14572 | end |
|
161 | Taonnor-14572 | ||
162 | Taonnor-14572 | --- Wrapper for the different ping removal functions. |
|
163 | Taonnor-14572 | --- For waypoints and rally points it calls their respective removal function |
|
164 | Taonnor-14572 | --- For group pings it just sets the position to 0, 0 as there is no function to clear them |
|
165 | Taonnor-14572 | function lib:RemoveMapPing(pingType) |
|
166 | Taonnor-14572 | if(REMOVE_MAP_PING_FUNCTION[pingType]) then |
|
167 | Taonnor-14572 | REMOVE_MAP_PING_FUNCTION[pingType]() |
|
168 | Taonnor-14572 | end |
|
169 | Taonnor-14572 | end |
|
170 | Taonnor-14572 | ||
171 | Taonnor-14572 | --- Wrapper for the different get ping functions. Returns coordinates regardless of their suppression state. |
|
172 | Taonnor-14572 | --- The game API functions return 0, 0 when the ping type is suppressed. |
|
173 | Taonnor-14572 | --- pingType is the same as for SetMapPing. |
|
174 | Taonnor-14572 | --- pingTag is optionally used if another group member's MAP_PIN_TYPE_PING should be returned (possible values: group1 .. group24). |
|
175 | Taonnor-14572 | function lib:GetMapPing(pingType, pingTag) |
|
176 | Taonnor-14572 | local x, y = 0, 0 |
|
177 | Taonnor-14572 | if(GET_MAP_PING_FUNCTION[pingType]) then |
|
178 | Taonnor-14572 | x, y = GET_MAP_PING_FUNCTION[pingType](pingTag or GetPingTagFromType(pingType)) |
|
179 | Taonnor-14572 | end |
|
180 | Taonnor-14572 | return x, y |
|
181 | Taonnor-14572 | end |
|
182 | Taonnor-14572 | ||
183 | Taonnor-14572 | --- Returns the MapPingState for the pingType and pingTag. |
|
184 | Taonnor-14572 | function lib:GetMapPingState(pingType, pingTag) |
|
185 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
186 | Taonnor-14572 | local state = lib.pingState[key] |
|
187 | Taonnor-14572 | if state == nil then |
|
188 | Taonnor-14572 | local x, y = lib:GetMapPing(pingType, pingTag) |
|
189 | Taonnor-14572 | state = (x ~= 0 or y ~= 0) and lib.MAP_PING_SET or lib.MAP_PING_NOT_SET |
|
190 | Taonnor-14572 | lib.pingState[key] = state |
|
191 | Taonnor-14572 | end |
|
192 | Taonnor-14572 | return lib.pingState[key] |
|
193 | Taonnor-14572 | end |
|
194 | Taonnor-14572 | --- Returns true if ping state is MAP_PING_SET_PENDING or MAP_PING_SET |
|
195 | Taonnor-14572 | function lib:HasMapPing(pingType, pingTag) |
|
196 | Taonnor-14572 | local state = lib:GetMapPingState(pingType, pingTag) |
|
197 | Taonnor-14572 | return state == lib.MAP_PING_SET_PENDING or state == lib.MAP_PING_SET |
|
198 | Taonnor-14572 | end |
|
199 | Taonnor-14572 | ||
200 | Taonnor-14572 | --- Refreshes the pin icon for the pingType on the worldmap |
|
201 | Taonnor-14572 | --- Returns true if the pin has been refreshed. |
|
202 | Taonnor-14572 | function lib:RefreshMapPin(pingType, pingTag) |
|
203 | Taonnor-14572 | if(not g_mapPinManager) then |
|
204 | Taonnor-14572 | Log("PinManager not available. Using ZO_WorldMap_UpdateMap instead.") |
|
205 | Taonnor-14572 | ZO_WorldMap_UpdateMap() |
|
206 | Taonnor-14572 | return true |
|
207 | Taonnor-14572 | end |
|
208 | Taonnor-14572 | ||
209 | Taonnor-14572 | pingTag = pingTag or GetPingTagFromType(pingType) |
|
210 | Taonnor-14572 | g_mapPinManager:RemovePins(PING_CATEGORY, pingType, pingTag) |
|
211 | Taonnor-14572 | ||
212 | Taonnor-14572 | local x, y = lib:GetMapPing(pingType, pingTag) |
|
213 | Taonnor-14572 | if(lib:IsPositionOnMap(x, y)) then |
|
214 | Taonnor-14572 | g_mapPinManager:CreatePin(pingType, pingTag, x, y) |
|
215 | Taonnor-14572 | return true |
|
216 | Taonnor-14572 | end |
|
217 | Taonnor-14572 | return false |
|
218 | Taonnor-14572 | end |
|
219 | Taonnor-14572 | ||
220 | Taonnor-14572 | --- Returns true if the normalized position is within 0 and 1. |
|
221 | Taonnor-14572 | function lib:IsPositionOnMap(x, y) |
|
222 | Taonnor-14572 | return not (x < 0 or y < 0 or x > 1 or y > 1 or (x == 0 and y == 0)) |
|
223 | Taonnor-14572 | end |
|
224 | Taonnor-14572 | ||
225 | Taonnor-14572 | --- Mutes the map ping of the specified type, so it does not make a sound when it is set. |
|
226 | Taonnor-14572 | --- Do not forget to call UnmutePing later, otherwise the sound will be permanently muted! |
|
227 | Taonnor-14572 | function lib:MutePing(pingType, pingTag) |
|
228 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
229 | Taonnor-14572 | local mute = lib.mutePing[key] or 0 |
|
230 | Taonnor-14572 | lib.mutePing[key] = mute + 1 |
|
231 | Taonnor-14572 | end |
|
232 | Taonnor-14572 | ||
233 | Taonnor-14572 | --- Unmutes the map ping of the specified type. |
|
234 | Taonnor-14572 | --- Do not call this more often than you called MutePing, or you might interfere with other addons. |
|
235 | Taonnor-14572 | --- The sounds are played between the BeforePing* and AfterPing* callbacks are fired. |
|
236 | Taonnor-14572 | function lib:UnmutePing(pingType, pingTag) |
|
237 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
238 | Taonnor-14572 | local mute = (lib.mutePing[key] or 0) - 1 |
|
239 | Taonnor-14572 | if(mute < 0) then mute = 0 end |
|
240 | Taonnor-14572 | lib.mutePing[key] = mute |
|
241 | Taonnor-14572 | end |
|
242 | Taonnor-14572 | ||
243 | Taonnor-14572 | --- Returns true if the map ping has been muted |
|
244 | Taonnor-14572 | function lib:IsPingMuted(pingType, pingTag) |
|
245 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
246 | Taonnor-14572 | return lib.mutePing[key] and lib.mutePing[key] > 0 |
|
247 | Taonnor-14572 | end |
|
248 | Taonnor-14572 | ||
249 | Taonnor-14572 | --- Suppresses the map ping of the specified type, so that it neither makes a sound nor shows up on the map. |
|
250 | Taonnor-14572 | --- This also makes the API functions return 0, 0 for that ping. |
|
251 | Taonnor-14572 | --- In order to access the actual coordinates lib:GetMapPing has to be used. |
|
252 | Taonnor-14572 | --- Do not forget to call UnsuppressPing later, otherwise map pings won't work anymore for the user and other addons! |
|
253 | Taonnor-14572 | function lib:SuppressPing(pingType, pingTag) |
|
254 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
255 | Taonnor-14572 | local suppress = lib.suppressPing[key] or 0 |
|
256 | Taonnor-14572 | lib.suppressPing[key] = suppress + 1 |
|
257 | Taonnor-14572 | end |
|
258 | Taonnor-14572 | ||
259 | Taonnor-14572 | --- Unsuppresses the map ping so it shows up again |
|
260 | Taonnor-14572 | --- Do not call this more often than you called SuppressPing, or you might interfere with other addons. |
|
261 | Taonnor-14572 | function lib:UnsuppressPing(pingType, pingTag) |
|
262 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
263 | Taonnor-14572 | local suppress = (lib.suppressPing[key] or 0) - 1 |
|
264 | Taonnor-14572 | if(suppress < 0) then suppress = 0 end |
|
265 | Taonnor-14572 | lib.suppressPing[key] = suppress |
|
266 | Taonnor-14572 | end |
|
267 | Taonnor-14572 | ||
268 | Taonnor-14572 | --- Returns true if the map ping has been suppressed |
|
269 | Taonnor-14572 | function lib:IsPingSuppressed(pingType, pingTag) |
|
270 | Taonnor-14572 | local key = GetKey(pingType, pingTag) |
|
271 | Taonnor-14572 | return lib.suppressPing[key] and lib.suppressPing[key] > 0 |
|
272 | Taonnor-14572 | end |
|
273 | Taonnor-14572 | ||
274 | Taonnor-14572 | local function InterceptMapPinManager() |
|
275 | Taonnor-14572 | if (g_mapPinManager) then return end |
|
276 | Taonnor-14572 | local orgRefreshCustomPins = ZO_WorldMapPins.RefreshCustomPins |
|
277 | Taonnor-14572 | function ZO_WorldMapPins:RefreshCustomPins() |
|
278 | Taonnor-14572 | g_mapPinManager = self |
|
279 | Taonnor-14572 | lib.mapPinManager = self |
|
280 | Taonnor-14572 | end |
|
281 | Taonnor-14572 | ZO_WorldMap_RefreshCustomPinsOfType() |
|
282 | Taonnor-14572 | ZO_WorldMapPins.RefreshCustomPins = orgRefreshCustomPins |
|
283 | Taonnor-14572 | end |
|
284 | Taonnor-14572 | ||
285 | Taonnor-14572 | --- Register to callbacks from the library. |
|
286 | Taonnor-14572 | --- Valid events are BeforePingAdded, AfterPingAdded, BeforePingRemoved and AfterPingRemoved. |
|
287 | Taonnor-14572 | --- These are fired at certain points during handling EVENT_MAP_PING. |
|
288 | Taonnor-14572 | function lib:RegisterCallback(eventName, callback) |
|
289 | Taonnor-14572 | lib.cm:RegisterCallback(eventName, callback) |
|
290 | Taonnor-14572 | end |
|
291 | Taonnor-14572 | ||
292 | Taonnor-14572 | --- Unregister from callbacks. See lib:RegisterCallback. |
|
293 | Taonnor-14572 | function lib:UnregisterCallback(eventName, callback) |
|
294 | Taonnor-14572 | lib.cm:UnregisterCallback(eventName, callback) |
|
295 | Taonnor-14572 | end |
|
296 | Taonnor-14572 | ||
297 | Taonnor-14572 | local function Unload() |
|
298 | Taonnor-14572 | EVENT_MANAGER:UnregisterForEvent(LIB_IDENTIFIER, EVENT_ADD_ON_LOADED) |
|
299 | Taonnor-14572 | EVENT_MANAGER:UnregisterForEvent(LIB_IDENTIFIER, EVENT_MAP_PING) |
|
300 | Taonnor-14572 | PingMap = originalPingMap |
|
301 | Taonnor-14572 | GetMapPlayerWaypoint = GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_PLAYER_WAYPOINT] |
|
302 | Taonnor-14572 | GetMapPing = GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_PING] |
|
303 | Taonnor-14572 | GetMapRallyPoint = GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_RALLY_POINT] |
|
304 | Taonnor-14572 | RemovePlayerWaypoint = originalRemovePlayerWaypoint |
|
305 | Taonnor-14572 | RemoveRallyPoint = originalRemoveRallyPoint |
|
306 | Taonnor-14572 | end |
|
307 | Taonnor-14572 | ||
308 | Taonnor-14572 | local function Load() |
|
309 | Taonnor-14572 | InterceptMapPinManager() |
|
310 | Taonnor-14572 | ||
311 | Taonnor-14572 | originalPingMap = PingMap |
|
312 | Taonnor-14572 | PingMap = CustomPingMap |
|
313 | Taonnor-14572 | ||
314 | Taonnor-14572 | GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_PLAYER_WAYPOINT] = GetMapPlayerWaypoint |
|
315 | Taonnor-14572 | GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_PING] = GetMapPing |
|
316 | Taonnor-14572 | GET_MAP_PING_FUNCTION[MAP_PIN_TYPE_RALLY_POINT] = GetMapRallyPoint |
|
317 | Taonnor-14572 | GetMapPlayerWaypoint = CustomGetMapPlayerWaypoint |
|
318 | Taonnor-14572 | GetMapPing = CustomGetMapPing |
|
319 | Taonnor-14572 | GetMapRallyPoint = CustomGetMapRallyPoint |
|
320 | Taonnor-14572 | ||
321 | Taonnor-14572 | -- we want to use the altered versions in the library in order to set the correct ping state |
|
322 | Taonnor-14572 | -- so we need to also save the originals |
|
323 | Taonnor-14572 | originalRemovePlayerWaypoint = RemovePlayerWaypoint |
|
324 | Taonnor-14572 | originalRemoveRallyPoint = RemoveRallyPoint |
|
325 | Taonnor-14572 | RemovePlayerWaypoint = CustomRemovePlayerWaypoint |
|
326 | Taonnor-14572 | RemoveRallyPoint = CustomRemoveRallyPoint |
|
327 | Taonnor-14572 | REMOVE_MAP_PING_FUNCTION[MAP_PIN_TYPE_PLAYER_WAYPOINT] = CustomRemovePlayerWaypoint |
|
328 | Taonnor-14572 | REMOVE_MAP_PING_FUNCTION[MAP_PIN_TYPE_PING] = CustomRemoveMapPing -- has no real api equivalent |
|
329 | Taonnor-14572 | REMOVE_MAP_PING_FUNCTION[MAP_PIN_TYPE_RALLY_POINT] = CustomRemoveRallyPoint |
|
330 | Taonnor-14572 | ||
331 | Taonnor-14572 | EVENT_MANAGER:RegisterForEvent(LIB_IDENTIFIER, EVENT_ADD_ON_LOADED, function(_, addonName) |
|
332 | Taonnor-14572 | if(addonName == "ZO_Ingame") then |
|
333 | Taonnor-14572 | EVENT_MANAGER:UnregisterForEvent(LIB_IDENTIFIER, EVENT_ADD_ON_LOADED) |
|
334 | Taonnor-14572 | -- don't let worldmap do anything as we manage it instead |
|
335 | Taonnor-14572 | EVENT_MANAGER:UnregisterForEvent("ZO_WorldMap", EVENT_MAP_PING) |
|
336 | Taonnor-14572 | EVENT_MANAGER:RegisterForEvent(LIB_IDENTIFIER, EVENT_MAP_PING, HandleMapPing) |
|
337 | Taonnor-14572 | end |
|
338 | Taonnor-14572 | end) |
|
339 | Taonnor-14572 | ||
340 | Taonnor-14572 | lib.Unload = Unload |
|
341 | Taonnor-14572 | end |
|
342 | Taonnor-14572 | ||
343 | Taonnor-14572 | if(lib.Unload) then lib.Unload() end |
|
344 | Taonnor-14572 | Load() |