From 1f024dfca5520ccc86f6a8589b7f0bd1e2053353 Mon Sep 17 00:00:00 2001
From: SandPoot <43283559+SandPoot@users.noreply.github.com>
Date: Sun, 6 Aug 2023 00:37:03 -0300
Subject: [PATCH] Screentip images (#76889)
## About The Pull Request
Adds some nice little mouse button indicators (optional), this is a port
of my version at
[Citadel-Station-13/15973](https://github.com/Citadel-Station-13/Citadel-Station-13/pull/15973).
**There is no more intent coloring**
## Why It's Good For The Game
Quick identification of what to do. Eh, i dunno if it's getting
accepted, mothblocks asked me to port it over.
## Changelog
:cl:
image: Changed screentips icons to something a lot fancier unified with
the LMB / RMB text.
qol: There are accessibility preferences to disable this! Look for
"Screentip context with images" beside the other screentip preferences.
/:cl:
---------
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
---
code/_onclick/hud/hud.dm | 4 +++
code/datums/screentips/screentips.dm | 34 ++++++++++++++++++
code/game/atoms.dm | 24 +++++++------
code/modules/client/preferences/screentips.dm | 8 +++++
icons/ui_icons/screentips/cursor_hints.dmi | Bin 0 -> 309 bytes
tgstation.dme | 1 +
.../features/game_preferences/screentips.tsx | 14 ++++++--
7 files changed, 71 insertions(+), 14 deletions(-)
create mode 100644 code/datums/screentips/screentips.dm
create mode 100644 icons/ui_icons/screentips/cursor_hints.dmi
diff --git a/code/_onclick/hud/hud.dm b/code/_onclick/hud/hud.dm
index e9c83fce771..2318b35970e 100644
--- a/code/_onclick/hud/hud.dm
+++ b/code/_onclick/hud/hud.dm
@@ -71,6 +71,9 @@ GLOBAL_LIST_INIT(available_ui_styles, list(
/// had with a proc call, especially on one of the hottest procs in the
/// game (MouseEntered).
var/screentips_enabled = SCREENTIP_PREFERENCE_ENABLED
+ /// Whether to use text or images for click hints.
+ /// Same behavior as `screentips_enabled`--very hot, updated when the preference is updated.
+ var/screentip_images = TRUE
/// If this client is being shown atmos debug overlays or not
var/atmos_debug_overlays = FALSE
@@ -117,6 +120,7 @@ GLOBAL_LIST_INIT(available_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/choiced/enable_screentips)
+ screentip_images = preferences?.read_preference(/datum/preference/toggle/screentip_images)
screentip_text = new(null, src)
static_inventory += screentip_text
diff --git a/code/datums/screentips/screentips.dm b/code/datums/screentips/screentips.dm
new file mode 100644
index 00000000000..d72e41960e5
--- /dev/null
+++ b/code/datums/screentips/screentips.dm
@@ -0,0 +1,34 @@
+#define HINT_ICON_FILE 'icons/ui_icons/screentips/cursor_hints.dmi'
+
+/// Stores the cursor hint icons for screentip context.
+GLOBAL_LIST_INIT_TYPED(screentip_context_icons, /image, prepare_screentip_context_icons())
+
+/proc/prepare_screentip_context_icons()
+ var/list/output = list()
+ for(var/state in icon_states(HINT_ICON_FILE))
+ output[state] = image(HINT_ICON_FILE, icon_state = state)
+ return output
+
+/*
+ * # Compiles a string for this key
+ * Args:
+ * - context = list (REQUIRED)
+ * - Must contain key
+ * - key = string (REQUIRED)
+ * - allow_image = boolean (not required)
+*/
+/proc/build_context(list/context, key, allow_image)
+ if(!length(context) || !context[key] || !key)
+ return ""
+ // Splits key combinations from mouse buttons. e.g. `Ctrl-Shift-LMB` goes in, `Ctrl-Shift-` goes out. Will be empty for single button actions.
+ var/key_combo = length(key) > 3 ? "[copytext(key, 1, -3)]" : ""
+ // Grab the mouse button, LMB/RMB
+ var/button = copytext(key, -3)
+ if(allow_image)
+ // Compile into image, if allowed
+ button = "\icon[GLOB.screentip_context_icons[button]]"
+
+ // Voilá, final result
+ return "[key_combo][button][allow_image ? "" : ":"] [context[key]]"
+
+#undef HINT_ICON_FILE
diff --git a/code/game/atoms.dm b/code/game/atoms.dm
index b817c34e3f7..592b81b762c 100644
--- a/code/game/atoms.dm
+++ b/code/game/atoms.dm
@@ -2077,15 +2077,16 @@
| (held_item && SEND_SIGNAL(held_item, COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET, context, src, user))
if (contextual_screentip_returns & CONTEXTUAL_SCREENTIP_SET)
+ var/screentip_images = active_hud.screentip_images
// 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]]" : ""
+ var/lmb_text = build_context(context, SCREENTIP_CONTEXT_LMB, screentip_images)
+ var/rmb_text = build_context(context, SCREENTIP_CONTEXT_RMB, screentip_images)
- if (lmb_text)
+ if (lmb_text != "")
lmb_rmb_line = lmb_text
- if (rmb_text)
+ if (rmb_text != "")
lmb_rmb_line += " | [rmb_text]"
- else if (rmb_text)
+ else if (rmb_text != "")
lmb_rmb_line = rmb_text
// Ctrl-LMB, Ctrl-RMB on one line...
@@ -2093,33 +2094,34 @@
lmb_rmb_line += "
"
extra_lines++
if (SCREENTIP_CONTEXT_CTRL_LMB in context)
- ctrl_lmb_ctrl_rmb_line += "[SCREENTIP_CONTEXT_CTRL_LMB]: [context[SCREENTIP_CONTEXT_CTRL_LMB]]"
+ ctrl_lmb_ctrl_rmb_line += build_context(context, SCREENTIP_CONTEXT_CTRL_LMB, screentip_images)
+
if (SCREENTIP_CONTEXT_CTRL_RMB in context)
if (ctrl_lmb_ctrl_rmb_line != "")
ctrl_lmb_ctrl_rmb_line += " | "
- ctrl_lmb_ctrl_rmb_line += "[SCREENTIP_CONTEXT_CTRL_RMB]: [context[SCREENTIP_CONTEXT_CTRL_RMB]]"
+ ctrl_lmb_ctrl_rmb_line += build_context(context, SCREENTIP_CONTEXT_CTRL_RMB, screentip_images)
// Alt-LMB, Alt-RMB on one line...
if (ctrl_lmb_ctrl_rmb_line != "")
ctrl_lmb_ctrl_rmb_line += "
"
extra_lines++
if (SCREENTIP_CONTEXT_ALT_LMB in context)
- alt_lmb_alt_rmb_line += "[SCREENTIP_CONTEXT_ALT_LMB]: [context[SCREENTIP_CONTEXT_ALT_LMB]]"
+ alt_lmb_alt_rmb_line += build_context(context, SCREENTIP_CONTEXT_ALT_LMB, screentip_images)
if (SCREENTIP_CONTEXT_ALT_RMB in context)
if (alt_lmb_alt_rmb_line != "")
alt_lmb_alt_rmb_line += " | "
- alt_lmb_alt_rmb_line += "[SCREENTIP_CONTEXT_ALT_RMB]: [context[SCREENTIP_CONTEXT_ALT_RMB]]"
+ alt_lmb_alt_rmb_line += build_context(context, SCREENTIP_CONTEXT_ALT_RMB, screentip_images)
// Shift-LMB, Ctrl-Shift-LMB on one line...
if (alt_lmb_alt_rmb_line != "")
alt_lmb_alt_rmb_line += "
"
extra_lines++
if (SCREENTIP_CONTEXT_SHIFT_LMB in context)
- shift_lmb_ctrl_shift_lmb_line += "[SCREENTIP_CONTEXT_SHIFT_LMB]: [context[SCREENTIP_CONTEXT_SHIFT_LMB]]"
+ shift_lmb_ctrl_shift_lmb_line += build_context(context, SCREENTIP_CONTEXT_SHIFT_LMB, screentip_images)
if (SCREENTIP_CONTEXT_CTRL_SHIFT_LMB in context)
if (shift_lmb_ctrl_shift_lmb_line != "")
shift_lmb_ctrl_shift_lmb_line += " | "
- shift_lmb_ctrl_shift_lmb_line += "[SCREENTIP_CONTEXT_CTRL_SHIFT_LMB]: [context[SCREENTIP_CONTEXT_CTRL_SHIFT_LMB]]"
+ shift_lmb_ctrl_shift_lmb_line += build_context(context, SCREENTIP_CONTEXT_CTRL_SHIFT_LMB, screentip_images)
if (shift_lmb_ctrl_shift_lmb_line != "")
extra_lines++
diff --git a/code/modules/client/preferences/screentips.dm b/code/modules/client/preferences/screentips.dm
index fe257823375..87ce18d7f24 100644
--- a/code/modules/client/preferences/screentips.dm
+++ b/code/modules/client/preferences/screentips.dm
@@ -36,3 +36,11 @@
/datum/preference/color/screentip_color/create_default_value()
return LIGHT_COLOR_FAINT_BLUE
+
+/datum/preference/toggle/screentip_images
+ category = PREFERENCE_CATEGORY_GAME_PREFERENCES
+ savefile_key = "screentip_images"
+ savefile_identifier = PREFERENCE_PLAYER
+
+/datum/preference/toggle/screentip_images/apply_to_client(client/client, value)
+ client.mob?.hud_used?.screentip_images = value
diff --git a/icons/ui_icons/screentips/cursor_hints.dmi b/icons/ui_icons/screentips/cursor_hints.dmi
new file mode 100644
index 0000000000000000000000000000000000000000..2fdbb2d04d50bb8f651c044e61195f5630facc74
GIT binary patch
literal 309
zcmV-50m}Y~P)V=-0C=2JR&a84_w-Y6@%7{?OD!tS%+FJ>RWQ*r;NmRLOex6#axAzwGg33t
zGfIGLQ?BBY#FA7XODQQQF)v$*i!&v&s2IpMKN$wRoz5Kkk{RA^>8I8?mqIjN
zO3{$1!)ju!Jy#B6S%Mz6(C&X4tP-{j<|gWQ?eN;fo%+cI>|R11jgi_#00000NkvXX
Hu0mjfLYspm
literal 0
HcmV?d00001
diff --git a/tgstation.dme b/tgstation.dme
index 9f8ddc3c606..71026e8e42b 100644
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -1480,6 +1480,7 @@
#include "code\datums\ruins\space.dm"
#include "code\datums\screentips\atom_context.dm"
#include "code\datums\screentips\item_context.dm"
+#include "code\datums\screentips\screentips.dm"
#include "code\datums\skills\_skill.dm"
#include "code\datums\skills\cleaning.dm"
#include "code\datums\skills\fishing.dm"
diff --git a/tgui/packages/tgui/interfaces/PreferencesMenu/preferences/features/game_preferences/screentips.tsx b/tgui/packages/tgui/interfaces/PreferencesMenu/preferences/features/game_preferences/screentips.tsx
index 91f22c6b284..dec7ef1ac8f 100644
--- a/tgui/packages/tgui/interfaces/PreferencesMenu/preferences/features/game_preferences/screentips.tsx
+++ b/tgui/packages/tgui/interfaces/PreferencesMenu/preferences/features/game_preferences/screentips.tsx
@@ -1,8 +1,8 @@
import { multiline } from 'common/string';
-import { FeatureColorInput, Feature, FeatureChoiced, FeatureDropdownInput } from '../base';
+import { CheckboxInput, FeatureColorInput, FeatureToggle, Feature, FeatureChoiced, FeatureDropdownInput } from '../base';
export const screentip_color: Feature = {
- name: 'Screentips color',
+ name: 'Screentips: Screentips color',
category: 'UI',
description: multiline`
The color of screen tips, the text you see when hovering over something.
@@ -10,8 +10,16 @@ export const screentip_color: Feature = {
component: FeatureColorInput,
};
+export const screentip_images: FeatureToggle = {
+ name: 'Screentips: Allow images',
+ category: 'UI',
+ description: multiline`When enabled, screentip hints use images for
+ the mouse button rather than LMB/RMB.`,
+ component: CheckboxInput,
+};
+
export const screentip_pref: FeatureChoiced = {
- name: 'Enable screentips',
+ name: 'Screentips: Enable screentips',
category: 'UI',
description: multiline`
Enables screen tips, the text you see when hovering over something.