|
1 | 1 | /datum/element/turf_z_transparency
|
2 |
| - var/show_bottom_level = FALSE |
3 |
| - var/turf/our_turf |
| 2 | + element_flags = ELEMENT_DETACH //Important so it is properly cleared out on turf qdel. |
4 | 3 |
|
5 | 4 | ///This proc sets up the signals to handle updating viscontents when turfs above/below update. Handle plane and layer here too so that they don't cover other obs/turfs in Dream Maker
|
6 |
| -/datum/element/turf_z_transparency/Attach(datum/target, show_bottom_level = TRUE) |
| 5 | +/datum/element/turf_z_transparency/Attach(turf/our_turf, show_bottom_level = TRUE) |
7 | 6 | . = ..()
|
8 |
| - if(!isturf(target)) |
| 7 | + if(!isturf(our_turf)) |
9 | 8 | return ELEMENT_INCOMPATIBLE
|
10 | 9 |
|
11 |
| - our_turf = target |
12 |
| - |
13 |
| - src.show_bottom_level = show_bottom_level |
14 |
| - |
15 | 10 | our_turf.plane = OPENSPACE_PLANE
|
16 | 11 | our_turf.layer = OPENSPACE_LAYER
|
17 | 12 |
|
18 |
| - RegisterSignal(target, COMSIG_TURF_MULTIZ_DEL, PROC_REF(on_multiz_turf_del), TRUE) |
19 |
| - RegisterSignal(target, COMSIG_TURF_MULTIZ_NEW, PROC_REF(on_multiz_turf_new), TRUE) |
| 13 | + RegisterSignal(our_turf, COMSIG_TURF_MULTIZ_DEL, PROC_REF(on_multiz_turf_del), TRUE) |
| 14 | + RegisterSignal(our_turf, COMSIG_TURF_MULTIZ_NEW, PROC_REF(on_multiz_turf_new), TRUE) |
| 15 | + RegisterSignal(our_turf, COMSIG_TURF_INITIALIZE_TRANSPARENCY, PROC_REF(initilize_turf_transparency), TRUE) |
20 | 16 |
|
21 | 17 | ADD_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, TURF_TRAIT)
|
22 |
| - |
23 |
| - |
24 |
| - update_multiz(our_turf, TRUE, TRUE) |
| 18 | + if(show_bottom_level) //Sets up the trait to check when initializing the turf elsewhere. |
| 19 | + ADD_TRAIT(our_turf, TURF_Z_SHOW_BOTTOM_TRAIT, TURF_TRAIT) |
25 | 20 |
|
26 | 21 | /datum/element/turf_z_transparency/Detach(datum/source, force)
|
27 | 22 | . = ..()
|
28 | 23 | var/turf/our_turf = source
|
29 |
| - our_turf.vis_contents.len = 0 |
| 24 | + our_turf.vis_contents.len = 0 //vis_contents are handled by Destroy() when a turf is qdel'd, but you could also call Detach from elsewhere. |
30 | 25 | UnregisterSignal(our_turf, COMSIG_TURF_MULTIZ_DEL)
|
31 | 26 | UnregisterSignal(our_turf, COMSIG_TURF_MULTIZ_NEW)
|
| 27 | + UnregisterSignal(our_turf, COMSIG_TURF_INITIALIZE_TRANSPARENCY) |
32 | 28 | REMOVE_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, TURF_TRAIT)
|
| 29 | + REMOVE_TRAIT(our_turf, TURF_Z_SHOW_BOTTOM_TRAIT, TURF_TRAIT) |
33 | 30 |
|
34 | 31 | ///Updates the viscontents or underlays below this tile.
|
35 | 32 | /datum/element/turf_z_transparency/proc/update_multiz(turf/our_turf, prune_on_fail = FALSE, init = FALSE)
|
|
39 | 36 | if(!show_bottom_level(our_turf) && prune_on_fail) //If we cant show whats below, and we prune on fail, change the turf to plating as a fallback
|
40 | 37 | our_turf.ChangeTurf(/turf/open/floor/plating, flags = CHANGETURF_INHERIT_AIR)
|
41 | 38 | return FALSE
|
42 |
| - if(init) |
43 |
| - our_turf.vis_contents += below_turf |
44 |
| - if(isclosedturf(our_turf)) //Show girders below closed turfs |
45 |
| - var/mutable_appearance/girder_underlay = mutable_appearance('icons/obj/structures.dmi', "girder", layer = TURF_LAYER-0.01) |
46 |
| - girder_underlay.appearance_flags = RESET_ALPHA | RESET_COLOR |
47 |
| - our_turf.underlays += girder_underlay |
48 |
| - var/mutable_appearance/plating_underlay = mutable_appearance('icons/turf/floors.dmi', "plating", layer = TURF_LAYER-0.02) |
49 |
| - plating_underlay = RESET_ALPHA | RESET_COLOR |
50 |
| - our_turf.underlays += plating_underlay |
| 39 | + else |
| 40 | + if(init) |
| 41 | + our_turf.vis_contents += below_turf |
| 42 | + if(isclosedturf(our_turf)) //Show girders below closed turfs |
| 43 | + var/mutable_appearance/girder_underlay = mutable_appearance('icons/obj/structures.dmi', "girder", layer = TURF_LAYER-0.01) |
| 44 | + girder_underlay.appearance_flags = RESET_ALPHA | RESET_COLOR |
| 45 | + our_turf.underlays += girder_underlay |
| 46 | + var/mutable_appearance/plating_underlay = mutable_appearance('icons/turf/floors.dmi', "plating", layer = TURF_LAYER-0.02) |
| 47 | + plating_underlay = RESET_ALPHA | RESET_COLOR |
| 48 | + our_turf.underlays += plating_underlay |
51 | 49 | return TRUE
|
52 | 50 |
|
53 | 51 | /datum/element/turf_z_transparency/proc/on_multiz_turf_del(turf/our_turf, turf/T, dir)
|
|
62 | 60 | return
|
63 | 61 | update_multiz(our_turf)
|
64 | 62 |
|
| 63 | +/** |
| 64 | + * Initializes, or actually gives appearance to, transparent tiles. |
| 65 | + * |
| 66 | + * Called via COMSIG_TURF_INITIALIZE_TRANSPARENCY from: |
| 67 | + * ChangeTurf() - generic case for glass floors, initialized when plating turns into glass floor. |
| 68 | + * on_applied_turf() - material application, special case. You can make transparent tiled floor, so it's initialized here as the proc calls are different. |
| 69 | + * onShuttleMove() is a case for both glass and material floors, as it's called only when the shuttle moves. |
| 70 | + * |
| 71 | + * We do these calls as late as possible to get a full baseturfs list to later pass to show_bottom_level(). |
| 72 | + * This should have no effect on multi-z performance, but I have not tested it. |
| 73 | + * |
| 74 | + * Arguments: |
| 75 | + * * our_turf - turf being passed to initialize transparency. Only tested on open turfs. |
| 76 | + */ |
| 77 | +/datum/element/turf_z_transparency/proc/initilize_turf_transparency(turf/our_turf) |
| 78 | + SIGNAL_HANDLER |
| 79 | + update_multiz(our_turf, TRUE, TRUE) |
| 80 | + |
65 | 81 | ///Called when there is no real turf below this turf
|
66 | 82 | /datum/element/turf_z_transparency/proc/show_bottom_level(turf/our_turf)
|
67 |
| - if(!show_bottom_level) |
| 83 | + if(!HAS_TRAIT(our_turf, TURF_Z_SHOW_BOTTOM_TRAIT)) |
68 | 84 | return FALSE
|
69 |
| - var/turf/path = our_turf.virtual_level_trait(ZTRAIT_BASETURF) || /turf/open/space |
70 |
| - if(!ispath(path)) |
71 |
| - path = text2path(path) |
| 85 | + |
| 86 | + var/turf/path |
| 87 | + if(our_turf.baseturfs && length(our_turf.baseturfs) > 1) |
| 88 | + path = our_turf.baseturfs[2] //Why 2? It's usually a better indicator of what we landed on. |
| 89 | + if(ispath(path, /turf/closed)) //Do not want to show walls, looks strange. |
| 90 | + path = our_turf.baseturfs[1] //The first element is going to be a floor of some kind. |
| 91 | + |
| 92 | + if(!path) //Fallback to the regular, bland, method of determining a level baseturf. |
| 93 | + //linters fix, change to this in the future: |
| 94 | + //path = our_turf.get_z_base_turf() |
| 95 | + path = our_turf.virtual_level_trait(ZTRAIT_BASETURF) || /turf/open/space |
72 | 96 | if(!ispath(path))
|
73 |
| - warning("Z-level [our_turf.z] has invalid baseturf '[our_turf.virtual_level_trait(ZTRAIT_BASETURF)]'") |
74 |
| - path = /turf/open/space |
75 |
| - var/mutable_appearance/underlay_appearance = mutable_appearance(initial(path.icon), initial(path.icon_state), layer = TURF_LAYER-0.02, plane = PLANE_SPACE) |
| 97 | + path = text2path(path) |
| 98 | + if(!ispath(path)) |
| 99 | + warning("Z-level [our_turf.z] has invalid baseturf '[our_turf.virtual_level_trait(ZTRAIT_BASETURF)]'") |
| 100 | + path = /turf/open/space |
| 101 | + |
| 102 | + //PLANE_SPACE to show the parallax if it's a space tile. |
| 103 | + var/mutable_appearance/underlay_appearance = mutable_appearance(initial(path.icon), initial(path.icon_state), layer = TURF_LAYER-0.02, plane = (ispath(path, /turf/open/space) ? PLANE_SPACE : null)) |
76 | 104 | underlay_appearance.appearance_flags = RESET_ALPHA | RESET_COLOR
|
77 | 105 | our_turf.underlays += underlay_appearance
|
78 | 106 | return TRUE
|
0 commit comments