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

📄 coptionsdlg.cpp

📁 3D游戏疯狂的鸡蛋
💻 CPP
字号:
/*
	Crazy Eggs Remade By Kevin Lynx

	File : COptionsDlg.cpp
	Desc : create a option dialog
	Date : 2007.1.25
*/
#include	<SexyAppBase.h>
#include	<ImageFont.h>
#include	"../CGame.h"
#include	"COptionsDlg.h"

#include	"../resourceGen/res.h"

COptionsDlg::COptionsDlg() :
	Dialog( DIALOG_SMALL, DIALOG_BTN, DLG_ID, true, "Options", "", "", BUTTONS_OK_CANCEL )
{
	SetHeaderFont( NORMAL_FONT );
	( (ImageFont*)mHeaderFont )->SetScale( 1.5f );
	SetLinesFont( NORMAL_FONT );
	SetButtonFont( NORMAL_FONT );
	SetColor( Dialog::COLOR_HEADER, Color( 0, 0, 255 ) );
	SetColor( Dialog::COLOR_BUTTON_TEXT, Color( 255, 237, 120 ) );
	SetColor( Dialog::COLOR_LINES, Color( 255, 230, 100 ) ); 
		
	mContentInsets	=	Insets( 55, 50, 55, 50 );
	mSpaceAfterHeader	=	20;		
	
	Resize( ( G_WINDOW_WIDTH - 400 ) / 2, ( G_WINDOW_HEIGHT - 350 ) / 2, 400, 350 );

	//create controls on this dialog

	//check box
	int	checkbox_h	=	CHECK_BOX->GetHeight() / 4;
	int	checkbox_w  =   CHECK_BOX->GetWidth() ;

	//checbox ,using 3d
	m_ckb3D		=	new	Checkbox( CHECK_BOX, CHECK_BOX, CKB_3D_ID, this );
	m_ckb3D->mUncheckedRect	=	Rect( 0, 0, checkbox_w, checkbox_h );
	m_ckb3D->mCheckedRect   =   Rect( 0, checkbox_h, checkbox_w, checkbox_h );
	
	//checkbox, fullscree
	m_ckbFS		=	new	Checkbox( CHECK_BOX, CHECK_BOX, CKB_FS_ID, this );
	m_ckbFS->mUncheckedRect	=	Rect( 0, 0, checkbox_w, checkbox_h );
	m_ckbFS->mCheckedRect   =   Rect( 0, checkbox_h, checkbox_w, checkbox_h );
	
	//slider, music volume
	m_sliMusic	=	new	Slider( SLIDER_TRACK, SLIDER_THUMB, SLI_MUSIC_ID, this );
	
	//slider, sound volume
	m_sliSound	=	new	Slider( SLIDER_TRACK, SLIDER_THUMB, SLI_SOUND_ID, this );

	//resize all the controls
	m_sliMusic->Resize( mX + mContentInsets.mLeft, mY + 100, 
						mWidth - mContentInsets.mLeft - mContentInsets.mRight, 
						SLIDER_TRACK->GetHeight() );
	m_sliSound->Resize( mX + mContentInsets.mLeft, mY + 150, 
						mWidth - mContentInsets.mLeft - mContentInsets.mRight, 
						SLIDER_TRACK->GetHeight() );
	
	m_ckb3D->Resize( mX + mContentInsets.mLeft + 10,
					 mY + 190, checkbox_w, checkbox_h );
	m_ckbFS->Resize( mX + mWidth / 2 + 10, 
					 mY + 190, checkbox_w, checkbox_h );

}

COptionsDlg::~COptionsDlg()
{
	delete	m_ckb3D;
	delete	m_ckbFS;

	delete	m_sliMusic;
	delete	m_sliSound;
}

void	COptionsDlg::Update()
{
	Dialog::Update();
}

void	COptionsDlg::Draw( Graphics *g )
{
	Dialog::Draw( g );

	g->SetFont( NORMAL_FONT );
	g->SetColor( Color( 255, 237, 10 ) );
	
	g->DrawString("Music volume:", m_sliMusic->mX - mX, 
			m_sliMusic->mY - mY - m_sliMusic->mHeight);

	g->DrawString("Sound volume:", m_sliSound->mX - mX, 
			m_sliSound->mY - mY - m_sliSound->mHeight);

	g->DrawString("3D Mode", m_ckb3D->mX - mX + m_ckb3D->mWidth + 10, m_ckb3D->mY - mY + 20 );
	g->DrawString("Full Screen", m_ckbFS->mX - mX + m_ckbFS->mWidth + 10, m_ckbFS->mY - mY + 20 );

}

void	COptionsDlg::AddedToManager( WidgetManager *theWidgetManager )
{
	Dialog::AddedToManager( theWidgetManager );

	//reget the status of the game
	m_ckb3D->SetChecked( gSexyAppBase->Is3DAccelerated() );
	m_ckbFS->SetChecked( !gSexyAppBase->mIsWindowed );

	m_sliMusic->SetValue( gSexyAppBase->GetMusicVolume() );
	m_sliSound->SetValue( gSexyAppBase->GetSfxVolume() );

	//add all the controls to the manager
	theWidgetManager->AddWidget( m_ckb3D );
	theWidgetManager->AddWidget( m_ckbFS );
	theWidgetManager->AddWidget( m_sliMusic );
	theWidgetManager->AddWidget( m_sliSound );
}

void	COptionsDlg::RemovedFromManager( WidgetManager *theWidgetManager )
{
	Dialog::RemovedFromManager( theWidgetManager );

	//remove all the controls from the manager
	theWidgetManager->RemoveWidget( m_ckb3D );
	theWidgetManager->RemoveWidget( m_ckbFS );
	theWidgetManager->RemoveWidget( m_sliMusic );
	theWidgetManager->RemoveWidget( m_sliSound );

}

void	COptionsDlg::ButtonDepress( int theId )
{
	if( theId == ID_OK )
	{
		//reset something
		gSexyAppBase->SwitchScreenMode( !m_ckbFS->IsChecked(), m_ckb3D->IsChecked() );

		gSexyAppBase->KillDialog( this );
	}

	if( theId == ID_CANCEL )
	{
		gSexyAppBase->KillDialog( this );
	}
}

void	COptionsDlg::SliderVal( int theId, double theVal )
{
	if( theId == SLI_MUSIC_ID )
	{
		gSexyAppBase->SetMusicVolume( theVal );
	}

	if( theId == SLI_SOUND_ID )
	{
		gSexyAppBase->SetSfxVolume( theVal );
	}
}

void	COptionsDlg::CheckboxChecked( int theId, bool checked )
{
	//here, i should check the user' computer whether support 3D or Fullscreen /windowed mode
	//but now, i 'll do nothing here
}

void	COptionsDlg::MouseDrag( int x,int y )
{
	//do nothing to make the dialog cannot be moved
}

⌨️ 快捷键说明

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