// // Draws the ammo bar on the hud // int DrawBar( int x, int y, int width, int height, float f ) { int r, g, b; f = bound( 0.0f, f, 1.0f ); if( f ) { int w = f * width; // Always show at least one pixel if we have ammo. if( w <= 0 ) w = 1; UnpackRGB( r, g, b, RGB_GREENISH ); FillRGBA( x, y, w, height, r, g, b, 255 ); x += w; width -= w; } UnpackRGB( r, g, b, gHUD.m_iHUDColor ); FillRGBA( x, y, width, height, r, g, b, 128 ); return (x + width); }
// // Draws the ammo bar on the hud // int DrawBar(int x, int y, int width, int height, float f) { int r, g, b; if(f < 0) f = 0; if(f > 1) f = 1; if(f) { int w = f * width; // Always show at least one pixel if we have ammo. if(w <= 0) w = 1; UnpackRGB(r, g, b, RGB_GREENISH); FillRGBA(x, y, w, height, r, g, b, 255); x += w; width -= w; } UnpackRGB(r, g, b, RGB_YELLOWISH); FillRGBA(x, y, width, height, r, g, b, 128); return (x + width); }
int CHudFlashlight::Draw(float flTime) { if ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) return 1; int r, g, b, x, y, a; wrect_t rc; if (!(gHUD.m_iWeaponBits & (1<<(4096)) )) return 1; if (m_fOn) a = 225; else a = MIN_ALPHA; if (m_flBat < 0.20) UnpackRGB(r,g,b, RGB_REDISH); else UnpackRGB(r,g,b, RGB_YELLOWISH); ScaleColors(r, g, b, a); y = (m_prc1->bottom - m_prc2->top)/2; x = ScreenWidth - m_iWidth - m_iWidth/2 ; // Draw the flashlight casing SPR_Set(m_hSprite1, r, g, b ); SPR_DrawAdditive( 0, x, y, m_prc1); if ( m_fOn ) { // draw the flashlight beam x = ScreenWidth - m_iWidth/2; SPR_Set( m_hBeam, r, g, b ); SPR_DrawAdditive( 0, x, y, m_prcBeam ); } // draw the flashlight energy level x = ScreenWidth - m_iWidth - m_iWidth/2 ; int iOffset = m_iWidth * (1.0 - m_flBat); if (iOffset < m_iWidth) { rc = *m_prc2; rc.left += iOffset; SPR_Set(m_hSprite2, r, g, b ); SPR_DrawAdditive( 0, x + iOffset, y, &rc); } return 1; }
int CHudBackground::Draw(float flTime) { int r = 0, g = 0, b = 0, x = 0, y = 0; int x_length = 0, y_length = 0; // positions of the spots y_length = gHUD.GetSpriteRect(m_HUD_back).bottom - gHUD.GetSpriteRect(m_HUD_back).top; x_length = gHUD.GetSpriteRect(m_HUD_back).right - gHUD.GetSpriteRect(m_HUD_back).left; UnpackRGB(r, g, b, RGB_WHITEISH); ScaleColors(r, g, b, 255); // position the sprite in the upper right corner of display... x = XRES(0); y = (YRES(480) - y_length); if (g_iWaterLevel != 3) { y_length = gHUD.GetSpriteRect(m_HUD_back).bottom - gHUD.GetSpriteRect(m_HUD_back).top; x_length = gHUD.GetSpriteRect(m_HUD_back).right - gHUD.GetSpriteRect(m_HUD_back).left; SPR_Set(m_hSprite, r, g, b); SPR_DrawHoles(0, x, y, m_SpriteArea); return 1; } else { y_length = gHUD.GetSpriteRect(m_HUD_water).bottom - gHUD.GetSpriteRect(m_HUD_water).top; x_length = gHUD.GetSpriteRect(m_HUD_water).right - gHUD.GetSpriteRect(m_HUD_water).left; SPR_Set(gHUD.GetSprite(m_HUD_water), r, g, b); SPR_DrawHoles((((int)(flTime*14))%24), x, y, m_SpriteArea); return 0; } }
// Returns back a color from the // Green <-> Yellow <-> Red ramp void CHudHealth::GetPainColor(int &r, int &g, int &b) { int iHealth = m_iHealth; if(iHealth > 25) iHealth -= 25; else if(iHealth < 0) iHealth = 0; #if 0 g = iHealth * 255 / 100; r = 255 - g; b = 0; #else if(m_iHealth > 25) { UnpackRGB(r, g, b, RGB_YELLOWISH); } else { r = 250; g = 0; b = 0; } #endif }
// // Draws the ammo bar on the hud // int DrawBar(int x, int y, int width, int height, float f) { int r, g, b; if (f < 0) f = 0; if (f > 1) f = 1; if (f) { int w = f * width; // Always show at least one pixel if we have ammo. if (w <= 0) w = 1; UnpackRGB(r, g, b, RGB_GREENISH); FillRGBA(x, y, w, height, r, g, b, 255); x += w; width -= w; } // Fograin92: A little changes //UnpackRGB(r,g,b, RGB_YELLOWISH); r = SM_HUDcolor(1); g = SM_HUDcolor(2); b = SM_HUDcolor(3); FillRGBA(x, y, width, height, r, g, b, 128); return (x + width); }
int CHudHealth::DrawDamage(float flTime) { int r, g, b, a; DAMAGE_IMAGE *pdmg; if (!m_bitsDamage) return 1; UnpackRGB(r,g,b, RGB_YELLOWISH); a = (int)( fabs(sin(flTime*2)) * 256.0); ScaleColors(r, g, b, a); // Draw all the items int i; for (i = 0; i < NUM_DMG_TYPES; i++) { if (m_bitsDamage & giDmgFlags[i]) { pdmg = &m_dmg[i]; SPR_Set(gHUD.GetSprite(m_HUD_dmg_bio + i), r, g, b ); SPR_DrawAdditive(0, pdmg->x, pdmg->y, &gHUD.GetSpriteRect(m_HUD_dmg_bio + i)); } } // check for bits that should be expired for ( i = 0; i < NUM_DMG_TYPES; i++ ) { DAMAGE_IMAGE *pdmg = &m_dmg[i]; if ( m_bitsDamage & giDmgFlags[i] ) { pdmg->fExpire = min( flTime + DMG_IMAGE_LIFE, pdmg->fExpire ); if ( pdmg->fExpire <= flTime // when the time has expired && a < 40 ) // and the flash is at the low point of the cycle { pdmg->fExpire = 0; int y = pdmg->y; pdmg->x = pdmg->y = 0; // move everyone above down for (int j = 0; j < NUM_DMG_TYPES; j++) { pdmg = &m_dmg[j]; if ((pdmg->y) && (pdmg->y < y)) pdmg->y += giDmgHeight; } m_bitsDamage &= ~giDmgFlags[i]; // clear the bits } } } return 1; }
int CHudAmmoSecondary::Draw( float flTime ) { if( ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL ) ) ) return 1; // draw secondary ammo icons above normal ammo readout int a, x, y, r, g, b, AmmoWidth; UnpackRGB( r, g, b, RGB_YELLOWISH ); a = (int)max( MIN_ALPHA, m_fFade ); if( m_fFade > 0 ) m_fFade -= ( gHUD.m_flTimeDelta * 20 ); // slowly lower alpha to fade out icons ScaleColors( r, g, b, a ); AmmoWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left; y = ScreenHeight - ( gHUD.m_iFontHeight * 4 ); // this is one font height higher than the weapon ammo values x = ScreenWidth - AmmoWidth; if( m_HUD_ammoicon ) { // Draw the ammo icon x -= ( gHUD.GetSpriteRect( m_HUD_ammoicon ).right - gHUD.GetSpriteRect( m_HUD_ammoicon ).left ); y -= ( gHUD.GetSpriteRect( m_HUD_ammoicon ).top - gHUD.GetSpriteRect( m_HUD_ammoicon ).bottom ); SPR_Set( gHUD.GetSprite( m_HUD_ammoicon ), r, g, b ); SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( m_HUD_ammoicon ) ); } else { // move the cursor by the '0' char instead, since we don't have an icon to work with x -= AmmoWidth; y -= ( gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).top - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).bottom ); } // draw the ammo counts, in reverse order, from right to left for( int i = MAX_SEC_AMMO_VALUES-1; i >= 0; i-- ) { if( m_iAmmoAmounts[i] < 0 ) continue; // negative ammo amounts imply that they shouldn't be drawn // half a char gap between the ammo number and the previous pic x -= ( AmmoWidth / 2 ); // draw the number, right-aligned x -= ( gHUD.GetNumWidth( m_iAmmoAmounts[i], DHN_DRAWZERO ) * AmmoWidth ); gHUD.DrawHudNumber( x, y, DHN_DRAWZERO, m_iAmmoAmounts[i], r, g, b ); if( i != 0 ) { // draw the divider bar x -= ( AmmoWidth / 2 ); FillRGBA( x, y, ( AmmoWidth/10 ), gHUD.m_iFontHeight, r, g, b, a ); } } return 1; }
void UI_ApplyCustomColors( void ) { char *afile = (char *)LOAD_FILE( "gfx/shell/colors.lst", NULL ); char *pfile = afile; char token[1024]; if( !afile ) { // not error, not warning, just notify Con_Printf( "UI_SetColors: colors.lst not found\n" ); return; } while(( pfile = COM_ParseFile( pfile, token )) != NULL ) { if( !stricmp( token, "HELP_COLOR" )) { UI_ParseColor( pfile, &uiColorHelp ); } else if( !stricmp( token, "PROMPT_BG_COLOR" )) { UI_ParseColor( pfile, &uiPromptBgColor ); } else if( !stricmp( token, "PROMPT_TEXT_COLOR" )) { UI_ParseColor( pfile, &uiPromptTextColor ); } else if( !stricmp( token, "PROMPT_FOCUS_COLOR" )) { UI_ParseColor( pfile, &uiPromptFocusColor ); } else if( !stricmp( token, "INPUT_TEXT_COLOR" )) { UI_ParseColor( pfile, &uiInputTextColor ); } else if( !stricmp( token, "INPUT_BG_COLOR" )) { UI_ParseColor( pfile, &uiInputBgColor ); } else if( !stricmp( token, "INPUT_FG_COLOR" )) { UI_ParseColor( pfile, &uiInputFgColor ); } else if( !stricmp( token, "CON_TEXT_COLOR" )) { UI_ParseColor( pfile, &uiColorConsole ); } } int r, g, b; UnpackRGB( r, g, b, uiColorConsole ); ConsoleSetColor( r, g, b ); FREE_FILE( afile ); }
int CHudVote::Draw(float time) { if (status == VoteStatus::HIDDEN || gHUD.m_flTime >= draw_until) { m_iFlags &= ~HUD_ACTIVE; return 0; } int r, g, b; UnpackRGB(r, g, b, gHUD.m_iDefaultHUDColor); char str[72]; const int x = ScreenWidth / 20; int y = ScreenHeight / 8; sprintf(str, "Vote: %s %s", str1, str2); gEngfuncs.pfnDrawString(x, y, str, r, g, b); y += gHUD.m_scrinfo.iCharHeight; sprintf(str, "Called by: %s", called_by); gHUD.DrawHudStringWithColorTags(x, y, str, r, g, b); y += gHUD.m_scrinfo.iCharHeight * 3 / 2; switch (status) { case VoteStatus::IN_PROGRESS: sprintf(str, "For: %hhu", count_for); gEngfuncs.pfnDrawString(x, y, str, r, g, b); y += gHUD.m_scrinfo.iCharHeight; sprintf(str, "Against: %hhu", count_against); gEngfuncs.pfnDrawString(x, y, str, r, g, b); y += gHUD.m_scrinfo.iCharHeight; sprintf(str, "Undecided: %hhu", count_undecided); gEngfuncs.pfnDrawString(x, y, str, r, g, b); return 0; case VoteStatus::ACCEPTED: sprintf(str, "Accepted!"); break; case VoteStatus::DENIED: sprintf(str, "Denied!"); break; default: return 0; } gEngfuncs.pfnDrawString(x, y, str, r, g, b); return 0; }
// Returns back a color from the // Green <-> Yellow <-> Red ramp void CHudHealth::GetPainColor( int &r, int &g, int &b ) { int iHealth = m_iHealth; if( iHealth > 25) iHealth -= 25; else if( iHealth < 0 ) iHealth = 0; if( m_iHealth > 25 ) { UnpackRGB( r, g, b, gHUD.m_iHUDColor ); } else { r = 250; g = 0; b = 0; } }
int CHudTrain::Draw( float fTime ) { if( !m_hSprite ) m_hSprite = LoadSprite( "sprites/640_train.spr" ); if( m_iPos ) { int r, g, b, x, y; UnpackRGB( r, g, b, gHUD.m_iHUDColor ); SPR_Set( m_hSprite, r, g, b ); // This should show up to the right and part way up the armor number y = ScreenHeight - SPR_Height( m_hSprite, 0 ) - gHUD.m_iFontHeight; x = ScreenWidth / 3 + SPR_Width( m_hSprite, 0 ) / 4; SPR_DrawAdditive( m_iPos - 1, x, y, NULL ); } return 1; }
int CHudDebug::Draw(float time) { if (hud_debug->value == 0.0f) return 0; int r, g, b; UnpackRGB(r, g, b, gHUD.m_iDefaultHUDColor); int y = 50; gHUD.DrawHudString(0, y, 0, fmt("time: %.8f", time), r, g, b); gHUD.DrawHudString(0, y += gHUD.m_scrinfo.iCharHeight, 0, fmt("GetClientTime: %.8f", gEngfuncs.GetClientTime()), r, g, b); gHUD.DrawHudString(0, y += gHUD.m_scrinfo.iCharHeight, 0, fmt("GetClientOldTime: %.8f", gEngfuncs.hudGetClientOldTime()), r, g, b); for (const auto& str : split(additional_data, '\n')) gHUD.DrawHudString(0, y += gHUD.m_scrinfo.iCharHeight, 0, const_cast<char*>(str.c_str()), r, g, b); additional_data.clear(); return 0; }
int CHudWatermark::Draw(float time) { if (refresh_draw_until) { refresh_draw_until = false; draw_until = gHUD.m_flTime + 15.0f; } if (gHUD.m_flTime >= draw_until) { m_iFlags &= ~HUD_ACTIVE; return 0; } int r, g, b; UnpackRGB(r, g, b, gHUD.m_iDefaultHUDColor); gEngfuncs.pfnDrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight, "OpenAG client build " __DATE__, r, g, b); gEngfuncs.pfnDrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 2, "j.mp/OpenAG", r, g, b); if (update_is_available) gEngfuncs.pfnDrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight / 2 * 7, "An update is available.", r, g, b); return 0; }
// returns the ypos where it finishes drawing int CHudScoreboard::DrawPlayers(int xpos_rel, float list_slot, int nameoffset, char *team) { int can_show_packetloss = 0; int FAR_RIGHT; // Packetloss removed on Kelly 'shipping nazi' Bailey's orders if(cl_showpacketloss && cl_showpacketloss->value && (ScreenWidth >= 400)) { can_show_packetloss = 1; SCOREBOARD_WIDTH = 400; } else { SCOREBOARD_WIDTH = 320; } FAR_RIGHT = can_show_packetloss ? PL_RANGE_MAX : PING_RANGE_MAX; FAR_RIGHT += 5; // draw the players, in order, and restricted to team if set while(1) { // Find the top ranking player int highest_frags = -99999; int lowest_deaths = 99999; int best_player = 0; for(int i = 1; i < MAX_PLAYERS; i++) { if(g_PlayerInfoList[i].name && g_PlayerExtraInfo[i].frags >= highest_frags) { if(!(team && stricmp(g_PlayerExtraInfo[i].teamname, team))) // make sure it is the specified team { extra_player_info_t *pl_info = &g_PlayerExtraInfo[i]; if(pl_info->frags > highest_frags || pl_info->deaths < lowest_deaths) { best_player = i; lowest_deaths = pl_info->deaths; highest_frags = pl_info->frags; } } } } if(!best_player) break; // draw out the best player hud_player_info_t *pl_info = &g_PlayerInfoList[best_player]; int ypos = ROW_RANGE_MIN + (list_slot * ROW_GAP); // check we haven't drawn too far down if(ypos > ROW_RANGE_MAX) // don't draw to close to the lower border break; int xpos = NAME_RANGE_MIN + xpos_rel; int r = 255, g = 255, b = 255; if(best_player == m_iLastKilledBy && m_fLastKillTime && m_fLastKillTime > gHUD.m_flTime) { if(pl_info->thisplayer) { // green is the suicide color? i wish this could do grey... FillRGBA(NAME_RANGE_MIN + xpos_rel - 5, ypos, FAR_RIGHT, ROW_GAP, 80, 155, 0, 70); } else { // Highlight the killers name - overlay the background in red, then draw the score text over it FillRGBA(NAME_RANGE_MIN + xpos_rel - 5, ypos, FAR_RIGHT, ROW_GAP, 255, 0, 0, ((float)15 * (float)(m_fLastKillTime - gHUD.m_flTime))); } } else if(pl_info->thisplayer) // if it is their name, draw it a different color { // overlay the background in blue, then draw the score text over it FillRGBA(NAME_RANGE_MIN + xpos_rel - 5, ypos, FAR_RIGHT, ROW_GAP, 0, 0, 255, 70); } // draw their name (left to right) gHUD.DrawHudString(xpos + nameoffset, ypos, NAME_RANGE_MAX + xpos_rel, pl_info->name, r, g, b); // draw kills (right to left) xpos = KILLS_RANGE_MAX + xpos_rel; gHUD.DrawHudNumberString(xpos, ypos, KILLS_RANGE_MIN + xpos_rel, g_PlayerExtraInfo[best_player].frags, r, g, b); // draw divider xpos = DIVIDER_POS + xpos_rel; gHUD.DrawHudString(xpos, ypos, xpos + 20, "/", r, g, b); // draw deaths xpos = DEATHS_RANGE_MAX + xpos_rel; gHUD.DrawHudNumberString(xpos, ypos, DEATHS_RANGE_MIN + xpos_rel, g_PlayerExtraInfo[best_player].deaths, r, g, b); // draw ping & packetloss static char buf[64]; sprintf(buf, "%d", g_PlayerInfoList[best_player].ping); xpos = ((PING_RANGE_MAX - PING_RANGE_MIN) / 2) + PING_RANGE_MIN + xpos_rel + 25; gHUD.DrawHudStringReverse(xpos, ypos, xpos - 50, buf, r, g, b); // Packetloss removed on Kelly 'shipping nazi' Bailey's orders if(can_show_packetloss) { if(g_PlayerInfoList[best_player].packetloss >= 63) { UnpackRGB(r, g, b, RGB_REDISH); sprintf(buf, " !!!!"); } else { sprintf(buf, " %d", g_PlayerInfoList[best_player].packetloss); } xpos = ((PL_RANGE_MAX - PL_RANGE_MIN) / 2) + PL_RANGE_MIN + xpos_rel + 25; gHUD.DrawHudString(xpos, ypos, xpos + 50, buf, r, g, b); } pl_info->name = NULL; // set the name to be NULL, so this client won't get drawn again list_slot++; } return list_slot; }
int CHudHealth::DrawDamage(float flTime) { int r, g, b, a; DAMAGE_IMAGE *pdmg; if (!m_bitsDamage) return 1; UnpackRGB(r,g,b, RGB_YELLOWISH); a = (int)( fabs(sin(flTime*2)) * 256.0); ScaleColors(r, g, b, a); // Draw all the items for (int i = 0; i < NUM_DMG_TYPES; i++) { if (m_bitsDamage & giDmgFlags[i]) { pdmg = &m_dmg[i]; SPR_Set(gHUD.GetSprite(m_HUD_dmg_bio + i), r, g, b ); // Discwar: Hack. Freeze is the only icon we use. Just place it directly above the disc ammo int iX = (ScreenWidth - DISC_ICON_WIDTH) / 2; int iXPos = iX - DISC_ICON_SPACER; SPR_DrawAdditive(0, iXPos + (DISC_ICON_SPACER), ScreenHeight - YRES(92), &gHUD.GetSpriteRect(m_HUD_dmg_bio + i)); } } /* // check for bits that should be expired for ( i = 0; i < NUM_DMG_TYPES; i++ ) { DAMAGE_IMAGE *pdmg = &m_dmg[i]; if ( m_bitsDamage & giDmgFlags[i] ) { pdmg->fExpire = min( flTime + DMG_IMAGE_LIFE, pdmg->fExpire ); if ( pdmg->fExpire <= flTime // when the time has expired && a < 40 ) // and the flash is at the low point of the cycle { pdmg->fExpire = 0; int y = pdmg->y; pdmg->x = pdmg->y = 0; // move everyone above down for (int j = 0; j < NUM_DMG_TYPES; j++) { pdmg = &m_dmg[j]; if ((pdmg->y) && (pdmg->y < y)) pdmg->y += giDmgHeight; } m_bitsDamage &= ~giDmgFlags[i]; // clear the bits } } } */ return 1; }
int CHudHealth::Draw( float flTime ) { int r, g, b; int a = 0, x, y; int HealthWidth; if( ( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH ) || gEngfuncs.IsSpectateOnly() ) return 1; if( !m_hSprite ) m_hSprite = LoadSprite( PAIN_NAME ); // Has health changed? Flash the health # if( m_fFade ) { m_fFade -= ( gHUD.m_flTimeDelta * 20 ); if( m_fFade <= 0 ) { a = MIN_ALPHA; m_fFade = 0; } // Fade the health number back to dim a = MIN_ALPHA + ( m_fFade / FADE_TIME ) * 128; } else a = MIN_ALPHA; // If health is getting low, make it bright red if( m_iHealth <= 15 ) a = 255; GetPainColor( r, g, b ); ScaleColors( r, g, b, a ); // Only draw health if we have the suit. if( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) { HealthWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left; int CrossWidth = gHUD.GetSpriteRect( m_HUD_cross ).right - gHUD.GetSpriteRect( m_HUD_cross ).left; y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; x = CrossWidth / 2; SPR_Set( gHUD.GetSprite( m_HUD_cross ), r, g, b ); SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( m_HUD_cross ) ); x = CrossWidth + HealthWidth / 2; x = gHUD.DrawHudNumber( x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iHealth, r, g, b ); x += HealthWidth / 2; int iHeight = gHUD.m_iFontHeight; int iWidth = HealthWidth / 10; UnpackRGB( r, g, b, RGB_YELLOWISH ); FillRGBA( x, y, iWidth, iHeight, r, g, b, a ); } DrawDamage( flTime ); return DrawPain( flTime ); }
// // Draw Ammo pickup history // int HistoryResource::DrawAmmoHistory(float flTime) { for(int i = 0; i < MAX_HISTORY; i++) { if(rgAmmoHistory[i].type) { rgAmmoHistory[i].DisplayTime = min(rgAmmoHistory[i].DisplayTime, gHUD.m_flTime + HISTORY_DRAW_TIME); if(rgAmmoHistory[i].DisplayTime <= flTime) { // pic drawing time has expired memset(&rgAmmoHistory[i], 0, sizeof(HIST_ITEM)); CheckClearHistory(); } else if(rgAmmoHistory[i].type == HISTSLOT_AMMO) { wrect_t rcPic; HSPRITE *spr = gWR.GetAmmoPicFromWeapon(rgAmmoHistory[i].iId, rcPic); int r, g, b; UnpackRGB(r, g, b, RGB_YELLOWISH); float scale = (rgAmmoHistory[i].DisplayTime - flTime) * 80; ScaleColors(r, g, b, min(scale, 255)); // Draw the pic int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); int xpos = ScreenWidth - 24; if(spr && *spr) // weapon isn't loaded yet so just don't draw the pic { // the dll has to make sure it has sent info the weapons you need SPR_Set(*spr, r, g, b); SPR_DrawAdditive(0, xpos, ypos, &rcPic); } // Draw the number gHUD.DrawHudNumberString(xpos - 10, ypos, xpos - 100, rgAmmoHistory[i].iCount, r, g, b); } else if(rgAmmoHistory[i].type == HISTSLOT_WEAP) { WEAPON *weap = gWR.GetWeapon(rgAmmoHistory[i].iId); if(!weap) return 1; // we don't know about the weapon yet, so don't draw anything int r, g, b; UnpackRGB(r, g, b, RGB_YELLOWISH); if(!gWR.HasAmmo(weap)) UnpackRGB(r, g, b, RGB_REDISH); // if the weapon doesn't have ammo, display it as red float scale = (rgAmmoHistory[i].DisplayTime - flTime) * 80; ScaleColors(r, g, b, min(scale, 255)); int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); int xpos = ScreenWidth - (weap->rcInactive.right - weap->rcInactive.left); SPR_Set(weap->hInactive, r, g, b); SPR_DrawAdditive(0, xpos, ypos, &weap->rcInactive); } else if(rgAmmoHistory[i].type == HISTSLOT_ITEM) { int r, g, b; if(!rgAmmoHistory[i].iId) continue; // sprite not loaded wrect_t rect = gHUD.GetSpriteRect(rgAmmoHistory[i].iId); UnpackRGB(r, g, b, RGB_YELLOWISH); float scale = (rgAmmoHistory[i].DisplayTime - flTime) * 80; ScaleColors(r, g, b, min(scale, 255)); int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i)); int xpos = ScreenWidth - (rect.right - rect.left) - 10; SPR_Set(gHUD.GetSprite(rgAmmoHistory[i].iId), r, g, b); SPR_DrawAdditive(0, xpos, ypos, &rect); } } } return 1; }
/* ================= UI_DrawMenu ================= */ void UI_DrawMenu( menuFramework_s *menu ) { static long statusFadeTime; static menuCommon_s *lastItem; menuCommon_s *item; int i; // draw contents for( i = 0; i < menu->numItems; i++ ) { item = (menuCommon_s *)menu->items[i]; if( item->flags & QMF_HIDDEN ) continue; if( item->ownerdraw ) { // total subclassing, owner draws everything item->ownerdraw( item ); continue; } switch( item->type ) { case QMTYPE_SCROLLLIST: UI_ScrollList_Draw((menuScrollList_s *)item ); break; case QMTYPE_SPINCONTROL: UI_SpinControl_Draw((menuSpinControl_s *)item ); break; case QMTYPE_CHECKBOX: UI_CheckBox_Draw((menuCheckBox_s *)item ); break; case QMTYPE_SLIDER: UI_Slider_Draw((menuSlider_s *)item ); break; case QMTYPE_FIELD: UI_Field_Draw((menuField_s *)item ); break; case QMTYPE_ACTION: UI_Action_Draw((menuAction_s *)item ); break; case QMTYPE_BITMAP: UI_Bitmap_Draw((menuBitmap_s *)item ); break; case QMTYPE_BM_BUTTON: UI_PicButton_Draw((menuPicButton_s *)item ); break; } } // draw status bar item = (menuCommon_s *)UI_ItemAtCursor( menu ); if( item != lastItem ) { // flash on selected button (like in GoldSrc) if( item ) item->lastFocusTime = uiStatic.realTime; statusFadeTime = uiStatic.realTime; lastItem = item; } if( item && ( item->flags & QMF_HASMOUSEFOCUS && !( item->flags & QMF_NOTIFY )) && ( item->statusText != NULL )) { // fade it in, but wait a second int alpha = bound( 0, ((( uiStatic.realTime - statusFadeTime ) - 1000 ) * 0.001f ) * 255, 255 ); int r, g, b, x, len; GetConsoleStringSize( item->statusText, &len, NULL ); UnpackRGB( r, g, b, uiColorHelp ); TextMessageSetColor( r, g, b, alpha ); x = ( ScreenWidth - len ) * 0.5; // centering DrawConsoleString( x, 720 * uiStatic.scaleY, item->statusText ); } else statusFadeTime = uiStatic.realTime; }
// // Draw Weapon Menu // int CHudAmmo::DrawWList(float flTime) { int r, g, b, x, y, a, i; if(!gpActiveSel) return 0; int iActiveSlot; if(gpActiveSel == (WEAPON *)1) iActiveSlot = -1; // current slot has no weapons else iActiveSlot = gpActiveSel->iSlot; x = 10; //!!! y = 10; //!!! // Ensure that there are available choices in the active slot if(iActiveSlot > 0) { if(!gWR.GetFirstPos(iActiveSlot)) { gpActiveSel = (WEAPON *)1; iActiveSlot = -1; } } // Draw top line for(i = 0; i < MAX_WEAPON_SLOTS; i++) { int iWidth; UnpackRGB(r, g, b, RGB_YELLOWISH); if(iActiveSlot == i) a = 255; else a = 192; ScaleColors(r, g, b, 255); SPR_Set(gHUD.GetSprite(m_HUD_bucket0 + i), r, g, b); // make active slot wide enough to accomodate gun pictures if(i == iActiveSlot) { WEAPON *p = gWR.GetFirstPos(iActiveSlot); if(p) iWidth = p->rcActive.right - p->rcActive.left; } else iWidth = giBucketWidth; if(i == iActiveSlot) SPR_DrawAdditive(0, x + 104, y, &gHUD.GetSpriteRect(m_HUD_bucket0 + i)); else SPR_DrawAdditive(0, x, y, &gHUD.GetSpriteRect(m_HUD_bucket0 + i)); x += iWidth + 5; } a = 128; //!!! x = 10; // Draw all of the buckets for(i = 1; i < MAX_WEAPON_SLOTS + 1; i++) { y = giBucketHeight + 10; // If this is the active slot, draw the bigger pictures, // otherwise just draw boxes if(i == iActiveSlot) { WEAPON *p = gWR.GetFirstPos(i); int iWidth = giBucketWidth; if(p) iWidth = p->rcActive.right - p->rcActive.left; for(int iPos = 0; iPos < MAX_WEAPON_POSITIONS; iPos++) { p = gWR.GetWeaponSlot(i, iPos); if(!p || !p->iId) continue; UnpackRGB(r, g, b, RGB_YELLOWISH); // if active, then we must have ammo. if(gpActiveSel == p) { if(gWR.HasAmmo(p)) ScaleColors(r, g, b, 192); else { UnpackRGB(r, g, b, RGB_REDISH); ScaleColors(r, g, b, 128); } SPR_Set(p->hActive, r, g, b); SPR_DrawAdditive(0, x, y, &p->rcActive); } else { // Draw Weapon if Red if no ammo if(gWR.HasAmmo(p)) ScaleColors(r, g, b, 192); else { UnpackRGB(r, g, b, RGB_REDISH); ScaleColors(r, g, b, 128); } SPR_Set(p->hInactive, r, g, b); SPR_DrawAdditive(0, x, y, &p->rcInactive); } // Draw Ammo Bar DrawAmmoBar(p, x + giABWidth / 2, y, giABWidth, giABHeight); y += p->rcActive.bottom - p->rcActive.top + 5; } x += iWidth + 5; } else { // Draw Row of weapons. UnpackRGB(r, g, b, RGB_YELLOWISH); for(int iPos = 0; iPos < MAX_WEAPON_POSITIONS; iPos++) { WEAPON *p = gWR.GetWeaponSlot(i, iPos); if(!p || !p->iId) continue; if(gWR.HasAmmo(p)) { UnpackRGB(r, g, b, RGB_YELLOWISH); a = 128; } else { UnpackRGB(r, g, b, RGB_REDISH); a = 96; } FillRGBA(x, y, giBucketWidth, giBucketHeight, r, g, b, a); y += giBucketHeight + 5; } x += giBucketWidth + 5; } } return 1; }
int CHudAmmo::Draw(float flTime) { int a, x, y, r, g, b; int AmmoWidth; int iCrossX; int iCrossY; int iCrossLength; char *chCrossHair = "+"; // Heh /*if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) )) return 1;*/ if((gHUD.m_iHideHUDDisplay & (HIDEHUD_WEAPONS | HIDEHUD_ALL))) return 1; // Draw Weapon Menu DrawWList(flTime); // Draw ammo pickup history gHR.DrawAmmoHistory(flTime); if(!(m_iFlags & HUD_ACTIVE)) return 0; if(!m_pWeapon) return 0; WEAPON *pw = m_pWeapon; // shorthand // SPR_Draw Ammo if((pw->iAmmoType < 0) && (pw->iAmmo2Type < 0)) return 0; int iFlags = DHN_DRAWZERO; // draw 0 values AmmoWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left; a = (int)max(MIN_ALPHA, m_fFade); if(m_fFade > 0) m_fFade -= (gHUD.m_flTimeDelta * 20); UnpackRGB(r, g, b, RGB_YELLOWISH); ScaleColors(r, g, b, a); // Does this weapon have a clip? y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; /******************* DRAW CROSSHAIR *********************/ iCrossLength = gHUD.m_scrinfo.charWidths[*chCrossHair]; iCrossY = ScreenHeight / 2 - gHUD.m_scrinfo.iCharHeight / 2; iCrossX = ScreenWidth / 2 - iCrossLength / 2; gHUD.DrawHudString(iCrossX, iCrossY, iCrossX + 50, chCrossHair, 170, 170, 170); /******************* DRAW CROSSHAIR *********************/ // Does weapon have any ammo at all? if(m_pWeapon->iAmmoType > 0) { int iIconWidth = m_pWeapon->rcAmmo.right - m_pWeapon->rcAmmo.left; if(pw->iClip >= 0) { x = ScreenWidth - (8 * AmmoWidth) - iIconWidth; UnpackRGB(r, g, b, RGB_YELLOWISH); // GL Seems to need this ScaleColors(r, g, b, a); m_iNumberXPosition = x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmoType), r, g, b); } // Draw the ammo Icon int iOffset = (m_pWeapon->rcAmmo.bottom - m_pWeapon->rcAmmo.top) / 8; SPR_Set(m_pWeapon->hAmmo, r, g, b); SPR_DrawAdditive(0, x, y - iOffset, &m_pWeapon->rcAmmo); m_iXPosition = x; } return 1; }
int CHudFlashlight::Draw( float flTime ) { static bool show = ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ); if( show != !( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) ) { show = !( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ); if( gMobileEngfuncs ) { gMobileEngfuncs->pfnTouchHideButtons( "flashlight", !show ); } } if( !show ) return 1; int r, g, b, x, y, a; wrect_t rc; if( gEngfuncs.IsSpectateOnly() ) return 1; if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) ) return 1; if( m_fOn ) a = 225; else a = MIN_ALPHA; if( m_flBat < 0.20 ) UnpackRGB( r,g,b, RGB_REDISH ); else UnpackRGB( r,g,b, RGB_YELLOWISH ); ScaleColors( r, g, b, a ); y = ( m_prc1->bottom - m_prc2->top ) / 2; x = ScreenWidth - m_iWidth - m_iWidth / 2 ; // Draw the flashlight casing SPR_Set( m_hSprite1, r, g, b ); SPR_DrawAdditive( 0, x, y, m_prc1 ); if( m_fOn ) { // draw the flashlight beam x = ScreenWidth - m_iWidth / 2; SPR_Set( m_hBeam, r, g, b ); SPR_DrawAdditive( 0, x, y, m_prcBeam ); } // draw the flashlight energy level x = ScreenWidth - m_iWidth - m_iWidth / 2; int iOffset = m_iWidth * ( 1.0 - m_flBat ); if( iOffset < m_iWidth ) { rc = *m_prc2; rc.left += iOffset; SPR_Set( m_hSprite2, r, g, b ); SPR_DrawAdditive( 0, x + iOffset, y, &rc ); } return 1; }
//------------------------------------------------------------------------- // Drawing code //------------------------------------------------------------------------- int CHudAmmo::Draw( float flTime ) { int a, x, y, r, g, b; int AmmoWidth; if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) )) return 1; if(( gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL ))) return 1; // Draw Weapon Menu DrawWList( flTime ); // Draw ammo pickup history gHR.DrawAmmoHistory( flTime ); if( !( m_iFlags & HUD_ACTIVE )) return 0; if( !m_pWeapon ) { return 0; } WEAPON *pw = m_pWeapon; // shorthand // SPR_Draw Ammo if(( pw->iAmmoType < 0 ) && ( pw->iAmmo2Type < 0 )) return 0; int iFlags = DHN_DRAWZERO; // draw 0 values AmmoWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left; a = (int)max( MIN_ALPHA, m_fFade ); if( m_fFade > 0 ) m_fFade -= (gHUD.m_flTimeDelta * 20); UnpackRGB( r, g, b, gHUD.m_iHUDColor ); ScaleColors( r, g, b, a ); // Does this weapon have a clip? y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; // Does weapon have any ammo at all? if( m_pWeapon->iAmmoType > 0 ) { int iIconWidth = m_pWeapon->rcAmmo.right - m_pWeapon->rcAmmo.left; if( pw->iClip >= 0 ) { // room for the number and the '|' and the current ammo x = ScreenWidth - ( 8 * AmmoWidth ) - iIconWidth; x = gHUD.DrawHudNumber( x, y, iFlags | DHN_3DIGITS, pw->iClip, r, g, b ); wrect_t rc; rc.top = 0; rc.left = 0; rc.right = AmmoWidth; rc.bottom = 100; int iBarWidth = AmmoWidth / 10; x += AmmoWidth / 2; UnpackRGB( r, g, b, gHUD.m_iHUDColor ); // draw the | bar FillRGBA( x, y, iBarWidth, gHUD.m_iFontHeight, r, g, b, a ); x += iBarWidth + AmmoWidth / 2; // GL Seems to need this ScaleColors( r, g, b, a ); x = gHUD.DrawHudNumber( x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo( pw->iAmmoType ), r, g, b ); } else { // SPR_Draw a bullets only line x = ScreenWidth - 4 * AmmoWidth - iIconWidth; x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo( pw->iAmmoType ), r, g, b ); } // Draw the ammo Icon int iOffset = ( m_pWeapon->rcAmmo.bottom - m_pWeapon->rcAmmo.top ) / 8; SPR_Set( m_pWeapon->hAmmo, r, g, b ); SPR_DrawAdditive( 0, x, y - iOffset, &m_pWeapon->rcAmmo ); } // Does weapon have seconday ammo? if( pw->iAmmo2Type > 0 ) { int iIconWidth = m_pWeapon->rcAmmo2.right - m_pWeapon->rcAmmo2.left; // Do we have secondary ammo? if(( pw->iAmmo2Type != 0 ) && ( gWR.CountAmmo(pw->iAmmo2Type ) > 0)) { y -= gHUD.m_iFontHeight + gHUD.m_iFontHeight / 4; x = ScreenWidth - 4 * AmmoWidth - iIconWidth; x = gHUD.DrawHudNumber( x, y, iFlags|DHN_3DIGITS, gWR.CountAmmo( pw->iAmmo2Type ), r, g, b ); // Draw the ammo Icon SPR_Set( m_pWeapon->hAmmo2, r, g, b ); int iOffset = ( m_pWeapon->rcAmmo2.bottom - m_pWeapon->rcAmmo2.top ) / 8; SPR_DrawAdditive( 0, x, y - iOffset, &m_pWeapon->rcAmmo2 ); } } return 1; }
int CHudScoreboard :: Draw( float fTime ) { if ( !m_iShowscoresHeld && gHUD.m_Health.m_iHealth > 0 && !gHUD.m_iIntermission ) return 1; GetAllPlayersInfo(); // just sort the list on the fly // list is sorted first by frags, then by deaths float list_slot = 0; int xpos_rel = (ScreenWidth - SCOREBOARD_WIDTH) / 2; // print the heading line int ypos = ROW_RANGE_MIN + (list_slot * ROW_GAP); int xpos = NAME_RANGE_MIN + xpos_rel; if ( !gHUD.m_Teamplay ) gHUD.DrawHudString( xpos, ypos, NAME_RANGE_MAX + xpos_rel, "Player", 255, 140, 0 ); else gHUD.DrawHudString( xpos, ypos, NAME_RANGE_MAX + xpos_rel, "Teams", 255, 140, 0 ); gHUD.DrawHudStringReverse( KILLS_RANGE_MAX + xpos_rel, ypos, 0, "kills", 255, 140, 0 ); gHUD.DrawHudString( DIVIDER_POS + xpos_rel, ypos, ScreenWidth, "/", 255, 140, 0 ); gHUD.DrawHudString( DEATHS_RANGE_MIN + xpos_rel + 5, ypos, ScreenWidth, "deaths", 255, 140, 0 ); gHUD.DrawHudString( PING_RANGE_MAX + xpos_rel - 35, ypos, ScreenWidth, "latency", 255, 140, 0 ); list_slot += 1.2; ypos = ROW_RANGE_MIN + (list_slot * ROW_GAP); xpos = NAME_RANGE_MIN + xpos_rel; FillRGBA( xpos - 5, ypos, PING_RANGE_MAX - 5, 1, 255, 140, 0, 255); // draw the seperator line list_slot += 0.8; if ( !gHUD.m_Teamplay ) { // it's not teamplay, so just draw a simple player list DrawPlayers( xpos_rel, list_slot ); return 1; } // clear out team scores for ( int i = 1; i <= m_iNumTeams; i++ ) { if ( !m_TeamInfo[i].scores_overriden ) m_TeamInfo[i].frags = m_TeamInfo[i].deaths = 0; m_TeamInfo[i].ping = m_TeamInfo[i].packetloss = 0; } // recalc the team scores, then draw them for ( i = 1; i < MAX_PLAYERS; i++ ) { if ( m_PlayerInfoList[i].name == NULL ) continue; // empty player slot, skip if ( m_PlayerExtraInfo[i].teamname[0] == 0 ) continue; // skip over players who are not in a team // find what team this player is in for ( int j = 1; j <= m_iNumTeams; j++ ) { if ( !stricmp( m_PlayerExtraInfo[i].teamname, m_TeamInfo[j].name ) ) break; } if ( j > m_iNumTeams ) // player is not in a team, skip to the next guy continue; if ( !m_TeamInfo[j].scores_overriden ) { m_TeamInfo[j].frags += m_PlayerExtraInfo[i].frags; m_TeamInfo[j].deaths += m_PlayerExtraInfo[i].deaths; } m_TeamInfo[j].ping += m_PlayerInfoList[i].ping; m_TeamInfo[j].packetloss += m_PlayerInfoList[i].packetloss; if ( m_PlayerInfoList[i].thisplayer ) m_TeamInfo[j].ownteam = TRUE; else m_TeamInfo[j].ownteam = FALSE; } // find team ping/packetloss averages for ( i = 1; i <= m_iNumTeams; i++ ) { m_TeamInfo[i].already_drawn = FALSE; if ( m_TeamInfo[i].players > 0 ) { m_TeamInfo[i].ping /= m_TeamInfo[i].players; // use the average ping of all the players in the team as the teams ping m_TeamInfo[i].packetloss /= m_TeamInfo[i].players; // use the average ping of all the players in the team as the teams ping } } // Draw the teams while ( 1 ) { int highest_frags = -99999; int lowest_deaths = 99999; int best_team = 0; for ( i = 1; i <= m_iNumTeams; i++ ) { if ( m_TeamInfo[i].players < 0 ) continue; if ( !m_TeamInfo[i].already_drawn && m_TeamInfo[i].frags >= highest_frags ) { if ( m_TeamInfo[i].frags > highest_frags || m_TeamInfo[i].deaths < lowest_deaths ) { best_team = i; lowest_deaths = m_TeamInfo[i].deaths; highest_frags = m_TeamInfo[i].frags; } } } // draw the best team on the scoreboard if ( !best_team ) break; // draw out the best team team_info_t *team_info = &m_TeamInfo[best_team]; ypos = ROW_RANGE_MIN + (list_slot * ROW_GAP); // check we haven't drawn too far down if ( ypos > ROW_RANGE_MAX ) // don't draw to close to the lower border break; xpos = NAME_RANGE_MIN + xpos_rel; int r = 255, g = 225, b = 55; // draw the stuff kinda yellowish if ( team_info->ownteam ) // if it is their team, draw the background different color { // overlay the background in blue, then draw the score text over it FillRGBA( NAME_RANGE_MIN + xpos_rel - 5, ypos, PING_RANGE_MAX - 5, ROW_GAP, 0, 0, 255, 70 ); } // draw their name (left to right) gHUD.DrawHudString( xpos, ypos, NAME_RANGE_MAX + xpos_rel, team_info->name, r, g, b ); // draw kills (right to left) xpos = KILLS_RANGE_MAX + xpos_rel; gHUD.DrawHudNumberString( xpos, ypos, KILLS_RANGE_MIN + xpos_rel, team_info->frags, r, g, b ); // draw divider xpos = DIVIDER_POS + xpos_rel; gHUD.DrawHudString( xpos, ypos, xpos + 20, "/", r, g, b ); // draw deaths xpos = DEATHS_RANGE_MAX + xpos_rel; gHUD.DrawHudNumberString( xpos, ypos, DEATHS_RANGE_MIN + xpos_rel, team_info->deaths, r, g, b ); // draw ping // draw ping & packetloss static char buf[64]; sprintf( buf, "%d", team_info->ping ); xpos = ((PING_RANGE_MAX - PING_RANGE_MIN) / 2) + PING_RANGE_MIN + xpos_rel + 25; UnpackRGB( r, g, b, RGB_YELLOWISH ); gHUD.DrawHudStringReverse( xpos, ypos, xpos - 50, buf, r, g, b ); /* Packetloss removed on Kelly 'shipping nazi' Bailey's orders sprintf( buf, " %d", team_info->packetloss ); gHUD.DrawHudString( xpos, ypos, xpos+50, buf, r, g, b ); */ team_info->already_drawn = TRUE; // set the already_drawn to be TRUE, so this team won't get drawn again list_slot++; // draw all the players that belong to this team, indented slightly list_slot = DrawPlayers( xpos_rel, list_slot, 10, team_info->name ); } // draw all the players who are not in a team list_slot += 0.5; DrawPlayers( xpos_rel, list_slot, 0, "" ); return 1; }
int CHudBattery::Draw( float flTime ) { if( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH ) return 1; if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) )) return 1; int r, g, b, x, y, a; wrect_t rc; rc = *m_prc2; // battery can go from 0 to 100 so * 0.01 goes from 0 to 1 rc.top += m_iHeight * ((float)( 100 - ( min( 100, m_iBat ))) * 0.01f ); UnpackRGB( r, g, b, RGB_YELLOWISH ); // Has health changed? Flash the health # if( m_fFade ) { if( m_fFade > FADE_TIME ) m_fFade = FADE_TIME; m_fFade -= (gHUD.m_flTimeDelta * 20); if( m_fFade <= 0 ) { a = 128; m_fFade = 0; } // Fade the health number back to dim a = MIN_ALPHA + (m_fFade / FADE_TIME) * 128; } else { a = MIN_ALPHA; } ScaleColors( r, g, b, a ); int iOffset = (m_prc1->bottom - m_prc1->top) / 6; y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2; x = ScreenWidth / 5; // make sure we have the right sprite handles if( !m_hSprite1 ) m_hSprite1 = gHUD.GetSprite( gHUD.GetSpriteIndex( "suit_empty" )); if( !m_hSprite2 ) m_hSprite2 = gHUD.GetSprite( gHUD.GetSpriteIndex( "suit_full" )); if( !m_hSprite1Helmet ) m_hSprite1Helmet = gHUD.GetSprite( gHUD.GetSpriteIndex( "suithelmet_empty" )); if( !m_hSprite2Helmet ) m_hSprite2Helmet = gHUD.GetSprite( gHUD.GetSpriteIndex( "suithelmet_full" )); if( m_enArmorType == Vest ) SPR_Set( m_hSprite1, r, g, b ); else SPR_Set( m_hSprite1Helmet, r, g, b ); SPR_DrawAdditive( 0, x, y - iOffset, m_prc1 ); if( rc.bottom > rc.top ) { if( m_enArmorType == Vest ) SPR_Set( m_hSprite2, r, g, b ); else SPR_Set( m_hSprite2Helmet, r, g, b ); SPR_DrawAdditive( 0, x, y - iOffset + (rc.top - m_prc2->top), &rc ); } x += (m_prc1->right - m_prc1->left); x = gHUD.DrawHudNumber( x, y, DHN_3DIGITS|DHN_DRAWZERO, m_iBat, r, g, b ); return 1; }
int CHudHealth::Draw(float flTime) { int r = 0, g = 0, b = 0; int x = 0, y = 0; int iDraw = 0; if ( gHUD.m_iHideHUDDisplay & (HIDEHUD_ALL) ) return 1; if(g_iTeamNumber == UNDEFINED || g_iTeamNumber == SPECS ) { gHUD.m_iHideHUDDisplay |= HIDEHUD_HEALTH; return 1; } if(g_iUser1 != 0) return 1; m_flHealth = g_flHealth; if ( !m_hSprite ) m_hSprite = LoadSprite(PAIN_NAME); //hocked on here as this is a good palce as they are related. if(IEngineStudio.IsHardware()) iDraw = gBackground.Draw(flTime); if(iDraw == 0) { gHUD.m_iHideHUDDisplay |= HIDEHUD_HEALTH; return 1; } else { gHUD.m_iHideHUDDisplay &= ~HIDEHUD_HEALTH; } gStamina.Draw(flTime); if(ScreenWidth >= 640) gMiddle.Draw(flTime); gHintBox.Draw(flTime); UnpackRGB(r, g, b, RGB_WHITEISH); HSPRITE m_hSprite = gHUD.GetSprite( m_HUD_health ); wrect_t *m_SpriteArea = &gHUD.GetSpriteRect( m_HUD_health ); int x_length, y_length; // positions of the spots y_length = gHUD.GetSpriteRect(m_HUD_health).bottom - gHUD.GetSpriteRect(m_HUD_health).top; x_length = gHUD.GetSpriteRect(m_HUD_health).right - gHUD.GetSpriteRect(m_HUD_health).left; if(ScreenWidth >= 640) x = 5; else x = 2; y = (YRES(480) - (y_length + ((ScreenWidth >= 640) ? 5 : 3))); if(!IEngineStudio.IsHardware()) { UnpackRGB(r, g, b, RGB_WHITEISH); gStamina.Draw(flTime); if(ScreenWidth >= 640) x = 5; else x = 2; y = (YRES(480) - (20 + ((ScreenWidth >= 640) ? 5 : 3))); gHUD.DrawHudNumber(x, y, DHN_2DIGITS | DHN_DRAWZERO, m_flHealth, r, g, b); return 1; } SPR_Set(m_hSprite, r, g, b); int iClipLevel = (y_length - ((m_flHealth * y_length) / MAX_HEALTH)); //clipper starts at the clipping level. its height is the full amount of health take away the mamount clipped SPR_EnableScissor(x, y+iClipLevel, 24 , y_length-iClipLevel); SPR_DrawHoles(0, x, y, m_SpriteArea); SPR_DisableScissor(); DrawDamage(flTime); return DrawPain(flTime); }
int CHudStatusBar::Draw(float fTime) { int r, g, b, a, name_r, name_g, name_b; if(m_bReparseString) { for(int i = 0; i < MAX_STATUSBAR_LINES; i++) ParseStatusString(i); m_bReparseString = FALSE; } //Not Watching anyone if(m_iStatusValues[1] == 0) { m_iFlags &= ~HUD_ACTIVE; return 1; } // Draw the status bar lines for(int i = 0; i < MAX_STATUSBAR_LINES; i++) { int TextHeight = 0; int TotalTextWidth = 0; //Ugly way to get if(m_iTeamMate[i]) { TotalTextWidth += gHUD.ReturnStringPixelLength(m_szName[i]); TotalTextWidth += gHUD.ReturnStringPixelLength(m_szHealth[i]); TotalTextWidth += gHUD.ReturnStringPixelLength(m_szArmor[i]); TotalTextWidth += 48; TextHeight = gHUD.m_scrinfo.iCharHeight; } else TotalTextWidth += gHUD.ReturnStringPixelLength(m_szName[i]); TextHeight = gHUD.m_scrinfo.iCharHeight; if(g_iNameColors == 1) { name_r = 255; name_g = 50; name_b = 50; } else if(g_iNameColors == 2) { name_r = 50; name_g = 50; name_b = 255; } else name_r = name_g = name_b = 255; int Y_START; if(ScreenHeight >= 480) Y_START = ScreenHeight - 55; else Y_START = ScreenHeight - 45; int x = gHUD.m_Ammo.m_iNumberXPosition; int y = Y_START; // = ( ScreenHeight / 2 ) + ( TextHeight * 3 ); int x_offset; a = 200; UnpackRGB(r, g, b, RGB_NORMAL); ScaleColors(r, g, b, a); ScaleColors(name_r, name_g, name_b, 125); //Draw the name First gHUD.DrawHudString(x, y, 1024, m_szName[i], name_r, name_g, name_b); if(!m_iTeamMate[i]) continue; //Get the length in pixels for the name x_offset = gHUD.ReturnStringPixelLength(m_szName[i]); //Add the offset x += (x_offset + 8); //Now draw the Sprite for the health SPR_Set(m_hHealth, r, g, b); SPR_DrawHoles(0, x, y, &gHUD.GetSpriteRect(m_iHealthSpriteIndex)); //Add the sprite width size x += 16; //Draw the health value ( x + offset for the name lenght + width of the sprite ) gHUD.DrawHudString(x, y, 1024, m_szHealth[i], name_r, name_g, name_b); //Get the length in pixels for the health x_offset = gHUD.ReturnStringPixelLength(m_szHealth[i]); //Add the offset x += (x_offset + 8); //Now draw the Sprite for the Armor SPR_Set(m_hArmor, r, g, b); SPR_DrawHoles(0, x, y, &gHUD.GetSpriteRect(m_iArmorSpriteIndex)); x += 16; //Draw the armor value ( x + offset for the name lenght + width of the sprite ) gHUD.DrawHudString(x, y, 1024, m_szArmor[i], name_r, name_g, name_b); } return 1; }
int CHudRadar::Draw(float flTime) { if ( (gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH) || gEngfuncs.IsSpectateOnly() || !(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)))) { return 1; } cl_entity_t *pLocal = gEngfuncs.GetLocalPlayer(); if(!pLocal) { return 1; } float flPlayerAngles, flLength, flAngle, flRadians, pos_x, pos_y; vec3_t vecViewAngles, v_right, vecPlayerOrigin, vecOtherOrigin, vecDifference, vecAngles; /* * Draw Background radar */ // Get origin for radar int x = ScreenWidth; int y = 0; int iRadarWidth = gHUD.GetSpriteRect(m_HUD_radar).right - gHUD.GetSpriteRect(m_HUD_radar).left; int iRadarHeight = gHUD.GetSpriteRect(m_HUD_radar).bottom - gHUD.GetSpriteRect(m_HUD_radar).top; int infox = ScreenWidth - INFO_WIDTH; int infoy = iRadarHeight; int infoheight = gHUD.GetSpriteRect(m_HUD_radar_info).bottom - gHUD.GetSpriteRect(m_HUD_radar_info).top; x -= iRadarWidth; // Slide radar + info bar in/out when we enable/disable if(m_blPrevRadar != m_blRadar && !m_blSliding) { m_blSliding = true; m_flSlideTime = flTime; } // We switched the radar on/off while in the middle of sliding else if(m_blPrevRadar == m_blRadar && m_blSliding) { m_blPrevRadar = !m_blPrevRadar; // Invert time float flSlideTime = flTime - m_flSlideTime; flSlideTime = SLIDETIME - flSlideTime; m_flSlideTime = flTime - flSlideTime; } if(m_blSliding) { // Sliding is done, disable if((m_flSlideTime + SLIDETIME) < flTime) { m_blSliding = false; m_flSlideTime = 0; m_blPrevRadar = m_blRadar; // Done sliding and radar is off, disable if(!m_blRadar) { return 1; } } // we're still sliding else { float flPercent; if(m_blRadar) flPercent = (SLIDETIME-(flTime - m_flSlideTime))/SLIDETIME; else flPercent = (flTime - m_flSlideTime)/SLIDETIME; // Slide Radar y = -iRadarHeight * flPercent; // Slide Infobox infox += INFO_WIDTH * flPercent; } } // Done sliding and radar is off, disable if(!m_blRadar && !m_blSliding) { return 1; } // Draw Radar SPR_Set(gHUD.GetSprite(m_HUD_radar), 255, 255, 255); SPR_DrawHoles(0, x,y, &gHUD.GetSpriteRect(m_HUD_radar)); // Draw info box SPR_Set(gHUD.GetSprite(m_HUD_radar_info), 255,255,255); SPR_DrawHoles(0, infox,infoy, &gHUD.GetSpriteRect(m_HUD_radar_info)); if(m_blSliding) m_iyBottomRadar = y + iRadarHeight; else m_iyBottomRadar = infoy + infoheight; // Sliding or radar is just off, dont display information if(m_blSliding || !m_blRadar) { return 1; } /* * Get Player Angles */ // Setting player angles gEngfuncs.GetViewAngles((float *)vecViewAngles); AngleVectors(vecViewAngles, NULL, v_right, NULL ); // Inverse vector VectorInverse(v_right); v_right.z = 0; // Get angles VectorAngles(v_right,vecAngles); flPlayerAngles = vecAngles.y; // strictly 0 to 360 if(flPlayerAngles < 0) flPlayerAngles += 360; // Move x and y to the middle of the radar x += OFFSET_RAD_WIDTH; y += OFFSET_RAD_HEIGHT; /* * Loop and draw dots */ for(int i=0; i<MAX_PLAYERS; i++) { int r=255,g=255,b=255; bool blDrawInfo = false; cl_entity_t *pPlayer = gEngfuncs.GetEntityByIndex(i); // Invalid if(!pPlayer) { continue; } // Not player if(!pPlayer->player) { continue; } // Render check, make sure player is being rendered if(!g_RenderCheck[i].blRendered) { continue; } // Draw yourself as a orange dot if(pPlayer == pLocal) { r=255; g=255; b=0; } // Get Origins vecPlayerOrigin = pLocal->origin; vecOtherOrigin = pPlayer->origin; vecPlayerOrigin.z = 0; vecOtherOrigin.z = 0; vecDifference = vecPlayerOrigin - vecOtherOrigin; flLength = vecDifference.Length(); // Player is too far away, dont draw if(flLength > MAX_RADAR_DIST) continue; vecDifference = vecDifference.Normalize(); // Set 0 to 360 VectorAngles(vecDifference, vecAngles); flAngle = vecAngles.y; if(flAngle < 0) flAngle += 360; // Subtract Angles flAngle = flPlayerAngles - flAngle; // Set length according to the size of the radar flLength = (flLength/(float)MAX_RADAR_DIST) * RAD_DIAM; // Angles to radians flRadians = flAngle * PI_180; pos_x = int(cos(flRadians)*flLength); pos_y = int(sin(flRadians)*flLength); // Set positions + draw radar pos_x += x; pos_y += y; // Shift dot over so it's drawn in the correct position int iDotWidth = (gHUD.GetSpriteRect(m_HUD_radardot).right - gHUD.GetSpriteRect(m_HUD_radardot).left)/2; int iDotHeight = (gHUD.GetSpriteRect(m_HUD_radardot).bottom - gHUD.GetSpriteRect(m_HUD_radardot).top)/2; pos_x -= iDotWidth; pos_y -= iDotHeight; // Person is targeted by our missles, color them red if( gHUD.m_Lockon.FindLock( pPlayer->index ) != -1 ) { r=255; g=0; b=0; } // Yellow if our crosshair is/was over the player if( gHUD.m_Crosshair.m_iMouseOverEnt == pPlayer->index && ((flTime - gHUD.m_Crosshair.m_flMouseOverTime) < 3) ) { UnpackRGB(r,g,b, RGB_YELLOWISH); blDrawInfo = true; } // Draw SPR_Set(gHUD.GetSprite(m_HUD_radardot), r,g,b); SPR_DrawAdditive(0, pos_x,pos_y, &gHUD.GetSpriteRect(m_HUD_radardot)); // Draw information if specified if(blDrawInfo) { int line_height=0,line_width=0; pos_x = ScreenWidth - INFO_WIDTH + INFO_OFFSET_WIDTH; pos_y = iRadarHeight + INFO_OFFSET_HEIGHT; hud_player_info_t *pl_info = &g_PlayerInfoList[i]; char szName[128]; // Get colors float flTeamR,flTeamG,flTeamB; if((g_PlayerExtraInfo[i].teamnumber == g_PlayerExtraInfo[pLocal->index].teamnumber) && gHUD.m_Teamplay) { flTeamR=0; flTeamG=0.9; flTeamB=0; } else { flTeamR=1.0; flTeamG=0.2; flTeamB=0.2; } // Draw player name strcpy(szName,"Name: "); int iNameX = DrawConsoleString( pos_x, pos_y, szName ); // Draw name in color, depending if player is on your team strcpy(szName, pl_info->name); // Set color gEngfuncs.pfnDrawSetTextColor(flTeamR,flTeamG,flTeamB); // Draw DrawConsoleString( iNameX, pos_y, szName ); // Adjust offset GetConsoleStringSize( szName, &line_width, &line_height ); pos_y += line_height + INFO_OFFSET_LINE; // Draw Label strcpy(szName,"Mech: "); iNameX = DrawConsoleString( pos_x, pos_y, szName ); // Get Mech Name int iClass = g_PlayerExtraInfo[i].playerclass; if(iClass < 0) iClass = 0; else if(iClass >= PC_LASTCLASS) iClass = PC_LASTCLASS-1; strcpy(szName, szClassNames[iClass] ); // Set Color gEngfuncs.pfnDrawSetTextColor(flTeamR,flTeamG,flTeamB); // Draw Mech Name DrawConsoleString( iNameX, pos_y, szName ); } } return 1; }