diff options
author | Paul Gilbert | 2007-08-25 06:08:02 +0000 |
---|---|---|
committer | Paul Gilbert | 2007-08-25 06:08:02 +0000 |
commit | ca96ba431c5fd95852464ab13bcb78d2c5ad4682 (patch) | |
tree | 1a43cd0a05d278bb9ba463e51742b9e8cb1974a6 /engines/lure | |
parent | 5fd1bf64f24ead49799627b39e305a684f738e9c (diff) | |
download | scummvm-rg350-ca96ba431c5fd95852464ab13bcb78d2c5ad4682.tar.gz scummvm-rg350-ca96ba431c5fd95852464ab13bcb78d2c5ad4682.tar.bz2 scummvm-rg350-ca96ba431c5fd95852464ab13bcb78d2c5ad4682.zip |
Completed the restart/restore dialog screen and functionality
svn-id: r28714
Diffstat (limited to 'engines/lure')
-rw-r--r-- | engines/lure/game.cpp | 176 | ||||
-rw-r--r-- | engines/lure/game.h | 3 | ||||
-rw-r--r-- | engines/lure/res.cpp | 14 | ||||
-rw-r--r-- | engines/lure/res.h | 3 | ||||
-rw-r--r-- | engines/lure/res_struct.cpp | 6 | ||||
-rw-r--r-- | engines/lure/res_struct.h | 1 | ||||
-rw-r--r-- | engines/lure/room.cpp | 27 | ||||
-rw-r--r-- | engines/lure/surface.cpp | 86 |
8 files changed, 210 insertions, 106 deletions
diff --git a/engines/lure/game.cpp b/engines/lure/game.cpp index 091cfbfe0a..110d577386 100644 --- a/engines/lure/game.cpp +++ b/engines/lure/game.cpp @@ -46,7 +46,7 @@ Game::Game() { int_game = this; _debugger = new Debugger(); _slowSpeedFlag = true; - _preloadFlag = true; + _preloadFlag = false; _soundFlag = true; } @@ -130,23 +130,30 @@ void Game::execute() { uint32 timerVal2 = system.getMillis(); screen.empty(); - //_screen.resetPalette(); screen.setPaletteEmpty(); + // Flag for starting game + setState(GS_RESTART); + while (!events.quitFlag) { - setState(0); - Script::execute(STARTUP_SCRIPT); + + if ((_state & GS_RESTART) != 0) { + res.reset(); + + setState(0); + Script::execute(STARTUP_SCRIPT); - int bootParam = ConfMan.getInt("boot_param"); - handleBootParam(bootParam); + int bootParam = ConfMan.getInt("boot_param"); + handleBootParam(bootParam); +if (bootParam == 1) _state = GS_RESTORE_RESTART; //******DEBUG****** + } // Set the player direction - res.getActiveHotspot(PLAYER_ID)->setDirection(UP); +// res.getActiveHotspot(PLAYER_ID)->setDirection(UP); room.update(); mouse.setCursorNum(CURSOR_ARROW); mouse.cursorOn(); -if (bootParam == 1) _state = GS_RESTORE_RESTART; //******DEBUG****** // Main game loop while (!events.quitFlag && ((_state & GS_RESTART) == 0)) { @@ -188,48 +195,46 @@ if (bootParam == 1) _state = GS_RESTORE_RESTART; //******DEBUG****** SaveRestoreDialog::show(false); break; - default: - handled = false; - } - if (handled) - continue; + case Common::KEYCODE_F9: + doRestart(); + break; - // Handle any remaining standard keys - switch (events.event().kbd.keycode) { - case Common::KEYCODE_ESCAPE: - events.quitFlag = true; - break; + case Common::KEYCODE_KP_PLUS: + while (++roomNum <= 51) + if (res.getRoom(roomNum) != NULL) break; + if (roomNum == 52) roomNum = 1; - case '+': - while (++roomNum <= 51) - if (res.getRoom(roomNum) != NULL) break; - if (roomNum == 52) roomNum = 1; + room.leaveRoom(); + room.setRoomNumber(roomNum); + break; - room.leaveRoom(); - room.setRoomNumber(roomNum); - break; + case Common::KEYCODE_KP_MINUS: + if (roomNum == 1) roomNum = 55; + while (res.getRoom(--roomNum) == NULL) ; - case '-': - if (roomNum == 1) roomNum = 55; - while (res.getRoom(--roomNum) == NULL) ; + room.leaveRoom(); + room.setRoomNumber(roomNum); + break; - room.leaveRoom(); - room.setRoomNumber(roomNum); - break; + case Common::KEYCODE_KP_MULTIPLY: + res.getActiveHotspot(PLAYER_ID)->setRoomNumber( + room.roomNumber()); + break; - case '*': - res.getActiveHotspot(PLAYER_ID)->setRoomNumber( - room.roomNumber()); - break; + case Common::KEYCODE_KP_DIVIDE: + case Common::KEYCODE_SLASH: + room.setShowInfo(!room.showInfo()); + break; - case Common::KEYCODE_KP_DIVIDE: - case Common::KEYCODE_SLASH: - room.setShowInfo(!room.showInfo()); - break; + case Common::KEYCODE_ESCAPE: + doQuit(); + break; - default: - break; + default: + handled = false; } + if (handled) + continue; } if ((events.type() == Common::EVENT_LBUTTONDOWN) || @@ -260,7 +265,6 @@ if (bootParam == 1) _state = GS_RESTORE_RESTART; //******DEBUG****** } room.leaveRoom(); - screen.paletteFadeOut(); // If Skorl catches player, show the catching animation if ((_state & GS_CAUGHT) != 0) { @@ -270,7 +274,7 @@ if (bootParam == 1) _state = GS_RESTORE_RESTART; //******DEBUG****** mouse.cursorOff(); Sound.addSound(0x33); anim->show(); - mouse.cursorOn(); + delete anim; } // If the Restart/Restore dialog is needed, show it @@ -278,12 +282,9 @@ if (bootParam == 1) _state = GS_RESTORE_RESTART; //******DEBUG****** // Show the Restore/Restart dialog bool restartFlag = RestartRestoreDialog::show(); - setState(0); - - if (restartFlag) { - res.reloadData(); - Script::execute(STARTUP_SCRIPT); - } + if (restartFlag) + setState(GS_RESTART); + } else if ((_state & GS_RESTART) == 0) // Exiting game events.quitFlag = true; @@ -299,6 +300,7 @@ void Game::handleMenuResponse(uint8 selection) { break; case MENUITEM_RESTART_GAME: + doQuit(); break; case MENUITEM_SAVE_GAME: @@ -863,31 +865,13 @@ void Game::doShowCredits() { } void Game::doQuit() { - Mouse &mouse = Mouse::getReference(); - Events &events = Events::getReference(); - Screen &screen = Screen::getReference(); - - mouse.cursorOff(); - Surface *s = Surface::newDialog(190, "Are you sure (y/n)?"); - s->centerOnScreen(); - delete s; - - Common::KeyCode key = Common::KEYCODE_INVALID; - do { - if (events.pollEvent()) { - if (events.event().type == Common::EVENT_KEYDOWN) { - key = events.event().kbd.keycode; - } - } - } while ((key != Common::KEYCODE_ESCAPE) && - (key != Common::KEYCODE_y) && - (key != Common::KEYCODE_n)); + if (getYN()) + Events::getReference().quitFlag = true; +} - events.quitFlag = (key == Common::KEYCODE_n); - if (!events.quitFlag) { - screen.update(); - mouse.cursorOn(); - } +void Game::doRestart() { + if (getYN()) + setState(GS_RESTART); } void Game::doTextSpeed() { @@ -948,7 +932,53 @@ void Game::handleBootParam(int value) { room.setRoomNumber(2); break; + + default: + room.setRoomNumber(value); + break; } } +bool Game::getYN() { + Mouse &mouse = Mouse::getReference(); + Events &events = Events::getReference(); + Screen &screen = Screen::getReference(); + + mouse.cursorOff(); + Surface *s = Surface::newDialog(190, "Are you sure (y/n)?"); + s->centerOnScreen(); + delete s; + + bool breakFlag = false; + bool result = false; + + do { + if (events.pollEvent()) { + if (events.event().type == Common::EVENT_KEYDOWN) { + Common::KeyCode key = events.event().kbd.keycode; + if ((key == Common::KEYCODE_y) || (key == Common::KEYCODE_n) || + (key == Common::KEYCODE_ESCAPE)) { + breakFlag = true; + result = key == Common::KEYCODE_y; + } + } + if (events.event().type == Common::EVENT_LBUTTONUP) { + breakFlag = true; + result = true; + } + if (events.event().type == Common::EVENT_RBUTTONUP) { + breakFlag = true; + result = false; + } + } + + g_system->delayMillis(10); + } while (!events.quitFlag && !breakFlag); + + screen.update(); + mouse.cursorOn(); + + return result; +} + } // end of namespace Lure diff --git a/engines/lure/game.h b/engines/lure/game.h index 7b2099ef0c..50b730e354 100644 --- a/engines/lure/game.h +++ b/engines/lure/game.h @@ -63,7 +63,7 @@ private: void displayChuteAnimation(); void displayBarrelAnimation(); void handleBootParam(int value); - int restartRestoreScreen(); + bool getYN(); public: Game(); virtual ~Game(); @@ -81,6 +81,7 @@ public: void doDebugMenu(); void doShowCredits(); void doQuit(); + void doRestart(); void doTextSpeed(); void doSound(); }; diff --git a/engines/lure/res.cpp b/engines/lure/res.cpp index a2f2530248..44d9d9859f 100644 --- a/engines/lure/res.cpp +++ b/engines/lure/res.cpp @@ -62,11 +62,16 @@ void Resources::freeData() { _indexedRoomExitHospots.clear(); _pausedList.clear(); _stringList.clear(); + _actionsList.clear(); + _coordinateList.clear(); + _talkHeaders.clear(); + _talkData.clear(); + free(_hotspotScriptData); delete _paletteSubset; delete _scriptData; delete _script2Data; - free(_hotspotScriptData); + delete _talkDialogData; delete _messagesData; delete _cursors; delete [] _charOffsets; @@ -77,6 +82,13 @@ struct AnimRecordTemp { MovementDataList *list; }; +void Resources::reset() { + freeData(); + + _fieldList.reset(); + reloadData(); +} + void Resources::reloadData() { Disk &d = Disk::getReference(); MemoryBlock *mb, *paths; diff --git a/engines/lure/res.h b/engines/lure/res.h index 7c9970f27f..86d5ad5d95 100644 --- a/engines/lure/res.h +++ b/engines/lure/res.h @@ -88,12 +88,13 @@ private: int _talkStartEntry; uint16 _talkingCharacter; + void reloadData(); void freeData(); public: Resources(); ~Resources(); static Resources &getReference(); - void reloadData(); + void reset(); byte *getResource(uint16 resId); RoomDataList &roomData() { return _roomData; } diff --git a/engines/lure/res_struct.cpp b/engines/lure/res_struct.cpp index 3db92d9c56..3ccd14f99c 100644 --- a/engines/lure/res_struct.cpp +++ b/engines/lure/res_struct.cpp @@ -1206,12 +1206,16 @@ void StringList::clear() { // Field list and miscellaneous variables ValueTableData::ValueTableData() { + reset(); +} + +void ValueTableData::reset() { _numGroats = 0; _playerNewPos.roomNumber = 0; _playerNewPos.position.x = 0; _playerNewPos.position.y = 0; _flags = GAMEFLAG_4 | GAMEFLAG_1; - _hdrFlagMask = 1; + _hdrFlagMask = 1; for (uint16 index = 0; index < NUM_VALUE_FIELDS; ++index) _fieldList[index] = 0; diff --git a/engines/lure/res_struct.h b/engines/lure/res_struct.h index 0e0475bbde..d5b80439cc 100644 --- a/engines/lure/res_struct.h +++ b/engines/lure/res_struct.h @@ -839,6 +839,7 @@ private: bool isKnownField(uint16 fieldIndex); public: ValueTableData(); + void reset(); uint16 getField(uint16 fieldIndex); uint16 getField(FieldName fieldName); diff --git a/engines/lure/room.cpp b/engines/lure/room.cpp index 6806b13b9a..acab44deea 100644 --- a/engines/lure/room.cpp +++ b/engines/lure/room.cpp @@ -492,13 +492,13 @@ void Room::update() { } void Room::setRoomNumber(uint16 newRoomNumber, bool showOverlay) { - Resources &r = Resources::getReference(); + Resources &res = Resources::getReference(); Game &game = Game::getReference(); Mouse &mouse = Mouse::getReference(); mouse.pushCursorNum(CURSOR_DISK); - _roomData = r.getRoom(newRoomNumber); + _roomData = res.getRoom(newRoomNumber); if (!_roomData) error("Tried to change to non-existant room: %d", newRoomNumber); bool leaveFlag = (_layers[0] && (newRoomNumber != _roomNumber) && (_roomNumber != 0)); @@ -512,6 +512,7 @@ void Room::setRoomNumber(uint16 newRoomNumber, bool showOverlay) { } _screen.empty(); + _screen.setPaletteEmpty(GAME_COLOURS); _numLayers = _roomData->numLayers; if (showOverlay) ++_numLayers; @@ -521,20 +522,25 @@ void Room::setRoomNumber(uint16 newRoomNumber, bool showOverlay) { _layers[layerNum] = new RoomLayer(_roomData->layers[layerNum], layerNum == 0); - // Load in the game palette and set the non-room specific colours at the top end of the palette + // Load in the game palette, which contains at it's top end general GUI element colours Palette mainPalette(GAME_PALETTE_RESOURCE_ID); - _screen.setPalette(&mainPalette, MAIN_PALETTE_SIZE, GAME_COLOURS - MAIN_PALETTE_SIZE); + _screen.setPalette(&mainPalette, 0, GAME_COLOURS); + + // Generate the palette for the room that will be faded in + Palette p(MAIN_PALETTE_SIZE, NULL, RGB64); + Palette tempPalette(paletteId); + p.copyFrom(&tempPalette); + res.insertPaletteSubset(p); // Set the new room number - r.fieldList().setField(ROOM_NUMBER, newRoomNumber); + res.fieldList().setField(ROOM_NUMBER, newRoomNumber); if (_roomData->sequenceOffset != 0xffff) Script::execute(_roomData->sequenceOffset); loadRoomHotspots(); - if (_roomData->exitTime != 0xffff) - { + if ((_roomData->exitTime != 0xffff) && (_roomData->exitTime != 0)) { // If time has passed, animation ticks needed before room is displayed int numSeconds = (g_system->getMillis() - _roomData->exitTime) / 1000; if (numSeconds > 300) numSeconds = 300; @@ -545,14 +551,9 @@ void Room::setRoomNumber(uint16 newRoomNumber, bool showOverlay) { game.preloadFlag() = false; } + game.tick(); update(); _screen.update(); - - // Generate the palette for the room and fade it in - Palette p(MAIN_PALETTE_SIZE, NULL, RGB64); - Palette tempPalette(paletteId); - p.copyFrom(&tempPalette); - r.insertPaletteSubset(p); _screen.paletteFadeIn(&p); mouse.popCursor(); diff --git a/engines/lure/surface.cpp b/engines/lure/surface.cpp index 0465fe16de..c179e1420d 100644 --- a/engines/lure/surface.cpp +++ b/engines/lure/surface.cpp @@ -632,7 +632,6 @@ bool SaveRestoreDialog::show(bool saveDialog) { Screen &screen = Screen::getReference(); Mouse &mouse = Mouse::getReference(); Events &events = Events::getReference(); - Room &room = Room::getReference(); Resources &res = Resources::getReference(); LureEngine &engine = LureEngine::getReference(); int selectedLine = -1; @@ -656,7 +655,6 @@ bool SaveRestoreDialog::show(bool saveDialog) { return false; } - room.update(); Surface *s = new Surface(INFO_DIALOG_WIDTH, SR_SAVEGAME_NAMES_Y + numSaves * FONT_HEIGHT + FONT_HEIGHT + 2); @@ -799,8 +797,7 @@ RestartRecord buttonBounds[] = { }; -bool RestartRestoreDialog::show() -{ +bool RestartRestoreDialog::show() { Resources &res = Resources::getReference(); Events &events = Events::getReference(); Mouse &mouse = Mouse::getReference(); @@ -814,6 +811,7 @@ bool RestartRestoreDialog::show() // See if there are any savegames that can be restored String *firstSave = engine.detectSave(1); bool restartFlag = (firstSave == NULL); + int highlightedButton = -1; if (!restartFlag) { Memory::dealloc(firstSave); @@ -824,37 +822,93 @@ bool RestartRestoreDialog::show() (btnRecord->Language != UNK_LANG)) ++btnRecord; - // Fade in the restart/restore screen - Palette p(RESTART_RESOURCE_ID + 1); + // Fade out the screen + screen.paletteFadeOut(RES_PALETTE_ENTRIES); + + // Get the palette that will be used, and first fade out the prior screen + Palette p(RESTART_RESOURCE_ID - 1); + + // Turn on the mouse + mouse.cursorOn(); + + // Load the restore/restart screen image Surface *s = Surface::getScreen(RESTART_RESOURCE_ID); + s->copyTo(&screen.screen(), 0, MENUBAR_Y_SIZE); + delete s; res.activeHotspots().clear(); Hotspot *btnHotspot = new Hotspot(); + // Restart button btnHotspot->setSize(btnRecord->width, btnRecord->height); btnHotspot->setPosition(btnRecord->BtnRestart.x, btnRecord->BtnRestart.y); btnHotspot->setAnimation(0x184B); - btnHotspot->copyTo(s); + btnHotspot->copyTo(&screen.screen()); + // Restore button btnHotspot->setFrameNumber(1); btnHotspot->setPosition(btnRecord->BtnRestore.x, btnRecord->BtnRestore.y); - btnHotspot->copyTo(s); - - // Copy the surface to the screen - screen.setPaletteEmpty(); - s->copyToScreen(0, 0); - delete s; + btnHotspot->copyTo(&screen.screen()); + screen.update(); screen.paletteFadeIn(&p); - events.waitForPress(); - screen.paletteFadeOut(); + // Event loop for making selection + while (!events.quitFlag) { + // Handle events + if (events.pollEvent()) { + if ((events.type() == Common::EVENT_LBUTTONDOWN) && (highlightedButton != -1)) { + mouse.waitForRelease(); + break; + } + } + + // Check if the pointer is over either button + int currentButton = -1; + if ((mouse.y() >= btnRecord->BtnRestart.y) && + (mouse.y() < btnRecord->BtnRestart.y + btnRecord->height)) { + // Check whether the Restart or Restore button is highlighted + if ((mouse.x() >= btnRecord->BtnRestart.x) && + (mouse.x() < btnRecord->BtnRestart.x + btnRecord->width)) + currentButton = 0; + else if ((mouse.x() >= btnRecord->BtnRestore.x) && + (mouse.x() < btnRecord->BtnRestore.x + btnRecord->width)) + currentButton = 1; + } - //restartFlag = !SaveRestoreDialog::show(false); + // Take care of highlighting as the selected button changes + if (currentButton != highlightedButton) { + highlightedButton = currentButton; + + // Restart button + btnHotspot->setFrameNumber((highlightedButton == 0) ? 2 : 0); + btnHotspot->setPosition(btnRecord->BtnRestart.x, btnRecord->BtnRestart.y); + btnHotspot->copyTo(&screen.screen()); + + // Restore button + btnHotspot->setFrameNumber((highlightedButton == 1) ? 3 : 1); + btnHotspot->setPosition(btnRecord->BtnRestore.x, btnRecord->BtnRestore.y); + btnHotspot->copyTo(&screen.screen()); + } + + + screen.update(); + g_system->delayMillis(10); + } + + restartFlag = highlightedButton == 0; + delete btnHotspot; } Sound.killSounds(); + if (!restartFlag && !events.quitFlag) { + // Need to show Restore game dialog + if (!SaveRestoreDialog::show(false)) + // User cancelled, so fall back on Restart + restartFlag = true; + } + return restartFlag; } |