==================
*/
-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;
}
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);
}
}
- 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);
}
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);
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)
}
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;
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);
}
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;
}