From: MirceaKitsune Date: Sat, 2 Feb 2013 14:03:00 +0000 (+0200) Subject: Use independent functions for some tasks, and fix how scale and position are defined X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bc84d94d3716372fd6c1ea49ab9cf52badad0d4a;p=voretournament%2Fvoretournament.git Use independent functions for some tasks, and fix how scale and position are defined --- diff --git a/data/hudVT.cfg b/data/hudVT.cfg index 0e0e1b02..a965ad82 100644 --- a/data/hudVT.cfg +++ b/data/hudVT.cfg @@ -16,24 +16,24 @@ set hud_item_armor_text_scale 12 set hud_item_ammo_icon_position "0.095 -0.91 0" set hud_item_ammo_icon_scale "0.025 0.04 0" -set hud_item_ammo_noload_text_position "0.025 0.91 0" +set hud_item_ammo_noload_text_position "0.025 -0.91 0" set hud_item_ammo_noload_text_scale 16 set hud_item_ammo_load_text_position "0.015 -0.935 0" set hud_item_ammo_load_text_scale 12 set hud_item_clip_load_text_position "0.03 -0.89 0" set hud_item_clip_load_text_scale 16 -set hud_item_predator_position "140 450 0" -set hud_item_predator_scale "130 10 0" +set hud_item_predator_position "-0.64 -0.525 0" +set hud_item_predator_scale "0.17 0.0175 0" set hud_item_predator_colors_location 0 set hud_item_predator_colors_length 0.15 set hud_item_predator_name_location 0.15 set hud_item_predator_name_length 0.85 -set hud_item_preylist_spacing 1.25 -set hud_item_preylist_entries 9 -set hud_item_preylist_position "110 475 0" -set hud_item_preylist_scale "190 10 0" +set hud_item_preylist_position "-0.72 -0.6 0" +set hud_item_preylist_scale "0.25 0.0175 0" +set hud_item_preylist_entry_spacing "0 -1.25 0" +set hud_item_preylist_entry_number 9 set hud_item_preylist_colors_location 0 set hud_item_preylist_colors_length 0.1 set hud_item_preylist_name_location 0.1 diff --git a/data/qcsrc/client/hud.qc b/data/qcsrc/client/hud.qc index b91c6a26..c7050149 100644 --- a/data/qcsrc/client/hud.qc +++ b/data/qcsrc/client/hud.qc @@ -72,15 +72,39 @@ vector Sbar_AccuracyColor(float accuracy) return rgb; } -void Sbar_DrawPic(string pic, vector position, vector dimensions, float background) +vector Sbar_ConvertToScreen_PicScale(vector dimensions) { - vector pos, sz; + vector sz; sz_x = vid_conwidth * dimensions_x; sz_y = vid_conheight * dimensions_y; + return sz; +} +vector Sbar_ConvertToScreen_PicPosition(vector position, vector dimensions) +{ + vector pos, sz; + sz = Sbar_ConvertToScreen_PicScale(dimensions); pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); pos_x -= sz_x / 2; pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); pos_y -= sz_y / 2; + return pos; +} +vector Sbar_ConvertToScreen_TextPosition(string text, vector position, float lettersize) +{ + vector pos, sz; + sz_x = sz_y = lettersize; + pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); + pos_x -= stringwidth(text, FALSE, sz) * 0.5; + pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); + pos_y -= sz_y / 2; + return pos; +} + +void Sbar_DrawPic(string pic, vector position, vector dimensions, float background) +{ + vector pos, sz; + pos = Sbar_ConvertToScreen_PicPosition(position, dimensions); + sz = Sbar_ConvertToScreen_PicScale(dimensions); if(background) { @@ -96,11 +120,8 @@ void Sbar_DrawPic(string pic, vector position, vector dimensions, float backgrou void Sbar_DrawString(string text, vector position, float lettersize) { vector pos, sz; + pos = Sbar_ConvertToScreen_TextPosition(text, position, lettersize); sz_x = sz_y = lettersize; - pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); - pos_x -= stringwidth(text, FALSE, sz) * 0.5; - pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); - pos_y -= sz_y / 2; drawstring(pos, text, sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } @@ -152,11 +173,8 @@ void Sbar_DrawXNum (vector position, float num, float digits, float showminusplu final_num = strcat(final_num, str); vector pos, sz; + pos = Sbar_ConvertToScreen_TextPosition(final_num, position, lettersize); sz_x = sz_y = lettersize; - pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); - pos_x -= stringwidth(final_num, FALSE, sz) * 0.5; - pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); - pos_y -= sz_y / 2; drawstring(pos, final_num, sz, rgb, alpha, dflags); } @@ -745,6 +763,44 @@ string Sbar_GetStomachFieldPred(entity pl, float field) //return "error"; } +vector Sbar_GetVoreColor() +{ + // gets color based on vore status + if(getstati(STAT_VORE_EATEN)) + { + if(teamplay && (GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(player_localentnum - 1) || GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(spectatee_status - 1))) // same team + return stov(cvar_string("sbar_stomachboard_color2")); + else + return stov(cvar_string("sbar_stomachboard_color3")); + } + else + return stov(cvar_string("sbar_stomachboard_color1")); +} + +vector colorfade_current; +vector Sbar_ColorFade(vector target_color) +{ + local float step; + step = cvar("sbar_stomachboard_status_fade") * frametime; + + if(colorfade_current_x >= target_color_x + step) + colorfade_current_x -= step; + else if(colorfade_current_x <= target_color_x - step) + colorfade_current_x += step; + + if(colorfade_current_y >= target_color_y + step) + colorfade_current_y -= step; + else if(colorfade_current_y <= target_color_y - step) + colorfade_current_y += step; + + if(colorfade_current_z >= target_color_z + step) + colorfade_current_z -= step; + else if(colorfade_current_z <= target_color_z - step) + colorfade_current_z += step; + + return colorfade_current; +} + float xmin, xmax, ymin, ymax, sbwidth; float sbar_fixscoreboardcolumnwidth_len; float sbar_fixscoreboardcolumnwidth_iconlen; @@ -949,23 +1005,22 @@ void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_num } } -float fieldcounter; void Sbar_PrintStomachboardItem(entity pl, vector position, vector dimensions) { // lists all players in the stomach string str; float f, field, field_number; - vector hl_color; field_number = 3; // the number of components each row has - // center defined position on the x axis - position_x -= dimensions_x / 2; + position = Sbar_ConvertToScreen_PicPosition(position, dimensions); + dimensions = Sbar_ConvertToScreen_PicScale(dimensions); // set font size to the height of each entry vector font_sz; font_sz_x = font_sz_y = dimensions_y; + float fieldcounter; for(fieldcounter = 1; fieldcounter <= field_number; ++fieldcounter) { vector pos, sz; @@ -978,16 +1033,7 @@ void Sbar_PrintStomachboardItem(entity pl, vector position, vector dimensions) pos = position; sz = dimensions; - if(getstati(STAT_VORE_EATEN)) - { - if(teamplay && (GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(player_localentnum - 1) || GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(spectatee_status - 1))) // same team - hl_color = stov(cvar_string("sbar_stomachboard_color2")); - else - hl_color = stov(cvar_string("sbar_stomachboard_color3")); - } - else - hl_color = stov(cvar_string("sbar_stomachboard_color1")); - drawfill(pos, sz, hl_color, cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL); + drawfill(pos, sz, Sbar_ColorFade(Sbar_GetVoreColor()), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL); } if(field == ST_NAME) { @@ -1022,27 +1068,26 @@ void Sbar_PrintStomachboardItem(entity pl, vector position, vector dimensions) } } -float fieldcounter2; void Sbar_PrintStomachboardItemPred(entity pl, vector position, vector dimensions) { // shows the name of our predator string str; float f, field, field_number; - vector hl_color; field_number = 2; // the number of components each row has - // center defined position on the x axis - position_x -= dimensions_x / 2; + position = Sbar_ConvertToScreen_PicPosition(position, dimensions); + dimensions = Sbar_ConvertToScreen_PicScale(dimensions); // set font size to the height of each entry vector font_sz; font_sz_x = font_sz_y = dimensions_y; - for(fieldcounter2 = 1; fieldcounter2 <= field_number; ++fieldcounter2) + float fieldcounter; + for(fieldcounter = 1; fieldcounter <= field_number; ++fieldcounter) { vector pos, sz; - field = -fieldcounter2; + field = -fieldcounter; str = Sbar_GetStomachFieldPred(pl, field); // row highlighting @@ -1051,16 +1096,7 @@ void Sbar_PrintStomachboardItemPred(entity pl, vector position, vector dimension pos = position; sz = dimensions; - if(getstati(STAT_VORE_EATEN)) - { - if(teamplay && (GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(player_localentnum - 1) || GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(spectatee_status - 1))) // same team - hl_color = stov(cvar_string("sbar_stomachboard_color2")); - else - hl_color = stov(cvar_string("sbar_stomachboard_color3")); - } - else - hl_color = stov(cvar_string("sbar_stomachboard_color1")); - drawfill(pos, sz, hl_color, cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL); + drawfill(pos, sz, Sbar_ColorFade(Sbar_GetVoreColor()), cvar("sbar_stomachboard_highlight_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL); } if(field == STP_NAME) { @@ -2919,30 +2955,6 @@ float vote_prev; // previous state of vote_active to check for a change float vote_alpha; float vote_change; // "time" when vote_active changed -vector stomachstatus_colorfade_current; -vector StomachStatus_ColorFade(vector target_color) -{ - local float step; - step = cvar("sbar_stomachboard_status_fade") * frametime; - - if(stomachstatus_colorfade_current_x >= target_color_x + step) - stomachstatus_colorfade_current_x -= step; - else if(stomachstatus_colorfade_current_x <= target_color_x - step) - stomachstatus_colorfade_current_x += step; - - if(stomachstatus_colorfade_current_y >= target_color_y + step) - stomachstatus_colorfade_current_y -= step; - else if(stomachstatus_colorfade_current_y <= target_color_y - step) - stomachstatus_colorfade_current_y += step; - - if(stomachstatus_colorfade_current_z >= target_color_z + step) - stomachstatus_colorfade_current_z -= step; - else if(stomachstatus_colorfade_current_z <= target_color_z - step) - stomachstatus_colorfade_current_z += step; - - return stomachstatus_colorfade_current; -} - void Sbar_Draw (void) { // vectors for top right, bottom right, bottom and bottom left corners @@ -3202,7 +3214,7 @@ void Sbar_Draw (void) Sbar_Reset(); - StomachStatus_ColorFade('0 0 0'); + Sbar_ColorFade('0 0 0'); } else { @@ -3253,23 +3265,7 @@ void Sbar_Draw (void) } } - vector hl_color; - string hl_string; - if(getstati(STAT_VORE_EATEN)) - { - if(teamplay && (GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(player_localentnum - 1) || GetPlayerColor(getstati(STAT_VORE_EATEN) - 1) == GetPlayerColor(spectatee_status - 1))) // same team - hl_color = stov(cvar_string("sbar_stomachboard_color2")); - else - hl_color = stov(cvar_string("sbar_stomachboard_color3")); - hl_string = "predator:"; - } - else - { - hl_color = stov(cvar_string("sbar_stomachboard_color1")); - hl_string = "self:"; - } - drawpic(bottomleft - '0 256 0', "gfx/hud/bg_stomach_status", '256 256 0', StomachStatus_ColorFade(hl_color), cvar("sbar_stomachboard_status_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(bottomleft - '-80 173 0', hl_string, '11 11 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawpic(bottomleft - '0 256 0', "gfx/hud/bg_stomach_status", '256 256 0', Sbar_ColorFade(Sbar_GetVoreColor()), cvar("sbar_stomachboard_status_alpha") * sbar_alpha_fg, DRAWFLAG_NORMAL); float stomach_load, stomach_maxload; // shows the predator's stomach load when we are eaten, and ours otherwise stomach_load = getstati(STAT_VORE_LOAD); @@ -3308,6 +3304,7 @@ void Sbar_Draw (void) hud_total_prey = 0; pos = stov(cvar_string("hud_item_preylist_position")); vector sz = stov(cvar_string("hud_item_preylist_scale")); + vector dir = stov(cvar_string("hud_item_preylist_entry_spacing")) * 2; for(pl = players.sort_next; pl; pl = pl.sort_next) { if(pl.team == COLOR_SPECTATOR) @@ -3325,12 +3322,13 @@ void Sbar_Draw (void) if(f) { - if(l < cvar("hud_item_preylist_entries")) // limit the stomach board to the given number of entries + if(l < cvar("hud_item_preylist_entry_number")) // limit the stomach board to the given number of entries { Sbar_PrintStomachboardItem(pl, pos, sz); - // advance y position for each entry - pos_y += sz_y * cvar("hud_item_preylist_spacing"); + // advance position for each entry + pos_x += sz_x * dir_x; + pos_y += sz_y * dir_y; l += 1; } ++hud_total_prey;