[Scummvm-git-logs] scummvm master -> 6921ba7757684e96151a064491070db3ded28046

dreammaster dreammaster at scummvm.org
Mon Dec 18 02:00:03 CET 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
6921ba7757 XEEN: Close cast spell dialog only after a spell is successfully cast


Commit: 6921ba7757684e96151a064491070db3ded28046
    https://github.com/scummvm/scummvm/commit/6921ba7757684e96151a064491070db3ded28046
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-12-17T19:59:53-05:00

Commit Message:
XEEN: Close cast spell dialog only after a spell is successfully cast

Changed paths:
    engines/xeen/dialogs_spells.cpp
    engines/xeen/dialogs_spells.h
    engines/xeen/interface.cpp


diff --git a/engines/xeen/dialogs_spells.cpp b/engines/xeen/dialogs_spells.cpp
index abdc802..bdd4940 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 c1aeadc..4781a8d 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 458c89c..968ddbb 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();





More information about the Scummvm-git-logs mailing list