diff options
Diffstat (limited to 'src/game/client')
| -rw-r--r-- | src/game/client/cl_skin.cpp | 47 | ||||
| -rw-r--r-- | src/game/client/cl_skin.h | 2 | ||||
| -rw-r--r-- | src/game/client/game_client.cpp | 26 | ||||
| -rw-r--r-- | src/game/client/menu2.cpp | 50 |
4 files changed, 67 insertions, 58 deletions
diff --git a/src/game/client/cl_skin.cpp b/src/game/client/cl_skin.cpp index 6e450b4f..292b0a99 100644 --- a/src/game/client/cl_skin.cpp +++ b/src/game/client/cl_skin.cpp @@ -80,3 +80,50 @@ int skin_find(const char *name) return -1; } + + + +// these converter functions were nicked from some random internet pages +static float hue_to_rgb(float v1, float v2, float h) +{ + if(h < 0) h += 1; + if(h > 1) h -= 1; + if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h; + if((2 * h) < 1) return v2; + if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6; + return v1; +} + +vec3 hsl_to_rgb(vec3 in) +{ + float v1, v2; + vec3 out; + + if(in.s == 0) + { + out.r = in.l; + out.g = in.l; + out.b = in.l; + } + else + { + if(in.l < 0.5f) + v2 = in.l * (1 + in.s); + else + v2 = (in.l+in.s) - (in.s*in.l); + + v1 = 2 * in.l - v2; + + out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f)); + out.g = hue_to_rgb(v1, v2, in.h); + out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f)); + } + + return out; +} + +vec4 skin_get_color(int v) +{ + vec3 r = hsl_to_rgb(vec3((v>>16)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); + return vec4(r.r, r.g, r.b, 1.0f); +} diff --git a/src/game/client/cl_skin.h b/src/game/client/cl_skin.h index 84dbc5f2..0b5875b3 100644 --- a/src/game/client/cl_skin.h +++ b/src/game/client/cl_skin.h @@ -1,3 +1,4 @@ +#include "../vmath.h" // do this better and nicer typedef struct @@ -8,6 +9,7 @@ typedef struct const char term[1]; } skin; +vec4 skin_get_color(int v); void skin_init(); int skin_num(); const skin *skin_get(int index); diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp index 5698fc05..d9c2ba53 100644 --- a/src/game/client/game_client.cpp +++ b/src/game/client/game_client.cpp @@ -4,7 +4,6 @@ #include <string.h> extern "C" { - #include <engine/external/glfw/include/GL/glfw.h> // DEBUG TESTING #include <engine/client/ui.h> #include <engine/config.h> }; @@ -26,10 +25,6 @@ enum CHN_WORLD, }; -// red team color = 54090 -// blue team color = 10998628 - - data_container *data = 0x0; int gametype = GAMETYPE_DM; @@ -855,7 +850,9 @@ void send_info(bool start) msg_pack_start(MSG_CHANGEINFO, MSGFLAG_VITAL); msg_pack_string(config.player_name, 64); msg_pack_string(config.player_skin, 64); + msg_pack_int(config.player_use_custom_color); msg_pack_int(config.player_color_body); + msg_pack_int(config.player_color_feet); msg_pack_end(); client_send_msg(); } @@ -2640,19 +2637,28 @@ extern "C" void modc_message(int msg) int cid = msg_unpack_int(); const char *name = msg_unpack_string(); const char *skinname = msg_unpack_string(); - int color = msg_unpack_int(); - (void)color; + strncpy(client_datas[cid].name, name, 64); strncpy(client_datas[cid].skin_name, skinname, 64); - client_datas[cid].skin_info.color_body = vec4(1,1,1,1); //color; - client_datas[cid].skin_info.color_feet = vec4(1,1,1,1); //color; + + int use_custom_color = msg_unpack_int(); + client_datas[cid].skin_info.color_body = skin_get_color(msg_unpack_int()); + client_datas[cid].skin_info.color_feet = skin_get_color(msg_unpack_int()); client_datas[cid].skin_info.size = 64; // find new skin client_datas[cid].skin_id = skin_find(client_datas[cid].skin_name); if(client_datas[cid].skin_id < 0) client_datas[cid].skin_id = 0; - client_datas[cid].skin_info.texture = skin_get(client_datas[cid].skin_id)->org_texture; + + if(use_custom_color) + client_datas[cid].skin_info.texture = skin_get(client_datas[cid].skin_id)->color_texture; + else + { + client_datas[cid].skin_info.texture = skin_get(client_datas[cid].skin_id)->org_texture; + client_datas[cid].skin_info.color_body = vec4(1,1,1,1); + client_datas[cid].skin_info.color_feet = vec4(1,1,1,1); + } } else if(msg == MSG_READY_TO_ENTER) { diff --git a/src/game/client/menu2.cpp b/src/game/client/menu2.cpp index f1c0ac72..53d80235 100644 --- a/src/game/client/menu2.cpp +++ b/src/game/client/menu2.cpp @@ -1012,52 +1012,6 @@ static void menu2_render_serverbrowser(RECT main_view) } } - -// these converter functions were nicked from some random internet pages -static float hue_to_rgb(float v1, float v2, float h) -{ - if(h < 0) h += 1; - if(h > 1) h -= 1; - if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h; - if((2 * h) < 1) return v2; - if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6; - return v1; -} - -vec3 hsl_to_rgb(vec3 in) -{ - float v1, v2; - vec3 out; - - if(in.s == 0) - { - out.r = in.l; - out.g = in.l; - out.b = in.l; - } - else - { - if(in.l < 0.5f) - v2 = in.l * (1 + in.s); - else - v2 = (in.l+in.s) - (in.s*in.l); - - v1 = 2 * in.l - v2; - - out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f)); - out.g = hue_to_rgb(v1, v2, in.h); - out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f)); - } - - return out; -} - -static vec4 get_color(int v) -{ - vec3 r = hsl_to_rgb(vec3((v>>16)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); - return vec4(r.r, r.g, r.b, 1.0f); -} - static void menu2_render_settings_player(RECT main_view) { RECT button; @@ -1176,8 +1130,8 @@ static void menu2_render_settings_player(RECT main_view) info.color_feet = vec4(1,1,1,1); if(config.player_use_custom_color) { - info.color_body = get_color(config.player_color_body); - info.color_feet = get_color(config.player_color_feet); + info.color_body = skin_get_color(config.player_color_body); + info.color_feet = skin_get_color(config.player_color_feet); info.texture = s->color_texture; } |