aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/dialogs_whowill.cpp
blob: a2be4e3a944d42c1e10832c4e85c7f77ad67d546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "xeen/dialogs_whowill.h"
#include "xeen/resources.h"
#include "xeen/xeen.h"

namespace Xeen {

int WhoWill::show(XeenEngine *vm, int message, int action, bool type) {
	WhoWill *dlg = new WhoWill(vm);
	int result = dlg->execute(message, action, type);
	delete dlg;

	return result;
}

int WhoWill::execute(int message, int action, bool type) {
	EventsManager &events = *_vm->_events;
	Interface &intf = *_vm->_interface;
	Map &map = *_vm->_map;
	Party &party = *_vm->_party;
	Scripts &scripts = *_vm->_scripts;
	LocationManager &loc = *_vm->_locations;
	Windows &windows = *_vm->_windows;
	int numFrames;

	if (party._activeParty.size() <= 1)
		// Unless there's at least two characters, just return the first one
		return 1;

	windows[38].close();
	windows[12].close();

	Common::String actionStr = type ? map._events._text[action] : Res.WHO_WILL_ACTIONS[action];
	Common::String msg = Common::String::format(Res.WHO_WILL, actionStr.c_str(),
		Res.WHO_ACTIONS[message], party._activeParty.size());

	windows[36].open();
	windows[36].writeString(msg);
	windows[36].update();

	intf._face1State = map._headData[party._mazePosition.y][party._mazePosition.x]._left;
	intf._face2State = map._headData[party._mazePosition.y][party._mazePosition.x]._right;

	while (!_vm->shouldQuit()) {
		events.updateGameCounter();

		if (windows[11]._enabled) {
			loc.drawAnim(false);
			windows[36].frame();
			numFrames = 3;
		} else {
			intf.draw3d(false);
			windows[36].frame();
			windows[3].update();
			numFrames = 1;
		}

		events.wait(numFrames);
		checkEvents(_vm);
		if (!_buttonValue)
			continue;

		if (_buttonValue == 27) {
			_buttonValue = 0;
			break;
		} else if (_buttonValue >= Common::KEYCODE_F1 && _buttonValue <= Common::KEYCODE_F6) {
			_buttonValue -= Common::KEYCODE_F1 - 1;
			if (_buttonValue > (int)party._activeParty.size())
				continue;

			if (party._activeParty[_buttonValue - 1].noActions())
				continue;

			scripts._whoWill = _buttonValue;
			break;
		}
	}

	intf._face1State = intf._face2State = 2;
	windows[36].close();
	return _buttonValue;
}

} // End of namespace Xeen