Files
Bubberstation/code/modules/wiremod/shell/controller.dm
Jeremiah 8e3f635b98 Alt click refactor (#82656)
## About The Pull Request
Rewrites how alt click works. 
Based heavily on #82625. What a cool concept, it flows nicely with
#82533.

Fixes #81242 
(tm bugs fixed)
Fixes #82668

<details><summary>More info for devs</summary>

Handy regex used for alt click s&r:
`AltClick\((.*).*\)(\n\t.*\.\.\(\))?`
`click_alt($1)` (yes I am aware this only copies the first arg. there
are no other args!)

### Obj reskins
No reason for obj reskin to check on every single alt click for every
object. It applies to only a few items.
- Moved to obj/item
- Made into signal
- Added screentips

### Ventcrawling
Every single atmospherics machine checked for ventcrawling capability on
alt click despite only 3 objects needing that functionality. This has
been moved down to those individual items.
</details>

## Why It's Good For The Game
For players: 
- Alt clicking should work more logically, not causing double actions
like eject disk and open item window
- Added context menus for reskinnable items
- Removed adjacency restriction on loot panel

For devs:
- Makes alt click interactions easier to work with, no more click chain
nonsense and redundant guard clauses.
- OOP hell reduced
- Pascal Case reduced
- Glorious snake case

## Changelog
🆑
add: The lootpanel now works at range.
add: Screentips for reskinnable items.
fix: Alt click interactions have been refactored, which may lead to
unintentional changes to gameplay. Report any issues, please.
/🆑
2024-04-16 17:48:03 -06:00

87 lines
3.0 KiB
Plaintext

/**
* # Compact Remote
*
* A handheld device with several buttons.
* In game, this translates to having different signals for normal usage, alt-clicking, and ctrl-clicking when in your hand.
*/
/obj/item/controller
name = "controller"
icon = 'icons/obj/science/circuits.dmi'
icon_state = "setup_small_calc"
inhand_icon_state = "electronic"
worn_icon_state = "electronic"
lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi'
righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi'
light_system = OVERLAY_LIGHT_DIRECTIONAL
light_on = FALSE
/obj/item/controller/Initialize(mapload)
. = ..()
AddComponent(/datum/component/shell, list(
new /obj/item/circuit_component/controller()
), SHELL_CAPACITY_MEDIUM)
/obj/item/circuit_component/controller
display_name = "Controller"
desc = "Used to receive inputs from the controller shell. Use the shell in hand to trigger the output signal."
desc_controls = "Alt-click for the alternate signal. Right click for the extra signal."
/// The three separate buttons that are called in attack_hand on the shell.
var/datum/port/output/signal
var/datum/port/output/alt
var/datum/port/output/right
/// The entity output
var/datum/port/output/entity
/obj/item/circuit_component/controller/populate_ports()
entity = add_output_port("User", PORT_TYPE_USER)
signal = add_output_port("Signal", PORT_TYPE_SIGNAL)
alt = add_output_port("Alternate Signal", PORT_TYPE_SIGNAL)
right = add_output_port("Extra Signal", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/controller/register_shell(atom/movable/shell)
RegisterSignal(shell, COMSIG_ITEM_ATTACK_SELF, PROC_REF(send_trigger))
RegisterSignal(shell, COMSIG_CLICK_ALT, PROC_REF(send_alternate_signal))
RegisterSignal(shell, COMSIG_ITEM_ATTACK_SELF_SECONDARY, PROC_REF(send_right_signal))
/obj/item/circuit_component/controller/unregister_shell(atom/movable/shell)
UnregisterSignal(shell, list(
COMSIG_ITEM_ATTACK_SELF,
COMSIG_ITEM_ATTACK_SELF_SECONDARY,
COMSIG_CLICK_ALT,
))
/obj/item/circuit_component/controller/proc/handle_trigger(atom/source, user, port_name, datum/port/output/port_signal)
source.balloon_alert(user, "clicked [port_name] button")
playsound(source, get_sfx(SFX_TERMINAL_TYPE), 25, FALSE)
entity.set_output(user)
port_signal.set_output(COMPONENT_SIGNAL)
/**
* Called when the shell item is used in hand
*/
/obj/item/circuit_component/controller/proc/send_trigger(atom/source, mob/user)
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
handle_trigger(source, user, "primary", signal)
/**
* Called when the shell item is alt-clicked
*/
/obj/item/circuit_component/controller/proc/send_alternate_signal(atom/source, mob/user)
SIGNAL_HANDLER
handle_trigger(source, user, "alternate", alt)
return CLICK_ACTION_SUCCESS
/**
* Called when the shell item is right-clicked in active hand
*/
/obj/item/circuit_component/controller/proc/send_right_signal(atom/source, mob/user)
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
handle_trigger(source, user, "extra", right)