From 306b828631951377fac925960500c3f67d93ccbc Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 11 Aug 2023 20:42:44 +0200 Subject: [PATCH] [MIRROR] Polishing the greyscale modify menu's lackluster support for non-atom targets. [MDB IGNORE] (#22965) * Polishing the greyscale modify menu's lackluster support for non-atom targets. (#77322) ## About The Pull Request So, I've been recently told that Skyrat uses the greyscale modify menu for loadouts, and the new ui state kinda borked it. I honestly haven't taken the possibility that the target could be anything but a subtype of `/atom` (and still work) into account because much of the code assumes the target is an atom. It's kinda crappy. Also I hadn't noticed we've an `unlocked` variable, which makes `vv_mode` var superflous, so i'm going to remove the latter. * Polishing the greyscale modify menu's lackluster support for non-atom targets. * I hope I won't have to get back and edit out the ability to modify the alpha on clothes for this --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> Co-authored-by: GoldenAlpharex --- code/modules/admin/greyscale_modify_menu.dm | 64 +++++++++++++------ .../admin/view_variables/topic_basic.dm | 3 +- code/modules/tgui/states/greyscale_menu.dm | 3 + code/modules/vending/_vending.dm | 2 - .../loadouts/loadout_ui/loadout_manager.dm | 2 +- 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/code/modules/admin/greyscale_modify_menu.dm b/code/modules/admin/greyscale_modify_menu.dm index 0e707fe224f..554328524e0 100644 --- a/code/modules/admin/greyscale_modify_menu.dm +++ b/code/modules/admin/greyscale_modify_menu.dm @@ -2,7 +2,7 @@ /// If `Unlock()` is not called the menu is safe for players to use. /datum/greyscale_modify_menu /// The "owner" object of this menu, is usually the greyscale object being edited but that can be changed for specific uses of this menu - var/atom/target + var/datum/target /// The client that opened this menu var/client/user @@ -32,34 +32,48 @@ /// Whether the menu is in the middle of refreshing the preview var/refreshing = TRUE - /// Whether the menu is currently locked down to prevent abuse from players. Currently is only unlocked when opened from vv. + /** + * Whether the menu is currently locked down to prevent abuse from players. + * Currently is only unlocked when opened from vv. + * It also enables the user to modify the alpha channel of the colors. + */ var/unlocked = FALSE - /// If defined, the always state will be used, and the user will be able to set the alpha channel of the colors too. - var/vv_mode = FALSE - -/datum/greyscale_modify_menu/New(atom/target, client/user, list/allowed_configs, datum/callback/apply_callback, starting_icon_state="", starting_config, starting_colors, vv_mode = FALSE) +/datum/greyscale_modify_menu/New(datum/target, client/user, list/allowed_configs, datum/callback/apply_callback, starting_icon_state = "", starting_config, starting_colors, unlocked = FALSE) src.target = target + var/atom/atom_target + if(isatom(target)) + atom_target = target src.user = user - src.apply_callback = apply_callback || CALLBACK(src, PROC_REF(DefaultApply)) + src.apply_callback = apply_callback + if(!apply_callback) + if(atom_target) + src.apply_callback = CALLBACK(src, PROC_REF(DefaultApply)) + else + stack_trace("A geyscale modify menu was instantiated with a non-atom target and no specified apply callback (DefaultApply won't do).") + icon_state = starting_icon_state - src.vv_mode = vv_mode SetupConfigOwner() - var/current_config = "[starting_config]" || "[target?.greyscale_config]" + + var/current_config = "[starting_config]" || "[atom_target?.greyscale_config]" var/datum/greyscale_config/new_config = SSgreyscale.configurations[current_config] if(!(current_config in allowed_configs)) new_config = SSgreyscale.configurations["[allowed_configs[pick(allowed_configs)]]"] change_config(new_config) - var/list/config_choices = list() - for(var/config_string in allowed_configs) - var/datum/greyscale_config/allowed_config = text2path("[config_string]") - config_choices[initial(allowed_config.name)] = config_string - src.allowed_configs = config_choices + if(unlocked) + Unlock() + else + var/list/config_choices = list() + for(var/config_string in allowed_configs) + var/datum/greyscale_config/allowed_config = text2path("[config_string]") + config_choices[initial(allowed_config.name)] = config_string - ReadColorsFromString(starting_colors || target?.greyscale_colors) + src.allowed_configs = config_choices + + ReadColorsFromString(starting_colors || atom_target?.greyscale_colors) if(target) RegisterSignal(target, COMSIG_QDELETING, PROC_REF(ui_close)) @@ -72,7 +86,7 @@ return ..() /datum/greyscale_modify_menu/ui_state(mob/user) - return vv_mode ? GLOB.always_state : GLOB.greyscale_menu_state + return unlocked ? GLOB.always_state : GLOB.greyscale_menu_state /datum/greyscale_modify_menu/ui_close() qdel(src) @@ -139,7 +153,7 @@ if("recolor") var/index = text2num(params["color_index"]) var/new_color = lowertext(params["new_color"]) - if(split_colors[index] != new_color && (findtext(new_color, GLOB.is_color) || (vv_mode && findtext(new_color, GLOB.is_alpha_color)))) + if(split_colors[index] != new_color && (findtext(new_color, GLOB.is_color) || (unlocked && findtext(new_color, GLOB.is_alpha_color)))) split_colors[index] = new_color queue_refresh() @@ -229,7 +243,7 @@ This is highly likely to cause massive amounts of lag as every object in the gam var/list/colors = splittext(colorString, "#") for(var/index in 2 to length(colors)) var/color = "#[colors[index]]" - if(!findtext(color, GLOB.is_color) && (!vv_mode || !findtext(color, GLOB.is_alpha_color))) + if(!findtext(color, GLOB.is_color) && (!unlocked || !findtext(color, GLOB.is_alpha_color))) return FALSE new_split_colors += color split_colors = new_split_colors @@ -265,8 +279,12 @@ This is highly likely to cause massive amounts of lag as every object in the gam sprite_data["icon_states"] = generated_icon_states if(!(icon_state in generated_icon_states)) - icon_state = target.icon_state - if(!(icon_state in generated_icon_states)) + if(isatom(target)) + var/atom/atom_target = target + icon_state = atom_target.icon_state + if(!(icon_state in generated_icon_states)) + icon_state = pick(generated_icon_states) + else icon_state = pick(generated_icon_states) var/image/finished @@ -304,10 +322,14 @@ This is highly likely to cause massive amounts of lag as every object in the gam unlocked = TRUE /datum/greyscale_modify_menu/proc/DefaultApply() - target.set_greyscale(split_colors, config.type) + var/atom/atom_target = target + atom_target.set_greyscale(split_colors, config.type) /// Gets the top level type that first uses the configuration in this type path /datum/greyscale_modify_menu/proc/SetupConfigOwner() + if(!isatom(target)) + return + var/atom/current = target.type var/atom/parent = target.parent_type if(!initial(current.greyscale_config)) diff --git a/code/modules/admin/view_variables/topic_basic.dm b/code/modules/admin/view_variables/topic_basic.dm index 9804b3ed88b..96500de5070 100644 --- a/code/modules/admin/view_variables/topic_basic.dm +++ b/code/modules/admin/view_variables/topic_basic.dm @@ -140,8 +140,7 @@ if(href_list[VV_HK_MODIFY_GREYSCALE]) if(!check_rights(NONE)) return - var/datum/greyscale_modify_menu/menu = new(target, usr, SSgreyscale.configurations, vv_mode = TRUE) - menu.Unlock() + var/datum/greyscale_modify_menu/menu = new(target, usr, SSgreyscale.configurations, unlocked = TRUE) menu.ui_interact(usr) if(href_list[VV_HK_CALLPROC]) usr.client.callproc_datum(target) diff --git a/code/modules/tgui/states/greyscale_menu.dm b/code/modules/tgui/states/greyscale_menu.dm index 58936f807d9..9de6140e709 100644 --- a/code/modules/tgui/states/greyscale_menu.dm +++ b/code/modules/tgui/states/greyscale_menu.dm @@ -8,4 +8,7 @@ GLOBAL_DATUM_INIT(greyscale_menu_state, /datum/ui_state/greyscale_menu_state, ne /datum/ui_state/greyscale_menu_state/can_use_topic(src_object, mob/user) var/datum/greyscale_modify_menu/menu = src_object + if(!isatom(menu.target)) + return TRUE + return GLOB.default_state.can_use_topic(menu.target, user) diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index 48d12c926c5..909e00bcc1c 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -1212,8 +1212,6 @@ /obj/machinery/vending/proc/vend_greyscale(list/params, datum/greyscale_modify_menu/menu) if(usr != menu.user) return - if(!menu.target.can_interact(usr)) - return vend(params, menu.split_colors) /obj/machinery/vending/proc/vend(list/params, list/greyscale_colors) diff --git a/modular_skyrat/modules/loadouts/loadout_ui/loadout_manager.dm b/modular_skyrat/modules/loadouts/loadout_ui/loadout_manager.dm index 28e4b846648..d705ca95758 100644 --- a/modular_skyrat/modules/loadouts/loadout_ui/loadout_manager.dm +++ b/modular_skyrat/modules/loadouts/loadout_ui/loadout_manager.dm @@ -176,7 +176,7 @@ starting_icon_state = initial(colored_item.icon_state), starting_config = initial(colored_item.greyscale_config), starting_colors = slot_starting_colors, - vv_mode = TRUE, + unlocked = TRUE, ) RegisterSignal(menu, COMSIG_PREQDELETED, TYPE_PROC_REF(/datum/loadout_manager, cleanup_greyscale_menu)) menu.ui_interact(usr)