-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathmap_view.dm
71 lines (58 loc) · 2.58 KB
/
map_view.dm
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
67
68
69
70
71
/**
* A screen object, which acts as a container for turfs and other things
* you want to show on the map, which you usually attach to "vis_contents".
* Additionally manages the plane masters required to display said container contents
*/
INITIALIZE_IMMEDIATE(/atom/movable/screen/map_view)
/atom/movable/screen/map_view
name = "screen"
// Map view has to be on the lowest plane to enable proper lighting
layer = GAME_PLANE
plane = GAME_PLANE
del_on_map_removal = FALSE
// Weakrefs of all our hud viewers -> a weakref to the hud datum they last used
var/list/datum/weakref/viewers_to_huds = list()
var/datum/plane_master_group/popup/pop_planes
/atom/movable/screen/map_view/Destroy()
for(var/datum/weakref/client_ref in viewers_to_huds)
var/client/our_client = client_ref.resolve()
if(!our_client)
continue
hide_from(our_client.mob)
return ..()
/atom/movable/screen/map_view/proc/generate_view(map_key)
// Map keys have to start and end with an A-Z character,
// and definitely NOT with a square bracket or even a number.
// I wasted 6 hours on this. :agony:
// -- Stylemistake
assigned_map = map_key
set_position(1, 1)
/atom/movable/screen/map_view/proc/display_to(mob/show_to)
show_to.client.register_map_obj(src)
// We need to add planesmasters to the popup, otherwise
// blending fucks up massively. Any planesmaster on the main screen does
// NOT apply to map popups. If there's ever a way to make planesmasters
// omnipresent, then this wouldn't be needed.
// We lazy load this because there's no point creating all these if none's gonna see em
// Store this info in a client -> hud pattern, so ghosts closing the window nukes the right group
var/datum/weakref/client_ref = WEAKREF(show_to.client)
var/datum/weakref/hud_ref = viewers_to_huds[client_ref]
var/datum/hud/our_hud = hud_ref?.resolve()
if(our_hud)
return our_hud.get_plane_group(PLANE_GROUP_POPUP_WINDOW(src))
// Generate a new plane group for this case
pop_planes = new(PLANE_GROUP_POPUP_WINDOW(src), assigned_map)
viewers_to_huds[client_ref] = WEAKREF(show_to.hud_used)
pop_planes.attach_to(show_to.hud_used)
return pop_planes
/atom/movable/screen/map_view/proc/hide_from(mob/hide_from)
hide_from?.canon_client.clear_map(assigned_map)
var/client_ref = WEAKREF(hide_from?.canon_client)
// Make sure we clear the *right* hud
var/datum/weakref/hud_ref = viewers_to_huds[client_ref]
viewers_to_huds -= client_ref
var/datum/hud/clear_from = hud_ref?.resolve()
if(!clear_from)
return
var/datum/plane_master_group/popup/pop_planes = clear_from.get_plane_group(PLANE_GROUP_POPUP_WINDOW(src))
qdel(pop_planes)