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

📄 gamegui.cpp

📁 使用DirectX9 写的通用3D游戏框架
💻 CPP
字号:
#include "GameGUI.h"

CGameGUI::CGameGUI(LPDIRECT3DDEVICE9 pDevice, HWND hWnd) :
m_pd3dDevice(pDevice),
m_hWnd(hWnd),
m_bPlayGame(false),
m_bLoading(false)
{
	m_pDXRender		= new CEGUI::DirectX9Renderer(m_pd3dDevice, 0);
	m_pGUISystem	= new CEGUI::System(m_pDXRender);

	CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>
		(CEGUI::System::getSingleton().getResourceProvider());

	rp->setResourceGroupDirectory("schemes",	"GUI/schemes/");
	rp->setResourceGroupDirectory("imagesets",	"GUI/imagesets/");
	rp->setResourceGroupDirectory("fonts",		"GUI/fonts/");
	rp->setResourceGroupDirectory("layouts",	"GUI/layouts/");
	rp->setResourceGroupDirectory("looknfeels",	"GUI/looknfeel/");

	CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
	CEGUI::Imageset::setDefaultResourceGroup("imagesets");
	CEGUI::Font::setDefaultResourceGroup("fonts");
	CEGUI::Scheme::setDefaultResourceGroup("schemes");
	CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
	CEGUI::WindowManager::setDefaultResourceGroup("layouts");
}

CGameGUI::~CGameGUI()
{

}

void CGameGUI::Init()
{	
	using namespace CEGUI;

	SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
	SchemeManager::getSingleton().loadScheme("WindowsLook.scheme");

	System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
	FontManager::getSingleton().createFont("DejaVuSans-10.font");

	WindowManager& winMgr = WindowManager::getSingleton();
	CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");	//设置鼠标的图片
	CEGUI::MouseCursor::getSingleton().show( );									//显示鼠标

	//加载图片资源
	ImagesetManager::getSingleton().createImagesetFromImageFile("CreditPicture", "aboutus.jpg");
	ImagesetManager::getSingleton().createImagesetFromImageFile("loadpicture", "loading.jpg");
	ImagesetManager::getSingleton().createImagesetFromImageFile("startpicture", "background.jpg");
	ImagesetManager::getSingleton().createImagesetFromImageFile("wpimage1", "weapon_1.PNG");
	ImagesetManager::getSingleton().createImagesetFromImageFile("wpimage2", "weapon_2.PNG");
	ImagesetManager::getSingleton().createImagesetFromImageFile("wpimage3", "weapon_3.PNG");
	ImagesetManager::getSingleton().createImagesetFromImageFile("bulletimage", "defense.png");
	ImagesetManager::getSingleton().createImagesetFromImageFile("bloodimage", "weapon.png");


	Window* Root = WindowManager::getSingleton().loadWindowLayout("MyGame.layout");
	System::getSingleton().setGUISheet(Root);

	m_pStartWindow	= WindowManager::getSingleton().getWindow("StartWindow");
	m_pLoadWindow	= WindowManager::getSingleton().getWindow("LoadWindow");
	m_pCreditWindow	= WindowManager::getSingleton().getWindow("CreditWindow");
	m_pGameWindow	= WindowManager::getSingleton().getWindow("GameWindow");
	m_pStartWindow	->setVisible(true);
	m_pLoadWindow	->setVisible(false);
	m_pCreditWindow	->setVisible(false);
	m_pGameWindow	->setVisible(false);

	m_pWeaponRootWindow = WindowManager::getSingleton().getWindow("weapons");
	m_pWeapon1Window	= WindowManager::getSingleton().getWindow("wp1");
	m_pWeapon2Window	= WindowManager::getSingleton().getWindow("wp2");
	m_pWeapon3Window	= WindowManager::getSingleton().getWindow("wp3");
	m_pWeaponRootWindow	->setVisible(false);

	m_pStartButton	= static_cast<PushButton*>(WindowManager::getSingleton().getWindow("startbutton"));
	m_pCreditButton	= static_cast<PushButton*>(WindowManager::getSingleton().getWindow("creditbutton"));
	m_pExitButton	= static_cast<PushButton*>(WindowManager::getSingleton().getWindow("exitbutton"));
	m_pBackButton	= static_cast<PushButton*>(WindowManager::getSingleton().getWindow("backbutton"));

	m_pLoadProBar	= static_cast<ProgressBar*>(WindowManager::getSingleton().getWindow("loadbar"));
	m_pHBProBar		= static_cast<ProgressBar*>(WindowManager::getSingleton().getWindow("loadbarbt"));
	m_pHBProBar		->setProgress(1.0f);
	m_pHBProBar		= static_cast<ProgressBar*>(WindowManager::getSingleton().getWindow("loadbarbl"));
	m_pHBProBar		->setProgress(1.0f);

	m_pStartButton	->subscribeEvent( CEGUI::PushButton::EventClicked, Event::Subscriber(&CGameGUI::HandleStart, this));
	m_pCreditButton	->subscribeEvent( CEGUI::PushButton::EventClicked, Event::Subscriber(&CGameGUI::HandleCredit, this));
	m_pExitButton	->subscribeEvent( CEGUI::PushButton::EventClicked, Event::Subscriber(&CGameGUI::HandleQuit, this));
	m_pBackButton	->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CGameGUI::HandleBack, this));

}

void CGameGUI::Update()
{
	SetCursor(NULL);
	static float mousepositionx = 400.0f;
	static float mousepositiony = 300.0f;
	mousepositionx += float(INPUT->MouseDX());
	mousepositiony += float(INPUT->MouseDY());
	CEGUI::System::getSingleton().injectMousePosition(mousepositionx,mousepositiony);

	if(INPUT->MouseButtonDown(0))
	{
		CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
	}
	else
	{
		CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
	}

	if(INPUT->MouseButtonDown(1))
	{
		CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
	}
	else
	{
		CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
	}

	if(INPUT->KeyDown(DIK_1))
	{
		m_pWeaponRootWindow->setVisible(true);
		m_pWeapon1Window->setAlpha(1.0);
		m_pWeapon2Window->setAlpha(0.5);
		m_pWeapon3Window->setAlpha(0.5);
	}

	if(INPUT->KeyDown(DIK_2))
	{
		m_pWeaponRootWindow->setVisible(true);
		m_pWeapon1Window->setAlpha(0.5);
		m_pWeapon2Window->setAlpha(1.0);
		m_pWeapon3Window->setAlpha(0.5);
	}

	if(INPUT->KeyDown(DIK_3))
	{
		m_pWeaponRootWindow->setVisible(true);
		m_pWeapon1Window->setAlpha(0.5);
		m_pWeapon2Window->setAlpha(0.5);
		m_pWeapon3Window->setAlpha(1.0);
	}

	if(INPUT->KeyDown(DIK_4))
	{
		m_pWeaponRootWindow->setVisible(true);
		m_pWeapon1Window->setAlpha(0.5);
		m_pWeapon2Window->setAlpha(0.5);
		m_pWeapon3Window->setAlpha(0.5);
	}

	if(INPUT->MouseButtonClicked(0))
	{
		m_pWeaponRootWindow->setVisible(false);
	}

	if(INPUT->KeyDown(DIK_ESCAPE))
	{
		CEGUI::MouseCursor::getSingleton().show();
		m_pGameWindow->setVisible(false);
		m_pStartWindow->setVisible(true);
		m_bPlayGame = false;
	}

}

void CGameGUI::Render()
{
	CEGUI::System::getSingleton().renderGUI();
}

void CGameGUI::SetHP(float fHP)
{
	m_pHBProBar	= static_cast<CEGUI::ProgressBar*>(CEGUI::WindowManager::getSingleton().getWindow("loadbarbt"));
	m_pHBProBar	->setProgress(fHP);
}

void CGameGUI::SetLoaded(int iLoaded)
{ 
	if(iLoaded == 100)
	{
		m_bLoading = false;
		m_bPlayGame = true;
		m_pLoadWindow->setVisible(false);
		m_pGameWindow->setVisible(true);
	}

	m_pLoadProBar->setProgress(iLoaded * 0.01f);
	
}

bool CGameGUI::HandleStart(const CEGUI::EventArgs& e)
{
	m_pStartWindow->setVisible(false);
	m_pLoadWindow->setVisible(true);
	CEGUI::MouseCursor::getSingleton().hide();	//隐藏鼠标
	m_bLoading = true;

	return true;
}

bool CGameGUI::HandleCredit(const CEGUI::EventArgs &e)
{
	m_pStartWindow->setVisible(false);
	m_pCreditWindow->setVisible(true);

	return true;
}

bool CGameGUI::HandleQuit(const CEGUI::EventArgs& e)
{
	PostMessage(m_hWnd, WM_QUIT, 0, 0);

	return true;
}

bool CGameGUI::HandleBack(const CEGUI::EventArgs& e)
{
	m_pStartWindow->setVisible(true);
	m_pCreditWindow->setVisible(false);

	return true;
}

⌨️ 快捷键说明

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