Change GuiProfile to use Sound Asset

-Added SoundAssetInspector to bypass circular issue
-Added SoundAsset to GuiTypes
This commit is contained in:
marauder2k7 2022-08-29 23:40:51 +01:00
parent ebbf0947b3
commit 5d85664b40
10 changed files with 91 additions and 106 deletions

View file

@ -218,60 +218,6 @@ bool GuiControlProfile::protectedSetBitmap( void *object, const char *index, con
return false;
}
const char* GuiControlProfile::protectedGetSoundButtonDown( void* object, const char* data )
{
GuiControlProfile* profile = reinterpret_cast< GuiControlProfile* >( object );
SFXTrack* track = profile->mSoundButtonDown;
if( !track )
return "";
return track->getName();
}
bool GuiControlProfile::protectedSetSoundButtonDown( void* object, const char* index, const char* data )
{
GuiControlProfile* profile = reinterpret_cast< GuiControlProfile* >( object );
SFXTrack* track = NULL;
if( data && data[ 0] && !Sim::findObject( data, track ) )
{
Con::errorf( "GuiControlProfile::protectedSetSoundButtonDown - no SFXTrack '%s'", data );
return false;
}
profile->mSoundButtonDown = track;
return false;
}
const char* GuiControlProfile::protectedGetSoundButtonOver( void* object, const char* data )
{
GuiControlProfile* profile = reinterpret_cast< GuiControlProfile* >( object );
SFXTrack* track = profile->mSoundButtonOver;
if( !track )
return "";
return track->getName();
}
bool GuiControlProfile::protectedSetSoundButtonOver( void* object, const char* index, const char* data )
{
GuiControlProfile* profile = reinterpret_cast< GuiControlProfile* >( object );
SFXTrack* track = NULL;
if( data && data[ 0] && !Sim::findObject( data, track ) )
{
Con::errorf( "GuiControlProfile::protectedSetSoundButtonOver - no SFXTrack '%s'", data );
return false;
}
profile->mSoundButtonOver = track;
return false;
}
GuiControlProfile::GuiControlProfile(void) :
mFillColor(255,0,255,255),
mFillColorHL(255,0,255,255),
@ -293,6 +239,8 @@ GuiControlProfile::GuiControlProfile(void) :
mTextOffset(0,0),
mBitmapArrayRects(0)
{
INIT_ASSET(SoundButtonDown);
INIT_ASSET(SoundButtonOver);
mLoadCount = 0;
mUseCount = 0;
@ -367,8 +315,19 @@ GuiControlProfile::GuiControlProfile(void) :
mTextOffset = def->mTextOffset;
// default sound
mSoundButtonDown = def->mSoundButtonDown;
mSoundButtonOver = def->mSoundButtonOver;
_setSoundButtonDown(def->getSoundButtonDown());
if (getSoundButtonDown() != StringTable->EmptyString())
{
if (!getSoundButtonDownProfile())
Con::errorf(ConsoleLogEntry::General, "GuiControlProfile: Can't get default button pressed sound asset.");
}
_setSoundButtonOver(def->getSoundButtonOver());
if (getSoundButtonOver() != StringTable->EmptyString())
{
if (!getSoundButtonOverProfile())
Con::errorf(ConsoleLogEntry::General, "GuiControlProfile: Can't get default button hover sound asset.");
}
//used by GuiTextCtrl
mModal = def->mModal;
@ -478,9 +437,9 @@ void GuiControlProfile::initPersistFields()
addField("hasBitmapArray", TypeBool, Offset(mUseBitmapArray, GuiControlProfile),
"If true, 'bitmap' is an array of images." );
addProtectedField( "soundButtonDown", TypeSFXTrackName, Offset(mSoundButtonDown, GuiControlProfile),
&GuiControlProfile::protectedSetSoundButtonDown, &GuiControlProfile::protectedGetSoundButtonDown,
"Sound to play when mouse has been pressed on control." );
INITPERSISTFIELD_SOUNDASSET(SoundButtonDown, GuiControlProfile, "The sound button down.");
INITPERSISTFIELD_SOUNDASSET(SoundButtonOver, GuiControlProfile, "The sound button down.");
addProtectedField( "soundButtonOver", TypeSFXTrackName, Offset(mSoundButtonOver, GuiControlProfile),
&GuiControlProfile::protectedSetSoundButtonOver, &GuiControlProfile::protectedGetSoundButtonOver,
"Sound to play when mouse is hovering over control." );

View file

@ -36,6 +36,10 @@
#include "console/dynamicTypes.h"
#endif
#ifndef SOUND_ASSET_H_
#include "T3D/assets/SoundAsset.h"
#endif
#include "T3D/assets/ImageAsset.h"
#include "gfx/gfxDevice.h"
@ -562,9 +566,11 @@ public:
bool mUseBitmapArray; ///< Flag to use the bitmap array or to fallback to non-array rendering
Vector<RectI> mBitmapArrayRects; ///< Used for controls which use an array of bitmaps such as checkboxes
// sound members
SimObjectPtr< SFXTrack > mSoundButtonDown; ///< Sound played when the object is "down" ie a button is pushed
SimObjectPtr< SFXTrack > mSoundButtonOver; ///< Sound played when the mouse is over the object
DECLARE_SOUNDASSET(GuiControlProfile, SoundButtonDown); ///< Sound played when a button is pressed.
DECLARE_ASSET_SETGET(GuiControlProfile, SoundButtonDown);
DECLARE_SOUNDASSET(GuiControlProfile, SoundButtonOver); ///< Sound played when a button is hovered.
DECLARE_ASSET_SETGET(GuiControlProfile, SoundButtonOver);
StringTableEntry mChildrenProfileName; ///< The name of the profile to use for the children controls
@ -583,10 +589,6 @@ protected:
GuiControlProfile* mChildrenProfile; ///< Profile used with children controls (such as the scroll bar on a popup menu) when defined.
static bool protectedSetBitmap( void *object, const char *index, const char *data );
static bool protectedSetSoundButtonDown( void* object, const char* index, const char* data );
static bool protectedSetSoundButtonOver( void* object, const char* index, const char* data );
static const char* protectedGetSoundButtonDown( void* object, const char* data );
static const char* protectedGetSoundButtonOver( void* object, const char* data );
public:
DECLARE_CONOBJECT(GuiControlProfile);