2017-02-27 05:25:14 +00:00
|
|
|
#include "CScriptMidi.hpp"
|
|
|
|
#include "TCastTo.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "MP1/CInGameGuiManager.hpp"
|
|
|
|
#include "CInGameTweakManagerBase.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CScriptMidi::CScriptMidi(TUniqueId id, const CEntityInfo& info, const std::string& name,
|
2017-08-13 05:26:14 +00:00
|
|
|
bool active, CAssetId csng, float fadeIn, float fadeOut, s32 volume)
|
2017-02-27 05:25:14 +00:00
|
|
|
: CEntity(id, info, active, name), x40_fadeInTime(fadeIn), x44_fadeOutTime(fadeOut),
|
|
|
|
x48_volume(volume)
|
|
|
|
{
|
|
|
|
x34_song = g_SimplePool->GetObj(SObjectTag{FOURCC('CSNG'), csng});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptMidi::StopInternal(float fadeTime)
|
|
|
|
{
|
|
|
|
if (x3c_handle)
|
|
|
|
{
|
|
|
|
CMidiManager::Stop(x3c_handle, fadeTime);
|
|
|
|
x3c_handle.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptMidi::Stop(CStateManager& mgr, float fadeTime)
|
|
|
|
{
|
|
|
|
const CWorld* wld = mgr.GetWorld();
|
|
|
|
const CGameArea* area = wld->GetAreaAlways(x4_areaId);
|
2017-05-21 16:01:04 +00:00
|
|
|
std::string twkName = CInGameTweakManagerBase::GetIdentifierForMidiEvent(wld->IGetWorldAssetId(),
|
|
|
|
area->GetAreaAssetId(),
|
|
|
|
x10_name);
|
2017-02-27 05:25:14 +00:00
|
|
|
if (g_TweakManager->HasTweakValue(twkName))
|
|
|
|
{
|
|
|
|
const CTweakValue::Audio& audio = g_TweakManager->GetTweakValue(twkName)->GetAudio();
|
|
|
|
fadeTime = audio.GetFadeOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
StopInternal(fadeTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptMidi::Play(CStateManager& mgr, float fadeTime)
|
|
|
|
{
|
|
|
|
u32 volume = x48_volume;
|
|
|
|
const CWorld* wld = mgr.GetWorld();
|
|
|
|
const CGameArea* area = wld->GetAreaAlways(x4_areaId);
|
2017-05-21 16:01:04 +00:00
|
|
|
std::string twkName = CInGameTweakManagerBase::GetIdentifierForMidiEvent(wld->IGetWorldAssetId(),
|
|
|
|
area->GetAreaAssetId(),
|
|
|
|
x10_name);
|
2017-02-27 05:25:14 +00:00
|
|
|
if (g_TweakManager->HasTweakValue(twkName))
|
|
|
|
{
|
|
|
|
const CTweakValue::Audio& audio = g_TweakManager->GetTweakValue(twkName)->GetAudio();
|
|
|
|
x34_song = g_SimplePool->GetObj(SObjectTag{FOURCC('CSNG'), audio.GetResId()});
|
|
|
|
fadeTime = audio.GetFadeIn();
|
|
|
|
volume = audio.GetVolume() * 127.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
x3c_handle = CMidiManager::Play(*x34_song, fadeTime, false, volume / 127.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptMidi::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptMidi::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
|
|
|
|
{
|
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case EScriptObjectMessage::Play:
|
|
|
|
if (GetActive())
|
|
|
|
Play(stateMgr, x40_fadeInTime);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Stop:
|
|
|
|
if (GetActive())
|
|
|
|
Stop(stateMgr, x44_fadeOutTime);
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Deactivate:
|
|
|
|
StopInternal(0.f);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|