mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-12 07:33:34 +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:
@@ -65,14 +65,14 @@
|
||||
if(prompt != "Continue")
|
||||
return
|
||||
|
||||
default = vv_get_class(var_value)
|
||||
default = vv_get_class(variable, var_value)
|
||||
|
||||
if(isnull(default))
|
||||
to_chat(src, "Unable to determine variable type.")
|
||||
else
|
||||
to_chat(src, "Variable appears to be <b>[uppertext(default)]</b>.")
|
||||
|
||||
to_chat(src, "Variable contains: [var_value]")
|
||||
to_chat(src, "Variable contains: [translate_bitfield(default, variable, var_value)]")
|
||||
|
||||
if(default == VV_NUM)
|
||||
var/dir_text = ""
|
||||
@@ -89,7 +89,7 @@
|
||||
if(dir_text)
|
||||
to_chat(src, "If a direction, direction is: [dir_text]")
|
||||
|
||||
var/value = vv_get_value(default_class = default)
|
||||
var/value = vv_get_value(class = (default == VV_BITFIELD ? VV_BITFIELD : null), default_class = default, var_name = variable)
|
||||
var/new_value = value["value"]
|
||||
var/class = value["class"]
|
||||
|
||||
@@ -207,7 +207,7 @@
|
||||
|
||||
log_world("### MassVarEdit by [src]: [O.type] (A/R [accepted]/[rejected]) [variable]=[html_encode("[O.vars[variable]]")]([list2params(value)])")
|
||||
log_admin("[key_name(src)] mass modified [original_name]'s [variable] to [O.vars[variable]] (Type: [class]) ([accepted] objects modified)")
|
||||
message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [html_encode("[O.vars[variable]]")] (Type: [class]) ([accepted] objects modified)")
|
||||
message_admins("[key_name_admin(src)] mass modified [original_name]'s [variable] to [html_encode(translate_bitfield(default, variable, O.vars[variable]))] (Type: [class]) ([accepted] objects modified)")
|
||||
|
||||
/proc/get_all_of_type(T, subtypes = TRUE)
|
||||
var/list/typecache = list()
|
||||
|
||||
@@ -12,12 +12,15 @@ GLOBAL_PROTECT(VVckey_edit)
|
||||
GLOBAL_PROTECT(VVpixelmovement)
|
||||
GLOBAL_PROTECT(VVmaint_only)
|
||||
|
||||
/client/proc/vv_get_class(var_value)
|
||||
/client/proc/vv_get_class(var_name, var_value)
|
||||
if(isnull(var_value))
|
||||
. = VV_NULL
|
||||
|
||||
else if(isnum(var_value))
|
||||
. = VV_NUM
|
||||
if(var_name in GLOB.bitfields)
|
||||
. = VV_BITFIELD
|
||||
else
|
||||
. = VV_NUM
|
||||
|
||||
else if(istext(var_value))
|
||||
if(findtext(var_value, "\n"))
|
||||
@@ -61,7 +64,7 @@ GLOBAL_PROTECT(VVmaint_only)
|
||||
else
|
||||
. = VV_NULL
|
||||
|
||||
/client/proc/vv_get_value(class, default_class, current_value, list/restricted_classes, list/extra_classes, list/classes)
|
||||
/client/proc/vv_get_value(class, default_class, current_value, list/restricted_classes, list/extra_classes, list/classes, var_name)
|
||||
. = list("class" = class, "value" = null)
|
||||
if(!class)
|
||||
if(!classes)
|
||||
@@ -120,6 +123,11 @@ GLOBAL_PROTECT(VVmaint_only)
|
||||
.["class"] = null
|
||||
return
|
||||
|
||||
if(VV_BITFIELD)
|
||||
.["value"] = input_bitfield(usr, var_name, current_value)
|
||||
if(.["value"] == null)
|
||||
.["class"] = null
|
||||
return
|
||||
|
||||
if(VV_ATOM_TYPE)
|
||||
.["value"] = pick_closest_path(FALSE)
|
||||
@@ -451,7 +459,7 @@ GLOBAL_PROTECT(VVmaint_only)
|
||||
else
|
||||
variable = L[index]
|
||||
|
||||
default = vv_get_class(variable)
|
||||
default = vv_get_class(objectvar, variable)
|
||||
|
||||
to_chat(src, "Variable appears to be <b>[uppertext(default)]</b>.")
|
||||
|
||||
@@ -582,14 +590,14 @@ GLOBAL_PROTECT(VVmaint_only)
|
||||
|
||||
var_value = O.vars[variable]
|
||||
|
||||
var/default = vv_get_class(var_value)
|
||||
var/default = vv_get_class(variable, var_value)
|
||||
|
||||
if(isnull(default))
|
||||
to_chat(src, "Unable to determine variable type.")
|
||||
else
|
||||
to_chat(src, "Variable appears to be <b>[uppertext(default)]</b>.")
|
||||
|
||||
to_chat(src, "Variable contains: [var_value]")
|
||||
to_chat(src, "Variable contains: [translate_bitfield(default, variable, var_value)]")
|
||||
|
||||
if(default == VV_NUM)
|
||||
var/dir_text = ""
|
||||
@@ -611,7 +619,7 @@ GLOBAL_PROTECT(VVmaint_only)
|
||||
default = VV_MESSAGE
|
||||
class = default
|
||||
|
||||
var/list/value = vv_get_value(class, default, var_value, extra_classes = list(VV_LIST))
|
||||
var/list/value = vv_get_value(class, default, var_value, extra_classes = list(VV_LIST), var_name = variable)
|
||||
class = value["class"]
|
||||
|
||||
if(!class)
|
||||
@@ -645,5 +653,4 @@ GLOBAL_PROTECT(VVmaint_only)
|
||||
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_VAR_EDIT, args)
|
||||
log_world("### VarEdit by [src]: [O.type] [variable]=[html_encode("[var_new]")] (Type: [class])")
|
||||
log_admin("[key_name(src)] modified [original_name]'s [variable] to [var_new] (Type: [class])")
|
||||
var/msg = "[key_name_admin(src)] modified [original_name]'s [variable] to [html_encode("[var_new]")] (Type: [class])"
|
||||
message_admins(msg)
|
||||
message_admins("[key_name_admin(src)] modified [original_name]'s [variable] to [html_encode(translate_bitfield(default, variable, var_new))] (Type: [class])")
|
||||
|
||||
@@ -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