Skip to content

Commit

Permalink
Refactors hud code, MASSIVELY improves Observe verb. (#657)
Browse files Browse the repository at this point in the history
* pass hud into screen object new

* sanitize all screen object clicks

* robust observe

* fix action buttons and gunpoint

* fix skew

* fix radials and the crafting menu

* fix craft menu for real

* fix crafting 4 real

* use timer uses new format

* fix
  • Loading branch information
Kapu1178 authored Feb 12, 2024
1 parent 643bbcf commit 4dee479
Show file tree
Hide file tree
Showing 52 changed files with 695 additions and 588 deletions.
13 changes: 10 additions & 3 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,12 @@

/atom/proc/ShiftClick(mob/user)
var/flags = SEND_SIGNAL(user, COMSIG_CLICK_SHIFT, src)
if(user.client && (user.client.eye == user || user.client.eye == user.loc || flags & COMPONENT_ALLOW_EXAMINATE))
user.examinate(src)
return
if(!user.client)
return
if(!((user.client.eye == user) || (user.client.eye == user.loc) || isobserver(user)) && !(flags & COMPONENT_ALLOW_EXAMINATE))
return

user.examinate(src)

/**
* Ctrl click
Expand Down Expand Up @@ -548,6 +551,10 @@
transform = M

/atom/movable/screen/click_catcher/Click(location, control, params)
. = ..()
if(.)
return FALSE

var/list/modifiers = params2list(params)
if(LAZYACCESS(modifiers, MIDDLE_CLICK) && iscarbon(usr))
var/mob/living/carbon/C = usr
Expand Down
65 changes: 31 additions & 34 deletions code/_onclick/hud/action_button.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)
/atom/movable/screen/movable/action_button
var/datum/action/linked_action
var/datum/hud/our_hud
var/actiontooltipstyle = ""
screen_loc = null

Expand All @@ -21,31 +20,30 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)
var/datum/weakref/last_hovored_ref

/atom/movable/screen/movable/action_button/Destroy()
if(our_hud)
var/mob/viewer = our_hud.mymob
our_hud.hide_action(src)
if(hud)
var/mob/viewer = hud.mymob
hud.hide_action(src)
viewer?.client?.screen -= src
linked_action.viewers -= our_hud
linked_action.viewers -= hud
viewer.update_action_buttons()
our_hud = null
linked_action = null
return ..()

/atom/movable/screen/movable/action_button/proc/can_use(mob/user)
/atom/movable/screen/movable/action_button/can_usr_use(mob/user)
// Observers can only click on action buttons if they're not observing something
if(isobserver(user))
var/mob/dead/observer/dead_mob = user
if(dead_mob.observetarget) // Observers can only click on action buttons if they're not observing something
var/mob/dead/observer/O = user
if(O.observetarget)
return FALSE

if(linked_action)
if(linked_action.viewers[user.hud_used])
return TRUE
return FALSE

return TRUE
return FALSE

/atom/movable/screen/movable/action_button/Click(location,control,params)
if (!can_use(usr))
. = ..()
if(.)
return FALSE

var/list/modifiers = params2list(params)
Expand All @@ -55,6 +53,7 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)
return TRUE
if(usr.next_click > world.time)
return

usr.next_click = world.time + 1
var/trigger_flags
if(LAZYACCESS(modifiers, RIGHT_CLICK))
Expand All @@ -66,7 +65,7 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)
// Very much byond logic, but I want nice behavior, so we fake it with drag
/atom/movable/screen/movable/action_button/MouseDrag(atom/over_object, src_location, over_location, src_control, over_control, params)
. = ..()
if(!can_use(usr))
if(!can_usr_use(usr))
return
if(IS_WEAKREF_OF(over_object, last_hovored_ref))
return
Expand Down Expand Up @@ -95,7 +94,7 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)

/atom/movable/screen/movable/action_button/MouseDrop(over_object)
last_hovored_ref = null
if(!can_use(usr))
if(!can_usr_use(usr))
return
var/datum/hud/our_hud = usr.hud_used
if(over_object == src)
Expand Down Expand Up @@ -123,7 +122,7 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)
save_position()

/atom/movable/screen/movable/action_button/proc/save_position()
var/mob/user = our_hud.mymob
var/mob/user = hud.mymob
if(!user?.client)
return
var/position_info = ""
Expand All @@ -138,14 +137,14 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)
user.client.prefs.action_buttons_screen_locs["[name]_[id]"] = position_info

/atom/movable/screen/movable/action_button/proc/load_position()
var/mob/user = our_hud.mymob
var/mob/user = hud.mymob
if(!user)
return
var/position_info = user.client?.prefs?.action_buttons_screen_locs["[name]_[id]"] || SCRN_OBJ_DEFAULT
user.hud_used.position_action(src, position_info)

/atom/movable/screen/movable/action_button/proc/dump_save()
var/mob/user = our_hud.mymob
var/mob/user = hud.mymob
if(!user?.client)
return
user.client.prefs.action_buttons_screen_locs -= "[name]_[id]"
Expand Down Expand Up @@ -253,12 +252,12 @@ DEFINE_INTERACTABLE(/atom/movable/screen/movable/action_button)

/atom/movable/screen/button_palette/Destroy()
if(our_hud)
our_hud.mymob?.client?.screen -= src
our_hud.mymob?.canon_client?.screen -= src
our_hud.toggle_palette = null
our_hud = null
return ..()

/atom/movable/screen/button_palette/Initialize(mapload)
/atom/movable/screen/button_palette/Initialize(mapload, datum/hud/hud_owner)
. = ..()
update_appearance()

Expand Down Expand Up @@ -318,15 +317,10 @@ GLOBAL_LIST_INIT(palette_removed_matrix, list(1.4,0,0,0, 0.7,0.4,0,0, 0.4,0,0.6,
color_timer_id = null
remove_atom_colour(TEMPORARY_COLOUR_PRIORITY, to_remove)

/atom/movable/screen/button_palette/proc/can_use(mob/user)
if (isobserver(user))
var/mob/dead/observer/O = user
return !O.observetarget
return TRUE

/atom/movable/screen/button_palette/Click(location, control, params)
if(!can_use(usr))
return
. = ..()
if(.)
return FALSE

var/list/modifiers = params2list(params)

Expand Down Expand Up @@ -376,7 +370,8 @@ GLOBAL_LIST_INIT(palette_removed_matrix, list(1.4,0,0,0, 0.7,0.4,0,0, 0.4,0,0.6,
var/scroll_direction = 0
var/datum/hud/our_hud

/atom/movable/screen/palette_scroll/proc/can_use(mob/user)
/atom/movable/screen/palette_scroll/can_usr_use(mob/user)
. = ..()
if (isobserver(user))
var/mob/dead/observer/O = user
return !O.observetarget
Expand All @@ -395,8 +390,10 @@ GLOBAL_LIST_INIT(palette_removed_matrix, list(1.4,0,0,0, 0.7,0.4,0,0, 0.4,0,0.6,
icon = settings["bg_icon"]

/atom/movable/screen/palette_scroll/Click(location, control, params)
if(!can_use(usr))
return
. = ..()
if(.)
return FALSE

our_hud.palette_actions.scroll(scroll_direction)

/atom/movable/screen/palette_scroll/MouseEntered(location, control, params)
Expand All @@ -417,7 +414,7 @@ GLOBAL_LIST_INIT(palette_removed_matrix, list(1.4,0,0,0, 0.7,0.4,0,0, 0.4,0,0.6,

/atom/movable/screen/palette_scroll/down/Destroy()
if(our_hud)
our_hud.mymob?.client?.screen -= src
our_hud.mymob?.canon_client?.screen -= src
our_hud.palette_down = null
our_hud = null
return ..()
Expand All @@ -430,7 +427,7 @@ GLOBAL_LIST_INIT(palette_removed_matrix, list(1.4,0,0,0, 0.7,0.4,0,0, 0.4,0,0.6,

/atom/movable/screen/palette_scroll/up/Destroy()
if(our_hud)
our_hud.mymob?.client?.screen -= src
our_hud.mymob?.canon_client?.screen -= src
our_hud.palette_up = null
our_hud = null
return ..()
Expand All @@ -448,7 +445,7 @@ GLOBAL_LIST_INIT(palette_removed_matrix, list(1.4,0,0,0, 0.7,0.4,0,0, 0.4,0,0.6,
/atom/movable/screen/action_landing/Destroy()
if(owner)
owner.landing = null
owner?.owner?.mymob?.client?.screen -= src
owner?.owner?.mymob?.canon_client?.screen -= src
owner.refresh_actions()
owner = null
return ..()
Expand Down
55 changes: 21 additions & 34 deletions code/_onclick/hud/ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
icon = 'icons/hud/screen_ai.dmi'

/atom/movable/screen/ai/Click()
. = ..()
if(.)
return FALSE

if(isobserver(usr) || usr.incapacitated())
return TRUE

Expand Down Expand Up @@ -184,106 +188,89 @@
var/mob/living/silicon/ai/myai = mymob

// Language menu
using = new /atom/movable/screen/language_menu
using = new /atom/movable/screen/language_menu(null, src)
using.screen_loc = ui_ai_language_menu
using.hud = src
static_inventory += using

//AI core
using = new /atom/movable/screen/ai/aicore()
using = new /atom/movable/screen/ai/aicore(null, src)
using.screen_loc = ui_ai_core
using.hud = src
static_inventory += using

//Camera list
using = new /atom/movable/screen/ai/camera_list()
using = new /atom/movable/screen/ai/camera_list(null, src)
using.screen_loc = ui_ai_camera_list
using.hud = src
static_inventory += using

//Track
using = new /atom/movable/screen/ai/camera_track()
using = new /atom/movable/screen/ai/camera_track(null, src)
using.screen_loc = ui_ai_track_with_camera
using.hud = src
static_inventory += using

//Camera light
using = new /atom/movable/screen/ai/camera_light()
using = new /atom/movable/screen/ai/camera_light(null, src)
using.screen_loc = ui_ai_camera_light
using.hud = src
static_inventory += using

//Crew Monitoring
using = new /atom/movable/screen/ai/crew_monitor()
using = new /atom/movable/screen/ai/crew_monitor(null, src)
using.screen_loc = ui_ai_crew_monitor
using.hud = src
static_inventory += using

//Crew Manifest
using = new /atom/movable/screen/ai/crew_manifest()
using = new /atom/movable/screen/ai/crew_manifest(null, src)
using.screen_loc = ui_ai_crew_manifest
using.hud = src
static_inventory += using

//Alerts
using = new /atom/movable/screen/ai/alerts()
using = new /atom/movable/screen/ai/alerts(null, src)
using.screen_loc = ui_ai_alerts
using.hud = src
static_inventory += using

//Announcement
using = new /atom/movable/screen/ai/announcement()
using = new /atom/movable/screen/ai/announcement(null, src)
using.screen_loc = ui_ai_announcement
using.hud = src
static_inventory += using

//Shuttle
using = new /atom/movable/screen/ai/call_shuttle()
using = new /atom/movable/screen/ai/call_shuttle(null, src)
using.screen_loc = ui_ai_shuttle
using.hud = src
static_inventory += using

//Laws
using = new /atom/movable/screen/ai/state_laws()
using = new /atom/movable/screen/ai/state_laws(null, src)
using.screen_loc = ui_ai_state_laws
using.hud = src
static_inventory += using

// Modular Interface
using = new /atom/movable/screen/ai/modpc()
using = new /atom/movable/screen/ai/modpc(null, src)
using.screen_loc = ui_ai_mod_int
using.hud = src
static_inventory += using
myai.interfaceButton = using
var/atom/movable/screen/ai/modpc/tabletbutton = using
tabletbutton.robot = myai

//Take image
using = new /atom/movable/screen/ai/image_take()
using = new /atom/movable/screen/ai/image_take(null, src)
using.screen_loc = ui_ai_take_picture
using.hud = src
static_inventory += using

//View images
using = new /atom/movable/screen/ai/image_view()
using = new /atom/movable/screen/ai/image_view(null, src)
using.screen_loc = ui_ai_view_images
using.hud = src
static_inventory += using

//Medical/Security sensors
using = new /atom/movable/screen/ai/sensors()
using = new /atom/movable/screen/ai/sensors(null, src)
using.screen_loc = ui_ai_sensor
using.hud = src
static_inventory += using

//Multicamera mode
using = new /atom/movable/screen/ai/multicam()
using = new /atom/movable/screen/ai/multicam(null, src)
using.screen_loc = ui_ai_multicam
using.hud = src
static_inventory += using

//Add multicamera camera
using = new /atom/movable/screen/ai/add_multicam()
using = new /atom/movable/screen/ai/add_multicam(null, src)
using.screen_loc = ui_ai_add_multicam
using.hud = src
static_inventory += using
6 changes: 5 additions & 1 deletion code/_onclick/hud/alert.dm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
/// Boolean. If TRUE, the Click() proc will attempt to Click() on the master first if there is a master.
var/click_master = TRUE

/atom/movable/screen/alert/can_usr_use(mob/user)
return owner == usr

/atom/movable/screen/alert/MouseEntered(location,control,params)
. = ..()
Expand Down Expand Up @@ -871,8 +873,10 @@ or shoot a gun to move around via Newton's 3rd Law of Motion."
return 1

/atom/movable/screen/alert/Click(location, control, params)
if(!usr || !usr.client)
. = ..()
if(.)
return FALSE

if(usr != owner)
return FALSE
var/list/modifiers = params2list(params)
Expand Down
Loading

0 comments on commit 4dee479

Please sign in to comment.