forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimPingGroup.lua
66 lines (59 loc) · 2.06 KB
/
SimPingGroup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- Add a ping chicklet for the user to click on
-- This function returns an ID of the ping group for use if you need to delete it later.
-- callback - function to be executed when the ping is issued by the user
-- name - string that appears on the tooltip
-- blueprintID - used to create the unit icon
-- type - type of ping, can be "move", "alert", or "attack"
local PingGroups = {}
local idNum = 1
function AddPingGroup(name, blueprintID, type, description)
local PingGroup = {
_id = idNum,
Name = name,
Description = description,
BlueprintID = blueprintID,
Type = type,
_callbacks = {},
AddCallback = function(self, cb)
table.insert(self._callbacks, cb)
end,
Destroy = function(self)
if not Sync.RemovePingGroups then
Sync.RemovePingGroups = {}
end
table.insert(Sync.RemovePingGroups, self._id)
PingGroups[self._id] = nil
end,
}
idNum = idNum + 1
if not Sync.AddPingGroups then
Sync.AddPingGroups = {}
end
table.insert(Sync.AddPingGroups, {ID = PingGroup._id, Name = name, BlueprintID = blueprintID, description = description, Type = type})
PingGroups[PingGroup._id] = PingGroup
return PingGroup
end
function OnClickCallback(data)
-- Check to make sure all of the pings are numbers (happens if the user clicks off the map somewhere)
for i, v in data.Location do
if v != v then
return
end
end
if PingGroups[data.ID] then
for _, callback in PingGroups[data.ID]._callbacks do
if callback then callback(data.Location) end
end
end
end
function OnPostLoad()
ForkThread(function()
WaitSeconds(5)
if not Sync.AddPingGroups then
Sync.AddPingGroups = {}
end
for _, PingGroup in PingGroups do
table.insert(Sync.AddPingGroups, {ID = PingGroup._id, Name = PingGroup.Name, BlueprintID = PingGroup.BlueprintID, Type = PingGroup.Type})
end
end)
end