[Scummvm-git-logs] scummvm master -> 526cbcd41e358bf50c57cf0ef71335fa1403226d

dreammaster noreply at scummvm.org
Wed Mar 22 05:39:16 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:
2276d36e16 MM: MM1: Beginnings of enocunter view
0a2b2edc36 MM: MM1: Support trading selected items to other chars
526cbcd41e MM: MM1: Beginnings of trade view


Commit: 2276d36e16788e12e50ccc871d952e03ecc8ff16
    https://github.com/scummvm/scummvm/commit/2276d36e16788e12e50ccc871d952e03ecc8ff16
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-03-21T20:36:40-07:00

Commit Message:
MM: MM1: Beginnings of enocunter view

Changed paths:
  A engines/mm/mm1/views_enh/encounter.cpp
  A engines/mm/mm1/views_enh/encounter.h
    engines/mm/mm1/views_enh/dialogs.h
    engines/mm/mm1/views_enh/text_view.cpp
    engines/mm/mm1/views_enh/text_view.h
    engines/mm/module.mk


diff --git a/engines/mm/mm1/views_enh/dialogs.h b/engines/mm/mm1/views_enh/dialogs.h
index 0fabe4b6f6b..caac08428e4 100644
--- a/engines/mm/mm1/views_enh/dialogs.h
+++ b/engines/mm/mm1/views_enh/dialogs.h
@@ -31,6 +31,7 @@
 #include "mm/mm1/views_enh/characters.h"
 #include "mm/mm1/views_enh/confirm.h"
 #include "mm/mm1/views_enh/create_characters.h"
+#include "mm/mm1/views_enh/encounter.h"
 #include "mm/mm1/views_enh/exchange.h"
 #include "mm/mm1/views_enh/game.h"
 #include "mm/mm1/views_enh/game_messages.h"
@@ -78,6 +79,7 @@ private:
 	ViewsEnh::Characters _characters;
 	ViewsEnh::Confirm _confirm;
 	ViewsEnh::CreateCharacters _createCharacters;
+	ViewsEnh::Encounter _encounter;
 	ViewsEnh::Exchange _exchange;
 	ViewsEnh::Game _game;
 	ViewsEnh::GameMessages _gameMessages;
diff --git a/engines/mm/mm1/views_enh/encounter.cpp b/engines/mm/mm1/views_enh/encounter.cpp
new file mode 100644
index 00000000000..88233621b3f
--- /dev/null
+++ b/engines/mm/mm1/views_enh/encounter.cpp
@@ -0,0 +1,394 @@
+/* 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/encounter.h"
+#include "mm/mm1/game/encounter.h"
+#include "mm/mm1/globals.h"
+#include "mm/mm1/mm1.h"
+#include "mm/mm1/sound.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+
+Encounter::Encounter() : ScrollView("Encounter") {
+	setBounds(Common::Rect(0, 144, 234, 200));
+}
+
+bool Encounter::msgFocus(const FocusMessage &msg) {
+	_mode = ALERT;
+	return true;
+}
+
+void Encounter::draw() {
+	Game::Encounter &enc = g_globals->_encounters;
+	Graphics::ManagedSurface s = getSurface();
+
+	if (_mode != ALERT)
+		ScrollView::draw();
+
+	switch (_mode) {
+	case ALERT:
+		for (int y = 6; y <= 8; ++y)
+			writeLine(y, "            ", ALIGN_MIDDLE);
+		writeLine(7, STRING["dialogs.encounter.title"], ALIGN_MIDDLE);
+		delaySeconds(2);
+		break;
+
+	case SURPRISED_BY_MONSTERS:
+		writeLine(0, STRING["dialogs.encounter.surprised"], ALIGN_MIDDLE);
+		enc._encounterType = Game::FORCE_SURPRISED;
+		delaySeconds(2);
+		break;
+
+	case SURPRISED_MONSTERS:
+		writeLine(1, STRING["dialogs.encounter.surprise"], ALIGN_MIDDLE);
+		writeLine(2, STRING["dialogs.encounter.approach"], ALIGN_MIDDLE);
+		break;
+
+	case ENCOUNTER_OPTIONS: {
+		// Write the encounter options
+		writeString(0, 21, STRING["dialogs.encounter.options1"]);
+		writeString(10, 22, STRING["dialogs.encounter.options2"]);
+		break;
+	}
+
+	case NOWHERE_TO_RUN:
+		writeString(11, 21, STRING["dialogs.encounter.nowhere_to_run"]);
+		delaySeconds(2);
+		break;
+
+	case SURROUNDED:
+		writeString(5, 21, STRING["dialogs.encounter.surround"]);
+		delaySeconds(2);
+		break;
+
+	case SURRENDER_FAILED:
+		writeString(2, 21, STRING["dialogs.encounter.surrender_failed"]);
+		delaySeconds(2);
+		break;
+
+	case NO_RESPONSE:
+		writeString(12, 21, STRING["dialogs.encounter.no_response"]);
+		delaySeconds(2);
+		break;
+
+	case BRIBE:
+		enc._bribeFleeCtr++;
+		enc._bribeAlignmentCtr++;
+		writeString(5, 21, Common::String::format(
+			STRING["dialogs.encounter.give_up"].c_str(),
+			_bribeTypeStr.c_str()));
+		break;
+
+	case NOT_ENOUGH:
+		writeString(14, 21, STRING["dialogs.encounter.not_enough"]);
+		delaySeconds(2);
+		break;
+
+	case COMBAT:
+		writeString(16, 21, STRING["dialogs.encounter.combat"]);
+		delaySeconds(2);
+		break;
+
+	default:
+		break;
+	}
+
+	if (_mode != ALERT) {
+		// Display the monster
+		drawGraphic(enc._monsterImgNum);
+
+		// Write the monster list
+		for (uint i = 0; i < enc._monsterList.size(); ++i) {
+			writeChar(22, i, 'A' + i);
+			writeString(") ");
+			writeString(enc._monsterList[i]._name);
+		}
+	}
+
+	if (_mode == NO_RESPONSE || _mode == SURROUNDED ||
+			_mode == NOT_ENOUGH || _mode == COMBAT ||
+			_mode == NOWHERE_TO_RUN || _mode == SURRENDER_FAILED ||
+			_mode == SURPRISED_BY_MONSTERS) {
+		if (enc._alignmentsChanged) {
+			writeString(8, 23, STRING["dialogs.encounter.alignment_slips"]);
+			Sound::sound(SOUND_2);
+		}
+
+		_mode = BATTLE;
+	}
+}
+
+void Encounter::timeout() {
+	const Game::Encounter &enc = g_globals->_encounters;
+	const Maps::Map &map = *g_maps->_currentMap;
+
+	switch (_mode) {
+	case ALERT:
+		// Finished displaying initial encounter alert
+		if (enc._encounterType == Game::FORCE_SURPRISED) {
+			_mode = SURPRISED_BY_MONSTERS;
+		} else if (enc._encounterType == Game::NORMAL_SURPRISED ||
+			/* ENCOUNTER_OPTIONS */
+			g_engine->getRandomNumber(100) > map[Maps::MAP_21]) {
+			// Potentially surprised. Check for guard dog spell
+			if (g_globals->_activeSpells._s.guard_dog ||
+				g_engine->getRandomNumber(100) > map[Maps::MAP_20])
+				_mode = ENCOUNTER_OPTIONS;
+			else
+				_mode = SURPRISED_BY_MONSTERS;
+		} else {
+			_mode = SURPRISED_MONSTERS;
+		}
+		break;
+
+	case BATTLE:
+		// Switch to combat view
+		close();
+		send("Combat", GameMessage("COMBAT"));
+		break;
+
+	default:
+		break;
+	}
+
+	redraw();
+}
+
+bool Encounter::msgKeypress(const KeypressMessage &msg) {
+	const Maps::Map &map = *g_maps->_currentMap;
+
+	switch (_mode) {
+	case SURPRISED_MONSTERS:
+		if (msg.keycode == Common::KEYCODE_y) {
+			_mode = ENCOUNTER_OPTIONS;
+			redraw();
+		} else if (msg.keycode == Common::KEYCODE_n) {
+			encounterEnded();
+		}
+		break;
+
+	case ENCOUNTER_OPTIONS:
+		switch (msg.keycode) {
+		case Common::KEYCODE_a:
+			attack();
+			break;
+		case Common::KEYCODE_b:
+			bribe();
+			break;
+		case Common::KEYCODE_r:
+			retreat();
+			break;
+		case Common::KEYCODE_s:
+			surrender();
+			break;
+		default:
+			break;
+		}
+		break;
+
+	case BRIBE:
+		if (msg.keycode == Common::KEYCODE_y) {
+			if (getRandomNumber(100) > map[Maps::MAP_BRIBE_THRESHOLD]) {
+				_mode = NOT_ENOUGH;
+				redraw();
+			} else {
+				switch (_bribeType) {
+				case BRIBE_GOLD:
+					g_globals->_party.clearPartyGold();
+					break;
+				case BRIBE_GEMS:
+					g_globals->_party.clearPartyGems();
+					break;
+				case BRIBE_FOOD:
+					g_globals->_party.clearPartyFood();
+					break;
+				}
+
+				encounterEnded();
+			}
+		} else if (msg.keycode == Common::KEYCODE_n) {
+			_mode = ENCOUNTER_OPTIONS;
+			redraw();
+		}
+		break;
+
+	default:
+		break;
+	}
+
+	return true;
+}
+
+void Encounter::encounterEnded() {
+	close();
+	g_events->send("Game", GameMessage("UPDATE"));
+}
+
+void Encounter::attack() {
+	const Game::Encounter &enc = g_globals->_encounters;
+
+	if (!enc.checkSurroundParty() || !enc.checkSurroundParty() ||
+			!enc.checkSurroundParty()) {
+		increaseAlignments();
+	}
+
+	_mode = COMBAT;
+	redraw();
+}
+
+void Encounter::bribe() {
+	const Game::Encounter &enc = g_globals->_encounters;
+
+	if (enc.checkSurroundParty()) {
+		if (!enc._bribeAlignmentCtr)
+			decreaseAlignments();
+
+		_mode = NO_RESPONSE;
+		redraw();
+
+	} else if (getRandomNumber(7) == 5 && !enc._bribeFleeCtr) {
+		// Rare chance to abort combat immediately
+		encounterEnded();
+
+	} else {
+		_mode = BRIBE;
+
+		int val = getRandomNumber(100);
+		if (val < 6) {
+			_bribeType = BRIBE_GEMS;
+			_bribeTypeStr = STRING["dialogs.encounter.gems"];
+		} else if (val < 16) {
+			_bribeType = BRIBE_FOOD;
+			_bribeTypeStr = STRING["dialogs.encounter.food"];
+		} else {
+			_bribeType = BRIBE_GOLD;
+			_bribeTypeStr = STRING["dialogs.encounter.gold"];
+		}
+
+		redraw();
+	}
+}
+
+void Encounter::retreat() {
+	const Maps::Map &map = *g_maps->_currentMap;
+	const Game::Encounter &enc = g_globals->_encounters;
+	int val = getRandomNumber(110);
+
+	if (val >= 100) {
+		// 9% chance of simply fleeing
+		flee();
+	} else if (val > map[Maps::MAP_FLEE_THRESHOLD]) {
+		// Nowhere to run depending on the map
+		_mode = NOWHERE_TO_RUN;
+		redraw();
+	} else if (enc._monsterList.size() < g_globals->_party.size() || !enc.checkSurroundParty()) {
+		// Only allow fleeing if the number of monsters
+		// are less than the size of the party
+		flee();
+	} else {
+		_mode = SURROUNDED;
+		redraw();
+	}
+}
+
+void Encounter::surrender() {
+	const Game::Encounter &enc = g_globals->_encounters;
+	const Maps::Map &map = *g_maps->_currentMap;
+
+	if (getRandomNumber(100) > map[Maps::MAP_SURRENDER_THRESHOLD] ||
+			getRandomNumber(100) > enc._fleeThreshold) {
+		_mode = SURRENDER_FAILED;
+		redraw();
+	} else {
+		g_maps->_mapPos.x = map[Maps::MAP_SURRENDER_X];
+		g_maps->_mapPos.y = map[Maps::MAP_SURRENDER_Y];
+
+		// Randomly remove food, gems, or gold from the party
+		int val = getRandomNumber(200);
+		if (val < 51) {
+		} else if (val < 151) {
+			g_globals->_party.clearPartyGold();
+		} else if (val < 161) {
+			g_globals->_party.clearPartyGems();
+		} else if (val < 171) {
+			g_globals->_party.clearPartyFood();
+		} else if (val < 191) {
+			g_globals->_party.clearPartyFood();
+			g_globals->_party.clearPartyGold();
+		} else if (val < 200) {
+			g_globals->_party.clearPartyGold();
+			g_globals->_party.clearPartyGems();
+		} else {
+			g_globals->_party.clearPartyGems();
+			g_globals->_party.clearPartyFood();
+			g_globals->_party.clearPartyGold();
+		}
+
+		encounterEnded();
+	}
+}
+
+void Encounter::flee() {
+	const Maps::Map &map = *g_maps->_currentMap;
+	g_maps->_mapPos.x = map[Maps::MAP_FLEE_X];
+	g_maps->_mapPos.y = map[Maps::MAP_FLEE_Y];
+	encounterEnded();
+}
+
+void Encounter::decreaseAlignments() {
+	Game::Encounter &enc = g_globals->_encounters;
+
+	for (uint i = 0; i < g_globals->_party.size(); ++i) {
+		Character &c = g_globals->_party[i];
+		g_globals->_currCharacter = &c;
+
+		if (c._alignmentCtr) {
+			--c._alignmentCtr;
+			if (c._alignmentCtr == 0)
+				enc.changeCharAlignment(GOOD);
+			else if (c._alignmentCtr == 16)
+				enc.changeCharAlignment(NEUTRAL);
+		}
+	}
+}
+
+void Encounter::increaseAlignments() {
+	Game::Encounter &enc = g_globals->_encounters;
+
+	for (uint i = 0; i < g_globals->_party.size(); ++i) {
+		Character &c = g_globals->_party[i];
+		g_globals->_currCharacter = &c;
+
+		if (c._alignmentCtr != 32) {
+			++c._alignmentCtr;
+			if (c._alignmentCtr == 32)
+				enc.changeCharAlignment(EVIL);
+			else if (c._alignmentCtr == 16)
+				enc.changeCharAlignment(NEUTRAL);
+		}
+	}
+}
+
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/views_enh/encounter.h b/engines/mm/mm1/views_enh/encounter.h
new file mode 100644
index 00000000000..4d233063577
--- /dev/null
+++ b/engines/mm/mm1/views_enh/encounter.h
@@ -0,0 +1,116 @@
+/* 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_ENCOUNTER_H
+#define MM1_VIEWS_ENH_ENCOUNTER_H
+
+#include "mm/mm1/events.h"
+#include "mm/mm1/views_enh/scroll_view.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+
+class Encounter : public ScrollView {
+private:
+	enum Mode {
+		ALERT, SURPRISED_BY_MONSTERS, SURPRISED_MONSTERS,
+		ENCOUNTER_OPTIONS, NOWHERE_TO_RUN, SURROUNDED,
+		SURRENDER_FAILED, NO_RESPONSE, BRIBE, NOT_ENOUGH,
+		COMBAT, BATTLE
+	};
+	Mode _mode = ALERT;
+	enum BribeType { BRIBE_GOLD, BRIBE_GEMS, BRIBE_FOOD };
+	BribeType _bribeType = BRIBE_GOLD;
+	Common::String _bribeTypeStr;
+
+	/**
+	 * Handles the end of the encounter
+	 */
+	void encounterEnded();
+
+	/**
+	 * Initiates the combat
+	 */
+	void attack();
+
+	/**
+	 * Try and bribe the enemies
+	 */
+	void bribe();
+
+	/**
+	 * Try and retreat
+	 */
+	void retreat();
+
+	/**
+	 * Try and surrender
+	 */
+	void surrender();
+
+	/**
+	 * Ends an encounter
+	 */
+	void flee();
+
+	/**
+	 * Decreases the alignment counter, gradually turning
+	 * EVIL to NEUTRAL to GOOD
+	 */
+	void decreaseAlignments();
+
+	/**
+	 * Increases the alignment counter, gradually turning
+	 * GOOD to NEUTRAL to EVIL
+	 */
+	void increaseAlignments();
+public:
+	Encounter();
+	virtual ~Encounter() {}
+
+	/**
+	 * Called when the view is focused
+	 */
+	bool msgFocus(const FocusMessage &msg) override;
+
+	/**
+	 * Draw the encounter details overlayed on
+	 * the existing game screen
+	 */
+	void draw() override;
+
+	/**
+	 * Handles delay timeouts
+	 */
+	void timeout() override;
+
+	/**
+	 * Handles keypresses
+	 */
+	bool msgKeypress(const KeypressMessage &msg) override;
+};
+
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/mm1/views_enh/text_view.cpp b/engines/mm/mm1/views_enh/text_view.cpp
index d48f0df3e6b..07516069dcc 100644
--- a/engines/mm/mm1/views_enh/text_view.cpp
+++ b/engines/mm/mm1/views_enh/text_view.cpp
@@ -247,6 +247,12 @@ void TextView::clearSurface() {
 	_textPos.x = _textPos.y = 0;
 }
 
+void TextView::drawGraphic(int gfxNum) {
+	const Graphics::ManagedSurface img =
+		g_globals->_monsters.getMonsterImage(gfxNum);
+	getSurface().blitFrom(img, Common::Point(64, 16));
+}
+
 } // namespace ViewsEnh
 } // namespace MM1
 } // namespace MM
diff --git a/engines/mm/mm1/views_enh/text_view.h b/engines/mm/mm1/views_enh/text_view.h
index b8210d394f8..53565172651 100644
--- a/engines/mm/mm1/views_enh/text_view.h
+++ b/engines/mm/mm1/views_enh/text_view.h
@@ -96,6 +96,8 @@ protected:
 	 */
 	void clearSurface() override;
 
+	void drawGraphic(int gfxNum);
+
 public:
 	TextView(const Common::String &name);
 	TextView(const Common::String &name, UIElement *owner);
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index ff147fc22b1..75a54b7a5bb 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -136,6 +136,7 @@ MODULE_OBJS += \
 	mm1/views_enh/confirm.o \
 	mm1/views_enh/create_characters.o \
 	mm1/views_enh/dialogs.o \
+	mm1/views_enh/encounter.o \
 	mm1/views_enh/exchange.o \
 	mm1/views_enh/game.o \
 	mm1/views_enh/game_commands.o \


Commit: 0a2b2edc363741cc35e086c99b1fc9b57ac76b88
    https://github.com/scummvm/scummvm/commit/0a2b2edc363741cc35e086c99b1fc9b57ac76b88
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-03-21T20:36:40-07:00

Commit Message:
MM: MM1: Support trading selected items to other chars

Changed paths:
    engines/mm/mm1/views_enh/character_inventory.cpp
    engines/mm/mm1/views_enh/character_inventory.h


diff --git a/engines/mm/mm1/views_enh/character_inventory.cpp b/engines/mm/mm1/views_enh/character_inventory.cpp
index adf004dfd0f..cf05f205e6f 100644
--- a/engines/mm/mm1/views_enh/character_inventory.cpp
+++ b/engines/mm/mm1/views_enh/character_inventory.cpp
@@ -41,8 +41,7 @@ CharacterInventory::CharacterInventory() : ItemsView("CharacterInventory") {
 
 bool CharacterInventory::msgFocus(const FocusMessage &msg) {
 	ItemsView::msgFocus(msg);
-	_initialChar = g_globals->_currCharacter;
-	assert(_initialChar);
+	assert(g_globals->_currCharacter);
 
 	if (dynamic_cast<WhichItem *>(msg._priorView) == nullptr)
 		_mode = BACKPACK_MODE;
@@ -125,6 +124,7 @@ void CharacterInventory::populateItems() {
 	_items.clear();
 	_selectedItem = -1;
 	_selectedButton = BTN_NONE;
+	_initialChar = g_globals->_currCharacter;
 
 	const Character &c = *g_globals->_currCharacter;
 	const Inventory &inv = (_mode == ARMS_MODE) ? c._equipped : c._backpack;
@@ -144,6 +144,10 @@ void CharacterInventory::selectedCharChanged() {
 			g_globals->_currCharacter = _initialChar;
 			g_events->send("GameParty", GameMessage("CHAR_HIGHLIGHT", (int)true));
 		}
+	} else if (_selectedItem != -1) {
+		// Trade to another character
+		tradeItem(_initialChar);
+
 	} else {
 		populateItems();
 		redraw();
@@ -188,7 +192,6 @@ void CharacterInventory::performAction() {
 	}
 }
 
-
 void CharacterInventory::equipItem() {
 	Common::String errMsg;
 	Common::Point textPos;
@@ -224,6 +227,31 @@ void CharacterInventory::discardItem() {
 	redraw();
 }
 
+void CharacterInventory::tradeItem(Character *from) {
+	if (g_globals->_currCharacter == _initialChar)
+		return;
+
+	// Get source and dest inventories
+	Character &cSrc = *_initialChar;
+	Inventory &iSrc = (_mode == ARMS_MODE) ? cSrc._equipped : cSrc._backpack;
+	Character &cDest = *g_globals->_currCharacter;
+	Inventory &iDest = cDest._backpack;
+
+	if (iDest.full()) {
+		g_globals->_currCharacter = _initialChar;
+		backpackFull();
+
+	} else {
+		Inventory::Entry item = iSrc[_selectedItem];
+		iSrc.removeAt(_selectedItem);
+		iDest.add(item._id, item._charges);
+
+		_mode = BACKPACK_MODE;
+		populateItems();
+		redraw();
+	}
+}
+
 } // namespace ViewsEnh
 } // namespace MM1
 } // namespace MM
diff --git a/engines/mm/mm1/views_enh/character_inventory.h b/engines/mm/mm1/views_enh/character_inventory.h
index 06961ae47e5..9f7dc99896f 100644
--- a/engines/mm/mm1/views_enh/character_inventory.h
+++ b/engines/mm/mm1/views_enh/character_inventory.h
@@ -77,6 +77,11 @@ private:
 	 */
 	void discardItem();
 
+	/**
+	 * Trade an item to another character
+	 */
+	void tradeItem(Character *from);
+
 protected:
 	/**
 	 * Called when an item is selected


Commit: 526cbcd41e358bf50c57cf0ef71335fa1403226d
    https://github.com/scummvm/scummvm/commit/526cbcd41e358bf50c57cf0ef71335fa1403226d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2023-03-21T22:39:00-07:00

Commit Message:
MM: MM1: Beginnings of trade view

Changed paths:
  A engines/mm/mm1/views_enh/trade.cpp
  A engines/mm/mm1/views_enh/trade.h
    devtools/create_mm/files/mm1/strings_en.yml
    engines/mm/mm1/views_enh/character_inventory.cpp
    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 b1820b42bbc..ef16d41fdd8 100644
--- a/devtools/create_mm/files/mm1/strings_en.yml
+++ b/devtools/create_mm/files/mm1/strings_en.yml
@@ -609,6 +609,14 @@ enhdialogs:
 		donate: "\x01""37Donate"
 		uncurse: "\x01""37Uncurse"
 		realign: "\x01""37Re-align"
+	trade:
+		which: "Trade which:"
+		gems: "\x01""37Gems"
+		gold: "Gol\x01""37d"
+		food: "\x01""37Food"
+		items: "\x01""37Items"
+		how_much: "How much:"
+		items_help: "To trade items, select an item from the inventory, and then select the portrait of the character to trade to"
 	training:
 		title: "Training"
 		train: "\x01""37Train"
diff --git a/engines/mm/mm1/views_enh/character_inventory.cpp b/engines/mm/mm1/views_enh/character_inventory.cpp
index cf05f205e6f..6fc83027bc1 100644
--- a/engines/mm/mm1/views_enh/character_inventory.cpp
+++ b/engines/mm/mm1/views_enh/character_inventory.cpp
@@ -105,7 +105,9 @@ bool CharacterInventory::msgKeypress(const KeypressMessage &msg) {
 	case Common::KEYCODE_d:
 		selectButton(BTN_DISCARD);
 		break;
-
+	case Common::KEYCODE_t:
+		addView("Trade");
+		break;
 	default:
 		return ItemsView::msgKeypress(msg);
 	}
diff --git a/engines/mm/mm1/views_enh/dialogs.h b/engines/mm/mm1/views_enh/dialogs.h
index caac08428e4..e1699450905 100644
--- a/engines/mm/mm1/views_enh/dialogs.h
+++ b/engines/mm/mm1/views_enh/dialogs.h
@@ -42,6 +42,7 @@
 #include "mm/mm1/views_enh/rest.h"
 #include "mm/mm1/views_enh/search.h"
 #include "mm/mm1/views_enh/title.h"
+#include "mm/mm1/views_enh/trade.h"
 #include "mm/mm1/views_enh/trap.h"
 #include "mm/mm1/views_enh/unlock.h"
 #include "mm/mm1/views_enh/which_item.h"
@@ -90,6 +91,7 @@ private:
 	ViewsEnh::Rest _rest;
 	ViewsEnh::Search _search;
 	ViewsEnh::Title _title;
+	ViewsEnh::Trade _trade;
 	ViewsEnh::Trap _trap;
 	ViewsEnh::Unlock _unlock;
 	ViewsEnh::WhichItem _whichItem;
diff --git a/engines/mm/mm1/views_enh/trade.cpp b/engines/mm/mm1/views_enh/trade.cpp
new file mode 100644
index 00000000000..13a1bbf6ac7
--- /dev/null
+++ b/engines/mm/mm1/views_enh/trade.cpp
@@ -0,0 +1,83 @@
+/* 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/trade.h"
+#include "mm/mm1/globals.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+
+Trade::Trade() : PartyView("Trade") {
+	setBounds(Common::Rect(0, 144, 234, 200));
+}
+
+bool Trade::msgFocus(const FocusMessage &msg) {
+	setMode(TRADE_OPTIONS);
+	_btnIcons.load("view.icn");
+
+	return PartyView::msgFocus(msg);
+}
+
+void Trade::draw() {
+	PartyView::draw();
+	_btnIcons.clear();
+
+	switch (_mode) {
+	case TRADE_OPTIONS:
+		drawOptions();
+		break;
+	}
+}
+
+bool Trade::msgKeypress(const KeypressMessage &msg) {
+
+	return true;
+}
+
+void Trade::setMode(TradeMode mode) {
+	_mode = mode;
+
+	clearButtons();
+
+	switch (_mode) {
+	case TRADE_OPTIONS:
+		addButton(&_btnIcons, Common::Point(80, 0), 32, Common::KEYCODE_g);
+		addButton(&_btnIcons, Common::Point(158, 0), 34, Common::KEYCODE_d);
+		addButton(&_btnIcons, Common::Point(80, 20), 36, Common::KEYCODE_f);
+		addButton(&_btnIcons, Common::Point(158, 20), 38, Common::KEYCODE_i);
+		addButton(&g_globals->_escSprites, Common::Point(0, 20), 0, KEYBIND_ESCAPE);
+		break;
+	}
+}
+
+void Trade::drawOptions() {
+	writeString(0, 5, STRING["enhdialogs.trade.which"]);
+	writeString(28, 25, STRING["enhdialogs.misc.exit"]);
+	writeString(108, 5, STRING["enhdialogs.trade.gold"]);
+	writeString(186, 5, STRING["enhdialogs.trade.gems"]);
+	writeString(108, 25, STRING["enhdialogs.trade.food"]);
+	writeString(186, 25, STRING["enhdialogs.trade.items"]);
+}
+
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
diff --git a/engines/mm/mm1/views_enh/trade.h b/engines/mm/mm1/views_enh/trade.h
new file mode 100644
index 00000000000..4b1cf2d5f5a
--- /dev/null
+++ b/engines/mm/mm1/views_enh/trade.h
@@ -0,0 +1,56 @@
+/* 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_TRADE_H
+#define MM1_VIEWS_ENH_TRADE_H
+
+#include "mm/mm1/views_enh/party_view.h"
+
+namespace MM {
+namespace MM1 {
+namespace ViewsEnh {
+
+class Trade : public PartyView {
+private:
+	enum TradeMode { TRADE_OPTIONS };
+	TradeMode _mode = TRADE_OPTIONS;
+	Shared::Xeen::SpriteResource _btnIcons;
+
+	/**
+	  * Set the display mode
+	  */
+	void setMode(TradeMode mode);
+
+	void drawOptions();
+public:
+	Trade();
+	virtual ~Trade() {}
+
+	bool msgFocus(const FocusMessage &msg) override;
+	void draw() override;
+	bool msgKeypress(const KeypressMessage &msg) override;
+};
+
+} // namespace ViewsEnh
+} // namespace MM1
+} // namespace MM
+
+#endif
diff --git a/engines/mm/module.mk b/engines/mm/module.mk
index 75a54b7a5bb..538ff2c3951 100644
--- a/engines/mm/module.mk
+++ b/engines/mm/module.mk
@@ -159,6 +159,7 @@ MODULE_OBJS += \
 	mm1/views_enh/text_entry.o \
 	mm1/views_enh/text_view.o \
 	mm1/views_enh/title.o \
+	mm1/views_enh/trade.o \
 	mm1/views_enh/trap.o \
 	mm1/views_enh/unlock.o \
 	mm1/views_enh/which_item.o \




More information about the Scummvm-git-logs mailing list