[MIRROR] List pick component [MDB IGNORE] (#18811)

List pick component (#72097)

## About The Pull Request

Adds a new component to let a user pick from a list. and pass the picked
value as a result.

The player most be adjescent to the connected circuit for this to work.

## Why It's Good For The Game

You can do similar thing through voice activation, but this is honestly
way easier for normal players to use instead of knowing "magic words" or
having the circuit say all the options and copy pasting.


![showcircuit](https://user-images.githubusercontent.com/36102060/208455809-f18af1ff-1d29-4d61-a546-5faf245654f8.gif)


## Changelog
🆑
add: New circuit component, list pick!
/🆑

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>

Co-authored-by: Autisem <36102060+Autisem@users.noreply.github.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-01-19 15:31:21 -05:00
committed by GitHub
co-authored by Mothblocks Jeremiah Autisem
parent 4102b5c67b
commit 92cb29c361
3 changed files with 110 additions and 0 deletions
@@ -0,0 +1,25 @@
/**
* # associative List pick component
*
* Allows user to select 1 entry from a list
* For actuel code refer to code\modules\wiremod\components\list\list_pick.dm
*/
/obj/item/circuit_component/list_pick/assoc
display_name = "Associative List Pick"
desc = "A component that lets a user pick 1 element from an associative list. Returns the selected element."
category = "List"
/obj/item/circuit_component/list_pick/assoc/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/list_pick/assoc/make_list_port()
input_list = add_input_port("List", PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, PORT_TYPE_LIST(PORT_TYPE_ANY)))
/obj/item/circuit_component/list_pick/assoc/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_type = list_options.value
input_list.set_datatype(PORT_TYPE_ASSOC_LIST(PORT_TYPE_STRING, new_type))
output.set_datatype(new_type)
@@ -0,0 +1,83 @@
/**
* # 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
var/index_type = PORT_TYPE_NUMBER
/obj/item/circuit_component/list_pick/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/list_pick/proc/make_list_port()
input_list = add_input_port("List", PORT_TYPE_LIST(PORT_TYPE_ANY))
/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_ATOM)
make_list_port()
output = add_output_port("Picked Item", PORT_TYPE_NUMBER)
trigger_output = add_output_port("Triggered", PORT_TYPE_SIGNAL)
failure = add_output_port("On Failure", PORT_TYPE_SIGNAL)
success = add_output_port("On Succes", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/list_pick/pre_input_received(datum/port/input/port)
if(port == list_options)
var/new_type = list_options.value
input_list.set_datatype(PORT_TYPE_LIST(new_type))
output.set_datatype(new_type)
/obj/item/circuit_component/list_pick/input_received(datum/port/input/port)
if(parent.Adjacent(user.value))
return
if(ismob(user.value))
trigger_output.set_output(COMPONENT_SIGNAL)
INVOKE_ASYNC(src, PROC_REF(show_list), user.value, 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.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE)))
return
var/picked = tgui_input_list(user, message = message, items = showed_list)
if(!(user.canUseTopic(src, be_close = TRUE, no_dexterity = FALSE, no_tk = TRUE)))
return
if(picked)
output.set_output(picked)
success.set_output(COMPONENT_SIGNAL)
else
failure.set_output(COMPONENT_SIGNAL)