2023-06-29 04:10:08 -04:00
|
|
|
#include "radio.h"
|
|
|
|
|
2024-03-18 11:05:05 -04:00
|
|
|
#include "isle_actions.h"
|
2023-12-14 18:24:21 -05:00
|
|
|
#include "legocontrolmanager.h"
|
|
|
|
#include "legogamestate.h"
|
2024-05-03 12:19:12 -04:00
|
|
|
#include "legoworld.h"
|
2024-03-09 15:07:52 -05:00
|
|
|
#include "misc.h"
|
2024-05-03 12:19:12 -04:00
|
|
|
#include "mxactionnotificationparam.h"
|
2024-01-30 13:57:20 -05:00
|
|
|
#include "mxbackgroundaudiomanager.h"
|
|
|
|
#include "mxcontrolpresenter.h"
|
2024-03-09 15:07:52 -05:00
|
|
|
#include "mxmisc.h"
|
2023-12-14 18:24:21 -05:00
|
|
|
#include "mxnotificationmanager.h"
|
2024-05-03 12:19:12 -04:00
|
|
|
#include "radiostate.h"
|
2024-05-04 08:06:32 -04:00
|
|
|
#include "scripts.h"
|
2023-12-14 18:24:21 -05:00
|
|
|
|
2024-03-22 21:30:58 -04:00
|
|
|
DECOMP_SIZE_ASSERT(Radio, 0x10)
|
2023-12-14 18:24:21 -05:00
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002c850
|
|
|
|
Radio::Radio()
|
|
|
|
{
|
|
|
|
NotificationManager()->Register(this);
|
|
|
|
ControlManager()->Register(this);
|
|
|
|
|
2024-01-29 16:17:17 -05:00
|
|
|
m_unk0x0c = TRUE;
|
2023-12-14 18:24:21 -05:00
|
|
|
CreateRadioState();
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:57:20 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002c990
|
2023-06-29 04:10:08 -04:00
|
|
|
Radio::~Radio()
|
|
|
|
{
|
2024-01-30 13:57:20 -05:00
|
|
|
if (m_state->IsActive()) {
|
|
|
|
BackgroundAudioManager()->Stop();
|
|
|
|
m_state->SetActive(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlManager()->Unregister(this);
|
|
|
|
NotificationManager()->Unregister(this);
|
2023-10-25 14:51:59 -04:00
|
|
|
}
|
2023-12-14 18:24:21 -05:00
|
|
|
|
2024-01-30 13:57:20 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002ca30
|
2024-01-20 18:04:46 -05:00
|
|
|
MxLong Radio::Notify(MxParam& p_param)
|
|
|
|
{
|
2024-01-30 13:57:20 -05:00
|
|
|
MxLong result = 0;
|
|
|
|
|
|
|
|
if (m_unk0x0c) {
|
|
|
|
switch (((MxNotificationParam&) p_param).GetType()) {
|
|
|
|
case c_notificationEndAction:
|
|
|
|
result = HandleEndAction((MxEndActionNotificationParam&) p_param);
|
|
|
|
break;
|
2024-01-31 09:47:15 -05:00
|
|
|
case c_notificationClick:
|
|
|
|
result = HandleClick((LegoControlManagerEvent&) p_param);
|
2024-01-30 13:57:20 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002ca70
|
|
|
|
void Radio::Play()
|
|
|
|
{
|
|
|
|
if (!m_state->IsActive()) {
|
2024-02-02 12:18:46 -05:00
|
|
|
CurrentWorld();
|
2024-01-30 13:57:20 -05:00
|
|
|
|
|
|
|
MxDSAction action;
|
|
|
|
action.SetObjectId(m_state->FUN_1002d090());
|
|
|
|
action.SetAtomId(*g_jukeboxScript);
|
|
|
|
action.SetLoopCount(1);
|
|
|
|
|
2024-02-14 11:48:39 -05:00
|
|
|
m_audioEnabled = BackgroundAudioManager()->GetEnabled();
|
|
|
|
if (!m_audioEnabled) {
|
2024-01-30 13:57:20 -05:00
|
|
|
BackgroundAudioManager()->Enable(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundAudioManager()->PlayMusic(action, 3, 4);
|
|
|
|
m_state->SetActive(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002cb70
|
|
|
|
void Radio::Stop()
|
|
|
|
{
|
|
|
|
if (m_state->IsActive()) {
|
2024-02-02 12:18:46 -05:00
|
|
|
LegoWorld* world = CurrentWorld();
|
2024-01-30 13:57:20 -05:00
|
|
|
|
2024-04-28 07:27:17 -04:00
|
|
|
MxControlPresenter* presenter = (MxControlPresenter*) world->Find(world->GetAtom(), IsleScript::c_Radio_Ctl);
|
2024-01-30 13:57:20 -05:00
|
|
|
|
2024-02-01 15:42:10 -05:00
|
|
|
if (presenter) {
|
2024-01-30 13:57:20 -05:00
|
|
|
presenter->VTable0x6c(0);
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2024-01-30 13:57:20 -05:00
|
|
|
|
|
|
|
BackgroundAudioManager()->Stop();
|
2024-02-14 11:48:39 -05:00
|
|
|
BackgroundAudioManager()->Enable(m_audioEnabled);
|
2024-01-30 13:57:20 -05:00
|
|
|
m_state->SetActive(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002cbc0
|
2024-01-31 09:47:15 -05:00
|
|
|
MxLong Radio::HandleClick(LegoControlManagerEvent& p_param)
|
2024-01-30 13:57:20 -05:00
|
|
|
{
|
|
|
|
MxDSAction action; // Unused
|
|
|
|
MxS32 objectId = p_param.GetClickedObjectId();
|
|
|
|
|
2024-03-18 11:05:05 -04:00
|
|
|
if (objectId == IsleScript::c_Radio_Ctl) {
|
2024-01-30 13:57:20 -05:00
|
|
|
if (m_state->IsActive()) {
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Play();
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:18:46 -05:00
|
|
|
if (CurrentWorld()) {
|
2024-01-30 13:57:20 -05:00
|
|
|
#ifdef COMPAT_MODE
|
|
|
|
MxNotificationParam param(c_notificationEndAction, this);
|
2024-02-02 12:18:46 -05:00
|
|
|
CurrentWorld()->Notify(param);
|
2024-01-30 13:57:20 -05:00
|
|
|
#else
|
2024-02-02 12:18:46 -05:00
|
|
|
CurrentWorld()->Notify(MxNotificationParam(c_notificationType0, this));
|
2024-01-30 13:57:20 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1002ccc0
|
|
|
|
MxLong Radio::HandleEndAction(MxEndActionNotificationParam& p_param)
|
|
|
|
{
|
|
|
|
if (m_state->IsActive() &&
|
|
|
|
m_state->FUN_1002d0c0(p_param.GetAction()->GetAtomId(), p_param.GetAction()->GetObjectId())) {
|
|
|
|
|
|
|
|
MxDSAction action;
|
|
|
|
action.SetAtomId(*g_jukeboxScript);
|
|
|
|
action.SetObjectId(m_state->FUN_1002d090());
|
|
|
|
action.SetLoopCount(1);
|
|
|
|
|
|
|
|
BackgroundAudioManager()->PlayMusic(action, 3, 4);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-01-20 18:04:46 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-01-21 12:38:22 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002cdc0
|
|
|
|
void Radio::Initialize(MxBool p_und)
|
|
|
|
{
|
2024-01-29 16:17:17 -05:00
|
|
|
if (m_unk0x0c != p_und) {
|
|
|
|
m_unk0x0c = p_und;
|
2024-01-21 12:38:22 -05:00
|
|
|
CreateRadioState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-14 18:24:21 -05:00
|
|
|
// FUNCTION: LEGO1 0x1002cde0
|
|
|
|
void Radio::CreateRadioState()
|
|
|
|
{
|
|
|
|
LegoGameState* gameState = GameState();
|
|
|
|
RadioState* state = (RadioState*) gameState->GetState("RadioState");
|
|
|
|
if (state == NULL) {
|
|
|
|
state = (RadioState*) gameState->CreateState("RadioState");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_state = state;
|
|
|
|
}
|