mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-21 21:17:44 +01:00
TGUI input box conversions 1 (#63313)
This commit is contained in:
@@ -23,9 +23,9 @@
|
||||
user = client.mob
|
||||
else
|
||||
return
|
||||
/// Client does NOT have tgui_fancy 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
|
||||
return input(user, message, title, default) as null|num
|
||||
var/datum/tgui_input_number/numbox = new(user, message, title, default, max_value, min_value, timeout)
|
||||
numbox.ui_interact(user)
|
||||
numbox.wait()
|
||||
@@ -147,9 +147,9 @@
|
||||
return
|
||||
switch(action)
|
||||
if("submit")
|
||||
if(max_value && (length(params["entry"]) > max_value))
|
||||
if(max_value && (params["entry"] > max_value))
|
||||
return FALSE
|
||||
if(min_value && (length(params["entry"]) < min_value))
|
||||
if(min_value && (params["entry"] < min_value))
|
||||
return FALSE
|
||||
set_entry(params["entry"])
|
||||
SStgui.close_uis(src)
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
* * message - The content of the textbox, shown in the body of the TGUI window.
|
||||
* * title - The title of the textbox modal, shown on the top of the TGUI window.
|
||||
* * default - The default (or current) value, shown as a placeholder.
|
||||
* * max_length - Specifies a max length for input.
|
||||
* * max_length - Specifies a max length for input. MAX_MESSAGE_LEN is default (1024)
|
||||
* * multiline - Bool that determines if the input box is much larger. Good for large messages, laws, etc.
|
||||
* * encode - Toggling this determines if input is filtered via html_encode. Setting this to FALSE gives raw input.
|
||||
* * timeout - The timeout of the textbox, after which the modal will close and qdel itself. Set to zero for no timeout.
|
||||
*/
|
||||
/proc/tgui_input_text(mob/user, message = null, title = "Text Input", default = null, max_length = null, multiline = FALSE, timeout = 0)
|
||||
/proc/tgui_input_text(mob/user, message = null, title = "Text Input", default = null, max_length = MAX_MESSAGE_LEN, multiline = FALSE, encode = TRUE, timeout = 0)
|
||||
if (!user)
|
||||
user = usr
|
||||
if (!istype(user))
|
||||
@@ -23,7 +24,7 @@
|
||||
user = client.mob
|
||||
else
|
||||
return
|
||||
/// Client does NOT have tgui_fancy 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))
|
||||
if(max_length)
|
||||
if(multiline)
|
||||
@@ -32,7 +33,7 @@
|
||||
return stripped_input(user, message, title, default, max_length)
|
||||
else
|
||||
return input(user, message, title, default)
|
||||
var/datum/tgui_input_text/textbox = new(user, message, title, default, max_length, multiline, timeout)
|
||||
var/datum/tgui_input_text/textbox = new(user, message, title, default, max_length, multiline, encode, timeout)
|
||||
textbox.ui_interact(user)
|
||||
textbox.wait()
|
||||
if (textbox)
|
||||
@@ -50,10 +51,11 @@
|
||||
* * default - The default (or current) value, shown as a placeholder.
|
||||
* * max_length - Specifies a max length for input.
|
||||
* * multiline - Bool that determines if the input box is much larger. Good for large messages, laws, etc.
|
||||
* * encode - If toggled, input is filtered via html_encode. Setting this to FALSE gives raw input.
|
||||
* * callback - The callback to be invoked when a choice is made.
|
||||
* * timeout - The timeout of the textbox, after which the modal will close and qdel itself. Disabled by default, can be set to seconds otherwise.
|
||||
*/
|
||||
/proc/tgui_input_text_async(mob/user, message = null, title = "Text Input", default = null, max_length = null, multiline = FALSE, datum/callback/callback, timeout = 0)
|
||||
/proc/tgui_input_text_async(mob/user, message = null, title = "Text Input", default = null, max_length = null, multiline = FALSE, encode = TRUE, datum/callback/callback, timeout = 0)
|
||||
if (!user)
|
||||
user = usr
|
||||
if (!istype(user))
|
||||
@@ -62,7 +64,7 @@
|
||||
user = client.mob
|
||||
else
|
||||
return
|
||||
var/datum/tgui_input_text/async/textbox = new(user, message, title, default, max_length, multiline, callback, timeout)
|
||||
var/datum/tgui_input_text/async/textbox = new(user, message, title, default, max_length, multiline, encode, callback, timeout)
|
||||
textbox.ui_interact(user)
|
||||
|
||||
/**
|
||||
@@ -76,6 +78,8 @@
|
||||
var/closed
|
||||
/// The default (or current) value, shown as a default.
|
||||
var/default
|
||||
/// Whether the input should be stripped using html_encode
|
||||
var/encode
|
||||
/// The entry that the user has return_typed in.
|
||||
var/entry
|
||||
/// The maximum length for text entry
|
||||
@@ -92,8 +96,9 @@
|
||||
var/title
|
||||
|
||||
|
||||
/datum/tgui_input_text/New(mob/user, message, title, default, max_length, multiline, timeout)
|
||||
/datum/tgui_input_text/New(mob/user, message, title, default, max_length, multiline, encode, timeout)
|
||||
src.default = default
|
||||
src.encode = encode
|
||||
src.max_length = max_length
|
||||
src.message = message
|
||||
src.multiline = multiline
|
||||
@@ -152,8 +157,11 @@
|
||||
return
|
||||
switch(action)
|
||||
if("submit")
|
||||
if(max_length && (length(params["entry"]) > max_length))
|
||||
return FALSE
|
||||
if(max_length)
|
||||
if(length(params["entry"]) > max_length)
|
||||
return FALSE
|
||||
if(encode && (length(html_encode(params["entry"])) > max_length))
|
||||
to_chat(usr, span_notice("Input uses special characters, thus reducing the maximum length."))
|
||||
set_entry(params["entry"])
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
@@ -163,7 +171,8 @@
|
||||
return TRUE
|
||||
|
||||
/datum/tgui_input_text/proc/set_entry(entry)
|
||||
src.entry = entry
|
||||
var/converted_entry = encode ? html_encode(entry) : entry
|
||||
src.entry = trim(converted_entry, max_length)
|
||||
|
||||
/**
|
||||
* # async tgui_input_text
|
||||
@@ -174,8 +183,8 @@
|
||||
/// The callback to be invoked by the tgui_input_text upon having a choice made.
|
||||
var/datum/callback/callback
|
||||
|
||||
/datum/tgui_input_text/async/New(mob/user, message, title, default, max_length, multiline, callback, timeout)
|
||||
..(user, message, title, default, max_length, multiline, timeout)
|
||||
/datum/tgui_input_text/async/New(mob/user, message, title, default, max_length, multiline, encode, callback, timeout)
|
||||
..(user, message, title, default, max_length, multiline, encode, timeout)
|
||||
src.callback = callback
|
||||
|
||||
/datum/tgui_input_text/async/Destroy(force, ...)
|
||||
|
||||
Reference in New Issue
Block a user