Color code weapon gauges

This commit is contained in:
Kp 2012-11-04 02:52:44 +00:00
parent 6e722eb789
commit 94ce68f556

View file

@ -1152,9 +1152,129 @@ static void draw_primary_ammo_info(int ammo_count)
draw_ammo_info(PRIMARY_AMMO_X,PRIMARY_AMMO_Y,ammo_count,1);
}
static void hud_set_fontcolor_red()
{
gr_set_fontcolor(BM_XRGB(20,0,0),-1);
}
static void hud_set_fontcolor_yellow()
{
gr_set_fontcolor(BM_XRGB(15,15,0),-1);
}
static void hud_set_fontcolor_green()
{
gr_set_fontcolor(BM_XRGB(0,15,0),-1);
}
static void hud_set_fontcolor_dimgreen()
{
gr_set_fontcolor(BM_XRGB(0,6,0),-1);
}
static void hud_set_fontcolor_gray()
{
gr_set_fontcolor(BM_XRGB(3,3,3),-1);
}
static void hud_set_primary_weapon_fontcolor(const int consider_weapon)
{
if (Primary_weapon==consider_weapon)
hud_set_fontcolor_red();
else{
if (player_has_weapon(consider_weapon,0) & HAS_WEAPON_FLAG)
{
const int is_super = (consider_weapon >= 5);
#if defined(DXX_BUILD_DESCENT_II)
const int base_weapon = is_super ? consider_weapon - 5 : consider_weapon;
if (Primary_last_was_super[base_weapon])
{
if (is_super)
hud_set_fontcolor_green();
else
hud_set_fontcolor_yellow();
}
else
#endif
{
if (is_super)
hud_set_fontcolor_yellow();
else
hud_set_fontcolor_green();
}
}
else
hud_set_fontcolor_gray();
}
}
static void hud_set_secondary_weapon_fontcolor(const int consider_weapon)
{
if (Secondary_weapon==consider_weapon)
hud_set_fontcolor_red();
else{
if (Players[Player_num].secondary_ammo[consider_weapon]>0)
{
const int is_super = (consider_weapon >= 5);
#if defined(DXX_BUILD_DESCENT_II)
const int base_weapon = is_super ? consider_weapon - 5 : consider_weapon;
if (Secondary_last_was_super[base_weapon])
{
if (is_super)
hud_set_fontcolor_green();
else
hud_set_fontcolor_yellow();
}
else
#endif
{
if (is_super)
hud_set_fontcolor_yellow();
else
hud_set_fontcolor_green();
}
}
else
hud_set_fontcolor_dimgreen();
}
}
static void hud_printf_vulcan_ammo(const int x, const int y)
{
if (PlayerCfg.CockpitMode[1]!=CM_FULL_SCREEN)
return;
const unsigned primary_weapon_flags = Players[Player_num].primary_weapon_flags;
const unsigned vulcan_mask = 1 << VULCAN_INDEX;
#if defined(DXX_BUILD_DESCENT_I)
const unsigned gauss_mask = 0;
#elif defined(DXX_BUILD_DESCENT_II)
const unsigned gauss_mask = 1 << GAUSS_INDEX;
#endif
const int fmt_vulcan_ammo = f2i((unsigned int)Players[Player_num].vulcan_ammo * VULCAN_AMMO_SCALE);
const unsigned has_weapon_uses_vulcan_ammo = (primary_weapon_flags & (gauss_mask | vulcan_mask));
if (!has_weapon_uses_vulcan_ammo && !fmt_vulcan_ammo)
return;
if (weapon_index_uses_vulcan_ammo(Primary_weapon))
hud_set_fontcolor_red();
else if (has_weapon_uses_vulcan_ammo)
hud_set_fontcolor_green();
else
hud_set_fontcolor_gray();
char c;
#if defined(DXX_BUILD_DESCENT_II)
if ((primary_weapon_flags & gauss_mask) && Primary_last_was_super[VULCAN_INDEX])
c = 'G';
else
#endif
if (primary_weapon_flags & vulcan_mask)
c = 'V';
else
c = 'A';
gr_printf(x,y,"%c:%i", c, fmt_vulcan_ammo);
}
static void hud_show_weapons_mode(int type,int vertical,int orig_x,int orig_y){
int i,w,h,aw,x=orig_x,y=orig_y;
char weapon_str[10];
if (vertical){
y=y+(LINE_SPACING*4);
@ -1162,58 +1282,51 @@ static void hud_show_weapons_mode(int type,int vertical,int orig_x,int orig_y){
if (type==0){
for (i=4;i>=0;i--){
if (Primary_weapon==i)
gr_set_fontcolor(BM_XRGB(20,0,0),-1);
else{
if (player_has_weapon(i,0) & HAS_WEAPON_FLAG)
gr_set_fontcolor(BM_XRGB(0,15,0),-1);
else
gr_set_fontcolor(BM_XRGB(3,3,3),-1);
}
const char *txtweapon;
char weapon_str[10];
hud_set_primary_weapon_fontcolor(i);
switch(i){
case 0:
sprintf(weapon_str,"%c%i",
(Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)?'Q':'L',
Players[Player_num].laser_level+1);
snprintf(weapon_str, sizeof(weapon_str), "%c%i", (Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)?'Q':'L', Players[Player_num].laser_level+1);
txtweapon = weapon_str;
break;
case 1:
#if defined(DXX_BUILD_DESCENT_I)
if (PlayerCfg.CockpitMode[1]==CM_FULL_SCREEN)
{
sprintf(weapon_str,"V%i", f2i(Players[Player_num].vulcan_ammo * VULCAN_AMMO_SCALE));
txtweapon = weapon_str;
}
else
#endif
sprintf(weapon_str,"V");
txtweapon = "V";
break;
case 2:
sprintf(weapon_str,"S");break;
txtweapon = "S";
break;
case 3:
sprintf(weapon_str,"P");break;
txtweapon = "P";
break;
case 4:
sprintf(weapon_str,"F");break;
txtweapon = "F";
break;
}
gr_get_string_size(weapon_str, &w, &h, &aw );
gr_get_string_size(txtweapon, &w, &h, &aw );
if (vertical){
y-=h+FSPACY(2);
}else
x-=w+FSPACX(3);
gr_string(x, y, weapon_str);
#if defined(DXX_BUILD_DESCENT_II)
if (i == 1 && Primary_weapon == i && PlayerCfg.CockpitMode[1]==CM_FULL_SCREEN)
gr_printf(x,y-(LINE_SPACING*1),"V:%i",f2i((unsigned int)Players[Player_num].vulcan_ammo * VULCAN_AMMO_SCALE));
#endif
gr_string(x, y, txtweapon);
if (i == 1 && !vertical)
{
hud_printf_vulcan_ammo(x, y - (LINE_SPACING * 1));
}
}
} else {
for (i=4;i>=0;i--){
if (Secondary_weapon==i)
gr_set_fontcolor(BM_XRGB(20,0,0),-1);
else{
if (Players[Player_num].secondary_ammo[i]>0)
gr_set_fontcolor(BM_XRGB(0,15,0),-1);
else
gr_set_fontcolor(BM_XRGB(0,6,0),-1);
}
sprintf(weapon_str,"%i",Players[Player_num].secondary_ammo[i]);
char weapon_str[10];
hud_set_secondary_weapon_fontcolor(i);
snprintf(weapon_str,sizeof(weapon_str),"%i",Players[Player_num].secondary_ammo[i]);
gr_get_string_size(weapon_str, &w, &h, &aw );
if (vertical){
y-=h+FSPACY(2);
@ -1238,53 +1351,50 @@ static void hud_show_weapons_mode(int type,int vertical,int orig_x,int orig_y){
if (type==0) {
for (i=9;i>=5;i--){
if (Primary_weapon==i)
gr_set_fontcolor(BM_XRGB(20,0,0),-1);
else{
if (player_has_weapon(i,0) & HAS_WEAPON_FLAG)
gr_set_fontcolor(BM_XRGB(0,15,0),-1);
else
gr_set_fontcolor(BM_XRGB(3,3,3),-1);
}
const char *txtweapon;
char weapon_str[10];
hud_set_primary_weapon_fontcolor(i);
switch(i){
case 5:
sprintf(weapon_str," ");
txtweapon = " ";
break;
case 6:
sprintf(weapon_str,"G");
txtweapon = "G";
break;
case 7:
sprintf(weapon_str,"H");break;
txtweapon = "H";
break;
case 8:
sprintf(weapon_str,"P");break;
txtweapon = "P";
break;
case 9:
if (PlayerCfg.CockpitMode[1]==CM_FULL_SCREEN)
sprintf(weapon_str, "O%03i", Omega_charge * 100/MAX_OMEGA_CHARGE);
{
snprintf(weapon_str, sizeof(weapon_str), "O%03i", Omega_charge * 100/MAX_OMEGA_CHARGE);
txtweapon = weapon_str;
}
else
sprintf(weapon_str,"O");
txtweapon = "O";
break;
}
gr_get_string_size(weapon_str, &w, &h, &aw );
gr_get_string_size(txtweapon, &w, &h, &aw );
if (vertical){
y-=h+FSPACY(2);
}else
x-=w+FSPACX(3);
gr_string(x, y, weapon_str);
if (i == 6 && Primary_weapon == i && PlayerCfg.CockpitMode[1]==CM_FULL_SCREEN)
gr_printf(x+FSPACX(9),y-(LINE_SPACING*2),"G:%i",f2i((unsigned int)Players[Player_num].vulcan_ammo * VULCAN_AMMO_SCALE));
if (i == 5)
{
if (vertical)
hud_printf_vulcan_ammo(x, y);
continue;
}
gr_string(x, y, txtweapon);
}
} else {
for (i=9;i>=5;i--){
if (Secondary_weapon==i)
gr_set_fontcolor(BM_XRGB(20,0,0),-1);
else{
if (Players[Player_num].secondary_ammo[i]>0)
gr_set_fontcolor(BM_XRGB(0,15,0),-1);
else
gr_set_fontcolor(BM_XRGB(0,6,0),-1);
}
sprintf(weapon_str,"%i",Players[Player_num].secondary_ammo[i]);
char weapon_str[10];
hud_set_secondary_weapon_fontcolor(i);
snprintf(weapon_str,sizeof(weapon_str),"%i",Players[Player_num].secondary_ammo[i]);
gr_get_string_size(weapon_str, &w, &h, &aw );
if (vertical){
y-=h+FSPACY(2);