From b425a19e9b20a5809e62ab8e9969cb32026aca5c Mon Sep 17 00:00:00 2001 From: MistakeNot4892 Date: Wed, 13 May 2026 14:47:08 +1000 Subject: [PATCH] Adding an Interact hotkey. --- code/game/atoms.dm | 3 ++ .../machinery/_machines_base/machinery.dm | 1 + code/game/machinery/doors/_door.dm | 1 + code/game/objects/items/__item.dm | 1 + code/game/objects/structures/doors/_door.dm | 1 + .../game/objects/structures/fences/_fences.dm | 1 + code/game/objects/structures/inflatable.dm | 1 + code/modules/atmospherics/atmospherics.dm | 1 + code/modules/keybindings/binds/mob.dm | 39 +++++++++++++++++++ code/modules/lights/light_fixture_base.dm | 1 + 10 files changed, 50 insertions(+) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 0d0b617fc5a5..f1c8442e2166 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -73,6 +73,9 @@ /// (DATUM) Similar to above, but largely used by /turf/wall, /obj/structure and /obj/item/stack/material var/decl/material/reinf_material + /// (BOOLEAN) Set to TRUE to prioritise this atom when using the interact hotkey. + var/interaction_priority + /atom/proc/get_max_health() return max_health diff --git a/code/game/machinery/_machines_base/machinery.dm b/code/game/machinery/_machines_base/machinery.dm index bf6673bab4ce..dbdeb293a6c5 100644 --- a/code/game/machinery/_machines_base/machinery.dm +++ b/code/game/machinery/_machines_base/machinery.dm @@ -81,6 +81,7 @@ Class Procs: ) temperature_sensitive = TRUE abstract_type = /obj/machinery + interaction_priority = TRUE var/stat = 0 var/waterproof = TRUE diff --git a/code/game/machinery/doors/_door.dm b/code/game/machinery/doors/_door.dm index 2aef4698196b..53b5ff87862a 100644 --- a/code/game/machinery/doors/_door.dm +++ b/code/game/machinery/doors/_door.dm @@ -15,6 +15,7 @@ uncreated_component_parts = null required_interaction_dexterity = DEXTERITY_SIMPLE_MACHINES max_health = 300 + interaction_priority = TRUE var/can_open_manually = TRUE diff --git a/code/game/objects/items/__item.dm b/code/game/objects/items/__item.dm index dfc848c8b322..1aa3d47a8b00 100644 --- a/code/game/objects/items/__item.dm +++ b/code/game/objects/items/__item.dm @@ -5,6 +5,7 @@ pass_flags = PASS_FLAG_TABLE abstract_type = /obj/item temperature_sensitive = TRUE + interaction_priority = TRUE /// Set to prefix name with this string ('woven' for 'woven basket' etc) var/name_prefix diff --git a/code/game/objects/structures/doors/_door.dm b/code/game/objects/structures/doors/_door.dm index 586450e6d93e..3bce4984aaf4 100644 --- a/code/game/objects/structures/doors/_door.dm +++ b/code/game/objects/structures/doors/_door.dm @@ -9,6 +9,7 @@ anchored = TRUE opacity = TRUE structure_flags = STRUCTURE_FLAG_THROWN_DAMAGE + interaction_priority = TRUE var/has_window = FALSE var/changing_state = FALSE var/door_sound_volume = 25 diff --git a/code/game/objects/structures/fences/_fences.dm b/code/game/objects/structures/fences/_fences.dm index 9bc566ec9e88..af0323e27e68 100644 --- a/code/game/objects/structures/fences/_fences.dm +++ b/code/game/objects/structures/fences/_fences.dm @@ -227,6 +227,7 @@ name = "fence gate" desc = "Much like a regular door, but thinner." icon_state = "door-closed" + interaction_priority = TRUE /obj/structure/fence/door/can_install_lock() return TRUE diff --git a/code/game/objects/structures/inflatable.dm b/code/game/objects/structures/inflatable.dm index 137ce1cba193..0251001628ed 100644 --- a/code/game/objects/structures/inflatable.dm +++ b/code/game/objects/structures/inflatable.dm @@ -192,6 +192,7 @@ density = TRUE anchored = TRUE opacity = FALSE + interaction_priority = TRUE icon_state = "door_closed" undeploy_path = /obj/item/inflatable/door diff --git a/code/modules/atmospherics/atmospherics.dm b/code/modules/atmospherics/atmospherics.dm index 1d8c5e788fee..78d6fab2615c 100644 --- a/code/modules/atmospherics/atmospherics.dm +++ b/code/modules/atmospherics/atmospherics.dm @@ -14,6 +14,7 @@ Pipelines + Other Objects -> Pipe network idle_power_usage = 0 active_power_usage = 0 power_channel = ENVIRON + interaction_priority = null var/power_rating //the maximum amount of power the machine can use to do work, affects how powerful the machine is, in Watts diff --git a/code/modules/keybindings/binds/mob.dm b/code/modules/keybindings/binds/mob.dm index 73a6bc128a75..7ec531a4881c 100644 --- a/code/modules/keybindings/binds/mob.dm +++ b/code/modules/keybindings/binds/mob.dm @@ -183,3 +183,42 @@ /datum/keybinding/mob/minimal_hud/down(client/user) user.mob.minimize_hud() return TRUE + +/datum/keybinding/mob/interact + hotkey_keys = list("Enter") + name = "interact" + full_name = "Interact" + description = "Interact with the turf directly in front of you." + +/datum/keybinding/mob/interact/down(client/user) + user.mob.interact_with_facing() + return TRUE + +/mob/proc/interact_with_facing() + + var/turf/facing = get_step(get_turf(src), dir) + if(!istype(facing)) + return + + var/atom/click_on + if(length(facing.contents)) + var/list/atoms = sortTim(facing.contents.Copy(), /proc/cmp_planelayer) + + // Move non-prioritised atoms to the end of the list (to avoid burning our hands on lights when trying to open a closet) + for(var/atom/clickable as anything in atoms) + if(!clickable.interaction_priority) + atoms -= clickable + atoms += clickable + + // Try to click something. + for(var/atom/clickable as anything in atoms) + if(!clickable.simulated) + continue + if(clickable.invisibility > see_invisible) + continue + click_on = clickable + break + else + click_on = facing + + click_on?.Click() diff --git a/code/modules/lights/light_fixture_base.dm b/code/modules/lights/light_fixture_base.dm index 1afdd5b1552f..6db79ddaa955 100644 --- a/code/modules/lights/light_fixture_base.dm +++ b/code/modules/lights/light_fixture_base.dm @@ -12,6 +12,7 @@ idle_power_usage = 2 active_power_usage = 20 power_channel = LIGHT //Lights are calc'd via area so they dont need to be in the machine list + interaction_priority = null uncreated_component_parts = list( /obj/item/stock_parts/power/apc