From 91fd0e9145ada508a35bb6a144620747b760ba75 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 5 Nov 2021 20:57:04 +0000 Subject: [PATCH] [MIRROR] Adds the color matrix editor [MDB IGNORE] (#9265) * tgui: Color matrix editor (#62413) * adds the color matrix editor * weakrefs and add_atom_color * a little ui polish * Adds the color matrix editor Co-authored-by: Y0SH1M4S73R --- code/__DEFINES/vv.dm | 2 + code/_globalvars/colorvars.dm | 1 + code/game/atoms.dm | 5 + .../view_variables/color_matrix_editor.dm | 129 ++++++++++++++++++ .../admin/view_variables/get_variables.dm | 11 +- icons/misc/colortest.dmi | Bin 0 -> 352 bytes tgstation.dme | 2 + .../tgui/interfaces/ColorMatrixEditor.js | 82 +++++++++++ 8 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 code/_globalvars/colorvars.dm create mode 100644 code/modules/admin/view_variables/color_matrix_editor.dm create mode 100644 icons/misc/colortest.dmi create mode 100644 tgui/packages/tgui/interfaces/ColorMatrixEditor.js diff --git a/code/__DEFINES/vv.dm b/code/__DEFINES/vv.dm index 87d53c152a1..cb38597f7b1 100644 --- a/code/__DEFINES/vv.dm +++ b/code/__DEFINES/vv.dm @@ -2,6 +2,7 @@ #define VV_TEXT "Text" #define VV_MESSAGE "Mutiline Text" #define VV_COLOR "Color" +#define VV_COLOR_MATRIX "Color Matrix" #define VV_ICON "Icon" #define VV_ATOM_REFERENCE "Atom Reference" #define VV_DATUM_REFERENCE "Datum Reference" @@ -89,6 +90,7 @@ #define VV_HK_TRIGGER_EXPLOSION "explode" #define VV_HK_AUTO_RENAME "auto_rename" #define VV_HK_EDIT_FILTERS "edit_filters" +#define VV_HK_EDIT_COLOR_MATRIX "edit_color_matrix" #define VV_HK_ADD_AI "add_ai" // /atom/movable diff --git a/code/_globalvars/colorvars.dm b/code/_globalvars/colorvars.dm new file mode 100644 index 00000000000..c49a3d90dfc --- /dev/null +++ b/code/_globalvars/colorvars.dm @@ -0,0 +1 @@ +GLOBAL_LIST_INIT(color_vars, list("color")) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 016bf6a2855..5c39503cd8e 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -1214,6 +1214,7 @@ VV_DROPDOWN_OPTION(VV_HK_TRIGGER_EMP, "EMP Pulse") VV_DROPDOWN_OPTION(VV_HK_TRIGGER_EXPLOSION, "Explosion") VV_DROPDOWN_OPTION(VV_HK_EDIT_FILTERS, "Edit Filters") + VV_DROPDOWN_OPTION(VV_HK_EDIT_COLOR_MATRIX, "Edit Color as Matrix") VV_DROPDOWN_OPTION(VV_HK_ADD_AI, "Add AI controller") if(greyscale_colors) VV_DROPDOWN_OPTION(VV_HK_MODIFY_GREYSCALE, "Modify greyscale colors") @@ -1308,6 +1309,10 @@ var/client/C = usr.client C?.open_filter_editor(src) + if(href_list[VV_HK_EDIT_COLOR_MATRIX] && check_rights(R_VAREDIT)) + var/client/C = usr.client + C?.open_color_matrix_editor(src) + /atom/vv_get_header() . = ..() var/refid = REF(src) diff --git a/code/modules/admin/view_variables/color_matrix_editor.dm b/code/modules/admin/view_variables/color_matrix_editor.dm new file mode 100644 index 00000000000..1f1634a284b --- /dev/null +++ b/code/modules/admin/view_variables/color_matrix_editor.dm @@ -0,0 +1,129 @@ +INITIALIZE_IMMEDIATE(/atom/movable/screen/color_matrix_proxy_view) + +/atom/movable/screen/color_matrix_proxy_view + name = "color_matrix_proxy_view" + del_on_map_removal = FALSE + layer = GAME_PLANE + plane = GAME_PLANE + + var/list/plane_masters = list() + + /// The client that is watching this view + var/client/client + +/atom/movable/screen/color_matrix_proxy_view/Initialize(mapload) + . = ..() + + assigned_map = "color_matrix_proxy_[REF(src)]" + set_position(1, 1) + +/atom/movable/screen/color_matrix_proxy_view/Destroy() + for (var/plane_master in plane_masters) + client?.screen -= plane_master + qdel(plane_master) + + client?.clear_map(assigned_map) + + client = null + plane_masters = null + + return ..() + +/atom/movable/screen/color_matrix_proxy_view/proc/register_to_client(client/client) + QDEL_LIST(plane_masters) + + src.client = client + + if (!client) + return + + for (var/plane_master_type in subtypesof(/atom/movable/screen/plane_master) - /atom/movable/screen/plane_master/blackness) + var/atom/movable/screen/plane_master/plane_master = new plane_master_type() + plane_master.screen_loc = "[assigned_map]:CENTER" + client?.screen |= plane_master + + plane_masters += plane_master + + client?.register_map_obj(src) + +/datum/color_matrix_editor + var/client/owner + var/datum/weakref/target + var/atom/movable/screen/color_matrix_proxy_view/proxy_view + var/list/current_color + var/closed + +/datum/color_matrix_editor/New(user, atom/_target = null) + owner = CLIENT_FROM_VAR(user) + if(islist(_target?.color)) + current_color = _target.color + else if(istext(_target?.color)) + current_color = color_hex2color_matrix(_target.color) + else + current_color = color_matrix_identity() + proxy_view = new + if(_target) + target = WEAKREF(_target) + proxy_view.appearance = image(_target) + else + proxy_view.appearance = image('icons/misc/colortest.dmi', "colors") + + proxy_view.color = current_color + proxy_view.register_to_client(owner) + +/datum/color_matrix_editor/Destroy(force, ...) + QDEL_NULL(proxy_view) + return ..() + +/datum/color_matrix_editor/ui_state(mob/user) + return GLOB.admin_state + +/datum/color_matrix_editor/ui_static_data(mob/user) + var/list/data = list() + data["mapRef"] = proxy_view.assigned_map + + return data + +/datum/color_matrix_editor/ui_data(mob/user) + var/list/data = list() + data["currentColor"] = current_color + + return data + +/datum/color_matrix_editor/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "ColorMatrixEditor") + ui.open() + +/datum/color_matrix_editor/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) + . = ..() + if(.) + return + switch(action) + if("transition_color") + current_color = params["color"] + animate(proxy_view, time = 4, color = current_color) + if("confirm") + on_confirm() + SStgui.close_uis(src) + +/datum/color_matrix_editor/ui_close(mob/user) + . = ..() + closed = TRUE + +/datum/color_matrix_editor/proc/on_confirm() + var/atom/target_atom = target?.resolve() + if(istype(target_atom)) + target_atom.add_atom_colour(current_color, ADMIN_COLOUR_PRIORITY) + +/datum/color_matrix_editor/proc/wait() + while(!closed) + stoplag(1) + +/client/proc/open_color_matrix_editor(atom/in_atom) + var/datum/color_matrix_editor/editor = new /datum/color_matrix_editor(src, in_atom) + editor.ui_interact(mob) + editor.wait() + . = editor.current_color + qdel(editor) diff --git a/code/modules/admin/view_variables/get_variables.dm b/code/modules/admin/view_variables/get_variables.dm index 57827f15230..2e9c0c75f03 100644 --- a/code/modules/admin/view_variables/get_variables.dm +++ b/code/modules/admin/view_variables/get_variables.dm @@ -40,7 +40,10 @@ . = VV_TYPE else if(islist(var_value)) - . = VV_LIST + if(var_name in GLOB.color_vars) + . = VV_COLOR_MATRIX + else + . = VV_LIST else if(isfile(var_value)) . = VV_FILE @@ -57,6 +60,7 @@ VV_MESSAGE, VV_ICON, VV_COLOR, + VV_COLOR_MATRIX, VV_ATOM_REFERENCE, VV_DATUM_REFERENCE, VV_MOB_REFERENCE, @@ -280,5 +284,10 @@ .["class"] = null return + if(VV_COLOR_MATRIX) + .["value"] = open_color_matrix_editor() + if(.["value"] == color_matrix_identity()) //identity is equivalent to null + .["class"] = null + if(VV_INFINITY) .["value"] = INFINITY diff --git a/icons/misc/colortest.dmi b/icons/misc/colortest.dmi new file mode 100644 index 0000000000000000000000000000000000000000..0f74685ebc24d90bc3227e01ec7cb9a06d785725 GIT binary patch literal 352 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=c~v11B`&GO$wiq3C7Jno3=9=> zRF7}uYETeiy>RopsQB&04!2?sakT$p_w-&UR1>uS{)IBX=E7NTxi&{sIX#?`pRr<_ z@<+9JWfL}6rM8kIzuH%?W|S&Aovx?j`6EO^%C>Xw4(&gA25Z^UHhy7@oh7yW_U>)r zK%3Wkx;TbZ%z1mmkn6C42p?6=yDxT%o>&amMexKRQDXe%te%A)LX%b|EiN z{A-IDkh~&%i-F;W+=G8Qb%&}CEG}k+XkcJifMn7=X0iYOAMRv=DrX4r&tL`y7SNmn a?-=Z-Zsv}B(s=|FmJFV*elF{r5}E)m#EDG+ literal 0 HcmV?d00001 diff --git a/tgstation.dme b/tgstation.dme index 299ca35310b..85bf2f075d4 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -294,6 +294,7 @@ #include "code\__HELPERS\~skyrat_helpers\unsorted.dm" #include "code\_globalvars\admin.dm" #include "code\_globalvars\bitfields.dm" +#include "code\_globalvars\colorvars.dm" #include "code\_globalvars\configuration.dm" #include "code\_globalvars\game_modes.dm" #include "code\_globalvars\genetics.dm" @@ -1796,6 +1797,7 @@ #include "code\modules\admin\verbs\SDQL2\SDQL_spells\spell_edit_menu.dm" #include "code\modules\admin\verbs\SDQL2\SDQL_spells\spells.dm" #include "code\modules\admin\view_variables\admin_delete.dm" +#include "code\modules\admin\view_variables\color_matrix_editor.dm" #include "code\modules\admin\view_variables\debug_variables.dm" #include "code\modules\admin\view_variables\filterrific.dm" #include "code\modules\admin\view_variables\get_variables.dm" diff --git a/tgui/packages/tgui/interfaces/ColorMatrixEditor.js b/tgui/packages/tgui/interfaces/ColorMatrixEditor.js new file mode 100644 index 00000000000..bcd6c7a2720 --- /dev/null +++ b/tgui/packages/tgui/interfaces/ColorMatrixEditor.js @@ -0,0 +1,82 @@ +import { useBackend } from '../backend'; +import { toFixed } from 'common/math'; +import { Box, Stack, Section, ByondUi, NumberInput, Button } from '../components'; +import { Window } from '../layouts'; + +export const ColorMatrixEditor = (props, context) => { + const { act, data } = useBackend(context); + const { mapRef, currentColor } = data; + const [ + [rr, rg, rb, ra], + [gr, gg, gb, ga], + [br, bg, bb, ba], + [ar, ag, ab, aa], + [cr, cg, cb, ca], + ] = currentColor; + const prefixes = ['r', 'g', 'b', 'a', 'c']; + return ( + + + + + + + +
+ + {[0, 1, 2, 3].map((col, key) => ( + + + {[0, 1, 2, 3, 4].map((row, key) => ( + + + {`${prefixes[row]}${prefixes[col]}:`} + + toFixed(value, 2)} + onDrag={(e, value) => { + let retColor = currentColor; + retColor[row*4+col] = value; + act("transition_color", { color: retColor }); + }} /> + + ))} + + + ))} + +
+
+ + + act("confirm")} /> + +
+
+ + + +
+
+
+ ); +};