From e35431da34dd95f602b259ee4ecc15c22df7a4bf Mon Sep 17 00:00:00 2001 From: Markolie Date: Sat, 1 Aug 2015 23:22:20 +0200 Subject: [PATCH] Port Bay's appearance changer --- code/__DEFINES/mob.dm | 13 ++ code/game/objects/structures/mirror.dm | 48 +---- code/modules/admin/admin_verbs.dm | 39 +++- .../mob/living/carbon/human/appearance.dm | 188 ++++++++++++++++++ code/modules/nano/modules/human_appearance.dm | 159 +++++++++++++++ nano/templates/appearance_changer.tmpl | 75 +++++++ paradise.dme | 2 + 7 files changed, 482 insertions(+), 42 deletions(-) create mode 100644 code/modules/mob/living/carbon/human/appearance.dm create mode 100644 code/modules/nano/modules/human_appearance.dm create mode 100644 nano/templates/appearance_changer.tmpl diff --git a/code/__DEFINES/mob.dm b/code/__DEFINES/mob.dm index 88f1bc3eeda..0080658562b 100644 --- a/code/__DEFINES/mob.dm +++ b/code/__DEFINES/mob.dm @@ -78,3 +78,16 @@ // Reagent type flags, defines the types of mobs this reagent will affect #define ORGANIC 1 #define SYNTHETIC 2 + +// Appearance change flags +#define APPEARANCE_UPDATE_DNA 1 +#define APPEARANCE_RACE 2|APPEARANCE_UPDATE_DNA +#define APPEARANCE_GENDER 4|APPEARANCE_UPDATE_DNA +#define APPEARANCE_SKIN 8 +#define APPEARANCE_HAIR 16 +#define APPEARANCE_HAIR_COLOR 32 +#define APPEARANCE_FACIAL_HAIR 64 +#define APPEARANCE_FACIAL_HAIR_COLOR 128 +#define APPEARANCE_EYE_COLOR 256 +#define APPEARANCE_ALL_HAIR APPEARANCE_HAIR|APPEARANCE_HAIR_COLOR|APPEARANCE_FACIAL_HAIR|APPEARANCE_FACIAL_HAIR_COLOR +#define APPEARANCE_ALL 511 diff --git a/code/game/objects/structures/mirror.dm b/code/game/objects/structures/mirror.dm index e32c879b304..955ce2756e1 100644 --- a/code/game/objects/structures/mirror.dm +++ b/code/game/objects/structures/mirror.dm @@ -7,52 +7,18 @@ density = 0 anchored = 1 var/shattered = 0 - + var/list/ui_users = list() /obj/structure/mirror/attack_hand(mob/user as mob) if(shattered) return if(ishuman(user)) - var/mob/living/carbon/human/H = user - - var/userloc = H.loc - - //see code/modules/mob/new_player/preferences.dm at approx line 545 for comments! - //this is largely copypasted from there. - - //handle facial hair (if necessary) - if(H.gender == MALE) - var/list/species_facial_hair = list() - if(H.species) - for(var/i in facial_hair_styles_list) - var/datum/sprite_accessory/facial_hair/tmp_facial = facial_hair_styles_list[i] - if(H.species.name in tmp_facial.species_allowed) - species_facial_hair += i - else - species_facial_hair = facial_hair_styles_list - - var/new_style = input(user, "Select a facial hair style", "Grooming") as null|anything in species_facial_hair - if(userloc != H.loc) return //no tele-grooming - if(new_style) - H.f_style = new_style - - //handle normal hair - var/list/species_hair = list() - if(H.species) - for(var/i in hair_styles_list) - var/datum/sprite_accessory/hair/tmp_hair = hair_styles_list[i] - if(H.species.name in tmp_hair.species_allowed) - species_hair += i - else - species_hair = hair_styles_list - - var/new_style = input(user, "Select a hair style", "Grooming") as null|anything in species_hair - if(userloc != H.loc) return //no tele-grooming - if(new_style) - H.h_style = new_style - - H.update_hair() - + var/datum/nano_module/appearance_changer/AC = ui_users[user] + if(!AC) + AC = new(src, user) + AC.name = "SalonPro Nano-Mirror(TM)" + ui_users[user] = AC + AC.ui_interact(user) /obj/structure/mirror/proc/shatter() if(shattered) return diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index cca7dcb27cc..d6f0608a216 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -66,7 +66,9 @@ var/list/admin_verbs_admin = list( /client/proc/freeze, /client/proc/freezemecha, /client/proc/alt_check, - /client/proc/secrets + /client/proc/secrets, + /client/proc/change_human_appearance_admin, /* Allows an admin to change the basic appearance of human-based mobs */ + /client/proc/change_human_appearance_self /* Allows the human-based mob itself change its basic appearance */ ) var/list/admin_verbs_ban = list( /client/proc/unban_panel, @@ -543,6 +545,41 @@ var/list/admin_verbs_mentor = list( if(holder) src.holder.output_ai_laws() +/client/proc/change_human_appearance_admin(mob/living/carbon/human/H in world) + set name = "Change Mob Appearance - Admin" + set desc = "Allows you to change the mob appearance" + set category = "Admin" + + if(!istype(H)) + return + + if(holder) + admin_log_and_message_admins("is altering the appearance of [H].") + H.change_appearance(APPEARANCE_ALL, usr, usr, check_species_whitelist = 0) + feedback_add_details("admin_verb","CHAA") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + +/client/proc/change_human_appearance_self(mob/living/carbon/human/H in world) + set name = "Change Mob Appearance - Self" + set desc = "Allows the mob to change its appearance" + set category = "Admin" + + if(!istype(H)) + return + + if(!H.client) + usr << "Only mobs with clients can alter their own appearance." + return + + if(holder) + switch(alert("Do you wish for [H] to be allowed to select non-whitelisted races?","Alter Mob Appearance","Yes","No","Cancel")) + if("Yes") + admin_log_and_message_admins("has allowed [H] to change \his appearance, without whitelisting of races.") + H.change_appearance(APPEARANCE_ALL, H.loc, check_species_whitelist = 0) + if("No") + admin_log_and_message_admins("has allowed [H] to change \his appearance, with whitelisting of races.") + H.change_appearance(APPEARANCE_ALL, H.loc, check_species_whitelist = 1) + feedback_add_details("admin_verb","CMAS") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + //---- bs12 verbs ---- diff --git a/code/modules/mob/living/carbon/human/appearance.dm b/code/modules/mob/living/carbon/human/appearance.dm new file mode 100644 index 00000000000..2b562516e5a --- /dev/null +++ b/code/modules/mob/living/carbon/human/appearance.dm @@ -0,0 +1,188 @@ +/mob/living/carbon/human/proc/change_appearance(var/flags = APPEARANCE_ALL_HAIR, var/location = src, var/mob/user = src, var/check_species_whitelist = 1, var/list/species_whitelist = list(), var/list/species_blacklist = list(), var/datum/topic_state/state = default_state) + var/datum/nano_module/appearance_changer/AC = new(location, src, check_species_whitelist, species_whitelist, species_blacklist) + AC.flags = flags + AC.ui_interact(user, state = state) + +/mob/living/carbon/human/proc/change_species(var/new_species) + if(!new_species) + return + + if(species == new_species) + return + + if(!(new_species in all_species)) + return + + set_species(new_species) + reset_hair() + return 1 + +/mob/living/carbon/human/proc/change_gender(var/gender) + if(src.gender == gender) + return + + src.gender = gender + reset_hair() + update_body() + update_dna() + return 1 + +/mob/living/carbon/human/proc/change_hair(var/hair_style) + if(!hair_style) + return + + if(h_style == hair_style) + return + + if(!(hair_style in hair_styles_list)) + return + + h_style = hair_style + + update_hair() + return 1 + +/mob/living/carbon/human/proc/change_facial_hair(var/facial_hair_style) + if(!facial_hair_style) + return + + if(f_style == facial_hair_style) + return + + if(!(facial_hair_style in facial_hair_styles_list)) + return + + f_style = facial_hair_style + + update_hair() + return 1 + +/mob/living/carbon/human/proc/reset_hair() + var/list/valid_hairstyles = generate_valid_hairstyles() + var/list/valid_facial_hairstyles = generate_valid_facial_hairstyles() + + if(valid_hairstyles.len) + h_style = pick(valid_hairstyles) + else + //this shouldn't happen + h_style = "Bald" + + if(valid_facial_hairstyles.len) + f_style = pick(valid_facial_hairstyles) + else + //this shouldn't happen + f_style = "Shaved" + + update_hair() + +/mob/living/carbon/human/proc/change_eye_color(var/red, var/green, var/blue) + if(red == r_eyes && green == g_eyes && blue == b_eyes) + return + + r_eyes = red + g_eyes = green + b_eyes = blue + + update_eyes() + update_body() + return 1 + +/mob/living/carbon/human/proc/change_hair_color(var/red, var/green, var/blue) + if(red == r_eyes && green == g_eyes && blue == b_eyes) + return + + r_hair = red + g_hair = green + b_hair = blue + + update_hair() + return 1 + +/mob/living/carbon/human/proc/change_facial_hair_color(var/red, var/green, var/blue) + if(red == r_facial && green == g_facial && blue == b_facial) + return + + r_facial = red + g_facial = green + b_facial = blue + + update_hair() + return 1 + +/mob/living/carbon/human/proc/change_skin_color(var/red, var/green, var/blue) + if(red == r_skin && green == g_skin && blue == b_skin || !(species.flags & HAS_SKIN_COLOR)) + return + + r_skin = red + g_skin = green + b_skin = blue + + force_update_limbs() + update_body() + return 1 + +/mob/living/carbon/human/proc/change_skin_tone(var/tone) + if(s_tone == tone || !(species.flags & HAS_SKIN_TONE)) + return + + s_tone = tone + + force_update_limbs() + update_body() + return 1 + +/mob/living/carbon/human/proc/update_dna() + check_dna() + dna.ready_dna(src) + +/mob/living/carbon/human/proc/generate_valid_species(var/check_whitelist = 1, var/list/whitelist = list(), var/list/blacklist = list()) + var/list/valid_species = new() + for(var/current_species_name in all_species) + var/datum/species/current_species = all_species[current_species_name] + + if(check_whitelist && config.usealienwhitelist && !check_rights(R_ADMIN, 0, src)) //If we're using the whitelist, make sure to check it! + if(whitelist.len && !(current_species_name in whitelist)) + continue + if(blacklist.len && (current_species_name in blacklist)) + continue + if((current_species.flags & IS_WHITELISTED) && !is_alien_whitelisted(src, current_species_name)) + continue + + valid_species += current_species_name + + return valid_species + +/mob/living/carbon/human/proc/generate_valid_hairstyles() + var/list/valid_hairstyles = new() + for(var/hairstyle in hair_styles_list) + var/datum/sprite_accessory/S = hair_styles_list[hairstyle] + + if(gender == MALE && S.gender == FEMALE) + continue + if(gender == FEMALE && S.gender == MALE) + continue + if(!(species.name in S.species_allowed)) + continue + valid_hairstyles += hairstyle + + return valid_hairstyles + +/mob/living/carbon/human/proc/generate_valid_facial_hairstyles() + var/list/valid_facial_hairstyles = new() + for(var/facialhairstyle in facial_hair_styles_list) + var/datum/sprite_accessory/S = facial_hair_styles_list[facialhairstyle] + + if(gender == MALE && S.gender == FEMALE) + continue + if(gender == FEMALE && S.gender == MALE) + continue + if(!(species.name in S.species_allowed)) + continue + + valid_facial_hairstyles += facialhairstyle + + return valid_facial_hairstyles + +/proc/q() + var/mob/living/carbon/human/H = usr + H.change_appearance(APPEARANCE_ALL) \ No newline at end of file diff --git a/code/modules/nano/modules/human_appearance.dm b/code/modules/nano/modules/human_appearance.dm new file mode 100644 index 00000000000..f5bc0240bc5 --- /dev/null +++ b/code/modules/nano/modules/human_appearance.dm @@ -0,0 +1,159 @@ +/datum/nano_module/appearance_changer + name = "Appearance Editor" + var/flags = APPEARANCE_ALL_HAIR + var/mob/living/carbon/human/owner = null + var/list/valid_species = list() + var/list/valid_hairstyles = list() + var/list/valid_facial_hairstyles = list() + + var/check_whitelist + var/list/whitelist + var/list/blacklist + +/datum/nano_module/appearance_changer/New(var/location, var/mob/living/carbon/human/H, var/check_species_whitelist = 1, var/list/species_whitelist = list(), var/list/species_blacklist = list()) + ..() + owner = H + src.check_whitelist = check_species_whitelist + src.whitelist = species_whitelist + src.blacklist = species_blacklist + +/datum/nano_module/appearance_changer/Topic(ref, href_list, var/nowindow, var/datum/topic_state/state = default_state) + if(..()) + return 1 + + if(href_list["race"]) + if(can_change(APPEARANCE_RACE) && (href_list["race"] in valid_species)) + if(owner.change_species(href_list["race"])) + cut_and_generate_data() + return 1 + if(href_list["gender"]) + if(can_change(APPEARANCE_GENDER)) + if(owner.change_gender(href_list["gender"])) + cut_and_generate_data() + return 1 + if(href_list["skin_tone"]) + if(can_change_skin_tone()) + var/new_s_tone = input(usr, "Choose your character's skin-tone:\n(Light 1 - 220 Dark)", "Skin Tone", owner.s_tone) as num|null + if(isnum(new_s_tone) && can_still_topic(state)) + new_s_tone = 35 - max(min( round(new_s_tone), 220),1) + return owner.change_skin_tone(new_s_tone) + if(href_list["skin_color"]) + if(can_change_skin_color()) + var/new_skin = input(usr, "Choose your character's skin colour: ", "Skin Color", rgb(owner.r_skin, owner.g_skin, owner.b_skin)) as color|null + if(new_skin && can_still_topic(state)) + var/r_skin = hex2num(copytext(new_skin, 2, 4)) + var/g_skin = hex2num(copytext(new_skin, 4, 6)) + var/b_skin = hex2num(copytext(new_skin, 6, 8)) + if(owner.change_skin_color(r_skin, g_skin, b_skin)) + update_dna() + return 1 + if(href_list["hair"]) + if(can_change(APPEARANCE_HAIR) && (href_list["hair"] in valid_hairstyles)) + if(owner.change_hair(href_list["hair"])) + update_dna() + return 1 + if(href_list["hair_color"]) + if(can_change(APPEARANCE_HAIR_COLOR)) + var/new_hair = input("Please select hair color.", "Hair Color", rgb(owner.r_hair, owner.g_hair, owner.b_hair)) as color|null + if(new_hair && can_still_topic(state)) + var/r_hair = hex2num(copytext(new_hair, 2, 4)) + var/g_hair = hex2num(copytext(new_hair, 4, 6)) + var/b_hair = hex2num(copytext(new_hair, 6, 8)) + if(owner.change_hair_color(r_hair, g_hair, b_hair)) + update_dna() + return 1 + if(href_list["facial_hair"]) + if(can_change(APPEARANCE_FACIAL_HAIR) && (href_list["facial_hair"] in valid_facial_hairstyles)) + if(owner.change_facial_hair(href_list["facial_hair"])) + update_dna() + return 1 + if(href_list["facial_hair_color"]) + if(can_change(APPEARANCE_FACIAL_HAIR_COLOR)) + var/new_facial = input("Please select facial hair color.", "Facial Hair Color", rgb(owner.r_facial, owner.g_facial, owner.b_facial)) as color|null + if(new_facial && can_still_topic(state)) + var/r_facial = hex2num(copytext(new_facial, 2, 4)) + var/g_facial = hex2num(copytext(new_facial, 4, 6)) + var/b_facial = hex2num(copytext(new_facial, 6, 8)) + if(owner.change_facial_hair_color(r_facial, g_facial, b_facial)) + update_dna() + return 1 + if(href_list["eye_color"]) + if(can_change(APPEARANCE_EYE_COLOR)) + var/new_eyes = input("Please select eye color.", "Eye Color", rgb(owner.r_eyes, owner.g_eyes, owner.b_eyes)) as color|null + if(new_eyes && can_still_topic(state)) + var/r_eyes = hex2num(copytext(new_eyes, 2, 4)) + var/g_eyes = hex2num(copytext(new_eyes, 4, 6)) + var/b_eyes = hex2num(copytext(new_eyes, 6, 8)) + if(owner.change_eye_color(r_eyes, g_eyes, b_eyes)) + update_dna() + return 1 + + return 0 + +/datum/nano_module/appearance_changer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = default_state) + generate_data(check_whitelist, whitelist, blacklist) + var/data[0] + + data["specimen"] = owner.species.name + data["gender"] = owner.gender + data["change_race"] = can_change(APPEARANCE_RACE) + if(data["change_race"]) + var/species[0] + for(var/specimen in valid_species) + species[++species.len] = list("specimen" = specimen) + data["species"] = species + + data["change_gender"] = can_change(APPEARANCE_GENDER) + data["change_skin_tone"] = can_change_skin_tone() + data["change_skin_color"] = can_change_skin_color() + data["change_eye_color"] = can_change(APPEARANCE_EYE_COLOR) + data["change_hair"] = can_change(APPEARANCE_HAIR) + if(data["change_hair"]) + var/hair_styles[0] + for(var/hair_style in valid_hairstyles) + hair_styles[++hair_styles.len] = list("hairstyle" = hair_style) + data["hair_styles"] = hair_styles + data["hair_style"] = owner.h_style + + data["change_facial_hair"] = can_change(APPEARANCE_FACIAL_HAIR) + if(data["change_facial_hair"]) + var/facial_hair_styles[0] + for(var/facial_hair_style in valid_facial_hairstyles) + facial_hair_styles[++facial_hair_styles.len] = list("facialhairstyle" = facial_hair_style) + data["facial_hair_styles"] = facial_hair_styles + data["facial_hair_style"] = owner.f_style + + data["change_hair_color"] = can_change(APPEARANCE_HAIR_COLOR) + data["change_facial_hair_color"] = can_change(APPEARANCE_FACIAL_HAIR_COLOR) + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + if (!ui) + ui = new(user, src, ui_key, "appearance_changer.tmpl", "[src]", 800, 450, state = state) + ui.set_initial_data(data) + ui.open() + ui.set_auto_update(1) + +/datum/nano_module/appearance_changer/proc/update_dna() + if(owner && (flags & APPEARANCE_UPDATE_DNA)) + owner.update_dna() + +/datum/nano_module/appearance_changer/proc/can_change(var/flag) + return owner && (flags & flag) + +/datum/nano_module/appearance_changer/proc/can_change_skin_tone() + return owner && (flags & APPEARANCE_SKIN) && owner.species.flags & HAS_SKIN_TONE + +/datum/nano_module/appearance_changer/proc/can_change_skin_color() + return owner && (flags & APPEARANCE_SKIN) && owner.species.flags & HAS_SKIN_COLOR + +/datum/nano_module/appearance_changer/proc/cut_and_generate_data() + // Making the assumption that the available species remain constant + valid_facial_hairstyles.Cut() + valid_facial_hairstyles.Cut() + generate_data() + +/datum/nano_module/appearance_changer/proc/generate_data() + if(!valid_species.len) + valid_species = owner.generate_valid_species(check_whitelist, whitelist, blacklist) + if(!valid_hairstyles.len || !valid_facial_hairstyles.len) + valid_hairstyles = owner.generate_valid_hairstyles() + valid_facial_hairstyles = owner.generate_valid_facial_hairstyles() \ No newline at end of file diff --git a/nano/templates/appearance_changer.tmpl b/nano/templates/appearance_changer.tmpl new file mode 100644 index 00000000000..19e7fd4759b --- /dev/null +++ b/nano/templates/appearance_changer.tmpl @@ -0,0 +1,75 @@ +{{if data.change_race}} +
+
+ Species: +
+
+ {{for data.species}} + {{:helper.link(value.specimen, null, { 'race' : value.specimen}, null, data.specimen == value.specimen ? 'selected' : null)}} + {{/for}} +
+
+{{/if}} + +{{if data.change_gender}} +
+
+ Gender: +
+
+ {{:helper.link('Male', null, { 'gender' : 'male'}, null, data.gender == 'male' ? 'selected' : null)}} + {{:helper.link('Female', null, { 'gender' : 'female'}, null, data.gender == 'female' ? 'selected' : null)}} +
+
+{{/if}} + +{{if data.change_eye_color || data.change_skin_tone || data.change_skin_color || data.change_hair_color || data.change_facial_hair_color}} +
+
+ Colors: +
+
+ {{if data.change_eye_color}} + {{:helper.link('Change eye color', null, { 'eye_color' : 1})}} + {{/if}} + {{if data.change_skin_tone}} + {{:helper.link('Change skin tone', null, { 'skin_tone' : 1})}} + {{/if}} + {{if data.change_skin_color}} + {{:helper.link('Change skin color', null, { 'skin_color' : 1})}} + {{/if}} + {{if data.change_hair_color}} + {{:helper.link('Change hair color', null, { 'hair_color' : 1})}} + {{/if}} + {{if data.change_facial_hair_color}} + {{:helper.link('Change facial hair color', null, { 'facial_hair_color' : 1})}} + {{/if}} +
+
+{{/if}} + +{{if data.change_hair}} +
+
+ Hair styles: +
+
+ {{for data.hair_styles}} + {{:helper.link(value.hairstyle, null, { 'hair' : value.hairstyle}, null, data.hair_style == value.hairstyle ? 'selected' : null)}} + {{/for}} +
+
+{{/if}} + +{{if data.change_facial_hair}} +
+
+ Facial hair styles: +
+
+ {{for data.facial_hair_styles}} + {{:helper.link(value.facialhairstyle, null, { 'facial_hair' : value.facialhairstyle}, null, data.facial_hair_style == value.facialhairstyle ? 'selected' : null)}} + {{/for}} +
+
+{{/if}} diff --git a/paradise.dme b/paradise.dme index 131d5139d79..9cccdb8a954 100644 --- a/paradise.dme +++ b/paradise.dme @@ -1301,6 +1301,7 @@ #include "code\modules\mob\living\carbon\brain\MMI.dm" #include "code\modules\mob\living\carbon\brain\posibrain.dm" #include "code\modules\mob\living\carbon\brain\say.dm" +#include "code\modules\mob\living\carbon\human\appearance.dm" #include "code\modules\mob\living\carbon\human\death.dm" #include "code\modules\mob\living\carbon\human\emote.dm" #include "code\modules\mob\living\carbon\human\examine.dm" @@ -1468,6 +1469,7 @@ #include "code\modules\nano\interaction\physical.dm" #include "code\modules\nano\interaction\zlevel.dm" #include "code\modules\nano\modules\crew_monitor.dm" +#include "code\modules\nano\modules\human_appearance.dm" #include "code\modules\nano\modules\nano_module.dm" #include "code\modules\ninja\energy_katana.dm" #include "code\modules\ninja\suit\gloves.dm"