]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sbar.c
Added the cvar sbar_alpha.
[xonotic/darkplaces.git] / sbar.c
diff --git a/sbar.c b/sbar.c
index 5c8dcefb02643449fc2637e513e38c577ed9cdd5..d2e37eba1a7f1ae5a64cf1fcb8d6dd1c0772a1c5 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -50,7 +50,8 @@ sbarpic_t *sb_scorebar;
 // AK only used by NEX(and only if everybody agrees)
 sbarpic_t *sb_sbar_overlay;
 
-sbarpic_t *sb_weapons[7][8]; // 0 is active, 1 is owned, 2-5 are flashes
+// AK changed the bound to 9
+sbarpic_t *sb_weapons[7][9]; // 0 is active, 1 is owned, 2-5 are flashes
 sbarpic_t *sb_ammo[4];
 sbarpic_t *sb_sigil[4];
 sbarpic_t *sb_armor[3];
@@ -83,6 +84,7 @@ int hipweapons[4] = {HIT_LASER_CANNON_BIT,HIT_MJOLNIR_BIT,4,HIT_PROXIMITY_GUN_BI
 sbarpic_t *hsb_items[2];
 
 cvar_t showfps = {CVAR_SAVE, "showfps", "0"};
+cvar_t sbar_alpha = {CVAR_SAVE, "sbar_alpha", "1"};
 
 void Sbar_MiniDeathmatchOverlay (void);
 void Sbar_DeathmatchOverlay (void);
@@ -136,7 +138,7 @@ void sbar_start(void)
        sb_colon = Sbar_NewPic ("gfx/num_colon");
        sb_slash = Sbar_NewPic ("gfx/num_slash");
 
-       //AK NEX uses its own hud
+       //AK NX uses its own hud
        if(gamemode == GAME_NEXUIZ)
        {
                sb_ammo[0] = Sbar_NewPic ("gfx/sb_shells");
@@ -152,6 +154,9 @@ void sbar_start(void)
                sb_sbar = Sbar_NewPic("gfx/sbar");
                sb_sbar_overlay = Sbar_NewPic("gfx/sbar_overlay");
 
+               for(i = 0; i < 9;i++)
+                       sb_weapons[0][i] = Sbar_NewPic(va("gfx/inv_weapon%i",i));
+
                return;
        }
 
@@ -287,6 +292,7 @@ void Sbar_Init (void)
        Cmd_AddCommand ("+showscores", Sbar_ShowScores);
        Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
        Cvar_RegisterVariable (&showfps);
+       Cvar_RegisterVariable (&sbar_alpha);
 
        R_RegisterModule("sbar", sbar_start, sbar_shutdown, sbar_newmap);
 }
@@ -305,12 +311,12 @@ Sbar_DrawPic
 */
 void Sbar_DrawPic (int x, int y, sbarpic_t *sbarpic)
 {
-       DrawQ_Pic (sbar_x + x, sbar_y + y, sbarpic->name, 0, 0, 1, 1, 1, 1, 0);
+       DrawQ_Pic (sbar_x + x, sbar_y + y, sbarpic->name, 0, 0, 1, 1, 1, sbar_alpha.value, 0);
 }
 
 void Sbar_DrawAlphaPic (int x, int y, sbarpic_t *sbarpic, float alpha)
 {
-       DrawQ_Pic (sbar_x + x, sbar_y + y, sbarpic->name, 0, 0, 1, 1, 1, alpha, 0);
+       DrawQ_Pic (sbar_x + x, sbar_y + y, sbarpic->name, 0, 0, 1, 1, 1, alpha * sbar_alpha.value, 0);
 }
 
 /*
@@ -322,7 +328,7 @@ Draws one solid graphics character
 */
 void Sbar_DrawCharacter (int x, int y, int num)
 {
-       DrawQ_String (sbar_x + x + 4 , sbar_y + y, va("%c", num), 0, 8, 8, 1, 1, 1, 1, 0);
+       DrawQ_String (sbar_x + x + 4 , sbar_y + y, va("%c", num), 0, 8, 8, 1, 1, 1, sbar_alpha.value, 0);
 }
 
 /*
@@ -332,7 +338,7 @@ Sbar_DrawString
 */
 void Sbar_DrawString (int x, int y, char *str)
 {
-       DrawQ_String (sbar_x + x, sbar_y + y, str, 0, 8, 8, 1, 1, 1, 1, 0);
+       DrawQ_String (sbar_x + x, sbar_y + y, str, 0, 8, 8, 1, 1, 1, sbar_alpha.value, 0);
 }
 
 /*
@@ -361,6 +367,39 @@ void Sbar_DrawNum (int x, int y, int num, int digits, int color)
 
                Sbar_DrawPic (x, y, sb_nums[color][frame]);
                x += 24;
+
+               ptr++;
+       }
+}
+
+/*
+=============
+Sbar_DrawXNum
+=============
+*/
+
+void Sbar_DrawXNum (int x, int y, int num, int digits, int lettersize, float r, float g, float b, float a, int flags)
+{
+       char str[32], *ptr;
+       int l, frame;
+
+       l = sprintf(str, "%i", num);
+       ptr = str;
+       if (l > digits)
+               ptr += (l-digits);
+       if (l < digits)
+               x += (digits-l) * lettersize;
+
+       while (*ptr)
+       {
+               if (*ptr == '-')
+                       frame = STAT_MINUS;
+               else
+                       frame = *ptr -'0';
+
+               DrawQ_Pic (sbar_x + x, sbar_y + y, sb_nums[0][frame]->name,lettersize,lettersize,r,g,b,a * sbar_alpha.value,flags);
+               x += lettersize;
+
                ptr++;
        }
 }
@@ -444,6 +483,20 @@ void Sbar_DrawScoreboard (void)
 
 //=============================================================================
 
+// AK to make DrawInventory smaller
+static void Sbar_DrawWeapon(int nr, float fade, int active)
+{
+       // width = 300, height = 100
+       const int w_width = 300, w_height = 100, w_space = 10, font_size = 10;
+       const float w_scale = 0.4;
+
+       DrawQ_Pic(vid.conwidth - (w_width + w_space) * w_scale, (w_height + w_space) * w_scale * nr + w_space, sb_weapons[0][nr]->name, w_width * w_scale, w_height * w_scale, (active) ? 1 : 0.6, active ? 1 : 0.6, active ? 1 : 1, fade * sbar_alpha.value, DRAWFLAG_ADDITIVE);
+       DrawQ_String(vid.conwidth - (w_space + font_size ), (w_height + w_space) * w_scale * nr + w_space, va("%i",nr+1), 0, font_size, font_size, 1, 0, 0, fade, 0);
+
+       if (active)
+               DrawQ_Fill(vid.conwidth - (w_width + w_space) * w_scale, (w_height + w_space) * w_scale * nr + w_space, w_width * w_scale, w_height * w_scale, 0.3, 0.3, 0.3, fade * sbar_alpha.value, DRAWFLAG_ADDITIVE);
+}
+
 /*
 ===============
 Sbar_DrawInventory
@@ -451,10 +504,34 @@ Sbar_DrawInventory
 */
 void Sbar_DrawInventory (void)
 {
-       int             i;
-       char    num[6];
-       float   time;
-       int             flashon;
+       int i;
+       char num[6];
+       float time;
+       int flashon;
+       // AK 2003
+       float fade;
+
+       if(gamemode == GAME_NEXUIZ)
+       {
+               num[0] = cl.stats[STAT_ACTIVEWEAPON];
+               // we have a max time 2s (min time = 0)
+               if ((time = cl.time - cl.weapontime) > 2)
+                       return;
+
+               fade = (1.0 - 0.5 * time);
+               fade *= fade;
+               for (i = 0; i < 8;i++)
+               {
+                       if (!(cl.items & (1 << i)))
+                               continue;
+                       Sbar_DrawWeapon(i + 1, fade, (i == num[0]));
+               }
+
+               if(!(cl.items & (1<<12)))
+                       return;
+               Sbar_DrawWeapon(0, fade, (num[0] == 12));
+               return;
+       }
 
        if (gamemode == GAME_ROGUE)
        {
@@ -621,9 +698,9 @@ void Sbar_DrawFrags (void)
 
                // draw background
                c = (qbyte *)&palette_complete[(s->colors & 0xf0) + 8];
-               DrawQ_Fill (sbar_x + x + 10, sbar_y     - 23, 28, 4, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
+               DrawQ_Fill (sbar_x + x + 10, sbar_y     - 23, 28, 4, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha.value, 0);
                c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
-               DrawQ_Fill (sbar_x + x + 10, sbar_y + 4 - 23, 28, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
+               DrawQ_Fill (sbar_x + x + 10, sbar_y + 4 - 23, 28, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha.value, 0);
 
                // draw number
                f = s->frags;
@@ -666,9 +743,9 @@ void Sbar_DrawFace (void)
                // draw background
                Sbar_DrawPic (112, 0, rsb_teambord);
                c = (qbyte *)&palette_complete[(s->colors & 0xf0) + 8];
-               DrawQ_Fill (sbar_x + 113, vid.conheight-SBAR_HEIGHT+3, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
+               DrawQ_Fill (sbar_x + 113, vid.conheight-SBAR_HEIGHT+3, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha.value, 0);
                c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
-               DrawQ_Fill (sbar_x + 113, vid.conheight-SBAR_HEIGHT+12, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
+               DrawQ_Fill (sbar_x + 113, vid.conheight-SBAR_HEIGHT+12, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha.value, 0);
 
                // draw number
                f = s->frags;
@@ -765,8 +842,8 @@ void Sbar_ShowFPS(void)
                fps_y = vid.conheight - sb_lines/* - 8*/; // yes this might draw over the sbar
                if (fps_y > vid.conheight - fps_scaley)
                        fps_y = vid.conheight - fps_scaley;
-               DrawQ_Fill(fps_x, fps_y, fps_scalex * strlen(temp), fps_scaley, 0, 0, 0, 0.5, 0);
-               DrawQ_String(fps_x, fps_y, temp, 0, fps_scalex, fps_scaley, 1, 1, 1, 1, 0);
+               DrawQ_Fill(fps_x, fps_y, fps_scalex * strlen(temp), fps_scaley, 0, 0, 0, 0.5 * sbar_alpha.value, 0);
+               DrawQ_String(fps_x, fps_y, temp, 0, fps_scalex, fps_scaley, 1, 1, 1, 1 * sbar_alpha.value, 0);
        }
 }
 
@@ -791,21 +868,21 @@ void Sbar_Draw (void)
                return;
        }
 
-       if(gamemode == GAME_NEXUIZ)
+       if (gamemode == GAME_NEXUIZ)
        {
                sbar_y = vid.conheight - 47;
                sbar_x = (vid.conwidth - 640)/2;
 
-               if (sb_lines > 24)
+               if (sb_lines)
                {
+                       Sbar_DrawInventory();
                        if (!cl.islocalgame)
                                Sbar_DrawFrags ();
                }
 
                if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
                {
-                       if (gamemode != GAME_GOODVSBAD2)
-                               Sbar_DrawAlphaPic (0, 0, sb_scorebar, 0.4);
+                       Sbar_DrawAlphaPic (0, 0, sb_scorebar, 0.4);
                        Sbar_DrawScoreboard ();
                }
                else if (sb_lines)
@@ -815,35 +892,42 @@ void Sbar_Draw (void)
                        // special items
                        if (cl.items & IT_INVULNERABILITY)
                        {
-                               Sbar_DrawNum (24, 0, 666, 3, 1);
+                               Sbar_DrawNum (36, 0, 666, 3, 1);
                                Sbar_DrawPic (0, 0, sb_disc);
                        }
 
                        // armor
-                       Sbar_DrawNum ((340-3*24), 12, cl.stats[STAT_ARMOR], 3, cl.stats[STAT_ARMOR] <= 25);
+                       Sbar_DrawXNum ((340-3*24), 12, cl.stats[STAT_ARMOR], 3, 24, 0.6,0.7,0.8,1,0);
 
                        // health
-                       Sbar_DrawNum ((154-3*24), 12, cl.stats[STAT_HEALTH], 3, cl.stats[STAT_HEALTH] <= 25);
+                       if(cl.stats[STAT_HEALTH] > 100)
+                               Sbar_DrawXNum((154-3*24),12,cl.stats[STAT_HEALTH],3,24,1,1,1,1,0);
+                       else if(cl.stats[STAT_HEALTH] <= 25 && cl.time - (int)cl.time > 0.5)
+                               Sbar_DrawXNum((154-3*24),12,cl.stats[STAT_HEALTH],3,24,0.7,0,0,1,0);
+                       else
+                               Sbar_DrawXNum((154-3*24),12,cl.stats[STAT_HEALTH],3,24,0.6,0.7,0.8,1,0);
 
-                       if (cl.items & NEX_IT_SHELLS)
-                               Sbar_DrawPic (519, 0, sb_ammo[0]);
-                       else if (cl.items & NEX_IT_BULLETS)
-                               Sbar_DrawPic (519, 0, sb_ammo[1]);
-                       else if (cl.items & NEX_IT_ROCKETS)
-                               Sbar_DrawPic (519, 0, sb_ammo[2]);
-                       else if (cl.items & NEX_IT_CELLS)
-                               Sbar_DrawPic (519, 0, sb_ammo[3]);
+                       // AK dont draw ammo for the laser
+                       if(cl.stats[STAT_ACTIVEWEAPON] != 12)
+                       {
+                               if (cl.items & NEX_IT_SHELLS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[0]);
+                               else if (cl.items & NEX_IT_BULLETS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[1]);
+                               else if (cl.items & NEX_IT_ROCKETS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[2]);
+                               else if (cl.items & NEX_IT_CELLS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[3]);
+
+                               if(cl.stats[STAT_AMMO] <= 10)
+                                       Sbar_DrawXNum ((519-3*24), 12, cl.stats[STAT_AMMO], 3, 24, 0.7, 0,0,1,0);
+                               else
+                                       Sbar_DrawXNum ((519-3*24), 12, cl.stats[STAT_AMMO], 3, 24, 0.6, 0.7,0.8,1,0);
 
-                       Sbar_DrawNum ((519-3*24), 12, cl.stats[STAT_AMMO], 3, cl.stats[STAT_AMMO] <= 10);
+                       }
 
-                       //Sbar_DrawAlphaPic(0,0,sb_sbar_overlay,0.5);
                        DrawQ_Pic(sbar_x,sbar_y,sb_sbar_overlay->name,0,0,1,1,1,1,DRAWFLAG_MODULATE);
-
                }
-
-               if (vid.conwidth > 320 && cl.gametype == GAME_DEATHMATCH)
-                       Sbar_MiniDeathmatchOverlay ();
-
        }
        else
        {
@@ -954,7 +1038,6 @@ void Sbar_Draw (void)
                }
        }
 
-
        if (vid.conwidth > 320 && cl.gametype == GAME_DEATHMATCH)
                Sbar_MiniDeathmatchOverlay ();
 
@@ -978,11 +1061,11 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
        {
                // draw colors behind score
                c = (qbyte *)&palette_complete[(s->colors & 0xf0) + 8];
-               DrawQ_Fill(x + 8, y+1, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
+               DrawQ_Fill(x + 8, y+1, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha.value, 0);
                c = (qbyte *)&palette_complete[((s->colors & 15)<<4) + 8];
-               DrawQ_Fill(x + 8, y+4, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f), 0);
+               DrawQ_Fill(x + 8, y+4, 32, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha.value, 0);
                // print the text
-               DrawQ_String(x, y, va("%c%4i %s", (s - cl.scores) == cl.playerentity - 1 ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1, 0);
+               DrawQ_String(x, y, va("%c%4i %s", (s - cl.scores) == cl.playerentity - 1 ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha.value, 0);
                return 8;
        }
        else
@@ -995,7 +1078,7 @@ void Sbar_DeathmatchOverlay (void)
        cachepic_t *pic;
 
        pic = Draw_CachePic ("gfx/ranking.lmp");
-       DrawQ_Pic ((vid.conwidth - pic->width)/2, 8, "gfx/ranking.lmp", 0, 0, 1, 1, 1, 1, 0);
+       DrawQ_Pic ((vid.conwidth - pic->width)/2, 8, "gfx/ranking.lmp", 0, 0, 1, 1, 1, 1 * sbar_alpha.value, 0);
 
        // scores
        Sbar_SortFrags ();
@@ -1017,8 +1100,18 @@ void Sbar_MiniDeathmatchOverlay (void)
        int i, x, y, numlines;
 
        // decide where to print
-       x = 324;
-       y = vid.conheight - sb_lines;
+       // AK Nex wants its scores on the upper left
+       if(gamemode == GAME_NEXUIZ)
+       {
+               x = 0;
+               y = 0;
+       }
+       else
+       {
+               x = 324;
+               y = vid.conheight - sb_lines;
+       }
+
        numlines = (vid.conheight - y) / 8;
        // give up if there isn't room
        if (x + (6 + 15) * 8 > vid.conwidth || numlines < 1)
@@ -1064,8 +1157,8 @@ void Sbar_IntermissionOverlay (void)
        sbar_x = (vid.conwidth - 320) >> 1;
        sbar_y = (vid.conheight - 200) >> 1;
 
-       DrawQ_Pic (sbar_x + 64, sbar_y + 24, "gfx/complete.lmp", 0, 0, 1, 1, 1, 1, 0);
-       DrawQ_Pic (sbar_x + 0, sbar_y + 56, "gfx/inter.lmp", 0, 0, 1, 1, 1, 1, 0);
+       DrawQ_Pic (sbar_x + 64, sbar_y + 24, "gfx/complete.lmp", 0, 0, 1, 1, 1, 1 * sbar_alpha.value, 0);
+       DrawQ_Pic (sbar_x + 0, sbar_y + 56, "gfx/inter.lmp", 0, 0, 1, 1, 1, 1 * sbar_alpha.value, 0);
 
 // time
        dig = cl.completed_time/60;
@@ -1097,6 +1190,6 @@ void Sbar_FinaleOverlay (void)
        cachepic_t      *pic;
 
        pic = Draw_CachePic ("gfx/finale.lmp");
-       DrawQ_Pic((vid.conwidth - pic->width)/2, 16, "gfx/finale.lmp", 0, 0, 1, 1, 1, 1, 0);
+       DrawQ_Pic((vid.conwidth - pic->width)/2, 16, "gfx/finale.lmp", 0, 0, 1, 1, 1, 1 * sbar_alpha.value, 0);
 }