#include #include // Replaces: EN_LIFT_ROTATION_HALF (Sprite 107; Profile ID 481 @ 80AF96F8) class dMsgBoxManager_c : public dStageActor_c { public: void showMessage(int id); dMsgBoxManager_c() : state(this, &StateID_LoadRes) { } int onCreate(); int onDelete(); int onExecute(); int onDraw(); int beforeExecute() { return true; } int afterExecute(int) { return true; } m2d::EmbedLayout_c layout; dDvdLoader_c msgDataLoader; bool layoutLoaded; bool visible; dStateWrapper_c state; USING_STATES(dMsgBoxManager_c); DECLARE_STATE(LoadRes); DECLARE_STATE(Wait); DECLARE_STATE(BoxAppearWait); // DECLARE_STATE(ButtonAppearWait); DECLARE_STATE(ShownWait); // DECLARE_STATE(ButtonDisappearWait); DECLARE_STATE(BoxDisappearWait); static dMsgBoxManager_c *instance; static dMsgBoxManager_c *build(); private: struct entry_s { u32 id; u32 titleOffset; u32 msgOffset; }; struct header_s { u32 count; entry_s entry[1]; }; }; dMsgBoxManager_c *dMsgBoxManager_c::instance = 0; dMsgBoxManager_c *dMsgBoxManager_c::build() { void *buffer = AllocFromGameHeap1(sizeof(dMsgBoxManager_c)); dMsgBoxManager_c *c = new(buffer) dMsgBoxManager_c; instance = c; return c; } #define ANIM_BOX_APPEAR 0 #define ANIM_BOX_DISAPPEAR 1 //#define ANIM_BUTTON_APPEAR 2 //#define ANIM_BUTTON_DISAPPEAR 3 extern int MessageBoxIsShowing; /*****************************************************************************/ // Events int dMsgBoxManager_c::onCreate() { if (!layoutLoaded) { if (!layout.loadArc("msgbox.arc", false)) return false; static const char *brlanNames[2] = { "BoxAppear.brlan", "BoxDisappear.brlan", // "ButtonAppear.brlan", // "ButtonDisappear.brlan" }; static const char *groupNames[2] = { "G_Box", "G_Box", // "G_Button", "G_Button" }; layout.build("MessageBox.brlyt"); if (IsWideScreen()) { layout.layout.rootPane->scale.x = 0.7711f; } layout.loadAnimations(brlanNames, 2); layout.loadGroups(groupNames, (int[2]){0,1}, 2); layout.disableAllAnimations(); layout.drawOrder = 0xA0; layoutLoaded = true; } visible = false; return true; } int dMsgBoxManager_c::onExecute() { //OSReport("E: %s\n", state.getCurrentState()->getName()); state.execute(); layout.execAnimations(); layout.update(); return true; } int dMsgBoxManager_c::onDraw() { if (visible) { layout.scheduleForDrawing(); } return true; } int dMsgBoxManager_c::onDelete() { instance = 0; return layout.free(); } /*****************************************************************************/ // Load Resources CREATE_STATE_E(dMsgBoxManager_c, LoadRes); void dMsgBoxManager_c::executeState_LoadRes() { OSReport("Trying to load\n"); if (msgDataLoader.load("/NewerRes/Messages.bin")) { OSReport(":)\n"); state.setState(&StateID_Wait); OSReport("changed\n"); } else { OSReport(":(\n"); } } /*****************************************************************************/ // Waiting CREATE_STATE_E(dMsgBoxManager_c, Wait); void dMsgBoxManager_c::executeState_Wait() { // null } /*****************************************************************************/ // Show Box void dMsgBoxManager_c::showMessage(int id) { // get the data file header_s *data = (header_s*)msgDataLoader.buffer; const wchar_t *title = 0, *msg = 0; for (int i = 0; i < data->count; i++) { if (data->entry[i].id == id) { title = (const wchar_t*)((u32)data + data->entry[i].titleOffset); msg = (const wchar_t*)((u32)data + data->entry[i].msgOffset); break; } } if (title == 0) { OSReport("WARNING! Tried to show message %x but it could not be found!\n", id); return; } layout.findTextBoxByName("T_title")->SetString(title); layout.findTextBoxByName("T_msg")->SetString(msg); state.setState(&StateID_BoxAppearWait); } CREATE_STATE(dMsgBoxManager_c, BoxAppearWait); void dMsgBoxManager_c::beginState_BoxAppearWait() { visible = true; MessageBoxIsShowing = true; layout.enableNonLoopAnim(ANIM_BOX_APPEAR); OSReport("Enabling box appear @ %d\n", GlobalTickCount); } void dMsgBoxManager_c::executeState_BoxAppearWait() { if (!layout.isAnimOn(ANIM_BOX_APPEAR)) { OSReport("Box appeared @ %d\n", GlobalTickCount); state.setState(&StateID_ShownWait); } } void dMsgBoxManager_c::endState_BoxAppearWait() { } /*****************************************************************************/ // Show Button /*CREATE_STATE(dMsgBoxManager_c, ButtonAppearWait); void dMsgBoxManager_c::beginState_ButtonAppearWait() { layout.enableNonLoopAnim(ANIM_BUTTON_APPEAR); OSReport("Enabling button appear @ %d\n", GlobalTickCount); } void dMsgBoxManager_c::executeState_ButtonAppearWait() { if (!layout.isAnimOn(ANIM_BUTTON_APPEAR)) { OSReport("Button appeared @ %d\n", GlobalTickCount); state.setState(&StateID_ShownWait); } } void dMsgBoxManager_c::endState_ButtonAppearWait() { }*/ /*****************************************************************************/ // Wait For Player To Finish CREATE_STATE(dMsgBoxManager_c, ShownWait); void dMsgBoxManager_c::beginState_ShownWait() { } void dMsgBoxManager_c::executeState_ShownWait() { int nowPressed = Remocon_GetPressed(GetActiveRemocon()); if (nowPressed & WPAD_TWO) { state.setState(&StateID_BoxDisappearWait); } } void dMsgBoxManager_c::endState_ShownWait() { } /*****************************************************************************/ // Hide Button /*CREATE_STATE(dMsgBoxManager_c, ButtonDisappearWait); void dMsgBoxManager_c::beginState_ButtonDisappearWait() { layout.enableNonLoopAnim(ANIM_BUTTON_DISAPPEAR); OSReport("Enabling button disappear @ %d\n", GlobalTickCount); } void dMsgBoxManager_c::executeState_ButtonDisappearWait() { if (!layout.isAnimOn(ANIM_BUTTON_DISAPPEAR)) { OSReport("Button disappeared @ %d\n", GlobalTickCount); state.setState(&StateID_BoxDisappearWait); } } void dMsgBoxManager_c::endState_ButtonDisappearWait() { }*/ /*****************************************************************************/ // Hide Box CREATE_STATE(dMsgBoxManager_c, BoxDisappearWait); void dMsgBoxManager_c::beginState_BoxDisappearWait() { layout.enableNonLoopAnim(ANIM_BOX_DISAPPEAR); OSReport("Enabling box disappear @ %d\n", GlobalTickCount); } void dMsgBoxManager_c::executeState_BoxDisappearWait() { if (!layout.isAnimOn(ANIM_BOX_DISAPPEAR)) { OSReport("Box disappeared @ %d\n", GlobalTickCount); state.setState(&StateID_Wait); for (int i = 0; i < 2; i++) layout.resetAnim(i); layout.disableAllAnimations(); } } void dMsgBoxManager_c::endState_BoxDisappearWait() { visible = false; MessageBoxIsShowing = false; } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ // Replaces: EN_BLUR (Sprite 152; Profile ID 603 @ 80ADD890) class daEnMsgBlock_c : public daEnBlockMain_c { public: TileRenderer tile; Physics::Info physicsInfo; int onCreate(); int onDelete(); int onExecute(); void calledWhenUpMoveExecutes(); void calledWhenDownMoveExecutes(); void blockWasHit(bool isDown); USING_STATES(daEnMsgBlock_c); DECLARE_STATE(Wait); static daEnMsgBlock_c *build(); }; CREATE_STATE(daEnMsgBlock_c, Wait); int daEnMsgBlock_c::onCreate() { OSReport("Creating Block\n"); blockInit(pos.y); physicsInfo.x1 = -8; physicsInfo.y1 = 16; physicsInfo.x2 = 8; physicsInfo.y2 = 0; physicsInfo.otherCallback1 = &daEnBlockMain_c::OPhysicsCallback1; physicsInfo.otherCallback2 = &daEnBlockMain_c::OPhysicsCallback2; physicsInfo.otherCallback3 = &daEnBlockMain_c::OPhysicsCallback3; physics.setup(this, &physicsInfo, 3, currentLayerID); physics.flagsMaybe = 0x260; physics.callback1 = &daEnBlockMain_c::PhysicsCallback1; physics.callback2 = &daEnBlockMain_c::PhysicsCallback2; physics.callback3 = &daEnBlockMain_c::PhysicsCallback3; physics.addToList(); TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0); list->add(&tile); tile.x = pos.x - 8; tile.y = -(16 + pos.y); tile.tileNumber = 0x98; doStateChange(&daEnMsgBlock_c::StateID_Wait); OSReport("Created Block\n"); return true; } int daEnMsgBlock_c::onDelete() { TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0); list->remove(&tile); physics.removeFromList(); return true; } int daEnMsgBlock_c::onExecute() { acState.execute(); physics.update(); blockUpdate(); tile.setPosition(pos.x-8, -(16+pos.y), pos.z); tile.setVars(scale.x); // now check zone bounds based on state if (acState.getCurrentState()->isEqual(&StateID_Wait)) { checkZoneBoundaries(0); } return true; } daEnMsgBlock_c *daEnMsgBlock_c::build() { void *buffer = AllocFromGameHeap1(sizeof(daEnMsgBlock_c)); return new(buffer) daEnMsgBlock_c; } void daEnMsgBlock_c::blockWasHit(bool isDown) { pos.y = initialY; dMsgBoxManager_c::instance->showMessage(settings); physics.setup(this, &physicsInfo, 3, currentLayerID); physics.addToList(); doStateChange(&StateID_Wait); } void daEnMsgBlock_c::calledWhenUpMoveExecutes() { if (initialY >= pos.y) blockWasHit(false); } void daEnMsgBlock_c::calledWhenDownMoveExecutes() { if (initialY <= pos.y) blockWasHit(true); } void daEnMsgBlock_c::beginState_Wait() { } void daEnMsgBlock_c::endState_Wait() { } void daEnMsgBlock_c::executeState_Wait() { int result = blockResult(); if (result == 0) return; if (result == 1) { doStateChange(&daEnBlockMain_c::StateID_UpMove); anotherFlag = 2; isGroundPound = false; } else { doStateChange(&daEnBlockMain_c::StateID_DownMove); anotherFlag = 1; isGroundPound = true; } }