[Scummvm-git-logs] scummvm master -> e548fd5be3de24602ac1b9daae869c8cc37fd2bc

dreammaster noreply at scummvm.org
Sun Jun 4 05:37:17 UTC 2023


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c80f16628b MM: MM1: Fixes for original Recharge Item view
30f4adf46b MM: MM1: Added Recharge Item views
e548fd5be3 MM: MM1: Finished teleport spell views


Commit: c80f16628b4c7769814851a42188dcc0b3c05cac
    https://github.com/scummvm/scummvm/commit/c80f16628b4c7769814851a42188dcc0b3c05cac
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-06-03T18:51:32-07:00

Commit Message:
MM: MM1: Fixes for original Recharge Item view

Changed paths:
    engines/mm/mm1/game/spells_party.cpp
    engines/mm/mm1/views/spells/recharge_item.cpp
    engines/mm/mm1/views/spells/recharge_item.h
    engines/mm/mm1/views/spells/spell_view.cpp


diff --git a/engines/mm/mm1/game/spells_party.cpp b/engines/mm/mm1/game/spells_party.cpp
index 4fd06cc1930..d0440835019 100644
--- a/engines/mm/mm1/game/spells_party.cpp
+++ b/engines/mm/mm1/game/spells_party.cpp
@@ -921,6 +921,7 @@ SpellResult SpellsParty::wizard64_protectionFromMagic() {
 }
 
 SpellResult SpellsParty::wizard65_rechargeItem() {
+	g_events->replaceView("RechargeItem");
 	return SR_FAILED;
 }
 
diff --git a/engines/mm/mm1/views/spells/recharge_item.cpp b/engines/mm/mm1/views/spells/recharge_item.cpp
index 79a6c9fe807..e827c35944b 100644
--- a/engines/mm/mm1/views/spells/recharge_item.cpp
+++ b/engines/mm/mm1/views/spells/recharge_item.cpp
@@ -28,13 +28,6 @@ namespace MM1 {
 namespace Views {
 namespace Spells {
 
-void RechargeItem::show() {
-	UIElement *view = dynamic_cast<RechargeItem *>(g_events->findView("RechargeItem"));
-	assert(view);
-
-	view->open();
-}
-
 RechargeItem::RechargeItem() : SpellView("RechargeItem") {
 	_bounds = getLineBounds(20, 24);
 }
@@ -43,7 +36,7 @@ void RechargeItem::draw() {
 	clearSurface();
 	escToGoBack(0);
 
-	writeString(10, 0, STRING["dialogs.charcater.which_item"]);
+	writeString(10, 0, STRING["dialogs.character.which"]);
 }
 
 bool RechargeItem::msgKeypress(const KeypressMessage &msg) {
@@ -64,6 +57,7 @@ bool RechargeItem::msgKeypress(const KeypressMessage &msg) {
 				inv[itemIndex]._charges +
 				g_engine->getRandomNumber(4),
 				(int)item->_maxCharges);
+			spellDone();
 		}
 	}
 
diff --git a/engines/mm/mm1/views/spells/recharge_item.h b/engines/mm/mm1/views/spells/recharge_item.h
index 4982b08efc7..37d81042738 100644
--- a/engines/mm/mm1/views/spells/recharge_item.h
+++ b/engines/mm/mm1/views/spells/recharge_item.h
@@ -30,11 +30,6 @@ namespace Views {
 namespace Spells {
 
 class RechargeItem : public SpellView {
-public:
-	/**
-	 * Show the view
-	 */
-	static void show();
 public:
 	/**
 	 * Constructor
diff --git a/engines/mm/mm1/views/spells/spell_view.cpp b/engines/mm/mm1/views/spells/spell_view.cpp
index 6100eacf38c..ca74c73f98c 100644
--- a/engines/mm/mm1/views/spells/spell_view.cpp
+++ b/engines/mm/mm1/views/spells/spell_view.cpp
@@ -39,7 +39,7 @@ void SpellView::spellFailed() {
 
 void SpellView::spellDone() {
 	clearSurface();
-	writeString(14, 2, STRING["dialogs.misc.done"]);
+	writeString(14, 2, STRING["spells.done"]);
 	g_globals->_party.updateAC();
 
 	Sound::sound(SOUND_2);


Commit: 30f4adf46b2d3ca45ba4170b25d64f54d7913eeb
    https://github.com/scummvm/scummvm/commit/30f4adf46b2d3ca45ba4170b25d64f54d7913eeb
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-06-03T20:49:22-07:00

Commit Message:
MM: MM1: Added Recharge Item views

Changed paths:
  A engines/mm/mm1/game/recharge_item.cpp
  A engines/mm/mm1/game/recharge_item.h
  A engines/mm/mm1/views_enh/spells/recharge_item.cpp
  A engines/mm/mm1/views_enh/spells/recharge_item.h
    devtools/create_mm/files/mm1/strings_en.yml
    engines/mm/mm1/views/spells/recharge_item.cpp
    engines/mm/mm1/views/spells/recharge_item.h
    engines/mm/mm1/views_enh/character_inventory.cpp
    engines/mm/mm1/views_enh/character_inventory.h
    engines/mm/mm1/views_enh/dialogs.h
    engines/mm/mm1/views_enh/items_view.h
    engines/mm/module.mk


diff --git a/devtools/create_mm/files/mm1/strings_en.yml b/devtools/create_mm/files/mm1/strings_en.yml
index 766edfaf47a..9c7207567d8 100644
--- a/devtools/create_mm/files/mm1/strings_en.yml
+++ b/devtools/create_mm/files/mm1/strings_en.yml
@@ -563,6 +563,7 @@ enhdialogs:
 		remove: "Remove"
 		discard: "Discard"
 		use: "Use"
+		charge: "Charge"
 		buttons:
 		buttons:
 			weapons: "\x01""37Weap"
@@ -579,6 +580,7 @@ enhdialogs:
 			discard: "\x01""37Disc"
 			trade: "\x01""37Trade"		
 			use: "\x01""37Use"
+			charge: "\x01""37Charg"
 	location:
 		store: "Store"
 		options: "options"
diff --git a/engines/mm/mm1/game/recharge_item.cpp b/engines/mm/mm1/game/recharge_item.cpp
new file mode 100644
index 00000000000..d570952f46e
--- /dev/null
+++ b/engines/mm/mm1/game/recharge_item.cpp
@@ -0,0 +1,48 @@
+/* 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/recharge_item.h"
+#include "mm/mm1/data/character.h"
+#include "mm/mm1/globals.h"
+
+namespace MM {
+namespace MM1 {
+namespace Game {
+
+bool RechargeItem::charge(Inventory &inv, int itemIndex) {
+	const Item &item = *g_globals->_items.getItem(inv[itemIndex]._id);
+
+	if (getRandomNumber(100) == 100) {
+		// OMG: The original seriously had this fringe
+		// case that happens so rarely
+		inv.removeAt(itemIndex);	// Break item
+		return false;
+
+	} else {
+		inv[itemIndex]._charges = MIN(inv[itemIndex]._charges + getRandomNumber(4),
+			(int)item._maxCharges);
+		return true;
+	}
+}
+
+} // namespace Game
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/game/recharge_item.h b/engines/mm/mm1/game/recharge_item.h
new file mode 100644
index 00000000000..7c9848a451a
--- /dev/null
+++ b/engines/mm/mm1/game/recharge_item.h
@@ -0,0 +1,46 @@
+/* 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_RECHARGE_ITEM_H
+#define MM1_GAME_RECHARGE_ITEM_H
+
+#include "mm/mm1/game/game_logic.h"
+#include "mm/mm1/data/character.h"
+#include "mm/mm1/data/items.h"
+
+namespace MM {
+namespace MM1 {
+namespace Game {
+
+class RechargeItem : public GameLogic {
+protected:
+	/**
+	 * Charge a given item
+	 * @returns Returns true if the spell succeeded
+	 */
+	bool charge(Inventory &inv, int itemIndex);
+};
+
+} // namespace Game
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/mm1/views/spells/recharge_item.cpp b/engines/mm/mm1/views/spells/recharge_item.cpp
index e827c35944b..9fbf13c5bfd 100644
--- a/engines/mm/mm1/views/spells/recharge_item.cpp
+++ b/engines/mm/mm1/views/spells/recharge_item.cpp
@@ -45,19 +45,11 @@ bool RechargeItem::msgKeypress(const KeypressMessage &msg) {
 	if (msg.keycode >= Common::KEYCODE_a &&
 			msg.keycode < (Common::KEYCODE_a + (int)inv.size())) {
 		int itemIndex = msg.keycode - Common::KEYCODE_a;
-		Item *item = g_globals->_items.getItem(inv[itemIndex]._id);
 
-		if (g_engine->getRandomNumber(100) == 100) {
-			// OMG: The original seriously had this fringe
-			// case that happens so rarely
-			inv.removeAt(itemIndex);	// Break item
-			spellFailed();
-		} else {
-			inv[itemIndex]._charges = MIN(
-				inv[itemIndex]._charges +
-				g_engine->getRandomNumber(4),
-				(int)item->_maxCharges);
+		if (charge(inv, itemIndex)) {
 			spellDone();
+		} else {
+			spellFailed();
 		}
 	}
 
@@ -66,7 +58,7 @@ bool RechargeItem::msgKeypress(const KeypressMessage &msg) {
 
 bool RechargeItem::msgAction(const ActionMessage &msg) {
 	if (msg._action == KEYBIND_ESCAPE) {
-		spellFailed();
+		close();
 		return true;
 	}
 
diff --git a/engines/mm/mm1/views/spells/recharge_item.h b/engines/mm/mm1/views/spells/recharge_item.h
index 37d81042738..bd3449c756c 100644
--- a/engines/mm/mm1/views/spells/recharge_item.h
+++ b/engines/mm/mm1/views/spells/recharge_item.h
@@ -23,13 +23,14 @@
 #define MM1_VIEWS_SPELLS_RECHARGE_ITEM_H
 
 #include "mm/mm1/views/spells/spell_view.h"
+#include "mm/mm1/game/recharge_item.h"
 
 namespace MM {
 namespace MM1 {
 namespace Views {
 namespace Spells {
 
-class RechargeItem : public SpellView {
+class RechargeItem : public SpellView, public MM1::Game::RechargeItem {
 public:
 	/**
 	 * Constructor
diff --git a/engines/mm/mm1/views_enh/character_inventory.cpp b/engines/mm/mm1/views_enh/character_inventory.cpp
index 9011d5f06a2..3102598cb51 100644
--- a/engines/mm/mm1/views_enh/character_inventory.cpp
+++ b/engines/mm/mm1/views_enh/character_inventory.cpp
@@ -32,6 +32,14 @@ namespace MM1 {
 namespace ViewsEnh {
 
 CharacterInventory::CharacterInventory() : ItemsView("CharacterInventory") {
+	setup();
+}
+
+CharacterInventory::CharacterInventory(const Common::String &name) : ItemsView(name) {
+	setup();
+}
+
+void CharacterInventory::setup() {
 	_btnSprites.load("items.icn");
 	addButton(2, STRING["enhdialogs.items.buttons.arms"], Common::KEYCODE_a);
 	addButton(6, STRING["enhdialogs.items.buttons.backpack"], Common::KEYCODE_b);
@@ -48,7 +56,7 @@ bool CharacterInventory::msgFocus(const FocusMessage &msg) {
 	assert(g_globals->_currCharacter);
 
 	bool inCombat = g_events->isInCombat();
-	for (int i = 2; i < 7; ++i)
+	for (int i = 2; i < ((int)getButtonCount() - 1); ++i)
 		setButtonEnabled(i, !inCombat);
 
 	if (dynamic_cast<WhichItem *>(msg._priorView) == nullptr &&
@@ -199,6 +207,7 @@ void CharacterInventory::selectButton(SelectedButton btnMode) {
 
 	if (_selectedItem != -1) {
 		performAction();
+
 	} else {
 		Common::String btn = STRING["enhdialogs.items.equip"];
 		if (btnMode == BTN_REMOVE)
@@ -207,6 +216,8 @@ void CharacterInventory::selectButton(SelectedButton btnMode) {
 			btn = STRING["enhdialogs.items.discard"];
 		else if (btnMode == BTN_USE)
 			btn = STRING["enhdialogs.items.use"];
+		else if (btnMode == BTN_CHARGE)
+			btn = STRING["enhdialogs.items.charge"];
 
 		send("WhichItem", GameMessage("DISPLAY",
 			Common::String::format("%s %s", btn.c_str(),
@@ -220,6 +231,7 @@ void CharacterInventory::performAction() {
 	case BTN_EQUIP:
 		equipItem();
 		break;
+
 	case BTN_REMOVE:
 		removeItem();
 		break;
diff --git a/engines/mm/mm1/views_enh/character_inventory.h b/engines/mm/mm1/views_enh/character_inventory.h
index 74287001c80..16ea8bcd1e0 100644
--- a/engines/mm/mm1/views_enh/character_inventory.h
+++ b/engines/mm/mm1/views_enh/character_inventory.h
@@ -33,15 +33,17 @@ namespace ViewsEnh {
 
 class CharacterInventory : public ItemsView, public Game::EquipRemove,
 		public Game::UseItem {
-private:
+protected:
+	enum SelectedButton {
+		BTN_NONE, BTN_EQUIP, BTN_REMOVE, BTN_DISCARD, BTN_USE, BTN_CHARGE
+	};
 	enum DisplayMode {
 		ARMS_MODE, BACKPACK_MODE
 	};
-	DisplayMode _mode = ARMS_MODE;
-	enum SelectedButton {
-		BTN_NONE, BTN_EQUIP, BTN_REMOVE, BTN_DISCARD, BTN_USE
-	};
 	SelectedButton _selectedButton = BTN_NONE;
+	DisplayMode _mode = ARMS_MODE;
+
+private:
 	Common::String _tradeMode;
 	int _tradeAmount;
 
@@ -55,16 +57,6 @@ private:
 	 */
 	void drawTitle();
 
-	/**
-	 * Selects a button mode
-	 */
-	void selectButton(SelectedButton btnMode);
-
-	/**
-	 * Handle action with selected button mode and selected item
-	 */
-	void performAction();
-
 	/**
 	 * Equip an item
 	 */
@@ -116,9 +108,21 @@ protected:
 	 */
 	void charSwitched(Character *priorChar) override;
 
+	/**
+	 * Handle action with selected button mode and selected item
+	 */
+	virtual void performAction();
+
+	/**
+	 * Selects a button mode
+	 */
+	void selectButton(SelectedButton btnMode);
+
 public:
 	CharacterInventory();
+	CharacterInventory(const Common::String &name);
 	virtual ~CharacterInventory() {}
+	void setup();
 
 	bool msgFocus(const FocusMessage &msg) override;
 	bool msgGame(const GameMessage &msg) override;
diff --git a/engines/mm/mm1/views_enh/dialogs.h b/engines/mm/mm1/views_enh/dialogs.h
index 736e55a4a50..b7420684bb3 100644
--- a/engines/mm/mm1/views_enh/dialogs.h
+++ b/engines/mm/mm1/views_enh/dialogs.h
@@ -90,6 +90,7 @@
 #include "mm/mm1/views_enh/spells/detect_magic.h"
 #include "mm/mm1/views_enh/spells/fly.h"
 #include "mm/mm1/views_enh/spells/location.h"
+#include "mm/mm1/views_enh/spells/recharge_item.h"
 
 namespace MM {
 namespace MM1 {
@@ -143,6 +144,7 @@ private:
 	ViewsEnh::Spells::DetectMagic _detectMagic;
 	ViewsEnh::Spells::Fly _fly;
 	ViewsEnh::Spells::Location _location;
+	ViewsEnh::Spells::RechargeItem _rechargeItem;
 	ViewsEnh::CharacterInfo _characterInfo;
 	ViewsEnh::CharacterInfoCombat _characterInfoCombat;
 	ViewsEnh::CharacterInventory _characterInventory;
diff --git a/engines/mm/mm1/views_enh/items_view.h b/engines/mm/mm1/views_enh/items_view.h
index ec40530f092..9635fc97cd3 100644
--- a/engines/mm/mm1/views_enh/items_view.h
+++ b/engines/mm/mm1/views_enh/items_view.h
@@ -71,6 +71,14 @@ protected:
 	 */
 	virtual void itemSelected() = 0;
 
+	/**
+	 * Clear the buttons list
+	 */
+	void clearButtons() {
+		_btnText.clear();
+		PartyView::clearButtons();
+	}
+
 public:
 	ItemsView(const Common::String &name);
 	virtual ~ItemsView() {}
diff --git a/engines/mm/mm1/views_enh/spells/recharge_item.cpp b/engines/mm/mm1/views_enh/spells/recharge_item.cpp
new file mode 100644
index 00000000000..7e5321c23a6
--- /dev/null
+++ b/engines/mm/mm1/views_enh/spells/recharge_item.cpp
@@ -0,0 +1,66 @@
+/* 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/recharge_item.h"
+#include "mm/mm1/globals.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+namespace Spells {
+
+RechargeItem::RechargeItem() : CharacterInventory("RechargeItem") {
+	clearButtons();
+
+	addButton(2, STRING["enhdialogs.items.buttons.arms"], Common::KEYCODE_a);
+	addButton(6, STRING["enhdialogs.items.buttons.backpack"], Common::KEYCODE_b);
+	addButton(8, STRING["enhdialogs.items.buttons.charge"], Common::KEYCODE_c);
+	addButton(16, STRING["enhdialogs.misc.exit"], Common::KEYCODE_ESCAPE);
+}
+
+bool RechargeItem::msgKeypress(const KeypressMessage &msg) {
+	if (msg.keycode == Common::KEYCODE_a || msg.keycode == Common::KEYCODE_b ||
+			(msg.keycode >= Common::KEYCODE_1 && msg.keycode <= Common::KEYCODE_6)) {
+		// Allow switching between 
+		CharacterInventory::msgKeypress(msg);
+
+	} else if (msg.keycode == Common::KEYCODE_c) {
+		selectButton(BTN_CHARGE);
+	}
+
+	return true;
+}
+
+void RechargeItem::performAction() {
+	assert(_selectedButton == BTN_CHARGE);
+	Inventory &inv = _mode == ARMS_MODE ? g_globals->_currCharacter->_equipped :
+		g_globals->_currCharacter->_backpack;
+
+	bool result = charge(inv, _selectedItem);
+	close();
+
+	g_events->send(InfoMessage(STRING[result ? "spells.done" : "spells.failed"]));
+}
+
+} // namespace Spells
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/views_enh/spells/recharge_item.h b/engines/mm/mm1/views_enh/spells/recharge_item.h
new file mode 100644
index 00000000000..2c6b09dcd85
--- /dev/null
+++ b/engines/mm/mm1/views_enh/spells/recharge_item.h
@@ -0,0 +1,59 @@
+/* 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_RECHARGE_ITEM_H
+#define MM1_VIEWS_ENH_SPELLS_RECHARGE_ITEM_H
+
+#include "mm/mm1/views_enh/character_inventory.h"
+#include "mm/mm1/game/recharge_item.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+namespace Spells {
+
+class RechargeItem : public CharacterInventory, public MM1::Game::RechargeItem {
+protected:
+	/**
+	 * Handle action with selected button mode and selected item
+	 */
+	void performAction() override;
+
+public:
+	/**
+	 * Constructor
+	 */
+	RechargeItem();
+
+	/**
+	 * Destructor
+	 */
+	virtual ~RechargeItem() {}
+
+	bool msgKeypress(const KeypressMessage &msg) override;
+};
+
+} // namespace Spells
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index c9ef5f419e8..c4108379158 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -46,6 +46,7 @@ MODULE_OBJS += \
 	mm1/game/fly.o \
 	mm1/game/leprechaun.o \
 	mm1/game/monster_touch.o \
+	mm1/game/recharge_item.o \
 	mm1/game/rest.o \
 	mm1/game/spell_casting.o \
 	mm1/game/spells_party.o \
@@ -139,6 +140,7 @@ MODULE_OBJS += \
 	mm1/views_enh/spells/detect_magic.o \
 	mm1/views_enh/spells/fly.o \
 	mm1/views_enh/spells/location.o \
+	mm1/views_enh/spells/recharge_item.o \
 	mm1/views_enh/button_container.o \
 	mm1/views_enh/character_base.o \
 	mm1/views_enh/character_info.o \


Commit: e548fd5be3de24602ac1b9daae869c8cc37fd2bc
    https://github.com/scummvm/scummvm/commit/e548fd5be3de24602ac1b9daae869c8cc37fd2bc
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-06-03T22:36:50-07:00

Commit Message:
MM: MM1: Finished teleport spell views

Changed paths:
  A engines/mm/mm1/views_enh/spells/teleport.cpp
  A engines/mm/mm1/views_enh/spells/teleport.h
    devtools/create_mm/files/mm1/strings_en.yml
    engines/mm/mm1/game/spells_party.cpp
    engines/mm/mm1/views/spells/teleport.cpp
    engines/mm/mm1/views/spells/teleport.h
    engines/mm/mm1/views_enh/dialogs.h
    engines/mm/module.mk


diff --git a/devtools/create_mm/files/mm1/strings_en.yml b/devtools/create_mm/files/mm1/strings_en.yml
index 9c7207567d8..683ea4f1497 100644
--- a/devtools/create_mm/files/mm1/strings_en.yml
+++ b/devtools/create_mm/files/mm1/strings_en.yml
@@ -744,10 +744,10 @@ spells:
 	monsters_destroyed: "Some monsters were destroyed!"
 	casts_spell: "casts a spell:"
 
-	enter_to_cast: "'enter' to cast"
-	cast_on_char: "cast on: '1'-'%d'?"
-	cast_on_monster: "cast on: 'a'-'%c'?"
-	which_town: "which town (1-5)?"
+	enter_to_cast: "'Enter' to cast"
+	cast_on_char: "Cast on: '1'-'%d'?"
+	cast_on_monster: "Cast on: 'a'-'%c'?"
+	which_town: "Which town (1-5)?"
 
 	info:
 		hp: "hp = "
diff --git a/engines/mm/mm1/game/spells_party.cpp b/engines/mm/mm1/game/spells_party.cpp
index d0440835019..b1720a6d831 100644
--- a/engines/mm/mm1/game/spells_party.cpp
+++ b/engines/mm/mm1/game/spells_party.cpp
@@ -885,7 +885,7 @@ SpellResult SpellsParty::wizard54_shelter() {
 }
 
 SpellResult SpellsParty::wizard55_teleport() {
-	Views::Spells::Teleport::show();
+	g_events->replaceView("Teleport");
 	return SR_SUCCESS_SILENT;
 }
 
diff --git a/engines/mm/mm1/views/spells/teleport.cpp b/engines/mm/mm1/views/spells/teleport.cpp
index 56713cbda4c..161386b3f1f 100644
--- a/engines/mm/mm1/views/spells/teleport.cpp
+++ b/engines/mm/mm1/views/spells/teleport.cpp
@@ -27,13 +27,6 @@ namespace MM1 {
 namespace Views {
 namespace Spells {
 
-void Teleport::show() {
-	UIElement *teleport = dynamic_cast<Teleport *>(g_events->findView("Teleport"));
-	assert(teleport);
-
-	teleport->open();
-}
-
 Teleport::Teleport() : SpellView("Teleport") {
 	_bounds = getLineBounds(20, 24);
 }
@@ -77,18 +70,24 @@ bool Teleport::msgKeypress(const KeypressMessage &msg) {
 		_squares = msg.keycode - Common::KEYCODE_0;
 		_mode = CAST;
 		redraw();
-
-	} else if (_mode == CAST && msg.keycode == Common::KEYCODE_RETURN) {
-		teleport();
 	}
 
 	return true;
 }
 
 bool Teleport::msgAction(const ActionMessage &msg) {
-	if (msg._action == KEYBIND_ESCAPE) {
+	switch (msg._action) {
+	case KEYBIND_ESCAPE:
 		close();
 		return true;
+
+	case KEYBIND_SELECT:
+		if (_mode == CAST)
+			teleport();
+		return true;
+
+	default:
+		break;
 	}
 
 	return false;
diff --git a/engines/mm/mm1/views/spells/teleport.h b/engines/mm/mm1/views/spells/teleport.h
index 8917d0948fc..d2dc625a464 100644
--- a/engines/mm/mm1/views/spells/teleport.h
+++ b/engines/mm/mm1/views/spells/teleport.h
@@ -42,11 +42,7 @@ private:
 	 * Handle the teleporting
 	 */
 	void teleport();
-public:
-	/**
-	 * Show the view
-	 */
-	static void show();
+
 public:
 	/**
 	 * Constructor
diff --git a/engines/mm/mm1/views_enh/dialogs.h b/engines/mm/mm1/views_enh/dialogs.h
index b7420684bb3..f7d1610df63 100644
--- a/engines/mm/mm1/views_enh/dialogs.h
+++ b/engines/mm/mm1/views_enh/dialogs.h
@@ -91,6 +91,7 @@
 #include "mm/mm1/views_enh/spells/fly.h"
 #include "mm/mm1/views_enh/spells/location.h"
 #include "mm/mm1/views_enh/spells/recharge_item.h"
+#include "mm/mm1/views_enh/spells/teleport.h"
 
 namespace MM {
 namespace MM1 {
@@ -145,6 +146,7 @@ private:
 	ViewsEnh::Spells::Fly _fly;
 	ViewsEnh::Spells::Location _location;
 	ViewsEnh::Spells::RechargeItem _rechargeItem;
+	ViewsEnh::Spells::Teleport _teleport;
 	ViewsEnh::CharacterInfo _characterInfo;
 	ViewsEnh::CharacterInfoCombat _characterInfoCombat;
 	ViewsEnh::CharacterInventory _characterInventory;
diff --git a/engines/mm/mm1/views_enh/spells/teleport.cpp b/engines/mm/mm1/views_enh/spells/teleport.cpp
new file mode 100644
index 00000000000..3bbb8f88fa6
--- /dev/null
+++ b/engines/mm/mm1/views_enh/spells/teleport.cpp
@@ -0,0 +1,136 @@
+/* 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/teleport.h"
+#include "mm/mm1/globals.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+namespace Spells {
+
+#define TEXT_X 120
+
+Teleport::Teleport() : ScrollView("Teleport") {
+	setBounds(Common::Rect(0, 144, 234, 200));
+	addButton(&g_globals->_escSprites, Common::Point(5, 28), 0, KEYBIND_ESCAPE, true);
+}
+
+bool Teleport::msgFocus(const FocusMessage &msg) {
+	ScrollView::msgFocus(msg);
+
+	_mode = SELECT_DIRECTION;
+	return 0;
+}
+
+void Teleport::draw() {
+	ScrollView::draw();
+
+	setReduced(true);
+	writeString(20, 30, STRING["enhdialogs.misc.go_back"]);
+
+	writeLine(0, STRING["dialogs.spells.teleport_dir"], ALIGN_RIGHT, TEXT_X);
+	writeChar((_mode == SELECT_DIRECTION) ? '_' : _direction);
+
+	if (_mode == SELECT_SQUARES || _mode == CAST) {
+		writeLine(1, STRING["dialogs.spells.teleport_squares"], ALIGN_RIGHT, TEXT_X);
+		writeChar((_mode == SELECT_SQUARES) ? '_' : '0' + _squares);
+	}
+
+	if (_mode == CAST)
+		writeString(0, 30, STRING["spells.enter_to_cast"], ALIGN_RIGHT);
+
+	setReduced(false);
+}
+
+bool Teleport::msgKeypress(const KeypressMessage &msg) {
+	if (_mode == SELECT_DIRECTION && (
+		msg.keycode == Common::KEYCODE_n ||
+		msg.keycode == Common::KEYCODE_s ||
+		msg.keycode == Common::KEYCODE_e ||
+		msg.keycode == Common::KEYCODE_w)) {
+		_direction = toupper(msg.ascii);
+		_mode = SELECT_SQUARES;
+		redraw();
+
+	} else if (_mode == SELECT_SQUARES && (
+		msg.keycode >= Common::KEYCODE_0 &&
+		msg.keycode <= Common::KEYCODE_9)) {
+		_squares = msg.keycode - Common::KEYCODE_0;
+		_mode = CAST;
+		redraw();
+	}
+
+	return true;
+}
+
+bool Teleport::msgAction(const ActionMessage &msg) {
+	switch (msg._action) {
+	case KEYBIND_ESCAPE:
+		close();
+		return true;
+
+	case KEYBIND_SELECT:
+		if (_mode == CAST)
+			teleport();
+		return true;
+
+	default:
+		break;
+	}
+
+	return false;
+}
+
+void Teleport::teleport() {
+	Maps::Maps &maps = *g_maps;
+	Maps::Map &map = *maps._currentMap;
+
+	close();
+	if (map[Maps::MAP_FLAGS] & 2) {
+		g_events->send(SoundMessage(STRING["spells.failed"]));
+
+	} else {
+		switch (_direction) {
+		case 'N':
+			maps.step(Common::Point(0, _squares));
+			break;
+		case 'S':
+			maps.step(Common::Point(0, -_squares));
+			break;
+		case 'E':
+			maps.step(Common::Point(_squares, 0));
+			break;
+		case 'W':
+			maps.step(Common::Point(-_squares, 0));
+			break;
+		default:
+			return;
+		}
+
+		send("Game", GameMessage("UPDATE"));
+	}
+}
+
+} // namespace Spells
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/views_enh/spells/teleport.h b/engines/mm/mm1/views_enh/spells/teleport.h
new file mode 100644
index 00000000000..b2b0b7e1e46
--- /dev/null
+++ b/engines/mm/mm1/views_enh/spells/teleport.h
@@ -0,0 +1,82 @@
+/* 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_TELEPORT_H
+#define MM1_VIEWS_ENH_SPELLS_TELEPORT_H
+
+#include "mm/mm1/views_enh/scroll_view.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+namespace Spells {
+
+class Teleport : public ScrollView {
+private:
+	enum Mode { SELECT_DIRECTION, SELECT_SQUARES, CAST };
+	Mode _mode = SELECT_DIRECTION;
+	char _direction = '\0';
+	int _squares = 0;
+
+	/**
+	 * Handle the teleporting
+	 */
+	void teleport();
+
+public:
+	/**
+	 * Constructor
+	 */
+	Teleport();
+
+	/**
+	 * Destructor
+	 */
+	virtual ~Teleport() {
+	}
+
+	/**
+	 * 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;
+};
+
+} // namespace Spells
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index c4108379158..00bd2001796 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -141,6 +141,7 @@ MODULE_OBJS += \
 	mm1/views_enh/spells/fly.o \
 	mm1/views_enh/spells/location.o \
 	mm1/views_enh/spells/recharge_item.o \
+	mm1/views_enh/spells/teleport.o \
 	mm1/views_enh/button_container.o \
 	mm1/views_enh/character_base.o \
 	mm1/views_enh/character_info.o \




More information about the Scummvm-git-logs mailing list