ID:1909143
 
(See the best response by Lummox JR.)
Alright i've done a lot of searching and there was even a post not long ago on this but i'm having difficulty understanding whats going on and why.

What i'm trying to achieve is the ability for a player to choose a hair style then picks its colour themselves.

However I wan't this to only happen once they have triggered the equipped proc which would be overridden.

However I don't fully understand whats going on and i've seen a few ways of doing things.

Here is my code for reference;

    hair3
name = "Afro"
icon_state = "hair1-standing"
description = "Afro Hair"
overlay_state = "hair1"
overlay_layer = 6
map_state = "hair1-standing"
icon = 'hairs.dmi'
overlay_icon = 'hairs.dmi'
map_icon = 'hairs.dmi'

slot = HAIR

Click()
usr.equip(new /item/hair1())
usr << usr.sound_effect('boop.wav')

equipped(mob/m)
m.overlay(src)

unequipped(mob/m)
m.remove(src)


Ive seen some people do

overlays += setcolor

And have setcolor set by an input("pick a color", "color", setcolor) as color

However when I do this I am left with a blank Icon, I think its because of the different Icon states that i'm using for movement and other actions.

I've also seen people do some kind of blend

Blend(icon, add, rgb etc etc

And I have no idea how blends works and yet to find an example.

I was wondering if you guys could explain how coloring an icon works, do you "Add" a solid color to the icon file and paste that over another icon on a higher layer.

Or do you change the hue of already existing colours?

And how would I get it working for that hair item described above?


Thanks in advance! (Sorry for being such a pain)
This is an example of the, set by an input pick a color.

Hair
var
hairicon
haircolor
Afro
hairicon = 'Afro.dmi'
Click()
haircolor = (input(usr,"Pick a Color For Your Hair.","Color Hair",haircolor)as color) //Allows the user to pick their hair color
hairicon += haircolor //Adds the hair color to the hair icon, in this case is Afro.dmi
usr.overlays += hairicon //Adds that icon to the user's overlays.

Thank you for the example, however the equipped proc adds the obj overlay_state to the players mob. With each state being changed to when "moving" or "attacking".

What i'm trying to do its edit the item before it gets equipped, which in my head its as simple as changing the colour in Equipped() or have Click() edit the new /item/hair that the player received.

And when I use that method the hair icon ends up being invisible, i'm not sure why but i'm almost positive its because of the different icon states, moving, attack etc etc

Also I am still very confused how that colouring works.

hairicon = 'afro.dmi' is a file, but you have a colour variable that is set by an input that is added to the file, does that add a nameless 32x32(depending on the setting) solid colour icon?

then you add the file as an overlay?

wouldn't that just take an icon with an "" name and use that. since the icon isn't defined I thought I would default to "".

Sorry if this is really simple.
I probably should have explained it more clearly, the hairicon is the icon of your hair.

If your case, hairicon = 'hairs.dmi'

I have haircolor stored and I added it to the hairicon to basically change the color of the hairicon to the haircolor. So in your case your afro and I chose the color red, the color of the afro would be red.

I don't really understand how your hair system is being used so I can't really make a code based off of it, so depending on it you might want to store the haircolor in the mob variables.

But for you to change your haircolor
mob
var
haircolor
Change_Color()
haircolor = (input(usr,"Pick a Color For Your Hair.","Color Hair",haircolor)as color)

Equipping your hair:
    hair3
name = "Afro"
icon_state = "hair1-standing"
description = "Afro Hair"
overlay_state = "hair1"
overlay_layer = 6
map_state = "hair1-standing"
icon = 'hairs.dmi'
overlay_icon = 'hairs.dmi'
map_icon = 'hairs.dmi'

slot = HAIR

Click()
var/item/hair1/hair = new()
hair.icon+=usr.haircolor
usr.equip(hair)
usr << usr.sound_effect('boop.wav')

equipped(mob/m)
m.overlay(src)

unequipped(mob/m)
m.remove(src)
Best response
DaGilbert wrote:
I've also seen people do some kind of blend

Blend(icon, add, rgb etc etc

And I have no idea how blends works and yet to find an example.

In the old days, this is what you would do to add color to an icon:

myicon += rgb(100,0,0)

Now we have better options. The /icon datum can be used to do more complex icon manipulations before committing an icon to the cache. So the same code can be done like this:

var/icon/I = new(myicon)
I.Blend(rgb(100,0,0), ICON_ADD)
myicon = fcopy_rsc(I)

The benefit to this: You can do more than one operation if you wish, and there are kinds of blends (like overlaying one icon on another) that aren't doable without Blend(). For colorizing it's maybe a little less useful, except for certain cases like MapColors().

Myself, I prefer multiplying an icon by a color rather than adding, because additive color will distort the saturation.

As a word of caution so that your savefiles don't become insanely huge, I recommend you do not build overlays in this manner. Doing icon manipulation is still fine, but you should make sure any such icons are stored, if they're stored at all, as tmp vars.

The best way to do this sort of thing is to only keep track of the various colors and styles used for hair, clothing, etc., and then have a master routine rebuild the overlays when they're needed (like at the end of Read()).