void UnitDrawerStateGLSL::SetTeamColor(int team, const float2 alpha) const { // NOTE: see UnitDrawerStateARB::SetTeamColor assert(modelShaders[MODEL_SHADER_ACTIVE]->IsBound()); modelShaders[MODEL_SHADER_ACTIVE]->SetUniform4fv(9, std::move(GetTeamColor(team, alpha.x))); // modelShaders[MODEL_SHADER_ACTIVE]->SetUniform1f(16, alpha.y); }
void UnitDrawerStateFFP::SetTeamColor(int team, const float2 alpha) const { // non-shader case via texture combiners const float4 m = {1.0f, 1.0f, 1.0f, alpha.x}; glActiveTexture(GL_TEXTURE0); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, std::move(GetTeamColor(team, alpha.x))); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, &m.x); }
void UnitDrawerStateARB::SetTeamColor(int team, const float2 alpha) const { // NOTE: // both UnitDrawer::DrawAlphaPass and FeatureDrawer::DrawAlphaPass // disable advShading in case of ARB, so in that case we should end // up in StateFFP::SetTeamColor assert(modelShaders[MODEL_SHADER_ACTIVE]->IsBound()); modelShaders[MODEL_SHADER_ACTIVE]->SetUniformTarget(GL_FRAGMENT_PROGRAM_ARB); modelShaders[MODEL_SHADER_ACTIVE]->SetUniform4fv(14, std::move(GetTeamColor(team, alpha.x))); }
//----------------------------------------------------------------------------- // Purpose: Draw function for the element //----------------------------------------------------------------------------- void CHUDBlockHealth::Paint() { wchar_t sIDString[ MAX_ID_STRING ]; sIDString[0] = 0; m_bBlockInTarget = false; C_BaseEntity *pEntity = ProcessTarget(); // Did we find a target? if ( pEntity ) { // Is it a block? if ( pEntity->IsBlock() && pEntity->GetHealth() > 0 ) { C_BlockBase *pBlock = static_cast< C_BlockBase * > ( pEntity ); Color c = GetTeamColor( pBlock->GetTeamNumber() ); float BlockHealth = pBlock->GetHealth(); float MaxBlockHealth = pBlock->GetMaxHealth(); float HealthRatio = ( BlockHealth / MaxBlockHealth ) * 100; wchar_t wszHealthText[ 10 ]; unsigned int HealthTextLen = ARRAYSIZE( wszHealthText ); _snwprintf( wszHealthText, HealthTextLen - 1, L"%.0f%%", HealthRatio ); wszHealthText[ HealthTextLen - 1 ] = '\0'; wchar_t *printFormatString = NULL; printFormatString = L"Health | %s1 |"; g_pVGuiLocalize->ConstructString( sIDString, sizeof( sIDString ), printFormatString, 1, wszHealthText ); // Check if we have anything to output if ( sIDString[0] ) { int wide, tall; vgui::surface()->GetTextSize( m_hFont, sIDString, wide, tall ); int ypos = YRES(260); int xpos = (ScreenWidth() - wide) / 2; vgui::surface()->DrawSetTextFont( m_hFont ); vgui::surface()->DrawSetTextPos( xpos, ypos ); vgui::surface()->DrawSetTextColor( c ); vgui::surface()->DrawPrintText( sIDString, wcslen(sIDString) ); } } } }
void allymarker_think (edict_t *self) { vec3_t start, right; // must have an owner if (!self->owner || !self->owner->inuse || !self->owner->teamnum) { G_FreeEdict(self); return; } // beam diameter goes to 0 if we're dead or cloaked (to hide it) if ((self->owner->health < 1) || (self->owner->client->cloaking && self->owner->svflags & SVF_NOCLIENT) || (self->owner->flags & FL_WORMHOLE)) self->s.frame = 0; else self->s.frame = 4; self->s.skinnum = GetTeamColor(self->owner->teamnum); self->s.angles[YAW]+=18; AngleCheck(&self->s.angles[YAW]); AngleVectors(self->s.angles, NULL, right, NULL); if (PM_PlayerHasMonster(self->owner)) { VectorCopy(self->owner->owner->s.origin, start); start[2] = self->owner->owner->absmax[2]+16; } else { VectorCopy(self->owner->s.origin, start); start[2] = self->owner->absmax[2]+16; } VectorMA(start, 12, right, self->s.origin); VectorMA(start, -12, right, self->s.old_origin); gi.linkentity(self); self->nextthink = level.time + FRAMETIME; }
void CreateAllyMarker (edict_t *ent) { edict_t *laser; // no team colors to assign if (!GetTeamColor(ent->teamnum)) return; laser = G_Spawn(); laser->movetype = MOVETYPE_NONE; laser->solid = SOLID_NOT; laser->s.renderfx = RF_BEAM|RF_TRANSLUCENT; laser->s.modelindex = 1; // must be non-zero laser->classname = "allylaser"; laser->s.frame = 4; // beam diameter laser->owner = ent; laser->think = allymarker_think; gi.linkentity(laser); laser->nextthink = level.time + FRAMETIME; }
void CHudFlagCarrier::PaintBackground( void ) { // Draw The Blue Flag Carrier vgui::surface()->DrawSetColor( m_BlueBackgroundColor ); vgui::surface()->DrawFilledRect ( m_flBlueRectX, m_flBlueRectY, m_flBlueRectX + m_flBlueRectWidth, m_flBlueRectY + m_flBlueRectHeight ); if ( m_DrawBlueBorder ) { const Color BlueBorderColor = Color ( GetTeamColor( TEAM_BLUE ).r(), GetTeamColor( TEAM_BLUE ).g(), GetTeamColor( TEAM_BLUE ).b(), 200 ); #if 0 DrawBrokenBorder ( BlueBorderColor, m_flBlueRectX, m_flBlueRectY, m_flBlueRectWidth, m_flBlueRectHeight, 12, 8 ); #endif // 0 } // Draw The Red Flag Carrier vgui::surface()->DrawSetColor( m_RedBackgroundColor ); vgui::surface()->DrawFilledRect ( m_flRedRectX, m_flRedRectY, m_flRedRectX + m_flRedRectWidth, m_flRedRectY + m_flRedRectHeight ); if ( m_DrawRedBorder ) { const Color RedBorderColor = Color ( GetTeamColor( TEAM_RED ).r(), GetTeamColor( TEAM_RED ).g(), GetTeamColor( TEAM_RED ).b(), 200 ); #if 0 DrawBrokenBorder ( RedBorderColor, m_flRedRectX, m_flRedRectY, m_flRedRectWidth, m_flRedRectHeight, 12, 8 ); #endif // 0 } }
int CHudScoreboard :: DrawTeams( float list_slot ) { int j; int ypos = ystart + (list_slot * ROW_GAP) + 5; // clear out team scores for ( int i = 1; i <= m_iNumTeams; i++ ) { if ( !g_TeamInfo[i].scores_overriden ) g_TeamInfo[i].frags = g_TeamInfo[i].deaths = 0; g_TeamInfo[i].sumping = 0; g_TeamInfo[i].players = 0; g_TeamInfo[i].already_drawn = FALSE; } // recalc the team scores, then draw them for ( int i = 1; i < MAX_PLAYERS; i++ ) { if ( !g_PlayerInfoList[i].name || !g_PlayerInfoList[i].name[0] ) continue; // empty player slot, skip if ( g_PlayerExtraInfo[i].teamname[0] == 0 ) continue; // skip over players who are not in a team // find what team this player is in for ( j = 1; j <= m_iNumTeams; j++ ) { if ( !stricmp( g_PlayerExtraInfo[i].teamname, g_TeamInfo[j].name ) ) break; } if ( j > m_iNumTeams ) // player is not in a team, skip to the next guy continue; if ( !g_TeamInfo[j].scores_overriden ) { g_TeamInfo[j].frags += g_PlayerExtraInfo[i].frags; g_TeamInfo[j].deaths += g_PlayerExtraInfo[i].deaths; } g_TeamInfo[j].sumping += g_PlayerInfoList[i].ping; if ( g_PlayerInfoList[i].thisplayer ) g_TeamInfo[j].ownteam = TRUE; else g_TeamInfo[j].ownteam = FALSE; g_TeamInfo[j].players++; } // Draw the teams int iSpectatorPos = -1; while( true ) { int highest_frags = -99999; int lowest_deaths = 99999; int best_team = 0; for ( int i = 1; i <= m_iNumTeams; i++ ) { // don't draw team without players if ( g_TeamInfo[i].players <= 0 ) continue; if (!strnicmp(g_TeamInfo[i].name, "SPECTATOR", MAX_TEAM_NAME)) { iSpectatorPos = i; continue; } if ( !g_TeamInfo[i].already_drawn && g_TeamInfo[i].frags >= highest_frags ) { if ( g_TeamInfo[i].frags > highest_frags || g_TeamInfo[i].deaths < lowest_deaths ) { best_team = i; lowest_deaths = g_TeamInfo[i].deaths; highest_frags = g_TeamInfo[i].frags; } } } // draw the best team on the scoreboard if ( !best_team ) { // if spectators is found and still not drawn if( iSpectatorPos != -1 && g_TeamInfo[iSpectatorPos].already_drawn == FALSE ) best_team = iSpectatorPos; else break; } // draw out the best team team_info_t *team_info = &g_TeamInfo[best_team]; // don't draw team without players if ( team_info->players <= 0 ) continue; ypos = ystart + (list_slot * ROW_GAP); // check we haven't drawn too far down if ( ypos > yend ) // don't draw to close to the lower border break; int r, g, b; char teamName[64]; GetTeamColor( r, g, b, team_info->teamnumber ); switch( team_info->teamnumber ) { case TEAM_TERRORIST: snprintf(teamName, sizeof(teamName), "Terrorists - %i players", team_info->players); DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b ); break; case TEAM_CT: snprintf(teamName, sizeof(teamName), "Counter-Terrorists - %i players", team_info->players); DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b ); break; case TEAM_SPECTATOR: case TEAM_UNASSIGNED: strncpy( teamName, "Spectators", sizeof(teamName) ); break; } DrawUtils::DrawHudString( NAME_POS_START(), ypos, NAME_POS_END(), teamName, r, g, b ); DrawUtils::DrawHudNumberString( PING_POS_END(), ypos, PING_POS_START(), team_info->sumping / team_info->players, r, g, b ); team_info->already_drawn = TRUE; // set the already_drawn to be TRUE, so this team won't get drawn again // draw underline list_slot += 1.2f; FillRGBA( xstart, ystart + (list_slot * ROW_GAP), xend - xstart, 1, r, g, b, 255); list_slot += 0.4f; // draw all the players that belong to this team, indented slightly list_slot = DrawPlayers( list_slot, 10, team_info->name ); } // draw all the players who are not in a team list_slot += 4.0f; DrawPlayers( list_slot, 0, "" ); return 1; }
// // DrawSelf // // Redraw self // void Color::DrawSelf(PaintInfo &pi) { IControl::DrawSelf(pi); // Get the color for the current color const PlayerInfo *playerInfo; Data::Get(&playerInfo, Network::GetCurrentPlayer().GetId()); ASSERT(playerInfo); ASSERT(teamId < Game::MAX_TEAMS); const Team *team; Data::Get(&team, teamId); ASSERT(team); // Update the current color colorCurrent->SetIntegerValue(team->color); // Figure out which colors are available BinTree<GroupTree> groups; BuildPlayerHierachy(groups); Bool colors[Game::MAX_TEAMS + 1]; for (U32 t = 0; t <= Game::MAX_TEAMS; t++) { colors[t] = FALSE; } for (BinTree<GroupTree>::Iterator gti(&groups); *gti; gti++) { for (BinTree<TeamTree>::Iterator tti(&(*gti)->teams); *tti; tti++) { colors[(*tti)->team->color] = TRUE; } } groups.DisposeAll(); /* // Is the currently selected color still available ? if (colors[colorSelected->GetIntegerValue()]) { colorSelected->SetIntegerValue(team->color); } */ // Display all of the available colors for (t = 0; t <= Game::MAX_TEAMS; t++) { // Is the color available ? if (!colors[t] || t == team->color) { Point<S32> p(t * pi.client.Height(), 0); // Draw the team color ClipRect c( pi.client.p0.x + p.x + 3, pi.client.p0.y + p.y + 3, pi.client.p0.x + p.x + pi.client.Height() - 3, pi.client.p0.y + p.y + pi.client.Height() - 3); IFace::RenderShadow( c, c + IFace::GetMetric(IFace::DROPSHADOW_UP), ::Color(0, 0, 0, IFace::GetMetric(IFace::SHADOW_ALPHA)), 0); IFace::RenderGradient(c, GetTeamColor(t), 150); // Is this the selected color ? if (t == U32(colorSelected->GetIntegerValue())) { IFace::RenderGradient( ClipRect( pi.client.p0.x + p.x + 1, pi.client.p0.y + p.y + 1, pi.client.p0.x + p.x + pi.client.Height() - 1, pi.client.p0.y + p.y + pi.client.Height() - 1), ::Color(1.0f, 1.0f, 1.0f, 0.4f), ::Color(0.5f, 0.5f, 0.5f, 0.4f)); } // Is this the current color ? else if (t == team->color) { IFace::RenderGradient( ClipRect( pi.client.p0.x + p.x + 1, pi.client.p0.y + p.y + 1, pi.client.p0.x + p.x + pi.client.Height() - 1, pi.client.p0.y + p.y + pi.client.Height() - 1), ::Color(1.0f, 1.0f, 1.0f, 0.15f), ::Color(0.5f, 0.5f, 0.5f, 0.15f)); } } } }
void CHudDomScore::PaintBackground( void ) { // Draw The Blue Flag Carrier vgui::surface()->DrawSetColor( m_BlueBackgroundColor ); vgui::surface()->DrawFilledRect ( m_flBlueRectX, m_flBlueRectY, m_flBlueRectX + m_flBlueRectWidth, m_flBlueRectY + m_flBlueRectHeight ); if ( m_DrawBlueBorder ) { const Color BlueBorderColor = Color ( GetTeamColor( SDK_TEAM_BLUE ).r(), GetTeamColor( SDK_TEAM_BLUE ).g(), GetTeamColor( SDK_TEAM_BLUE ).b(), 200 ); // DrawBrokenBorder // ( // BlueBorderColor, // m_flBlueRectX, // m_flBlueRectY, // m_flBlueRectWidth, // m_flBlueRectHeight, // 12, 8 // ); } // Draw The Red Flag Carrier vgui::surface()->DrawSetColor( m_RedBackgroundColor ); vgui::surface()->DrawFilledRect ( m_flRedRectX, m_flRedRectY, m_flRedRectX + m_flRedRectWidth, m_flRedRectY + m_flRedRectHeight ); if ( m_DrawRedBorder ) { const Color RedBorderColor = Color ( GetTeamColor( SDK_TEAM_RED ).r(), GetTeamColor( SDK_TEAM_RED ).g(), GetTeamColor( SDK_TEAM_RED ).b(), 200 ); // DrawBrokenBorder // ( // RedBorderColor, // m_flRedRectX, // m_flRedRectY, // m_flRedRectWidth, // m_flRedRectHeight, // 12, 8 // ); } }
void ScoreboardView::Draw() { SPADES_MARK_FUNCTION(); world = client->GetWorld(); if(!world){ // no world return; } ctf = dynamic_cast<CTFGameMode *>(world->GetMode()); tc = dynamic_cast<TCGameMode *>(world->GetMode()); Handle<IImage>image; IFont *font; Vector2 pos, size; char buf[256]; std::string str; float scrWidth = renderer->ScreenWidth(); float scrHeight = renderer->ScreenHeight(); const Vector4 whiteColor = {1,1,1,1}; Handle<IImage> whiteImage = renderer->RegisterImage("Gfx/White.tga"); float teamBarTop = 120.f; float teamBarHeight = 60.f; float contentsLeft = scrWidth * .5f - 400.f; float contentsRight = scrWidth * .5f + 400.f; float playersHeight = 300.f; float playersTop = teamBarTop + teamBarHeight; float playersBottom = playersTop + playersHeight; // draw shadow image = renderer->RegisterImage("Gfx/Scoreboard/TopShadow.tga"); size.y = 32.f; renderer->SetColor(MakeVector4(0,0,0,0.2f)); renderer->DrawImage(image, AABB2(0, teamBarTop-size.y, scrWidth, size.y)); renderer->SetColor(MakeVector4(0,0,0,0.2f)); renderer->DrawImage(image, AABB2(0, playersBottom + size.y, scrWidth, -size.y)); // draw scores image = renderer->RegisterImage("Gfx/Scoreboard/ScoresBg.tga"); size = MakeVector2(180.f, 32.f); pos = MakeVector2((scrWidth - size.x) * .5f, teamBarTop - size.y); renderer->SetColor(MakeVector4(1.f, .45f, .2f, 1.f)); renderer->DrawImage(image, AABB2(pos.x,pos.y,size.x,size.y)); pos.y = pos.y + 5.f; font = client->designFont; sprintf(buf, "%d", GetTeamScore(0)); size = font->Measure(buf); pos.x = scrWidth * .5f - size.x - 16.f; font->Draw(buf, pos + MakeVector2(0, 1), 1.f, MakeVector4(0, 0, 0, 0.3)); font->Draw(buf, pos, 1.f, whiteColor); sprintf(buf, "%d", GetTeamScore(1)); size = font->Measure(buf); pos.x = scrWidth * .5f + 16.f; font->Draw(buf, pos + MakeVector2(0, 1), 1.f, MakeVector4(0, 0, 0, 0.3)); font->Draw(buf, pos, 1.f, whiteColor); sprintf(buf, "-"); size = font->Measure(buf); pos.x = scrWidth * .5f - size.x * .5f; font->Draw(buf, pos + MakeVector2(0, 1), 1.f, MakeVector4(0, 0, 0, 0.3)); font->Draw(buf, pos, 1.f, whiteColor); // draw team bar image = whiteImage; renderer->SetColor(AdjustColor(GetTeamColor(0), 0.8f, 0.3f)); renderer->DrawImage(image, AABB2(0, teamBarTop, scrWidth * .5f, teamBarHeight)); renderer->SetColor(AdjustColor(GetTeamColor(1), 0.8f, 0.3f)); renderer->DrawImage(image, AABB2(scrWidth * .5f, teamBarTop, scrWidth * .5f, teamBarHeight)); image = renderer->RegisterImage("Gfx/Scoreboard/Grunt.tga"); size.x = 120.f; size.y = 60.f; renderer->DrawImage(image, AABB2(contentsLeft, teamBarTop + teamBarHeight - size.y, size.x, size.y)); renderer->DrawImage(image, AABB2(contentsRight, teamBarTop + teamBarHeight - size.y, -size.x, size.y)); font = client->bigTextFont; str = world->GetTeam(0).name; pos.x = contentsLeft + 110.f; pos.y = teamBarTop + 5.f; font->Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5)); font->Draw(str, pos, 1.f, whiteColor); str = world->GetTeam(1).name; size = font->Measure(str); pos.x = contentsRight - 110.f - size.x; pos.y = teamBarTop + 5.f; font->Draw(str, pos + MakeVector2(0, 2), 1.f, MakeVector4(0, 0, 0, 0.5)); font->Draw(str, pos, 1.f, whiteColor); // players background image = renderer->RegisterImage("Gfx/Scoreboard/PlayersBg.tga"); renderer->SetColor(MakeVector4(0, 0, 0, 1.f)); renderer->DrawImage(image, AABB2(0, playersTop, scrWidth, playersHeight)); // draw players DrawPlayers(0, contentsLeft, playersTop, (contentsRight - contentsLeft) * .5f, playersHeight); DrawPlayers(1, scrWidth * .5f, playersTop, (contentsRight - contentsLeft) * .5f, playersHeight); }
void ScoreboardView::DrawPlayers(int team, float left, float top, float width, float height){ IFont *font = client->textFont; float rowHeight = 24.f; char buf[256]; Vector2 size; Vector4 white = { 1,1,1,1 }; int maxRows = (int)floorf(height / rowHeight); int numPlayers = 0; int cols; std::vector<ScoreboardEntry> entries; for(int i = 0; i < world->GetNumPlayerSlots(); i++){ Player *p = world->GetPlayer(i); if(!p) continue; if(p->GetTeamId() != team) continue; ScoreboardEntry ent; ent.name = p->GetName(); ent.score = world->GetPlayerPersistent(i).kills; ent.id = i; entries.push_back(ent); numPlayers++; } std::sort(entries.begin(), entries.end()); cols = (numPlayers + maxRows - 1) / maxRows; if(cols == 0)cols = 1; maxRows = (numPlayers + cols - 1) / cols; int row = 0, col = 0; float colWidth = (float)width / (float)cols; for(int i = 0; i < numPlayers; i++){ ScoreboardEntry& ent = entries[i]; float rowY = top + 6.f + row * rowHeight; float colX = left + width / (float)cols * (float)col; Vector4 color = white; if(ent.id == world->GetLocalPlayerIndex()) color = GetTeamColor(team); sprintf(buf, "#%d", ent.id); // FIXME: 1-base? size = font->Measure(buf); font->Draw(buf, MakeVector2(colX + 35.f - size.x, rowY), 1.f, color); font->Draw(ent.name, MakeVector2(colX + 45.f, rowY), 1.f, color); sprintf(buf, "%d", ent.score); size = font->Measure(buf); font->Draw(buf, MakeVector2(colX + colWidth - 10.f - size.x, rowY), 1.f, color); row++; if(row >= maxRows){ col++; row = 0; } } }