From cdbd585f4de7db52f7cc7b751e22e243b7d7e207 Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 6 Jul 2021 21:50:53 +0300 Subject: [PATCH] update_appearance --- code/__DEFINES/dcs/flags.dm | 16 +++++ code/__DEFINES/dcs/signals.dm | 33 ++++++++-- code/game/atoms.dm | 60 +++++++++++++++---- code/game/machinery/_machinery.dm | 11 ++++ .../mecha/equipment/weapons/mecha_ammo.dm | 2 +- code/game/objects/items/plushes.dm | 2 +- code/game/objects/items/stacks/cash.dm | 2 +- code/game/objects/structures/door_assembly.dm | 2 +- code/modules/arousal/genitals.dm | 4 +- code/modules/arousal/toys/dildos.dm | 2 +- .../food_and_drinks/food/customizables.dm | 2 +- code/modules/hydroponics/gene_modder.dm | 2 +- .../mob/living/simple_animal/slime/slime.dm | 2 +- code/modules/power/power.dm | 24 +++++--- .../research/nanites/nanite_program_hub.dm | 5 +- .../research/nanites/nanite_programmer.dm | 5 +- 16 files changed, 134 insertions(+), 40 deletions(-) diff --git a/code/__DEFINES/dcs/flags.dm b/code/__DEFINES/dcs/flags.dm index 719a795824..3a6877eeb3 100644 --- a/code/__DEFINES/dcs/flags.dm +++ b/code/__DEFINES/dcs/flags.dm @@ -83,3 +83,19 @@ #define COMBAT_MODE_ACTIVE (1<<1) /// combat mode is not active #define COMBAT_MODE_INACTIVE (1<<2) + +// Update flags for [/atom/proc/update_appearance] +/// Update the atom's name +#define UPDATE_NAME (1<<0) +/// Update the atom's desc +#define UPDATE_DESC (1<<1) +/// Update the atom's icon state +#define UPDATE_ICON_STATE (1<<2) +/// Update the atom's overlays +#define UPDATE_OVERLAYS (1<<3) +/// Update the atom's greyscaling +#define UPDATE_GREYSCALE (1<<4) +/// Update the atom's smoothing. (More accurately, queue it for an update) +#define UPDATE_SMOOTHING (1<<5) +/// Update the atom's icon +#define UPDATE_ICON (UPDATE_ICON_STATE|UPDATE_OVERLAYS) diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 5f8745ca8e..e692e424e8 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -74,11 +74,30 @@ #define EXAMINE_POSITION_BEFORE (1<<1) //End positions #define COMPONENT_EXNAME_CHANGED (1<<0) -#define COMSIG_ATOM_UPDATE_ICON "atom_update_icon" //from base of atom/update_icon(): () - #define COMSIG_ATOM_NO_UPDATE_ICON_STATE 1 - #define COMSIG_ATOM_NO_UPDATE_OVERLAYS 2 -#define COMSIG_ATOM_UPDATE_OVERLAYS "atom_update_overlays" //from base of atom/update_overlays(): (list/new_overlays) -#define COMSIG_ATOM_UPDATED_ICON "atom_updated_icon" //from base of atom/update_icon(): (signalOut, did_anything) +///from base of [/atom/proc/update_appearance]: (updates) +#define COMSIG_ATOM_UPDATE_APPEARANCE "atom_update_appearance" + /// If returned from [COMSIG_ATOM_UPDATE_APPEARANCE] it prevents the atom from updating its name. + #define COMSIG_ATOM_NO_UPDATE_NAME UPDATE_NAME + /// If returned from [COMSIG_ATOM_UPDATE_APPEARANCE] it prevents the atom from updating its desc. + #define COMSIG_ATOM_NO_UPDATE_DESC UPDATE_DESC + /// If returned from [COMSIG_ATOM_UPDATE_APPEARANCE] it prevents the atom from updating its icon. + #define COMSIG_ATOM_NO_UPDATE_ICON UPDATE_ICON +///from base of [/atom/proc/update_name]: (updates) +#define COMSIG_ATOM_UPDATE_NAME "atom_update_name" +///from base of [/atom/proc/update_desc]: (updates) +#define COMSIG_ATOM_UPDATE_DESC "atom_update_desc" +///from base of [/atom/update_icon]: () +#define COMSIG_ATOM_UPDATE_ICON "atom_update_icon" + /// If returned from [COMSIG_ATOM_UPDATE_ICON] it prevents the atom from updating its icon state. + #define COMSIG_ATOM_NO_UPDATE_ICON_STATE UPDATE_ICON_STATE + /// If returned from [COMSIG_ATOM_UPDATE_ICON] it prevents the atom from updating its overlays. + #define COMSIG_ATOM_NO_UPDATE_OVERLAYS UPDATE_OVERLAYS +///from base of [atom/update_icon_state]: () +#define COMSIG_ATOM_UPDATE_ICON_STATE "atom_update_icon_state" +///from base of [/atom/update_overlays]: (list/new_overlays) +#define COMSIG_ATOM_UPDATE_OVERLAYS "atom_update_overlays" +///from base of [/atom/update_icon]: (signalOut, did_anything) +#define COMSIG_ATOM_UPDATED_ICON "atom_updated_icon" #define COMSIG_ATOM_ENTERED "atom_entered" //from base of atom/Entered(): (atom/movable/entering, /atom) #define COMSIG_ATOM_EXIT "atom_exit" //from base of atom/Exit(): (/atom/movable/exiting, /atom/newloc) #define COMPONENT_ATOM_BLOCK_EXIT 1 @@ -361,6 +380,10 @@ // /machinery signals #define COMSIG_MACHINE_EJECT_OCCUPANT "eject_occupant" //from base of obj/machinery/dropContents() (occupant) +///from base power_change() when power is lost +#define COMSIG_MACHINERY_POWER_LOST "machinery_power_lost" +///from base power_change() when power is restored +#define COMSIG_MACHINERY_POWER_RESTORED "machinery_power_restored" // /obj/item signals #define COMSIG_ITEM_ATTACK "item_attack" //from base of obj/item/attack(): (/mob/living/target, /mob/living/user) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index e9957fdae2..0379897c08 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -531,37 +531,75 @@ if(!LAZYLEN(.)) // lol ..length return list("You examine [src] closer, but find nothing of interest...") +/** + * Updates the appearence of the icon + * + * Mostly delegates to update_name, update_desc, and update_icon + * + * Arguments: + * - updates: A set of bitflags dictating what should be updated. Defaults to [ALL] + */ +/atom/proc/update_appearance(updates=ALL) + //SHOULD_NOT_SLEEP(TRUE) + //SHOULD_CALL_PARENT(TRUE) + + . = NONE + updates &= ~SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_APPEARANCE, updates) + if(updates & UPDATE_NAME) + . |= update_name(updates) + if(updates & UPDATE_DESC) + . |= update_desc(updates) + if(updates & UPDATE_ICON) + . |= update_icon(updates) + +/// Updates the name of the atom +/atom/proc/update_name(updates=ALL) + //SHOULD_CALL_PARENT(TRUE) + return SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_NAME, updates) + +/// Updates the description of the atom +/atom/proc/update_desc(updates=ALL) + //SHOULD_CALL_PARENT(TRUE) + return SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_DESC, updates) + /// Updates the icon of the atom -/atom/proc/update_icon() - // I expect we're going to need more return flags and options in this proc - var/signalOut = SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_ICON) - . = FALSE +/atom/proc/update_icon(updates=ALL) + SIGNAL_HANDLER + //SHOULD_CALL_PARENT(TRUE) - if(!(signalOut & COMSIG_ATOM_NO_UPDATE_ICON_STATE)) + . = NONE + updates &= ~SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_ICON, updates) + if(updates & UPDATE_ICON_STATE) update_icon_state() - . = TRUE + . |= UPDATE_ICON_STATE - if(!(signalOut & COMSIG_ATOM_NO_UPDATE_OVERLAYS)) - var/list/new_overlays = update_overlays() + if(updates & UPDATE_OVERLAYS) + if(LAZYLEN(managed_vis_overlays)) + SSvis_overlays.remove_vis_overlay(src, managed_vis_overlays) + + var/list/new_overlays = update_overlays(updates) if(managed_overlays) cut_overlay(managed_overlays) managed_overlays = null if(length(new_overlays)) managed_overlays = new_overlays add_overlay(new_overlays) - . = TRUE + . |= UPDATE_OVERLAYS - SEND_SIGNAL(src, COMSIG_ATOM_UPDATED_ICON, signalOut, .) + . |= SEND_SIGNAL(src, COMSIG_ATOM_UPDATED_ICON, updates, .) /// Updates the icon state of the atom /atom/proc/update_icon_state() + //SHOULD_CALL_PARENT(TRUE) + return SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_ICON_STATE) /// Updates the overlays of the atom /atom/proc/update_overlays() - SHOULD_CALL_PARENT(TRUE) + //SHOULD_CALL_PARENT(TRUE) . = list() SEND_SIGNAL(src, COMSIG_ATOM_UPDATE_OVERLAYS, .) + /atom/proc/relaymove(mob/living/user) if(!istype(user)) return //why are you buckling nonliving mobs to atoms? diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 2ccf7d317d..4f61577eca 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -176,6 +176,17 @@ Class Procs: /obj/machinery/proc/process_atmos()//If you dont use process why are you here return PROCESS_KILL +///Called when we want to change the value of the stat variable. Holds bitflags. +/obj/machinery/proc/set_machine_stat(new_value) + if(new_value == stat) + return + . = stat + stat = new_value + on_machine_stat_update(stat) + +/obj/machinery/proc/on_machine_stat_update(stat) + return + /obj/machinery/emp_act(severity) . = ..() if(use_power && !stat && !(. & EMP_PROTECT_SELF)) diff --git a/code/game/mecha/equipment/weapons/mecha_ammo.dm b/code/game/mecha/equipment/weapons/mecha_ammo.dm index 83a85ffcba..3253e6cbd6 100644 --- a/code/game/mecha/equipment/weapons/mecha_ammo.dm +++ b/code/game/mecha/equipment/weapons/mecha_ammo.dm @@ -12,7 +12,7 @@ var/load_audio = "sound/weapons/gun_magazine_insert_empty_1.ogg" var/ammo_type -/obj/item/mecha_ammo/proc/update_name() +/obj/item/mecha_ammo/update_name() if(!rounds) name = "empty ammo box" desc = "An exosuit ammuniton box that has since been emptied. Please recycle." diff --git a/code/game/objects/items/plushes.dm b/code/game/objects/items/plushes.dm index 31481f58cf..4d2bee3089 100644 --- a/code/game/objects/items/plushes.dm +++ b/code/game/objects/items/plushes.dm @@ -446,7 +446,7 @@ mood_message = null cheer_up() -/obj/item/toy/plush/proc/update_desc() +/obj/item/toy/plush/update_desc() desc = normal_desc if(mood_message) desc += mood_message diff --git a/code/game/objects/items/stacks/cash.dm b/code/game/objects/items/stacks/cash.dm index 68762a63c7..382e361e8a 100644 --- a/code/game/objects/items/stacks/cash.dm +++ b/code/game/objects/items/stacks/cash.dm @@ -18,7 +18,7 @@ . = ..() update_desc() -/obj/item/stack/spacecash/proc/update_desc() +/obj/item/stack/spacecash/update_desc() var/total_worth = get_item_credit_value() desc = "It's worth [total_worth] credit[( total_worth > 1 ) ? "s" : ""]" diff --git a/code/game/objects/structures/door_assembly.dm b/code/game/objects/structures/door_assembly.dm index aba3b743bb..d03e0fd57e 100644 --- a/code/game/objects/structures/door_assembly.dm +++ b/code/game/objects/structures/door_assembly.dm @@ -269,7 +269,7 @@ . += get_airlock_overlay("glass_construction", overlays_file) . += get_airlock_overlay("panel_c[state+1]", overlays_file) -/obj/structure/door_assembly/proc/update_name() +/obj/structure/door_assembly/update_name() name = "" switch(state) if(AIRLOCK_ASSEMBLY_NEEDS_WIRES) diff --git a/code/modules/arousal/genitals.dm b/code/modules/arousal/genitals.dm index 723049a784..ed41cae8ce 100644 --- a/code/modules/arousal/genitals.dm +++ b/code/modules/arousal/genitals.dm @@ -150,7 +150,7 @@ /obj/item/organ/genital/proc/update_size() return -/obj/item/organ/genital/proc/update_appearance() +/obj/item/organ/genital/proc/update_appearance_genitals() if(!owner || owner.stat == DEAD) aroused_state = FALSE @@ -187,7 +187,7 @@ . = ..() if(.) update() - RegisterSignal(owner, COMSIG_MOB_DEATH, .proc/update_appearance) + RegisterSignal(owner, COMSIG_MOB_DEATH, .proc/update_appearance_genitals) if(genital_flags & GENITAL_THROUGH_CLOTHES) owner.exposed_genitals += src diff --git a/code/modules/arousal/toys/dildos.dm b/code/modules/arousal/toys/dildos.dm index 2482b93300..4de6877915 100644 --- a/code/modules/arousal/toys/dildos.dm +++ b/code/modules/arousal/toys/dildos.dm @@ -20,7 +20,7 @@ var/is_knotted = FALSE //Lists moved to _cit_helpers.dm as globals so they're not instanced individually -/obj/item/dildo/proc/update_appearance() +/obj/item/dildo/update_appearance() icon_state = "[dildo_type]_[dildo_shape]_[dildo_size]" var/sizeword = "" switch(dildo_size) diff --git a/code/modules/food_and_drinks/food/customizables.dm b/code/modules/food_and_drinks/food/customizables.dm index 0e2bdc63c8..42f536c4f3 100644 --- a/code/modules/food_and_drinks/food/customizables.dm +++ b/code/modules/food_and_drinks/food/customizables.dm @@ -66,7 +66,7 @@ . = ..() -/obj/item/reagent_containers/food/snacks/customizable/proc/update_name(obj/item/reagent_containers/food/snacks/S) +/obj/item/reagent_containers/food/snacks/customizable/update_name(obj/item/reagent_containers/food/snacks/S) for(var/obj/item/I in ingredients) if(!istype(S, I.type)) customname = "custom" diff --git a/code/modules/hydroponics/gene_modder.dm b/code/modules/hydroponics/gene_modder.dm index a0c273613f..a6ba5ec461 100644 --- a/code/modules/hydroponics/gene_modder.dm +++ b/code/modules/hydroponics/gene_modder.dm @@ -430,7 +430,7 @@ src.pixel_x = rand(-5, 5) src.pixel_y = rand(-5, 5) -/obj/item/disk/plantgene/proc/update_name() +/obj/item/disk/plantgene/update_name() if(gene) name = "[gene.get_name()] (plant data disk)" else diff --git a/code/modules/mob/living/simple_animal/slime/slime.dm b/code/modules/mob/living/simple_animal/slime/slime.dm index f6169be902..68de074e07 100644 --- a/code/modules/mob/living/simple_animal/slime/slime.dm +++ b/code/modules/mob/living/simple_animal/slime/slime.dm @@ -129,7 +129,7 @@ coretype = text2path("/obj/item/slime_extract/[sanitizedcolour]") regenerate_icons() -/mob/living/simple_animal/slime/proc/update_name() +/mob/living/simple_animal/slime/update_name() if(slime_name_regex.Find(name)) number = rand(1, 1000) name = "[colour] [is_adult ? "adult" : "baby"] slime ([number])" diff --git a/code/modules/power/power.dm b/code/modules/power/power.dm index 9bbdcf4f66..c2dd77290a 100644 --- a/code/modules/power/power.dm +++ b/code/modules/power/power.dm @@ -104,15 +104,23 @@ /obj/machinery/proc/removeStaticPower(value, powerchannel) addStaticPower(-value, powerchannel) -/obj/machinery/proc/power_change() // called whenever the power settings of the containing area change - // by default, check equipment channel & set flag - // can override if needed - if(powered(power_channel)) - stat &= ~NOPOWER - else +/obj/machinery/proc/power_change() + //SIGNAL_HANDLER + //SHOULD_CALL_PARENT(TRUE) - stat |= NOPOWER - return + if(stat & BROKEN) + return + if(powered(power_channel)) + if(stat & NOPOWER) + SEND_SIGNAL(src, COMSIG_MACHINERY_POWER_RESTORED) + . = TRUE + set_machine_stat(stat & ~NOPOWER) + else + if(!(stat & NOPOWER)) + SEND_SIGNAL(src, COMSIG_MACHINERY_POWER_LOST) + . = TRUE + set_machine_stat(stat | NOPOWER) + update_appearance() // connect the machine to a powernet if a node cable is present on the turf /obj/machinery/power/proc/connect_to_network() diff --git a/code/modules/research/nanites/nanite_program_hub.dm b/code/modules/research/nanites/nanite_program_hub.dm index 5baeb8b846..db94f6548b 100644 --- a/code/modules/research/nanites/nanite_program_hub.dm +++ b/code/modules/research/nanites/nanite_program_hub.dm @@ -28,11 +28,10 @@ /obj/machinery/nanite_program_hub/update_overlays() . = ..() - SSvis_overlays.remove_vis_overlay(src, managed_vis_overlays) if((stat & (NOPOWER|MAINT|BROKEN)) || panel_open) return - SSvis_overlays.add_vis_overlay(src, icon, "nanite_program_hub_on", layer, plane) - SSvis_overlays.add_vis_overlay(src, icon, "nanite_program_hub_on", EMISSIVE_LAYER, EMISSIVE_PLANE) + . += mutable_appearance(icon, "nanite_program_hub_on") + . += mutable_appearance(icon, "nanite_program_hub_on", layer, EMISSIVE_PLANE) /obj/machinery/nanite_program_hub/attackby(obj/item/I, mob/user) if(istype(I, /obj/item/disk/nanite_program)) diff --git a/code/modules/research/nanites/nanite_programmer.dm b/code/modules/research/nanites/nanite_programmer.dm index f23a44909c..9399e69086 100644 --- a/code/modules/research/nanites/nanite_programmer.dm +++ b/code/modules/research/nanites/nanite_programmer.dm @@ -13,11 +13,10 @@ /obj/machinery/nanite_programmer/update_overlays() . = ..() - SSvis_overlays.remove_vis_overlay(src, managed_vis_overlays) if((stat & (NOPOWER|MAINT|BROKEN)) || panel_open) return - SSvis_overlays.add_vis_overlay(src, icon, "nanite_programmer_on", layer, plane) - SSvis_overlays.add_vis_overlay(src, icon, "nanite_programmer_on", EMISSIVE_LAYER, EMISSIVE_PLANE) + . += mutable_appearance(icon, "nanite_programmer_on") + . += mutable_appearance(icon, "nanite_programmer_on", layer, EMISSIVE_PLANE) /obj/machinery/nanite_programmer/attackby(obj/item/I, mob/user) if(istype(I, /obj/item/disk/nanite_program))