Skip to content

Commit

Permalink
adds the ability to keybind click() triggers (ParadiseSS13#23395)
Browse files Browse the repository at this point in the history
* adds the ability to keybind click() triggers

* Update code/datums/keybindings/click_keybindings.dm

Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>

* Update code/_onclick/click.dm

* final fixes

* runtime fix

---------

Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>
  • Loading branch information
GDNgit and Sirryan2002 authored Feb 21, 2024
1 parent 8335d99 commit 599f645
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 24 deletions.
3 changes: 2 additions & 1 deletion code/__DEFINES/keybindings_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#define KB_CATEGORY_EMOTE_SILICON 14
#define KB_CATEGORY_EMOTE_ANIMAL 15
#define KB_CATEGORY_EMOTE_CUSTOM 16
#define KB_CATEGORY_COMMUNICATION 17
#define KB_CATEGORY_CLICK 17
#define KB_CATEGORY_COMMUNICATION 18
#define KB_CATEGORY_UNSORTED 1000

///Max length of a keypress command before it's considered to be a forged packet/bogus command
Expand Down
1 change: 1 addition & 0 deletions code/_globalvars/lists/keybindings_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GLOBAL_LIST_INIT(keybindings_groups, list(
"Animal Emote" = KB_CATEGORY_EMOTE_ANIMAL,
"Brain Emote" = KB_CATEGORY_EMOTE_BRAIN,
"Alien Emote" = KB_CATEGORY_EMOTE_ALIEN,
"Click Keybinds" = KB_CATEGORY_CLICK,
"Admin" = KB_CATEGORY_ADMIN,
"Other" = KB_CATEGORY_UNSORTED,
"Custom Emotes (Character-based)" = KB_CATEGORY_EMOTE_CUSTOM,
Expand Down
59 changes: 36 additions & 23 deletions code/_onclick/ai_onclick.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,8 @@
if(control_disabled || stat)
return

var/turf/pixel_turf = isturf(A) ? A : get_turf_pixel(A)
if(isnull(pixel_turf))
if(!can_click_on_turf(A))
return
if(!can_see(A))
if(isturf(A)) //On unmodified clients clicking the static overlay clicks the turf underneath
return // So there's no point messaging admins
add_attack_logs(src, src, "[key_name_admin(src)] might be running a modified client! (failed can_see on AI click of [A]([ADMIN_COORDJMP(pixel_turf)]))", ATKLOG_ALL)
var/message = "[key_name(src)] might be running a modified client! (failed can_see on AI click of [A]([COORD(pixel_turf)]))"
log_admin(message)
GLOB.discord_manager.send2discord_simple_noadmins("**\[Warning]** [key_name(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([COORD(pixel_turf)]))")


var/turf_visible
if(pixel_turf)
turf_visible = GLOB.cameranet.checkTurfVis(pixel_turf)
if(!turf_visible)
if(istype(loc, /obj/item/aicard) && (pixel_turf in view(client.view, loc)))
turf_visible = TRUE
else
if(pixel_turf.obscured)
log_admin("[key_name_admin(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([COORD(pixel_turf)])")
add_attack_logs(src, src, "[key_name_admin(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([ADMIN_COORDJMP(pixel_turf)]))", ATKLOG_ALL)
GLOB.discord_manager.send2discord_simple_noadmins("**\[Warning]** [key_name(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([COORD(pixel_turf)]))")
return

var/list/modifiers = params2list(params)
if(modifiers["shift"] && modifiers["ctrl"])
Expand Down Expand Up @@ -106,6 +84,41 @@
A.add_hiddenprint(src)
A.attack_ai(src)

/mob/living/silicon/ai/MiddleShiftControlClickOn(atom/A)
return

/mob/living/silicon/ai/can_use_clickbinds()
var/atom/atom_targeted = locateUID(client.moused_over)
if(atom_targeted)
return can_click_on_turf(atom_targeted)

/mob/living/silicon/ai/proc/can_click_on_turf(atom/A)
var/turf/pixel_turf = isturf(A) ? A : get_turf_pixel(A)
if(isnull(pixel_turf))
return
if(!can_see(A))
if(isturf(A)) //On unmodified clients clicking the static overlay clicks the turf underneath
return // So there's no point messaging admins
add_attack_logs(src, src, "[key_name_admin(src)] might be running a modified client! (failed can_see on AI click of [A]([ADMIN_COORDJMP(pixel_turf)]))", ATKLOG_ALL)
var/message = "[key_name(src)] might be running a modified client! (failed can_see on AI click of [A]([COORD(pixel_turf)]))"
log_admin(message)
GLOB.discord_manager.send2discord_simple_noadmins("**\[Warning]** [key_name(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([COORD(pixel_turf)]))")
return FALSE

var/turf_visible
if(pixel_turf)
turf_visible = GLOB.cameranet.checkTurfVis(pixel_turf)
if(!turf_visible)
if(istype(loc, /obj/item/aicard) && (pixel_turf in view(client.view, loc)))
turf_visible = TRUE
else
if(pixel_turf.obscured)
log_admin("[key_name_admin(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([COORD(pixel_turf)])")
add_attack_logs(src, src, "[key_name_admin(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([ADMIN_COORDJMP(pixel_turf)]))", ATKLOG_ALL)
GLOB.discord_manager.send2discord_simple_noadmins("**\[Warning]** [key_name(src)] might be running a modified client! (failed checkTurfVis on AI click of [A]([COORD(pixel_turf)]))")
return FALSE
return TRUE

/*
AI has no need for the UnarmedAttack() and RangedAttack() procs,
because the AI code is not generic; attack_ai() is used instead.
Expand Down
4 changes: 4 additions & 0 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@

return

/// Can this mob use keybinded click actions? (Altclick, Ctrlclick, ect)
/mob/proc/can_use_clickbinds()
return TRUE

//Is the atom obscured by a PREVENT_CLICK_UNDER_1 object above it
/atom/proc/IsObscured()
if(!isturf(loc)) //This only makes sense for things directly on turfs for now
Expand Down
3 changes: 3 additions & 0 deletions code/_onclick/cyborg.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
return
return

/mob/living/silicon/robot/MiddleShiftControlClickOn(atom/A)
return

//Ctrl+Middle click cycles through modules
/mob/living/silicon/robot/proc/CtrlMiddleClickOn(atom/A)
cycle_modules()
Expand Down
15 changes: 15 additions & 0 deletions code/_onclick/observer_onclick.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@
/mob/dead/observer/ShiftClickOn(atom/A)
examinate(A)

/mob/dead/observer/AltClickOn(atom/A)
AltClickNoInteract(src, A)

/mob/dead/observer/AltShiftClickOn(atom/A)
return

/mob/dead/observer/CtrlShiftClickOn(atom/A)
return

/mob/dead/observer/MiddleShiftClickOn(atom/A)
return

/mob/dead/observer/MiddleShiftControlClickOn(atom/A)
return

/atom/proc/attack_ghost(mob/user)
if(SEND_SIGNAL(src, COMSIG_ATOM_ATTACK_GHOST, user) & COMPONENT_CANCEL_ATTACK_CHAIN)
return TRUE
Expand Down
3 changes: 3 additions & 0 deletions code/_onclick/other_mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
/mob/new_player/ClickOn()
return

/mob/new_player/can_use_clickbinds()
return FALSE

// pAIs are not intended to interact with anything in the world
/mob/living/silicon/pai/UnarmedAttack(atom/A)
return
12 changes: 12 additions & 0 deletions code/_onclick/overmind_onclick.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@
var/turf/T = get_turf(A)
if(T)
remove_blob(T)

/mob/camera/blob/AltShiftClickOn(atom/A)
return AltClickOn(A)

/mob/camera/blob/CtrlShiftClickOn(atom/A)
return CtrlClickOn(A)

/mob/camera/blob/MiddleShiftClickOn(atom/A)
return MiddleClickOn(A)

/mob/camera/blob/MiddleShiftControlClickOn(atom/A)
return MiddleClickOn(A)
77 changes: 77 additions & 0 deletions code/datums/keybindings/click_keybindings.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/datum/keybinding/clickbind
category = KB_CATEGORY_CLICK

/datum/keybinding/clickbind/can_use(client/C, mob/M)
return istype(M) && M.can_use_clickbinds() && ..()

/datum/keybinding/clickbind/down(client/C)
..()
if(C.mob.next_click > world.time)
return
C.mob.changeNext_click(1)
return locateUID(C.moused_over)

/datum/keybinding/clickbind/alt_click
name = "Alt-Click"

/datum/keybinding/clickbind/alt_click/down(client/C)
. = ..()
if(.)
C.mob.AltClickOn(.)

/datum/keybinding/clickbind/ctrl_click
name = "Ctrl-Click"

/datum/keybinding/clickbind/ctrl_click/down(client/C)
. = ..()
if(.)
C.mob.CtrlClickOn(.)

/datum/keybinding/clickbind/shift_click
name = "Shift-Click"

/datum/keybinding/clickbind/shift_click/down(client/C)
. = ..()
if(.)
C.mob.ShiftClickOn(.)

/datum/keybinding/clickbind/middle_click
name = "Middle-Click"

/datum/keybinding/clickbind/middle_click/down(client/C)
. = ..()
if(.)
C.mob.MiddleClickOn(.)

/datum/keybinding/clickbind/alt_shift_click
name = "Alt-Shift-Click"

/datum/keybinding/clickbind/alt_shift_click/down(client/C)
. = ..()
if(.)
C.mob.AltShiftClickOn(.)

/datum/keybinding/clickbind/ctrl_shift_click
name = "Ctrl-Shift-Click"

/datum/keybinding/clickbind/ctrl_shift_click/down(client/C)
. = ..()
if(.)
C.mob.CtrlShiftClickOn(.)

/datum/keybinding/clickbind/middle_shift_click
name = "Middle-Shift-Click"

/datum/keybinding/clickbind/middle_shift_click/down(client/C)
. = ..()
if(.)
C.mob.MiddleShiftClickOn(.)

/datum/keybinding/clickbind/middle_shift_ctrl_click
name = "Middle-Shift-Ctrl-Click"

/datum/keybinding/clickbind/middle_shift_ctrl_click/down(client/C)
. = ..()
if(.)
C.mob.MiddleShiftControlClickOn(.)

2 changes: 2 additions & 0 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,11 @@
return
//We inline a MAPTEXT() here, because there's no good way to statically add to a string like this
active_hud.screentip_text.maptext = "<span class='maptext' style='font-family: sans-serif; text-align: center; font-size: [screentip_mode]px; color: [usr.client.prefs.screentip_color]'>[name]</span>"
usr.client.moused_over = UID()

/atom/movable/MouseExited(location, control, params)
usr.hud_used.screentip_text.maptext = ""
usr.client.moused_over = null

/atom/movable/proc/choose_crush_crit(mob/living/carbon/victim)
if(!length(GLOB.tilt_crits))
Expand Down
2 changes: 2 additions & 0 deletions code/modules/client/client_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
var/list/active_keybindings = list()
/// The client's movement keybindings to directions, which work regardless of modifiers.
var/list/movement_kb_dirs = list()
/// The client's currently moused over datum, limited to movable and stored as UID
var/atom/movable/moused_over

/// A lazy list of atoms we've examined in the last RECENT_EXAMINE_MAX_WINDOW (default 2) seconds, so that we will call [/atom/proc/examine_more] instead of [/atom/proc/examine] on them when examining
var/list/recent_examines
Expand Down
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
#include "code\datums\keybindings\admin_keybinds.dm"
#include "code\datums\keybindings\ai_keybinds.dm"
#include "code\datums\keybindings\carbon_keybinds.dm"
#include "code\datums\keybindings\click_keybindings.dm"
#include "code\datums\keybindings\client.dm"
#include "code\datums\keybindings\communication_keybinds.dm"
#include "code\datums\keybindings\emote_keybinds.dm"
Expand Down

0 comments on commit 599f645

Please sign in to comment.