aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/worldofxeen/worldofxeen_menu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/xeen/worldofxeen/worldofxeen_menu.cpp')
-rw-r--r--engines/xeen/worldofxeen/worldofxeen_menu.cpp351
1 files changed, 182 insertions, 169 deletions
diff --git a/engines/xeen/worldofxeen/worldofxeen_menu.cpp b/engines/xeen/worldofxeen/worldofxeen_menu.cpp
index 7f5e7f35c1..a91a711a67 100644
--- a/engines/xeen/worldofxeen/worldofxeen_menu.cpp
+++ b/engines/xeen/worldofxeen/worldofxeen_menu.cpp
@@ -29,236 +29,249 @@
namespace Xeen {
namespace WorldOfXeen {
-void WorldOfXeenMenu::show(XeenEngine *vm) {
- WorldOfXeenMenu *menu;
+void MainMenuContainer::show() {
+ MainMenuContainer *menu;
- switch (vm->getGameID()) {
+ switch (g_vm->getGameID()) {
case GType_Clouds:
- menu = new CloudsOptionsMenu(vm);
+ menu = new CloudsMainMenuContainer();
break;
case GType_DarkSide:
- menu = new DarkSideOptionsMenu(vm);
+ menu = new DarkSideMainMenuContainer();
break;
case GType_WorldOfXeen:
- menu = new WorldOptionsMenu(vm);
+ menu = new WorldOfXeenMainMenuContainer();
break;
default:
- error("Unsupported game");
- break;
+ error("Invalid game");
}
menu->execute();
delete menu;
}
-void WorldOfXeenMenu::execute() {
- _vm->_files->setGameCc(1);
- SpriteResource special("special.icn");
- Windows &windows = *_vm->_windows;
- EventsManager &events = *_vm->_events;
-
- File newBright("newbrigh.m");
- _vm->_sound->playSong(newBright);
-
- windows[GAME_WINDOW].setBounds(Common::Rect(72, 25, 248, 175));
+MainMenuContainer::MainMenuContainer(const Common::String &spritesName) : _animateCtr(0), _dialog(nullptr) {
+ _backgroundSprites.load(spritesName);
+}
- Common::String title1, title2;
- startup(title1, title2);
- SpriteResource title1Sprites(title1), title2Sprites(title2);
+MainMenuContainer::~MainMenuContainer() {
+ delete _dialog;
+ g_vm->_windows->closeAll();
+ g_vm->_sound->stopAllAudio();
+ g_vm->_events->clearEvents();
+}
- bool firstTime = true, doFade = true;
- while (!_vm->shouldExit()) {
- setBackground(doFade);
+void MainMenuContainer::draw() {
+ g_vm->_screen->restoreBackground();
+ _animateCtr = (_animateCtr + 1) % 9;
+ _backgroundSprites.draw(0, _animateCtr);
+}
- if (firstTime) {
- firstTime = false;
- events.setCursor(0);
- events.showCursor();
+void MainMenuContainer::execute() {
+ EventsManager &events = *g_vm->_events;
+ bool showFlag = false;
+
+ // Show the cursor
+ events.clearEvents();
+ events.setCursor(0);
+ events.showCursor();
+
+ while (!g_vm->shouldExit() && g_vm->_gameMode == GMODE_NONE) {
+ // Draw the menu
+ draw();
+ if (_dialog)
+ _dialog->draw();
+
+ // Fade/scroll in screen if first frame
+ if (!showFlag) {
+ loadBackground();
+ // TODO: doScroll(false, false);
+ showFlag = true;
}
- showTitles1(title1Sprites);
- showTitles2();
-
- clearButtons();
- setupButtons(&title2Sprites);
- openWindow();
-
- while (!_vm->shouldExit()) {
- // Show the dialog with a continually animating background
- while (!_vm->shouldExit() && !_buttonValue)
- showContents(title1Sprites, true);
- if (_vm->shouldExit())
- return;
-
- // Handle keypress
- int key = toupper(_buttonValue);
- _buttonValue = 0;
-
- if (key == Common::KEYCODE_ESCAPE) {
- // Hide the options menu
- closeWindow();
- break;
- } else if (key == 'C' || key == 'V') {
- // Show credits
- closeWindow();
- CreditsScreen::show(_vm);
- break;
- } else if (key == 'S') {
- // Start new game
- int result = DifficultyDialog::show(_vm);
- if (result == -1)
- break;
-
- // Load a new game state and set the difficulty
- _vm->_saves->newGame();
- _vm->_party->_difficulty = (Difficulty)result;
- _vm->_gameMode = GMODE_PLAY_GAME;
- closeWindow();
- return;
- } else if (key == 'L') {
- _vm->_saves->newGame();
- if (_vm->_saves->loadGame()) {
- _vm->_gameMode = GMODE_PLAY_GAME;
- break;
+ // Check for events
+ events.updateGameCounter();
+
+ if (events.wait(4, true)) {
+ if (_dialog) {
+ // There's a dialog active, so let it handle the event
+ _dialog->handleEvents();
+
+ // If dialog was removed as a result of the event, flag screen for re-showing
+ // if the menu screen isn't being left
+ if (!_dialog)
+ showFlag = false;
+ } else {
+ // No active dialog. If Escape pressed, exit game entirely. Otherwise,
+ // open up the main menu dialog
+ if (events.isKeyPending()) {
+ Common::KeyState key;
+ if (events.getKey(key) && key.keycode == Common::KEYCODE_ESCAPE)
+ g_vm->_gameMode = GMODE_QUIT;
}
+
+ events.clearEvents();
+ showMenuDialog();
}
}
}
}
-void WorldOfXeenMenu::showTitles1(SpriteResource &sprites) {
- Screen &screen = *_vm->_screen;
- EventsManager &events = *_vm->_events;
-
- int frameNum = 0;
- while (!_vm->shouldExit() && !events.isKeyMousePressed()) {
- events.updateGameCounter();
-
- frameNum = (frameNum + 1) % (_vm->getGameID() == GType_WorldOfXeen ? 5 : 10);
- screen.restoreBackground();
- sprites.draw(0, frameNum);
+/*------------------------------------------------------------------------*/
- events.wait(4);
- }
+CloudsMainMenuContainer::CloudsMainMenuContainer() : MainMenuContainer("intro.vga") {
+ g_vm->_sound->playSong("inn.m");
}
-void WorldOfXeenMenu::showTitles2() {
- Screen &screen = *_vm->_screen;
- EventsManager &events = *_vm->_events;
- Sound &sound = *_vm->_sound;
- Windows &windows = *_vm->_windows;
-
- SpriteResource titleSprites("title2b.raw");
- SpriteResource kludgeSprites("kludge.int");
- SpriteResource title2Sprites[8] = {
- SpriteResource("title2b.int"), SpriteResource("title2c.int"),
- SpriteResource("title2d.int"), SpriteResource("title2e.int"),
- SpriteResource("title2f.int"), SpriteResource("title2g.int"),
- SpriteResource("title2h.int"), SpriteResource("title2i.int"),
- };
-
- kludgeSprites.draw(0, 0);
+void CloudsMainMenuContainer::loadBackground() {
+ Screen &screen = *g_vm->_screen;
+ screen.loadPalette("mm4.pal");
+ screen.loadBackground("intro.raw");
screen.saveBackground();
- sound.playSound("elect.voc");
-
- for (int i = 0; i < 30 && !_vm->shouldExit(); ++i) {
- events.updateGameCounter();
- screen.restoreBackground();
- title2Sprites[i / 4].draw(0, i % 4);
- windows[0].update();
+}
- if (i == 19)
- sound.stopSound();
+void CloudsMainMenuContainer::showMenuDialog() {
+ setOwner(new CloudsMenuDialog(this));
+}
- while (!_vm->shouldExit() && events.timeElapsed() < 2)
- events.pollEventsAndWait();
- }
+/*------------------------------------------------------------------------*/
- screen.restoreBackground();
- windows[0].update();
+DarkSideMainMenuContainer::DarkSideMainMenuContainer() : MainMenuContainer("intro.vga") {
+ g_vm->_sound->playSong("inn.m");
}
-void WorldOfXeenMenu::setupButtons(SpriteResource *buttons) {
- addButton(Common::Rect(124, 87, 124 + 53, 87 + 10), 'S');
- addButton(Common::Rect(126, 98, 126 + 47, 98 + 10), 'L');
- addButton(Common::Rect(91, 110, 91 + 118, 110 + 10), 'C');
- addButton(Common::Rect(85, 121, 85 + 131, 121 + 10), 'O');
+void DarkSideMainMenuContainer::loadBackground() {
+ Screen &screen = *g_vm->_screen;
+ screen.loadPalette("mm4.pal");
+ screen.loadBackground("intro.raw");
+ screen.saveBackground();
}
-void WorldOptionsMenu::setupButtons(SpriteResource *buttons) {
- addButton(Common::Rect(93, 53, 93 + 134, 53 + 20), 'S', buttons);
- addButton(Common::Rect(93, 78, 93 + 134, 78 + 20), 'L', buttons);
- addButton(Common::Rect(93, 103, 93 + 134, 103 + 20), 'C', buttons);
- addButton(Common::Rect(93, 128, 93 + 134, 128 + 20), 'O', buttons);
+void DarkSideMainMenuContainer::showMenuDialog() {
+ setOwner(new CloudsMenuDialog(this));
}
/*------------------------------------------------------------------------*/
-void CloudsOptionsMenu::startup(Common::String &title1, Common::String &title2) {
- title1 = "title1.int";
- title2 = "title1a.int";
+WorldOfXeenMainMenuContainer::WorldOfXeenMainMenuContainer() : MainMenuContainer("intro.vga") {
+ g_vm->_sound->playSong("inn.m");
}
-/*------------------------------------------------------------------------*/
+void WorldOfXeenMainMenuContainer::loadBackground() {
+ Screen &screen = *g_vm->_screen;
+ screen.loadPalette("mm4.pal");
+ screen.loadBackground("intro.raw");
+ screen.saveBackground();
+}
-void DarkSideOptionsMenu::startup(Common::String &title1, Common::String &title2) {
- title1 = "title2.int";
- title2 = "title2a.int";
+void WorldOfXeenMainMenuContainer::showMenuDialog() {
+ setOwner(new CloudsMenuDialog(this));
}
-void WorldOptionsMenu::startup(Common::String &title1, Common::String &title2) {
- title1 = "world.int";
- title2 = "start.icn";
+/*------------------------------------------------------------------------*/
- Screen &screen = *_vm->_screen;
- screen.fadeOut();
- screen.loadPalette("dark.pal");
- _vm->_events->clearEvents();
-}
+bool MainMenuDialog::handleEvents() {
+ checkEvents(g_vm);
+ int difficulty;
+
+ switch (_buttonValue) {
+ case Common::KEYCODE_s:
+ // Start new game
+ difficulty = DifficultyDialog::show(g_vm);
+ if (difficulty == -1)
+ return true;
+
+ // Load a new game state and set the difficulty
+ g_vm->_saves->newGame();
+ g_vm->_party->_difficulty = (Difficulty)difficulty;
+ g_vm->_gameMode = GMODE_PLAY_GAME;
+ break;
-void WorldOptionsMenu::setBackground(bool doFade) {
- Screen &screen = *_vm->_screen;
- screen.loadBackground("world.raw");
- screen.saveBackground();
+ case Common::KEYCODE_l:
+ // Load existing game
+ g_vm->_saves->newGame();
+ if (!g_vm->_saves->loadGame())
+ return true;
+
+ g_vm->_gameMode = GMODE_PLAY_GAME;
+ break;
+
+ case Common::KEYCODE_c:
+ case Common::KEYCODE_v:
+ // Show credits
+ CreditsScreen::show(g_vm);
+ break;
+
+ default:
+ return false;
+ }
- if (doFade)
- screen.fadeIn();
+ // If this point is reached, delete the dialog itself, which will return the main menu
+ // to it's default "No dialog showing" state
+ delete this;
+ return true;
}
-void WorldOptionsMenu::openWindow() {
- Windows &windows = *_vm->_windows;
- windows[GAME_WINDOW].open();
+/*------------------------------------------------------------------------*/
+
+CloudsMenuDialog::CloudsMenuDialog(MainMenuContainer *owner) : MainMenuDialog(owner) {
+ Windows &windows = *g_vm->_windows;
+ Window &w = windows[GAME_WINDOW];
+ w.setBounds(Common::Rect(72, 25, 248, g_vm->_gameWon[0] ? 175 : 150));
+ w.open();
+
+ loadButtons();
}
-void WorldOptionsMenu::closeWindow() {
- Windows &windows = *_vm->_windows;
- windows[GAME_WINDOW].close();
+CloudsMenuDialog::~CloudsMenuDialog() {
+ Windows &windows = *g_vm->_windows;
+ Window &w = windows[GAME_WINDOW];
+ w.close();
}
-void WorldOptionsMenu::showContents(SpriteResource &title1, bool waitFlag) {
- EventsManager &events = *_vm->_events;
- Screen &screen = *_vm->_screen;
- Windows &windows = *_vm->_windows;
- events.updateGameCounter();
+void CloudsMenuDialog::loadButtons() {
+ _buttonSprites.load("start.icn");
+ addButton(Common::Rect(93, 53, 227, 73), Common::KEYCODE_s, &_buttonSprites);
+ addButton(Common::Rect(93, 78, 227, 98), Common::KEYCODE_l, &_buttonSprites);
+ addButton(Common::Rect(93, 103, 227, 123), Common::KEYCODE_c, &_buttonSprites);
+ if (g_vm->_gameWon[0])
+ addButton(Common::Rect(93, 128, 227, 148), Common::KEYCODE_e, &_buttonSprites);
+}
- // Draw the background frame in a continous cycle
- _bgFrame = (_bgFrame + 1) % 5;
- title1.draw(windows[0], _bgFrame);
+void CloudsMenuDialog::draw() {
+ Windows &windows = *g_vm->_windows;
+ Window &w = windows[GAME_WINDOW];
+
+ w.frame();
+ w.writeString(Common::String::format(Res.CLOUDS_MAIN_MENU, g_vm->_gameWon[0] ? 117 : 92));
+ drawButtons(&w);
+}
- // Draw the basic frame for the optitons menu and title text
- windows[GAME_WINDOW].frame();
- windows[GAME_WINDOW].writeString(Res.OPTIONS_TITLE);
+bool CloudsMenuDialog::handleEvents() {
+ if (MainMenuDialog::handleEvents())
+ return true;
- drawButtons(&windows[0]);
- screen.update();
+ switch (_buttonValue) {
+ case Common::KEYCODE_e:
+ if (g_vm->_gameWon[0]) {
+ // Close the window
+ delete this;
- if (waitFlag) {
- while (!_vm->shouldExit() && !_buttonValue && events.timeElapsed() < 3) {
- events.pollEventsAndWait();
- checkEvents(_vm);
+ // Show clouds ending
+ WOX_VM.showCloudsEnding(g_vm->_finalScore[0]);
+ return true;
}
+ break;
+
+ default:
+ break;
}
+
+ return false;
}
+/*------------------------------------------------------------------------*/
+
+
} // End of namespace WorldOfXeen
} // End of namespace Xeen