diff options
Diffstat (limited to 'engines/xeen')
-rw-r--r-- | engines/xeen/dialogs_spells.cpp | 61 | ||||
-rw-r--r-- | engines/xeen/dialogs_spells.h | 6 | ||||
-rw-r--r-- | engines/xeen/interface.cpp | 8 |
3 files changed, 44 insertions, 31 deletions
diff --git a/engines/xeen/dialogs_spells.cpp b/engines/xeen/dialogs_spells.cpp index abdc8028cb..bdd4940146 100644 --- a/engines/xeen/dialogs_spells.cpp +++ b/engines/xeen/dialogs_spells.cpp @@ -435,6 +435,26 @@ const char *SpellsDialog::setSpellText(Character *c, int isCasting) { /*------------------------------------------------------------------------*/ +CastSpell::CastSpell(XeenEngine *vm) : ButtonContainer(vm) { + Windows &windows = *_vm->_windows; + _oldMode = _vm->_mode; + _vm->_mode = MODE_3; + + windows[10].open(); + loadButtons(); +} + +CastSpell::~CastSpell() { + Interface &intf = *_vm->_interface; + Windows &windows = *_vm->_windows; + + windows[10].close(); + intf.unhighlightChar(); + + _vm->_mode = (Mode)_oldMode; +} + + int CastSpell::show(XeenEngine *vm) { Combat &combat = *vm->_combat; Interface &intf = *vm->_interface; @@ -459,19 +479,27 @@ int CastSpell::show(XeenEngine *vm) { Character *c = &party._activeParty[charNum]; intf.highlightChar(charNum); - CastSpell *dlg = new CastSpell(vm); - int spellId = dlg->execute(c); - delete dlg; - - return spellId; + return show(vm, c); } int CastSpell::show(XeenEngine *vm, Character *&c) { + Spells &spells = *vm->_spells; CastSpell *dlg = new CastSpell(vm); - int spellId = dlg->execute(c); - delete dlg; + int spellId; + int result = -1; - return spellId; + do { + spellId = dlg->execute(c); + + if (g_vm->shouldQuit() || spellId == -1) { + result = 0; + } else { + result = spells.castSpell(c, (MagicSpell)spellId); + } + } while (result == -1); + + delete dlg; + return result; } int CastSpell::execute(Character *&c) { @@ -482,12 +510,6 @@ int CastSpell::execute(Character *&c) { Windows &windows = *_vm->_windows; Window &w = windows[10]; - Mode oldMode = _vm->_mode; - _vm->_mode = MODE_3; - - w.open(); - loadButtons(); - int spellId = -1; bool redrawFlag = true; do { @@ -524,8 +546,8 @@ int CastSpell::execute(Character *&c) { case Common::KEYCODE_F5: case Common::KEYCODE_F6: // Only allow changing character if the party is not in combat - if (oldMode != MODE_COMBAT) { - _vm->_mode = oldMode; + if (_oldMode != MODE_COMBAT) { + _vm->_mode = (Mode)_oldMode; _buttonValue -= Common::KEYCODE_F1; if (_buttonValue < (int)party._activeParty.size()) { @@ -549,7 +571,7 @@ int CastSpell::execute(Character *&c) { case Common::KEYCODE_n: // Select new spell - _vm->_mode = oldMode; + _vm->_mode = (Mode)_oldMode; c = SpellsDialog::show(_vm, this, c, 1); redrawFlag = true; break; @@ -559,13 +581,8 @@ int CastSpell::execute(Character *&c) { } } while (!_vm->shouldQuit() && _buttonValue != Common::KEYCODE_ESCAPE); - w.close(); - intf.unhighlightChar(); - if (_vm->shouldQuit()) spellId = -1; - - _vm->_mode = oldMode; return spellId; } diff --git a/engines/xeen/dialogs_spells.h b/engines/xeen/dialogs_spells.h index c1aeadc68d..4781a8d08c 100644 --- a/engines/xeen/dialogs_spells.h +++ b/engines/xeen/dialogs_spells.h @@ -60,8 +60,10 @@ public: class CastSpell : public ButtonContainer { private: SpriteResource _iconSprites; - - CastSpell(XeenEngine *vm) : ButtonContainer(vm) {} + int _oldMode; +private: + CastSpell(XeenEngine *vm); + ~CastSpell(); int execute(Character *&c); diff --git a/engines/xeen/interface.cpp b/engines/xeen/interface.cpp index 458c89cc00..968ddbbb59 100644 --- a/engines/xeen/interface.cpp +++ b/engines/xeen/interface.cpp @@ -531,17 +531,11 @@ void Interface::perform() { draw3d(true); } - int result = 0; Character *c = &party._activeParty[(spells._lastCaster < 0 || spells._lastCaster >= (int)party._activeParty.size()) ? (int)party._activeParty.size() - 1 : spells._lastCaster]; - do { - int spellId = CastSpell::show(_vm, c); - if (spellId == -1) - break; - result = spells.castSpell(c, (MagicSpell)spellId); - } while (result != -1); + int result = CastSpell::show(_vm, c); if (result == 1) { chargeStep(); |