From 8ee205a7aad6c2be9e255c27f32b56457db94da0 Mon Sep 17 00:00:00 2001 From: Cody Brittain Date: Wed, 22 May 2024 05:09:12 -0400 Subject: [PATCH] Add support for item tooltips and outlines (#19154) This adds support for item tooltips and outlines, if the item in question is in an inventory and not in storage: ![image](https://github.com/Aurorastation/Aurora.3/assets/1779662/25a027b1-f78b-434c-971e-acd27c98eb3c) --------- Co-authored-by: Cody Brittain --- code/__DEFINES/color.dm | 8 ++ .../signals/signals_object/signals_object.dm | 2 + code/__DEFINES/misc.dm | 16 ++-- code/game/objects/items.dm | 79 +++++++++++++++++++ .../objects/items/weapons/storage/storage.dm | 1 + .../preference_setup/global/02_settings.dm | 2 + code/modules/client/preferences.dm | 2 +- code/modules/client/preferences_toggles.dm | 18 +++++ .../GeneralCamo - Item Outlines.yml | 58 ++++++++++++++ 9 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 html/changelogs/GeneralCamo - Item Outlines.yml diff --git a/code/__DEFINES/color.dm b/code/__DEFINES/color.dm index 34492d7b6d9..090461f4ca3 100644 --- a/code/__DEFINES/color.dm +++ b/code/__DEFINES/color.dm @@ -166,3 +166,11 @@ #define BLOB_COLOR_PULS "#b5ff5b" #define RANDOM_RGB rgb(rand(0,255), rand(0,255), rand(0,255)) + +///Main colors for UI themes +#define COLOR_THEME_MIDNIGHT "#6086A0" +#define COLOR_THEME_PLASMAFIRE "#FFB200" +#define COLOR_THEME_RETRO "#24CA00" +#define COLOR_THEME_SLIMECORE "#4FB259" +#define COLOR_THEME_OPERATIVE "#B8221F" +#define COLOR_THEME_CLOCKWORK "#CFBA47" diff --git a/code/__DEFINES/dcs/signals/signals_object/signals_object.dm b/code/__DEFINES/dcs/signals/signals_object/signals_object.dm index 1cb47de99a0..6ceb286e458 100644 --- a/code/__DEFINES/dcs/signals/signals_object/signals_object.dm +++ b/code/__DEFINES/dcs/signals/signals_object/signals_object.dm @@ -7,3 +7,5 @@ ///from base of obj/item/dropped(): (mob/user) #define COMSIG_ITEM_DROPPED "item_drop" +///from base of obj/item/pickup(): (mob/user) +#define COMSIG_ITEM_PICKUP "item_pickup" diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 368493a4dac..d33e0b86fcf 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -47,14 +47,14 @@ #define CHAT_NOICONS 0x8000 #define CHAT_GHOSTLOOC 0x10000 -// 0x1 is free. -// 0x2 is free. -#define PROGRESS_BARS 0x4 -#define PARALLAX_IS_STATIC 0x8 -#define FLOATING_MESSAGES 0x10 -#define HOTKEY_DEFAULT 0x20 -#define FULLSCREEN_MODE 0x40 -#define ACCENT_TAG_TEXT 0x80 +#define SEE_ITEM_OUTLINES 0x1 +#define HIDE_ITEM_TOOLTIPS 0x2 +#define PROGRESS_BARS 0x4 +#define PARALLAX_IS_STATIC 0x8 +#define FLOATING_MESSAGES 0x10 +#define HOTKEY_DEFAULT 0x20 +#define FULLSCREEN_MODE 0x40 +#define ACCENT_TAG_TEXT 0x80 #define TOGGLES_DEFAULT (SOUND_ADMINHELP | SOUND_MIDI | SOUND_LOBBY | CHAT_OOC | CHAT_DEAD | CHAT_GHOSTEARS | CHAT_GHOSTSIGHT | CHAT_PRAYER | CHAT_RADIO | CHAT_ATTACKLOGS | CHAT_LOOC | CHAT_GHOSTLOOC) diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 5db136b1c4f..ccd4bb75dee 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -238,6 +238,16 @@ ///Used to determine what this item can be changed into with a modkit var/list/convert_options + //Tooltip vars + var/in_inventory = FALSE //is this item equipped into an inventory slot or hand of a mob? + var/tip_timer = 0 + + // item hover FX + /// Is this item inside a storage object? + var/in_storage = FALSE + /// Holder var for the item outline filter, null when no outline filter on the item. + var/outline_filter + /obj/item/Initialize(mapload, ...) . = ..() if(islist(armor)) @@ -481,6 +491,8 @@ SEND_SIGNAL(src, COMSIG_ITEM_DROPPED, user) + in_inventory = FALSE + if(user && (z_flags & ZMM_MANGLE_PLANES)) addtimer(CALLBACK(user, /mob/proc/check_emissive_equipment), 0, TIMER_UNIQUE) @@ -511,17 +523,21 @@ /obj/item/proc/pickup(mob/user) pixel_x = 0 pixel_y = 0 + SEND_SIGNAL(src, COMSIG_ITEM_PICKUP, user) if(item_flags & ITEM_FLAG_HELD_MAP_TEXT) addtimer(CALLBACK(src, PROC_REF(check_maptext)), 1) // invoke async does not work here + in_inventory = TRUE do_pickup_animation(user) // called when this item is removed from a storage item, which is passed on as S. The loc variable is already set to the new destination before this is called. /obj/item/proc/on_exit_storage(obj/item/storage/S as obj) do_drop_animation(S) + in_storage = FALSE return // called when this item is added into a storage item, which is passed on as S. The loc variable is already set to the storage item. /obj/item/proc/on_enter_storage(obj/item/storage/S as obj) + in_storage = TRUE return // called when "found" in pockets and storage items. Returns 1 if the search should end. @@ -538,6 +554,7 @@ equip_slot = slot if(user.client) user.client.screen |= src if(user.pulling == src) user.stop_pulling() + in_inventory = TRUE if(slot == slot_l_hand || slot == slot_r_hand) playsound(src, pickup_sound, PICKUP_SOUND_VOLUME) else if(slot_flags && slot) @@ -1171,6 +1188,7 @@ modules/mob/living/carbon/human/life.dm if you die, you will be zoomed out. /obj/item/throw_at() ..() + in_inventory = FALSE if(item_flags & ITEM_FLAG_HELD_MAP_TEXT) check_maptext() @@ -1225,6 +1243,67 @@ modules/mob/living/carbon/human/life.dm if you die, you will be zoomed out. /obj/item/proc/throw_fail_consequences(var/mob/living/carbon/C) return +/obj/item/proc/openTip(location, control, params, user) + openToolTip(user, src, params, title = name, content = "[desc]", theme = "") + +/obj/item/MouseEntered(location, control, params) + . = ..() + if(in_inventory || in_storage) + var/mob/user = usr + if(!(user.client.prefs.toggles_secondary & HIDE_ITEM_TOOLTIPS)) + tip_timer = addtimer(CALLBACK(src, PROC_REF(openTip), location, control, params, user), 8, TIMER_STOPPABLE) + if(QDELETED(src)) + return + if(!(user.client.prefs.toggles_secondary & SEE_ITEM_OUTLINES)) + return + var/mob/living/L = user + if(istype(L) && L.incapacitated()) + apply_outline(L, COLOR_RED_GRAY) //if they're dead or handcuffed, let's show the outline as red to indicate that they can't interact with that right now + else + apply_outline(L) //if the player's alive and well we send the command with no color set, so it uses the theme's color + +/obj/item/MouseDrop(atom/over, src_location, over_location, src_control, over_control, params) + . = ..() + remove_outline() + +/obj/item/MouseExited() + deltimer(tip_timer) //delete any in-progress timer if the mouse is moved off the item before it finishes + closeToolTip(usr) + remove_outline() + return ..() + +/obj/item/proc/apply_outline(mob/user, outline_color = null) + if(!(in_inventory || in_storage) || QDELETED(src) || isobserver(user)) //cancel if the item isn't in an inventory, is being deleted, or if the person hovering is a ghost (so that people spectating you don't randomly make your items glow) + return + var/theme = lowertext(user.client.prefs.UI_style) + if(!outline_color) //if we weren't provided with a color, take the theme's color + switch(theme) //yeah it kinda has to be this way + if("midnight") + outline_color = COLOR_THEME_MIDNIGHT + if("plasmafire") + outline_color = COLOR_THEME_PLASMAFIRE + if("retro") + outline_color = COLOR_THEME_RETRO + if("slimecore") + outline_color = COLOR_THEME_SLIMECORE + if("operative") + outline_color = COLOR_THEME_OPERATIVE + if("clockwork") + outline_color = COLOR_THEME_CLOCKWORK + else //this should never happen, hopefully + outline_color = COLOR_WHITE + if(color) + outline_color = COLOR_WHITE //if the item is recolored then the outline will be too, let's make the outline white so it becomes the same color instead of some ugly mix of the theme and the tint + if(outline_filter) + filters -= outline_filter + outline_filter = filter(type = "outline", size = 1, color = outline_color) + filters += outline_filter + +/obj/item/proc/remove_outline() + if(outline_filter) + filters -= outline_filter + outline_filter = null + /** * Determines if the item can be used to cut down wood (trees and the likes) * diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index 2fd95d5b1a8..98daa9f63cb 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -203,6 +203,7 @@ . += "It contains: [counting_english_list(contents)]" /obj/item/storage/MouseDrop(obj/over_object) + . = ..() if(!canremove) return if(!over_object || over_object == src) diff --git a/code/modules/client/preference_setup/global/02_settings.dm b/code/modules/client/preference_setup/global/02_settings.dm index cfb653b6e2e..8cb6406d63d 100644 --- a/code/modules/client/preference_setup/global/02_settings.dm +++ b/code/modules/client/preference_setup/global/02_settings.dm @@ -74,6 +74,8 @@ "Ghost sight: [(pref.toggles & CHAT_GHOSTSIGHT) ? "All Emotes" : "Nearest Creatures"]
", "Ghost radio: [(pref.toggles & CHAT_GHOSTRADIO) ? "All Chatter" : "Nearest Speakers"]
", "Observer LOOC: [(pref.toggles & CHAT_GHOSTLOOC) ? "Visible" : "Hidden"]
", + "Item Outlines: [(pref.toggles_secondary & SEE_ITEM_OUTLINES) ? "Visible" : "Hidden"]
", + "Hide Item Tooltips: [(pref.toggles_secondary & HIDE_ITEM_TOOLTIPS) ? "Yes" : "No"]
", "Progress Bars: [(pref.toggles_secondary & PROGRESS_BARS) ? "Yes" : "No"]
", "Floating Messages: [(pref.toggles_secondary & FLOATING_MESSAGES) ? "Yes" : "No"]
", "Hotkey Mode Default: [(pref.toggles_secondary & HOTKEY_DEFAULT) ? "On" : "Off"]
" diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 9e9b63d82f0..e3f231d8a62 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -163,7 +163,7 @@ var/list/preferences_datums = list() var/metadata = "" // SPAAAACE - var/toggles_secondary = PROGRESS_BARS | FLOATING_MESSAGES | HOTKEY_DEFAULT + var/toggles_secondary = SEE_ITEM_OUTLINES | PROGRESS_BARS | FLOATING_MESSAGES | HOTKEY_DEFAULT var/clientfps = 100 var/floating_chat_color var/speech_bubble_type = "default" diff --git a/code/modules/client/preferences_toggles.dm b/code/modules/client/preferences_toggles.dm index 539439d61ae..d7d0f82aae6 100644 --- a/code/modules/client/preferences_toggles.dm +++ b/code/modules/client/preferences_toggles.dm @@ -164,3 +164,21 @@ prefs.toggles_secondary ^= FLOATING_MESSAGES prefs.save_preferences() to_chat(src, SPAN_NOTICE("Floating messages are now [prefs.toggles_secondary & FLOATING_MESSAGES ? "enabled" : "disabled"].")) + +/client/verb/toggle_item_outlines() + set name = "Toggle Item Outlines" + set desc = "Toggles outlines appearing on items in your inventory." + set category = "Preferences" + + prefs.toggles_secondary ^= SEE_ITEM_OUTLINES + prefs.save_preferences() + to_chat(src, SPAN_NOTICE("Item outlines are now [prefs.toggles_secondary & SEE_ITEM_OUTLINES ? "enabled" : "disabled"].")) + +/client/verb/toggle_item_tooltips() + set name = "Toggle Item Tooltips" + set desc = "Toggles tooltips appearing on items in your inventory." + set category = "Preferences" + + prefs.toggles_secondary ^= HIDE_ITEM_TOOLTIPS + prefs.save_preferences() + to_chat(src, SPAN_NOTICE("Item outlines are now [prefs.toggles_secondary & HIDE_ITEM_TOOLTIPS ? "disabled" : "enabled"].")) diff --git a/html/changelogs/GeneralCamo - Item Outlines.yml b/html/changelogs/GeneralCamo - Item Outlines.yml new file mode 100644 index 00000000000..bacfe580d66 --- /dev/null +++ b/html/changelogs/GeneralCamo - Item Outlines.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: GeneralCamo + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - qol: "Hovering over an item in an inventory, not in storage, will now show a tooltip and outline."