📄 fraginfo.cpp
字号:
HSURFACE hScreen = m_pClientDE->GetScreenSurface();
m_pClientDE->DrawSurfaceToSurfaceTransparent(hScreen, m_hFragTable, DNULL, m_nFragTableX, m_nFragTableY, m_hTransColor);
}
}
//*********************************************************************************
void CFragInfo::AdjustRes()
{
if(!m_pClientDE) return;
HSURFACE hScreen = m_pClientDE->GetScreenSurface();
DDWORD width, height;
m_pClientDE->GetSurfaceDims(hScreen, &width, &height);
// If we're at the same resolution, just return
if((width == m_nScreenWidth) && (height == m_nScreenHeight))
return;
// Otherwise set the variables to the new resolution
m_nScreenWidth = width;
m_nScreenHeight = height;
m_pClientDE->GetSurfaceDims(m_hFragBar, &width, &height);
m_nFragTableX = (m_nScreenWidth - width) / 2;
m_nFragTableY = height;
m_nFragTableHeight = m_nScreenHeight - height - height;
m_nFragTableMaxDisp = m_nFragTableHeight / height;
if(m_hFragTable) { m_pClientDE->DeleteSurface(m_hFragTable); m_hFragTable = 0; }
m_hFragTable = m_pClientDE->CreateSurface(width, m_nFragTableHeight);
m_pClientDE->FillRect(m_hFragTable, DNULL, m_hTransColor);
}
//*********************************************************************************
void CFragInfo::UpdateFragTable()
{
if(!m_pClientDE || !m_pClients || !m_hFragTable) return;
DDWORD barWidth, barHeight;
DDWORD picWidth, picHeight;
DBYTE currentPic = 0;
DDWORD numClients = 0;
DDWORD i = 0, numDisp = 0;
DDWORD startY = 0;
CLIENT_INFO* pClient = m_pClients;
// Get the width and height of a frag display for just one character
m_pClientDE->GetSurfaceDims(m_hFragBar, &barWidth, &barHeight);
// Count the number of clients in the game
while(pClient)
{ numClients++; pClient = pClient->pNext; }
// Find the maximum number of clients to display frags for
if(numClients <= m_nFragTableMaxDisp)
numDisp = numClients;
else
numDisp = m_nFragTableMaxDisp;
// Check if we should be in scrunch mode...
DBOOL bScrunch = DFALSE;
if (m_nScreenHeight < 350)
{
bScrunch = DTRUE;
}
// Find out where to start drawing within the frag table
startY = (m_nFragTableHeight - (numDisp * barHeight)) / 2;
// Clear the frag screen and setup the variables
m_pClientDE->FillRect(m_hFragTable, DNULL, m_hTransColor);
m_pCursor->SetDest(m_hFragTable);
pClient = m_pClients;
while(pClient && (i < numDisp))
{
char temp[100];
// Choose which icon to draw for this client
currentPic = pClient->byCharacter;
if(currentPic < 0 || currentPic > (NUM_FRAG_PICS-2))
currentPic = FRAG_PIC_UNKNOWN;
// Get the width and height of a the character pic
m_pClientDE->GetSurfaceDims(m_hFragPics[currentPic], &picWidth, &picHeight);
// Draw the fragbar and icon for this client
if (!bScrunch)
{
m_pClientDE->DrawSurfaceToSurface(m_hFragTable, m_hFragBar, DNULL, 0, startY);
m_pClientDE->DrawSurfaceToSurface(m_hFragTable, m_hFragPics[currentPic], DNULL, 0, startY);
}
// Draw the name of the client
m_pCursor->SetLoc((short)picWidth, (short)(startY + ((barHeight - m_pFont->height) / 2)));
m_pCursor->SetJustify(CF_JUSTIFY_LEFT);
DrawClip(GetDisplayPingAndName(pClient, temp), FRAG_NAME_PIXEL_WIDTH);
// Draw the number of frag the client has
sprintf(temp, "%d", pClient->nFrags);
m_pCursor->SetLoc((short)(barWidth - FRAG_COUNT_OFFSET), (short)(startY + ((barHeight - m_pFont->height) / 2)));
m_pCursor->SetJustify(CF_JUSTIFY_CENTER);
m_pCursor->Draw(temp);
// Go to the next client
pClient = pClient->pNext;
startY += barHeight;
if (bScrunch) startY -= 18;
i++;
}
}
//*********************************************************************************
void CFragInfo::DrawTeams()
{
// Check if only one colum will fit on the screen...
if (m_nScreenWidth < 500)
{
DrawSingleColumnTeams();
return;
}
// Sort the players by frag counts...
m_pTeamMgr->SortPlayersByFrags();
// Get the width and height of a frag display for just one character..
DDWORD barWidth;
DDWORD barHeight;
m_pClientDE->GetSurfaceDims(m_hFragBar, &barWidth, &barHeight);
// Calculate the X draw coordinate...
int cTeams = m_pTeamMgr->GetNumTeams();
if (cTeams <= 0) return;
int nTotalWidth = (cTeams * barWidth) + ((cTeams - 1) * FRAG_COLUMN_SPACE);
int xDraw = (m_nScreenWidth / 2) - (nTotalWidth / 2);
if (xDraw < 0) xDraw = 0;
// Calculate the Y draw coordinate...
CTeam* pMostTeam = m_pTeamMgr->GetTeamWithMostPlayers(FALSE);
int cPlayers = m_nFragTableMaxDisp;
if (pMostTeam)
{
cPlayers = pMostTeam->GetNumPlayers();
}
cPlayers++; // add one more row for the colulmn title
int nTotalHeight = barHeight * cPlayers;
int yDraw = ((m_nScreenHeight / 2) - (nTotalHeight / 2)) - barHeight;
if (yDraw < 0) yDraw = 0;
// Draw each team...
CTeam* pTeam = m_pTeamMgr->GetFirstTeam();
while (pTeam)
{
DrawTeamColumn(pTeam, xDraw, yDraw, m_nFragTableMaxDisp);
pTeam = m_pTeamMgr->GetNextTeam(pTeam);
xDraw += barWidth + FRAG_COLUMN_SPACE;
}
}
//*********************************************************************************
void CFragInfo::DrawTeamColumn(CTeam* pTeam, int xDraw, int yDraw, int nMax)
{
// Sanity checks...
if (!pTeam) return;
if (!m_hFragBar) return;
// Clear the frag screen and setup the variables...
m_pClientDE->FillRect(m_hFragTable, DNULL, m_hTransColor);
m_pCursor->SetDest(m_hFragTable);
// Get the width and height of a frag display for just one character...
DDWORD barWidth;
DDWORD barHeight;
m_pClientDE->GetSurfaceDims(m_hFragBar, &barWidth, &barHeight);
// Check if we should be in scrunch mode...
DBOOL bScrunch = DFALSE;
if (m_nScreenHeight < 350)
{
bScrunch = DTRUE;
}
// Calculate the xStart and yStart values...
int xStart = 0;
int yStart = (m_nFragTableHeight - (m_nFragTableMaxDisp * barHeight)) / 2;
// Draw the column title with the team name and total score...
DDWORD picWidth, picHeight;
m_pClientDE->GetSurfaceDims(m_hFragPics[FRAG_PIC_VOICE], &picWidth, &picHeight);
if (!bScrunch)
{
m_pClientDE->DrawSurfaceToSurface(m_hFragTable, m_hFragBar, DNULL, xStart, yStart);
m_pClientDE->DrawSurfaceToSurface(m_hFragTable, m_hFragPics[FRAG_PIC_VOICE], DNULL, xStart, yStart);
}
m_pCursor->SetLoc((short)(xStart + picWidth), (short)(yStart + ((barHeight - m_pFont->height) / 2)));
m_pCursor->SetJustify(CF_JUSTIFY_LEFT);
m_pCursor->Draw(pTeam->GetName());
char sTemp[16];
sprintf(sTemp, "%d", pTeam->GetFrags());
m_pCursor->SetLoc((short)(xStart + (barWidth - FRAG_COUNT_OFFSET)), (short)(yStart + ((barHeight - m_pFont->height) / 2)));
m_pCursor->SetJustify(CF_JUSTIFY_CENTER);
m_pCursor->Draw(sTemp);
yStart += barHeight;
yStart += m_pFont->height / 2;
if (bScrunch) yStart -= 20;
// Draw each player's frag count on this team...
CTeamPlayer* pPlr = pTeam->GetFirstPlayer();
int nCount = 0;
while (pPlr)
{
// Find the client info for this player...
CLIENT_INFO* pClient = GetClientInfo(pPlr->GetID());
nCount++;
if (pClient && nCount < nMax)
{
// Choose which icon to draw for this client
DBYTE byPic = pClient->byCharacter;
if (byPic < 0 || byPic > (NUM_FRAG_PICS-2)) byPic = FRAG_PIC_UNKNOWN;
// Get the width and height of a the character pic
DDWORD picWidth, picHeight;
m_pClientDE->GetSurfaceDims(m_hFragPics[byPic], &picWidth, &picHeight);
// Draw the fragbar and icon for this client
if (!bScrunch)
{
m_pClientDE->DrawSurfaceToSurface(m_hFragTable, m_hFragBar, DNULL, xStart, yStart);
m_pClientDE->DrawSurfaceToSurface(m_hFragTable, m_hFragPics[byPic], DNULL, xStart, yStart);
}
// Draw the name of the client
char sTemp[100];
m_pCursor->SetLoc((short)(xStart + picWidth), (short)(yStart + ((barHeight - m_pFont->height) / 2)));
m_pCursor->SetJustify(CF_JUSTIFY_LEFT);
DrawClip(GetDisplayPingAndName(pClient, sTemp), FRAG_NAME_PIXEL_WIDTH);
// Draw the number of frag the client has
sprintf(sTemp, "%d", pClient->nFrags);
m_pCursor->SetLoc((short)(xStart + (barWidth - FRAG_COUNT_OFFSET)), (short)(yStart + ((barHeight - m_pFont->height) / 2)));
m_pCursor->SetJustify(CF_JUSTIFY_CENTER);
m_pCursor->Draw(sTemp);
// Update the drawing position
yStart += barHeight;
if (bScrunch) yStart -= 18;
}
// Get the next player...
pPlr = pTeam->GetNextPlayer(pPlr);
}
HSURFACE hScreen = m_pClientDE->GetScreenSurface();
DRESULT dr = m_pClientDE->DrawSurfaceToSurfaceTransparent(hScreen, m_hFragTable, DNULL, xDraw, yDraw, m_hTransColor);
}
//*********************************************************************************
void CFragInfo::DrawSingleColumnTeams()
{
// Sort the players by frag counts...
m_pTeamMgr->SortPlayersByFrags();
// Get the width and height of a frag display for just one character..
DDWORD barWidth;
DDWORD barHeight;
m_pClientDE->GetSurfaceDims(m_hFragBar, &barWidth, &barHeight);
// Calculate the X draw coordinate...
int cTeams = 1;
int nTotalWidth = (cTeams * barWidth) + ((cTeams - 1) * FRAG_COLUMN_SPACE);
int xDraw = (m_nScreenWidth / 2) - (nTotalWidth / 2);
if (xDraw < 0) xDraw = 0;
// Calculate the Y draw coordinate...
CTeam* pTeam = m_pTeamMgr->GetTeam(m_nTeamID);
if (!pTeam) return;
int cPlayers = pTeam->GetNumPlayers();
cPlayers++; // add one more row for the colulmn title
int nTotalHeight = barHeight * cPlayers;
int yDraw = ((m_nScreenHeight / 2) - (nTotalHeight / 2)) - barHeight;
if (yDraw < 0) yDraw = 0;
// Draw the team...
DrawTeamColumn(pTeam, xDraw, yDraw, m_nFragTableMaxDisp);
}
//*********************************************************************************
void CFragInfo::TurnOn()
{
// Get the next team to draw for team based toggle draw mode...
m_nTeamID++;
CTeam* pTeam = m_pTeamMgr->GetTeam(m_nTeamID);
if (!pTeam)
{
m_nTeamID = 1;
}
}
void CFragInfo::TurnOff()
{
}
//*********************************************************************************
char* CFragInfo::GetDisplayPingAndName(CLIENT_INFO* pClient, char* sBuf)
{
// Sanity checks...
if (!sBuf) return(DNULL);
strcpy(sBuf, "");
if (!pClient) return(sBuf);
// Copy the ping and name into the given buffer...
if (pClient->nPing <= 0)
{
sprintf(sBuf, "(-) %s", m_pClientDE->GetStringData(pClient->hstrName));
}
else
{
sprintf(sBuf, "(%i) %s", pClient->nPing, m_pClientDE->GetStringData(pClient->hstrName));
}
// All done...
return(sBuf);
}
//*********************************************************************************
void CFragInfo::UpdatePlayerPing(DDWORD dwPlayerID, int nPing)
{
CLIENT_INFO* pClient = GetClientInfo(dwPlayerID);
if (!pClient) return;
if (nPing == 0) nPing = 1;
pClient->nPing = nPing;
}
//*********************************************************************************
void CFragInfo::DrawClip(char* sText, int nMax)
{
// Sanity checks...
if (!sText) return;
if (nMax <= 0) return;
// Check if it's ok to write the entire string...
DIntPt pt = m_pFont->GetTextExtents(sText);
if (pt.x < nMax)
{
m_pCursor->Draw(sText);
}
// Draw the biggest sub-string that will fit...
int nLen = strlen(sText);
while (nLen > 1)
{
nLen--;
sText[nLen] = '\0';
DIntPt pt = m_pFont->GetTextExtents(sText);
if (pt.x < nMax)
{
m_pCursor->Draw(sText);
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -