[MIRROR] Contextual screentips -- Screentips now show you what items/objects can do [MDB IGNORE] (#11529)

* Contextual screentips -- Screentips now show you what items/objects can do (#64502)

Adds the foundational system for contextual screentips, which will show you what you can do with objects/items, including through context, such as what you are holding.

Provides several helper elements for most use cases, and applies it to a handful of common objects in order to show the full breadth of the system.

Changes screentips preference from on/off to on/off/only with context. Players who originally had it on off will have it migrated to only with context, though can re-disable it.

* Contextual screentips -- Screentips now show you what items/objects can do

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
This commit is contained in:
SkyratBot
2022-02-16 00:48:07 +01:00
committed by GitHub
parent 5cc0350ff9
commit d1cfb4338e
30 changed files with 770 additions and 29 deletions

View File

@@ -0,0 +1,23 @@
/// A "Type-A" contextual screentip interaction.
/// These are used for items that are defined by their behavior. They define their contextual text within *themselves*,
/// not in their targets.
/// Examples include syringes (LMB to inject, RMB to draw) and health analyzers (LMB to scan health/wounds, RMB for chems)
/// Items can override `add_item_context()`, and call `register_item_context()` in order to easily connect to this.
/// Called on /obj/item with a mutable screentip context list, the hovered target, and the mob hovering.
/// A screentip context list is a list that has context keys (SCREENTIP_CONTEXT_*, from __DEFINES/screentips.dm)
/// that map to the action as text.
/// If you mutate the list in this signal, you must return CONTEXTUAL_SCREENTIP_SET.
#define COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET "item_requesting_context_for_target"
/// A "Type-B" contextual screentip interaction.
/// These are atoms that are defined by what happens *to* them. These should define contextual text within themselves, and
/// not in their operating tools.
/// Examples include construction objects (LMB with glass to put in screen for computers).
/// Called on /atom with a mutable screentip context list, the item being used, and the mob hovering.
/// A screentip context list is a list that has context keys (SCREENTIP_CONTEXT_*, from __DEFINES/screentips.dm)
/// that map to the action as text.
/// If you mutate the list in this signal, you must return CONTEXTUAL_SCREENTIP_SET.
#define COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM "atom_requesting_context_from_item"
/// Tells the contextual screentips system that the list context was mutated.
#define CONTEXTUAL_SCREENTIP_SET (1 << 0)

View File

@@ -56,6 +56,8 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
#define HTML_USE_INITAL_ICON_1 (1<<20)
/// Can players recolor this in-game via vendors (and maybe more if support is added)?
#define IS_PLAYER_COLORABLE_1 (1<<21)
/// Whether or not this atom has contextual screentips when hovered OVER
#define HAS_CONTEXTUAL_SCREENTIPS_1 (1<<22)
// Update flags for [/atom/proc/update_appearance]
/// Update the atom's name

View File

@@ -39,6 +39,8 @@
#define NO_PIXEL_RANDOM_DROP (1<<17) //if dropped, it wont have a randomized pixel_x/pixel_y
///Can be equipped on digitigrade legs.
#define IGNORE_DIGITIGRADE (1<<18)
/// Has contextual screentips when HOVERING OVER OTHER objects
#define ITEM_HAS_CONTEXTUAL_SCREENTIPS (1 << 19)
// Flags for the clothing_flags var on /obj/item/clothing

View File

@@ -82,12 +82,6 @@
#define EXP_TYPE_GHOST "Ghost"
#define EXP_TYPE_ADMIN "Admin"
///Screentip settings
#define SCREENTIP_OFF 0
#define SCREENTIP_SMALL 1
#define SCREENTIP_MEDIUM 1
#define SCREENTIP_BIG 1
//Flags in the players table in the db
#define DB_FLAG_EXEMPT 1

View File

@@ -0,0 +1,17 @@
/// Context applied to LMB actions
#define SCREENTIP_CONTEXT_LMB "LMB"
/// Context applied to RMB actions
#define SCREENTIP_CONTEXT_RMB "RMB"
/// Context applied to Ctrl-LMB actions
#define SCREENTIP_CONTEXT_CTRL_LMB "Ctrl-LMB"
/// Screentips are always disabled
#define SCREENTIP_PREFERENCE_DISABLED "Disabled"
/// Screentips are always enabled
#define SCREENTIP_PREFERENCE_ENABLED "Enabled"
/// Screentips are only enabled when they have context
#define SCREENTIP_PREFERENCE_CONTEXT_ONLY "Only with tips"

View File

@@ -114,12 +114,14 @@ DEFINE_BITFIELD(flags_1, list(
"ATMOS_IS_PROCESSING_1" = ATMOS_IS_PROCESSING_1,
"CAN_BE_DIRTY_1" = CAN_BE_DIRTY_1,
"CONDUCT_1" = CONDUCT_1,
"HAS_CONTEXTUAL_SCREENTIPS_1" = HAS_CONTEXTUAL_SCREENTIPS_1,
"HOLOGRAM_1" = HOLOGRAM_1,
"INITIALIZED_1" = INITIALIZED_1,
"IS_ONTOP_1" = IS_ONTOP_1,
"IS_PLAYER_COLORABLE_1" = IS_PLAYER_COLORABLE_1,
"IS_SPINNING_1" = IS_SPINNING_1,
"NO_SCREENTIPS_1" = NO_SCREENTIPS_1,
"NODECONSTRUCT_1" = NODECONSTRUCT_1,
"NO_SCREENTIPS_1" = NO_SCREENTIPS_1,
"ON_BORDER_1" = ON_BORDER_1,
"OVERLAY_QUEUED_1" = OVERLAY_QUEUED_1,
"PREVENT_CLICK_UNDER_1" = PREVENT_CLICK_UNDER_1,
@@ -127,7 +129,6 @@ DEFINE_BITFIELD(flags_1, list(
"SHOCKED_1" = SHOCKED_1,
"SUPERMATTER_IGNORES_1" = SUPERMATTER_IGNORES_1,
"UNPAINTABLE_1" = UNPAINTABLE_1,
"IS_PLAYER_COLORABLE_1" = IS_PLAYER_COLORABLE_1,
))
DEFINE_BITFIELD(flags_ricochet, list(
@@ -169,16 +170,17 @@ DEFINE_BITFIELD(item_flags, list(
"EXAMINE_SKIP" = EXAMINE_SKIP,
"FORCE_STRING_OVERRIDE" = FORCE_STRING_OVERRIDE,
"HAND_ITEM" = HAND_ITEM,
"IMMUTABLE_SLOW" = IMMUTABLE_SLOW,
"IN_INVENTORY" = IN_INVENTORY,
"IN_STORAGE" = IN_STORAGE,
"IMMUTABLE_SLOW" = IMMUTABLE_SLOW,
"ITEM_HAS_CONTEXTUAL_SCREENTIPS" = ITEM_HAS_CONTEXTUAL_SCREENTIPS,
"NEEDS_PERMIT" = NEEDS_PERMIT,
"NOBLUDGEON" = NOBLUDGEON,
"NO_MAT_REDEMPTION" = NO_MAT_REDEMPTION,
"NO_PIXEL_RANDOM_DROP" = NO_PIXEL_RANDOM_DROP,
"SLOWS_WHILE_IN_HAND" = SLOWS_WHILE_IN_HAND,
"SURGICAL_TOOL" = SURGICAL_TOOL,
"XENOMORPH_HOLDABLE" = XENOMORPH_HOLDABLE,
"NO_PIXEL_RANDOM_DROP" = NO_PIXEL_RANDOM_DROP,
))
DEFINE_BITFIELD(machine_stat, list(

View File

@@ -85,7 +85,7 @@ GLOBAL_LIST_INIT(available_erp_ui_styles, list(
/// This is updated by the preference for cheaper reads than would be
/// had with a proc call, especially on one of the hottest procs in the
/// game (MouseEntered).
var/screentips_enabled = TRUE
var/screentips_enabled = SCREENTIP_PREFERENCE_ENABLED
/// The color to use for the screentips.
/// This is updated by the preference for cheaper reads than would be
@@ -128,7 +128,7 @@ GLOBAL_LIST_INIT(available_erp_ui_styles, list(
var/datum/preferences/preferences = owner?.client?.prefs
screentip_color = preferences?.read_preference(/datum/preference/color/screentip_color)
screentips_enabled = preferences?.read_preference(/datum/preference/toggle/enable_screentips)
screentips_enabled = preferences?.read_preference(/datum/preference/choiced/enable_screentips)
screentip_text = new(null, src)
static_inventory += screentip_text

View File

@@ -0,0 +1,136 @@
# Contextual screentips (and when to not use this folder)
Contextual screentips provide information in the form of text at the top of your screen to inform you of the possibilities of an item. The "contextual" here refers to this being handled entirely through code, what it displays and when is completely up to you.
## The elements (and this folder)
This folder provides several useful shortcuts to be able to handle 95% of situations.
### `/datum/element/contextual_screentip_bare_hands`
This element is used to display screentips **when the user hovers over the object with nothing in their active hand.**
It takes parameters in the form of both non-combat mode and, optionally, combat mode.
Example:
```dm
/obj/machinery/firealarm/Initialize(mapload)
. = ..()
AddElement( \
/datum/element/contextual_screentip_bare_hands, \
lmb_text = "Turn on", \
rmb_text = "Turn off", \
)
```
This will display "LMB: Turn on | RMB: Turn off" when the user hovers over a fire alarm with an empty active hand.
### `/datum/element/contextual_screentip_tools`
This element takes a map of tool behaviors to [context lists](#context-lists). These will be displayed **when the user hovers over the object with an item that has the tool behavior.**
Example:
```dm
/obj/structure/table/Initialize(mapload)
if (!(flags_1 & NODECONSTRUCT_1))
var/static/list/tool_behaviors = list(
TOOL_SCREWDRIVER = list(
SCREENTIP_CONTEXT_RMB = "Disassemble",
),
TOOL_WRENCH = list(
SCREENTIP_CONTEXT_RMB = "Deconstruct",
),
)
AddElement(/datum/element/contextual_screentip_tools, tool_behaviors)
```
This will display "RMB: Deconstruct" when the user hovers over a table with a wrench.
### `/datum/element/contextual_screentip_item_typechecks`
This element takes a map of item typepaths to [context lists](#context-lists). These will be displayed **when the user hovers over the object with the selected item.**
Example:
```dm
/obj/item/restraints/handcuffs/cable/Initialize(mapload)
. = ..()
var/static/list/hovering_item_typechecks = list(
/obj/item/stack/rods = list(
SCREENTIP_CONTEXT_LMB = "Craft wired rod",
),
/obj/item/stack/sheet/iron = list(
SCREENTIP_CONTEXT_LMB = "Craft bola",
),
)
AddElement(/datum/element/contextual_screentip_item_typechecks, hovering_item_typechecks)
```
This will display "LMB: Craft bola" when the user hovers over cable restraints with metal in their hand.
## The basic system (and when to not use this folder)
The basic system acknowledges the following two interactions:
### Self-defining items (Type A)
These are items that are defined by their behavior. These should define their contextual text within themselves, and not in their targets.
- Stun batons (LMB to stun, RMB to harm)
- Syringes (LMB to inject, RMB to draw)
- Health analyzers (LMB to scan for health/wounds [another piece of context], RMB to scans for chemicals)
### Receiving action defining objects (Type B)
These are objects (not necessarily items) that are defined by what happens *to* them. These should define their contextual text within themselves, and not in their operating tools.
- Tables (RMB with wrench to deconstruct)
- Construction objects (LMB with glass to put in screen for computers)
- Carbon copies (RMB to take a copy)
---
Both of these are supported, and can be hooked to through several means.
Note that you **must return `CONTEXTUAL_SCREENTIP_SET` if you change the contextual screentip at all**, otherwise you may not see it.
### `COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET`
This signal is registered on **items**, and receives **the hovering object**, provided in the form of `obj/item/source, list/context, atom/target, mob/living/user`.
### `/atom/proc/register_item_context()`, and `/atom/proc/add_item_context()`
`/atom/proc/add_item_context()` is a proc intended to be overridden to easily create Type-B interactions (ones where atoms are hovered over by items). It receives the exact same arguments as `COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET`: `obj/item/source, list/context, atom/target, mob/living/user`.
In order for your `add_item_context()` method to be run, you **must** call `register_item_context()`.
### `COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM`
This signal is registered on **atoms**, and receives **what the user is hovering with**, provided in the form of `atom/source, list/context, obj/item/held_item, mob/living/user`.
### `/atom/proc/register_context()`, and `/atom/proc/add_context()`
`/atom/proc/add_context()` is a proc intended to be overridden to easily create Type-B interactions (ones where atoms are hovered over by items). It receives the exact same arguments as `COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM`: `atom/source, list/context, obj/item/held_item, mob/living/user`.
In order for your `add_context()` method to be run, you **must** call `register_context()`.
---
When using any of these methods, you will receive a mutable context list.
### Context lists
Context lists are lists with keys mapping from `SCREENTIP_CONTEXT_*` to a string. You can find these keys in `code/__DEFINES/screentips.dm`.
The signals and `add_context()` variants mutate the list directly, while shortcut elements will just have you pass them in directly.
For example:
```dm
context[SCREENTIP_CONTEXT_LMB] = "Open"
context[SCREENTIP_CONTEXT_RMB] = "Destroy"
```

View File

@@ -0,0 +1,73 @@
/// Apply basic contextual screentips when the user hovers over this item with an empty hand.
/// A "Type B" interaction.
/// This stacks with other contextual screentip elements, though you may want to register the signal/flag manually at that point for performance.
/datum/element/contextual_screentip_bare_hands
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
id_arg_index = 3
/// If set, the text to show for LMB
var/lmb_text
/// If set, the text to show for RMB
var/rmb_text
/// If set, the text to show for LMB when in combat mode. Otherwise, defaults to lmb_text.
var/lmb_text_combat_mode
/// If set, the text to show for RMB when in combat mode. Otherwise, defaults to rmb_text.
var/rmb_text_combat_mode
// If you're curious about `use_named_parameters`, it's because you should use named parameters!
// AddElement(/datum/element/contextual_screentip_bare_hands, lmb_text = "Do the thing")
/datum/element/contextual_screentip_bare_hands/Attach(
datum/target,
use_named_parameters,
lmb_text,
rmb_text,
lmb_text_combat_mode,
rmb_text_combat_mode,
)
. = ..()
if (!isatom(target))
return ELEMENT_INCOMPATIBLE
if (!isnull(use_named_parameters))
CRASH("Use named parameters instead of positional ones.")
src.lmb_text = lmb_text
src.rmb_text = rmb_text
src.lmb_text_combat_mode = lmb_text_combat_mode || lmb_text
src.rmb_text_combat_mode = rmb_text_combat_mode || rmb_text
var/atom/atom_target = target
atom_target.flags_1 |= HAS_CONTEXTUAL_SCREENTIPS_1
RegisterSignal(atom_target, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, .proc/on_requesting_context_from_item)
/datum/element/contextual_screentip_bare_hands/Detach(datum/source, ...)
UnregisterSignal(source, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM)
// We don't remove HAS_CONTEXTUAL_SCREENTIPS_1, since there could be other stuff still hooked to it,
// and being set without signals is not dangerous, just less performant.
// A lot of things don't do this, perhaps make a proc that checks if any signals are still set, and if not,
// remove the flag.
return ..()
/datum/element/contextual_screentip_bare_hands/proc/on_requesting_context_from_item(
datum/source,
list/context,
obj/item/held_item,
mob/living/user,
)
SIGNAL_HANDLER
if (!isnull(held_item))
return NONE
if (!isnull(lmb_text))
context[SCREENTIP_CONTEXT_LMB] = user.combat_mode ? lmb_text_combat_mode : lmb_text
if (!isnull(rmb_text))
context[SCREENTIP_CONTEXT_RMB] = user.combat_mode ? rmb_text_combat_mode : rmb_text
return CONTEXTUAL_SCREENTIP_SET

View File

@@ -0,0 +1,47 @@
/// Apply basic contextual screentips when the user hovers over this item with a provided item.
/// A "Type B" interaction.
/// This stacks with other contextual screentip elements, though you may want to register the signal/flag manually at that point for performance.
/datum/element/contextual_screentip_item_typechecks
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
id_arg_index = 2
/// Map of item paths to contexts to usages
var/list/item_paths_to_contexts
/datum/element/contextual_screentip_item_typechecks/Attach(datum/target, item_paths_to_contexts)
. = ..()
if (!isatom(target))
return ELEMENT_INCOMPATIBLE
src.item_paths_to_contexts = item_paths_to_contexts
var/atom/atom_target = target
atom_target.flags_1 |= HAS_CONTEXTUAL_SCREENTIPS_1
RegisterSignal(atom_target, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, .proc/on_requesting_context_from_item)
/datum/element/contextual_screentip_item_typechecks/Detach(datum/source, ...)
UnregisterSignal(source, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM)
// We don't remove HAS_CONTEXTUAL_SCREENTIPS_1, since there could be other stuff still hooked to it,
// and being set without signals is not dangerous, just less performant.
// A lot of things don't do this, perhaps make a proc that checks if any signals are still set, and if not,
// remove the flag.
return ..()
/datum/element/contextual_screentip_item_typechecks/proc/on_requesting_context_from_item(
datum/source,
list/context,
obj/item/held_item,
)
SIGNAL_HANDLER
if (isnull(held_item))
return NONE
for (var/item_path in item_paths_to_contexts)
if (istype(held_item, item_path))
context += item_paths_to_contexts[item_path]
return CONTEXTUAL_SCREENTIP_SET
return NONE

View File

@@ -0,0 +1,48 @@
/// Apply basic contextual screentips when the user hovers over this item with an item of the given tool behavior.
/// A "Type B" interaction.
/// This stacks with other contextual screentip elements, though you may want to register the signal/flag manually at that point for performance.
/datum/element/contextual_screentip_tools
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
id_arg_index = 2
/// Map of tool behaviors to contexts to usages
var/list/tool_behaviors
/datum/element/contextual_screentip_tools/Attach(datum/target, tool_behaviors)
. = ..()
if (!isatom(target))
return ELEMENT_INCOMPATIBLE
src.tool_behaviors = tool_behaviors
var/atom/atom_target = target
atom_target.flags_1 |= HAS_CONTEXTUAL_SCREENTIPS_1
RegisterSignal(atom_target, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, .proc/on_requesting_context_from_item)
/datum/element/contextual_screentip_tools/Detach(datum/source, ...)
UnregisterSignal(source, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM)
// We don't remove HAS_CONTEXTUAL_SCREENTIPS_1, since there could be other stuff still hooked to it,
// and being set without signals is not dangerous, just less performant.
// A lot of things don't do this, perhaps make a proc that checks if any signals are still set, and if not,
// remove the flag.
return ..()
/datum/element/contextual_screentip_tools/proc/on_requesting_context_from_item(
datum/source,
list/context,
obj/item/held_item,
)
SIGNAL_HANDLER
if (isnull(held_item))
return NONE
var/tool_behavior = held_item.tool_behaviour
if (!(tool_behavior in tool_behaviors))
return NONE
context += tool_behaviors[tool_behavior]
return CONTEXTUAL_SCREENTIP_SET

View File

@@ -0,0 +1,25 @@
/// Create a "Type-B" contextual screentip interaction, registering to `add_context()`.
/// This will run `add_context()` when the atom is hovered over by an item for context.
/// `add_context()` will *not* be called unless this is run.
/// This is not necessary for Type-B interactions, as you can just apply the flag and register to the signal yourself.
/atom/proc/register_context()
flags_1 |= HAS_CONTEXTUAL_SCREENTIPS_1
RegisterSignal(src, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, .proc/add_context)
/// Creates a "Type-B" contextual screentip interaction.
/// When a user hovers over this, this proc will be called in order
/// to provide context for contextual screentips.
/// You must call `register_context()` in order for this to be registered.
/// A screentip context list is a list that has context keys (SCREENTIP_CONTEXT_*, from __DEFINES/screentips.dm)
/// that map to the action as text.
/// If you mutate the list in this signal, you must return CONTEXTUAL_SCREENTIP_SET.
/// `source` can, in all cases, be replaced with `src`, and only exists because this proc directly connects to a signal.
/atom/proc/add_context(
atom/source,
list/context,
obj/item/held_item,
mob/living/user,
)
SIGNAL_HANDLER
return NONE

View File

@@ -0,0 +1,29 @@
/// Create a "Type-A" contextual screentip interaction, registering to `add_item_context()`.
/// This will run `add_item_context()` when the item hovers over another object for context.
/// `add_item_context()` will *not* be called unless this is run.
/// This is not necessary for Type-A interactions, as you can just apply the flag and register to the signal yourself.
/obj/item/proc/register_item_context()
item_flags |= ITEM_HAS_CONTEXTUAL_SCREENTIPS
RegisterSignal(
src,
COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET,
.proc/add_item_context,
)
/// Creates a "Type-A" contextual screentip interaction.
/// When a user hovers over something with this item in hand, this proc will be called in order
/// to provide context for contextual screentips.
/// You must call `register_item_context()` in order for this to be registered.
/// A screentip context list is a list that has context keys (SCREENTIP_CONTEXT_*, from __DEFINES/screentips.dm)
/// that map to the action as text.
/// If you mutate the list in this signal, you must return CONTEXTUAL_SCREENTIP_SET.
/// `source` can, in all cases, be replaced with `src`, and only exists because this proc directly connects to a signal.
/obj/item/proc/add_item_context(
obj/item/source,
list/context,
atom/target,
mob/living/user,
)
SIGNAL_HANDLER
return NONE

View File

@@ -2121,15 +2121,53 @@
SHOULD_NOT_SLEEP(TRUE)
var/mob/user = client?.mob
if (isnull(user))
return
// Screentips
var/datum/hud/active_hud = user?.hud_used
var/datum/hud/active_hud = user.hud_used
if(active_hud)
if(!active_hud.screentips_enabled || (flags_1 & NO_SCREENTIPS_1))
var/screentips_enabled = active_hud.screentips_enabled
if(screentips_enabled == SCREENTIP_PREFERENCE_DISABLED || (flags_1 & NO_SCREENTIPS_1))
active_hud.screentip_text.maptext = ""
else
//We inline a MAPTEXT() here, because there's no good way to statically add to a string like this
active_hud.screentip_text.maptext = "<span class='maptext' style='text-align: center; font-size: 32px; color: [active_hud.screentip_color]'>[name]</span>"
var/extra_context = ""
if (isliving(user))
var/obj/item/held_item = user.get_active_held_item()
if ((flags_1 & HAS_CONTEXTUAL_SCREENTIPS_1) || (held_item?.item_flags & ITEM_HAS_CONTEXTUAL_SCREENTIPS))
var/list/context = list()
var/contextual_screentip_returns = \
SEND_SIGNAL(src, COMSIG_ATOM_REQUESTING_CONTEXT_FROM_ITEM, context, held_item, user) \
| (held_item && SEND_SIGNAL(held_item, COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET, context, src, user))
if (contextual_screentip_returns & CONTEXTUAL_SCREENTIP_SET)
// LMB and RMB on one line...
var/lmb_text = (SCREENTIP_CONTEXT_LMB in context) ? "[SCREENTIP_CONTEXT_LMB]: [context[SCREENTIP_CONTEXT_LMB]]" : ""
var/rmb_text = (SCREENTIP_CONTEXT_RMB in context) ? "[SCREENTIP_CONTEXT_RMB]: [context[SCREENTIP_CONTEXT_RMB]]" : ""
if (lmb_text)
extra_context = lmb_text
if (rmb_text)
extra_context += " | [rmb_text]"
else if (rmb_text)
extra_context = rmb_text
// Ctrl-LMB and (in the future) Alt-LMB on another
if (SCREENTIP_CONTEXT_CTRL_LMB in context)
if (extra_context != "")
extra_context += "<br>"
extra_context += "[SCREENTIP_CONTEXT_CTRL_LMB]: [context[SCREENTIP_CONTEXT_CTRL_LMB]]"
extra_context = "<br><span style='font-size: 7px'>[extra_context]</span>"
if (screentips_enabled == SCREENTIP_PREFERENCE_CONTEXT_ONLY && extra_context == "")
active_hud.screentip_text.maptext = ""
else
//We inline a MAPTEXT() here, because there's no good way to statically add to a string like this
active_hud.screentip_text.maptext = "<span class='maptext' style='text-align: center; font-size: 32px; color: [active_hud.screentip_color]'>[name][extra_context]</span>"
///SKYRAT EDIT ADDITION BEGIN
// Face directions on combat mode. No procs, no typechecks, just a var for speed

View File

@@ -648,6 +648,38 @@
. += span_notice("Alt-click [src] to [ secondsElectrified ? "un-electrify" : "permanently electrify"] it.")
. += span_notice("Ctrl-Shift-click [src] to [ emergency ? "disable" : "enable"] emergency access.")
/obj/machinery/door/airlock/add_context(atom/source, list/context, obj/item/held_item, mob/living/user)
. = ..()
switch (held_item?.tool_behaviour)
if (TOOL_CROWBAR)
if (panel_open)
if (security_level == AIRLOCK_SECURITY_PLASTEEL_O_S || security_level == AIRLOCK_SECURITY_PLASTEEL_I_S)
context[SCREENTIP_CONTEXT_LMB] = "Remove shielding"
return CONTEXTUAL_SCREENTIP_SET
else if (should_try_removing_electronics())
context[SCREENTIP_CONTEXT_LMB] = "Remove electronics"
return CONTEXTUAL_SCREENTIP_SET
// Not always contextually true, but is contextually false in ways that make gameplay interesting.
// For example, trying to pry open an airlock, only for the bolts to be down and the lights off.
context[SCREENTIP_CONTEXT_LMB] = "Pry open"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_WELDER)
context[SCREENTIP_CONTEXT_RMB] = "Weld shut"
if (panel_open)
switch (security_level)
if (AIRLOCK_SECURITY_IRON, AIRLOCK_SECURITY_PLASTEEL_I, AIRLOCK_SECURITY_PLASTEEL_O)
context[SCREENTIP_CONTEXT_LMB] = "Cut shielding"
return CONTEXTUAL_SCREENTIP_SET
context[SCREENTIP_CONTEXT_LMB] = "Repair"
return CONTEXTUAL_SCREENTIP_SET
return .
/obj/machinery/door/airlock/attack_ai(mob/user)
if(!canAIControl(user))
if(canAIHack())
@@ -1048,16 +1080,38 @@
update_appearance()
return TRUE
/// Returns if a crowbar would remove the airlock electronics
/obj/machinery/door/airlock/proc/should_try_removing_electronics()
if (security_level != 0)
return FALSE
if (!panel_open)
return FALSE
if (obj_flags & EMAGGED)
return TRUE
if (!density)
return FALSE
if (!welded)
return FALSE
if (hasPower())
return FALSE
if (locked)
return FALSE
return TRUE
/obj/machinery/door/airlock/try_to_crowbar(obj/item/I, mob/living/user, forced = FALSE)
if(I)
var/beingcrowbarred = (I.tool_behaviour == TOOL_CROWBAR)
if(!security_level && (beingcrowbarred && panel_open && ((obj_flags & EMAGGED) || (density && welded && !operating && !hasPower() && !locked))))
user.visible_message(span_notice("[user] removes the electronics from the airlock assembly."), \
span_notice("You start to remove electronics from the airlock assembly..."))
if(I.use_tool(src, user, 40, volume=100))
deconstruct(TRUE, user)
return
if(I?.tool_behaviour == TOOL_CROWBAR && should_try_removing_electronics() && !operating)
user.visible_message(span_notice("[user] removes the electronics from the airlock assembly."), \
span_notice("You start to remove electronics from the airlock assembly..."))
if(I.use_tool(src, user, 40, volume=100))
deconstruct(TRUE, user)
return
if(seal)
to_chat(user, span_warning("Remove the seal first!"))
return

View File

@@ -52,6 +52,13 @@
. += span_notice("In the event of a red alert, its access requirements will automatically lift.")
. += span_notice("Its maintenance panel is [panel_open ? "open" : "<b>screwed</b> in place"].")
/obj/machinery/door/add_context(atom/source, list/context, obj/item/held_item, mob/living/user)
. = ..()
if (isnull(held_item))
context[SCREENTIP_CONTEXT_LMB] = "Open"
return CONTEXTUAL_SCREENTIP_SET
/obj/machinery/door/check_access_list(list/access_list)
if(red_alert_access && SSsecurity_level.current_level >= SEC_LEVEL_RED)
return TRUE
@@ -62,6 +69,7 @@
set_init_door_layer()
update_freelook_sight()
air_update_turf(TRUE, TRUE)
register_context()
GLOB.airlocks += src
spark_system = new /datum/effect_system/spark_spread
spark_system.set_up(2, 1, src)

View File

@@ -107,6 +107,44 @@
else
. += span_notice("The bolt locks have been <i>unscrewed</i>, but the bolts themselves are still <b>wrenched</b> to the floor.")
/obj/machinery/door/firedoor/add_context(atom/source, list/context, obj/item/held_item, mob/living/user)
. = ..()
if (isnull(held_item))
if (density)
// This should be LMB/RMB one day
if (user.combat_mode)
context[SCREENTIP_CONTEXT_LMB] = "Knock"
else
context[SCREENTIP_CONTEXT_LMB] = "Bash"
return CONTEXTUAL_SCREENTIP_SET
else
return .
switch (held_item.tool_behaviour)
if (TOOL_CROWBAR)
if (density)
context[SCREENTIP_CONTEXT_LMB] = "Close"
else if (!welded)
context[SCREENTIP_CONTEXT_LMB] = "Hold open"
context[SCREENTIP_CONTEXT_RMB] = "Open permanently"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_WELDER)
context[SCREENTIP_CONTEXT_LMB] = welded ? "Unweld shut" : "Weld shut"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_WRENCH)
if (welded && !boltslocked)
context[SCREENTIP_CONTEXT_LMB] = "Unfasten bolts"
return CONTEXTUAL_SCREENTIP_SET
if (TOOL_SCREWDRIVER)
if (welded)
context[SCREENTIP_CONTEXT_LMB] = "Unlock bolts"
return CONTEXTUAL_SCREENTIP_SET
return .
/**
* Calculates what areas we should worry about.
*

View File

@@ -52,6 +52,12 @@
RegisterSignal(SSsecurity_level, COMSIG_SECURITY_LEVEL_CHANGED, .proc/check_security_level)
soundloop = new(src, FALSE)
AddElement( \
/datum/element/contextual_screentip_bare_hands, \
lmb_text = "Turn on", \
rmb_text = "Turn off", \
)
/obj/machinery/firealarm/Destroy()
if(my_area)
LAZYREMOVE(my_area.firealarms, src)

View File

@@ -98,6 +98,11 @@ GENE SCANNER
var/advanced = FALSE
custom_price = PAYCHECK_HARD
/obj/item/healthanalyzer/Initialize(mapload)
. = ..()
register_item_context()
/obj/item/healthanalyzer/examine(mob/user)
. = ..()
. += span_notice("Alt-click [src] to toggle the limb damage readout.")
@@ -160,6 +165,24 @@ GENE SCANNER
chemscan(user, victim)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
/obj/item/healthanalyzer/add_item_context(
obj/item/source,
list/context,
atom/target,
)
if (!isliving(target))
return NONE
switch (scanmode)
if (SCANMODE_HEALTH)
context[SCREENTIP_CONTEXT_LMB] = "Scan health"
if (SCANMODE_WOUND)
context[SCREENTIP_CONTEXT_LMB] = "Scan wounds"
context[SCREENTIP_CONTEXT_RMB] = "Scan chemicals"
return CONTEXTUAL_SCREENTIP_SET
// Used by the PDA medical scanner too
/proc/healthscan(mob/user, mob/living/target, mode = SCANNER_VERBOSE, advanced = FALSE)
if(user.incapacitated())

View File

@@ -145,6 +145,21 @@
breakouttime = 30 SECONDS
cuffsound = 'sound/weapons/cablecuff.ogg'
/obj/item/restraints/handcuffs/cable/Initialize(mapload)
. = ..()
var/static/list/hovering_item_typechecks = list(
/obj/item/stack/rods = list(
SCREENTIP_CONTEXT_LMB = "Craft wired rod",
),
/obj/item/stack/sheet/iron = list(
SCREENTIP_CONTEXT_LMB = "Craft bola",
),
)
AddElement(/datum/element/contextual_screentip_item_typechecks, hovering_item_typechecks)
/**
* # Sinew restraints
*

View File

@@ -37,12 +37,32 @@
/// Whether the stun attack is logged. Only relevant for abductor batons, which have different modes.
var/log_stun_attack = TRUE
/// The context to show when the baton is active and targetting a living thing
var/context_living_target_active = "Stun"
/// The context to show when the baton is active and targetting a living thing in combat mode
var/context_living_target_active_combat_mode = "Stun"
/// The context to show when the baton is inactive and targetting a living thing
var/context_living_target_inactive = "Prod"
/// The context to show when the baton is inactive and targetting a living thing in combat mode
var/context_living_target_inactive_combat_mode = "Attack"
/// The RMB context to show when the baton is active and targetting a living thing
var/context_living_rmb_active = "Attack"
/// The RMB context to show when the baton is inactive and targetting a living thing
var/context_living_rmb_inactive = "Attack"
/obj/item/melee/baton/Initialize(mapload)
. = ..()
// Adding an extra break for the sake of presentation
if(stamina_damage != 0)
offensive_notes = "\nVarious interviewed security forces report being able to beat criminals into exhaustion with only [span_warning("[CEILING(100 / stamina_damage, 1)] hit\s!")]"
register_item_context()
/**
* Ok, think of baton attacks like a melee attack chain:
*
@@ -70,6 +90,30 @@
if(BATON_ATTACKING)
finalize_baton_attack(target, user, modifiers)
/obj/item/melee/baton/add_item_context(datum/source, list/context, atom/target, mob/living/user)
if (isturf(target))
return NONE
if (isobj(target))
context[SCREENTIP_CONTEXT_LMB] = "Attack"
else
if (active)
context[SCREENTIP_CONTEXT_RMB] = context_living_rmb_active
if (user.combat_mode)
context[SCREENTIP_CONTEXT_LMB] = context_living_target_active_combat_mode
else
context[SCREENTIP_CONTEXT_LMB] = context_living_target_active
else
context[SCREENTIP_CONTEXT_RMB] = context_living_rmb_inactive
if (user.combat_mode)
context[SCREENTIP_CONTEXT_LMB] = context_living_target_inactive_combat_mode
else
context[SCREENTIP_CONTEXT_LMB] = context_living_target_inactive
return CONTEXTUAL_SCREENTIP_SET
/obj/item/melee/baton/proc/baton_attack(mob/living/target, mob/living/user, modifiers)
. = BATON_ATTACKING
@@ -353,6 +397,8 @@
on_stun_volume = 50
active = FALSE
context_living_rmb_active = "Harmful Stun"
var/throw_stun_chance = 35
var/obj/item/stock_parts/cell/cell
var/preload_cell_type //if not empty the baton starts with this type of cell

View File

@@ -286,6 +286,21 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301
attack_verb_continuous = list("hits", "bludgeons", "whacks", "bonks")
attack_verb_simple = list("hit", "bludgeon", "whack", "bonk")
/obj/item/wirerod/Initialize(mapload)
. = ..()
var/static/list/hovering_item_typechecks = list(
/obj/item/shard = list(
SCREENTIP_CONTEXT_LMB = "Craft spear",
),
/obj/item/assembly/igniter = list(
SCREENTIP_CONTEXT_LMB = "Craft stunprod",
),
)
AddElement(/datum/element/contextual_screentip_item_typechecks, hovering_item_typechecks)
/obj/item/wirerod/attackby(obj/item/attacking_item, mob/user, params)
if(istype(attacking_item, /obj/item/shard))
var/datum/crafting_recipe/recipe_to_use = /datum/crafting_recipe/spear

View File

@@ -41,11 +41,26 @@
if(_buildstack)
buildstack = _buildstack
AddElement(/datum/element/climbable)
var/static/list/loc_connections = list(
COMSIG_CARBON_DISARM_COLLIDE = .proc/table_carbon,
)
AddElement(/datum/element/connect_loc, loc_connections)
if (!(flags_1 & NODECONSTRUCT_1))
var/static/list/tool_behaviors = list(
TOOL_SCREWDRIVER = list(
SCREENTIP_CONTEXT_RMB = "Disassemble",
),
TOOL_WRENCH = list(
SCREENTIP_CONTEXT_RMB = "Deconstruct",
),
)
AddElement(/datum/element/contextual_screentip_tools, tool_behaviors)
/obj/structure/table/examine(mob/user)
. = ..()
. += deconstruction_hints(user)

View File

@@ -1,11 +1,31 @@
/datum/preference/toggle/enable_screentips
/datum/preference/choiced/enable_screentips
category = PREFERENCE_CATEGORY_GAME_PREFERENCES
savefile_key = "screentip_pref"
savefile_identifier = PREFERENCE_PLAYER
/datum/preference/toggle/enable_screentips/apply_to_client(client/client, value)
/datum/preference/choiced/enable_screentips/init_possible_values()
return list(SCREENTIP_PREFERENCE_ENABLED, SCREENTIP_PREFERENCE_CONTEXT_ONLY, SCREENTIP_PREFERENCE_DISABLED)
/datum/preference/choiced/enable_screentips/create_default_value()
return SCREENTIP_PREFERENCE_ENABLED
/datum/preference/choiced/enable_screentips/apply_to_client(client/client, value)
client.mob?.hud_used?.screentips_enabled = value
/datum/preference/choiced/enable_screentips/deserialize(input, datum/preferences/preferences)
// Migrate old always disabled screentips to context only.
// Screentips were always meant to have context, though were initially merged without it.
// This accepts that those users found screentips distracting, but gives a second chance now that
// they provide a more obvious helping hand.
// If they are still too distracting, there's nothing stopping them from disabling it again for good.
if (input == FALSE)
return ..(SCREENTIP_PREFERENCE_CONTEXT_ONLY, preferences)
if (input == TRUE)
return ..(SCREENTIP_PREFERENCE_ENABLED, preferences)
return ..(input, preferences)
/datum/preference/color/screentip_color
category = PREFERENCE_CATEGORY_GAME_PREFERENCES
savefile_key = "screentip_color"

View File

@@ -3,6 +3,7 @@
create_reagents(1000, REAGENT_HOLDER_ALIVE)
assign_bodypart_ownership()
update_body_parts() //to update the carbon's new bodyparts appearance
register_context()
// Carbons cannot taste anything without a tongue; the tongue organ removes this on Insert
ADD_TRAIT(src, TRAIT_AGEUSIA, NO_TONGUE_TRAIT)

View File

@@ -0,0 +1,28 @@
/mob/living/carbon/add_context(atom/source, list/context, obj/item/held_item, mob/living/user)
. = ..()
if (!isnull(held_item))
return .
if (!ishuman(user))
return .
if (user.combat_mode)
context[SCREENTIP_CONTEXT_LMB] = "Attack"
else if (user == src)
context[SCREENTIP_CONTEXT_LMB] = "Check injuries"
if (get_bodypart(user.zone_selected)?.get_bleed_rate())
context[SCREENTIP_CONTEXT_CTRL_LMB] = "Grab limb"
if (user != src)
context[SCREENTIP_CONTEXT_RMB] = "Shove"
if (body_position == STANDING_UP)
context[SCREENTIP_CONTEXT_LMB] = "Comfort"
else if (health >= 0 && !HAS_TRAIT(src, TRAIT_FAKEDEATH))
context[SCREENTIP_CONTEXT_LMB] = "Shake"
else
context[SCREENTIP_CONTEXT_LMB] = "CPR"
return CONTEXTUAL_SCREENTIP_SET

View File

@@ -0,0 +1,23 @@
/mob/living/carbon/human/add_context(atom/source, list/context, obj/item/held_item, mob/living/user)
. = ..()
if (!ishuman(user))
return .
if (user == src)
return .
if (pulledby == user)
switch (user.grab_state)
if (GRAB_PASSIVE)
context[SCREENTIP_CONTEXT_CTRL_LMB] = "Grip"
if (GRAB_AGGRESSIVE)
context[SCREENTIP_CONTEXT_CTRL_LMB] = "Choke"
if (GRAB_NECK)
context[SCREENTIP_CONTEXT_CTRL_LMB] = "Strangle"
else
return .
else
context[SCREENTIP_CONTEXT_CTRL_LMB] = "Pull"
return CONTEXTUAL_SCREENTIP_SET

View File

@@ -3,6 +3,8 @@
return
/mob/living/carbon/get_bodypart(zone)
RETURN_TYPE(/obj/item/bodypart)
if(!zone)
zone = BODY_ZONE_CHEST
for(var/obj/item/bodypart/bodypart as anything in bodyparts)

View File

@@ -142,6 +142,7 @@
#include "code\__DEFINES\rust_g.dm"
#include "code\__DEFINES\rust_g_overrides.dm"
#include "code\__DEFINES\say.dm"
#include "code\__DEFINES\screentips.dm"
#include "code\__DEFINES\shuttles.dm"
#include "code\__DEFINES\sight.dm"
#include "code\__DEFINES\skills.dm"
@@ -222,6 +223,7 @@
#include "code\__DEFINES\dcs\signals\signals_reagent.dm"
#include "code\__DEFINES\dcs\signals\signals_restaurant.dm"
#include "code\__DEFINES\dcs\signals\signals_scangate.dm"
#include "code\__DEFINES\dcs\signals\signals_screentips.dm"
#include "code\__DEFINES\dcs\signals\signals_spatial_grid.dm"
#include "code\__DEFINES\dcs\signals\signals_specie.dm"
#include "code\__DEFINES\dcs\signals\signals_storage.dm"
@@ -1015,6 +1017,9 @@
#include "code\datums\elements\food\food_trash.dm"
#include "code\datums\elements\food\processable.dm"
#include "code\datums\elements\food\venue_price.dm"
#include "code\datums\elements\screentips\contextual_screentip_bare_hands.dm"
#include "code\datums\elements\screentips\contextual_screentip_item_typechecks.dm"
#include "code\datums\elements\screentips\contextual_screentip_tools.dm"
#include "code\datums\greyscale\_greyscale_config.dm"
#include "code\datums\greyscale\json_reader.dm"
#include "code\datums\greyscale\layer.dm"
@@ -1112,6 +1117,8 @@
#include "code\datums\ruins\icemoon.dm"
#include "code\datums\ruins\lavaland.dm"
#include "code\datums\ruins\space.dm"
#include "code\datums\screentips\atom_context.dm"
#include "code\datums\screentips\item_context.dm"
#include "code\datums\skills\_skill.dm"
#include "code\datums\skills\cleaning.dm"
#include "code\datums\skills\gaming.dm"
@@ -3142,6 +3149,7 @@
#include "code\modules\mob\living\brain\skillchip.dm"
#include "code\modules\mob\living\brain\status_procs.dm"
#include "code\modules\mob\living\carbon\carbon.dm"
#include "code\modules\mob\living\carbon\carbon_context.dm"
#include "code\modules\mob\living\carbon\carbon_defense.dm"
#include "code\modules\mob\living\carbon\carbon_defines.dm"
#include "code\modules\mob\living\carbon\carbon_movement.dm"
@@ -3197,6 +3205,7 @@
#include "code\modules\mob\living\carbon\human\examine.dm"
#include "code\modules\mob\living\carbon\human\examine_tgui.dm"
#include "code\modules\mob\living\carbon\human\human.dm"
#include "code\modules\mob\living\carbon\human\human_context.dm"
#include "code\modules\mob\living\carbon\human\human_defense.dm"
#include "code\modules\mob\living\carbon\human\human_defines.dm"
#include "code\modules\mob\living\carbon\human\human_helpers.dm"

View File

@@ -1,5 +1,5 @@
import { multiline } from "common/string";
import { FeatureColorInput, Feature, FeatureToggle, CheckboxInput } from "../base";
import { FeatureColorInput, Feature, FeatureChoiced, FeatureDropdownInput } from "../base";
export const screentip_color: Feature<string> = {
name: "Screentips color",
@@ -10,11 +10,13 @@ export const screentip_color: Feature<string> = {
component: FeatureColorInput,
};
export const screentip_pref: FeatureToggle = {
export const screentip_pref: FeatureChoiced = {
name: "Enable screentips",
category: "UI",
description: multiline`
Enables screen tips, the text you see when hovering over something.
When set to "Only with tips", will only show when there is more information
than just the name, such as what right-clicking it does.
`,
component: CheckboxInput,
component: FeatureDropdownInput,
};