diff options
Diffstat (limited to 'engines/bbvs/minigames/bbairguitar.cpp')
-rw-r--r-- | engines/bbvs/minigames/bbairguitar.cpp | 177 |
1 files changed, 142 insertions, 35 deletions
diff --git a/engines/bbvs/minigames/bbairguitar.cpp b/engines/bbvs/minigames/bbairguitar.cpp index f2e42313e3..26e27a966f 100644 --- a/engines/bbvs/minigames/bbairguitar.cpp +++ b/engines/bbvs/minigames/bbairguitar.cpp @@ -22,6 +22,12 @@ #include "bbvs/minigames/bbairguitar.h" +#include "common/savefile.h" +#include "common/translation.h" + +#include "gui/dialog.h" +#include "gui/message.h" + namespace Bbvs { static const char * const kNoteSoundFilenames[] = { @@ -198,12 +204,12 @@ void MinigameBbAirGuitar::buildDrawList1(DrawList &drawList) { if (_trackBarX > kTrackBarMaxX) _trackBarX = kTrackBarMaxX; - + _trackBarThumbRect.top = 208; _trackBarThumbRect.bottom = 218; _trackBarThumbRect.left = _trackBarX; _trackBarThumbRect.right = _trackBarX + 6; - + drawList.add(_objects[5].anim->frameIndices[0], _trackBarX, 208, 100); if (_playerMode != 0) { @@ -228,7 +234,7 @@ void MinigameBbAirGuitar::buildDrawList1(DrawList &drawList) { drawList.add(_objects[i].anim->frameIndices[frameIndex], kPointsTbl2[i - 47].x, kPointsTbl2[i - 47].y, 254); } } - + if (_backgroundSpriteIndex > 0) drawList.add(_backgroundSpriteIndex, 0, 0, 0); @@ -394,7 +400,7 @@ void MinigameBbAirGuitar::initObjects1() { _track[0].noteNum = -1; stop(); changePatch(0); - + } bool MinigameBbAirGuitar::updateStatus(int mouseX, int mouseY, uint mouseButtons) { @@ -408,7 +414,7 @@ bool MinigameBbAirGuitar::updateStatus(int mouseX, int mouseY, uint mouseButtons } bool MinigameBbAirGuitar::updateStatus0(int mouseX, int mouseY, uint mouseButtons) { - + if (mouseButtons & kAnyButtonDown) { stopSound(1); _rockTunePlaying = false; @@ -436,14 +442,14 @@ bool MinigameBbAirGuitar::updateStatus0(int mouseX, int mouseY, uint mouseButton } } - + return true; } bool MinigameBbAirGuitar::updateStatus1(int mouseX, int mouseY, uint mouseButtons) { - + int currTicks = _vm->_system->getMillis(); - + if (_playerMode == 1 && _track[_trackIndex].ticks <= currTicks - _noteStartTime) { noteOff(_track[_trackIndex].noteNum); if (_trackIndex < _trackCount && _track[++_trackIndex].noteNum != -1) @@ -481,17 +487,17 @@ bool MinigameBbAirGuitar::updateStatus1(int mouseX, int mouseY, uint mouseButton } else { ++_vuMeterRight2; } - + if (_resetAnims && _vm->_system->getMillis() - _noteStartTime >= 1000) resetObjs(); - + _objects[0].x = mouseX; _objects[0].y = mouseY; - + _trackBarMouseX = CLIP(mouseX, kTrackBarMinX, kTrackBarMaxX); - + bool checkClick = false; - + if (mouseButtons & kAnyButtonClicked) { checkClick = true; } else if (!(mouseButtons & kAnyButtonDown)) { @@ -506,14 +512,14 @@ bool MinigameBbAirGuitar::updateStatus1(int mouseX, int mouseY, uint mouseButton } } else if (!_movingTrackBar) checkClick = true; - + if (checkClick) { afterButtonReleased(); _objects[0].frameIndex = 1; - + if (ptInRect(&kRect2, mouseX, mouseY)) { - + if (_playerMode != 1 && ptInRect(&kPianoRect, mouseX, mouseY)) { for (int i = 0; i <= 12; ++i) { if (ptInPoly(&kPianoKeyAreas[i], mouseX, mouseY)) { @@ -538,7 +544,7 @@ bool MinigameBbAirGuitar::updateStatus1(int mouseX, int mouseY, uint mouseButton break; } } - + if (playerButtonNum >= 0) { _currButtonNum = playerButtonNum; _currPlayerButtonRect = &kPlayerButtonRects[playerButtonNum]; @@ -673,12 +679,12 @@ bool MinigameBbAirGuitar::updateStatus1(int mouseX, int mouseY, uint mouseButton } } } - + if (_buttonClickTicks + 1000 < currTicks) _buttonClickTicks = currTicks; - + int newKind = _buttonClickTicks + 500 < currTicks ? 1 : 0; - + switch (_playerMode) { case 1: @@ -770,20 +776,20 @@ bool MinigameBbAirGuitar::run(bool fromMainGame) { _gameResult = false; _gameDone = false; initObjects(); - + _spriteModule = new SpriteModule(); _spriteModule->load("bbairg/bbairg.000"); Palette palette = _spriteModule->getPalette(); _vm->_screen->setPalette(palette); - + loadSounds(); - + while (!_vm->shouldQuit() &&!_gameDone) { _vm->updateEvents(); update(); } - + _vm->_sound->unloadSounds(); delete _spriteModule; @@ -803,15 +809,15 @@ void MinigameBbAirGuitar::update() { inputTicks = 1; _gameTicks = _vm->_system->getMillis(); } - + if (_vm->_keyCode == Common::KEYCODE_ESCAPE) { - _gameDone = true; + _gameDone = querySaveModifiedTracks(); return; } - + if (inputTicks == 0) return; - + bool done; do { @@ -820,9 +826,9 @@ void MinigameBbAirGuitar::update() { _vm->_mouseButtons &= ~kRightButtonClicked; _vm->_keyCode = Common::KEYCODE_INVALID; } while (--inputTicks && _gameTicks > 0 && !done); - + drawSprites(); - + _vm->_system->delayMillis(10); } @@ -925,7 +931,8 @@ void MinigameBbAirGuitar::afterButtonReleased() { break; case 4: *_currFrameIndex = 1; - // TODO Run load dialog + loadTracks(); + _objects[1].kind = 0; break; case 5: _objects[3].kind = 0; @@ -950,7 +957,8 @@ void MinigameBbAirGuitar::afterButtonReleased() { break; case 12: *_currFrameIndex = 1; - // TODO Run save dialog + saveTracks(); + _objects[2].kind = 0; break; case 13: _objects[4].kind = 0; @@ -1001,7 +1009,7 @@ void MinigameBbAirGuitar::calcTotalTicks1() { } void MinigameBbAirGuitar::noteOn(int noteNum) { - + if (_currNoteNum != -2) { if (noteNum == _currNoteNum) return; @@ -1087,7 +1095,7 @@ void MinigameBbAirGuitar::noteOn(int noteNum) { } void MinigameBbAirGuitar::noteOff(int noteNum) { - + if (_currNoteNum != noteNum) return; @@ -1113,7 +1121,7 @@ void MinigameBbAirGuitar::noteOff(int noteNum) { if (_actionTrackPos + _ticksDelta > 15000) _ticksDelta = 15000 - _actionTrackPos; _track[_trackCount].ticks = _ticksDelta; - if (_trackCount < 2048) + if (_trackCount + 1 < 2048) ++_trackCount; _track[_trackCount].noteNum = -2; _noteStartTime = _vm->_system->getMillis(); @@ -1195,4 +1203,103 @@ void MinigameBbAirGuitar::stopNote(int noteNum) { stopSound(2 + _currPatchNum * kNoteSoundFilenamesCount + noteNum); } +bool MinigameBbAirGuitar::getLoadFilename(Common::String &filename) { + // TODO Run dialog and return actual filename + filename = "test.air"; + return true; +} + +bool MinigameBbAirGuitar::getSaveFilename(Common::String &filename) { + // TODO Run dialog and return actual filename + filename = "test.air"; + return true; +} + +bool MinigameBbAirGuitar::querySaveModifiedDialog() { + /* NOTE The original button captions don't fit so shortened variants are used + Original ok button caption: "Yeah, heh, heh, save it!" + Original discard button caption: "Who cares? It sucked!" + */ + GUI::MessageDialog query(_("Hey Beavis - you didn't save that last Jam!"), + _("Save it!"), + _("It sucked!")); + return query.runModal() == GUI::kMessageOK; +} + +bool MinigameBbAirGuitar::querySaveModifiedTracks() { + if (_modified && querySaveModifiedDialog()) { + if (!saveTracks()) + return false; + } + return true; +} + +bool MinigameBbAirGuitar::loadTracks() { + if (_playerMode != 0) + return false; + + if (!querySaveModifiedTracks()) + return false; + + Common::String filename; + if (!getLoadFilename(filename)) + return false; + + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::InSaveFile *stream = saveFileMan->openForLoading(filename); + if (!loadFromStream(stream)) { + Common::String msg = Common::String::format("%s is not a valid Air Guitar file", filename.c_str()); + GUI::MessageDialog dialog(msg); + dialog.runModal(); + } + delete stream; + + return true; +} + +bool MinigameBbAirGuitar::saveTracks() { + if (_playerMode != 0) + return false; + + Common::String filename; + if (!getSaveFilename(filename)) + return false; + + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::OutSaveFile *stream = saveFileMan->openForSaving(filename); + saveToStream(stream); + delete stream; + _modified = false; + + return true; +} + +bool MinigameBbAirGuitar::loadFromStream(Common::ReadStream *stream) { + uint32 magic = stream->readUint32BE(); + if (magic != MKTAG('A', 'I', 'R', 'G')) + return false; + for (uint i = 0; i < kMaxTracks; ++i) { + _track[i].noteNum = stream->readByte(); + _track[i].ticks = stream->readUint16LE(); + } + _trackCount = 0; + _actionTrackPos = 0; + while (_track[_trackCount].noteNum != -1) { + _actionTrackPos += _track[_trackCount].ticks; + ++_trackCount; + } + _totalTrackLength = _actionTrackPos; + _trackIndex = 0; + _currTrackPos = 0; + return true; +} + +void MinigameBbAirGuitar::saveToStream(Common::WriteStream *stream) { + stream->writeUint32BE(MKTAG('A', 'I', 'R', 'G')); + for (uint i = 0; i < kMaxTracks; ++i) { + stream->writeByte(_track[i].noteNum); + stream->writeUint16LE(_track[i].ticks); + } +} + } // End of namespace Bbvs |