From: terencehill Date: Fri, 5 Jun 2020 12:11:14 +0000 (+0200) Subject: Clean up and improve HUD_Get_Num_Color so that it can be used by crosshair_color_spec... X-Git-Tag: xonotic-v0.8.5~945 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6442b14758edee68d85a6047b5a384c10d88cab8;p=xonotic%2Fxonotic-data.pk3dir.git Clean up and improve HUD_Get_Num_Color so that it can be used by crosshair_color_special 2 --- diff --git a/qcsrc/client/hud/hud.qc b/qcsrc/client/hud/hud.qc index 91770fd72..bbb49199f 100644 --- a/qcsrc/client/hud/hud.qc +++ b/qcsrc/client/hud/hud.qc @@ -28,48 +28,45 @@ Misc HUD functions ================== */ -vector HUD_Get_Num_Color (float hp, float maxvalue) +vector HUD_Get_Num_Color(float hp, float maxvalue, bool blink) { - float blinkingamt; + const vector COLOR100 = '0 1 0'; // green + const vector COLOR75 = '0.4 0.9 0'; // lightgreen + const vector COLOR50 = '1 1 1'; // white + const vector COLOR25 = '1 1 0.2'; // lightyellow + const vector COLOR10 = '1 0 0'; // red vector color; - if(hp >= maxvalue) { - color.x = sin(2*M_PI*time); - color.y = 1; - color.z = sin(2*M_PI*time); - } - else if(hp > maxvalue * 0.75) { - color.x = 0.4 - (hp-150)*0.02 * 0.4; //red value between 0.4 -> 0 - color.y = 0.9 + (hp-150)*0.02 * 0.1; // green value between 0.9 -> 1 - color.z = 0; - } - else if(hp > maxvalue * 0.5) { - color.x = 1 - (hp-100)*0.02 * 0.6; //red value between 1 -> 0.4 - color.y = 1 - (hp-100)*0.02 * 0.1; // green value between 1 -> 0.9 - color.z = 1 - (hp-100)*0.02; // blue value between 1 -> 0 - } - else if(hp > maxvalue * 0.25) { - color.x = 1; - color.y = 1; - color.z = 0.2 + (hp-50)*0.02 * 0.8; // blue value between 0.2 -> 1 - } - else if(hp > maxvalue * 0.1) { - color.x = 1; - color.y = (hp-20)*90/27/100; // green value between 0 -> 1 - color.z = (hp-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2 - } - else { - color.x = 1; - color.y = 0; - color.z = 0; - } - blinkingamt = (1 - hp/maxvalue/0.25); - if(blinkingamt > 0) + float hp_percent = hp / maxvalue * 100; + #define CASE_COLOR_BETWEEN(min, max) \ + if(hp_percent > min) \ + color = COLOR##min + (COLOR##max - COLOR##min) * ((hp_percent - min) / (max - min)) + + if(hp_percent > 100) color = COLOR100; + else CASE_COLOR_BETWEEN(75, 100); + else CASE_COLOR_BETWEEN(50, 75); + else CASE_COLOR_BETWEEN(25, 50); + else CASE_COLOR_BETWEEN(10, 25); + else color = COLOR10; + + #undef CASE_COLOR_BETWEEN + + if (blink) { - color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time); - color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time); - color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time); + if(hp_percent >= 100) + { + float f = sin(2*M_PI*time); + if (color.x == 0) color.x = f; + if (color.y == 0) color.y = f; + if (color.z == 0) color.z = f; + } + else if(hp_percent < 25) + { + float f = (1 - hp_percent / 25) * sin(2*M_PI*time); + color -= color * f; + } } + return color; } diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index 38ca8a018..f93033f07 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -59,7 +59,7 @@ float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary); void HUD_Radar_Hide_Maximized(); float HUD_GetRowCount(int item_count, vector size, float item_aspect); -vector HUD_Get_Num_Color (float hp, float maxvalue); +vector HUD_Get_Num_Color(float hp, float maxvalue, bool blink); void DrawNumIcon(vector myPos, vector mySize, float theTime, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha); void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp); void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag); diff --git a/qcsrc/client/hud/panel/engineinfo.qc b/qcsrc/client/hud/panel/engineinfo.qc index 1c59e6c78..85d425977 100644 --- a/qcsrc/client/hud/panel/engineinfo.qc +++ b/qcsrc/client/hud/panel/engineinfo.qc @@ -72,7 +72,6 @@ void HUD_EngineInfo() } } - vector color; - color = HUD_Get_Num_Color (prevfps, 100); + vector color = HUD_Get_Num_Color(prevfps, 100, true); drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL); } diff --git a/qcsrc/client/hud/panel/healtharmor.qc b/qcsrc/client/hud/panel/healtharmor.qc index b1a931193..d6bf99fd6 100644 --- a/qcsrc/client/hud/panel/healtharmor.qc +++ b/qcsrc/client/hud/panel/healtharmor.qc @@ -132,7 +132,7 @@ void HUD_HealthArmor() drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "health", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); } if(autocvar_hud_panel_healtharmor_text) - DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal), 1); + DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal, true), 1); if(fuel) HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); @@ -229,7 +229,7 @@ void HUD_HealthArmor() HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL); } if(autocvar_hud_panel_healtharmor_text) - DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1); + DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth, true), 1); } //if(armor) @@ -276,7 +276,7 @@ void HUD_HealthArmor() } if(!autocvar_hud_panel_healtharmor_progressbar || p_armor) if(autocvar_hud_panel_healtharmor_text) - DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1); + DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor, true), 1); } vector cell_size = mySize; diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index a7efc181a..2b638dbbb 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -690,7 +690,7 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field) sbt_field_rgb = '1 1 1'; return ((pl.ping == 0) ? _("N/A") : "..."); // if 0 ping, either connecting or bot (either case can't show proper score) } - //sbt_field_rgb = HUD_Get_Num_Color(fps, 200); + //sbt_field_rgb = HUD_Get_Num_Color(fps, 200, true); sbt_field_rgb = '1 0 0' + '0 1 1' * (bound(0, fps, 60) / 60); return ftos(fps); } diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index cb6b623ec..5b07cdb21 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1016,47 +1016,8 @@ vector crosshair_getcolor(entity this, float health_stat) case 2: // color based on health and armor { vector v = healtharmor_maxdamage(health_stat, STAT(ARMOR), armorblockpercent, DEATH_WEAPON.m_id); - float hp = floor(v.x + 1); - - //x = red - //y = green - //z = blue - - wcross_color.z = 0; - - if(hp > 200) - { - wcross_color.x = 0; - wcross_color.y = 1; - } - else if(hp > 150) - { - wcross_color.x = 0.4 - (hp-150)*0.02 * 0.4; - wcross_color.y = 0.9 + (hp-150)*0.02 * 0.1; - } - else if(hp > 100) - { - wcross_color.x = 1 - (hp-100)*0.02 * 0.6; - wcross_color.y = 1 - (hp-100)*0.02 * 0.1; - wcross_color.z = 1 - (hp-100)*0.02; - } - else if(hp > 50) - { - wcross_color.x = 1; - wcross_color.y = 1; - wcross_color.z = 0.2 + (hp-50)*0.02 * 0.8; - } - else if(hp > 20) - { - wcross_color.x = 1; - wcross_color.y = (hp-20)*90/27/100; - wcross_color.z = (hp-20)*90/27/100 * 0.2; - } - else - { - wcross_color.x = 1; - wcross_color.y = 0; - } + float health_and_armor = floor(v.x + 1); + wcross_color = HUD_Get_Num_Color(health_and_armor, 200, false); break; }