forked from ParadiseSS13/Paradise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Bitfields to the VV menu (ParadiseSS13#27266)
* Adds Bitfields to the VV menu * oops * fixed * oops * woo --------- Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
- Loading branch information
1 parent
0b79bc2
commit 9b2cd0a
Showing
12 changed files
with
347 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,95 @@ | ||
GLOBAL_LIST_INIT(bitfields, generate_bitfields()) | ||
|
||
/// Specifies a bitfield for smarter debugging | ||
/datum/bitfield | ||
/// The variable name that contains the bitfield | ||
var/variable | ||
/// An associative list of the readable flag and its true value | ||
var/list/flags | ||
|
||
/datum/bitfield/can_vv_delete() | ||
return FALSE | ||
|
||
/datum/bitfield/vv_edit_var(var_name, var_value) | ||
return FALSE // no. | ||
|
||
/// Turns /datum/bitfield subtypes into a list for use in debugging | ||
/proc/generate_bitfields() | ||
var/list/bitfields = list() | ||
for(var/_bitfield in subtypesof(/datum/bitfield)) | ||
var/datum/bitfield/bitfield = new _bitfield | ||
bitfields[bitfield.variable] = bitfield.flags | ||
return bitfields | ||
|
||
/proc/translate_bitfield(variable_type, variable_name, variable_value) | ||
if(variable_type != VV_BITFIELD) | ||
return variable_value | ||
|
||
var/list/flags = list() | ||
for(var/flag in GLOB.bitfields[variable_name]) | ||
if(variable_value & GLOB.bitfields[variable_name][flag]) | ||
flags += flag | ||
if(length(flags)) | ||
return jointext(flags, ", ") | ||
return "NONE" | ||
|
||
/proc/input_bitfield(mob/user, bitfield, current_value) | ||
if(!user || !(bitfield in GLOB.bitfields)) | ||
return | ||
var/list/currently_checked = list() | ||
for(var/name in GLOB.bitfields[bitfield]) | ||
currently_checked[name] = (current_value & GLOB.bitfields[bitfield][name]) | ||
|
||
var/list/result = tgui_input_checkbox_list(user, "Editing bitfield for [bitfield].", "Editing bitfield", currently_checked) | ||
if(isnull(result) || !islist(result)) | ||
return | ||
|
||
var/new_result = 0 | ||
for(var/name in GLOB.bitfields[bitfield]) | ||
if(result[name]) | ||
new_result |= GLOB.bitfields[bitfield][name] | ||
return new_result | ||
|
||
// MARK: Default byond bitfields | ||
|
||
DEFINE_BITFIELD(appearance_flags, list( | ||
"KEEP_APART" = KEEP_APART, | ||
"KEEP_TOGETHER" = KEEP_TOGETHER, | ||
"LONG_GLIDE" = LONG_GLIDE, | ||
"NO_CLIENT_COLOR" = NO_CLIENT_COLOR, | ||
"PIXEL_SCALE" = PIXEL_SCALE, | ||
"PLANE_MASTER" = PLANE_MASTER, | ||
"RESET_ALPHA" = RESET_ALPHA, | ||
"RESET_COLOR" = RESET_COLOR, | ||
"RESET_TRANSFORM" = RESET_TRANSFORM, | ||
"TILE_BOUND" = TILE_BOUND, | ||
"PASS_MOUSE" = PASS_MOUSE, | ||
"TILE_MOVER" = TILE_MOVER, | ||
)) | ||
|
||
DEFINE_BITFIELD(sight, list( | ||
"BLIND" = BLIND, | ||
"SEE_BLACKNESS" = SEE_BLACKNESS, | ||
"SEE_INFRA" = SEE_INFRA, | ||
"SEE_MOBS" = SEE_MOBS, | ||
"SEE_OBJS" = SEE_OBJS, | ||
"SEE_PIXELS" = SEE_PIXELS, | ||
"SEE_SELF" = SEE_SELF, | ||
"SEE_THRU" = SEE_THRU, | ||
"SEE_TURFS" = SEE_TURFS, | ||
)) | ||
|
||
DEFINE_BITFIELD(vis_flags, list( | ||
"VIS_HIDE" = VIS_HIDE, | ||
"VIS_INHERIT_DIR" = VIS_INHERIT_DIR, | ||
"VIS_INHERIT_ICON" = VIS_INHERIT_ICON, | ||
"VIS_INHERIT_ICON_STATE" = VIS_INHERIT_ICON_STATE, | ||
"VIS_INHERIT_ID" = VIS_INHERIT_ID, | ||
"VIS_INHERIT_LAYER" = VIS_INHERIT_LAYER, | ||
"VIS_INHERIT_PLANE" = VIS_INHERIT_PLANE, | ||
"VIS_UNDERLAY" = VIS_UNDERLAY, | ||
)) | ||
|
||
|
||
// MARK: Other bitfields | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.