Files
Bubberstation/code/game/objects/effects/cursor_catcher.dm
SkyratBot e021ec7176 [MIRROR] Blocks (most instances of) screen elements from entering base atom /Click (#27049)
* Blocks (most instances of) screen elements from entering base atom `/Click` (#82236)

## About The Pull Request

Fixes #76495

This PR prevents (most) screen elements from running base
`/atom/proc/Click` and `/mob/proc/ClickOn()` when clickend.

(The only exception I found to it was the cursor catcher for scopes.)

Why?
Most, if not everything in `ClickOn` is considered "in world"
interacting. It abides by `incapacitated`, runs `faceAtom`, etc.
This means, currently, you can "interact" with screen elements using in
world elements. For example, TK-ing / pointing a gun at your mood face.

Right now this affects very little, but there is a large potential for
errors. All you have to do is forget a sanity check in `afterattack` and
suddenly you have an item that can affect your screen objects.
The only example I found was the `/item/godstaff`, which can color some
of your screen elements. But there may be more. Like guns.

Note:
Many, many screen elements ALREADY do not fall down into atom click.
They simply don't call parent. Which is totally fine.
I am just ensuring ALL* screen elements do not fall down into atom
click.

## Changelog

🆑 Melbert
fix: Blocks mobs from trying to "physically" interact with some of their
hud elements, such as using Telekinesis or point a gun at your mood
meter.
/🆑

* Blocks (most instances of) screen elements from entering base atom `/Click`

---------

Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
2024-04-04 13:38:44 -04:00

68 lines
2.4 KiB
Plaintext

/// An effect which tracks the cursor's location on the screen
/atom/movable/screen/fullscreen/cursor_catcher
icon_state = "fullscreen_blocker" // Fullscreen semi transparent icon
plane = HUD_PLANE
mouse_opacity = MOUSE_OPACITY_ICON
default_click = TRUE
/// The mob whose cursor we are tracking.
var/mob/owner
/// Client view size of the scoping mob.
var/list/view_list
/// Pixel x we send to the scope component.
var/given_x
/// Pixel y we send to the scope component.
var/given_y
/// The turf we send to the scope component.
var/turf/given_turf
/// Mouse parameters, for calculation.
var/mouse_params
/// Links this up with a mob
/atom/movable/screen/fullscreen/cursor_catcher/proc/assign_to_mob(mob/owner)
src.owner = owner
view_list = getviewsize(owner.client.view)
RegisterSignal(owner, COMSIG_MOVABLE_MOVED, PROC_REF(on_move))
RegisterSignal(owner, COMSIG_VIEWDATA_UPDATE, PROC_REF(on_viewdata_update))
calculate_params()
/// Update when the mob we're assigned to has moved
/atom/movable/screen/fullscreen/cursor_catcher/proc/on_move(atom/source, atom/oldloc, dir, forced)
SIGNAL_HANDLER
if(!given_turf)
return
var/x_offset = source.loc.x - oldloc.x
var/y_offset = source.loc.y - oldloc.y
given_turf = locate(given_turf.x+x_offset, given_turf.y+y_offset, given_turf.z)
/// Update when our screen size changes
/atom/movable/screen/fullscreen/cursor_catcher/proc/on_viewdata_update(datum/source, view)
SIGNAL_HANDLER
view_list = getviewsize(view)
/atom/movable/screen/fullscreen/cursor_catcher/MouseEntered(location, control, params)
. = ..()
MouseMove(location, control, params)
if(usr == owner)
calculate_params()
/atom/movable/screen/fullscreen/cursor_catcher/MouseMove(location, control, params)
if(usr != owner)
return
mouse_params = params
/atom/movable/screen/fullscreen/cursor_catcher/proc/calculate_params()
var/list/modifiers = params2list(mouse_params)
var/icon_x = text2num(LAZYACCESS(modifiers, VIS_X))
if(isnull(icon_x))
icon_x = text2num(LAZYACCESS(modifiers, ICON_X))
var/icon_y = text2num(LAZYACCESS(modifiers, VIS_Y))
if(isnull(icon_y))
icon_y = text2num(LAZYACCESS(modifiers, ICON_Y))
var/our_x = round(icon_x / world.icon_size)
var/our_y = round(icon_y / world.icon_size)
given_turf = locate(owner.x + our_x - round(view_list[1]/2), owner.y + our_y - round(view_list[2]/2), owner.z)
given_x = round(icon_x - world.icon_size * our_x, 1)
given_y = round(icon_y - world.icon_size * our_y, 1)