From d91650ea39fbb74b60577c2383b82edd9969afc3 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Fri, 7 Jun 2024 22:50:33 +0530 Subject: [PATCH] Alt right click refactor (#83736) --- code/_onclick/click.dm | 20 +-------- code/_onclick/click_alt.dm | 43 ++++++++++++++++++- code/game/objects/items/cards_ids.dm | 10 ++--- code/modules/clothing/neck/_neck.dm | 8 ++-- code/modules/clothing/under/_under.dm | 10 +---- .../projectiles/guns/ballistic/shotgun.dm | 3 +- .../chemistry/machinery/chem_mass_spec.dm | 7 +-- 7 files changed, 53 insertions(+), 48 deletions(-) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index 3c99364542c..ff0da9caa5e 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -94,7 +94,7 @@ return if(LAZYACCESS(modifiers, ALT_CLICK)) // alt and alt-gr (rightalt) if(LAZYACCESS(modifiers, RIGHT_CLICK)) - alt_click_on_secondary(A) + base_click_alt_secondary(A) else base_click_alt(A) return @@ -386,24 +386,6 @@ A.CtrlClick(src) return - -///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) - . = SEND_SIGNAL(src, COMSIG_MOB_ALTCLICKON_SECONDARY, A) - if(. & COMSIG_MOB_CANCEL_CLICKON) - return - A.alt_click_secondary(src) - -///The base proc of when something is right clicked on when alt is held -/atom/proc/alt_click_secondary(mob/user) - if(!user.can_interact_with(src)) - return FALSE - if(SEND_SIGNAL(src, COMSIG_CLICK_ALT_SECONDARY, user) & COMPONENT_CANCEL_CLICK_ALT_SECONDARY) - return - if(isobserver(user) && user.client && check_rights_for(user.client, R_DEBUG)) - user.client.toggle_tag_datum(src) - return - /mob/proc/TurfAdjacent(turf/tile) return tile.Adjacent(src) diff --git a/code/_onclick/click_alt.dm b/code/_onclick/click_alt.dm index dfda35ebda9..957f55ab217 100644 --- a/code/_onclick/click_alt.dm +++ b/code/_onclick/click_alt.dm @@ -1,5 +1,5 @@ /** - * ### Base proc for alt click interaction. + * ### Base proc for alt click interaction left click. * * If you wish to add custom `click_alt` behavior for a single type, use that proc. */ @@ -53,7 +53,6 @@ client.loot_panel.open(tile) - /** * ## Custom alt click interaction * Override this to change default alt click behavior. Return `CLICK_ACTION_SUCCESS`, `CLICK_ACTION_BLOCKING` or `NONE`. @@ -86,6 +85,46 @@ return NONE +/** + * ### Base proc for alt click interaction right click. + * + * If you wish to add custom `click_alt_secondary` behavior for a single type, use that proc. + */ +/mob/proc/base_click_alt_secondary(atom/target) + SHOULD_NOT_OVERRIDE(TRUE) + + //Hook on the mob to intercept the click + if(SEND_SIGNAL(src, COMSIG_MOB_ALTCLICKON_SECONDARY, target) & COMSIG_MOB_CANCEL_CLICKON) + return + + var/can_use_click_action = FALSE + if(isturf(target)) + // Turfs are special because they can't be used with can_perform_action + can_use_click_action = can_perform_turf_action(target) + else + can_use_click_action = can_perform_action(target, target.interaction_flags_click | SILENT_ADJACENCY) + if(!can_use_click_action) + return + + //Hook on the atom to intercept the click + if(SEND_SIGNAL(target, COMSIG_CLICK_ALT_SECONDARY, src) & COMPONENT_CANCEL_CLICK_ALT_SECONDARY) + return + if(isobserver(src) && client && check_rights_for(client, R_DEBUG)) + client.toggle_tag_datum(src) + return + target.click_alt_secondary(src) + +/** + * ## Custom alt click secondary interaction + * Override this to change default alt right click behavior. + * + * ### Guard clauses + * Consider adding `interaction_flags_click` before adding unique guard clauses. + **/ +/atom/proc/click_alt_secondary(mob/user) + SHOULD_CALL_PARENT(FALSE) + return NONE + /// Helper proc to validate turfs. Used because can_perform_action does not support turfs. /mob/proc/can_perform_turf_action(turf/target) if(!CanReach(target)) // No error message for parity with SILENT_ADJACENCY diff --git a/code/game/objects/items/cards_ids.dm b/code/game/objects/items/cards_ids.dm index fe03aaaf01e..880e619da0a 100644 --- a/code/game/objects/items/cards_ids.dm +++ b/code/game/objects/items/cards_ids.dm @@ -56,6 +56,7 @@ icon_state = "card_grey" worn_icon_state = "nothing" slot_flags = ITEM_SLOT_ID + interaction_flags_click = FORBID_TELEKINESIS_REACH armor_type = /datum/armor/card_id resistance_flags = FIRE_PROOF | ACID_PROOF @@ -633,9 +634,6 @@ /obj/item/card/id/proc/alt_click_can_use_id(mob/living/user) if(!isliving(user)) return FALSE - if(!user.can_perform_action(src, FORBID_TELEKINESIS_REACH)) - return FALSE - return TRUE /// Attempts to set a new bank account on the ID card. @@ -706,13 +704,11 @@ registered_account.bank_card_talk(span_warning("ERROR: The linked account requires [difference] more credit\s to perform that withdrawal."), TRUE) return CLICK_ACTION_BLOCKING -/obj/item/card/id/alt_click_secondary(mob/user) - . = ..() +/obj/item/card/id/click_alt_secondary(mob/user) if(!alt_click_can_use_id(user)) - return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN + return if(!registered_account || registered_account.replaceable) set_new_account(user) - return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN /obj/item/card/id/proc/pay_debt(user) var/amount_to_pay = tgui_input_number(user, "How much do you want to pay? (Max: [registered_account.account_balance] cr)", "Debt Payment", max_value = min(registered_account.account_balance, registered_account.account_debt)) diff --git a/code/modules/clothing/neck/_neck.dm b/code/modules/clothing/neck/_neck.dm index 2cac0968579..7a3c0f1150d 100644 --- a/code/modules/clothing/neck/_neck.dm +++ b/code/modules/clothing/neck/_neck.dm @@ -3,6 +3,7 @@ icon = 'icons/obj/clothing/neck.dmi' body_parts_covered = NECK slot_flags = ITEM_SLOT_NECK + interaction_flags_click = NEED_DEXTERITY strip_delay = 40 equip_delay_other = 40 @@ -103,11 +104,8 @@ user.update_clothing(ITEM_SLOT_NECK) return CLICK_ACTION_SUCCESS -/obj/item/clothing/neck/tie/alt_click_secondary(mob/user) - . = ..() - if(!user.can_perform_action(src, NEED_DEXTERITY)) - return - alternate_worn_layer = alternate_worn_layer == initial(alternate_worn_layer) ? NONE : initial(alternate_worn_layer) +/obj/item/clothing/neck/tie/click_alt_secondary(mob/user) + alternate_worn_layer = (alternate_worn_layer == initial(alternate_worn_layer) ? NONE : initial(alternate_worn_layer)) user.update_clothing(ITEM_SLOT_NECK) balloon_alert(user, "wearing [alternate_worn_layer == initial(alternate_worn_layer) ? "below" : "above"] suits") diff --git a/code/modules/clothing/under/_under.dm b/code/modules/clothing/under/_under.dm index fd8512c3eb8..40f8068aef5 100644 --- a/code/modules/clothing/under/_under.dm +++ b/code/modules/clothing/under/_under.dm @@ -6,6 +6,7 @@ righthand_file = 'icons/mob/inhands/clothing/suits_righthand.dmi' body_parts_covered = CHEST|GROIN|LEGS|ARMS slot_flags = ITEM_SLOT_ICLOTHING + interaction_flags_click = NEED_DEXTERITY armor_type = /datum/armor/clothing_under equip_sound = 'sound/items/equip/jumpsuit_equip.ogg' drop_sound = 'sound/items/handling/cloth_drop.ogg' @@ -378,17 +379,10 @@ rolldown() return CLICK_ACTION_SUCCESS -/obj/item/clothing/under/alt_click_secondary(mob/user) - . = ..() - if(.) - return - +/obj/item/clothing/under/click_alt_secondary(mob/user) if(!LAZYLEN(attached_accessories)) balloon_alert(user, "no accessories to remove!") return - if(!user.can_perform_action(src, NEED_DEXTERITY)) - return - pop_accessory(user) /obj/item/clothing/under/verb/jumpsuit_adjust() diff --git a/code/modules/projectiles/guns/ballistic/shotgun.dm b/code/modules/projectiles/guns/ballistic/shotgun.dm index 85f3283ca43..a06f6954bf3 100644 --- a/code/modules/projectiles/guns/ballistic/shotgun.dm +++ b/code/modules/projectiles/guns/ballistic/shotgun.dm @@ -239,14 +239,13 @@ update_appearance() return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN -/obj/item/gun/ballistic/shotgun/bulldog/alt_click_secondary(mob/user) +/obj/item/gun/ballistic/shotgun/bulldog/click_alt_secondary(mob/user) if(secondary_magazine) var/obj/item/ammo_box/magazine/old_mag = secondary_magazine secondary_magazine = null user.put_in_hands(old_mag) update_appearance() playsound(src, load_empty_sound, load_sound_volume, load_sound_vary) - return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN /obj/item/gun/ballistic/shotgun/bulldog/proc/toggle_magazine() var/primary_magazine = magazine diff --git a/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm b/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm index e11910a13af..e43d32c661b 100644 --- a/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm +++ b/code/modules/reagents/chemistry/machinery/chem_mass_spec.dm @@ -434,13 +434,10 @@ replace_beaker(user, TRUE) return CLICK_ACTION_SUCCESS -/obj/machinery/chem_mass_spec/alt_click_secondary(mob/living/user) - . = ..() - if(!can_interact(user)) - return +/obj/machinery/chem_mass_spec/click_alt_secondary(mob/living/user) if(processing_reagents) balloon_alert(user, "still processing!") - return ..() + return replace_beaker(user, FALSE) /obj/machinery/chem_mass_spec/process(seconds_per_tick)