⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newstatusbar.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//*************************************************************************
//*****	Function:	UpdateCurrentWeap()
//*****	Details:	Changes the weapons to the latest one
//*************************************************************************

void CNewStatusBar::UpdateCurrentWeap(char slot)
{
	if((slot < 0) || (slot >= WEAPTAB_SLOTS))
	{
		// Clear out the weapon picture, cause it's probably an inventory weapon
		m_pClientDE->DeleteSurface(m_stAmmo.hIcon);
		m_stAmmo.hIcon = 0;
		m_nOldAmmo = -1;
		m_nOldAltAmmo = -1;
		return;
	}

	// Change the icon above the ammo to the current weapon
	if(m_stAmmo.hIcon)
	{
		m_pClientDE->DeleteSurface(m_stAmmo.hIcon);
		m_stAmmo.hIcon = 0;
	}

	if(m_pWeapPics[slot])
	{
		m_stAmmo.hIcon = m_pClientDE->CreateSurfaceFromBitmap(m_pClientDE->GetStringData(m_pWeapPics[slot]));
		m_nOldAmmo = -1;
		m_nOldAltAmmo = -1;
	}

	// Change the currently highlighted icon back to normal
	if(m_pWeapPics[m_nCurrentWeapon])
	{
		if(m_stWeapons[m_nCurrentWeapon].hIcon)
		{
			m_pClientDE->DeleteSurface(m_stWeapons[m_nCurrentWeapon].hIcon);
			m_stWeapons[m_nCurrentWeapon].hIcon = 0;
		}

		m_stWeapons[m_nCurrentWeapon].hIcon = m_pClientDE->CreateSurfaceFromBitmap(m_pClientDE->GetStringData(m_pWeapPics[m_nCurrentWeapon]));
		SetupTab(m_stWeapons[m_nCurrentWeapon], m_pStatNumbers2, TAB_INC_HIGH);
	}

	// Set the new current weapon to the highlighted icon
	if(m_pWeapPicsH[slot])
	{
		if(m_stWeapons[slot].hIcon)
		{
			m_pClientDE->DeleteSurface(m_stWeapons[slot].hIcon);
			m_stWeapons[slot].hIcon = 0;
		}

		m_stWeapons[slot].hIcon = m_pClientDE->CreateSurfaceFromBitmap(m_pClientDE->GetStringData(m_pWeapPicsH[slot]));
		SetupTab(m_stWeapons[slot], m_pStatNumbers2, TAB_INC_HIGH);
	}

	// Set the current weapon to the new weapon
	m_nCurrentWeapon = slot;
}

//*************************************************************************
//*****	Function:	StatLevelUp()
//*****	Details:	Increases the stat display level
//*************************************************************************

void CNewStatusBar::StatLevelUp()
{
	if(!m_bHighGraphics && (m_nStatLevel == STATTAB_LOW))	return;
	if(m_nStatLevel < STATTAB_HIGH) m_nStatLevel++;
}

//*************************************************************************
//*****	Function:	StatLevelDown()
//*****	Details:	Decreases the stat display level
//*************************************************************************

void CNewStatusBar::StatLevelDown()
{
	if(m_nStatLevel) m_nStatLevel--;
}

//*************************************************************************
//*****	Function:	SetStatLevel()
//*****	Details:	Sets the stat display level
//*************************************************************************

void CNewStatusBar::SetStatLevel(DBYTE nLevel)
{
	if((nLevel > STATTAB_LOW) && !m_bHighGraphics)	return;
	m_nStatLevel = nLevel;
}

//*************************************************************************
//*****	Function:	ToggleObjectives()
//*****	Details:	Turns the objectives screen on and off
//*************************************************************************

void CNewStatusBar::ToggleObjectives()
{
	PlaySoundInfo playSoundInfo;

	PLAYSOUNDINFO_INIT(playSoundInfo);
	playSoundInfo.m_dwFlags = PLAYSOUND_LOCAL;
	playSoundInfo.m_dwFlags |= PLAYSOUND_FILESTREAM;
	playSoundInfo.m_nPriority = SOUNDPRIORITY_MISC_MEDIUM;
	_mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)"Sounds\\Interface\\MainMenus\\missionobj.wav", sizeof(playSoundInfo.m_szSoundName) - 1);

	if(m_nObjLevel == OBJTAB_INVISIBLE)
	{
		m_nObjLevel = OBJTAB_SCALE_UP;
		m_fObjUpdateTime = m_pClientDE->GetTime();
		m_nObjIcon = OBJICON_INVISIBLE;
		m_pClientDE->PlaySound (&playSoundInfo);
	}
	else if(m_nObjLevel == OBJTAB_STOPPED)
	{
		m_nObjLevel = OBJTAB_SCALE_DOWN;
		m_fObjUpdateTime = m_pClientDE->GetTime();
		m_pClientDE->PlaySound (&playSoundInfo);
	}
}

//*************************************************************************
//*****	Function:	UpdateObjectives()
//*****	Details:	Change the current objective
//*************************************************************************

void CNewStatusBar::UpdateObjectives(char *title, char *string)
{
	if(!m_pClientDE || !m_hObjectives)	return;

	// If we send in a null title or string, reset the objectives
	if(!title || !string)
	{
		InitObjectivesTab();
		m_nObjIcon = OBJICON_INVISIBLE;
		return;
	}

	// If we're not in the right game type for objectives, just return
	if (g_pBloodClientShell->GetGameType() != GAMETYPE_SINGLE && g_pBloodClientShell->GetGameType() != GAMETYPE_CUSTOM)
	{
		return;
	}

	// Reset the background picture of the objectives
	DDWORD width, height;
	m_pClientDE->DrawBitmapToSurface(m_hObjectives, "interface/objectives/objectives.pcx", DNULL, 0, 0);
	m_pClientDE->GetSurfaceDims(m_hObjectives, &width, &height);

	// Setup the font and print it out on the surface
	m_pStatCursor->SetFont(m_pObjectivesFont1);
	m_pStatCursor->SetDest(m_hObjectives);

	m_pStatCursor->SetJustify(CF_JUSTIFY_CENTER);
	m_pStatCursor->SetLoc(OBJTAB_TITLE_CENTER, OBJTAB_TITLE_TOP);
	m_pStatCursor->Draw(title);

	m_pStatCursor->SetJustify(CF_JUSTIFY_LEFT);
	m_pStatCursor->SetLoc(OBJTAB_TEXT_LEFT, OBJTAB_TEXT_TOP);
	m_pStatCursor->DrawFormat(string, OBJTAB_TEXT_WIDTH);

	// Turn on the updated icon if we're not currently displaying the objectives
	if(m_nObjLevel == OBJTAB_INVISIBLE || m_nObjLevel == OBJTAB_SCALE_DOWN)
		m_nObjIcon = OBJICON_VISIBLE;
	else
		m_nObjIcon = OBJICON_INVISIBLE;

	// Play a sound to let the player know that the objectives have changed
	PlaySoundInfo playSoundInfo;

	PLAYSOUNDINFO_INIT(playSoundInfo);
	playSoundInfo.m_dwFlags = PLAYSOUND_LOCAL;
	playSoundInfo.m_dwFlags |= PLAYSOUND_FILESTREAM;
	playSoundInfo.m_nPriority = SOUNDPRIORITY_MISC_MEDIUM;
	_mbsncpy((unsigned char*)playSoundInfo.m_szSoundName, (const unsigned char*)"Sounds\\Events\\bellding1.wav", sizeof(playSoundInfo.m_szSoundName) - 1);

	m_pClientDE->PlaySound(&playSoundInfo);
}

//*************************************************************************
//*****	Function:	SetPowerBarLevel()
//*****	Details:	Set the air bar level to a certain percent
//*************************************************************************

void CNewStatusBar::SetPowerBarLevel(DBYTE nBar, DFLOAT fPercent)
{
	if(!m_pClientDE || !m_hPowerBar)	return;

	HSURFACE	bar = 0;
	HDECOLOR	color = 0;
	DDWORD		width, height, centerX, newX;
	DRect		fillArea;

	m_nPowerBar = nBar;
	m_fPowerBarUpdate = m_pClientDE->GetTime();

	m_pClientDE->FillRect(m_hPowerBar, DNULL, m_hTransColor);
	m_pClientDE->GetSurfaceDims(m_hPowerBar, &width, &height);

	centerX = width / 2;

	fillArea.top = 0;
	fillArea.bottom = height;

	switch(m_nPowerBar)
	{
		case	BARTAB_THROW:	bar = m_hThrowBar; color = m_hThrowColor;		break;
		case	BARTAB_AIR:		bar = m_hThrowBar; color = m_hAirColor;			break;
		case	BARTAB_BOSS:	bar = m_hHealthBar; color = m_hBossColor;		break;
	}

	if(bar && color)
	{
		m_pClientDE->GetSurfaceDims(bar, &width, &height);

		newX = centerX - (width / 2);
		fillArea.left = newX;
		fillArea.right = newX + (int)(width * fPercent);

		m_pClientDE->FillRect(m_hPowerBar, &fillArea, color);
		m_pClientDE->DrawSurfaceToSurfaceTransparent(m_hPowerBar, bar, DNULL, newX, 0, m_hMaskColor);
	}
}

//*************************************************************************
//*****	Function:	DisplayFlag()
//*****	Details:	Sets up the flag icon
//*************************************************************************

void CNewStatusBar::DisplayFlag(DBYTE bColor)
{
	if(!m_pClientDE)	return;

	if(m_hFlagIcon)
	{
		m_pClientDE->DeleteSurface(m_hFlagIcon);
		m_hFlagIcon = 0;
	}

	m_nFlagLevel = bColor;

	switch(m_nFlagLevel)
	{
		case	MULTIFLAG_NONE:
			break;

		case	MULTIFLAG_RED:
			m_hFlagIcon = m_pClientDE->CreateSurfaceFromBitmap("interface_multipatch\\flagred.pcx");
			break;

		case	MULTIFLAG_BLUE:
			m_hFlagIcon = m_pClientDE->CreateSurfaceFromBitmap("interface_multipatch\\flagblue.pcx");
			break;
	}
}

//*************************************************************************
//*****	Function:	SetTeamID()
//*****	Details:	Sets up the team icon
//*************************************************************************

void CNewStatusBar::SetTeamID(int nTeamID)
{
	// Check if we are already using this team id...

	if (m_hTeamIcon && (nTeamID == m_nTeamID))
	{
		return;
	}


	// Set the new team id and icon...

	m_nTeamIconHeight = 0;

	if(!m_pClientDE) return;

	if (m_hTeamIcon)
	{
		m_pClientDE->DeleteSurface(m_hTeamIcon);
		m_hTeamIcon = 0;
	}

	m_nTeamID = nTeamID;

	switch(nTeamID)
	{
		case TEAM_1:
		{
			m_hTeamIcon = m_pClientDE->CreateSurfaceFromBitmap("interface_multipatch\\teamblue.pcx");
			break;
		}

		case TEAM_2:
		{
			m_hTeamIcon = m_pClientDE->CreateSurfaceFromBitmap("interface_multipatch\\teamred.pcx");
			break;
		}
	}
}

//*************************************************************************
//*****	Function:	Draw()
//*****	Details:	Draws all active in-game interfaces
//*************************************************************************

void CNewStatusBar::Draw(DBOOL bDrawBar)
{
	if(!m_pClientDE) return;

	m_fTime = m_pClientDE->GetTime();

	AdjustRes();

	if(bDrawBar)
	{
		if(m_nStatLevel)						DrawStatTabs();
		if(m_nInvLevel && m_bHighGraphics)		DrawInvTabs();
		if(m_nWeapLevel && m_bHighGraphics)		DrawWeaponTabs();
		if(m_nObjLevel)							DrawObjectives();
		if(m_nObjIcon)							DrawObjectivesIcon();
		if(m_nPowerBar)							DrawPowerBar();
		if(m_nFlagLevel)						DrawFlagIcon();
		if(m_hTeamIcon)							DrawTeamIcon();
	}
}

//*************************************************************************
//*****	Function:	Reset()
//*****	Details:	Reset all the status bar stuff when switching levels
//*************************************************************************

void CNewStatusBar::Reset()
{
	m_stHealth.value = 100;
	m_stArmor.value = 0;
	m_stAmmo.value = 0;
	m_stAltAmmo.value = 0;

	m_nOldHealth = -1;
	m_nOldArmor = -1;
	m_nOldAmmo = -1;
	m_nOldAltAmmo = -1;

	m_nInvLevel = 0;
	m_nWeapLevel = 0;
	m_nObjLevel = 0;
	m_nObjIcon = 0;
	m_nPowerBar = 0;

	for(int i = 0; i < 10; i++)
		UpdateWeap(0, 0, i);

	UpdateInv(DFALSE, 0, 0, 0, 0, 0, 0, 0, 0);

	DisplayFlag(MULTIFLAG_NONE);
}


//*************************************************************************
//*****	Function:	SetupTab()
//*****	Details:	Setup the tab with the current graphics and values
//*************************************************************************

void CNewStatusBar::SetupTab(StatTab &stTab, CoolFont *font, DBYTE nFlags)
{
	if(!m_pClientDE) return;

	DDWORD		x, y;

	// Clear the surface to the transparent color
	if(stTab.hTab)
		m_pClientDE->FillRect(stTab.hTab, DNULL, m_hTransColor);

	// Draw the border in the offset position
	if(stTab.hBorder && (nFlags & TAB_INC_BORDER))
	{
		x = stTab.borderX;
		y = stTab.borderY;
		JustifySurface(stTab.hBorder, stTab.borderJ, x, y);
		m_pClientDE->DrawSurfaceToSurface(stTab.hTab, stTab.hBorder, DNULL, x, y);
	}

	// Draw the icon in the offset position
	if(stTab.hIcon && (nFlags & TAB_INC_ICON))
	{
		x = stTab.iconX;
		y = stTab.iconY;
		JustifySurface(stTab.hIcon, stTab.iconJ, x, y);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -