aboutsummaryrefslogtreecommitdiff
path: root/engines/bbvs
diff options
context:
space:
mode:
authorjohndoe1232015-01-22 13:06:02 +0100
committerjohndoe1232015-01-29 13:11:03 +0100
commita48a6ad30e52f52793ba9b09271146f2553a656d (patch)
tree34d23ccca221cd6e99089979989bbf0dbdb60d8b /engines/bbvs
parentf2fffeb17cd8a46728f02fd0195e3f72bb0b29c5 (diff)
downloadscummvm-rg350-a48a6ad30e52f52793ba9b09271146f2553a656d.tar.gz
scummvm-rg350-a48a6ad30e52f52793ba9b09271146f2553a656d.tar.bz2
scummvm-rg350-a48a6ad30e52f52793ba9b09271146f2553a656d.zip
BBVS: Implement loading and saving in the air guitar minigame
Diffstat (limited to 'engines/bbvs')
-rw-r--r--engines/bbvs/minigames/bbairguitar.cpp113
-rw-r--r--engines/bbvs/minigames/bbairguitar.h11
2 files changed, 120 insertions, 4 deletions
diff --git a/engines/bbvs/minigames/bbairguitar.cpp b/engines/bbvs/minigames/bbairguitar.cpp
index 1984dbb0fd..6f198cb42a 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[] = {
@@ -805,7 +811,7 @@ void MinigameBbAirGuitar::update() {
}
if (_vm->_keyCode == Common::KEYCODE_ESCAPE) {
- _gameDone = true;
+ _gameDone = querySaveModifiedTracks();
return;
}
@@ -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;
@@ -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
diff --git a/engines/bbvs/minigames/bbairguitar.h b/engines/bbvs/minigames/bbairguitar.h
index 40b8a50a03..b8b92ef433 100644
--- a/engines/bbvs/minigames/bbairguitar.h
+++ b/engines/bbvs/minigames/bbairguitar.h
@@ -47,7 +47,7 @@ public:
enum {
kMaxObjectsCount = 256,
- kMaxTracks = 2049
+ kMaxTracks = 2048
};
struct PianoKeyInfo {
@@ -141,6 +141,15 @@ public:
void playNote(int noteNum);
void stopNote(int noteNum);
+ bool getLoadFilename(Common::String &filename);
+ bool getSaveFilename(Common::String &filename);
+ bool querySaveModifiedDialog();
+ bool querySaveModifiedTracks();
+ bool loadTracks();
+ bool saveTracks();
+ bool loadFromStream(Common::ReadStream *stream);
+ void saveToStream(Common::WriteStream *stream);
+
};
} // End of namespace Bbvs