isle-portable/LEGO1/lego/legoomni/src/actors/radio.cpp

162 lines
3.3 KiB
C++
Raw Normal View History

#include "radio.h"
#include "isle_actions.h"
2023-12-14 18:24:21 -05:00
#include "legocontrolmanager.h"
#include "legogamestate.h"
#include "legoomni.h"
#include "misc.h"
#include "mxbackgroundaudiomanager.h"
#include "mxcontrolpresenter.h"
#include "mxmisc.h"
2023-12-14 18:24:21 -05:00
#include "mxnotificationmanager.h"
DECOMP_SIZE_ASSERT(Radio, 0x10)
2023-12-14 18:24:21 -05:00
// FUNCTION: LEGO1 0x1002c850
Radio::Radio()
{
NotificationManager()->Register(this);
ControlManager()->Register(this);
m_unk0x0c = TRUE;
2023-12-14 18:24:21 -05:00
CreateRadioState();
}
// FUNCTION: LEGO1 0x1002c990
Radio::~Radio()
{
if (m_state->IsActive()) {
BackgroundAudioManager()->Stop();
m_state->SetActive(FALSE);
}
ControlManager()->Unregister(this);
NotificationManager()->Unregister(this);
}
2023-12-14 18:24:21 -05:00
// FUNCTION: LEGO1 0x1002ca30
Enforce vtable match (#464) * vtable enforce * Vtable progress * IslePathActor subclasses * LegoState subclasses * LegoWorld subclasses * Presenter progress * Remaining presenters * All but two that need new files * Merge into vtable branch (#3) * Implement MxDisplaySurface::VTable0x44 (#467) * Update mxdisplaysurface.cpp * add arguments to header * Fix glitched bitmaps * WIP fixes * Match * Fix * Changes * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com> * Implmement PoliceState::VTable0x1c (#468) * Implmement PoliceState::VTable0x1c * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com> * Implement Lego3DView::Render (#470) * Implement Lego3DView::Render * use MxDouble * Revert "use MxDouble" This reverts commit a006b60e2066b79ded3e15e143a302d8fd707deb. * Begin work on Police class (#469) * Begin work on Police class * Use JukeBox::e_policeStation value * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com> * Implement MxDisplaySurface::CreateCursorSurface (#471) * Update mxdisplaysurface.cpp * Fixes * Update legovideomanager.cpp * Match to 100% --------- Co-authored-by: Christian Semmler <mail@csemmler.com> --------- Co-authored-by: Misha <106913236+MishaProductions@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com> Co-authored-by: Joshua Peisach <itzswirlz2020@outlook.com> * Police fix * Finish * motocycle lower case * Update historybook.h * Update hospitalstate.h * Update jetski.h * Update legoinputmanager.h * Update legolocomotionanimpresenter.h * Update pizza.h * Update act3shark.h * Update ambulancemissionstate.h * Update bumpbouy.h * Update doors.h --------- Co-authored-by: Misha <106913236+MishaProductions@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com> Co-authored-by: Joshua Peisach <itzswirlz2020@outlook.com>
2024-01-20 18:04:46 -05:00
MxLong Radio::Notify(MxParam& p_param)
{
MxLong result = 0;
if (m_unk0x0c) {
switch (((MxNotificationParam&) p_param).GetType()) {
case c_notificationEndAction:
result = HandleEndAction((MxEndActionNotificationParam&) p_param);
break;
case c_notificationClick:
result = HandleClick((LegoControlManagerEvent&) p_param);
break;
}
}
return result;
}
// FUNCTION: LEGO1 0x1002ca70
void Radio::Play()
{
if (!m_state->IsActive()) {
CurrentWorld();
MxDSAction action;
action.SetObjectId(m_state->FUN_1002d090());
action.SetAtomId(*g_jukeboxScript);
action.SetLoopCount(1);
m_audioEnabled = BackgroundAudioManager()->GetEnabled();
if (!m_audioEnabled) {
BackgroundAudioManager()->Enable(TRUE);
}
BackgroundAudioManager()->PlayMusic(action, 3, 4);
m_state->SetActive(TRUE);
}
}
// FUNCTION: LEGO1 0x1002cb70
void Radio::Stop()
{
if (m_state->IsActive()) {
LegoWorld* world = CurrentWorld();
MxControlPresenter* presenter = (MxControlPresenter*) world->Find(world->GetAtom(), 18);
if (presenter) {
presenter->VTable0x6c(0);
}
BackgroundAudioManager()->Stop();
BackgroundAudioManager()->Enable(m_audioEnabled);
m_state->SetActive(FALSE);
}
}
// FUNCTION: LEGO1 0x1002cbc0
MxLong Radio::HandleClick(LegoControlManagerEvent& p_param)
{
MxDSAction action; // Unused
MxS32 objectId = p_param.GetClickedObjectId();
if (objectId == IsleScript::c_Radio_Ctl) {
if (m_state->IsActive()) {
Stop();
}
else {
Play();
}
if (CurrentWorld()) {
#ifdef COMPAT_MODE
MxNotificationParam param(c_notificationEndAction, this);
CurrentWorld()->Notify(param);
#else
CurrentWorld()->Notify(MxNotificationParam(c_notificationType0, this));
#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;
}
Enforce vtable match (#464) * vtable enforce * Vtable progress * IslePathActor subclasses * LegoState subclasses * LegoWorld subclasses * Presenter progress * Remaining presenters * All but two that need new files * Merge into vtable branch (#3) * Implement MxDisplaySurface::VTable0x44 (#467) * Update mxdisplaysurface.cpp * add arguments to header * Fix glitched bitmaps * WIP fixes * Match * Fix * Changes * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com> * Implmement PoliceState::VTable0x1c (#468) * Implmement PoliceState::VTable0x1c * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com> * Implement Lego3DView::Render (#470) * Implement Lego3DView::Render * use MxDouble * Revert "use MxDouble" This reverts commit a006b60e2066b79ded3e15e143a302d8fd707deb. * Begin work on Police class (#469) * Begin work on Police class * Use JukeBox::e_policeStation value * Fixes --------- Co-authored-by: Christian Semmler <mail@csemmler.com> * Implement MxDisplaySurface::CreateCursorSurface (#471) * Update mxdisplaysurface.cpp * Fixes * Update legovideomanager.cpp * Match to 100% --------- Co-authored-by: Christian Semmler <mail@csemmler.com> --------- Co-authored-by: Misha <106913236+MishaProductions@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com> Co-authored-by: Joshua Peisach <itzswirlz2020@outlook.com> * Police fix * Finish * motocycle lower case * Update historybook.h * Update hospitalstate.h * Update jetski.h * Update legoinputmanager.h * Update legolocomotionanimpresenter.h * Update pizza.h * Update act3shark.h * Update ambulancemissionstate.h * Update bumpbouy.h * Update doors.h --------- Co-authored-by: Misha <106913236+MishaProductions@users.noreply.github.com> Co-authored-by: Christian Semmler <mail@csemmler.com> Co-authored-by: Joshua Peisach <itzswirlz2020@outlook.com>
2024-01-20 18:04:46 -05:00
return 0;
}
// FUNCTION: LEGO1 0x1002cdc0
void Radio::Initialize(MxBool p_und)
{
if (m_unk0x0c != p_und) {
m_unk0x0c = p_und;
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;
}