package Trackable import HashMap import TypeCasting /* If you need invisible trackable models here are a few downloadlinks: 8x8 "https://dl.dropbox.com/u/103859688/Trackables/8x8Track.mdx" 16x16 "https://dl.dropbox.com/u/103859688/Trackables/16x16Track.mdx" 32x32 "https://dl.dropbox.com/u/103859688/Trackables/32x32Track.mdx" 64x64 "https://dl.dropbox.com/u/103859688/Trackables/64x64Track.mdx" 128x128 "https://dl.dropbox.com/u/103859688/Trackables/128x128Track.mdx" 256x256 "https://dl.dropbox.com/u/103859688/Trackables/256x256Track.mdx" 512x512 "https://dl.dropbox.com/u/103859688/Trackables/512x512Track.mdx" */ public interface TrackableAction function run(TrackableEx clickedTrackable, player clickingPlayer) public class TrackableEx private static constant real doubleClickSpeed = 0.5 private static timer array playerDoubleClickTimer private static thistype array playerClickBefore private static HashMap trackableOwner= new HashMap() private static HashMap trackableObjects = new HashMap() private static trigger trackTrigger = CreateTrigger()..addAction(() -> trackableObjects.get(GetTriggeringTrackable()).trackHandler(trackableOwner.get(GetTriggeringTrackable()))) private static trigger clickTrigger = CreateTrigger()..addAction(() -> trackableObjects.get(GetTriggeringTrackable()).clickHandler(trackableOwner.get(GetTriggeringTrackable()))) private TrackableAction onTrack = null private TrackableAction onClick = null private TrackableAction onDoubleClick = null /** Creates a trackable at the target location. The trackable is clickable for all players */ construct(vec2 pos, string path) for int i = 0 to 11 if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER string newPath = "" if GetLocalPlayer() == Player(i) newPath = path trackable t = CreateTrackable(newPath, pos.x, pos.y, 0) trackableOwner.put(t, Player(i)) trackableObjects.put(t, this) trackTrigger.registerTrackableTrackEvent(t) clickTrigger.registerTrackableHitEvent(t) private function trackHandler(player p) if onTrack != null onTrack.run(this, p) private function clickHandler(player p) if onDoubleClick != null if playerClickBefore[p.getId()] == this onDoubleClick.run(this, p) playerClickBefore[p.getId()] = null playerDoubleClickTimer[p.getId()].pause() else playerDoubleClickTimer[p.getId()].start(doubleClickSpeed, () -> begin playerClickBefore[GetExpiredTimer().getData()] = null end) playerClickBefore[p.getId()] = this onClick.run(this, p) else if onClick != null onClick.run(this, p) /** Sets the action that is executed when the trackable gets hovered */ function onTrack(TrackableAction action) onTrack = action /** Sets the action that is executed when the trackable gets clicked */ function onClick(TrackableAction action) onClick = action /** Sets the action that is executed when the trackable gets doubleclicked */ function onDoubleClick(TrackableAction action) if onDoubleClick == null for int i = 0 to 11 if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER playerDoubleClickTimer[i] = getTimer()..setData(i) onDoubleClick = action /** Creates a Trackable at the target location*/ public function createTrackable(vec2 pos, angle ang, string path) returns trackable return CreateTrackable(path, pos.x, pos.y, ang.degrees()) endpackage