From 94cd53cac2fe36e663d068fd48b7160151f05578 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 3 Jun 2023 16:03:23 -0700 Subject: [PATCH] MM: MM1: Implement item discarding --- devtools/create_mm/files/mm1/strings_en.yml | 1 + engines/mm/mm1/views/character_info.cpp | 24 +++++++++++++++++++++ engines/mm/mm1/views/character_info.h | 7 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/devtools/create_mm/files/mm1/strings_en.yml b/devtools/create_mm/files/mm1/strings_en.yml index 77dee261f86..766edfaf47a 100644 --- a/devtools/create_mm/files/mm1/strings_en.yml +++ b/devtools/create_mm/files/mm1/strings_en.yml @@ -25,6 +25,7 @@ dialogs: legend2: " # view other 'd' discard 's' share" legend3: " 'e' equip 't' trade" legend4: "'esc' to go back 'g' gather 'u' use" + discard: "discard which item: 'a'-'f'?" equip: "equip which item: 'a'-'f'?" remove: "remove which item: '1'-'6'?" which: "which item: 'a'-'f'?" diff --git a/engines/mm/mm1/views/character_info.cpp b/engines/mm/mm1/views/character_info.cpp index 706c97586d3..cb4df042606 100644 --- a/engines/mm/mm1/views/character_info.cpp +++ b/engines/mm/mm1/views/character_info.cpp @@ -47,6 +47,11 @@ void CharacterInfo::draw() { writeString(0, 24, STRING["dialogs.character.legend4"]); break; + case DISCARD: + writeString(0, 20, STRING["dialogs.character.discard"]); + escToGoBack(0); + break; + case EQUIP: writeString(0, 20, STRING["dialogs.character.equip"]); escToGoBack(0); @@ -133,6 +138,11 @@ bool CharacterInfo::msgKeypress(const KeypressMessage &msg) { case Common::KEYCODE_c: send("CastSpell", GameMessage("SPELL", 0)); break; + case Common::KEYCODE_d: + if (!g_globals->_currCharacter->_backpack.empty()) + _state = DISCARD; + redraw(); + break; case Common::KEYCODE_e: if (!g_globals->_currCharacter->_backpack.empty()) _state = EQUIP; @@ -167,6 +177,13 @@ bool CharacterInfo::msgKeypress(const KeypressMessage &msg) { } break; + case DISCARD: + if (msg.keycode >= Common::KEYCODE_a && + msg.keycode <= Common::KEYCODE_f) + discardItem(msg.keycode - Common::KEYCODE_a); + redraw(); + break; + case EQUIP: if (msg.keycode >= Common::KEYCODE_a && msg.keycode <= Common::KEYCODE_f) @@ -305,6 +322,13 @@ bool CharacterInfo::msgGame(const GameMessage &msg) { return false; } +void CharacterInfo::discardItem(uint index) { + Inventory &inv = g_globals->_currCharacter->_backpack; + if (index < inv.size()) + inv.removeAt(index); + _state = DISPLAY; +} + void CharacterInfo::equipItem(uint index) { Common::String errMsg; _state = DISPLAY; diff --git a/engines/mm/mm1/views/character_info.h b/engines/mm/mm1/views/character_info.h index 2a19856b67a..3c77dcc1e5a 100644 --- a/engines/mm/mm1/views/character_info.h +++ b/engines/mm/mm1/views/character_info.h @@ -41,7 +41,7 @@ class CharacterInfo : public CharacterBase, MM1::Game::EquipRemove, public MM1::Game::UseItem { private: enum ViewState { - DISPLAY, EQUIP, GATHER, REMOVE, SHARE, + DISPLAY, DISCARD, EQUIP, GATHER, REMOVE, SHARE, TRADE_WITH, TRADE_KIND, TRADE_ITEM, USE }; ViewState _state = DISPLAY; Common::String _newName; @@ -50,6 +50,11 @@ private: TransferKind _tradeKind = TK_GEMS; TextEntry _textEntry; private: + /** + * Discards the item at the given index + */ + void discardItem(uint index); + /** * Equips the item at the given index */