mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-22 04:24:20 +01:00
Adds Bitfields to the VV menu (#27266)
* Adds Bitfields to the VV menu * oops * fixed * oops * woo --------- Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Creates a TGUI input list window and returns the user's response in a ranked order.
|
||||
*
|
||||
* Arguments:
|
||||
* * user - The user to show the input box to.
|
||||
* * 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_checkbox_list(mob/user, message, title = "Select", list/items, default, timeout = 0, ui_state = GLOB.always_state)
|
||||
if(!user)
|
||||
user = usr
|
||||
|
||||
if(!length(items))
|
||||
CRASH("[user] tried to open an empty TGUI Input Checkbox List. Contents are: [items]")
|
||||
|
||||
if(!istype(user))
|
||||
if(!isclient(user))
|
||||
CRASH("We passed something that wasn't a user/client in a TGUI Input Checkbox List! The passed user was [user]!")
|
||||
var/client/client = user
|
||||
user = client.mob
|
||||
|
||||
if(isnull(user.client))
|
||||
return
|
||||
|
||||
var/datum/tgui_list_input/checkbox/input = new(user, message, title, items, default, timeout, ui_state)
|
||||
|
||||
if(input.invalid)
|
||||
qdel(input)
|
||||
return
|
||||
|
||||
input.ui_interact(user)
|
||||
input.wait()
|
||||
if(input)
|
||||
. = input.choice
|
||||
qdel(input)
|
||||
|
||||
/**
|
||||
* # tgui_list_input/ranked
|
||||
*
|
||||
* Datum used for allowing a user to sort a TGUI-controlled list input that prompts the user with
|
||||
* a message and shows a list of rankable options
|
||||
*/
|
||||
/datum/tgui_list_input/checkbox
|
||||
modal_type = "CheckboxListInputModal"
|
||||
|
||||
/datum/tgui_list_input/checkbox/handle_new_items(list/_items)
|
||||
var/list/repeat_items = list()
|
||||
// Gets rid of illegal characters
|
||||
var/static/regex/blacklisted_words = regex(@{"([^\u0020-\u8000]+)"})
|
||||
|
||||
for(var/key in _items)
|
||||
var/string_key = blacklisted_words.Replace("[key]", "")
|
||||
|
||||
// Avoids duplicated keys E.g: when areas have the same name
|
||||
string_key = avoid_assoc_duplicate_keys(string_key, repeat_items)
|
||||
src.items += list(list(
|
||||
"key" = string_key,
|
||||
"checked" = (_items[key] ? TRUE : FALSE)
|
||||
))
|
||||
src.items_map = _items // we use this differently
|
||||
|
||||
/datum/tgui_list_input/checkbox/handle_submit_action(params)
|
||||
var/list/associated = list()
|
||||
for(var/list/sublist in params["entry"])
|
||||
associated[sublist["key"]] = (sublist["checked"] in list(1, "1", "true"))
|
||||
|
||||
if(!lists_equal_unordered(associated, items_map))
|
||||
return FALSE
|
||||
set_choice(associated)
|
||||
return TRUE
|
||||
|
||||
|
||||
@@ -76,25 +76,15 @@
|
||||
/// The TGUI modal to use for this popup
|
||||
var/modal_type = "ListInputModal"
|
||||
|
||||
/datum/tgui_list_input/New(mob/user, message, title, list/items, default, timeout, ui_state)
|
||||
/datum/tgui_list_input/New(mob/user, message, title, list/_items, default, timeout, ui_state)
|
||||
src.title = title
|
||||
src.message = message
|
||||
src.items = list()
|
||||
src.items_map = list()
|
||||
src.default = default
|
||||
src.state = ui_state
|
||||
var/list/repeat_items = list()
|
||||
|
||||
// Gets rid of illegal characters
|
||||
var/static/regex/whitelistedWords = regex(@{"([^\u0020-\u8000]+)"})
|
||||
|
||||
for(var/i in items)
|
||||
var/string_key = whitelistedWords.Replace("[i]", "")
|
||||
|
||||
// Avoids duplicated keys E.g: when areas have the same name
|
||||
string_key = avoid_assoc_duplicate_keys(string_key, repeat_items)
|
||||
src.items += string_key
|
||||
src.items_map[string_key] = i
|
||||
handle_new_items(_items)
|
||||
|
||||
if(length(src.items) == 0)
|
||||
invalid = TRUE
|
||||
@@ -173,3 +163,16 @@
|
||||
|
||||
/datum/tgui_list_input/proc/set_choice(choice)
|
||||
src.choice = choice
|
||||
|
||||
/datum/tgui_list_input/proc/handle_new_items(list/_items)
|
||||
var/list/repeat_items = list()
|
||||
// Gets rid of illegal characters
|
||||
var/static/regex/blacklisted_words = regex(@{"([^\u0020-\u8000]+)"})
|
||||
|
||||
for(var/i in items)
|
||||
var/string_key = blacklisted_words.Replace("[i]", "")
|
||||
|
||||
// Avoids duplicated keys E.g: when areas have the same name
|
||||
string_key = avoid_assoc_duplicate_keys(string_key, repeat_items)
|
||||
src.items += string_key
|
||||
src.items_map[string_key] = i
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Creates a TGUI input list window and returns the user's response.
|
||||
* Creates a TGUI ranked input list window and returns the user's response in a ranked order.
|
||||
*
|
||||
* This proc should be used to create alerts that the caller will wait for a response from.
|
||||
* Arguments:
|
||||
* * user - The user to show the input box to.
|
||||
* * message - The content of the input box, shown in the body of the TGUI window.
|
||||
@@ -15,11 +14,11 @@
|
||||
user = usr
|
||||
|
||||
if(!length(items))
|
||||
CRASH("[user] tried to open an empty TGUI Input List. Contents are: [items]")
|
||||
CRASH("[user] tried to open an empty TGUI Input Ranked List. Contents are: [items]")
|
||||
|
||||
if(!istype(user))
|
||||
if(!isclient(user))
|
||||
CRASH("We passed something that wasn't a user/client in a TGUI Input List! The passed user was [user]!")
|
||||
CRASH("We passed something that wasn't a user/client in a TGUI Input Ranked List! The passed user was [user]!")
|
||||
var/client/client = user
|
||||
user = client.mob
|
||||
|
||||
|
||||
Reference in New Issue
Block a user