[MIRROR] Sticker resprite and rewrite (#26853)

* Sticker resprite and rewrite (#81893)

Stealing from Goon is bad, but stickers are actually a good feature, and
loosing those will be a disappointment. This project aims to recreate
'em from scratch without using Jimmyl's and Goon's code. Also,
suspicious icons were resprited and renamed.

* Sticker resprite and rewrite

---------

Co-authored-by: Interception&? <137328283+intercepti0n@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-03-13 19:35:59 -04:00
committed by GitHub
co-authored by Interception&?
parent 24cd444494
commit 0e217eab7b
11 changed files with 327 additions and 277 deletions
@@ -1,78 +0,0 @@
// The attached sticker
/datum/component/attached_sticker
dupe_mode = COMPONENT_DUPE_ALLOWED
///The overlay we apply to things we stick to
var/mutable_appearance/sticker_overlay
///The turf our COMSIG_TURF_EXPOSE is registered to, so we can unregister it later.
var/turf/signal_turf
///Our physical sticker to drop
var/obj/item/sticker
///Can we be washed off?
var/washable = TRUE
/datum/component/attached_sticker/Initialize(px, py, obj/stick, mob/living/user, cleanable=TRUE)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
washable = cleanable
var/atom/atom_parent = parent
sticker = stick
sticker_overlay = mutable_appearance(stick.icon, stick.icon_state , layer = atom_parent.layer + 1, appearance_flags = RESET_COLOR | PIXEL_SCALE)
sticker_overlay.pixel_x = px
sticker_overlay.pixel_y = py
atom_parent.add_overlay(sticker_overlay)
if(isliving(parent) && user)
var/mob/living/victim = parent
if(victim.client)
user.log_message("stuck [sticker] to [key_name(victim)]", LOG_ATTACK)
victim.log_message("had [sticker] stuck to them by [key_name(user)]", LOG_ATTACK)
else if(isturf(parent) && (sticker.resistance_flags & FLAMMABLE))
//register signals on the users turf instead because we can assume they are on flooring sticking it to a wall so it should burn (otherwise it would fruitlessly check wall temperature)
signal_turf = (user && isclosedturf(parent)) ? get_turf(user) : parent
RegisterSignal(signal_turf, COMSIG_TURF_EXPOSE, PROC_REF(on_turf_expose))
sticker.moveToNullspace()
RegisterSignal(sticker, COMSIG_QDELETING, PROC_REF(peel))
/datum/component/attached_sticker/Destroy()
var/atom/as_atom = parent
as_atom.cut_overlay(sticker_overlay)
sticker_overlay = null
if(sticker)
QDEL_NULL(sticker)
return ..()
///Move sticker item from nullspace, delete this component, cut overlay
/datum/component/attached_sticker/proc/peel(atom/source)
SIGNAL_HANDLER
if(!QDELETED(sticker))
var/atom/as_atom = parent
sticker.forceMove(isturf(as_atom) ? as_atom : as_atom.drop_location())
sticker.pixel_y = rand(-4,1)
sticker.pixel_x = rand(-3,3)
sticker = null
if(!QDELETED(src))
qdel(src)
/datum/component/attached_sticker/RegisterWithParent()
if(sticker.resistance_flags & FLAMMABLE)
RegisterSignal(parent, COMSIG_LIVING_IGNITED, PROC_REF(peel))
if(washable)
RegisterSignal(parent, COMSIG_COMPONENT_CLEAN_ACT, PROC_REF(peel))
RegisterSignal(parent, COMSIG_QDELETING, PROC_REF(peel))
ADD_TRAIT(parent, TRAIT_STICKERED, REF(sticker))
/datum/component/attached_sticker/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_LIVING_IGNITED, COMSIG_QDELETING))
if(signal_turf)
UnregisterSignal(signal_turf, COMSIG_TURF_EXPOSE)
signal_turf = null
if(washable)
UnregisterSignal(parent, COMSIG_COMPONENT_CLEAN_ACT)
REMOVE_TRAIT(parent, TRAIT_STICKERED, REF(sticker))
///Signal handler for COMSIG_TURF_EXPOSE, deletes this sticker if the temperature is above 100C and it is flammable
/datum/component/attached_sticker/proc/on_turf_expose(datum/source, datum/gas_mixture/air, exposed_temperature)
SIGNAL_HANDLER
if(exposed_temperature <= FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
return
peel()
+111
View File
@@ -0,0 +1,111 @@
/**
* ### Sticker component
*
* Component that draws supplied atom's icon over parent object with specified offset,
* icon centering is handled inside.
*/
/datum/component/sticker
dupe_mode = COMPONENT_DUPE_ALLOWED
/// Either `turf` or `null`, used to connect to `COMSIG_TURF_EXPOSE` signal when parent is a turf.
var/turf/listening_turf
/// Refernce to a "stickered" atom.
var/atom/movable/our_sticker
/// Reference to the created overlay, used during component deletion.
var/mutable_appearance/sticker_overlay
/datum/component/sticker/Initialize(atom/stickering_atom, mob/user, dir = NORTH, px = 0, py = 0)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
src.our_sticker = our_sticker
if(isliving(parent) && !isnull(user))
var/mob/living/victim = parent
if(!isnull(victim.client))
user.log_message("stuck [stickering_atom] to [key_name(victim)]", LOG_ATTACK)
victim.log_message("had [stickering_atom] stuck to them by [key_name(user)]", LOG_ATTACK)
stick(stickering_atom, px, py)
register_turf_signals(dir)
/datum/component/sticker/Destroy(force)
var/atom/parent_atom = parent
parent_atom.cut_overlay(sticker_overlay)
unregister_turf_signals()
REMOVE_TRAIT(parent, TRAIT_STICKERED, REF(src))
QDEL_NULL(our_sticker)
QDEL_NULL(sticker_overlay)
return ..()
/datum/component/sticker/RegisterWithParent()
if(isliving(parent))
RegisterSignal(parent, COMSIG_LIVING_IGNITED, PROC_REF(on_ignite))
RegisterSignal(parent, COMSIG_COMPONENT_CLEAN_ACT, PROC_REF(on_clean))
/datum/component/sticker/UnregisterFromParent()
if(isliving(parent))
UnregisterSignal(parent, COMSIG_LIVING_IGNITED)
UnregisterSignal(parent, COMSIG_COMPONENT_CLEAN_ACT)
/// Subscribes to `COMSIG_TURF_EXPOSE` if parent atom is a turf. If turf is closed - subscribes to signal
/datum/component/sticker/proc/register_turf_signals(dir)
if(!isturf(parent))
return
listening_turf = isclosedturf(parent) ? get_step(parent, dir) : parent
RegisterSignal(listening_turf, COMSIG_TURF_EXPOSE, PROC_REF(on_turf_expose))
/// Unsubscribes from `COMSIG_TURF_EXPOSE` if `listening_turf` is not `null`.
/datum/component/sticker/proc/unregister_turf_signals()
if(isnull(listening_turf))
return
UnregisterSignal(listening_turf, COMSIG_TURF_EXPOSE)
/// Handles overlay creation from supplied atom, adds created icon to the parent object, moves source atom to the nullspace.
/datum/component/sticker/proc/stick(atom/movable/stickering_atom, px, py)
our_sticker = stickering_atom
our_sticker.moveToNullspace()
var/atom/parent_atom = parent
sticker_overlay = mutable_appearance(icon = our_sticker.icon, icon_state = our_sticker.icon_state, layer = parent_atom.layer + 0.01, appearance_flags = RESET_COLOR)
sticker_overlay.pixel_w = px - world.icon_size / 2
sticker_overlay.pixel_z = py - world.icon_size / 2
parent_atom.add_overlay(sticker_overlay)
ADD_TRAIT(parent, TRAIT_STICKERED, REF(src))
/// Moves stickered atom from the nullspace, deletes component.
/datum/component/sticker/proc/peel()
var/atom/parent_atom = parent
var/turf/drop_location = isnull(listening_turf) ? parent_atom.drop_location() : listening_turf
our_sticker.forceMove(drop_location)
our_sticker = null
qdel(src)
/datum/component/sticker/proc/on_ignite(datum/source)
SIGNAL_HANDLER
qdel(src)
/datum/component/sticker/proc/on_clean(datum/source, clean_types)
SIGNAL_HANDLER
peel()
return COMPONENT_CLEANED
/datum/component/sticker/proc/on_turf_expose(datum/source, datum/gas_mixture/air, exposed_temperature)
SIGNAL_HANDLER
if(exposed_temperature >= FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
qdel(src)