diff options
Diffstat (limited to 'engines/zvision/core')
-rw-r--r-- | engines/zvision/core/clock.h | 10 | ||||
-rw-r--r-- | engines/zvision/core/console.cpp | 159 | ||||
-rw-r--r-- | engines/zvision/core/console.h | 4 | ||||
-rw-r--r-- | engines/zvision/core/events.cpp | 150 | ||||
-rw-r--r-- | engines/zvision/core/menu.cpp | 765 | ||||
-rw-r--r-- | engines/zvision/core/menu.h | 125 | ||||
-rw-r--r-- | engines/zvision/core/save_manager.cpp | 295 | ||||
-rw-r--r-- | engines/zvision/core/save_manager.h | 106 |
8 files changed, 262 insertions, 1352 deletions
diff --git a/engines/zvision/core/clock.h b/engines/zvision/core/clock.h index cbf52be560..ae8c968111 100644 --- a/engines/zvision/core/clock.h +++ b/engines/zvision/core/clock.h @@ -67,14 +67,14 @@ public: } /** - * Pause the clock. Any future delta times will take this pause into account. - * Has no effect if the clock is already paused. - */ + * Un-pause the clock. + * Has no effect if the clock is already un-paused. + */ void start(); /** - * Un-pause the clock. - * Has no effect if the clock is already un-paused. + * Pause the clock. Any future delta times will take this pause into account. + * Has no effect if the clock is already paused. */ void stop(); }; diff --git a/engines/zvision/core/console.cpp b/engines/zvision/core/console.cpp index 4dd10d6f40..336541d82a 100644 --- a/engines/zvision/core/console.cpp +++ b/engines/zvision/core/console.cpp @@ -52,6 +52,10 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { registerCmd("setpanoramascale", WRAP_METHOD(Console, cmdSetPanoramaScale)); registerCmd("location", WRAP_METHOD(Console, cmdLocation)); registerCmd("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); + registerCmd("dumpfiles", WRAP_METHOD(Console, cmdDumpFiles)); + registerCmd("dumpimage", WRAP_METHOD(Console, cmdDumpImage)); + registerCmd("statevalue", WRAP_METHOD(Console, cmdStateValue)); + registerCmd("stateflag", WRAP_METHOD(Console, cmdStateFlag)); } bool Console::cmdLoadVideo(int argc, const char **argv) { @@ -78,12 +82,14 @@ bool Console::cmdLoadSound(int argc, const char **argv) { Audio::AudioStream *soundStream = makeRawZorkStream(argv[1], _engine); Audio::SoundHandle handle; _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); - } else if (argc == 4) { int isStereo = atoi(argv[3]); Common::File *file = new Common::File(); - file->open(argv[1]); + if (!_engine->getSearchManager()->openFile(*file, argv[1])) { + warning("File not found: %s", argv[1]); + return true; + } Audio::AudioStream *soundStream = makeRawZorkStream(file, atoi(argv[2]), isStereo == 0 ? false : true); Audio::SoundHandle handle; @@ -103,8 +109,10 @@ bool Console::cmdRawToWav(int argc, const char **argv) { } Common::File file; - if (!file.open(argv[1])) + if (!_engine->getSearchManager()->openFile(file, argv[1])) { + warning("File not found: %s", argv[1]); return true; + } Audio::AudioStream *audioStream = makeRawZorkStream(argv[1], _engine); @@ -133,6 +141,10 @@ bool Console::cmdRawToWav(int argc, const char **argv) { output.writeUint32LE(file.size() * 2); int16 *buffer = new int16[file.size()]; audioStream->readBuffer(buffer, file.size()); +#ifndef SCUMM_LITTLE_ENDIAN + for (int i = 0; i < file.size(); ++i) + buffer[i] = TO_LE_16(buffer[i]); +#endif output.write(buffer, file.size() * 2); delete[] buffer; @@ -194,7 +206,7 @@ bool Console::cmdLocation(int argc, const char **argv) { Common::String scrFile = Common::String::format("%c%c%c%c.scr", curLocation.world, curLocation.room, curLocation.node, curLocation.view); debugPrintf("Current location: world '%c', room '%c', node '%c', view '%c', offset %d, script %s\n", curLocation.world, curLocation.room, curLocation.node, curLocation.view, curLocation.offset, scrFile.c_str()); - + if (argc != 6) { debugPrintf("Use %s <char: world> <char: room> <char:node> <char:view> <int: x offset> to change your location\n", argv[0]); return true; @@ -205,6 +217,20 @@ bool Console::cmdLocation(int argc, const char **argv) { return true; } +void dumpFile(Common::SeekableReadStream *s, const char *outName) { + byte *buffer = new byte[s->size()]; + s->read(buffer, s->size()); + + Common::DumpFile dumpFile; + dumpFile.open(outName); + + dumpFile.write(buffer, s->size()); + dumpFile.flush(); + dumpFile.close(); + + delete[] buffer; +} + bool Console::cmdDumpFile(int argc, const char **argv) { if (argc != 2) { debugPrintf("Use %s <fileName> to dump a file\n", argv[0]); @@ -217,17 +243,126 @@ bool Console::cmdDumpFile(int argc, const char **argv) { return true; } - byte *buffer = new byte[f.size()]; - f.read(buffer, f.size()); + dumpFile(&f, argv[1]); - Common::DumpFile dumpFile; - dumpFile.open(argv[1]); + return true; +} - dumpFile.write(buffer, f.size()); - dumpFile.flush(); - dumpFile.close(); +bool Console::cmdDumpFiles(int argc, const char **argv) { + Common::String fileName; + Common::SeekableReadStream *in; - delete[] buffer; + if (argc != 2) { + debugPrintf("Use %s <file extension> to dump all files with a specific extension\n", argv[0]); + return true; + } + + SearchManager::MatchList fileList; + _engine->getSearchManager()->listMembersWithExtension(fileList, argv[1]); + + for (SearchManager::MatchList::iterator iter = fileList.begin(); iter != fileList.end(); ++iter) { + fileName = iter->_value.name; + debugPrintf("Dumping %s\n", fileName.c_str()); + + in = iter->_value.arch->createReadStreamForMember(iter->_value.name); + if (in) + dumpFile(in, fileName.c_str()); + delete in; + } + + return true; +} + +bool Console::cmdDumpImage(int argc, const char **argv) { + if (argc != 2) { + debugPrintf("Use %s <TGA/TGZ name> to dump a Z-Vision TGA/TGZ image into a regular BMP image\n", argv[0]); + return true; + } + + Common::String fileName = argv[1]; + if (!fileName.hasSuffix(".tga")) { + debugPrintf("%s is not an image file", argv[1]); + } + + Common::File f; + if (!_engine->getSearchManager()->openFile(f, argv[1])) { + warning("File not found: %s", argv[1]); + return true; + } + + Graphics::Surface surface; + _engine->getRenderManager()->readImageToSurface(argv[1], surface, false); + + // Open file + Common::DumpFile out; + + fileName.setChar('b', fileName.size() - 3); + fileName.setChar('m', fileName.size() - 2); + fileName.setChar('p', fileName.size() - 1); + + out.open(fileName); + + // Write BMP header + out.writeByte('B'); + out.writeByte('M'); + out.writeUint32LE(surface.h * surface.pitch + 54); + out.writeUint32LE(0); + out.writeUint32LE(54); + out.writeUint32LE(40); + out.writeUint32LE(surface.w); + out.writeUint32LE(surface.h); + out.writeUint16LE(1); + out.writeUint16LE(16); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + + // Write pixel data to BMP + out.write(surface.getPixels(), surface.pitch * surface.h); + + out.flush(); + out.close(); + + surface.free(); + + return true; +} + +bool Console::cmdStateValue(int argc, const char **argv) { + if (argc < 2) { + debugPrintf("Use %s <valuenum> to show the value of a state variable\n", argv[0]); + debugPrintf("Use %s <valuenum> <newvalue> to set the value of a state variable\n", argv[0]); + return true; + } + + int valueNum = atoi(argv[1]); + int newValue = (argc > 2) ? atoi(argv[2]) : -1; + + if (argc == 2) + debugPrintf("[%d] = %d\n", valueNum, _engine->getScriptManager()->getStateValue(valueNum)); + else if (argc == 3) + _engine->getScriptManager()->setStateValue(valueNum, newValue); + + return true; +} + +bool Console::cmdStateFlag(int argc, const char **argv) { + if (argc < 2) { + debugPrintf("Use %s <flagnum> to show the value of a state flag\n", argv[0]); + debugPrintf("Use %s <flagnum> <newvalue> to set the value of a state flag\n", argv[0]); + return true; + } + + int valueNum = atoi(argv[1]); + int newValue = (argc > 2) ? atoi(argv[2]) : -1; + + if (argc == 2) + debugPrintf("[%d] = %d\n", valueNum, _engine->getScriptManager()->getStateFlag(valueNum)); + else if (argc == 3) + _engine->getScriptManager()->setStateFlag(valueNum, newValue); return true; } diff --git a/engines/zvision/core/console.h b/engines/zvision/core/console.h index 299bd6127f..ac834185a0 100644 --- a/engines/zvision/core/console.h +++ b/engines/zvision/core/console.h @@ -46,6 +46,10 @@ private: bool cmdSetPanoramaScale(int argc, const char **argv); bool cmdLocation(int argc, const char **argv); bool cmdDumpFile(int argc, const char **argv); + bool cmdDumpFiles(int argc, const char **argv); + bool cmdDumpImage(int argc, const char **argv); + bool cmdStateValue(int argc, const char **argv); + bool cmdStateFlag(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/core/events.cpp b/engines/zvision/core/events.cpp index c66e61a61a..cc1c00b6d0 100644 --- a/engines/zvision/core/events.cpp +++ b/engines/zvision/core/events.cpp @@ -28,8 +28,9 @@ #include "zvision/graphics/cursors/cursor_manager.h" #include "zvision/graphics/render_manager.h" #include "zvision/scripting/script_manager.h" -#include "zvision/core/menu.h" +#include "zvision/scripting/menu.h" #include "zvision/sound/zork_raw.h" +#include "zvision/text/string_manager.h" #include "common/events.h" #include "common/system.h" @@ -39,23 +40,50 @@ namespace ZVision { +void ZVision::pushKeyToCheatBuf(uint8 key) { + for (int i = 0; i < KEYBUF_SIZE - 1; i++) + _cheatBuffer[i] = _cheatBuffer[i + 1]; + + _cheatBuffer[KEYBUF_SIZE - 1] = key; +} + +bool ZVision::checkCode(const char *code) { + int codeLen = strlen(code); + + if (codeLen > KEYBUF_SIZE) + return false; + + for (int i = 0; i < codeLen; i++) + if (code[i] != _cheatBuffer[KEYBUF_SIZE - codeLen + i] && code[i] != '?') + return false; + + return true; +} + +uint8 ZVision::getBufferedKey(uint8 pos) { + if (pos >= KEYBUF_SIZE) + return 0; + else + return _cheatBuffer[KEYBUF_SIZE - pos - 1]; +} + void ZVision::shortKeys(Common::Event event) { if (event.kbd.hasFlags(Common::KBD_CTRL)) { switch (event.kbd.keycode) { case Common::KEYCODE_s: - if (getMenuBarEnable() & menuBar_Save) + if (_menu->getEnable() & kMenubarSave) _scriptManager->changeLocation('g', 'j', 's', 'e', 0); break; case Common::KEYCODE_r: - if (getMenuBarEnable() & menuBar_Restore) + if (_menu->getEnable() & kMenubarRestore) _scriptManager->changeLocation('g', 'j', 'r', 'e', 0); break; case Common::KEYCODE_p: - if (getMenuBarEnable() & menuBar_Settings) + if (_menu->getEnable() & kMenubarSettings) _scriptManager->changeLocation('g', 'j', 'p', 'e', 0); break; case Common::KEYCODE_q: - if (getMenuBarEnable() & menuBar_Exit) + if (_menu->getEnable() & kMenubarExit) ifQuit(); break; default: @@ -65,16 +93,21 @@ void ZVision::shortKeys(Common::Event event) { } void ZVision::cheatCodes(uint8 key) { + Location loc = _scriptManager->getCurrentLocation(); + // Do not process cheat codes while in the game menus + if (loc.world == 'g' && loc.room == 'j') + return; + pushKeyToCheatBuf(key); if (getGameId() == GID_GRANDINQUISITOR) { if (checkCode("IMNOTDEAF")) { // Unknown cheat - showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented")); + _renderManager->showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented")); } if (checkCode("3100OPB")) { - showDebugMsg(Common::String::format("Current location: %c%c%c%c", + _renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c", _scriptManager->getStateValue(StateKey_World), _scriptManager->getStateValue(StateKey_Room), _scriptManager->getStateValue(StateKey_Node), @@ -91,9 +124,9 @@ void ZVision::cheatCodes(uint8 key) { } // There are 3 more cheats in script files: - // - "EAT ME": gjcr.scr - // - "WHOAMI": hp1e.scr - // - "HUISOK": uh1f.scr + // - "WHOAMI": gjcr.scr + // - "HUISOK": hp1e.scr + // - "EAT ME": uh1f.scr } else if (getGameId() == GID_NEMESIS) { if (checkCode("CHLOE")) { _scriptManager->changeLocation('t', 'm', '2', 'g', 0); @@ -101,7 +134,7 @@ void ZVision::cheatCodes(uint8 key) { } if (checkCode("77MASSAVE")) { - showDebugMsg(Common::String::format("Current location: %c%c%c%c", + _renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c", _scriptManager->getStateValue(StateKey_World), _scriptManager->getStateValue(StateKey_Room), _scriptManager->getStateValue(StateKey_Node), @@ -118,9 +151,8 @@ void ZVision::cheatCodes(uint8 key) { } if (checkCode("HELLOSAILOR")) { - Location loc = _scriptManager->getCurrentLocation(); Audio::AudioStream *soundStream; - if (loc.world == 'v' && loc.room == 'b' && loc.node == '1' && loc.view == '0') { + if (loc == "vb10") { soundStream = makeRawZorkStream("v000hpta.raw", this); } else { soundStream = makeRawZorkStream("v000hnta.raw", this); @@ -130,21 +162,29 @@ void ZVision::cheatCodes(uint8 key) { } } - if (checkCode("FRAME")) - showDebugMsg(Common::String::format("FPS: ???, not implemented")); + if (checkCode("FRAME")) { + Common::String fpsStr = Common::String::format("FPS: %d", getFPS()); + _renderManager->showDebugMsg(fpsStr); + } + + if (checkCode("COMPUTERARCH")) + _renderManager->showDebugMsg("COMPUTERARCH: var-viewer not implemented"); + // This cheat essentially toggles the GOxxxx cheat below if (checkCode("XYZZY")) _scriptManager->setStateValue(StateKey_DebugCheats, 1 - _scriptManager->getStateValue(StateKey_DebugCheats)); - if (checkCode("COMPUTERARCH")) - showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented")); - if (_scriptManager->getStateValue(StateKey_DebugCheats) == 1) if (checkCode("GO????")) _scriptManager->changeLocation(getBufferedKey(3), getBufferedKey(2), getBufferedKey(1), getBufferedKey(0), 0); + + // Show the Venus screen when "?" or "/" is pressed while inside the temple world + if (_scriptManager->getStateValue(StateKey_VenusEnable) == 1) + if (getBufferedKey(0) == 0xBF && _scriptManager->getStateValue(StateKey_World) == 't') + _scriptManager->changeLocation('g', 'j', 'h', 'e', 0); } void ZVision::processEvents() { @@ -194,19 +234,24 @@ void ZVision::processEvents() { case Common::KEYCODE_LEFT: case Common::KEYCODE_RIGHT: if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA) - _kbdVelocity = (_event.kbd.keycode == Common::KEYCODE_LEFT ? - -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) : - _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2; + _keyboardVelocity = (_event.kbd.keycode == Common::KEYCODE_LEFT ? + -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) : + _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2; break; case Common::KEYCODE_UP: case Common::KEYCODE_DOWN: if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT) - _kbdVelocity = (_event.kbd.keycode == Common::KEYCODE_UP ? - -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) : - _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2; + _keyboardVelocity = (_event.kbd.keycode == Common::KEYCODE_UP ? + -_scriptManager->getStateValue(StateKey_KbdRotateSpeed) : + _scriptManager->getStateValue(StateKey_KbdRotateSpeed)) * 2; break; + case Common::KEYCODE_F10: { + Common::String fpsStr = Common::String::format("FPS: %d", getFPS()); + _renderManager->showDebugMsg(fpsStr); + } + break; default: break; } @@ -226,12 +271,12 @@ void ZVision::processEvents() { case Common::KEYCODE_LEFT: case Common::KEYCODE_RIGHT: if (_renderManager->getRenderTable()->getRenderState() == RenderTable::PANORAMA) - _kbdVelocity = 0; + _keyboardVelocity = 0; break; case Common::KEYCODE_UP: case Common::KEYCODE_DOWN: if (_renderManager->getRenderTable()->getRenderState() == RenderTable::TILT) - _kbdVelocity = 0; + _keyboardVelocity = 0; break; default: break; @@ -279,26 +324,33 @@ void ZVision::onMouseMove(const Common::Point &pos) { // | // ^ - if (_workingWindow.contains(pos)) { - cursorWasChanged = _scriptManager->onMouseMove(pos, imageCoord); + // Clip the horizontal mouse position to the working window + Common::Point clippedPos = pos; + clippedPos.x = CLIP<int16>(pos.x, _workingWindow.left + 1, _workingWindow.right - 1); + + if (_workingWindow.contains(clippedPos)) { + cursorWasChanged = _scriptManager->onMouseMove(clippedPos, imageCoord); RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState(); if (renderState == RenderTable::PANORAMA) { - if (pos.x >= _workingWindow.left && pos.x < _workingWindow.left + ROTATION_SCREEN_EDGE_OFFSET) { + if (clippedPos.x >= _workingWindow.left && clippedPos.x < _workingWindow.left + ROTATION_SCREEN_EDGE_OFFSET) { int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4; - if (mspeed <= 0) - mspeed = 400 >> 4; - _mouseVelocity = (((pos.x - (ROTATION_SCREEN_EDGE_OFFSET + _workingWindow.left)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7; + if (mspeed <= 0) { + mspeed = 25; + } + _mouseVelocity = MIN(((Common::Rational(mspeed, ROTATION_SCREEN_EDGE_OFFSET) * (clippedPos.x - _workingWindow.left)) - mspeed).toInt(), -1); + _cursorManager->changeCursor(CursorIndex_Left); cursorWasChanged = true; - } else if (pos.x <= _workingWindow.right && pos.x > _workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET) { + } else if (clippedPos.x <= _workingWindow.right && clippedPos.x > _workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET) { int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4; - if (mspeed <= 0) - mspeed = 400 >> 4; - _mouseVelocity = (((pos.x - (_workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7; + if (mspeed <= 0) { + mspeed = 25; + } + _mouseVelocity = MAX((Common::Rational(mspeed, ROTATION_SCREEN_EDGE_OFFSET) * (clippedPos.x - _workingWindow.right + ROTATION_SCREEN_EDGE_OFFSET)).toInt(), 1); _cursorManager->changeCursor(CursorIndex_Right); cursorWasChanged = true; @@ -306,21 +358,23 @@ void ZVision::onMouseMove(const Common::Point &pos) { _mouseVelocity = 0; } } else if (renderState == RenderTable::TILT) { - if (pos.y >= _workingWindow.top && pos.y < _workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET) { + if (clippedPos.y >= _workingWindow.top && clippedPos.y < _workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET) { int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4; - if (mspeed <= 0) - mspeed = 400 >> 4; - _mouseVelocity = (((pos.y - (_workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7; + if (mspeed <= 0) { + mspeed = 25; + } + _mouseVelocity = MIN(((Common::Rational(mspeed, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.top)) - mspeed).toInt(), -1); _cursorManager->changeCursor(CursorIndex_UpArr); cursorWasChanged = true; - } else if (pos.y <= _workingWindow.bottom && pos.y > _workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET) { + } else if (clippedPos.y <= _workingWindow.bottom && clippedPos.y > _workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET) { int16 mspeed = _scriptManager->getStateValue(StateKey_RotateSpeed) >> 4; - if (mspeed <= 0) - mspeed = 400 >> 4; - _mouseVelocity = (((pos.y - (_workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET)) << 7) / ROTATION_SCREEN_EDGE_OFFSET * mspeed) >> 7; + if (mspeed <= 0) { + mspeed = 25; + } + _mouseVelocity = MAX((Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.bottom + ROTATION_SCREEN_EDGE_OFFSET)).toInt(), 1); _cursorManager->changeCursor(CursorIndex_DownArr); cursorWasChanged = true; @@ -441,4 +495,12 @@ uint8 ZVision::getZvisionKey(Common::KeyCode scummKeyCode) { return 0; } +bool ZVision::ifQuit() { + if (_renderManager->askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) { + quitGame(); + return true; + } + return false; +} + } // End of namespace ZVision diff --git a/engines/zvision/core/menu.cpp b/engines/zvision/core/menu.cpp deleted file mode 100644 index 31e0d71370..0000000000 --- a/engines/zvision/core/menu.cpp +++ /dev/null @@ -1,765 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" - -#include "zvision/core/menu.h" - -#include "zvision/graphics/render_manager.h" - -namespace ZVision { - -enum { - SLOT_START_SLOT = 151, - SLOT_SPELL_1 = 191, - SLOT_USER_CHOSE_THIS_SPELL = 205, - SLOT_REVERSED_SPELLBOOK = 206 -}; - -enum { - menu_MAIN_SAVE = 0, - menu_MAIN_REST = 1, - menu_MAIN_PREF = 2, - menu_MAIN_EXIT = 3 -}; - -MenuHandler::MenuHandler(ZVision *engine) { - _engine = engine; - menuBarFlag = 0xFFFF; -} - -MenuZGI::MenuZGI(ZVision *engine) : - MenuHandler(engine) { - menuMouseFocus = -1; - inmenu = false; - scrolled[0] = false; - scrolled[1] = false; - scrolled[2] = false; - scrollPos[0] = 0.0; - scrollPos[1] = 0.0; - scrollPos[2] = 0.0; - mouseOnItem = -1; - redraw = false; - clean = false; - - char buf[24]; - for (int i = 1; i < 4; i++) { - sprintf(buf, "gmzau%2.2x1.tga", i); - _engine->getRenderManager()->readImageToSurface(buf, menuback[i - 1][0], false); - sprintf(buf, "gmzau%2.2x1.tga", i + 0x10); - _engine->getRenderManager()->readImageToSurface(buf, menuback[i - 1][1], false); - } - for (int i = 0; i < 4; i++) { - sprintf(buf, "gmzmu%2.2x1.tga", i); - _engine->getRenderManager()->readImageToSurface(buf, menubar[i][0], false); - sprintf(buf, "gmznu%2.2x1.tga", i); - _engine->getRenderManager()->readImageToSurface(buf, menubar[i][1], false); - } - - for (int i = 0; i < 50; i++) { - items[i][0] = NULL; - items[i][1] = NULL; - itemId[i] = 0; - } - - for (int i = 0; i < 12; i++) { - magic[i][0] = NULL; - magic[i][1] = NULL; - magicId[i] = 0; - } -} - -MenuZGI::~MenuZGI() { - for (int i = 0; i < 3; i++) { - menuback[i][0].free(); - menuback[i][1].free(); - } - for (int i = 0; i < 4; i++) { - menubar[i][0].free(); - menubar[i][1].free(); - } - for (int i = 0; i < 50; i++) { - if (items[i][0]) { - items[i][0]->free(); - delete items[i][0]; - } - if (items[i][1]) { - items[i][1]->free(); - delete items[i][1]; - } - } - for (int i = 0; i < 12; i++) { - if (magic[i][0]) { - magic[i][0]->free(); - delete magic[i][0]; - } - if (magic[i][1]) { - magic[i][1]->free(); - delete magic[i][1]; - } - } -} - -void MenuZGI::onMouseUp(const Common::Point &Pos) { - if (Pos.y < 40) { - switch (menuMouseFocus) { - case menu_ITEM: - if (menuBarFlag & menuBar_Items) { - int itemCount = _engine->getScriptManager()->getStateValue(StateKey_Inv_TotalSlots); - if (itemCount == 0) - itemCount = 20; - - for (int i = 0; i < itemCount; i++) { - int itemspace = (600 - 28) / itemCount; - - if (Common::Rect(scrollPos[menu_ITEM] + itemspace * i, 0, - scrollPos[menu_ITEM] + itemspace * i + 28, 32).contains(Pos)) { - int32 mouseItem = _engine->getScriptManager()->getStateValue(StateKey_InventoryItem); - if (mouseItem >= 0 && mouseItem < 0xE0) { - _engine->getScriptManager()->inventoryDrop(mouseItem); - _engine->getScriptManager()->inventoryAdd(_engine->getScriptManager()->getStateValue(SLOT_START_SLOT + i)); - _engine->getScriptManager()->setStateValue(SLOT_START_SLOT + i, mouseItem); - - redraw = true; - } - } - } - } - break; - - case menu_MAGIC: - if (menuBarFlag & menuBar_Magic) { - for (int i = 0; i < 12; i++) { - - uint itemnum = _engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + i); - if (itemnum != 0) { - if (_engine->getScriptManager()->getStateValue(SLOT_REVERSED_SPELLBOOK) == 1) - itemnum = 0xEE + i; - else - itemnum = 0xE0 + i; - } - if (itemnum) - if (_engine->getScriptManager()->getStateValue(StateKey_InventoryItem) == 0 || _engine->getScriptManager()->getStateValue(StateKey_InventoryItem) >= 0xE0) - if (Common::Rect(668 + 47 * i - scrollPos[menu_MAGIC], 0, - 668 + 47 * i - scrollPos[menu_MAGIC] + 28, 32).contains(Pos)) - _engine->getScriptManager()->setStateValue(SLOT_USER_CHOSE_THIS_SPELL, itemnum); - } - - } - break; - - case menu_MAIN: - - // Exit - if (menuBarFlag & menuBar_Exit) - if (Common::Rect(320 + 135, - scrollPos[menu_MAIN], - 320 + 135 + 135, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - _engine->ifQuit(); - } - - // Settings - if (menuBarFlag & menuBar_Settings) - if (Common::Rect(320 , - scrollPos[menu_MAIN], - 320 + 135, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - _engine->getScriptManager()->changeLocation('g', 'j', 'p', 'e', 0); - } - - // Load - if (menuBarFlag & menuBar_Restore) - if (Common::Rect(320 - 135, - scrollPos[menu_MAIN], - 320, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - _engine->getScriptManager()->changeLocation('g', 'j', 'r', 'e', 0); - } - - // Save - if (menuBarFlag & menuBar_Save) - if (Common::Rect(320 - 135 * 2, - scrollPos[menu_MAIN], - 320 - 135, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - _engine->getScriptManager()->changeLocation('g', 'j', 's', 'e', 0); - } - break; - } - } -} - -void MenuZGI::onMouseMove(const Common::Point &Pos) { - if (Pos.y < 40) { - - if (!inmenu) - redraw = true; - inmenu = true; - switch (menuMouseFocus) { - case menu_ITEM: - if (menuBarFlag & menuBar_Items) { - int itemCount = _engine->getScriptManager()->getStateValue(StateKey_Inv_TotalSlots); - if (itemCount == 0) - itemCount = 20; - else if (itemCount > 50) - itemCount = 50; - - int lastItem = mouseOnItem; - - mouseOnItem = -1; - - for (int i = 0; i < itemCount; i++) { - int itemspace = (600 - 28) / itemCount; - - if (Common::Rect(scrollPos[menu_ITEM] + itemspace * i, 0, - scrollPos[menu_ITEM] + itemspace * i + 28, 32).contains(Pos)) { - mouseOnItem = i; - break; - } - } - - if (lastItem != mouseOnItem) - if (_engine->getScriptManager()->getStateValue(SLOT_START_SLOT + mouseOnItem) || - _engine->getScriptManager()->getStateValue(SLOT_START_SLOT + lastItem)) - redraw = true; - } - break; - - case menu_MAGIC: - if (menuBarFlag & menuBar_Magic) { - int lastItem = mouseOnItem; - mouseOnItem = -1; - for (int i = 0; i < 12; i++) { - if (Common::Rect(668 + 47 * i - scrollPos[menu_MAGIC], 0, - 668 + 47 * i - scrollPos[menu_MAGIC] + 28, 32).contains(Pos)) { - mouseOnItem = i; - break; - } - } - - if (lastItem != mouseOnItem) - if (_engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + mouseOnItem) || - _engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + lastItem)) - redraw = true; - - } - break; - - case menu_MAIN: { - int lastItem = mouseOnItem; - mouseOnItem = -1; - - // Exit - if (menuBarFlag & menuBar_Exit) - if (Common::Rect(320 + 135, - scrollPos[menu_MAIN], - 320 + 135 + 135, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_EXIT; - } - - // Settings - if (menuBarFlag & menuBar_Settings) - if (Common::Rect(320 , - scrollPos[menu_MAIN], - 320 + 135, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_PREF; - } - - // Load - if (menuBarFlag & menuBar_Restore) - if (Common::Rect(320 - 135, - scrollPos[menu_MAIN], - 320, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_REST; - } - - // Save - if (menuBarFlag & menuBar_Save) - if (Common::Rect(320 - 135 * 2, - scrollPos[menu_MAIN], - 320 - 135, - scrollPos[menu_MAIN] + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_SAVE; - } - - if (lastItem != mouseOnItem) - redraw = true; - } - break; - - default: - int cur_menu = menuMouseFocus; - if (Common::Rect(64, 0, 64 + 512, 8).contains(Pos)) { // Main - menuMouseFocus = menu_MAIN; - scrolled[menu_MAIN] = false; - scrollPos[menu_MAIN] = menuback[menu_MAIN][1].h - menuback[menu_MAIN][0].h; - _engine->getScriptManager()->setStateValue(StateKey_MenuState, 2); - } - - if (menuBarFlag & menuBar_Magic) - if (Common::Rect(640 - 28, 0, 640, 32).contains(Pos)) { // Magic - menuMouseFocus = menu_MAGIC; - scrolled[menu_MAGIC] = false; - scrollPos[menu_MAGIC] = 28; - _engine->getScriptManager()->setStateValue(StateKey_MenuState, 3); - } - - if (menuBarFlag & menuBar_Items) - if (Common::Rect(0, 0, 28, 32).contains(Pos)) { // Items - menuMouseFocus = menu_ITEM; - scrolled[menu_ITEM] = false; - scrollPos[menu_ITEM] = 28 - 600; - _engine->getScriptManager()->setStateValue(StateKey_MenuState, 1); - } - - if (cur_menu != menuMouseFocus) - clean = true; - - break; - } - } else { - if (inmenu) - clean = true; - inmenu = false; - if (_engine->getScriptManager()->getStateValue(StateKey_MenuState) != 0) - _engine->getScriptManager()->setStateValue(StateKey_MenuState, 0); - menuMouseFocus = -1; - } -} - -void MenuZGI::process(uint32 deltatime) { - if (clean) { - _engine->getRenderManager()->clearMenuSurface(); - clean = false; - } - switch (menuMouseFocus) { - case menu_ITEM: - if (menuBarFlag & menuBar_Items) - if (!scrolled[menu_ITEM]) { - redraw = true; - float scrl = 600.0 * (deltatime / 1000.0); - - if (scrl == 0) - scrl = 1.0; - - scrollPos [menu_ITEM] += scrl; - - if (scrollPos[menu_ITEM] >= 0) { - scrolled[menu_ITEM] = true; - scrollPos [menu_ITEM] = 0; - } - } - if (redraw) { - _engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_ITEM][0], scrollPos[menu_ITEM], 0); - - int itemCount = _engine->getScriptManager()->getStateValue(StateKey_Inv_TotalSlots); - if (itemCount == 0) - itemCount = 20; - else if (itemCount > 50) - itemCount = 50; - - for (int i = 0; i < itemCount; i++) { - int itemspace = (600 - 28) / itemCount; - - bool inrect = false; - - if (mouseOnItem == i) - inrect = true; - - uint curItemId = _engine->getScriptManager()->getStateValue(SLOT_START_SLOT + i); - - if (curItemId != 0) { - if (itemId[i] != curItemId) { - char buf[16]; - sprintf(buf, "gmzwu%2.2x1.tga", curItemId); - items[i][0] = _engine->getRenderManager()->loadImage(buf, false); - sprintf(buf, "gmzxu%2.2x1.tga", curItemId); - items[i][1] = _engine->getRenderManager()->loadImage(buf, false); - itemId[i] = curItemId; - } - - if (inrect) - _engine->getRenderManager()->blitSurfaceToMenu(*items[i][1], scrollPos[menu_ITEM] + itemspace * i, 0, 0); - else - _engine->getRenderManager()->blitSurfaceToMenu(*items[i][0], scrollPos[menu_ITEM] + itemspace * i, 0, 0); - - } else { - if (items[i][0]) { - items[i][0]->free(); - delete items[i][0]; - items[i][0] = NULL; - } - if (items[i][1]) { - items[i][1]->free(); - delete items[i][1]; - items[i][1] = NULL; - } - itemId[i] = 0; - } - } - - redraw = false; - } - break; - - case menu_MAGIC: - if (menuBarFlag & menuBar_Magic) - if (!scrolled[menu_MAGIC]) { - redraw = true; - float scrl = 600.0 * (deltatime / 1000.0); - - if (scrl == 0) - scrl = 1.0; - - scrollPos [menu_MAGIC] += scrl; - - if (scrollPos[menu_MAGIC] >= 600) { - scrolled[menu_MAGIC] = true; - scrollPos [menu_MAGIC] = 600; - } - } - if (redraw) { - _engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAGIC][0], 640 - scrollPos[menu_MAGIC], 0); - - for (int i = 0; i < 12; i++) { - bool inrect = false; - - if (mouseOnItem == i) - inrect = true; - - uint curItemId = _engine->getScriptManager()->getStateValue(SLOT_SPELL_1 + i); - if (curItemId) { - if (_engine->getScriptManager()->getStateValue(SLOT_REVERSED_SPELLBOOK) == 1) - curItemId = 0xEE + i; - else - curItemId = 0xE0 + i; - } - - if (curItemId != 0) { - if (itemId[i] != curItemId) { - char buf[16]; - sprintf(buf, "gmzwu%2.2x1.tga", curItemId); - magic[i][0] = _engine->getRenderManager()->loadImage(buf, false); - sprintf(buf, "gmzxu%2.2x1.tga", curItemId); - magic[i][1] = _engine->getRenderManager()->loadImage(buf, false); - magicId[i] = curItemId; - } - - if (inrect) - _engine->getRenderManager()->blitSurfaceToMenu(*magic[i][1], 668 + 47 * i - scrollPos[menu_MAGIC], 0, 0); - else - _engine->getRenderManager()->blitSurfaceToMenu(*magic[i][0], 668 + 47 * i - scrollPos[menu_MAGIC], 0, 0); - - } else { - if (magic[i][0]) { - magic[i][0]->free(); - delete magic[i][0]; - magic[i][0] = NULL; - } - if (magic[i][1]) { - magic[i][1]->free(); - delete magic[i][1]; - magic[i][1] = NULL; - } - magicId[i] = 0; - } - } - redraw = false; - } - break; - - case menu_MAIN: - if (!scrolled[menu_MAIN]) { - redraw = true; - float scrl = 32.0 * 2.0 * (deltatime / 1000.0); - - if (scrl == 0) - scrl = 1.0; - - scrollPos [menu_MAIN] += scrl; - - if (scrollPos[menu_MAIN] >= 0) { - scrolled[menu_MAIN] = true; - scrollPos [menu_MAIN] = 0; - } - } - if (redraw) { - _engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAIN][0], 30, scrollPos[menu_MAIN]); - - if (menuBarFlag & menuBar_Exit) { - if (mouseOnItem == menu_MAIN_EXIT) - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_EXIT][1], 320 + 135, scrollPos[menu_MAIN]); - else - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_EXIT][0], 320 + 135, scrollPos[menu_MAIN]); - } - if (menuBarFlag & menuBar_Settings) { - if (mouseOnItem == menu_MAIN_PREF) - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_PREF][1], 320, scrollPos[menu_MAIN]); - else - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_PREF][0], 320, scrollPos[menu_MAIN]); - } - if (menuBarFlag & menuBar_Restore) { - if (mouseOnItem == menu_MAIN_REST) - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_REST][1], 320 - 135, scrollPos[menu_MAIN]); - else - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_REST][0], 320 - 135, scrollPos[menu_MAIN]); - } - if (menuBarFlag & menuBar_Save) { - if (mouseOnItem == menu_MAIN_SAVE) - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_SAVE][1], 320 - 135 * 2, scrollPos[menu_MAIN]); - else - _engine->getRenderManager()->blitSurfaceToMenu(menubar[menu_MAIN_SAVE][0], 320 - 135 * 2, scrollPos[menu_MAIN]); - } - redraw = false; - } - break; - default: - if (redraw) { - if (inmenu) { - _engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAIN][1], 30, 0); - - if (menuBarFlag & menuBar_Items) - _engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_ITEM][1], 0, 0); - - if (menuBarFlag & menuBar_Magic) - _engine->getRenderManager()->blitSurfaceToMenu(menuback[menu_MAGIC][1], 640 - 28, 0); - } - redraw = false; - } - break; - } -} - -MenuNemesis::MenuNemesis(ZVision *engine) : - MenuHandler(engine) { - inmenu = false; - scrolled = false; - scrollPos = 0.0; - mouseOnItem = -1; - redraw = false; - delay = 0; - - char buf[24]; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 6; j++) { - sprintf(buf, "butfrm%d%d.tga", i + 1, j); - _engine->getRenderManager()->readImageToSurface(buf, but[i][j], false); - } - - _engine->getRenderManager()->readImageToSurface("bar.tga", menubar, false); - - frm = 0; -} - -MenuNemesis::~MenuNemesis() { - for (int i = 0; i < 4; i++) - for (int j = 0; j < 6; j++) - but[i][j].free(); - - menubar.free(); -} - -static const int16 buts[4][2] = { {120 , 64}, {144, 184}, {128, 328}, {120, 456} }; - -void MenuNemesis::onMouseUp(const Common::Point &Pos) { - if (Pos.y < 40) { - // Exit - if (menuBarFlag & menuBar_Exit) - if (Common::Rect(buts[3][1], - scrollPos, - buts[3][0] + buts[3][1], - scrollPos + 32).contains(Pos)) { - _engine->ifQuit(); - frm = 5; - redraw = true; - } - - // Settings - if (menuBarFlag & menuBar_Settings) - if (Common::Rect(buts[2][1], - scrollPos, - buts[2][0] + buts[2][1], - scrollPos + 32).contains(Pos)) { - _engine->getScriptManager()->changeLocation('g', 'j', 'p', 'e', 0); - frm = 5; - redraw = true; - } - - // Load - if (menuBarFlag & menuBar_Restore) - if (Common::Rect(buts[1][1], - scrollPos, - buts[1][0] + buts[1][1], - scrollPos + 32).contains(Pos)) { - _engine->getScriptManager()->changeLocation('g', 'j', 'r', 'e', 0); - frm = 5; - redraw = true; - } - - // Save - if (menuBarFlag & menuBar_Save) - if (Common::Rect(buts[0][1], - scrollPos, - buts[0][0] + buts[0][1], - scrollPos + 32).contains(Pos)) { - _engine->getScriptManager()->changeLocation('g', 'j', 's', 'e', 0); - frm = 5; - redraw = true; - } - } -} - -void MenuNemesis::onMouseMove(const Common::Point &Pos) { - if (Pos.y < 40) { - - inmenu = true; - - if (_engine->getScriptManager()->getStateValue(StateKey_MenuState) != 2) - _engine->getScriptManager()->setStateValue(StateKey_MenuState, 2); - - int lastItem = mouseOnItem; - mouseOnItem = -1; - - // Exit - if (menuBarFlag & menuBar_Exit) - if (Common::Rect(buts[3][1], - scrollPos, - buts[3][0] + buts[3][1], - scrollPos + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_EXIT; - } - - // Settings - if (menuBarFlag & menuBar_Settings) - if (Common::Rect(buts[2][1], - scrollPos, - buts[2][0] + buts[2][1], - scrollPos + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_PREF; - } - - // Load - if (menuBarFlag & menuBar_Restore) - if (Common::Rect(buts[1][1], - scrollPos, - buts[1][0] + buts[1][1], - scrollPos + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_REST; - } - - // Save - if (menuBarFlag & menuBar_Save) - if (Common::Rect(buts[0][1], - scrollPos, - buts[0][0] + buts[0][1], - scrollPos + 32).contains(Pos)) { - mouseOnItem = menu_MAIN_SAVE; - } - - if (lastItem != mouseOnItem) { - redraw = true; - frm = 0; - delay = 200; - } - } else { - inmenu = false; - if (_engine->getScriptManager()->getStateValue(StateKey_MenuState) != 0) - _engine->getScriptManager()->setStateValue(StateKey_MenuState, 0); - mouseOnItem = -1; - } -} - -void MenuNemesis::process(uint32 deltatime) { - if (inmenu) { - if (!scrolled) { - float scrl = 32.0 * 2.0 * (deltatime / 1000.0); - - if (scrl == 0) - scrl = 1.0; - - scrollPos += scrl; - redraw = true; - } - - if (scrollPos >= 0) { - scrolled = true; - scrollPos = 0; - } - - if (mouseOnItem != -1) { - delay -= deltatime; - if (delay <= 0 && frm < 4) { - delay = 200; - frm++; - redraw = true; - } - } - - if (redraw) { - _engine->getRenderManager()->blitSurfaceToMenu(menubar, 64, scrollPos); - - if (menuBarFlag & menuBar_Exit) - if (mouseOnItem == menu_MAIN_EXIT) - _engine->getRenderManager()->blitSurfaceToMenu(but[3][frm], buts[3][1], scrollPos); - - if (menuBarFlag & menuBar_Settings) - if (mouseOnItem == menu_MAIN_PREF) - _engine->getRenderManager()->blitSurfaceToMenu(but[2][frm], buts[2][1], scrollPos); - - if (menuBarFlag & menuBar_Restore) - if (mouseOnItem == menu_MAIN_REST) - _engine->getRenderManager()->blitSurfaceToMenu(but[1][frm], buts[1][1], scrollPos); - - if (menuBarFlag & menuBar_Save) - if (mouseOnItem == menu_MAIN_SAVE) - _engine->getRenderManager()->blitSurfaceToMenu(but[0][frm], buts[0][1], scrollPos); - - redraw = false; - } - } else { - scrolled = false; - if (scrollPos > -32) { - float scrl = 32.0 * 2.0 * (deltatime / 1000.0); - - if (scrl == 0) - scrl = 1.0; - - Common::Rect cl(64, 32 + scrollPos - scrl, 64 + 512, 32 + scrollPos + 1); - _engine->getRenderManager()->clearMenuSurface(cl); - - scrollPos -= scrl; - redraw = true; - } else - scrollPos = -32; - - if (redraw) { - _engine->getRenderManager()->blitSurfaceToMenu(menubar, 64, scrollPos); - redraw = false; - } - } -} - -} // End of namespace ZVision diff --git a/engines/zvision/core/menu.h b/engines/zvision/core/menu.h deleted file mode 100644 index ebe0bb50ac..0000000000 --- a/engines/zvision/core/menu.h +++ /dev/null @@ -1,125 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_MENU_H -#define ZVISION_MENU_H - -#include "graphics/surface.h" -#include "common/rect.h" - -#include "zvision/zvision.h" -#include "zvision/scripting/script_manager.h" - -namespace ZVision { - -enum menuBar { - menuBar_Exit = 0x1, - menuBar_Settings = 0x2, - menuBar_Restore = 0x4, - menuBar_Save = 0x8, - menuBar_Items = 0x100, - menuBar_Magic = 0x200 -}; - -class MenuHandler { -public: - MenuHandler(ZVision *engine); - virtual ~MenuHandler() {}; - virtual void onMouseMove(const Common::Point &Pos) {}; - virtual void onMouseDown(const Common::Point &Pos) {}; - virtual void onMouseUp(const Common::Point &Pos) {}; - virtual void process(uint32 deltaTimeInMillis) {}; - - void setEnable(uint16 flags) { - menuBarFlag = flags; - } - uint16 getEnable() { - return menuBarFlag; - } -protected: - uint16 menuBarFlag; - ZVision *_engine; -}; - -class MenuZGI: public MenuHandler { -public: - MenuZGI(ZVision *engine); - ~MenuZGI(); - void onMouseMove(const Common::Point &Pos); - void onMouseUp(const Common::Point &Pos); - void process(uint32 deltaTimeInMillis); -private: - Graphics::Surface menuback[3][2]; - Graphics::Surface menubar[4][2]; - Graphics::Surface *items[50][2]; - uint itemId[50]; - - Graphics::Surface *magic[12][2]; - uint magicId[12]; - - int menuMouseFocus; - bool inmenu; - - int mouseOnItem; - - bool scrolled[3]; - int16 scrollPos[3]; - - enum { - menu_ITEM = 0, - menu_MAGIC = 1, - menu_MAIN = 2 - }; - - bool clean; - bool redraw; - -}; - -class MenuNemesis: public MenuHandler { -public: - MenuNemesis(ZVision *engine); - ~MenuNemesis(); - void onMouseMove(const Common::Point &Pos); - void onMouseUp(const Common::Point &Pos); - void process(uint32 deltaTimeInMillis); -private: - Graphics::Surface but[4][6]; - Graphics::Surface menubar; - - bool inmenu; - - int mouseOnItem; - - bool scrolled; - int16 scrollPos; - - bool redraw; - - int frm; - int16 delay; - -}; - -} - -#endif diff --git a/engines/zvision/core/save_manager.cpp b/engines/zvision/core/save_manager.cpp deleted file mode 100644 index 20bd39fde5..0000000000 --- a/engines/zvision/core/save_manager.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" - -#include "zvision/core/save_manager.h" -#include "zvision/zvision.h" -#include "zvision/scripting/script_manager.h" -#include "zvision/graphics/render_manager.h" - -#include "common/system.h" -#include "common/translation.h" - -#include "graphics/surface.h" -#include "graphics/thumbnail.h" - -#include "gui/message.h" -#include "gui/saveload.h" - -namespace ZVision { - -const uint32 SaveManager::SAVEGAME_ID = MKTAG('Z', 'E', 'N', 'G'); - -bool SaveManager::scummVMSaveLoadDialog(bool isSave) { - GUI::SaveLoadChooser *dialog; - Common::String desc; - int slot; - - if (isSave) { - dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); - - slot = dialog->runModalWithCurrentTarget(); - desc = dialog->getResultString(); - - if (desc.empty()) { - // create our own description for the saved game, the user didnt enter it - desc = dialog->createDefaultSaveDescription(slot); - } - - if (desc.size() > 28) - desc = Common::String(desc.c_str(), 28); - } else { - dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); - slot = dialog->runModalWithCurrentTarget(); - } - - delete dialog; - - if (slot < 0) - return false; - - if (isSave) { - saveGame(slot, desc); - return true; - } else { - Common::ErrorCode result = loadGame(slot).getCode(); - return (result == Common::kNoError); - } -} - -void SaveManager::saveGame(uint slot, const Common::String &saveName) { - // The games only support 20 slots - //assert(slot <= 1 && slot <= 20); - - Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); - Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); - - writeSaveGameHeader(file, saveName); - - _engine->getScriptManager()->serialize(file); - - file->finalize(); - delete file; -} - -void SaveManager::saveGame(uint slot, const Common::String &saveName, Common::MemoryWriteStreamDynamic *stream) { - Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); - Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); - - writeSaveGameHeader(file, saveName); - - file->write(stream->getData(), stream->size()); - - file->finalize(); - delete file; -} - -void SaveManager::saveGameBuffered(uint slot, const Common::String &saveName) { - if (_tempSave) { - saveGame(slot, saveName, _tempSave); - flushSaveBuffer(); - } -} - -void SaveManager::autoSave() { - Common::OutSaveFile *file = g_system->getSavefileManager()->openForSaving(_engine->generateAutoSaveFileName()); - - writeSaveGameHeader(file, "auto"); - - _engine->getScriptManager()->serialize(file); - - // Cleanup - file->finalize(); - delete file; -} - -void SaveManager::writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName) { - - file->writeUint32BE(SAVEGAME_ID); - - // Write version - file->writeByte(SAVE_VERSION); - - // Write savegame name - file->writeString(saveName); - file->writeByte(0); - - // Create a thumbnail and save it - Graphics::saveThumbnail(*file); - - // Write out the save date/time - TimeDate td; - g_system->getTimeAndDate(td); - file->writeSint16LE(td.tm_year + 1900); - file->writeSint16LE(td.tm_mon + 1); - file->writeSint16LE(td.tm_mday); - file->writeSint16LE(td.tm_hour); - file->writeSint16LE(td.tm_min); -} - -Common::Error SaveManager::loadGame(uint slot) { - // The games only support 20 slots - //assert(slot <= 1 && slot <= 20); - - Common::SeekableReadStream *saveFile = getSlotFile(slot); - if (saveFile == 0) { - return Common::kPathDoesNotExist; - } - - // Read the header - SaveGameHeader header; - if (!readSaveGameHeader(saveFile, header)) { - return Common::kUnknownError; - } - - ScriptManager *scriptManager = _engine->getScriptManager(); - // Update the state table values - scriptManager->deserialize(saveFile); - - delete saveFile; - if (header.thumbnail) - delete header.thumbnail; - - return Common::kNoError; -} - -Common::Error SaveManager::loadGame(const Common::String &saveName) { - Common::File *saveFile = _engine->getSearchManager()->openFile(saveName); - if (saveFile == NULL) { - saveFile = new Common::File; - if (!saveFile->open(saveName)) { - delete saveFile; - return Common::kPathDoesNotExist; - } - } - - // Read the header - SaveGameHeader header; - if (!readSaveGameHeader(saveFile, header)) { - return Common::kUnknownError; - } - - ScriptManager *scriptManager = _engine->getScriptManager(); - // Update the state table values - scriptManager->deserialize(saveFile); - - delete saveFile; - if (header.thumbnail) - delete header.thumbnail; - - return Common::kNoError; -} - -bool SaveManager::readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) { - uint32 tag = in->readUint32BE(); - // Check if it's original savegame than fill header structure - if (tag == MKTAG('Z', 'N', 'S', 'G')) { - header.saveYear = 0; - header.saveMonth = 0; - header.saveDay = 0; - header.saveHour = 0; - header.saveMinutes = 0; - header.saveName = "Original Save"; - header.thumbnail = NULL; - header.version = SAVE_ORIGINAL; - in->seek(-4, SEEK_CUR); - return true; - } - if (tag != SAVEGAME_ID) { - warning("File is not a ZVision save file. Aborting load"); - return false; - } - - // Read in the version - header.version = in->readByte(); - - // Check that the save version isn't newer than this binary - if (header.version > SAVE_VERSION) { - uint tempVersion = header.version; - GUI::MessageDialog dialog(Common::String::format("This save file uses version %u, but this engine only supports up to version %d. You will need an updated version of the engine to use this save file.", tempVersion, SAVE_VERSION), "OK"); - dialog.runModal(); - } - - // Read in the save name - header.saveName.clear(); - char ch; - while ((ch = (char)in->readByte()) != '\0') - header.saveName += ch; - - // Get the thumbnail - header.thumbnail = Graphics::loadThumbnail(*in); - if (!header.thumbnail) - return false; - - // Read in save date/time - header.saveYear = in->readSint16LE(); - header.saveMonth = in->readSint16LE(); - header.saveDay = in->readSint16LE(); - header.saveHour = in->readSint16LE(); - header.saveMinutes = in->readSint16LE(); - - return true; -} - -Common::SeekableReadStream *SaveManager::getSlotFile(uint slot) { - Common::SeekableReadStream *saveFile = g_system->getSavefileManager()->openForLoading(_engine->generateSaveFileName(slot)); - if (saveFile == NULL) { - // Try to load standard save file - Common::String filename; - if (_engine->getGameId() == GID_GRANDINQUISITOR) - filename = Common::String::format("inqsav%u.sav", slot); - else if (_engine->getGameId() == GID_NEMESIS) - filename = Common::String::format("nemsav%u.sav", slot); - - saveFile = _engine->getSearchManager()->openFile(filename); - if (saveFile == NULL) { - Common::File *tmpFile = new Common::File; - if (!tmpFile->open(filename)) { - delete tmpFile; - } else { - saveFile = tmpFile; - } - } - - } - - return saveFile; -} - -void SaveManager::prepareSaveBuffer() { - if (_tempSave) - delete _tempSave; - - _tempSave = new Common::MemoryWriteStreamDynamic; - - _engine->getScriptManager()->serialize(_tempSave); -} - -void SaveManager::flushSaveBuffer() { - if (_tempSave) - delete _tempSave; - - _tempSave = NULL; -} - -} // End of namespace ZVision diff --git a/engines/zvision/core/save_manager.h b/engines/zvision/core/save_manager.h deleted file mode 100644 index 75841331e7..0000000000 --- a/engines/zvision/core/save_manager.h +++ /dev/null @@ -1,106 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef ZVISION_SAVE_MANAGER_H -#define ZVISION_SAVE_MANAGER_H - -#include "common/savefile.h" -#include "common/memstream.h" - -namespace Common { -class String; -} - -namespace Graphics { -struct Surface; -} - -namespace ZVision { - -class ZVision; - -struct SaveGameHeader { - byte version; - Common::String saveName; - Graphics::Surface *thumbnail; - int saveYear, saveMonth, saveDay; - int saveHour, saveMinutes; -}; - -class SaveManager { -public: - SaveManager(ZVision *engine) : _engine(engine), _tempSave(NULL) {} - ~SaveManager() { - flushSaveBuffer(); - } - -private: - ZVision *_engine; - static const uint32 SAVEGAME_ID; - - enum { - SAVE_ORIGINAL = 0, - SAVE_VERSION = 1 - }; - - Common::MemoryWriteStreamDynamic *_tempSave; - -public: - /** - * Called every room change. Saves the state of the room just before - * we switched rooms. Uses ZVision::generateAutoSaveFileName() to - * create the save file name. - */ - void autoSave(); - /** - * Copies the data from the last auto-save into a new save file. We - * can't use the current state data because the save menu *IS* a room. - * The file is named using ZVision::generateSaveFileName(slot) - * - * @param slot The save slot this save pertains to. Must be [1, 20] - * @param saveName The internal name for this save. This is NOT the name of the actual save file. - */ - void saveGame(uint slot, const Common::String &saveName); - void saveGame(uint slot, const Common::String &saveName, Common::MemoryWriteStreamDynamic *stream); - void saveGameBuffered(uint slot, const Common::String &saveName); - /** - * Loads the state data from the save file that slot references. Uses - * ZVision::generateSaveFileName(slot) to get the save file name. - * - * @param slot The save slot to load. Must be [1, 20] - */ - Common::Error loadGame(uint slot); - Common::Error loadGame(const Common::String &saveName); - - Common::SeekableReadStream *getSlotFile(uint slot); - bool readSaveGameHeader(Common::SeekableReadStream *in, SaveGameHeader &header); - - void prepareSaveBuffer(); - void flushSaveBuffer(); - bool scummVMSaveLoadDialog(bool isSave); -private: - void writeSaveGameHeader(Common::OutSaveFile *file, const Common::String &saveName); -}; - -} // End of namespace ZVision - -#endif |