aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/menu.cpp
blob: 33e8df3f6be751a010394ff9fdafaf1c1b761eb9 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* 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 "common/events.h"
#include "common/textconsole.h"

#include "pegasus/console.h"
#include "pegasus/pegasus.h"

namespace Pegasus {

enum {
	kInterfaceOverviewButton = 0,
	kStartButton = 1,
	kRestoreButton = 2,
	kDifficultyButton = 3,
	kCreditsButton = 4,
	kQuitButton = 5
};

enum {
	kDemoStartButton = 0,
	kDemoCreditsButton = 1,
	kDemoQuitButton = 2
};	

void PegasusEngine::runMainMenu() {
	_sound->playSound("Sounds/Main Menu.aiff", true);

	// Note down how long since the last click
	uint32 lastClickTime = _system->getMillis();

	int buttonSelected = 0;
	drawMenu(buttonSelected);

	while (!shouldQuit() && _system->getMillis() - lastClickTime < 60 * 1000) {
		Common::Event event;
	
		// Ignore events for now
		while (_eventMan->pollEvent(event)) {
			switch (event.type) {
			case Common::EVENT_KEYDOWN:
				switch (event.kbd.keycode) {
				case Common::KEYCODE_UP:
					if (buttonSelected > 0) {
						buttonSelected--;
						drawMenu(buttonSelected);
					}
					break;
				case Common::KEYCODE_DOWN:
					if ((isDemo() && buttonSelected < 2) || (!isDemo() && buttonSelected < 5)) {
						buttonSelected++;
						drawMenu(buttonSelected);
					}
					break;
				case Common::KEYCODE_LEFT:
				case Common::KEYCODE_RIGHT:
					if (buttonSelected == kDifficultyButton) {
						_adventureMode = !_adventureMode;
						drawMenu(buttonSelected);
					}
					break;
				case Common::KEYCODE_RETURN:
					if (buttonSelected != kDifficultyButton) {
						drawMenuButtonSelected(buttonSelected);
						setGameMode(buttonSelected);

						if (_gameMode != kMainMenuMode) {
							_sound->stopSound();
							return;
						}

						drawMenu(buttonSelected);
					}
					break;
				case Common::KEYCODE_d:
					if (event.kbd.flags & Common::KBD_CTRL) {
						_console->attach();
						_console->onFrame();
					}
					break;
				default:
					break;
				}

				// Update our last press time too
				lastClickTime = _system->getMillis();
				break;
			default:
				break;
			}
		}
		
		//_system->updateScreen();
		_system->delayMillis(10);
	}

	if (shouldQuit())
		return;

	// Too slow! Go back and show the intro again.
	_sound->stopSound();
	_video->playMovie(_introDirectory + "/LilMovie.movie");
	_gameMode = kIntroMode;
}

void PegasusEngine::drawMenu(int buttonSelected) {
	if (isDemo()) {
		_gfx->drawPict("Images/Demo/DemoMenu.pict", 0, 0, false);
	} else {
		_gfx->drawPict("Images/Main Menu/MainMenu.mac", 0, 0, false);
		if (!_adventureMode)
			_gfx->drawPict("Images/Main Menu/BtnWlk.pict", 320, 340, false);
	}

	drawMenuButtonHighlighted(buttonSelected);
}

// FIXME: Most of these coordinates can use tweaking

static const int kMainMenuButtonX = 152;
static const char s_mainMenuButtonSuffix[] = { 'L', 'S', 'S', 'L', 'S', 'S' };
static const int s_mainMenuButtonY[] = { 202, 252, 292, 337, 382, 422 };
static const char s_demoMainMenuButtonSuffix[] = { 'S', 'S', 'L' }; // SSL!
static const int s_demoMainMenuButtonX[] = { 38, 38, 28 };
static const int s_demoMainMenuButtonY[] = { 332, 366, 408 };

void PegasusEngine::drawMenuButtonHighlighted(int buttonSelected) {
	if (isDemo())
		_gfx->drawPictTransparent(Common::String("Images/Demo/Select") + s_demoMainMenuButtonSuffix[buttonSelected] + ".pict", s_demoMainMenuButtonX[buttonSelected], s_demoMainMenuButtonY[buttonSelected], _gfx->getColor(0xff, 0xff, 0xff), true);
	else
		_gfx->drawPictTransparent(Common::String("Images/Main Menu/Select") + s_mainMenuButtonSuffix[buttonSelected] + ".pict", kMainMenuButtonX, s_mainMenuButtonY[buttonSelected], _gfx->getColor(0xf8, 0xf8, 0xf8), true);
}

static const char *s_mainMenuButtonSelSuffix[] = { "Overvi", "Start", "Restor", "", "Credit", "Quit" };
static const char *s_demoMainMenuButtonSel[] = { "Start", "Credits", "Quit" };
static const int s_mainMenuSelButtonX[] = { 198, 210, 210, 0, 210, 210 };
static const int s_demoMainMenuSelButtonX[] = { 43, 43, 34 };
static const int s_demoMainMenuSelButtonY[] = { 338, 373, 410 };

void PegasusEngine::drawMenuButtonSelected(int buttonSelected) {
	if (isDemo())
		_gfx->drawPict(Common::String("Images/Demo/") + s_demoMainMenuButtonSel[buttonSelected] + ".pict", s_demoMainMenuSelButtonX[buttonSelected], s_demoMainMenuSelButtonY[buttonSelected], false);
	else
		_gfx->drawPict(Common::String("Images/Main Menu/pb") + s_mainMenuButtonSelSuffix[buttonSelected] + ".pict", s_mainMenuSelButtonX[buttonSelected], s_mainMenuButtonY[buttonSelected] + 5, false);

	drawMenuButtonHighlighted(buttonSelected);
}

void PegasusEngine::setGameMode(int buttonSelected) {
	if (isDemo()) {
		switch (buttonSelected) {
		case kDemoStartButton:
			_gameMode = kMainGameMode;
			break;
		case kDemoCreditsButton:
			_sound->stopSound();
			runDemoCredits();
			_sound->playSound("Sounds/Main Menu.aiff", true);
			break;
		case kDemoQuitButton:
			_gameMode = kQuitMode;
			break;
		}
	} else {
		switch (buttonSelected) {
		case kInterfaceOverviewButton:
			_sound->stopSound();
			runInterfaceOverview();
			_sound->playSound("Sounds/Main Menu.aiff", true);
			break;
		case kStartButton:
			_gameMode = kMainGameMode;
			break;
		case kRestoreButton:
			showLoadDialog();
			break;
		case kCreditsButton:
			_sound->stopSound();
			runCredits();
			_sound->playSound("Sounds/Main Menu.aiff", true);
			break;
		case kQuitButton:
			_gameMode = kQuitMode;
			break;
		}
	}
}

} // End of namespace Pegasus