Files
Bubberstation/code/modules/wiremod/shell/controller.dm
Timberpoes 75a3717a04 Modifies right click logic so that it is not the same priority as modifier keys. (#59656)
Strips out the existing right click code - Due to the myriad of ways right clicking has been implemented, dedicated signals and procs for right clicking without modifiers are fundamentally incompatible with our system of primary and secondary attacks.

Adds additional signals to attacking code. These signals allow atoms to cancel the attack chain early on secondary attacks, or override the standard procs and not send signals to prevent any undesired behaviour from signal handlers.

Items that used RightClick procs have been converted to attack_hand_secondary.

The slaughter demon, having its own set of snowflake code as poor OOP principles have been applied in UnarmedAttack() procs with lacking calls to parent procs and arbitrary redefinition of behaviour, checks for a right click in its own UnarmedAttack() and performs a bodyslam off that.

Storage components now hijack the secondary attackby stage via signals to handle their opening and closing shortcuts on right click. When you right click a storage component equipped item with an object in your active hand, the object has an opportunity to perform its logic in pre secondary attack code and cancel the attack chain. If it does not cancel the attack chain in pre-attack, then the storage component takes over for attackby and, if possible, opens the relevant inventory and ends the attack chain.

The forensic scanner is a proof-of-concept of this working in action. With its scan logic moved from afterattack code to pre attack code for right clicking, right clicking with the scanner will now perform a scan where previously one was impossible. Left clicking still does what it always does - Scans at the very end of the attack chain.

The logic still isn't perfect - For example, you still can't attack containers in melee even in combat mode (you'll either open them or put your weapon into them regardless of which option you choose) - But this is a better setup overall which allows for items to at least override this behaviour in pre-attack if needed.
2021-06-24 14:30:33 -03:00

86 lines
2.9 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/wiremod.dmi'
icon_state = "setup_small_calc"
inhand_icon_state = "electronic"
worn_icon_state = "electronic"
lefthand_file = 'icons/mob/inhands/misc/devices_lefthand.dmi'
righthand_file = 'icons/mob/inhands/misc/devices_righthand.dmi'
light_system = MOVABLE_LIGHT_DIRECTIONAL
light_on = FALSE
/obj/item/controller/Initialize()
. = ..()
AddComponent(/datum/component/shell, list(
new /obj/item/circuit_component/controller()
), SHELL_CAPACITY_MEDIUM)
/obj/item/circuit_component/controller
display_name = "Controller"
display_desc = "Used to receive inputs from the controller shell. Use the shell in hand to trigger the output signal. 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
/obj/item/circuit_component/controller/Initialize()
. = ..()
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/Destroy()
signal = null
alt = null
right = null
return ..()
/obj/item/circuit_component/controller/register_shell(atom/movable/shell)
RegisterSignal(shell, COMSIG_ITEM_ATTACK_SELF, .proc/send_trigger)
RegisterSignal(shell, COMSIG_CLICK_ALT, .proc/send_alternate_signal)
RegisterSignal(shell, COMSIG_ATOM_ATTACK_HAND_SECONDARY, .proc/send_right_signal)
/obj/item/circuit_component/controller/unregister_shell(atom/movable/shell)
UnregisterSignal(shell, list(
COMSIG_ITEM_ATTACK_SELF,
COMSIG_ATOM_ATTACK_HAND_SECONDARY,
COMSIG_CLICK_ALT,
))
/**
* Called when the shell item is used in hand, including right click.
*/
/obj/item/circuit_component/controller/proc/send_trigger(atom/source, mob/user)
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
source.balloon_alert(user, "clicked primary button")
playsound(source, get_sfx("terminal_type"), 25, FALSE)
signal.set_output(COMPONENT_SIGNAL)
/**
* Called when the shell item is alt-clicked
*/
/obj/item/circuit_component/controller/proc/send_alternate_signal(atom/source, mob/user)
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
source.balloon_alert(user, "clicked alternate button")
playsound(source, get_sfx("terminal_type"), 25, FALSE)
alt.set_output(COMPONENT_SIGNAL)
/obj/item/circuit_component/controller/proc/send_right_signal(atom/source, mob/user)
SIGNAL_HANDLER
if(!user.Adjacent(source))
return
source.balloon_alert(user, "clicked extra button")
playsound(source, get_sfx("terminal_type"), 25, FALSE)
right.set_output(COMPONENT_SIGNAL)