Adds buttons in the UI for specific components (#61622)

Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
This commit is contained in:
Watermelon914
2021-09-25 03:50:15 -07:00
committed by GitHub
co-authored by Watermelon914
parent b463e0417e
commit 390f60f571
5 changed files with 65 additions and 16 deletions
+18
View File
@@ -51,6 +51,9 @@
// Defines which shells support this component. Only used as an informational guide, does not restrict placing these components in circuits.
var/required_shells = null
/// The UI buttons of this circuit component. An assoc list that has this format: "button_icon" = "action_name"
var/ui_buttons = null
/// Called when the option ports should be set up
/obj/item/circuit_component/proc/populate_options()
return
@@ -295,6 +298,16 @@
if(length(input_ports))
. += create_ui_notice("Power Usage Per Input: [power_usage_per_input]", "orange", "bolt")
/**
* Called when a special button is pressed on this component in the UI.
*
* Arguments:
* * user - Interacting mob
* * action - A string for which action is being performed. No parameters passed because it's only a button press.
*/
/obj/item/circuit_component/proc/ui_perform_action(mob/user, action)
return
/**
* Creates a UI notice entry to be used in get_ui_notices()
*
@@ -309,6 +322,11 @@
"color" = color,
))
/obj/item/circuit_component/ui_host(mob/user)
if(parent)
return parent.ui_host()
return ..()
/**
* Creates a table UI notice entry to be used in get_ui_notices()
*
@@ -316,6 +316,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
component_data["y"] = component.rel_y
component_data["removable"] = component.removable
component_data["color"] = component.ui_color
component_data["ui_buttons"] = component.ui_buttons
.["components"] += list(component_data)
.["variables"] = list()
@@ -380,7 +381,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
#define WITHIN_RANGE(id, table) (id >= 1 && id <= length(table))
/obj/item/integrated_circuit/ui_act(action, list/params)
/obj/item/integrated_circuit/ui_act(action, list/params, datum/tgui/ui)
. = ..()
if(.)
return
@@ -464,6 +465,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
if(port.datatype != PORT_TYPE_ATOM && port.datatype != PORT_TYPE_ANY)
return
var/obj/item/multitool/circuit/marker = usr.get_active_held_item()
// Let's admins upload marked datums to an entity port.
if(!istype(marker))
var/client/user = usr.client
if(!check_rights_for(user, R_VAREDIT))
@@ -573,6 +575,15 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
if("move_screen")
screen_x = text2num(params["screen_x"])
screen_y = text2num(params["screen_y"])
if("perform_action")
var/component_id = text2num(params["component_id"])
if(!WITHIN_RANGE(component_id, attached_components))
return
var/obj/item/circuit_component/component = attached_components[component_id]
component.ui_perform_action(ui.user, params["action_name"])
#undef WITHIN_RANGE
/obj/item/integrated_circuit/proc/clear_setter_or_getter(datum/source)
SIGNAL_HANDLER
@@ -586,8 +597,6 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit)
usb_cable.balloon_alert(user, "circuit needs to be in a compatible shell")
return COMSIG_CANCEL_USB_CABLE_ATTACK
#undef WITHIN_RANGE
/// Sets the display name that appears on the shell.
/obj/item/integrated_circuit/proc/set_display_name(new_name)
display_name = new_name