Tgui list input hotfix + changes (#63515)

Previous issues addressed:

- You could not reselect search just by keying
- Pressing enter sometimes deselected
- Double click would deselect - which was intentional, but useless really
- Default values were not implemented in original
- Validation is required for tgui inputs but truly only one "needs" it, it costs performance otherwise

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
This commit is contained in:
Jeremiah
2021-12-25 11:37:05 +02:00
committed by GitHub
co-authored by Mothblocks
parent 6207f14e80
commit fe9bc91693
5 changed files with 113 additions and 73 deletions
+16 -7
View File
@@ -7,9 +7,10 @@
* * message - The content of the input box, shown in the body of the TGUI window.
* * title - The title of the input box, shown on the top of the TGUI window.
* * items - The options that can be chosen by the user, each string is assigned a button on the UI.
* * default - If an option is already preselected on the UI. Current values, etc.
* * timeout - The timeout of the input box, after which the menu will close and qdel itself. Set to zero for no timeout.
*/
/proc/tgui_input_list(mob/user, message, title = "Select", list/items, timeout = 0)
/proc/tgui_input_list(mob/user, message, title = "Select", list/items, default, timeout = 0)
if (!user)
user = usr
if(!length(items))
@@ -23,7 +24,7 @@
/// Client does NOT have tgui_input on: Returns regular input
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
return input(user, message, title) as null|anything in items
var/datum/tgui_list_input/input = new(user, message, title, items, timeout)
var/datum/tgui_list_input/input = new(user, message, title, items, default, timeout)
input.ui_interact(user)
input.wait()
if (input)
@@ -39,10 +40,11 @@
* * message - The content of the input box, shown in the body of the TGUI window.
* * title - The title of the input box, shown on the top of the TGUI window.
* * items - The options that can be chosen by the user, each string is assigned a button on the UI.
* * default - If an option is already preselected on the UI. Current values, etc.
* * callback - The callback to be invoked when a choice is made.
* * timeout - The timeout of the input box, after which the menu will close and qdel itself. Set to zero for no timeout.
*/
/proc/tgui_input_list_async(mob/user, message, title, list/items, datum/callback/callback, timeout = 60 SECONDS)
/proc/tgui_input_list_async(mob/user, message, title = "Select", list/items, default, datum/callback/callback, timeout = 60 SECONDS)
if (!user)
user = usr
if(!length(items))
@@ -53,7 +55,10 @@
user = client.mob
else
return
var/datum/tgui_list_input/async/input = new(user, message, title, items, callback, timeout)
/// Client does NOT have tgui_input on: Returns regular input
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
return input(user, message, title) as null|anything in items
var/datum/tgui_list_input/async/input = new(user, message, title, items, default, callback, timeout)
input.ui_interact(user)
/**
@@ -73,6 +78,8 @@
var/list/items_map
/// The button that the user has pressed, null if no selection has been made
var/choice
/// The default button to be selected
var/default
/// The time at which the tgui_list_input was created, for displaying timeout progress.
var/start_time
/// The lifespan of the tgui_list_input, after which the window will close and delete itself.
@@ -80,11 +87,12 @@
/// Boolean field describing if the tgui_list_input was closed by the user.
var/closed
/datum/tgui_list_input/New(mob/user, message, title, list/items, timeout)
/datum/tgui_list_input/New(mob/user, message, title, list/items, default, timeout)
src.title = title
src.message = message
src.items = list()
src.items_map = list()
src.default = default
var/list/repeat_items = list()
// Gets rid of illegal characters
@@ -136,6 +144,7 @@
/datum/tgui_list_input/ui_static_data(mob/user)
. = list(
"init_value" = default || items[1],
"items" = items,
"message" = message,
"preferences" = list(),
@@ -177,8 +186,8 @@
/// The callback to be invoked by the tgui_list_input upon having a choice made.
var/datum/callback/callback
/datum/tgui_list_input/async/New(mob/user, message, title, list/items, callback, timeout)
..(user, message, title, items, timeout)
/datum/tgui_list_input/async/New(mob/user, message, title, list/items, default, callback, timeout)
..(user, message, title, items, default, timeout)
src.callback = callback
/datum/tgui_list_input/async/Destroy(force, ...)
+8 -5
View File
@@ -14,7 +14,7 @@
* * min_value - Specifies a minimum value. Often 0.
* * timeout - The timeout of the number input, after which the modal will close and qdel itself. Set to zero for no timeout.
*/
/proc/tgui_input_number(mob/user, message = null, title = "Number Input", default = null, max_value = null, min_value = 0, timeout = 0)
/proc/tgui_input_number(mob/user, message, title = "Number Input", default, max_value, min_value, timeout = 0)
if (!user)
user = usr
if (!istype(user))
@@ -23,7 +23,7 @@
user = client.mob
else
return
/// Client does NOT have tgui_input on: Returns regular input
// Client does NOT have tgui_input on: Returns regular input
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
return input(user, message, title, default) as null|num
var/datum/tgui_input_number/number_input = new(user, message, title, default, max_value, min_value, timeout)
@@ -48,7 +48,7 @@
* * callback - The callback to be invoked when a choice is made.
* * timeout - The timeout of the number input, after which the modal will close and qdel itself. Set to zero for no timeout.
*/
/proc/tgui_input_number_async(mob/user, message = null, title = "Number Input", default = null, max_value = null, min_value = 0, datum/callback/callback, timeout = 60 SECONDS)
/proc/tgui_input_number_async(mob/user, message, title = "Number Input", default, max_value, min_value, datum/callback/callback, timeout = 60 SECONDS)
if (!user)
user = usr
if (!istype(user))
@@ -57,6 +57,9 @@
user = client.mob
else
return
// Client does NOT have tgui_input on: Returns regular input
if(!user.client.prefs.read_preference(/datum/preference/toggle/tgui_input))
return input(user, message, title, default) as null|num
var/datum/tgui_input_number/async/number_input = new(user, message, title, default, max_value, min_value, callback, timeout)
number_input.ui_interact(user)
@@ -126,10 +129,10 @@
/datum/tgui_input_number/ui_static_data(mob/user)
. = list(
"init_value" = default || 0, // Default is a reserved keyword
"max_value" = max_value,
"message" = message,
"min_value" = min_value,
"placeholder" = default, /// You cannot use default as a const
"min_value" = min_value || 0,
"preferences" = list(),
"title" = title
)