208 lines
6.3 KiB
C++
208 lines
6.3 KiB
C++
#pragma once
|
|
|
|
#include "Component.h"
|
|
|
|
// region User header
|
|
|
|
// endregion
|
|
|
|
namespace Soundwich
|
|
{
|
|
class PlayMenuMusic : public Component
|
|
{
|
|
// region Class name
|
|
|
|
public:
|
|
static const Util::String& GetType( )
|
|
{
|
|
static const Util::String type = "PlayMenuMusic";
|
|
return type;
|
|
}
|
|
|
|
const Util::String& GetDerivedType( ) const
|
|
{
|
|
return GetType( );
|
|
}
|
|
|
|
// endregion
|
|
|
|
// region Data
|
|
|
|
public:
|
|
struct Data : public Component::Data
|
|
{
|
|
Data( const Util::String& musicItem = "", flt32 fadeInDuration = 0.0f, bool playAtEndOfPreviousBrick = false, int32 endBeatOverride = -1, bool cancelAudioPreviewRequest = true, const Util::String& eventNameCallback = "" )
|
|
{
|
|
MusicItem = musicItem;
|
|
FadeInDuration = fadeInDuration;
|
|
PlayAtEndOfPreviousBrick = playAtEndOfPreviousBrick;
|
|
EndBeatOverride = endBeatOverride;
|
|
CancelAudioPreviewRequest = cancelAudioPreviewRequest;
|
|
EventNameCallback = eventNameCallback;
|
|
};
|
|
|
|
Util::String MusicItem;
|
|
flt32 FadeInDuration;
|
|
bool PlayAtEndOfPreviousBrick;
|
|
int32 EndBeatOverride;
|
|
bool CancelAudioPreviewRequest;
|
|
Util::String EventNameCallback;
|
|
};
|
|
|
|
// endregion
|
|
|
|
// region Constructor/Destructor
|
|
|
|
public:
|
|
PlayMenuMusic( Synth* synth, const Util::String& name, const Data& data )
|
|
: Component( synth, name )
|
|
, _data( data ) { Init( ); }
|
|
|
|
PlayMenuMusic( Synth* synth, const Util::String& name )
|
|
: Component( synth, name ) { Init( ); }
|
|
|
|
~PlayMenuMusic( );
|
|
|
|
bool Init( );
|
|
|
|
static void Create( Synth* synth, const Util::String& name, Component** component )
|
|
{
|
|
*component = new PlayMenuMusic( synth, name );
|
|
}
|
|
|
|
// Binary Serialization
|
|
|
|
void Serialize( Util::BinaryWriter& writer )
|
|
{
|
|
writer.Write< Util::String >( _data.MusicItem );
|
|
writer.Write< flt32 >( _data.FadeInDuration );
|
|
writer.Write< bool >( _data.PlayAtEndOfPreviousBrick );
|
|
writer.Write< int32 >( _data.EndBeatOverride );
|
|
writer.Write< bool >( _data.CancelAudioPreviewRequest );
|
|
writer.Write< Util::String >( _data.EventNameCallback );
|
|
}
|
|
|
|
bool Deserialize( Util::BinaryReader& reader )
|
|
{
|
|
bool success = true;
|
|
|
|
success &= reader.Read< Util::String >( _data.MusicItem );
|
|
success &= reader.Read< flt32 >( _data.FadeInDuration );
|
|
success &= reader.Read< bool >( _data.PlayAtEndOfPreviousBrick );
|
|
success &= reader.Read< int32 >( _data.EndBeatOverride );
|
|
success &= reader.Read< bool >( _data.CancelAudioPreviewRequest );
|
|
success &= reader.Read< Util::String >( _data.EventNameCallback );
|
|
|
|
success &= Component::Deserialize( reader );
|
|
|
|
return success;
|
|
}
|
|
|
|
// Xml Serialization
|
|
|
|
void Serialize( Util::XmlWriter& writer )
|
|
{
|
|
writer.WriteAttribute< Util::String >( "MusicItem", _data.MusicItem );
|
|
writer.WriteAttribute< flt32 >( "FadeInDuration", _data.FadeInDuration );
|
|
writer.WriteAttribute< bool >( "PlayAtEndOfPreviousBrick", _data.PlayAtEndOfPreviousBrick );
|
|
writer.WriteAttribute< int32 >( "EndBeatOverride", _data.EndBeatOverride );
|
|
writer.WriteAttribute< bool >( "CancelAudioPreviewRequest", _data.CancelAudioPreviewRequest );
|
|
writer.WriteAttribute< Util::String >( "EventNameCallback", _data.EventNameCallback );
|
|
}
|
|
|
|
bool Deserialize( Util::XmlReader& reader )
|
|
{
|
|
bool success = true;
|
|
|
|
success &= reader.ReadAttribute< Util::String >( "MusicItem", _data.MusicItem );
|
|
success &= reader.ReadAttribute< flt32 >( "FadeInDuration", _data.FadeInDuration );
|
|
success &= reader.ReadAttribute< bool >( "PlayAtEndOfPreviousBrick", _data.PlayAtEndOfPreviousBrick );
|
|
success &= reader.ReadAttribute< int32 >( "EndBeatOverride", _data.EndBeatOverride );
|
|
success &= reader.ReadAttribute< bool >( "CancelAudioPreviewRequest", _data.CancelAudioPreviewRequest );
|
|
success &= reader.ReadAttribute< Util::String >( "EventNameCallback", _data.EventNameCallback );
|
|
|
|
success &= Component::Deserialize( reader );
|
|
|
|
return success;
|
|
}
|
|
|
|
// endregion
|
|
|
|
// region Input Events
|
|
|
|
public:
|
|
enum InputEvents
|
|
{
|
|
InEventIn,
|
|
eNumInputEvents
|
|
};
|
|
|
|
inline void AddEventIn( uint32 index, EventConnection* connection )
|
|
{
|
|
Assert( connection );
|
|
Assert( _inputEvents[ index ].Find( connection ) == _inputEvents[ index ].End( ) );
|
|
|
|
_inputEvents[ index ].PushBack( connection );
|
|
}
|
|
|
|
void PushEventIn( uint32 index, Component* from );
|
|
|
|
private:
|
|
Util::FixedArray< EventConnectionList, PlayMenuMusic::eNumInputEvents > _inputEvents;
|
|
|
|
int32 GetEventInIndex( const Util::String& name )
|
|
{
|
|
if( name == "In" )
|
|
{
|
|
return InEventIn;
|
|
}
|
|
else
|
|
{
|
|
AssertMessage( 0, "Unknown PlayMenuMusic port name %s", name.Chars( ) );
|
|
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
const Util::String& GetEventInName( uint32 index )
|
|
{
|
|
if( index == InEventIn )
|
|
{
|
|
static Util::String name = "In";
|
|
return name;
|
|
}
|
|
else
|
|
{
|
|
AssertMessage( 0, "Unknown PlayMenuMusic port index %d", index );
|
|
|
|
static Util::String name = "Undefined";
|
|
return name;
|
|
}
|
|
};
|
|
|
|
// endregion
|
|
|
|
// region User methods
|
|
|
|
public:
|
|
static void RegisterCallback( IJustDancePlayMenuMusicCallback* cb );
|
|
static void UnregisterCallback( IJustDancePlayMenuMusicCallback* cb );
|
|
void ExecuteCallbacks( );
|
|
|
|
// endregion
|
|
|
|
// region Member variables
|
|
|
|
private:
|
|
Data _data;
|
|
|
|
// endregion
|
|
|
|
// region User member variables
|
|
|
|
private:
|
|
static Util::DynamicArray< IJustDancePlayMenuMusicCallback* > m_callbacks;
|
|
|
|
// endregion
|
|
};
|
|
}
|