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

📄 chsprefs.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Implementation of the ChSoundPrefs property page.  This page handles
	preferences for the Sound module.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChSound/ChSPrefs.cpp,v 1.18 1996/10/09 20:31:56 coyote Exp $

#include "stdlib.h"

#include "headers.h"
#if !defined(CH_PUEBLO_PLUGIN )
#include "resource.h"
#else
#include "vwrres.h"
#endif

#include <ChUtil.h>

#include "ChSOpen.h"
#include "ChSPrefs.h"
#include "ChSoundInfo.h"
#include "ChSoundUtils.h"

#ifdef _DEBUG
	#undef THIS_FILE
	static char BASED_CODE THIS_FILE[] = __FILE__;
#endif


/*----------------------------------------------------------------------------
	Constants
----------------------------------------------------------------------------*/

#define MIDI_TEST_FILE_NAME			"ChTest.mid"
#define SPEECH_TEST_FILE_NAME		"ChTest.vox"


/*----------------------------------------------------------------------------
	ChAlertTime class
----------------------------------------------------------------------------*/

ChAlertTime::ChAlertTime( ChRegistry* pSoundPrefs ) :
				 m_pSoundPrefs( pSoundPrefs ),
				 m_boolDirty( false )
{
	ReadAlertFreq();
}


void ChAlertTime::OnCommit()
{
	if (m_boolDirty)
	{
		WriteAlertFreq();
	}
}


void ChAlertTime::SetAlertCount( chint32 lCount )
{
	if (lCount < 0)
	{
		lCount = 0;
	}
	else if (lCount > 60)
	{
		lCount = 60;
	}

	if (lCount != m_lAlertCount)
	{
		m_boolDirty = true;
	}

	m_lAlertCount = lCount;
}


void ChAlertTime::SetAlertUnits( string strUnits )
{
	AlertUnitType	newUnits;

	newUnits = TranslateUnitsName( strUnits );

	SetAlertUnits( newUnits );
}


void ChAlertTime::SetAlertUnits( AlertUnitType newUnits )
{
	if (newUnits != m_timeUnits)
	{
		m_boolDirty = true;
	}

	m_timeUnits = newUnits;

	switch( newUnits )
	{
		case minutes:
		{
			m_lUnitsMultiplier = 60;
			break;
		}

		case hours:
		{
			m_lUnitsMultiplier = 3600;
			break;
		}

		default:
		{
			m_lUnitsMultiplier = 1;
			break;
		}
	}
}


string ChAlertTime::GetUnitsName()
{
	string	strUnits;

	switch( m_timeUnits )
	{
		case minutes:
		{
			strUnits = SOUND_PREFS_ALERT_FREQ_UNITS_MIN;
			break;
		}

		case hours:
		{
			strUnits = SOUND_PREFS_ALERT_FREQ_UNITS_HOUR;
			break;
		}

		default:
		{
			strUnits = SOUND_PREFS_ALERT_FREQ_UNITS_SEC;
			break;
		}
	}

	return strUnits;
}


ChAlertTime::AlertUnitType
ChAlertTime::TranslateUnitsName( const string& strUnitsName )
{
	AlertUnitType	units;
	string			strUnits( strUnitsName );

	strUnits.MakeLower();
	if (strUnits == SOUND_PREFS_ALERT_FREQ_UNITS_MIN)
	{
		units = minutes;
	}
	else if (strUnits == SOUND_PREFS_ALERT_FREQ_UNITS_HOUR)
	{
		units = hours;
	}
	else
	{										// Assume seconds
		units = seconds;
	}

	return units;
}


void ChAlertTime::ReadAlertFreq()
{
	string		strTimeUnits;

	m_pSoundPrefs->Read( SOUND_PREFS_ALERT_FREQ_COUNT, m_lAlertCount,
							SOUND_PREFS_ALERT_FREQ_COUNT_DEF );

	m_pSoundPrefs->Read( SOUND_PREFS_ALERT_FREQ_UNITS, strTimeUnits,
							SOUND_PREFS_ALERT_FREQ_UNITS_DEF );

	SetAlertUnits( TranslateUnitsName( strTimeUnits ) );

	m_boolDirty = false;
}


void ChAlertTime::WriteAlertFreq()
{
	m_pSoundPrefs->Write( SOUND_PREFS_ALERT_FREQ_COUNT, m_lAlertCount );
	m_pSoundPrefs->Write( SOUND_PREFS_ALERT_FREQ_UNITS, GetUnitsName() );
}


/*----------------------------------------------------------------------------
	ChSoundPrefs class
----------------------------------------------------------------------------*/

IMPLEMENT_DYNCREATE( ChSoundPrefs, ChPropertyBaseClass )

ChSoundPrefs::ChSoundPrefs() :
				ChPropertyBaseClass( ChSoundPrefs::IDD, 0 
#if !defined( CH_PUEBLO_PLUGIN )
					, ChSoundDLL.hModule 
#endif					
					),
				m_pMainInfo( 0 ),
				m_reg( SOUND_PREFS_GROUP ),
				m_boolInitialized( false ),
				m_alertTime( &m_reg )
{
	string		strDefAlertSound;

	//{{AFX_DATA_INIT(ChSoundPrefs)
	m_boolDisableSound = FALSE;
	//}}AFX_DATA_INIT

	ChUtil::GetAppDirectory( m_strMidiFilePath );
	m_strMidiFilePath += MIDI_TEST_FILE_NAME;

	if (!ChUtil::FileExists( m_strMidiFilePath ))
	{
		m_strMidiFilePath = "";
	}
											/* Pick a reasonable default alert
												sound */

	strDefAlertSound = GetSysSoundFilesPath() + "Tada.wav";
	m_reg.Read( SOUND_PREFS_ALERT_SOUND, m_strAlertSoundPath,
				strDefAlertSound );
											// Read whether we're disabled

	m_reg.ReadBool( SOUND_PREFS_DISABLED, m_boolDisableSound,
					SOUND_PREFS_DISABLED_DEF );
}


ChSoundPrefs::~ChSoundPrefs()
{
}

void ChSoundPrefs::SetMainInfo( ChSoundMainInfo* pMainInfo )
{
	m_pMainInfo = pMainInfo;
	m_boolSoundDeviceFound = pMainInfo->SoundDeviceFound();
}
											// Overrides


void ChSoundPrefs::DoDataExchange( CDataExchange* pDX )
{
	ChPropertyBaseClass::DoDataExchange( pDX );

	//{{AFX_DATA_MAP(ChSoundPrefs)
	DDX_Control(pDX, IDC_CHECK_DISABLE, m_btnDisable);
	DDX_Control(pDX, IDC_ALERT_SOUND, m_btnAlertSound);
	DDX_Control(pDX, IDC_STATIC_OFF, m_staticOff);
	DDX_Control(pDX, IDC_STATIC_MUSIC, m_staticMusic);
	DDX_Control(pDX, IDC_STATIC_MSG, m_staticMsg);
	DDX_Control(pDX, IDC_STATIC_MAX, m_staticMax);
	DDX_Control(pDX, IDC_STATIC_EFFECTS, m_staticEffects);
	DDX_Control(pDX, IDC_STATIC_DISABLE_MSG, m_staticDisableMsg);
	DDX_Control(pDX, IDC_STATIC_BOX, m_staticBox);
	DDX_Control(pDX, IDC_STATIC_ALERTS, m_staticAlerts);
	DDX_Control(pDX, IDC_ALERT_SOUND_NAME, m_staticAlertSoundName);
	DDX_Control(pDX, IDC_TIME_UNITS, m_comboTimeUnits);
	DDX_Control(pDX, IDC_TIME_COUNT, m_comboTimeCount);
	DDX_Control(pDX, IDC_SLIDER_VOLUME_MIDI, m_midiVolume);
	DDX_Control(pDX, IDC_SLIDER_VOLUME_WAVE, m_waveVolume);
	DDX_Control(pDX, IDC_SLIDER_VOLUME_ALERT, m_alertVolume);
	DDX_Check(pDX, IDC_CHECK_DISABLE, m_boolDisableSound);
	//}}AFX_DATA_MAP
}


bool ChSoundPrefs::OnSetActive()
{
	bool	boolResult;

	boolResult = ChPropertyBaseClass::OnSetActive();

	if (!m_boolInitialized)
	{
		InitVolumeSlider( m_midiVolume );
		InitVolumeSlider( m_waveVolume );
		InitVolumeSlider( m_alertVolume );

		ReadVolumeSliderPos( m_midiVolume, m_reg, SOUND_PREFS_MUSIC_VOLUME );
		ReadVolumeSliderPos( m_waveVolume, m_reg, SOUND_PREFS_EFFECTS_VOLUME );
		ReadVolumeSliderPos( m_alertVolume, m_reg, SOUND_PREFS_ALERT_VOLUME );

		UpdateAlertSoundName();
		InitAlertFreq();

		if (!GetMainInfo()->GetMidiPlayer()->DeviceExists())
		{
			m_midiVolume.EnableWindow( false );
		}

		if (!GetMainInfo()->GetWavePlayer()->DeviceExists())
		{
			m_waveVolume.EnableWindow( false );
			m_alertVolume.EnableWindow( false );
		}
											/* Set the initialized flag so
												that we don't do this again */
		m_boolInitialized = true;
	}

	return boolResult;
}


void ChSoundPrefs::OnCommit()
{
	if (m_boolInitialized)
	{
		WriteVolumeSliderPos( m_midiVolume, m_reg, SOUND_PREFS_MUSIC_VOLUME );
		WriteVolumeSliderPos( m_waveVolume, m_reg, SOUND_PREFS_EFFECTS_VOLUME );
		WriteVolumeSliderPos( m_alertVolume, m_reg, SOUND_PREFS_ALERT_VOLUME );

		WriteAlertSound();

		m_alertTime.OnCommit();
											/* Perform updates in
												ChSoundMainInfo */
		GetMainInfo()->UpdateVolume();
											// Update our cached data

		GetMainInfo()->SetAlertSoundPath( GetAlertSoundPath() );
		GetMainInfo()->SetDisabled( IsDisabled() );
		GetMainInfo()->UpdateAlertTimes();
	}
}

#if defined( CH_PUEBLO_PLUGIN )

BOOL ChSoundPrefs::OnKillActive()
{
	UpdateData();
	OnCommit();
	return true;
}

#endif


void ChSoundPrefs::OnDestroy()
{

⌨️ 快捷键说明

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