Skip to content

Commit

Permalink
XEEN: Fix highlighting of character when Cast Spell dialog is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Mar 31, 2018
1 parent 83412c9 commit eca76ea
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
11 changes: 11 additions & 0 deletions engines/xeen/character.cpp
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions engines/xeen/character.h
Expand Up @@ -165,6 +165,16 @@ class Character {
*/
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
*/
Expand Down Expand Up @@ -346,6 +356,14 @@ class Character {
void clearConditions();
};

class CharacterArray : public Common::Array<Character> {
public:
/**
* Returns the index of a given character in the array
*/
int indexOf(const Character &c);
};

} // End of namespace Xeen

#endif /* XEEN_CHARACTER_H */
7 changes: 4 additions & 3 deletions engines/xeen/dialogs/dialogs_spells.cpp
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions engines/xeen/interface.cpp
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions engines/xeen/interface.h
Expand Up @@ -71,8 +71,18 @@ class PartyDrawer {

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();
Expand Down
2 changes: 1 addition & 1 deletion engines/xeen/party.h
Expand Up @@ -215,7 +215,7 @@ class Party {
public:
// Other party related runtime data
Roster _roster;
Common::Array<Character> _activeParty;
CharacterArray _activeParty;
bool _newDay;
bool _isNight;
bool _stepped;
Expand Down

0 comments on commit eca76ea

Please sign in to comment.