[Scummvm-git-logs] scummvm master -> fcce523edb5f8ce1f96d57aaab7271ecc56b6d75
dreammaster
noreply at scummvm.org
Sat Jun 3 04:41:56 UTC 2023
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:
fcce523edb MM: MM1: Properly implement views for fly spell
Commit: fcce523edb5f8ce1f96d57aaab7271ecc56b6d75
https://github.com/scummvm/scummvm/commit/fcce523edb5f8ce1f96d57aaab7271ecc56b6d75
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-06-02T21:41:46-07:00
Commit Message:
MM: MM1: Properly implement views for fly spell
Changed paths:
A engines/mm/mm1/game/fly.cpp
A engines/mm/mm1/game/fly.h
A engines/mm/mm1/views_enh/spells/fly.cpp
A engines/mm/mm1/views_enh/spells/fly.h
engines/mm/mm1/game/spells_party.cpp
engines/mm/mm1/views/spells/fly.cpp
engines/mm/mm1/views/spells/fly.h
engines/mm/mm1/views_enh/dialogs.h
engines/mm/module.mk
diff --git a/engines/mm/mm1/game/fly.cpp b/engines/mm/mm1/game/fly.cpp
new file mode 100644
index 00000000000..5cbe3f9c365
--- /dev/null
+++ b/engines/mm/mm1/game/fly.cpp
@@ -0,0 +1,70 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "mm/mm1/game/fly.h"
+#include "mm/mm1/globals.h"
+
+namespace MM {
+namespace MM1 {
+namespace Game {
+
+static const byte FLY_MAP_ID1[20] = {
+ 1, 0, 4, 5, 0x12,
+ 2, 3, 0x11, 5, 6,
+ 2, 1, 4, 6, 0x1A,
+ 3, 3, 4, 1, 0x1B
+};
+
+static const byte FLY_MAP_ID2[20] = {
+ 0xF, 0xA, 3, 5, 1,
+ 5, 7, 0xA, 0xB, 7,
+ 0xB, 1, 9, 1, 0xB,
+ 1, 0xD, 0xF, 8, 1
+};
+
+static const byte FLY_MAP_X[20] = {
+ 15, 8, 11, 0, 9,
+ 15, 3, 10, 4, 11,
+ 15, 3, 3, 7, 12,
+ 14, 11, 5, 7, 15
+};
+
+static const byte FLY_MAP_Y[20] = {
+ 7, 10, 0, 8, 11,
+ 7, 2, 10, 0, 0,
+ 15, 3, 9, 0, 6,
+ 14, 15, 15, 7, 15
+};
+
+void Fly::fly(int mapIndex) {
+ if (mapIndex != -1) {
+ Maps::Maps &maps = *g_maps;
+ int id = FLY_MAP_ID1[mapIndex] | ((int)FLY_MAP_ID2[mapIndex] << 8);
+
+ maps._mapPos.x = FLY_MAP_X[mapIndex];
+ maps._mapPos.y = FLY_MAP_Y[mapIndex];
+ maps.changeMap(id, 2);
+ }
+}
+
+} // namespace Game
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/game/fly.h b/engines/mm/mm1/game/fly.h
new file mode 100644
index 00000000000..f9c55312157
--- /dev/null
+++ b/engines/mm/mm1/game/fly.h
@@ -0,0 +1,43 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MM1_GAME_FLY_H
+#define MM1_GAME_FLY_H
+
+#include "common/rect.h"
+
+namespace MM {
+namespace MM1 {
+namespace Game {
+
+class Fly {
+protected:
+ /**
+ * Handles teleporting to the given map
+ */
+ void fly(int mapIndex);
+};
+
+} // namespace Game
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/mm1/game/spells_party.cpp b/engines/mm/mm1/game/spells_party.cpp
index 1c4caa7fba2..ad2070a7625 100644
--- a/engines/mm/mm1/game/spells_party.cpp
+++ b/engines/mm/mm1/game/spells_party.cpp
@@ -135,34 +135,6 @@ SpellsParty::SpellFn SpellsParty::SPELLS[SPELLS_COUNT] = {
wizard75_prismaticLight
};
-byte FLY_MAP_ID1[20] = {
- 1, 0, 4, 5, 0x12,
- 2, 3, 0x11, 5, 6,
- 2, 1, 4, 6, 0x1A,
- 3, 3, 4, 1, 0x1B
-};
-
-byte FLY_MAP_ID2[20] = {
- 0xF, 0xA, 3, 5, 1,
- 5, 7, 0xA, 0xB, 7,
- 0xB, 1, 9, 1, 0xB,
- 1, 0xD, 0xF, 8, 1
-};
-
-byte FLY_MAP_X[20] = {
- 15, 8, 11, 0, 9,
- 15, 3, 10, 4, 11,
- 15, 3, 3, 7, 12,
- 14, 11, 5, 7, 15
-};
-
-byte FLY_MAP_Y[20] = {
- 7, 10, 0, 8, 11,
- 7, 2, 10, 0, 0,
- 15, 3, 9, 0, 6,
- 14, 15, 15, 7, 15
-};
-
SpellResult SpellsParty::cast(uint spell, Character *destChar) {
assert(spell < SPELLS_COUNT);
_destChar = destChar;
@@ -787,19 +759,7 @@ SpellResult SpellsParty::wizard31_fireball() {
}
SpellResult SpellsParty::wizard32_fly() {
- Views::Spells::Fly::show(
- [](int mapIndex) {
- if (mapIndex != -1) {
- Maps::Maps &maps = *g_maps;
- int id = FLY_MAP_ID1[mapIndex] | ((int)FLY_MAP_ID2[mapIndex] << 8);
-
- maps._mapPos.x = FLY_MAP_X[mapIndex];
- maps._mapPos.y = FLY_MAP_Y[mapIndex];
- maps.changeMap(id, 2);
- }
- }
- );
-
+ g_events->addView("Fly");
return SR_SUCCESS_SILENT;
}
diff --git a/engines/mm/mm1/views/spells/fly.cpp b/engines/mm/mm1/views/spells/fly.cpp
index fcf4195c359..549159a38db 100644
--- a/engines/mm/mm1/views/spells/fly.cpp
+++ b/engines/mm/mm1/views/spells/fly.cpp
@@ -27,14 +27,6 @@ namespace MM1 {
namespace Views {
namespace Spells {
-void Fly::show(FlyCallback callback) {
- Fly *fly = dynamic_cast<Fly *>(g_events->findView("Fly"));
- assert(fly);
-
- fly->_callback = callback;
- fly->open();
-}
-
Fly::Fly() : SpellView("Fly") {
_bounds = getLineBounds(21, 24);
}
@@ -78,12 +70,6 @@ bool Fly::msgKeypress(const KeypressMessage &msg) {
_mode = CAST;
_yIndex = msg.keycode - Common::KEYCODE_1;
redraw();
-
- } else if (_mode == CAST && msg.keycode == Common::KEYCODE_RETURN) {
- // Spell was cast
- close();
- int mapIndex = _yIndex * 5 + _xIndex;
- _callback(mapIndex);
}
return true;
@@ -92,8 +78,14 @@ bool Fly::msgKeypress(const KeypressMessage &msg) {
bool Fly::msgAction(const ActionMessage &msg) {
if (msg._action == KEYBIND_ESCAPE) {
close();
- _callback(-1);
+ fly(-1);
return true;
+
+ } else if (_mode == CAST && msg._action == KEYBIND_SELECT) {
+ // Spell was cast
+ close();
+ int mapIndex = _yIndex * 5 + _xIndex;
+ fly(mapIndex);
}
return false;
diff --git a/engines/mm/mm1/views/spells/fly.h b/engines/mm/mm1/views/spells/fly.h
index cdf5abdede6..006d1c0c5d4 100644
--- a/engines/mm/mm1/views/spells/fly.h
+++ b/engines/mm/mm1/views/spells/fly.h
@@ -23,32 +23,19 @@
#define MM1_VIEWS_SPELLS_FLY_H
#include "mm/mm1/views/spells/spell_view.h"
+#include "mm/mm1/game/fly.h"
namespace MM {
namespace MM1 {
namespace Views {
namespace Spells {
-/**
- * Callback that specifies the map selected,
- * or -1 if escape was pressed
- */
-typedef void (*FlyCallback)(int mapId);
-
-class Fly : public SpellView {
+class Fly : public SpellView, public MM1::Game::Fly {
private:
- FlyCallback _callback;
- enum Mode {
- SELECT_X, SELECT_Y, CAST
- };
+ enum Mode { SELECT_X, SELECT_Y, CAST };
Mode _mode = SELECT_X;
int _xIndex = 0, _yIndex = 0;
-public:
- /**
- * Show the view
- */
- static void show(FlyCallback callback);
public:
/**
* Constructor
diff --git a/engines/mm/mm1/views_enh/dialogs.h b/engines/mm/mm1/views_enh/dialogs.h
index f63678cef85..45e67c168a8 100644
--- a/engines/mm/mm1/views_enh/dialogs.h
+++ b/engines/mm/mm1/views_enh/dialogs.h
@@ -87,6 +87,7 @@
#include "mm/mm1/views_enh/locations/training.h"
#include "mm/mm1/views_enh/spells/cast_spell.h"
#include "mm/mm1/views_enh/spells/spellbook.h"
+#include "mm/mm1/views_enh/spells/fly.h"
#include "mm/mm1/views_enh/spells/location.h"
namespace MM {
@@ -138,6 +139,7 @@ private:
ViewsEnh::Locations::Training _training;
ViewsEnh::Spells::CastSpell _castSpell;
ViewsEnh::Spells::Spellbook _spellbook;
+ ViewsEnh::Spells::Fly _fly;
ViewsEnh::Spells::Location _location;
ViewsEnh::CharacterInfo _characterInfo;
ViewsEnh::CharacterInfoCombat _characterInfoCombat;
diff --git a/engines/mm/mm1/views_enh/spells/fly.cpp b/engines/mm/mm1/views_enh/spells/fly.cpp
new file mode 100644
index 00000000000..d10ce4e67ba
--- /dev/null
+++ b/engines/mm/mm1/views_enh/spells/fly.cpp
@@ -0,0 +1,110 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "mm/mm1/views_enh/spells/fly.h"
+#include "mm/mm1/globals.h"
+
+#define TEXT_X1 160
+#define TEXT_X2 195
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+namespace Spells {
+
+#define TEXT_X 120
+
+Fly::Fly() : ScrollView("Fly") {
+ setBounds(Common::Rect(0, 144, 234, 200));
+ addButton(&g_globals->_escSprites, Common::Point(5, 28), 0, KEYBIND_ESCAPE, true);
+}
+
+bool Fly::msgFocus(const FocusMessage &msg) {
+ ScrollView::msgFocus(msg);
+
+ _mode = SELECT_X;
+ _xIndex = _yIndex = 0;
+ return 0;
+}
+
+void Fly::draw() {
+ ScrollView::draw();
+
+ setReduced(true);
+ writeString(20, 30, STRING["enhdialogs.misc.go_back"]);
+
+ writeLine(0, STRING["dialogs.spells.fly_to_x"], ALIGN_RIGHT, TEXT_X);
+ writeChar((_mode == SELECT_X) ? '_' : 'A' + _xIndex);
+
+ if (_mode == SELECT_Y || _mode == CAST) {
+ writeLine(1, STRING["dialogs.spells.fly_to_y"], ALIGN_RIGHT, TEXT_X);
+ writeChar((_mode == SELECT_Y) ? '_' : '1' + _yIndex);
+ }
+
+ setReduced(false);
+}
+
+bool Fly::msgKeypress(const KeypressMessage &msg) {
+ if (_mode == SELECT_X && msg.keycode >= Common::KEYCODE_a
+ && msg.keycode <= Common::KEYCODE_d) {
+ // X map selected
+ _mode = SELECT_Y;
+ _xIndex = msg.keycode - Common::KEYCODE_a;
+ redraw();
+
+ } else if (_mode == SELECT_Y && msg.keycode >= Common::KEYCODE_1
+ && msg.keycode <= Common::KEYCODE_4) {
+ // Y map selected
+ _mode = CAST;
+ _yIndex = msg.keycode - Common::KEYCODE_1;
+
+ delaySeconds(1);
+ redraw();
+ }
+
+ return true;
+}
+
+bool Fly::msgAction(const ActionMessage &msg) {
+ if (endDelay())
+ return true;
+
+ if (msg._action == KEYBIND_ESCAPE) {
+ cancelDelay();
+ g_events->replaceView("Game", true);
+ fly(-1);
+ return true;
+ }
+
+ return false;
+}
+
+void Fly::timeout() {
+ // Spell was cast
+ g_events->replaceView("Game", true);
+ int mapIndex = _yIndex * 5 + _xIndex;
+ fly(mapIndex);
+}
+
+} // namespace Spells
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/views_enh/spells/fly.h b/engines/mm/mm1/views_enh/spells/fly.h
new file mode 100644
index 00000000000..d02192a9c1e
--- /dev/null
+++ b/engines/mm/mm1/views_enh/spells/fly.h
@@ -0,0 +1,81 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MM1_VIEWS_ENH_SPELLS_FLY_H
+#define MM1_VIEWS_ENH_SPELLS_FLY_H
+
+#include "mm/mm1/views_enh/scroll_view.h"
+#include "mm/mm1/game/fly.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+namespace Spells {
+
+class Fly : public ScrollView, public MM1::Game::Fly {
+private:
+ enum Mode { SELECT_X, SELECT_Y, CAST };
+ Mode _mode = SELECT_X;
+ int _xIndex = 0, _yIndex = 0;
+
+public:
+ /**
+ * Constructor
+ */
+ Fly();
+
+ /**
+ * Destructor
+ */
+ virtual ~Fly() {}
+
+ /**
+ * Show the view
+ */
+ bool msgFocus(const FocusMessage &) override;
+
+ /**
+ * Draw the view contents
+ */
+ void draw() override;
+
+ /**
+ * Keypress handler
+ */
+ bool msgKeypress(const KeypressMessage &msg) override;
+
+ /**
+ * Action handler
+ */
+ bool msgAction(const ActionMessage &msg) override;
+
+ /**
+ * Timeout handler
+ */
+ void timeout() override;
+};
+
+} // namespace Spells
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index eeaf4def54a..db98e669b93 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -42,6 +42,7 @@ MODULE_OBJS += \
mm1/game/combat.o \
mm1/game/encounter.o \
mm1/game/equip_remove.o \
+ mm1/game/fly.o \
mm1/game/leprechaun.o \
mm1/game/monster_touch.o \
mm1/game/rest.o \
@@ -134,6 +135,7 @@ MODULE_OBJS += \
mm1/views/wheel_spin.o \
mm1/views_enh/spells/cast_spell.o \
mm1/views_enh/spells/spellbook.o \
+ mm1/views_enh/spells/fly.o \
mm1/views_enh/spells/location.o \
mm1/views_enh/button_container.o \
mm1/views_enh/character_base.o \
More information about the Scummvm-git-logs
mailing list