[Scummvm-git-logs] scummvm master -> e000b92ab9964f8fbbdcc94a3b046bf1ba422e75
mduggan
mgithub at guarana.org
Sun May 2 00:49:46 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e000b92ab9 ULTIMA8: Add Crusader difficulty selector menu
Commit: e000b92ab9964f8fbbdcc94a3b046bf1ba422e75
https://github.com/scummvm/scummvm/commit/e000b92ab9964f8fbbdcc94a3b046bf1ba422e75
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2021-05-02T09:49:20+09:00
Commit Message:
ULTIMA8: Add Crusader difficulty selector menu
Finally allows also fixing new game creation from within game, and resuming
previous savegame by default like U8 does.
Changed paths:
A engines/ultima/ultima8/gumps/difficulty_gump.cpp
A engines/ultima/ultima8/gumps/difficulty_gump.h
engines/ultima/module.mk
engines/ultima/ultima8/games/remorse_game.cpp
engines/ultima/ultima8/gumps/remorse_menu_gump.cpp
engines/ultima/ultima8/ultima8.cpp
engines/ultima/ultima8/ultima8.h
diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index 120468d620..c6a1c89889 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -460,6 +460,7 @@ MODULE_OBJS := \
ultima8/gumps/cru_status_gump.o \
ultima8/gumps/cru_weapon_gump.o \
ultima8/gumps/desktop_gump.o \
+ ultima8/gumps/difficulty_gump.o \
ultima8/gumps/fast_area_vis_gump.o \
ultima8/gumps/game_map_gump.o \
ultima8/gumps/gump.o \
diff --git a/engines/ultima/ultima8/games/remorse_game.cpp b/engines/ultima/ultima8/games/remorse_game.cpp
index 5a454fd3f1..0d123381c8 100644
--- a/engines/ultima/ultima8/games/remorse_game.cpp
+++ b/engines/ultima/ultima8/games/remorse_game.cpp
@@ -142,7 +142,7 @@ bool RemorseGame::startGame() {
}
bool RemorseGame::startInitialUsecode(int saveSlot) {
- Process* proc = new StartCrusaderProcess();
+ Process* proc = new StartCrusaderProcess(saveSlot);
Kernel::get_instance()->addProcess(proc);
return true;
}
diff --git a/engines/ultima/ultima8/gumps/difficulty_gump.cpp b/engines/ultima/ultima8/gumps/difficulty_gump.cpp
new file mode 100644
index 0000000000..c4db64f3d3
--- /dev/null
+++ b/engines/ultima/ultima8/gumps/difficulty_gump.cpp
@@ -0,0 +1,180 @@
+/* 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 "ultima/ultima8/gumps/difficulty_gump.h"
+#include "ultima/ultima8/graphics/render_surface.h"
+#include "ultima/ultima8/graphics/gump_shape_archive.h"
+#include "ultima/ultima8/graphics/palette_manager.h"
+#include "ultima/ultima8/ultima8.h"
+#include "ultima/ultima8/games/game_data.h"
+#include "ultima/ultima8/graphics/shape.h"
+#include "ultima/ultima8/graphics/shape_frame.h"
+
+namespace Ultima {
+namespace Ultima8 {
+
+DEFINE_RUNTIME_CLASSTYPE_CODE(DifficultyGump)
+
+DifficultyGump::DifficultyGump()
+ : ModalGump(0, 0, 5, 5), _highlighted(3), _buttonWidth(0),
+ _buttonHeight(0) {
+}
+
+DifficultyGump::~DifficultyGump() {
+}
+
+static const int BUTTON_X = 158;
+static const int BUTTON_Y = 120;
+static const int BUTTON_SPACE = 17;
+static const int BUTTON_HEIGHT = 42;
+static const int RIGHT_FRAME_IDX_OFFSET = 16;
+
+
+// gumps: 73: "difficulty level"
+// 74-77: levels, 2 frames per level (left/right)
+
+void DifficultyGump::InitGump(Gump *newparent, bool take_focus) {
+ ModalGump::InitGump(newparent, take_focus);
+
+ _dims.top = 0;
+ _dims.left = 0;
+ _dims.bottom = 480;
+ _dims.right = 640;
+
+ GumpShapeArchive *shapeArchive = GameData::get_instance()->getGumps();
+
+ Shape *difficultyLevel = shapeArchive->getShape(73);
+
+ Shape *levelShape[4];
+ for (int s = 74; s < 78; s++) {
+ levelShape[s - 74] = shapeArchive->getShape(s);
+ }
+
+ if (!difficultyLevel || !levelShape[0] || !levelShape[1] ||
+ !levelShape[2] || !levelShape[3]) {
+ error("Couldn't load shapes for difficulty level");
+ return;
+ }
+
+ PaletteManager *palman = PaletteManager::get_instance();
+ assert(palman);
+ const Palette *pal = palman->getPalette(PaletteManager::Pal_Diff);
+ assert(pal);
+ difficultyLevel->setPalette(pal);
+ for (int s = 0; s < 4; s++) {
+ levelShape[s]->setPalette(pal);
+ }
+
+ const ShapeFrame *difficultyFrame = difficultyLevel->getFrame(0);
+ if (!difficultyFrame) {
+ error("Couldn't load shape frame for difficulty level");
+ return;
+ }
+ Gump *diffGump = new Gump(185, 77, difficultyFrame->_width, difficultyFrame->_height);
+ diffGump->SetShape(difficultyLevel, 0);
+ diffGump->InitGump(this, false);
+
+ for (int s = 0; s < 4; s++) {
+ const int y = BUTTON_Y + (BUTTON_SPACE + BUTTON_HEIGHT) * s;
+ const ShapeFrame *leftFrame = levelShape[s]->getFrame(0);
+ const ShapeFrame *rightFrame = levelShape[s]->getFrame(1);
+ if (!leftFrame || !rightFrame) {
+ error("Couldn't load shape frame for difficulty level %d", s);
+ return;
+ }
+ Gump *lGump = new Gump(BUTTON_X, y, leftFrame->_width, leftFrame->_height);
+ lGump->SetShape(levelShape[s], 0);
+ lGump->InitGump(this, false);
+ lGump->SetIndex(s + 1);
+ Gump *rGump = new Gump(BUTTON_X + leftFrame->_width, y, rightFrame->_width, rightFrame->_height);
+ rGump->SetShape(levelShape[s], 1);
+ rGump->InitGump(this, false);
+ rGump->SetIndex(s + 1 + RIGHT_FRAME_IDX_OFFSET);
+
+ _buttonHeight = MAX(_buttonHeight, leftFrame->_height);
+ _buttonHeight = MAX(_buttonHeight, rightFrame->_height);
+ _buttonWidth = MAX(_buttonWidth, leftFrame->_width + rightFrame->_width);
+ }
+
+ // remove focus from children (just in case)
+ if (_focusChild) _focusChild->OnFocus(false);
+ _focusChild = 0;
+}
+
+void DifficultyGump::Close(bool no_del) {
+ ModalGump::Close(no_del);
+}
+
+void DifficultyGump::OnFocus(bool gain) {
+}
+
+void DifficultyGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled) {
+ // Paint a highlight around the current level
+ int highlihght_y = BUTTON_Y + ((_highlighted - 1) * (BUTTON_SPACE + BUTTON_HEIGHT));
+ surf->Fill32(0xFF808080, BUTTON_X - 1, highlihght_y - 1, _buttonWidth + 2, _buttonHeight + 2);
+ ModalGump::PaintThis(surf, lerp_factor, scaled);
+}
+
+void DifficultyGump::onMouseClick(int button, int32 mx, int32 my) {
+ if (button == Shared::BUTTON_LEFT) {
+ Gump *gump = FindGump(mx, my);
+ if (gump && gump->GetIndex() > 0) {
+ int idx = gump->GetIndex();
+ if (idx > RIGHT_FRAME_IDX_OFFSET)
+ idx -= RIGHT_FRAME_IDX_OFFSET;
+ selectEntry(idx);
+ }
+ }
+}
+
+bool DifficultyGump::OnKeyDown(int key, int mod) {
+ if (ModalGump::OnKeyDown(key, mod)) return true;
+
+ if (key == Common::KEYCODE_ESCAPE) {
+ Close();
+ } else if (key >= Common::KEYCODE_1 && key <= Common::KEYCODE_4) {
+ selectEntry(key - Common::KEYCODE_1 + 1);
+ } else if (key == Common::KEYCODE_UP) {
+ _highlighted--;
+ if (_highlighted < 1)
+ _highlighted = 4;
+ } else if (key == Common::KEYCODE_DOWN) {
+ _highlighted++;
+ if (_highlighted > 4)
+ _highlighted = 1;
+ } else if (key == Common::KEYCODE_RETURN) {
+ selectEntry(_highlighted);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+void DifficultyGump::selectEntry(int num) {
+ debug(6, "select entry %d", num);
+ Ultima8Engine::get_instance()->newGame(-1, num);
+ // note; this is now deleted (the kernel will kill it)
+}
+
+} // End of namespace Ultima8
+} // End of namespace Ultima
diff --git a/engines/ultima/ultima8/gumps/difficulty_gump.h b/engines/ultima/ultima8/gumps/difficulty_gump.h
new file mode 100644
index 0000000000..174c012835
--- /dev/null
+++ b/engines/ultima/ultima8/gumps/difficulty_gump.h
@@ -0,0 +1,62 @@
+/* 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 ULTIMA8_GUMPS_DIFFICULTYGUMP_H
+#define ULTIMA8_GUMPS_DIFFICULTYGUMP_H
+
+#include "ultima/ultima8/gumps/modal_gump.h"
+
+namespace Ultima {
+namespace Ultima8 {
+
+/**
+ * Difficulty selector menu for Crusader: No Remorse
+ */
+class DifficultyGump : public ModalGump {
+public:
+ ENABLE_RUNTIME_CLASSTYPE()
+
+ DifficultyGump();
+ ~DifficultyGump() override;
+
+ void InitGump(Gump *newparent, bool take_focus = true) override;
+ void Close(bool no_del = false) override;
+
+ void onMouseClick(int button, int32 mx, int32 my) override;
+ bool OnKeyDown(int key, int mod) override;
+ void OnFocus(bool gain) override;
+ void PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled) override;
+
+ static Gump *showLoadSaveGump(Gump *parent, bool save);
+
+private:
+ int _highlighted;
+ int _buttonWidth;
+ int _buttonHeight;
+
+ void selectEntry(int num);
+};
+
+} // End of namespace Ultima8
+} // End of namespace Ultima
+
+#endif
diff --git a/engines/ultima/ultima8/gumps/remorse_menu_gump.cpp b/engines/ultima/ultima8/gumps/remorse_menu_gump.cpp
index 64e38ee4ba..4879b562a4 100644
--- a/engines/ultima/ultima8/gumps/remorse_menu_gump.cpp
+++ b/engines/ultima/ultima8/gumps/remorse_menu_gump.cpp
@@ -29,6 +29,7 @@
#include "ultima/ultima8/kernel/mouse.h"
#include "ultima/ultima8/gumps/widgets/button_widget.h"
#include "ultima/ultima8/gumps/quit_gump.h"
+#include "ultima/ultima8/gumps/difficulty_gump.h"
#include "ultima/ultima8/games/game.h"
#include "ultima/ultima8/world/actors/main_actor.h"
#include "ultima/ultima8/graphics/palette_manager.h"
@@ -193,9 +194,12 @@ void RemorseMenuGump::ChildNotify(Gump *child, uint32 message) {
void RemorseMenuGump::selectEntry(int entry) {
switch (entry) {
- case 1: // New Game
- Game::get_instance()->playIntroMovie(true);
+ case 1: { // New Game
+ DifficultyGump *gump = new DifficultyGump();
+ gump->InitGump(0);
+ gump->setRelativePosition(CENTER);
break;
+ }
case 2:
Ultima8Engine::get_instance()->loadGameDialog();
break;
diff --git a/engines/ultima/ultima8/ultima8.cpp b/engines/ultima/ultima8/ultima8.cpp
index 890abc3c61..6ba598347b 100644
--- a/engines/ultima/ultima8/ultima8.cpp
+++ b/engines/ultima/ultima8/ultima8.cpp
@@ -30,6 +30,7 @@
#include "ultima/ultima8/filesys/file_system.h"
#include "ultima/ultima8/kernel/object_manager.h"
#include "ultima/ultima8/games/start_u8_process.h"
+#include "ultima/ultima8/games/start_crusader_process.h"
#include "ultima/ultima8/graphics/fonts/font_manager.h"
#include "ultima/ultima8/graphics/render_surface.h"
#include "ultima/ultima8/games/game_data.h"
@@ -870,7 +871,8 @@ bool Ultima8Engine::canSaveGameStateCurrently(bool isAutosave) {
}
- if (dynamic_cast<StartU8Process *>(_kernel->getRunningProcess()))
+ if (dynamic_cast<StartU8Process *>(_kernel->getRunningProcess())
+ || dynamic_cast<StartCrusaderProcess *>(_kernel->getRunningProcess()))
// Don't save while starting up.
return false;
@@ -1075,8 +1077,8 @@ void Ultima8Engine::setupCoreGumps() {
_objectManager->reserveObjId(i);
}
-bool Ultima8Engine::newGame(int saveSlot) {
- debugN(MM_INFO, "Starting New Game...\n");
+bool Ultima8Engine::newGame(int saveSlot, int difficulty) {
+ debugN(MM_INFO, "Starting New Game (slot %d difficulty %d)... \n", saveSlot, difficulty);
// First validate we still have a save file for the slot
if (saveSlot != -1) {
@@ -1119,6 +1121,10 @@ bool Ultima8Engine::newGame(int saveSlot) {
_game->startInitialUsecode(saveSlot);
+ if (difficulty > 0) {
+ _world->get_instance()->setGameDifficulty(difficulty);
+ }
+
if (GAME_IS_CRUSADER) {
_kernel->addProcess(new TargetReticleProcess());
_kernel->addProcess(new ItemSelectionProcess());
diff --git a/engines/ultima/ultima8/ultima8.h b/engines/ultima/ultima8/ultima8.h
index 7783b7df47..b72dec55ae 100644
--- a/engines/ultima/ultima8/ultima8.h
+++ b/engines/ultima/ultima8/ultima8.h
@@ -334,7 +334,7 @@ public:
//! start a new game
//! \return true if succesful.
- bool newGame(int saveSlot = -1);
+ bool newGame(int saveSlot = -1, int difficulty = -1);
//! Enter gump text mode (aka Unicode keyhandling)
void enterTextMode(Gump *);
More information about the Scummvm-git-logs
mailing list