📄 credits.cpp
字号:
if (m_fColor > 1.0f) m_fColor = 1.0f;
HDECOLOR hColor = m_pClientDE->SetupColor1(m_fColor, 0, 0, DFALSE);
// Draw the credit...
Draw(s_dwScreenWidth / 2, s_dwScreenHeight / 2, hColor);
// All done...
return(m_fTimer == 0.0f);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredit::UpdateHoldIn
//
// PURPOSE: Updates the CS_HOLDIN state
//
// ----------------------------------------------------------------------- //
DBOOL CCredit::UpdateHoldIn()
{
// Update the timer value...
DFLOAT fDelta = m_pClientDE->GetFrameTime();
fDelta *= CCredits::GetSpeed();
if (s_bPause) fDelta = 0;
if (m_fTimer > fDelta)
{
m_fTimer -= fDelta;
}
else
{
m_fTimer = 0.0f;
}
// Create the color stuff...
m_fColor = 1.0f;
HDECOLOR hColor = m_pClientDE->SetupColor1(m_fColor, 0, 0, DFALSE);
// Draw the credit...
Draw(s_dwScreenWidth / 2, s_dwScreenHeight / 2, hColor);
// All done...
return(m_fTimer == 0.0f);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredit::UpdateFadeOut
//
// PURPOSE: Updates the CS_FADEOUT state
//
// ----------------------------------------------------------------------- //
DBOOL CCredit::UpdateFadeOut()
{
// Update the timer value...
DFLOAT fDelta = m_pClientDE->GetFrameTime();
fDelta *= CCredits::GetSpeed();
if (s_bPause) fDelta = 0;
if (m_fTimer > fDelta)
{
m_fTimer -= fDelta;
}
else
{
m_fTimer = 0.0f;
}
// Update our color value...
m_fColor = m_fTimer / m_fTimerStart;
// Create the color stuff...
if (m_fColor < 0.0f) m_fColor = 0.0f;
if (!s_bClearScreen && m_fColor < 0.1f)
{
m_fColor = 0.1f;
m_fTimer = 0.0f;
}
HDECOLOR hColor = m_pClientDE->SetupColor1(m_fColor, 0, 0, DFALSE);
// Draw the credit...
Draw(s_dwScreenWidth / 2, s_dwScreenHeight / 2, hColor);
// All done...
return(m_fTimer == 0.0f);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredit::UpdateHoldOut
//
// PURPOSE: Updates the CS_HOLDOUT state
//
// ----------------------------------------------------------------------- //
DBOOL CCredit::UpdateHoldOut()
{
// Update the timer value...
DFLOAT fDelta = m_pClientDE->GetFrameTime();
fDelta *= CCredits::GetSpeed();
if (s_bPause) fDelta = 0;
if (m_fTimer > fDelta)
{
m_fTimer -= fDelta;
}
else
{
m_fTimer = 0.0f;
}
// All done...
return(m_fTimer == 0.0f);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::Init
//
// PURPOSE: Initialization
//
// ----------------------------------------------------------------------- //
DBOOL CCredits::Init(CClientDE* pClientDE, CBloodClientShell* pClientShell, int nMode, DBOOL bClearScreen)
{
// Sanity checks...
if (!pClientDE) return(DFALSE);
if (!pClientShell) return(DFALSE);
Term();
// Set simple members...
m_pClientDE = pClientDE;
m_pClientShell = pClientShell;
m_iCredit = 0;
m_nMode = nMode;
m_bDone = DFALSE;
m_bClearScreen = bClearScreen;
s_fSpeed = DEF_CREDITS_SPEED;
// Init the screen size...
m_hScreen = m_pClientDE->GetScreenSurface();
if (!m_hScreen) return(DFALSE);
m_pClientDE->GetSurfaceDims(m_hScreen, &m_szScreen.cx, &m_szScreen.cy);
// Add all the credit objects...
AddCredits();
// All done...
m_bInited = DTRUE;
return(DTRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::Term
//
// PURPOSE: Termination
//
// ----------------------------------------------------------------------- //
void CCredits::Term()
{
// Term all the credits...
for (int i = 0; i < MAX_CREDITS; i++)
{
CCredit* pCredit = GetCredit(i);
if (pCredit) pCredit->Term();
}
// Clear all members...
CCredit::TermStaticInfo();
Clear();
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::HandleInput
//
// PURPOSE: Handler for input
//
// ----------------------------------------------------------------------- //
void CCredits::HandleInput(int vkey)
{
// Handle various kes...
switch (vkey)
{
case VK_UP:
{
if (IsIntro()) break;
IncSpeed();
break;
}
case VK_DOWN:
{
if (IsIntro()) break;
DecSpeed();
break;
}
case VK_HOME:
{
if (IsIntro()) break;
s_fSpeed = 1.0;
break;
}
case VK_RETURN:
case VK_SPACE:
case VK_NEXT:
{
if (IsIntro())
{
CCredit* pCredit = GetCredit(m_iCredit);
if (pCredit)
{
if (pCredit->GetState() == CS_HOLDIN)
{
pCredit->SetState(CS_FADEOUT);
}
}
}
else
{
AdvanceCredit(CS_HOLDIN);
}
break;
}
case VK_PAUSE:
{
if (IsIntro()) break;
s_bPause ^= 1;
break;
}
case VK_ESCAPE:
{
ExitToMainMenu();
break;
}
}
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::ExitToMainMenu
//
// PURPOSE: Exits back to the main menu game state
//
// ----------------------------------------------------------------------- //
void CCredits::ExitToMainMenu()
{
m_bDone = DTRUE;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::Update
//
// PURPOSE: Updates the credits
//
// ----------------------------------------------------------------------- //
void CCredits::Update()
{
// Sanity checks...
if (!m_pClientDE) return;
if (m_cCredits <= 0) return;
// Clear the screen...
if (m_bClearScreen)
{
m_pClientDE->ClearScreen(NULL, CLEARSCREEN_SCREEN);
}
// Update the current credit...
CCredit* pCredit = GetCredit(m_iCredit);
if (!pCredit) return;
if (pCredit->Update())
{
AdvanceCredit();
}
}
void CCredits::AdvanceCredit(int nState)
{
m_iCredit++;
if(m_iCredit >= m_cCredits)
{
m_iCredit = 0;
if (IsIntro()) m_bDone = DTRUE;
}
CCredit* pCredit = GetCredit(m_iCredit);
if (pCredit) pCredit->SetState(nState);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::DrawCenteredString
//
// PURPOSE: Draws the given string centered at the give coord
//
// ----------------------------------------------------------------------- //
void CCredits::DrawCenteredStringToScreen(HDEFONT hFont, HSTRING hString, HDECOLOR hForeColor, HDECOLOR hBackColor, int xDraw, int yDraw)
{
// Sanity checks...
if (!hFont) return;
if (!hString) return;
// Calculate the bounding rect of this string...
int xString = 100;
int yString = 100;
m_pClientDE->GetStringDimensions(hFont, hString, &xString, &yString);
DRect rcDraw;
rcDraw.left = xDraw - (xString / 2);
rcDraw.top = yDraw - (yString / 2);
rcDraw.right = m_szScreen.cx - 1;
rcDraw.bottom = m_szScreen.cy - 1;
// Draw the string to the screen surface...
if (!m_bClearScreen) hBackColor = SETRGB_T(0, 0, 0);
m_pClientDE->DrawStringToSurface(m_hScreen, hFont, hString, &rcDraw, hForeColor, hBackColor);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: CCredits::AddCredits
//
// PURPOSE: Adds all the credit objects
//
// ----------------------------------------------------------------------- //
void CCredits::AddCredits()
{
// Sanity checks...
if (!m_pClientDE) return;
// Set the static info...
if (!CCredit::SetStaticInfo(m_pClientDE, GetMode(), IsClearingScreen()))
{
return;
}
// Get the credits text buffer...
char* sName = NULL;
#ifdef _ADDON
if (IsIntro()) sName = "INTRO_AO";
else sName = "CREDITS_AO";
#else
if (IsIntro()) sName = "INTRO";
else sName = "CREDITS";
#endif
void* hModule = NULL;
m_pClientDE->GetEngineHook("cres_hinstance", &hModule);
char* sBuf = CreditsWin_GetTextBuffer(sName, hModule);
if (!sBuf) return;
char sCredit[1024];
int i = 0;
while (*sBuf)
{
if (*sBuf == '#' && *((char*)_mbsinc((const unsigned char*)sBuf)) == '#')
{
sCredit[i] = '\0';
if (_mbsnbcmp((const unsigned char*)sCredit, (const unsigned char*)">END", 4) == 0) // end?
{
return;
}
AddCredit(sCredit);
i = 0;
sBuf = (char*)_mbsinc((const unsigned char*)sBuf);
sBuf = (char*)_mbsinc((const unsigned char*)sBuf);
while (*sBuf != '\0' && ((*sBuf == '\n') || (*sBuf == '\r'))) sBuf++;
}
else
{
int nCount = _mbsnbcnt((const unsigned char*)sBuf,1);
memcpy(&sCredit[i], sBuf, nCount);
i += nCount;
sBuf = (char*)_mbsinc((const unsigned char*)sBuf);
}
}
}
void CCredits::AddCredit(char* sText)
{
// Sanity checks...
if (!m_pClientDE) return;
// Add the credit...
CCredit* pCredit = GetCredit(m_cCredits);
if (!pCredit) return;
if (!pCredit->Init(m_pClientDE, sText)) return;
// Inc our credit counter...
m_cCredits++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -