Skip to content

Commit

Permalink
[MIRROR] Alt click refactor (#2982)
Browse files Browse the repository at this point in the history
* [MIRROR] Alt click refactor (#2029)

* Alt click refactor

* Some early conflict removal

* Big modular refactor

* Update console.dm

* Update paper.dm

---------

Co-authored-by: Jeremiah <[email protected]>
Co-authored-by: Mal <[email protected]>

* FF modular alt clicks

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Jeremiah <[email protected]>
Co-authored-by: Mal <[email protected]>
Co-authored-by: Iajret <[email protected]>
  • Loading branch information
5 people authored Apr 20, 2024
1 parent 4458de8 commit cc106e3
Show file tree
Hide file tree
Showing 263 changed files with 1,349 additions and 1,427 deletions.
8 changes: 8 additions & 0 deletions code/__DEFINES/click.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Action has succeeded, preventing further alt click interaction
#define CLICK_ACTION_SUCCESS (1<<0)
/// Action failed, preventing further alt click interaction
#define CLICK_ACTION_BLOCKING (1<<1)
/// Either return state
#define CLICK_ACTION_ANY (CLICK_ACTION_SUCCESS | CLICK_ACTION_BLOCKING)

/// Use NONE for continue interaction
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define COMSIG_CLICK_CTRL "ctrl_click"
///from base of atom/AltClick(): (/mob)
#define COMSIG_CLICK_ALT "alt_click"
#define COMPONENT_CANCEL_CLICK_ALT (1<<0)
///from base of atom/alt_click_secondary(): (/mob)
#define COMSIG_CLICK_ALT_SECONDARY "alt_click_secondary"
#define COMPONENT_CANCEL_CLICK_ALT_SECONDARY (1<<0)
Expand Down
4 changes: 4 additions & 0 deletions code/__DEFINES/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,10 @@ GLOBAL_LIST_INIT(layers_to_offset, list(
#define ALLOW_SILICON_REACH (1<<6)
/// If resting on the floor is allowed to perform action (pAIs can play music while resting)
#define ALLOW_RESTING (1<<7)
/// If this is accessible to creatures with ventcrawl capabilities
#define NEED_VENTCRAWL (1<<8)
/// Checks for base adjacency, but silences the error
#define SILENT_ADJACENCY (1<<9)

/// The default mob sprite size (used for shrinking or enlarging the mob sprite to regular size)
#define RESIZE_DEFAULT_SIZE 1
Expand Down
3 changes: 0 additions & 3 deletions code/__DEFINES/traits/declarations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,4 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
/// Trait applied to objects and mobs that can attack a boulder and break it down. (See /obj/item/boulder/manual_process())
#define TRAIT_BOULDER_BREAKER "boulder_breaker"

/// Prevents the affected object from opening a loot window via alt click. See atom/AltClick()
#define TRAIT_ALT_CLICK_BLOCKER "no_alt_click"

// END TRAIT DEFINES
7 changes: 3 additions & 4 deletions code/__DEFINES/~nova_defines/combat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@
#define HEADSMASH_BLOCK_ARMOR 20
#define SUPLEX_TIMER 3 SECONDS

/// Skyrat change - alt-clicking a human as another human while grappling them tightly makes you try for grappling-based maneuvers.
/mob/living/carbon/human/AltClick(mob/user)
// alt-clicking a human as another human while grappling them tightly makes you try for grappling-based maneuvers.
/mob/living/carbon/human/click_alt(mob/user)
if(!ishuman(user))
return ..()
var/mob/living/carbon/human/human_user = user
if(human_user == src || !human_user.combat_mode || !human_user.dna.species.try_grab_maneuver(user, src))
return FALSE
. = ..()
return CLICK_ACTION_BLOCKING

/// State check for grab maneuver - because you can't logically suplex a man if you've stopped grappling them.
/datum/species/proc/grab_maneuver_state_check(mob/living/carbon/human/user, mob/living/carbon/human/target)
Expand Down
1 change: 0 additions & 1 deletion code/_globalvars/traits/_traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
GLOBAL_LIST_INIT(traits_by_type, list(
/atom = list(
"TRAIT_AI_PAUSED" = TRAIT_AI_PAUSED,
"TRAIT_ALT_CLICK_BLOCKER" = TRAIT_ALT_CLICK_BLOCKER,
"TRAIT_BANNED_FROM_CARGO_SHUTTLE" = TRAIT_BANNED_FROM_CARGO_SHUTTLE,
"TRAIT_BEING_SHOCKED" = TRAIT_BEING_SHOCKED,
"TRAIT_COMMISSIONED" = TRAIT_COMMISSIONED,
Expand Down
15 changes: 6 additions & 9 deletions code/_onclick/ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
ShiftClickOn(A)
return
if(LAZYACCESS(modifiers, ALT_CLICK)) // alt and alt-gr (rightalt)
AltClickOn(A)
A.ai_click_alt(src)
return
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlClickOn(A)
Expand Down Expand Up @@ -120,8 +120,6 @@
/mob/living/silicon/ai/CtrlClickOn(atom/target)
target.AICtrlClick(src)

/mob/living/silicon/ai/AltClickOn(atom/target)
target.AIAltClick(src)

/*
The following criminally helpful code is just the previous code cleaned up;
Expand All @@ -133,8 +131,7 @@
/atom/proc/AICtrlClick(mob/living/silicon/ai/user)
return

/atom/proc/AIAltClick(mob/living/silicon/ai/user)
AltClick(user)
/atom/proc/ai_click_alt(mob/living/silicon/ai/user)
return

/atom/proc/AIShiftClick(mob/living/silicon/ai/user)
Expand All @@ -150,7 +147,7 @@
toggle_bolt(user)
add_hiddenprint(user)

/obj/machinery/door/airlock/AIAltClick(mob/living/silicon/ai/user) // Eletrifies doors.
/obj/machinery/door/airlock/ai_click_alt(mob/living/silicon/ai/user)
if(obj_flags & EMAGGED)
return

Expand Down Expand Up @@ -219,7 +216,7 @@
update()

/// Toggle APC equipment settings
/obj/machinery/power/apc/AIAltClick(mob/living/silicon/ai/user)
/obj/machinery/power/apc/ai_click_alt(mob/living/silicon/ai/user)
if(!can_use(user, loud = TRUE))
return

Expand All @@ -243,7 +240,7 @@
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN

/* AI Turrets */
/obj/machinery/turretid/AIAltClick(mob/living/silicon/ai/user) //toggles lethal on turrets
/obj/machinery/turretid/ai_click_alt(mob/living/silicon/ai/user) //toggles lethal on turrets
if(ailock)
return
toggle_lethal(user)
Expand All @@ -254,7 +251,7 @@
toggle_on(user)

/* Holopads */
/obj/machinery/holopad/AIAltClick(mob/living/silicon/ai/user)
/obj/machinery/holopad/ai_click_alt(mob/living/silicon/ai/user)
if (user)
balloon_alert(user, "disrupted all active calls")
add_hiddenprint(user)
Expand Down
46 changes: 1 addition & 45 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
if(LAZYACCESS(modifiers, RIGHT_CLICK))
alt_click_on_secondary(A)
else
AltClickOn(A)
base_click_alt(A)
return
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlClickOn(A)
Expand Down Expand Up @@ -385,50 +385,6 @@
A.CtrlClick(src)
return

/**
* Alt click
* Unused except for AI
*/
/mob/proc/AltClickOn(atom/A)
. = SEND_SIGNAL(src, COMSIG_MOB_ALTCLICKON, A)
if(. & COMSIG_MOB_CANCEL_CLICKON)
return
A.AltClick(src)

/**
* Alt click on an atom.
* Performs alt-click actions before attempting to open a loot window.
* Returns TRUE if successful, FALSE if not.
*/
/atom/proc/AltClick(mob/user)
if(!user.can_interact_with(src))
return FALSE

if(SEND_SIGNAL(src, COMSIG_CLICK_ALT, user) & COMPONENT_CANCEL_CLICK_ALT)
return TRUE

if(HAS_TRAIT(src, TRAIT_ALT_CLICK_BLOCKER) && !isobserver(user))
return TRUE

var/turf/tile = get_turf(src)
if(isnull(tile))
return FALSE

if(!isturf(loc) && !isturf(src))
return FALSE

if(!user.TurfAdjacent(tile))
return FALSE

if(HAS_TRAIT(user, TRAIT_MOVE_VENTCRAWLING))
return FALSE

var/datum/lootpanel/panel = user.client?.loot_panel
if(isnull(panel))
return FALSE

panel.open(tile)
return TRUE

///The base proc of when something is right clicked on when alt is held - generally use alt_click_secondary instead
/atom/proc/alt_click_on_secondary(atom/A)
Expand Down
66 changes: 66 additions & 0 deletions code/_onclick/click_alt.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* ### Base proc for alt click interaction.
*
* If you wish to add custom `click_alt` behavior for a single type, use that proc.
*/
/mob/proc/base_click_alt(atom/target)
SHOULD_NOT_OVERRIDE(TRUE)

var/turf/tile = isturf(target) ? target : get_turf(target)

if(isobserver(src) || isrevenant(src))
open_lootpanel(tile)
return

if(!isturf(target) && can_perform_action(target, (target.interaction_flags_click | SILENT_ADJACENCY)))
if(SEND_SIGNAL(target, COMSIG_CLICK_ALT, src) & CLICK_ACTION_ANY)
return

if(target.click_alt(src) & CLICK_ACTION_ANY)
return

open_lootpanel(tile)


/// Helper for opening the lootpanel
/mob/proc/open_lootpanel(turf/target)
if(HAS_TRAIT(src, TRAIT_MOVE_VENTCRAWLING))
return

var/datum/lootpanel/panel = client?.loot_panel
if(isnull(panel))
return

panel.open(target)


/**
* ## Custom alt click interaction
* Override this to change default alt click behavior. Return `CLICK_ACTION_SUCCESS`, `CLICK_ACTION_BLOCKING` or `NONE`.
*
* ### Guard clauses
* Consider adding `interaction_flags_click` before adding unique guard clauses.
*
* ### Return flags
* Forgetting your return will cause the default alt click behavior to occur thereafter.
*
* The difference between NONE and BLOCKING can get hazy, but I like to keep NONE limited to guard clauses and "never" cases.
*
* A good usage for BLOCKING over NONE is when it's situational for the item and there's some feedback indicating this.
*
* ### Examples:
* User is a ghost, alt clicks on item with special disk eject: NONE
*
* Machine broken, no feedback: NONE
*
* Alt click a pipe to max output but its already max: BLOCKING
*
* Alt click a gun that normally works, but is out of ammo: BLOCKING
*
* User unauthorized, machine beeps: BLOCKING
*
* @param {mob} user - The person doing the alt clicking.
*/
/atom/proc/click_alt(mob/user)
SHOULD_CALL_PARENT(FALSE)
return NONE
22 changes: 10 additions & 12 deletions code/_onclick/cyborg.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
MiddleClickOn(A, params)
return
if(LAZYACCESS(modifiers, ALT_CLICK)) // alt and alt-gr (rightalt)
AltClickOn(A)
A.borg_click_alt(src)
return
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlClickOn(A)
Expand Down Expand Up @@ -89,7 +89,7 @@

if(after_attack_secondary_result == SECONDARY_ATTACK_CALL_NORMAL)
W.afterattack(A, src, FALSE, params)
else
else
W.afterattack(A, src, FALSE, params)

//Give cyborgs hotkey clicks without breaking existing uses of hotkey clicks
Expand All @@ -103,8 +103,6 @@
/mob/living/silicon/robot/CtrlClickOn(atom/target)
target.BorgCtrlClick(src)

/mob/living/silicon/robot/AltClickOn(atom/target)
target.BorgAltClick(src)

/atom/proc/BorgCtrlShiftClick(mob/living/silicon/robot/user) //forward to human click if not overridden
CtrlShiftClick(user)
Expand Down Expand Up @@ -152,9 +150,9 @@
else
..()

/obj/machinery/power/apc/BorgAltClick(mob/living/silicon/robot/user)
/obj/machinery/power/apc/borg_click_alt(mob/living/silicon/robot/user)
if(get_dist(src, user) <= user.interaction_range && !(user.control_disabled))
AIAltClick(user)
ai_click_alt(user)
else
..()

Expand All @@ -171,19 +169,19 @@
else
..()

/atom/proc/BorgAltClick(mob/living/silicon/robot/user)
AltClick(user)
/atom/proc/borg_click_alt(mob/living/silicon/robot/user)
user.base_click_alt(src)
return

/obj/machinery/door/airlock/BorgAltClick(mob/living/silicon/robot/user) // Eletrifies doors. Forwards to AI code.
/obj/machinery/door/airlock/borg_click_alt(mob/living/silicon/robot/user) // Eletrifies doors. Forwards to AI code.
if(get_dist(src, user) <= user.interaction_range && !(user.control_disabled))
AIAltClick(user)
ai_click_alt(user)
else
..()

/obj/machinery/turretid/BorgAltClick(mob/living/silicon/robot/user) //turret lethal on/off. Forwards to AI code.
/obj/machinery/turretid/borg_click_alt(mob/living/silicon/robot/user) //turret lethal on/off. Forwards to AI code.
if(get_dist(src, user) <= user.interaction_range && !(user.control_disabled))
AIAltClick(user)
ai_click_alt(user)
else
..()

Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/observer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
MiddleClickOn(A, params)
return
if(LAZYACCESS(modifiers, ALT_CLICK))
A.AltClick(src)
base_click_alt(A)
return
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlClickOn(A)
Expand Down
4 changes: 2 additions & 2 deletions code/_onclick/overmind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ShiftClickOn(A)
return
if(LAZYACCESS(modifiers, ALT_CLICK))
AltClickOn(A)
blob_click_alt(A)
return
if(LAZYACCESS(modifiers, CTRL_CLICK))
CtrlClickOn(A)
Expand All @@ -30,7 +30,7 @@
if(T)
create_shield(T)

/mob/camera/blob/AltClickOn(atom/A) //Remove a blob
/mob/camera/blob/proc/blob_click_alt(atom/A) //Remove a blob
var/turf/T = get_turf(A)
if(T)
remove_blob(T)
2 changes: 1 addition & 1 deletion code/datums/ai/oldhostile/hostile_tameable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
return
if(!istype(clicker) || blackboard[BB_HOSTILE_FRIEND] != clicker)
return
. = COMPONENT_CANCEL_CLICK_ALT
. = CLICK_ACTION_BLOCKING
INVOKE_ASYNC(src, PROC_REF(command_radial), clicker)

/// Show the command radial menu
Expand Down
6 changes: 3 additions & 3 deletions code/datums/components/gps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GLOBAL_LIST_EMPTY(GPS_list)
if(!emp_proof)
RegisterSignal(parent, COMSIG_ATOM_EMP_ACT, PROC_REF(on_emp_act))
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_CLICK_ALT, PROC_REF(on_AltClick))
RegisterSignal(parent, COMSIG_CLICK_ALT, PROC_REF(on_click_alt))

///Called on COMSIG_ITEM_ATTACK_SELF
/datum/component/gps/item/proc/interact(datum/source, mob/user)
Expand Down Expand Up @@ -85,11 +85,11 @@ GLOBAL_LIST_EMPTY(GPS_list)
A.add_overlay("working")

///Calls toggletracking
/datum/component/gps/item/proc/on_AltClick(datum/source, mob/user)
/datum/component/gps/item/proc/on_click_alt(datum/source, mob/user)
SIGNAL_HANDLER

toggletracking(user)
return COMPONENT_CANCEL_CLICK_ALT
return CLICK_ACTION_SUCCESS

///Toggles the tracking for the gps
/datum/component/gps/item/proc/toggletracking(mob/user)
Expand Down
1 change: 1 addition & 0 deletions code/datums/components/pet_commands/obeys_commands.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
return // Not our friend, can't boss us around

INVOKE_ASYNC(src, PROC_REF(display_radial_menu), clicker)
return CLICK_ACTION_SUCCESS

/// Actually display the radial menu and then do something with the result
/datum/component/obeys_commands/proc/display_radial_menu(mob/living/clicker)
Expand Down
Loading

0 comments on commit cc106e3

Please sign in to comment.