From eca76ea91ec0b932d90d20608db2f4c1b9aae1cf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 30 Mar 2018 20:08:31 -0400 Subject: XEEN: Fix highlighting of character when Cast Spell dialog is opened --- engines/xeen/character.cpp | 11 +++++++++++ engines/xeen/character.h | 18 ++++++++++++++++++ engines/xeen/dialogs/dialogs_spells.cpp | 7 ++++--- engines/xeen/interface.cpp | 6 ++++++ engines/xeen/interface.h | 10 ++++++++++ engines/xeen/party.h | 2 +- 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp index 333bad80fe..72d8ed653e 100644 --- a/engines/xeen/character.cpp +++ b/engines/xeen/character.cpp @@ -37,6 +37,17 @@ void AttributePair::synchronize(Common::Serializer &s) { /*------------------------------------------------------------------------*/ +int CharacterArray::indexOf(const Character &c) { + for (uint idx = 0; idx < size(); ++idx) { + if ((*this)[idx] == c) + return idx; + } + + return -1; +} + +/*------------------------------------------------------------------------*/ + Character::Character(): _weapons(this), _armor(this), _accessories(this), _misc(this), _items(this) { clear(); _faceSprites = nullptr; diff --git a/engines/xeen/character.h b/engines/xeen/character.h index b45cfaf5ad..43531c74cf 100644 --- a/engines/xeen/character.h +++ b/engines/xeen/character.h @@ -165,6 +165,16 @@ public: */ Character(const Character &src); + /** + * Equality operator + */ + bool operator==(const Character &src) const { return src._rosterId == _rosterId; } + + /** + * Inequality operator + */ + bool operator!=(const Character &src) const { return src._rosterId != _rosterId; } + /** * Clears the data for a character */ @@ -346,6 +356,14 @@ public: void clearConditions(); }; +class CharacterArray : public Common::Array { +public: + /** + * Returns the index of a given character in the array + */ + int indexOf(const Character &c); +}; + } // End of namespace Xeen #endif /* XEEN_CHARACTER_H */ diff --git a/engines/xeen/dialogs/dialogs_spells.cpp b/engines/xeen/dialogs/dialogs_spells.cpp index 21bd7e2776..828281e688 100644 --- a/engines/xeen/dialogs/dialogs_spells.cpp +++ b/engines/xeen/dialogs/dialogs_spells.cpp @@ -383,7 +383,6 @@ CastSpell::~CastSpell() { int CastSpell::show(XeenEngine *vm) { Combat &combat = *vm->_combat; - Interface &intf = *vm->_interface; Party &party = *vm->_party; Spells &spells = *vm->_spells; int charNum; @@ -403,17 +402,19 @@ int CastSpell::show(XeenEngine *vm) { } Character *c = &party._activeParty[charNum]; - intf.highlightChar(charNum); - return show(vm, c); } int CastSpell::show(XeenEngine *vm, Character *&c) { + Interface &intf = *vm->_interface; Spells &spells = *vm->_spells; CastSpell *dlg = new CastSpell(vm); int spellId; int result = -1; + // Highlight the character + intf.highlightChar(c); + do { spellId = dlg->execute(c); diff --git a/engines/xeen/interface.cpp b/engines/xeen/interface.cpp index de343feb15..648b01f2c9 100644 --- a/engines/xeen/interface.cpp +++ b/engines/xeen/interface.cpp @@ -118,6 +118,12 @@ void PartyDrawer::highlightChar(int charId) { } } +void PartyDrawer::highlightChar(const Character *c) { + int charNum = _vm->_party->_activeParty.indexOf(*c); + if (charNum != -1) + highlightChar(charNum); +} + void PartyDrawer::unhighlightChar() { Resources &res = *_vm->_resources; Windows &windows = *_vm->_windows; diff --git a/engines/xeen/interface.h b/engines/xeen/interface.h index bbc2a77f1e..6de04495b2 100644 --- a/engines/xeen/interface.h +++ b/engines/xeen/interface.h @@ -71,8 +71,18 @@ public: void drawParty(bool updateFlag); + /** + * Highlights the specified character in the party display at the bottom of the screen + * @param charId Character number + */ void highlightChar(int charId); + /** + * Highlights the specified character in the party display at the bottom of the screen + * @param c Character to highlight + */ + void highlightChar(const Character *c); + void unhighlightChar(); void resetHighlight(); diff --git a/engines/xeen/party.h b/engines/xeen/party.h index 23a9407a76..322ae2b052 100644 --- a/engines/xeen/party.h +++ b/engines/xeen/party.h @@ -215,7 +215,7 @@ public: public: // Other party related runtime data Roster _roster; - Common::Array _activeParty; + CharacterArray _activeParty; bool _newDay; bool _isNight; bool _stepped; -- cgit v1.2.3