From e154cc974d2ca2e2c50c9f1f932c3a2c94be243c Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+MemedHams@users.noreply.github.com> Date: Sat, 12 Aug 2023 04:32:14 -0400 Subject: [PATCH 1/7] it's so real world icons --- code/__DEFINES/dcs/signals.dm | 1 + code/datums/elements/world_icon.dm | 122 +++++++++++++++++++++++++++++ code/game/objects/items.dm | 7 +- code/game/objects/items/kitchen.dm | 5 ++ icons/obj/world/melee.dmi | Bin 0 -> 471 bytes shiptest.dme | 1 + 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 code/datums/elements/world_icon.dm create mode 100644 icons/obj/world/melee.dmi diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 6a07aec4084e..3bf88bbc6de3 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -513,6 +513,7 @@ #define COMSIG_ITEM_AFTERATTACK "item_afterattack" //from base of obj/item/afterattack(): (atom/target, mob/user, params) #define COMSIG_ITEM_ATTACK_QDELETED "item_attack_qdeleted" //from base of obj/item/attack_qdeleted(): (atom/target, mob/user, params) #define COMSIG_ITEM_EQUIPPED "item_equip" //from base of obj/item/equipped(): (/mob/equipper, slot) +#define COMSIG_MOB_EQUIPPED_ITEM "mob_equipped_item" /// A mob has just equipped an item. Called on [/mob] from base of [/obj/item/equipped()]: (/obj/item/equipped_item, slot) #define COMSIG_ITEM_DROPPED "item_drop" //from base of obj/item/dropped(): (mob/user) #define COMSIG_ITEM_PICKUP "item_pickup" //from base of obj/item/pickup(): (/mob/taker) #define COMSIG_ITEM_ATTACK_ZONE "item_attack_zone" //from base of mob/living/carbon/attacked_by(): (mob/living/carbon/target, mob/living/user, hit_zone) diff --git a/code/datums/elements/world_icon.dm b/code/datums/elements/world_icon.dm new file mode 100644 index 000000000000..548711d77ca6 --- /dev/null +++ b/code/datums/elements/world_icon.dm @@ -0,0 +1,122 @@ +///////////////////////////////////////////////////////////// +////////// MOJAVE SUN WORLD ICON ELEMENT DIRECTORY ////////// +///////////////////////////////////////////////////////////// + +// Slap onto something to give it a world icon that differs from the inventory one (allows for realistically sized objects and all that) // +// To fix 25/06/2021 : Blood Decals, Mutable Overlays and other baked in bitch ass overlays that need to be remade when the icon changes // +// Fixed 07/05/2022: Now you can deal with the above by handling everything with attached_proc instead +// Fixed 12/04/2023: Icon states, Needs major tuning up by someone who can properly make it work + +/datum/element/world_icon + id_arg_index = 2 + element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH + /** + * If we want COMPLEX world icon behavior, this proc will handle icon updating when the item is NOT in the inventory. + * I just assumed that the default update_icon is for inventory sprites because ss13 basically focuses on how the sprites + * look on your hand, not how they realistically look in the world. + */ + var/attached_proc + /// Only used if attached_proc doesn't exist, simply changes the icon of target to this when it's in the inventory + var/inventory_icon + /// Only used if attached_proc doesn't exist, simply changes the icon of target to this when it's NOT in the inventory + var/world_icon + /// Only used when inventory state icon is different from original + var/inventory_icon_state + /// Only used when world state icon is different from original, pretty much just the original "icon_state" but if you for some reason need to flip the standard icon states for this element around you can use this + var/world_icon_state + +/datum/element/world_icon/Attach(obj/item/target, attached_proc, world_icon, inventory_icon, world_icon_state, inventory_icon_state) + . = ..() + if(!istype(target)) + return ELEMENT_INCOMPATIBLE + + src.attached_proc = attached_proc + src.world_icon = world_icon + src.world_icon_state = world_icon_state + src.inventory_icon = inventory_icon + src.inventory_icon_state = inventory_icon_state + RegisterSignal(target, COMSIG_ATOM_UPDATE_ICON, .proc/update_icon) + RegisterSignal(target, COMSIG_ATOM_UPDATE_ICON_STATE, .proc/update_icon_state) + RegisterSignal(target, list(COMSIG_ITEM_EQUIPPED, COMSIG_STORAGE_ENTERED, COMSIG_ITEM_DROPPED, COMSIG_STORAGE_EXITED), .proc/inventory_updated) + target.update_appearance(UPDATE_ICON) + target.update_appearance(UPDATE_ICON_STATE) + +/datum/element/world_icon/Detach(obj/item/source) + . = ..() + UnregisterSignal(source, COMSIG_ATOM_UPDATE_ICON) + UnregisterSignal(source, COMSIG_ATOM_UPDATE_ICON_STATE, .proc/update_icon_state) + UnregisterSignal(source, list(COMSIG_ITEM_EQUIPPED, COMSIG_STORAGE_ENTERED, COMSIG_ITEM_DROPPED, COMSIG_STORAGE_EXITED)) + source.update_appearance(UPDATE_ICON) + source.update_appearance(UPDATE_ICON_STATE) + +/datum/element/world_icon/proc/update_icon(obj/item/source, updates) + SIGNAL_HANDLER + + if((source.item_flags & IN_INVENTORY) || (source.loc && SEND_SIGNAL(source.loc, COMSIG_CONTAINS_STORAGE))) + if(attached_proc) + return + return default_inventory_icon(source) + + if(attached_proc) + return call(source, attached_proc)(updates) + else + return default_world_icon(source) + +/datum/element/world_icon/proc/update_icon_state(obj/item/source, updates) + SIGNAL_HANDLER + + if((source.item_flags & IN_INVENTORY) || (source.loc && SEND_SIGNAL(source.loc, COMSIG_CONTAINS_STORAGE))) + if(attached_proc) + return + return default_inventory_icon_state(source) + + if(attached_proc) + return call(source, attached_proc)(updates) + else + return default_world_icon_state(source) + +/datum/element/world_icon/proc/inventory_updated(obj/item/source) + SIGNAL_HANDLER + + source.update_appearance(UPDATE_ICON) + source.update_appearance(UPDATE_ICON_STATE) + +/datum/element/world_icon/proc/default_inventory_icon(obj/item/source) + SIGNAL_HANDLER + + source.icon = inventory_icon + +/datum/element/world_icon/proc/default_world_icon(obj/item/source) + SIGNAL_HANDLER + + source.icon = world_icon + +/datum/element/world_icon/proc/default_inventory_icon_state(obj/item/source) + SIGNAL_HANDLER + + if(!inventory_icon_state) + source.icon_state = source.icon_state + return + + INVOKE_ASYNC(src, .proc/check_inventory_state, source) + +/datum/element/world_icon/proc/default_world_icon_state(obj/item/source) + SIGNAL_HANDLER + + if(!world_icon_state) + source.icon_state = source.icon_state + return + + INVOKE_ASYNC(src, .proc/check_world_icon_state, source) + +/datum/element/world_icon/proc/check_inventory_state(obj/item/source) + SIGNAL_HANDLER + + inventory_icon_state = source.inventory_state + source.icon_state = inventory_icon_state + +/datum/element/world_icon/proc/check_world_icon_state(obj/item/source) + SIGNAL_HANDLER + + world_icon_state = source.world_state + source.icon_state = world_icon_state diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 2153f2cd993d..438df4719c05 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -192,6 +192,10 @@ GLOBAL_VAR_INIT(embedpocalypse, FALSE) // if true, all items will be able to emb var/canMouseDown = FALSE + //for setting world icons on the go + var/inventory_state + var/world_state + /obj/item/Initialize() if(attack_verb) @@ -515,12 +519,13 @@ GLOBAL_VAR_INIT(embedpocalypse, FALSE) // if true, all items will be able to emb /obj/item/proc/equipped(mob/user, slot, initial = FALSE) SHOULD_CALL_PARENT(1) visual_equipped(user, slot, initial) - SEND_SIGNAL(src, COMSIG_ITEM_EQUIPPED, user, slot) for(var/X in actions) var/datum/action/A = X if(item_action_slot_check(slot, user)) //some items only give their actions buttons when in a specific slot. A.Grant(user) item_flags |= IN_INVENTORY + SEND_SIGNAL(src, COMSIG_ITEM_EQUIPPED, user, slot) + SEND_SIGNAL(user, COMSIG_MOB_EQUIPPED_ITEM, src, slot) if(!initial) if(equip_sound && (slot_flags & slot)) playsound(src, equip_sound, EQUIP_SOUND_VOLUME, TRUE, ignore_walls = FALSE) diff --git a/code/game/objects/items/kitchen.dm b/code/game/objects/items/kitchen.dm index 71799b83004e..eed5037eba09 100644 --- a/code/game/objects/items/kitchen.dm +++ b/code/game/objects/items/kitchen.dm @@ -177,6 +177,7 @@ /obj/item/kitchen/knife/combat name = "combat knife" + icon = 'icons/obj/world/melee.dmi' icon_state = "buckknife" desc = "A military combat utility survival knife." embedding = list("pain_mult" = 4, "embed_chance" = 65, "fall_chance" = 10, "ignore_throwspeed_threshold" = TRUE) @@ -185,6 +186,10 @@ attack_verb = list("slashed", "stabbed", "sliced", "torn", "ripped", "cut") bayonet = TRUE +/obj/item/kitchen/knife/combat/Initialize() + . = ..() + AddElement(/datum/element/world_icon, null, icon, 'icons/obj/kitchen.dmi') + /obj/item/kitchen/knife/combat/survival name = "survival knife" icon_state = "survivalknife" diff --git a/icons/obj/world/melee.dmi b/icons/obj/world/melee.dmi new file mode 100644 index 0000000000000000000000000000000000000000..3fc9cb784f30cf4ea81a796785fe91049d244612 GIT binary patch literal 471 zcmV;|0Vw{7P)&PA)DSCj8=-HezF+an%cTZ1SE-y4ABQG8v zAWho)ZvX%Q0d!JMQvg8b*k%9#0El{2Sad{Xb7OL8aCB*JZU6vyoKseCa&`CgQ*iP1 zO*FR#?l72u=_W@h8I|e{dcBt|8#ges^oFz+D38TY?X(;dffc%Qxs<^8)$=0r&4b zG~B1)A&=`ROhI^qghODSzaEOH|D{2NcJp7n&Z)mkb(lv#$HD(=6N}}#i4QzaPl2DY zAT3xBXDmpB1tPyFd7(cG{Oc|C=Lq>y3+~ToOtn-v-weWB;w_d7X9ckw13ARxvX}q> N002ovPDHLkV1kH1$%X&` literal 0 HcmV?d00001 diff --git a/shiptest.dme b/shiptest.dme index c5df26f5427b..17b5331b84b9 100644 --- a/shiptest.dme +++ b/shiptest.dme @@ -629,6 +629,7 @@ #include "code\datums\elements\update_icon_blocker.dm" #include "code\datums\elements\update_icon_updates_onmob.dm" #include "code\datums\elements\waddling.dm" +#include "code\datums\elements\world_icon.dm" #include "code\datums\elements\decals\_decals.dm" #include "code\datums\elements\decals\blood.dm" #include "code\datums\helper_datums\events.dm" From f22237b420089764fa71be15c9a8b78b5514d14b Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+MemedHams@users.noreply.github.com> Date: Sat, 12 Aug 2023 06:49:00 -0400 Subject: [PATCH 2/7] e --- code/datums/elements/world_icon.dm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/datums/elements/world_icon.dm b/code/datums/elements/world_icon.dm index 548711d77ca6..2935375cb55c 100644 --- a/code/datums/elements/world_icon.dm +++ b/code/datums/elements/world_icon.dm @@ -1,6 +1,7 @@ ///////////////////////////////////////////////////////////// -////////// MOJAVE SUN WORLD ICON ELEMENT DIRECTORY ////////// +////////// WORLD ICON ELEMENT DIRECTORY ////////// ///////////////////////////////////////////////////////////// +//PORTED FROM MOJAVE SUN// // Slap onto something to give it a world icon that differs from the inventory one (allows for realistically sized objects and all that) // // To fix 25/06/2021 : Blood Decals, Mutable Overlays and other baked in bitch ass overlays that need to be remade when the icon changes // From 7347b41fbea91a49b8a950ad77bc6d1b398fcc1b Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+MemedHams@users.noreply.github.com> Date: Mon, 13 Nov 2023 17:49:18 -0500 Subject: [PATCH 3/7] linters : D I was so high when I wrote this :))) --- code/datums/elements/world_icon.dm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/code/datums/elements/world_icon.dm b/code/datums/elements/world_icon.dm index 2935375cb55c..951edf978f2e 100644 --- a/code/datums/elements/world_icon.dm +++ b/code/datums/elements/world_icon.dm @@ -11,11 +11,9 @@ /datum/element/world_icon id_arg_index = 2 element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH - /** - * If we want COMPLEX world icon behavior, this proc will handle icon updating when the item is NOT in the inventory. - * I just assumed that the default update_icon is for inventory sprites because ss13 basically focuses on how the sprites - * look on your hand, not how they realistically look in the world. - */ + //If we want COMPLEX world icon behavior, this proc will handle icon updating when the item is NOT in the inventory. + //I just assumed that the default update_icon is for inventory sprites because ss13 basically focuses on how the sprites + //look on your hand, not how they realistically look in the world. var/attached_proc /// Only used if attached_proc doesn't exist, simply changes the icon of target to this when it's in the inventory var/inventory_icon @@ -36,16 +34,16 @@ src.world_icon_state = world_icon_state src.inventory_icon = inventory_icon src.inventory_icon_state = inventory_icon_state - RegisterSignal(target, COMSIG_ATOM_UPDATE_ICON, .proc/update_icon) - RegisterSignal(target, COMSIG_ATOM_UPDATE_ICON_STATE, .proc/update_icon_state) - RegisterSignal(target, list(COMSIG_ITEM_EQUIPPED, COMSIG_STORAGE_ENTERED, COMSIG_ITEM_DROPPED, COMSIG_STORAGE_EXITED), .proc/inventory_updated) + RegisterSignal(target, COMSIG_ATOM_UPDATE_ICON, PROC_REF(update_icon)) + RegisterSignal(target, COMSIG_ATOM_UPDATE_ICON_STATE, PROC_REF(update_icon_state)) + RegisterSignal(target, list(COMSIG_ITEM_EQUIPPED, COMSIG_STORAGE_ENTERED, COMSIG_ITEM_DROPPED, COMSIG_STORAGE_EXITED), PROC_REF(inventory_updated)) target.update_appearance(UPDATE_ICON) target.update_appearance(UPDATE_ICON_STATE) /datum/element/world_icon/Detach(obj/item/source) . = ..() UnregisterSignal(source, COMSIG_ATOM_UPDATE_ICON) - UnregisterSignal(source, COMSIG_ATOM_UPDATE_ICON_STATE, .proc/update_icon_state) + UnregisterSignal(source, COMSIG_ATOM_UPDATE_ICON_STATE, PROC_REF(update_icon_state)) UnregisterSignal(source, list(COMSIG_ITEM_EQUIPPED, COMSIG_STORAGE_ENTERED, COMSIG_ITEM_DROPPED, COMSIG_STORAGE_EXITED)) source.update_appearance(UPDATE_ICON) source.update_appearance(UPDATE_ICON_STATE) @@ -99,7 +97,7 @@ source.icon_state = source.icon_state return - INVOKE_ASYNC(src, .proc/check_inventory_state, source) + INVOKE_ASYNC(src, PROC_REF(check_inventory_state, source)) /datum/element/world_icon/proc/default_world_icon_state(obj/item/source) SIGNAL_HANDLER @@ -108,7 +106,7 @@ source.icon_state = source.icon_state return - INVOKE_ASYNC(src, .proc/check_world_icon_state, source) + INVOKE_ASYNC(src, PROC_REF(check_world_icon_state, source)) /datum/element/world_icon/proc/check_inventory_state(obj/item/source) SIGNAL_HANDLER From 11b6def3e5e56f157fe2bf1953f6b15bb4be7f25 Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+MemedHams@users.noreply.github.com> Date: Mon, 13 Nov 2023 17:52:18 -0500 Subject: [PATCH 4/7] living too dangerously apparently haha oops --- code/datums/elements/world_icon.dm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/datums/elements/world_icon.dm b/code/datums/elements/world_icon.dm index 951edf978f2e..bcb0129c6c68 100644 --- a/code/datums/elements/world_icon.dm +++ b/code/datums/elements/world_icon.dm @@ -97,7 +97,7 @@ source.icon_state = source.icon_state return - INVOKE_ASYNC(src, PROC_REF(check_inventory_state, source)) + INVOKE_ASYNC(src, PROC_REF(check_inventory_state), source) /datum/element/world_icon/proc/default_world_icon_state(obj/item/source) SIGNAL_HANDLER @@ -106,7 +106,7 @@ source.icon_state = source.icon_state return - INVOKE_ASYNC(src, PROC_REF(check_world_icon_state, source)) + INVOKE_ASYNC(src, PROC_REF(check_world_icon_state), source) /datum/element/world_icon/proc/check_inventory_state(obj/item/source) SIGNAL_HANDLER From da043ee76972a8ad6c94a61151221c58aeeae8ba Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+MemedHams@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:25:39 -0400 Subject: [PATCH 5/7] bad signal bad signal... --- code/__DEFINES/dcs/signals.dm | 1 - code/datums/elements/decals/blood.dm | 1 + code/game/objects/items.dm | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index df8e41aba98c..2b8dc67cb684 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -520,7 +520,6 @@ #define COMSIG_ITEM_AFTERATTACK "item_afterattack" //from base of obj/item/afterattack(): (atom/target, mob/user, params) #define COMSIG_ITEM_ATTACK_QDELETED "item_attack_qdeleted" //from base of obj/item/attack_qdeleted(): (atom/target, mob/user, params) #define COMSIG_ITEM_EQUIPPED "item_equip" //from base of obj/item/equipped(): (/mob/equipper, slot) -#define COMSIG_MOB_EQUIPPED_ITEM "mob_equipped_item" /// A mob has just equipped an item. Called on [/mob] from base of [/obj/item/equipped()]: (/obj/item/equipped_item, slot) #define COMSIG_ITEM_DROPPED "item_drop" //from base of obj/item/dropped(): (mob/user) #define COMSIG_ITEM_PICKUP "item_pickup" //from base of obj/item/pickup(): (/mob/taker) #define COMSIG_ITEM_ATTACK_ZONE "item_attack_zone" //from base of mob/living/carbon/attacked_by(): (mob/living/carbon/target, mob/living/user, hit_zone) diff --git a/code/datums/elements/decals/blood.dm b/code/datums/elements/decals/blood.dm index 85f75bef2416..8020c04aeee0 100644 --- a/code/datums/elements/decals/blood.dm +++ b/code/datums/elements/decals/blood.dm @@ -30,3 +30,4 @@ override[EXAMINE_POSITION_ARTICLE] = A.gender == PLURAL? "some" : "a" override[EXAMINE_POSITION_BEFORE] = " blood-stained " return COMPONENT_EXNAME_CHANGED + diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 21a84a49a080..c21434385c50 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -518,7 +518,6 @@ GLOBAL_VAR_INIT(embedpocalypse, FALSE) // if true, all items will be able to emb A.Grant(user) item_flags |= IN_INVENTORY SEND_SIGNAL(src, COMSIG_ITEM_EQUIPPED, user, slot) - SEND_SIGNAL(user, COMSIG_MOB_EQUIPPED_ITEM, src, slot) if(!initial) if(equip_sound && (slot_flags & slot)) playsound(src, equip_sound, EQUIP_SOUND_VOLUME, TRUE, ignore_walls = FALSE) From 49f63b321c0367480bff5c84a3b8531273c76ba9 Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+MemedHams@users.noreply.github.com> Date: Wed, 10 Apr 2024 21:43:20 -0400 Subject: [PATCH 6/7] wow the depths embrace you --- code/datums/components/forensics.dm | 2 +- code/datums/elements/decals/blood.dm | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/code/datums/components/forensics.dm b/code/datums/components/forensics.dm index 3c006073304c..6f2a34e50ea5 100644 --- a/code/datums/components/forensics.dm +++ b/code/datums/components/forensics.dm @@ -192,4 +192,4 @@ return if(isitem(parent)) var/obj/item/I = parent - I.AddElement(/datum/element/decal/blood, initial(I.icon) || I.icon, initial(I.icon_state) || I.icon_state, _color = get_blood_dna_color(blood_DNA)) + I.AddElement(/datum/element/decal/blood, I.icon, I.icon_state, _color = get_blood_dna_color(blood_DNA)) diff --git a/code/datums/elements/decals/blood.dm b/code/datums/elements/decals/blood.dm index 8020c04aeee0..0a3ca8ce59a3 100644 --- a/code/datums/elements/decals/blood.dm +++ b/code/datums/elements/decals/blood.dm @@ -6,9 +6,11 @@ . = ..() RegisterSignal(target, COMSIG_ATOM_GET_EXAMINE_NAME, PROC_REF(get_examine_name), TRUE) + RegisterSignal(target, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED), PROC_REF(redraw), TRUE) /datum/element/decal/blood/Detach(atom/source, force) UnregisterSignal(source, COMSIG_ATOM_GET_EXAMINE_NAME) + UnregisterSignal(source, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED)) return ..() /datum/element/decal/blood/generate_appearance(_icon, _icon_state, _dir, _layer, _color, _alpha, source) @@ -31,3 +33,10 @@ override[EXAMINE_POSITION_BEFORE] = " blood-stained " return COMPONENT_EXNAME_CHANGED +///this is probably quite bad, let me know if you have a better solution for this -S +/datum/element/decal/blood/proc/redraw(datum/source, mob/user) + SIGNAL_HANDLER + + var/atom/bloodsource = source + Detach(source) + bloodsource.AddElement(/datum/element/decal/blood, bloodsource.icon, bloodsource.icon_state, _color = get_blood_dna_color(bloodsource.return_blood_DNA())) From c991c7b7fb5d5295cb2fb4bd36f45eccade96b8b Mon Sep 17 00:00:00 2001 From: Sun-Soaked <45698967+Sun-Soaked@users.noreply.github.com> Date: Sat, 18 May 2024 15:54:04 -0400 Subject: [PATCH 7/7] e --- icons/obj/world/melee.dmi | Bin 471 -> 474 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/icons/obj/world/melee.dmi b/icons/obj/world/melee.dmi index 3fc9cb784f30cf4ea81a796785fe91049d244612..ff8e2114e82750930ad8ac463473092dc6af961d 100644 GIT binary patch delta 45 zcmV+|0Mh^01KI