support for items that switch states through update_icon.
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
/datum/element/polychromic
|
||||
element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH
|
||||
id_arg_index = 3
|
||||
var/list/overlays_by_atom = list()
|
||||
var/list/overlays_states //also used for worn/held overlsays
|
||||
var/overlays_states //A list or a number of states. In the latter case, the atom icon_state/item_state will be used followed by a number for the overlays.
|
||||
var/list/colors_by_atom = list() //list of color strings or mutable appearance depending on the above variable.
|
||||
var/icon_file
|
||||
var/list/overlays_names //wrap numbers into text strings please.
|
||||
var/list/actions_by_atom = list()
|
||||
@@ -15,7 +15,7 @@
|
||||
//item variables
|
||||
var/worn_file //used for boths held and worn overlays if present.
|
||||
|
||||
/datum/element/polychromic/Attach(datum/target, list/colors, list/states, _icon, _flags = POLYCHROMIC_ALTCLICK|POLYCHROMIC_NO_HELD, _worn, list/names = list("Primary", "Secondary", "Tertiary", "Quaternary", "Quinary", "Senary"))
|
||||
/datum/element/polychromic/Attach(datum/target, list/colors, states, _icon, _flags = POLYCHROMIC_ALTCLICK|POLYCHROMIC_NO_HELD, _worn, list/names = list("Primary", "Secondary", "Tertiary", "Quaternary", "Quinary", "Senary"))
|
||||
. = ..()
|
||||
var/states_len = length(overlays_states)
|
||||
var/names_len = length(names)
|
||||
@@ -30,11 +30,17 @@
|
||||
|
||||
var/mut_icon = icon_file || A.icon
|
||||
var/list/L = list()
|
||||
for(var/I in overlays_states)
|
||||
var/col = popleft(colors) || "#FFFFFF"
|
||||
L += mutable_appearance(mut_icon, I, color = col)
|
||||
A.add_overlay(L)
|
||||
overlays_by_atom[A] = L
|
||||
if(islist(overlays_states))
|
||||
for(var/I in overlays_states)
|
||||
var/col = popleft(colors) || "#FFFFFF"
|
||||
L += mutable_appearance(mut_icon, I, color = col)
|
||||
else
|
||||
for(var/I in 1 to overlays_states)
|
||||
var/col = LAZYACCESS(colors, I) || "#FFFFFF"
|
||||
L += col
|
||||
colors_by_atom[A] = L
|
||||
|
||||
RegisterSignal(A, COMSIG_ATOM_UPDATE_OVERLAYS, .proc/apply_overlays)
|
||||
|
||||
if(_flags & POLYCHROMIC_ALTCLICK)
|
||||
RegisterSignal(A, COMSIG_PARENT_EXAMINE, .proc/on_examine)
|
||||
@@ -61,40 +67,57 @@
|
||||
actions_by_atom[A] = P
|
||||
P.Grant(A)
|
||||
|
||||
A.update_icon()
|
||||
|
||||
/datum/element/polychromic/Detach(atom/A)
|
||||
. = ..()
|
||||
A.cut_overlay(overlays_by_atom[A])
|
||||
overlays_by_atom -= A
|
||||
A.cut_overlay(colors_by_atom[A])
|
||||
colors_by_atom -= A
|
||||
var/datum/action/polychromic/P = actions_by_atom[A]
|
||||
if(P)
|
||||
qdel(P)
|
||||
actions_by_atom -= A
|
||||
if(poly_flags & POLYCHROMIC_ALTCLICK)
|
||||
UnregisterSignal(A, list(COMSIG_PARENT_EXAMINE, COMSIG_CLICK_ALT))
|
||||
UnregisterSignal(A, list(COMSIG_PARENT_EXAMINE, COMSIG_CLICK_ALT, COMSIG_ATOM_UPDATE_OVERLAYS, COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED))
|
||||
|
||||
/datum/element/polychromic/proc/apply_worn_overlays(obj/item/source, isinhands, icon_file, style_flags, list/overlays)
|
||||
/datum/element/polychromic/proc/apply_overlays(atom/source, list/overlays)
|
||||
var/list/L = colors_by_atom[source]
|
||||
if(isnum(overlays_states))
|
||||
for(var/i in 1 to overlays_states)
|
||||
overlays += mutable_appearance(source.icon, "[source.icon_state]-[i]", color = L[i])
|
||||
else
|
||||
overlays += colors_by_atom[source]
|
||||
|
||||
/datum/element/polychromic/proc/apply_worn_overlays(obj/item/source, isinhands, icon_file, used_state, style_flags, list/overlays)
|
||||
if(poly_flags & (isinhands ? POLYCHROMIC_NO_HELD : POLYCHROMIC_NO_WORN))
|
||||
return
|
||||
var/f_icon = worn_file || icon_file
|
||||
var/list/L = overlays_by_atom[source]
|
||||
var/list/L = colors_by_atom[source]
|
||||
|
||||
for(var/I in 1 to length(overlays_states))
|
||||
var/mutable_appearance/M = L[I]
|
||||
overlays += mutable_appearance(f_icon, overlays_states[I], color = M.color)
|
||||
if(isnum(overlays_states))
|
||||
for(var/i in 1 to overlays_states)
|
||||
overlays += mutable_appearance(f_icon, "[used_state]-[i]", color = L[i])
|
||||
else
|
||||
for(var/I in 1 to length(overlays_states))
|
||||
var/mutable_appearance/M = L[I]
|
||||
overlays += mutable_appearance(f_icon, overlays_states[I], color = M.color)
|
||||
|
||||
/datum/element/polychromic/proc/set_color(atom/source, mob/user)
|
||||
var/choice = input(user,"Polychromic options", "Recolor [source]") as null|anything in overlays_names
|
||||
if(!choice || QDELETED(source) || !user.canUseTopic(src, BE_CLOSE, NO_DEXTERY))
|
||||
return
|
||||
choice = overlays_names.Find(choice)
|
||||
var/ncolor = input(user, "Polychromic options", "Choose [choice] Color") as color|null
|
||||
if(!ncolor || QDELETED(source) || !user.canUseTopic(src, BE_CLOSE, NO_DEXTERY))
|
||||
return
|
||||
var/list/L = overlays_by_atom[source]
|
||||
var/list/L = colors_by_atom[source]
|
||||
if(!L) // Ummmmmh.
|
||||
return
|
||||
var/mutable_appearance/M = L[choice]
|
||||
M.color = sanitize_hexcolor(ncolor, 6, TRUE, M.color)
|
||||
var/K = L[overlays_names.Find(choice)]
|
||||
if(istext(K))
|
||||
K = sanitize_hexcolor(ncolor, 6, TRUE, K)
|
||||
else
|
||||
var/mutable_appearance/M = K
|
||||
M.color = sanitize_hexcolor(ncolor, 6, TRUE, M.color)
|
||||
source.update_icon()
|
||||
return TRUE
|
||||
|
||||
@@ -105,7 +128,7 @@
|
||||
if(!P)
|
||||
P = new (source)
|
||||
actions_by_atom[source] = P
|
||||
P.check_flags = AB_CHECK_RESTRAINED|AB_CHECK_STUN|AB_CHECK_LYING|AB_CHECK_CONSCIOUS
|
||||
P.check_flags = AB_CHECK_RESTRAINED|AB_CHECK_STUN|AB_CHECK_CONSCIOUS
|
||||
RegisterSignal(P, COMSIG_ACTION_TRIGGER, .proc/activate_action)
|
||||
P.Grant(user)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user