Files
Bubberstation/code/modules/wiremod/components/list/list_pick.dm
SkyratBot 2b5cfd484f [MIRROR] Adds a user type to integrated circuits, refactors the list pick component. [MDB IGNORE] (#24827)
* Adds a user type to integrated circuits, refactors the list pick component. (#79412)

## About The Pull Request
Added a user type to integrated circuits that can't be stored as a user
type but can be typecasted to entity. Useful for components that
directly ask for an input from the user, like the list pick component.

Refactored the list pick component to use this user port and to also
send failure signals whenever a success signal is not sent.
Removed the triggered port for the list pick component.

Also fixes a runtime that occurs with the list pick component if the
list passed in only contains null values.

## Why It's Good For The Game
Can't force a prompt onto people who haven't interacted with your
circuit.

## Changelog
🆑
add: Added a user type to integrated circuits
/🆑

---------

Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>

* Adds a user type to integrated circuits, refactors the list pick component.

---------

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>
2023-11-06 21:21:54 -05:00

79 lines
2.6 KiB
Plaintext

/**
* # List pick component
*
* Allows user to select 1 entry from a list
*/
/obj/item/circuit_component/list_pick
display_name = "List Pick"
desc = "A component that lets a user pick 1 element from a list. Returns the selected element."
category = "List"
/// The data type of the input_list
var/datum/port/input/option/list_options
/// The list that will be shown to the user
var/datum/port/input/input_list
/// The user to show the list too
var/datum/port/input/user
/// Name passed onto the TGUI(gives the UI a name)
var/datum/port/input/input_name
/// What was picked from input_list
var/datum/port/output/output
/// A value was picked
var/datum/port/output/success
/// Either it was canceld or out of range
var/datum/port/output/failure
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
/obj/item/circuit_component/list_pick/proc/make_list_port()
input_list = add_input_port("List", PORT_TYPE_LIST(PORT_TYPE_STRING))
/obj/item/circuit_component/list_pick/populate_ports()
input_name = add_input_port("Input Name", PORT_TYPE_STRING)
user = add_input_port("User", PORT_TYPE_USER)
make_list_port()
output = add_output_port("Picked Item", PORT_TYPE_STRING)
failure = add_output_port("On Failure", PORT_TYPE_SIGNAL)
success = add_output_port("On Success", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/list_pick/input_received(datum/port/input/port)
var/mob/mob_user = user.value
if(!ismob(mob_user) || HAS_TRAIT_FROM(parent, TRAIT_CIRCUIT_UI_OPEN, REF(mob_user)))
failure.set_output(COMPONENT_SIGNAL)
return
INVOKE_ASYNC(src, PROC_REF(show_list), mob_user, input_name.value, input_list.value)
/// Show a list of options to the user using standed TGUI input list
/obj/item/circuit_component/list_pick/proc/show_list(mob/user, message, list/showed_list)
if(!showed_list || showed_list.len == 0)
failure.set_output(COMPONENT_SIGNAL)
return
if(!message)
message = "circuit input"
if(!(user.can_perform_action(parent.shell, FORBID_TELEKINESIS_REACH|ALLOW_SILICON_REACH|ALLOW_RESTING)))
failure.set_output(COMPONENT_SIGNAL)
return
var/user_ref = REF(user)
ADD_TRAIT(parent, TRAIT_CIRCUIT_UI_OPEN, user_ref)
var/picked = tgui_input_list(user, message = message, items = showed_list)
REMOVE_TRAIT(parent, TRAIT_CIRCUIT_UI_OPEN, user_ref)
if(QDELETED(src))
return
if(!(user.can_perform_action(parent.shell, FORBID_TELEKINESIS_REACH|ALLOW_SILICON_REACH|ALLOW_RESTING)))
failure.set_output(COMPONENT_SIGNAL)
return
choose_item(picked, showed_list)
/obj/item/circuit_component/list_pick/proc/choose_item(choice, list/choice_list)
if(choice)
output.set_output(choice)
success.set_output(COMPONENT_SIGNAL)
else
failure.set_output(COMPONENT_SIGNAL)