From: otta8634 Date: Sat, 14 Dec 2024 04:15:12 +0000 (+0800) Subject: Add code to support adding handicap icon to scoreboard X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6fde3adc5a678f45b1782580ab757d80d57f9185;p=xonotic%2Fxonotic-data.pk3dir.git Add code to support adding handicap icon to scoreboard Currently it's disabled with an if (false), since handicap isn't yet networked to the client. - This commit will be followed up by networking handicap to the client and enabling showing the icon. Added handicap icon, based on https://commons.wikimedia.org/wiki/File:Wheelchair_symbol.svg, ... modified with Inkscape to be more consistent with other HUD icons like mediasource's gfx/luma/gfx/scoreboard/player_ready.svg - Resized to be 32x32 with 3px padding around all edges (and thus made it be "square"). - Made the lines thicker, and extended the foot-rest. - Increased the size of the gap between the frame and the wheel. - Removed the arm-rest. - Mostly properly aligned the head to the right. Scoreboard changes: - Now player_ready and playercolors can be shown simultaneously, side-by-side. - Support for this was added with sbt_field_icon_extra*. In future it may be worthwhile considering making the extra icons align right, I think that would look better. --- diff --git a/gfx/scoreboard/player_handicap.tga b/gfx/scoreboard/player_handicap.tga new file mode 100644 index 000000000..180ac90db Binary files /dev/null and b/gfx/scoreboard/player_handicap.tga differ diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index af56134c2..6bf269152 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -973,19 +973,21 @@ string Scoreboard_AddPlayerId(string pl_name, entity pl) // MOVEUP:: vector sbt_field_rgb; -string sbt_field_icon0; -string sbt_field_icon1; -string sbt_field_icon2; -vector sbt_field_icon0_rgb; -vector sbt_field_icon1_rgb; -vector sbt_field_icon2_rgb; +// these are drawn overlapping +string sbt_field_icon_playercolor0; +string sbt_field_icon_playercolor1; +string sbt_field_icon_playercolor2; +vector sbt_field_icon_playercolor0_rgb; +vector sbt_field_icon_playercolor1_rgb; +vector sbt_field_icon_playercolor2_rgb; +// these are drawn side-by-side, next to playercolor (if present) +string sbt_field_icon_extra0; // player_ready +string sbt_field_icon_extra1; // player_handicap +vector sbt_field_icon_extra0_rgb; +vector sbt_field_icon_extra1_rgb; string Scoreboard_GetName(entity pl) { - if(ready_waiting && pl.ready) - { - sbt_field_icon0 = "gfx/scoreboard/player_ready"; - } - else if(!teamplay) + if (!teamplay) { int f; // NOTE: always adding 1024 allows saving the colormap 0 as a value != 0 @@ -994,13 +996,20 @@ string Scoreboard_GetName(entity pl) else f = entcs_GetClientColors(pl.sv_entnum); - { - sbt_field_icon0 = "gfx/scoreboard/playercolor_base"; - sbt_field_icon1 = "gfx/scoreboard/playercolor_shirt"; - sbt_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0); - sbt_field_icon2 = "gfx/scoreboard/playercolor_pants"; - sbt_field_icon2_rgb = colormapPaletteColor(f % 16, 1); - } + sbt_field_icon_playercolor0 = "gfx/scoreboard/playercolor_base"; + sbt_field_icon_playercolor1 = "gfx/scoreboard/playercolor_shirt"; + sbt_field_icon_playercolor1_rgb = colormapPaletteColor(floor(f / 16), 0); + sbt_field_icon_playercolor2 = "gfx/scoreboard/playercolor_pants"; + sbt_field_icon_playercolor2_rgb = colormapPaletteColor(f % 16, 1); + } + if (ready_waiting && pl.ready) + { + sbt_field_icon_extra0 = "gfx/scoreboard/player_ready"; + } + if (false) // TODO + { + sbt_field_icon_extra1 = "gfx/scoreboard/player_handicap"; + sbt_field_icon_extra1_rgb = '1 1 1'; } return entcs_GetName(pl.sv_entnum); } @@ -1027,12 +1036,16 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field, bool per_round) int f; string str; sbt_field_rgb = '1 1 1'; - sbt_field_icon0 = ""; - sbt_field_icon1 = ""; - sbt_field_icon2 = ""; - sbt_field_icon0_rgb = '1 1 1'; - sbt_field_icon1_rgb = '1 1 1'; - sbt_field_icon2_rgb = '1 1 1'; + sbt_field_icon_playercolor0 = ""; + sbt_field_icon_playercolor1 = ""; + sbt_field_icon_playercolor2 = ""; + sbt_field_icon_extra0 = ""; + sbt_field_icon_extra1 = ""; + sbt_field_icon_playercolor0_rgb = '1 1 1'; + sbt_field_icon_playercolor1_rgb = '1 1 1'; + sbt_field_icon_playercolor2_rgb = '1 1 1'; + sbt_field_icon_extra0_rgb = '1 1 1'; + sbt_field_icon_extra1_rgb = '1 1 1'; int rounds_played = 0; if (per_round) rounds_played = pl.(scores(SP_ROUNDS_PL)); @@ -1170,7 +1183,9 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field, bool per_round) } float sbt_fixcolumnwidth_len; -float sbt_fixcolumnwidth_iconlen; +float sbt_fixcolumnwidth_iconlen_playercolor; +float sbt_fixcolumnwidth_iconlen_extra0; +float sbt_fixcolumnwidth_iconlen_extra1; float sbt_fixcolumnwidth_marginlen; string Scoreboard_FixColumnWidth(int i, string str, bool init) @@ -1179,37 +1194,55 @@ string Scoreboard_FixColumnWidth(int i, string str, bool init) float f; vector sz; - sbt_fixcolumnwidth_iconlen = 0; + sbt_fixcolumnwidth_iconlen_playercolor = 0; + sbt_fixcolumnwidth_iconlen_extra0 = 0; + sbt_fixcolumnwidth_iconlen_extra1 = 0; - if(sbt_field_icon0 != "") + if(sbt_field_icon_playercolor0 != "") { - sz = draw_getimagesize(sbt_field_icon0); + sz = draw_getimagesize(sbt_field_icon_playercolor0); f = sz.x / sz.y; - if(sbt_fixcolumnwidth_iconlen < f) - sbt_fixcolumnwidth_iconlen = f; + if(sbt_fixcolumnwidth_iconlen_playercolor < f) + sbt_fixcolumnwidth_iconlen_playercolor = f; } - - if(sbt_field_icon1 != "") + if(sbt_field_icon_playercolor1 != "") { - sz = draw_getimagesize(sbt_field_icon1); + sz = draw_getimagesize(sbt_field_icon_playercolor1); f = sz.x / sz.y; - if(sbt_fixcolumnwidth_iconlen < f) - sbt_fixcolumnwidth_iconlen = f; + if(sbt_fixcolumnwidth_iconlen_playercolor < f) + sbt_fixcolumnwidth_iconlen_playercolor = f; } - - if(sbt_field_icon2 != "") + if(sbt_field_icon_playercolor2 != "") { - sz = draw_getimagesize(sbt_field_icon2); + sz = draw_getimagesize(sbt_field_icon_playercolor2); f = sz.x / sz.y; - if(sbt_fixcolumnwidth_iconlen < f) - sbt_fixcolumnwidth_iconlen = f; + if(sbt_fixcolumnwidth_iconlen_playercolor < f) + sbt_fixcolumnwidth_iconlen_playercolor = f; } - - if(sbt_fixcolumnwidth_iconlen != 0) + // NOTE: extra icons (player_ready and player_handicap) are squares (32x32), so this may not be necessary + // simply setting sbt_fixcolumnwidth_iconlen_extra* = 1 would be equivalent + if(sbt_field_icon_extra0 != "") { - sbt_fixcolumnwidth_iconlen *= hud_fontsize.y / hud_fontsize.x; // fix icon aspect - sbt_fixcolumnwidth_marginlen = stringwidth(" ", false, hud_fontsize); + sz = draw_getimagesize(sbt_field_icon_extra0); + sbt_fixcolumnwidth_iconlen_extra0 = sz.x / sz.y; + } + if(sbt_field_icon_extra1 != "") + { + sz = draw_getimagesize(sbt_field_icon_extra1); + sbt_fixcolumnwidth_iconlen_extra1 = sz.x / sz.y; } + + if(sbt_fixcolumnwidth_iconlen_playercolor != 0) + sbt_fixcolumnwidth_iconlen_playercolor *= hud_fontsize.y / hud_fontsize.x; // fix icon aspect + if(sbt_fixcolumnwidth_iconlen_extra0 != 0) + sbt_fixcolumnwidth_iconlen_extra0 *= hud_fontsize.y / hud_fontsize.x; // fix icon aspect + if(sbt_fixcolumnwidth_iconlen_extra1 != 0) + sbt_fixcolumnwidth_iconlen_extra1 *= hud_fontsize.y / hud_fontsize.x; // fix icon aspect + + if(sbt_fixcolumnwidth_iconlen_playercolor != 0 + || sbt_fixcolumnwidth_iconlen_extra0 != 0 + || sbt_fixcolumnwidth_iconlen_extra1 != 0) + sbt_fixcolumnwidth_marginlen = stringwidth(" ", false, hud_fontsize); else sbt_fixcolumnwidth_marginlen = 0; @@ -1219,20 +1252,22 @@ string Scoreboard_FixColumnWidth(int i, string str, bool init) if(sbt_field[i] == SP_NAME) // name gets all remaining space { int j; - float remaining_space = 0; + float used_space = 0; for(j = 0; j < sbt_num_fields; ++j) if(j != i) if (sbt_field[i] != SP_SEPARATOR) - remaining_space += sbt_field_size[j] + hud_fontsize.x; - sbt_field_size[i] = max(sbt_field_title_width[i], panel_size.x - remaining_space); - - if (sbt_fixcolumnwidth_iconlen != 0) - remaining_space += sbt_fixcolumnwidth_marginlen + sbt_fixcolumnwidth_iconlen * hud_fontsize.x; - float namesize = max(sbt_field_title_width[i], panel_size.x - remaining_space); + used_space += sbt_field_size[j] + hud_fontsize.x; + sbt_field_size[i] = max(sbt_field_title_width[i], panel_size.x - used_space); + + used_space += sbt_fixcolumnwidth_marginlen + + hud_fontsize.x * sbt_fixcolumnwidth_iconlen_playercolor + + hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra0 + + hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra1; + float namesize = max(sbt_field_title_width[i], panel_size.x - used_space); str = textShortenToWidth(str, namesize, hud_fontsize, stringwidth_colors); sbt_fixcolumnwidth_len = stringwidth(str, true, hud_fontsize); - max_namesize = max(sbt_field_title_width[i], vid_conwidth - remaining_space); + max_namesize = max(sbt_field_title_width[i], vid_conwidth - used_space); } else { @@ -1246,7 +1281,10 @@ string Scoreboard_FixColumnWidth(int i, string str, bool init) sbt_fixcolumnwidth_len = stringwidth(str, false, hud_fontsize); } - f = sbt_fixcolumnwidth_len + sbt_fixcolumnwidth_marginlen + sbt_fixcolumnwidth_iconlen * hud_fontsize.x; + f = sbt_fixcolumnwidth_len + sbt_fixcolumnwidth_marginlen + + hud_fontsize.x * sbt_fixcolumnwidth_iconlen_playercolor + + hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra0 + + hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra1; if(sbt_field_size[i] < f) sbt_field_size[i] = f; @@ -1392,6 +1430,7 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i pos.x += hud_fontsize.x * 0.5; pos.y += (1.25 - 1) / 2 * hud_fontsize.y; // center text vertically vector tmp = '0 0 0'; + vector icon_sz; int i; PlayerScoreField field; for(i = 0; i < sbt_num_fields; ++i) @@ -1410,7 +1449,10 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i pos.x += sbt_field_size[i] + hud_fontsize.x; if(field == SP_NAME) { - tmp.x = sbt_field_size[i] - hud_fontsize.x * sbt_fixcolumnwidth_iconlen - sbt_fixcolumnwidth_marginlen + hud_fontsize.x; + tmp.x = sbt_field_size[i] - sbt_fixcolumnwidth_marginlen + hud_fontsize.x + - hud_fontsize.x * sbt_fixcolumnwidth_iconlen_playercolor + - hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra0 + - hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra1; drawcolorcodedstring(pos - tmp, str, hud_fontsize, fg_alpha, DRAWFLAG_NORMAL); } else { tmp.x = sbt_fixcolumnwidth_len + hud_fontsize.x; @@ -1418,12 +1460,25 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i } tmp.x = sbt_field_size[i] + hud_fontsize.x; - if(sbt_field_icon0 != "") - drawpic(pos - tmp, sbt_field_icon0, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL); - if(sbt_field_icon1 != "") - drawpic(pos - tmp, sbt_field_icon1, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL); - if(sbt_field_icon2 != "") - drawpic(pos - tmp, sbt_field_icon2, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon2_rgb, fg_alpha, DRAWFLAG_NORMAL); + icon_sz = vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen_playercolor, hud_fontsize.y); + if(sbt_field_icon_playercolor0 != "") + drawpic(pos - tmp, sbt_field_icon_playercolor0, icon_sz, sbt_field_icon_playercolor1_rgb, fg_alpha, DRAWFLAG_NORMAL); + if(sbt_field_icon_playercolor1 != "") + drawpic(pos - tmp, sbt_field_icon_playercolor1, icon_sz, sbt_field_icon_playercolor1_rgb, fg_alpha, DRAWFLAG_NORMAL); + if(sbt_field_icon_playercolor2 != "") + drawpic(pos - tmp, sbt_field_icon_playercolor2, icon_sz, sbt_field_icon_playercolor2_rgb, fg_alpha, DRAWFLAG_NORMAL); + tmp.x -= icon_sz.x; + if(sbt_field_icon_extra0 != "") + { + icon_sz.x = hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra0; + drawpic(pos - tmp, sbt_field_icon_extra0, icon_sz, sbt_field_icon_extra0_rgb, fg_alpha, DRAWFLAG_NORMAL); + tmp.x -= icon_sz.x; + } + if(sbt_field_icon_extra1 != "") + { + icon_sz.x = hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra1; + drawpic(pos - tmp, sbt_field_icon_extra1, icon_sz, sbt_field_icon_extra1_rgb, fg_alpha, DRAWFLAG_NORMAL); + } } if(sbt_field[i] == SP_SEPARATOR) @@ -1452,12 +1507,25 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i } tmp.x = sbt_field_size[i]; - if(sbt_field_icon0 != "") - drawpic(pos - tmp, sbt_field_icon0, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL); - if(sbt_field_icon1 != "") - drawpic(pos - tmp, sbt_field_icon1, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL); - if(sbt_field_icon2 != "") - drawpic(pos - tmp, sbt_field_icon2, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon2_rgb, fg_alpha, DRAWFLAG_NORMAL); + icon_sz = vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen_playercolor, hud_fontsize.y); + if(sbt_field_icon_playercolor0 != "") + drawpic(pos - tmp, sbt_field_icon_playercolor0, icon_sz, sbt_field_icon_playercolor1_rgb, fg_alpha, DRAWFLAG_NORMAL); + if(sbt_field_icon_playercolor1 != "") + drawpic(pos - tmp, sbt_field_icon_playercolor1, icon_sz, sbt_field_icon_playercolor1_rgb, fg_alpha, DRAWFLAG_NORMAL); + if(sbt_field_icon_playercolor2 != "") + drawpic(pos - tmp, sbt_field_icon_playercolor2, icon_sz, sbt_field_icon_playercolor2_rgb, fg_alpha, DRAWFLAG_NORMAL); + tmp.x -= icon_sz.x; + if(sbt_field_icon_extra0 != "") + { + icon_sz.x = hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra0; + drawpic(pos - tmp, sbt_field_icon_extra0, icon_sz, sbt_field_icon_extra0_rgb, fg_alpha, DRAWFLAG_NORMAL); + tmp.x -= icon_sz.x; + } + if(sbt_field_icon_extra1 != "") + { + icon_sz.x = hud_fontsize.x * sbt_fixcolumnwidth_iconlen_extra1; + drawpic(pos - tmp, sbt_field_icon_extra1, icon_sz, sbt_field_icon_extra1_rgb, fg_alpha, DRAWFLAG_NORMAL); + } pos.x -= sbt_field_size[i] + hud_fontsize.x; } } diff --git a/qcsrc/server/handicap.qc b/qcsrc/server/handicap.qc index 5c03cd11b..8669897dc 100644 --- a/qcsrc/server/handicap.qc +++ b/qcsrc/server/handicap.qc @@ -88,3 +88,9 @@ float Handicap_GetTotalHandicap(entity player, bool receiving) return Handicap_GetForcedHandicap(player, receiving) * Handicap_GetVoluntaryHandicap(player, receiving); } + +float Handicap_GetTotalBidirectionalHandicap(entity player) +{ + return Handicap_GetTotalHandicap(player, true) * + Handicap_GetTotalHandicap(player, false); +} diff --git a/qcsrc/server/handicap.qh b/qcsrc/server/handicap.qh index 48129ed5c..987245f80 100644 --- a/qcsrc/server/handicap.qh +++ b/qcsrc/server/handicap.qh @@ -45,3 +45,8 @@ void Handicap_SetForcedHandicap(entity player, float value, bool receiving); /// \param[in] receiving Whether handicap is for receiving or dealing. /// \return Total handicap of the player. float Handicap_GetTotalHandicap(entity player, bool receiving); + +/// \brief Returns the total both-ways handicap of the player. +/// \param[in] player Player to check. +/// \return Total handicap of the player accounting for damage given and taken. +float Handicap_GetTotalBidirectionalHandicap(entity player);