mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-25 04:57:47 +01:00
fixes one of my first ever coding sins here (#18412)
* fixes one of my first ever coding sins here make it explicit naming fix that ancient bug too confirm sane . . move it up better keep it there only color objects . properly reset on bad values . urg . * , --------- Co-authored-by: Cameron Lennox <killer65311@gmail.com>
This commit is contained in:
co-authored by
Cameron Lennox
parent
054345cd87
commit
b0a8bfaec6
@@ -508,8 +508,8 @@
|
||||
if(!user)
|
||||
return
|
||||
if(!values)
|
||||
values = list(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
|
||||
if(values.len < 12)
|
||||
values = DEFAULT_COLORMATRIX
|
||||
if(length(values) < 12)
|
||||
values.len = 12
|
||||
var/list/output = list()
|
||||
output += "<form><input type='hidden' name='src' value='[REF(src)]'>"
|
||||
@@ -580,8 +580,13 @@
|
||||
var/client/C = user
|
||||
user = C.mob
|
||||
else
|
||||
return
|
||||
return null
|
||||
|
||||
var/datum/browser/modal/color_matrix_picker/B = new(user, message, title, button1, button2, button3, stealfocus, timeout, values)
|
||||
B.open()
|
||||
B.wait()
|
||||
return list("button" = B.selected_button, "matrix" = B.color_matrix)
|
||||
if(B.selected_button == 3 || !B.selected_button)
|
||||
return values
|
||||
if((B.selected_button == 2) || !islist(B.color_matrix) || !ISINRANGE(length(B.color_matrix), 9, 20))
|
||||
return list()
|
||||
return B.color_matrix
|
||||
|
||||
@@ -1,223 +0,0 @@
|
||||
/datum/ColorMate
|
||||
var/name = "colouring"
|
||||
var/atom/movable/inserted
|
||||
var/activecolor = "#FFFFFF"
|
||||
var/list/color_matrix_last
|
||||
var/active_mode = COLORMATE_HSV
|
||||
|
||||
var/build_hue = 0
|
||||
var/build_sat = 1
|
||||
var/build_val = 1
|
||||
|
||||
/// Minimum lightness for normal mode
|
||||
var/minimum_normal_lightness = 50
|
||||
/// Minimum lightness for matrix mode, tested using 4 test colors of full red, green, blue, white.
|
||||
var/minimum_matrix_lightness = 75
|
||||
/// Minimum matrix tests that must pass for something to be considered a valid color (see above)
|
||||
var/minimum_matrix_tests = 2
|
||||
/// Temporary messages
|
||||
var/temp
|
||||
|
||||
/datum/ColorMate/New(mob/user)
|
||||
color_matrix_last = list(
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1,
|
||||
0, 0, 0,
|
||||
)
|
||||
if(istype(user))
|
||||
inserted = user
|
||||
. = ..()
|
||||
|
||||
/datum/ColorMate/Destroy()
|
||||
inserted = null
|
||||
. = ..()
|
||||
|
||||
/datum/ColorMate/tgui_interact(mob/user, datum/tgui/ui)
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
if(!ui)
|
||||
ui = new(user, src, "ColorMate", src.name)
|
||||
ui.set_autoupdate(FALSE) //This might be a bit intensive, better to not update it every few ticks
|
||||
ui.open()
|
||||
|
||||
/datum/ColorMate/tgui_state(mob/user)
|
||||
return GLOB.tgui_conscious_state
|
||||
|
||||
/datum/ColorMate/tgui_data(mob/user)
|
||||
. = list()
|
||||
.["activemode"] = active_mode
|
||||
.["matrixcolors"] = list(
|
||||
"rr" = color_matrix_last[1],
|
||||
"rg" = color_matrix_last[2],
|
||||
"rb" = color_matrix_last[3],
|
||||
"gr" = color_matrix_last[4],
|
||||
"gg" = color_matrix_last[5],
|
||||
"gb" = color_matrix_last[6],
|
||||
"br" = color_matrix_last[7],
|
||||
"bg" = color_matrix_last[8],
|
||||
"bb" = color_matrix_last[9],
|
||||
"cr" = color_matrix_last[10],
|
||||
"cg" = color_matrix_last[11],
|
||||
"cb" = color_matrix_last[12],
|
||||
)
|
||||
.["buildhue"] = build_hue
|
||||
.["buildsat"] = build_sat
|
||||
.["buildval"] = build_val
|
||||
if(temp)
|
||||
.["temp"] = temp
|
||||
if(inserted)
|
||||
.["item"] = list()
|
||||
.["item"]["name"] = inserted.name
|
||||
.["item"]["sprite"] = icon2base64(get_flat_icon(inserted,dir=SOUTH,no_anim=TRUE))
|
||||
.["item"]["preview"] = icon2base64(build_preview(user))
|
||||
else
|
||||
.["item"] = null
|
||||
|
||||
/datum/ColorMate/tgui_act(action, params)
|
||||
. = ..()
|
||||
if(.)
|
||||
return
|
||||
if(inserted)
|
||||
switch(action)
|
||||
if("switch_modes")
|
||||
active_mode = text2num(params["mode"])
|
||||
return TRUE
|
||||
if("choose_color")
|
||||
var/chosen_color = tgui_color_picker(inserted, "Choose a color: ", "ColorMate colour picking", activecolor)
|
||||
if(chosen_color)
|
||||
activecolor = chosen_color
|
||||
return TRUE
|
||||
if("paint")
|
||||
do_paint(inserted)
|
||||
temp = "Painted Successfully!"
|
||||
if(isanimal(inserted))
|
||||
var/mob/living/simple_mob/M = inserted
|
||||
M.has_recoloured = TRUE
|
||||
if(isrobot(inserted))
|
||||
var/mob/living/silicon/robot/R = inserted
|
||||
R.has_recoloured = TRUE
|
||||
Destroy()
|
||||
if("drop")
|
||||
temp = ""
|
||||
Destroy()
|
||||
if("clear")
|
||||
inserted.remove_atom_colour(FIXED_COLOUR_PRIORITY)
|
||||
playsound(src, 'sound/effects/spray3.ogg', 50, 1)
|
||||
temp = "Cleared Successfully!"
|
||||
return TRUE
|
||||
if("set_matrix_color")
|
||||
color_matrix_last[params["color"]] = params["value"]
|
||||
return TRUE
|
||||
if("set_matrix_string")
|
||||
if(params["value"])
|
||||
var/list/colours = splittext(params["value"], ",")
|
||||
if(colours.len > 12)
|
||||
colours.Cut(13)
|
||||
for(var/i = 1, i <= colours.len, i++)
|
||||
var/number = text2num(colours[i])
|
||||
if(isnum(number))
|
||||
color_matrix_last[i] = clamp(number, -10, 10)
|
||||
return TRUE
|
||||
if("set_hue")
|
||||
build_hue = clamp(text2num(params["buildhue"]), 0, 360)
|
||||
return TRUE
|
||||
if("set_sat")
|
||||
build_sat = clamp(text2num(params["buildsat"]), -10, 10)
|
||||
return TRUE
|
||||
if("set_val")
|
||||
build_val = clamp(text2num(params["buildval"]), -10, 10)
|
||||
return TRUE
|
||||
|
||||
/datum/ColorMate/proc/do_paint(mob/user)
|
||||
var/color_to_use
|
||||
switch(active_mode)
|
||||
if(COLORMATE_TINT)
|
||||
color_to_use = activecolor
|
||||
if(COLORMATE_MATRIX)
|
||||
color_to_use = rgb_construct_color_matrix(
|
||||
text2num(color_matrix_last[1]),
|
||||
text2num(color_matrix_last[2]),
|
||||
text2num(color_matrix_last[3]),
|
||||
text2num(color_matrix_last[4]),
|
||||
text2num(color_matrix_last[5]),
|
||||
text2num(color_matrix_last[6]),
|
||||
text2num(color_matrix_last[7]),
|
||||
text2num(color_matrix_last[8]),
|
||||
text2num(color_matrix_last[9]),
|
||||
text2num(color_matrix_last[10]),
|
||||
text2num(color_matrix_last[11]),
|
||||
text2num(color_matrix_last[12]),
|
||||
)
|
||||
if(COLORMATE_HSV)
|
||||
color_to_use = color_matrix_hsv(build_hue, build_sat, build_val)
|
||||
color_matrix_last = color_to_use
|
||||
if(!color_to_use || !check_valid_color(color_to_use, user))
|
||||
to_chat(user, span_notice("Invalid color."))
|
||||
return FALSE
|
||||
inserted.add_atom_colour(color_to_use, FIXED_COLOUR_PRIORITY)
|
||||
playsound(src, 'sound/effects/spray3.ogg', 50, 1)
|
||||
return TRUE
|
||||
|
||||
/// Produces the preview image of the item, used in the UI, the way the color is not stacking is a sin.
|
||||
/datum/ColorMate/proc/build_preview(mob/user)
|
||||
if(inserted) //sanity
|
||||
var/list/cm
|
||||
switch(active_mode)
|
||||
if(COLORMATE_MATRIX)
|
||||
cm = rgb_construct_color_matrix(
|
||||
text2num(color_matrix_last[1]),
|
||||
text2num(color_matrix_last[2]),
|
||||
text2num(color_matrix_last[3]),
|
||||
text2num(color_matrix_last[4]),
|
||||
text2num(color_matrix_last[5]),
|
||||
text2num(color_matrix_last[6]),
|
||||
text2num(color_matrix_last[7]),
|
||||
text2num(color_matrix_last[8]),
|
||||
text2num(color_matrix_last[9]),
|
||||
text2num(color_matrix_last[10]),
|
||||
text2num(color_matrix_last[11]),
|
||||
text2num(color_matrix_last[12]),
|
||||
)
|
||||
if(!check_valid_color(cm, user))
|
||||
return get_flat_icon(inserted, dir=SOUTH, no_anim=TRUE)
|
||||
|
||||
if(COLORMATE_TINT)
|
||||
if(!check_valid_color(activecolor, user))
|
||||
return get_flat_icon(inserted, dir=SOUTH, no_anim=TRUE)
|
||||
|
||||
if(COLORMATE_HSV)
|
||||
cm = color_matrix_hsv(build_hue, build_sat, build_val)
|
||||
color_matrix_last = cm
|
||||
if(!check_valid_color(cm, user))
|
||||
return get_flat_icon(inserted, dir=SOUTH, no_anim=TRUE)
|
||||
|
||||
var/cur_color = inserted.color
|
||||
inserted.color = null
|
||||
inserted.color = (active_mode == COLORMATE_TINT ? activecolor : cm)
|
||||
var/icon/preview = get_flat_icon(inserted, dir=SOUTH, no_anim=TRUE)
|
||||
inserted.color = cur_color
|
||||
temp = ""
|
||||
|
||||
. = preview
|
||||
|
||||
/datum/ColorMate/proc/check_valid_color(list/cm, mob/user)
|
||||
if(!islist(cm)) // normal
|
||||
var/list/HSV = ReadHSV(RGBtoHSV(cm))
|
||||
if(HSV[3] < minimum_normal_lightness)
|
||||
temp = "[cm] is too dark (Minimum lightness: [minimum_normal_lightness])"
|
||||
return FALSE
|
||||
return TRUE
|
||||
else // matrix
|
||||
// We test using full red, green, blue, and white
|
||||
// A predefined number of them must pass to be considered valid
|
||||
var/passed = 0
|
||||
#define COLORTEST(thestring, thematrix) passed += (ReadHSV(RGBtoHSV(RGBMatrixTransform(thestring, thematrix)))[3] >= minimum_matrix_lightness)
|
||||
COLORTEST("FF0000", cm)
|
||||
COLORTEST("00FF00", cm)
|
||||
COLORTEST("0000FF", cm)
|
||||
COLORTEST("FFFFFF", cm)
|
||||
#undef COLORTEST
|
||||
if(passed < minimum_matrix_tests)
|
||||
temp = "Matrix is too dark. (passed [passed] out of [minimum_matrix_tests] required tests. Minimum lightness: [minimum_matrix_lightness])."
|
||||
return FALSE
|
||||
return TRUE
|
||||
@@ -24,9 +24,9 @@
|
||||
var/on_remove_on_mob_delete = FALSE
|
||||
/// The typepath to the alert thrown by the status effect when created.
|
||||
/// Status effect "name"s and "description"s are shown to the owner here.
|
||||
var/alert_type = /obj/screen/alert/status_effect
|
||||
var/alert_type = /atom/movable/screen/alert/status_effect
|
||||
/// The alert itself, created in [proc/on_creation] (if alert_type is specified).
|
||||
VAR_FINAL/obj/screen/alert/status_effect/linked_alert
|
||||
VAR_FINAL/atom/movable/screen/alert/status_effect/linked_alert
|
||||
/// If TRUE, and we have an alert, we will show a duration on the alert
|
||||
var/show_duration = FALSE
|
||||
/// Used to define if the status effect should be using SSfastprocess or SSprocessing
|
||||
@@ -64,7 +64,7 @@
|
||||
tick_interval = world.time + tick_interval
|
||||
|
||||
if(alert_type)
|
||||
var/obj/screen/alert/status_effect/new_alert = owner.throw_alert(id, alert_type)
|
||||
var/atom/movable/screen/alert/status_effect/new_alert = owner.throw_alert(id, alert_type)
|
||||
new_alert.attached_effect = src //so the alert can reference us, if it needs to
|
||||
linked_alert = new_alert //so we can reference the alert, if we need to
|
||||
update_shown_duration()
|
||||
@@ -242,13 +242,13 @@
|
||||
update_shown_duration()
|
||||
|
||||
/// Alert base type for status effect alerts
|
||||
/obj/screen/alert/status_effect
|
||||
/atom/movable/screen/alert/status_effect
|
||||
name = "Curse of Mundanity"
|
||||
desc = "You don't feel any different..."
|
||||
// maptext_y = 2
|
||||
/// The status effect we're linked to
|
||||
var/datum/status_effect/attached_effect
|
||||
|
||||
/obj/screen/alert/status_effect/Destroy()
|
||||
/atom/movable/screen/alert/status_effect/Destroy()
|
||||
attached_effect = null //Don't keep a ref now
|
||||
return ..()
|
||||
|
||||
Reference in New Issue
Block a user