From 984afed89ffd18bf216b7e42fc15d6d39aa9e940 Mon Sep 17 00:00:00 2001 From: Remie Richards Date: Thu, 7 Apr 2016 21:55:31 +0100 Subject: [PATCH] Adds a priority system for client.color effects --- code/__HELPERS/cmp.dm | 5 +- code/modules/client/client_colour.dm | 72 ++++++++++++++++++++++++++++ code/modules/mob/login.dm | 2 + code/modules/mob/mob.dm | 3 ++ tgstation.dme | 1 + 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 code/modules/client/client_colour.dm diff --git a/code/__HELPERS/cmp.dm b/code/__HELPERS/cmp.dm index 725742eaf04..9bf462dc80d 100644 --- a/code/__HELPERS/cmp.dm +++ b/code/__HELPERS/cmp.dm @@ -35,4 +35,7 @@ var/cmp_field = "name" /proc/cmp_subsystem_display(datum/subsystem/a, datum/subsystem/b) if(a.display == b.display) return sorttext(b.name, a.name) - return a.display - b.display \ No newline at end of file + return a.display - b.display + +/proc/cmp_clientcolour_priority(datum/client_colour/A, datum/client_colour/B) + return B.priority - A.priority \ No newline at end of file diff --git a/code/modules/client/client_colour.dm b/code/modules/client/client_colour.dm new file mode 100644 index 00000000000..8073b0abebf --- /dev/null +++ b/code/modules/client/client_colour.dm @@ -0,0 +1,72 @@ + +/* + Client Colour Priority System By RemieRichards + A System that gives finer control over which client.colour value to display on screen + so that the "highest priority" one is always displayed as opposed to the default of + "whichever was set last is displayed" +*/ + + + +/* + Define subtypes of this datum +*/ +/datum/client_colour + var/colour = "" //Any client.color-valid value + var/priority = 1 //Since only one client.color can be rendered on screen, we take the one with the highest priority value: + //eg: "Bloody screen" > "goggles colour" as the former is much more important + + +/mob + var/list/client_colours = list() + + + +/* + Adds an instance of colour_type to the mob's client_colours list + colour_type - a typepath (subtyped from /datum/client_colour) +*/ +/mob/proc/add_client_colour(colour_type) + if(!ispath(/datum/client_colour)) + return + + var/datum/client_colour/CC = new colour_type() + client_colours |= CC + sortTim(client_colours, /proc/cmp_clientcolour_priority) + update_client_colour() + + +/* + Removes an instance of colour_type from the mob's client_colours list + colour_type - a typepath (subtyped from /datum/client_colour) +*/ +/mob/proc/remove_client_colour(colour_type) + if(!ispath(/datum/client_colour)) + return + + for(var/cc in client_colours) + var/datum/client_colour/CC = cc + if(CC.type == colour_type) + client_colours -= CC + qdel(CC) + break + update_client_colour() + + +/* + Resets the mob's client.color to null, and then sets it to the highest priority + client_colour datum, if one exists +*/ +/mob/proc/update_client_colour() + if(!client) + return + client.color = "" + if(!client_colours.len) + return + var/datum/client_colour/CC = client_colours[1] + if(CC) + client.color = CC.colour + + + + diff --git a/code/modules/mob/login.dm b/code/modules/mob/login.dm index 1ce7aed14f9..f5005746041 100644 --- a/code/modules/mob/login.dm +++ b/code/modules/mob/login.dm @@ -70,3 +70,5 @@ var/datum/alternate_appearance/AA = viewing_alternate_appearances[aakey] if(AA) AA.display_to(list(src)) + + update_client_colour() \ No newline at end of file diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 9419b963f7f..0277e7528d2 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -7,6 +7,9 @@ spellremove(src) for(var/infection in viruses) qdel(infection) + for(var/cc in client_colours) + qdel(cc) + client_colours = null ghostize() return ..() diff --git a/tgstation.dme b/tgstation.dme index 1d122ea5942..a3f83fae7c0 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -914,6 +914,7 @@ #include "code\modules\client\asset_cache.dm" #include "code\modules\client\client defines.dm" #include "code\modules\client\client procs.dm" +#include "code\modules\client\client_colour.dm" #include "code\modules\client\message.dm" #include "code\modules\client\preferences.dm" #include "code\modules\client\preferences_savefile.dm"