From 5f79a8b266cfb1f6c3b052a6431600511e862698 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 1 Jun 2022 20:26:51 -0700 Subject: [PATCH] MM: MM1: Load Xeen UI background --- engines/mm/mm1/mm1.cpp | 51 +++++++++++++++++++++++++++++-- engines/mm/mm1/mm1.h | 4 +++ engines/mm/mm1/views_enh/game.cpp | 13 ++++++-- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/engines/mm/mm1/mm1.cpp b/engines/mm/mm1/mm1.cpp index c90d75b6cce..fd931234dbd 100644 --- a/engines/mm/mm1/mm1.cpp +++ b/engines/mm/mm1/mm1.cpp @@ -22,11 +22,14 @@ #include "common/scummsys.h" #include "common/config-manager.h" #include "common/debug-channels.h" -#include "common/events.h" +#include "common/file.h" +#include "common/system.h" #include "engines/util.h" +#include "graphics/palette.h" #include "mm/mm1/mm1.h" #include "mm/mm1/console.h" #include "mm/mm1/gfx/gfx.h" +#include "mm/xeen/files.h" namespace MM { namespace MM1 { @@ -46,8 +49,15 @@ MM1Engine::~MM1Engine() { Common::Error MM1Engine::run() { // Initialize graphics mode initGraphics(320, 200); - Gfx::GFX::setEgaPalette(0); + if (isEnhanced()) { + if (!setupEnhanced()) + return Common::kNoError; + } else { + setupNormal(); + } + + // Setup console setDebugger(new Console()); // Load globals @@ -58,5 +68,42 @@ Common::Error MM1Engine::run() { return Common::kNoError; } +bool MM1Engine::isEnhanced() const { + return (_gameDescription->features & GF_ENHANCED) != 0; +} + +void MM1Engine::setupNormal() { + Gfx::GFX::setEgaPalette(0); +} + +bool MM1Engine::setupEnhanced() { + if (!Common::File::exists("dark.cc")) { + GUIErrorMessage( + "In order to run in Enhanced mode, please copy dark.cc " + "from a copy of World of Xeen\n" + "or Dark Side of Xeen to your Might and Magic 1 game folder" + ); + + return false; + } + + // Add the Dark Side dark.cc archive + ::MM::Xeen::CCArchive *darkCC = new ::MM::Xeen::CCArchive( + "dark.cc", "dark", true); + SearchMan.add("dark", darkCC); + + // Load the palette + Common::File f; + if (!f.open("dark.pal")) + error("Could not load palette"); + + byte pal[PALETTE_SIZE]; + for (int i = 0; i < PALETTE_SIZE; ++i) + pal[i] = f.readByte() << 2; + g_system->getPaletteManager()->setPalette(pal, 0, PALETTE_COUNT); + + return true; +} + } // End of namespace Xeen } // End of namespace MM diff --git a/engines/mm/mm1/mm1.h b/engines/mm/mm1/mm1.h index 1dce4bd2138..2d1f2dd8d77 100644 --- a/engines/mm/mm1/mm1.h +++ b/engines/mm/mm1/mm1.h @@ -42,6 +42,9 @@ private: // Engine APIs Common::Error run() override; + bool isEnhanced() const; + void setupNormal(); + bool setupEnhanced(); public: Globals _globals; public: @@ -57,6 +60,7 @@ public: int getRandomNumber(int maxNumber) { return _randomSource.getRandomNumber(maxNumber); } + Common::String getTargetName() const { return _targetName; } diff --git a/engines/mm/mm1/views_enh/game.cpp b/engines/mm/mm1/views_enh/game.cpp index 58357a5a110..4589ee6b694 100644 --- a/engines/mm/mm1/views_enh/game.cpp +++ b/engines/mm/mm1/views_enh/game.cpp @@ -19,6 +19,7 @@ * */ +#include "common/file.h" #include "mm/mm1/views_enh/game.h" #include "mm/mm1/globals.h" #include "mm/mm1/meta_engine.h" @@ -42,8 +43,16 @@ bool Game::msgUnfocus(const UnfocusMessage &msg) { } void Game::draw() { - if (_needsRedraw) - clearSurface(); + if (_needsRedraw) { + // Load the Xeen background + Common::File f; + if (!f.open("back.raw")) + error("Could not load background"); + + Graphics::Surface s = getSurface(); + f.read((byte *)s.getPixels(), s.w * s.h); + } + UIElement::draw(); }