aboutsummaryrefslogtreecommitdiff
path: root/engines/illusions/duckman/menusystem_duckman.cpp
blob: 263cda83ce13e7045959c65eb04ed36acb1f4af6 (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
/* 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 "illusions/illusions.h"
#include "illusions/actor.h"
#include "illusions/duckman/illusions_duckman.h"
#include "illusions/duckman/menusystem_duckman.h"

namespace Illusions {

// DuckmanMenuSystem

DuckmanMenuSystem::DuckmanMenuSystem(IllusionsEngine_Duckman *vm)
	: BaseMenuSystem(vm), _vm(vm) {
	clearMenus();
}

DuckmanMenuSystem::~DuckmanMenuSystem() {
	freeMenus();
}

void DuckmanMenuSystem::runMenu(MenuChoiceOffsets menuChoiceOffsets, int16 *menuChoiceOffset,
	uint32 menuId, uint32 duration, uint timeOutMenuChoiceIndex, uint32 menuCallerThreadId) {
	
	debug(0, "DuckmanMenuSystem::runMenu(%08X)", menuId);

	setTimeOutDuration(duration, timeOutMenuChoiceIndex);
	setMenuCallerThreadId(menuCallerThreadId);
	setMenuChoiceOffsets(menuChoiceOffsets, menuChoiceOffset);

	int rootMenuId = convertRootMenuId(menuId | 0x180000);
	BaseMenu *rootMenu = getMenuById(rootMenuId);
	openMenu(rootMenu);

}

void DuckmanMenuSystem::clearMenus() {
	for (int i = 0; i < kDuckmanLastMenuIndex; ++i)
		_menus[i] = 0;
}

void DuckmanMenuSystem::freeMenus() {
	for (int i = 0; i < kDuckmanLastMenuIndex; ++i)
		delete _menus[i];
}

BaseMenu *DuckmanMenuSystem::getMenuById(int menuId) {
	if (!_menus[menuId])
		_menus[menuId] = createMenuById(menuId);
	return _menus[menuId];
}

BaseMenu *DuckmanMenuSystem::createMenuById(int menuId) {
	switch (menuId) {
	case kDuckmanMainMenu:
		return createMainMenu();
	case kDuckmanPauseMenu:
		return createPauseMenu();
	case kDuckmanQueryRestartMenu:
		return createQueryRestartMenu();
	case kDuckmanQueryQuitMenu:
		return createQueryQuitMenu();
	case kDuckmanSaveCompleteMenu:
		return createSaveCompleteMenu();
	case kDuckmanOptionsMenu:
		return createOptionsMenu();
	default:
		error("DuckmanMenuSystem::createMenuById() Invalid menu id %d", menuId);
	}
}

BaseMenu *DuckmanMenuSystem::createMainMenu() {
	BaseMenu *menu = new BaseMenu(this, 0x00120003, 12, 17, 11, 27, 0);
	menu->addMenuItem(new MenuItem("Start New Game", new MenuActionReturnChoice(this, 11)));
	menu->addMenuItem(new MenuItem("Load Saved Game", new MenuActionLoadGame(this, 1)));
	// TODO menu->addMenuItem(new MenuItem("Options", new MenuActionEnterMenu(this, kDuckmanOptionsMenu)));
	menu->addMenuItem(new MenuItem("Quit Game", new MenuActionEnterQueryMenu(this, kDuckmanQueryQuitMenu, 12)));
	return menu;
}

BaseMenu *DuckmanMenuSystem::createLoadGameMenu() {
	return 0; // TODO
}

BaseMenu *DuckmanMenuSystem::createOptionsMenu() {
	BaseMenu *menu = new BaseMenu(this, 0x00120003, 12, 17, 11, 27, 1);
	menu->addText("              GAME OPTIONS             @@@@");
	menu->addText("--------------------------------------");
	menu->addMenuItem(new MenuItem("SFX Volume     @@{~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
	menu->addMenuItem(new MenuItem("Music Volume  @@@{~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
	menu->addMenuItem(new MenuItem("Speech Volume {~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
	menu->addMenuItem(new MenuItem("Text Duration @@@{~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
	menu->addMenuItem(new MenuItem("Restore Defaults                      @@", new MenuActionReturnChoice(this, 21)));
	menu->addMenuItem(new MenuItem("Back                                       @@@", new MenuActionLeaveMenu(this)));
	return menu;
}

BaseMenu *DuckmanMenuSystem::createPauseMenu() {
	BaseMenu *menu = new BaseMenu(this, 0x00120003, 12, 17, 11, 27, 1);
	menu->addText("   Game Paused");
	menu->addText("--------------------");
	menu->addMenuItem(new MenuItem("Resume", new MenuActionReturnChoice(this, 21)));
	menu->addMenuItem(new MenuItem("Load Game", new MenuActionLoadGame(this, 1)));
	menu->addMenuItem(new MenuItem("Save Game", new MenuActionSaveGame(this, 11)));
	menu->addMenuItem(new MenuItem("Restart Game", new MenuActionEnterQueryMenu(this, kDuckmanQueryRestartMenu, 2)));
	menu->addMenuItem(new MenuItem("Options", new MenuActionEnterMenu(this, kDuckmanOptionsMenu)));
	menu->addMenuItem(new MenuItem("Quit Game", new MenuActionEnterQueryMenu(this, kDuckmanQueryQuitMenu, 23)));
	return menu;
}

BaseMenu *DuckmanMenuSystem::createQueryRestartMenu() {
	return 0; // TODO
}

BaseMenu *DuckmanMenuSystem::createQueryQuitMenu() {
	BaseMenu *menu = new BaseMenu(this, 0x00120003, 12, 17, 11, 27, 2);
	menu->addText("Do you really want to quit?");
	menu->addText("-------------------------------");
	menu->addMenuItem(new MenuItem("Yes, I'm outta here", new MenuActionReturnChoice(this, getQueryConfirmationChoiceIndex())));
	menu->addMenuItem(new MenuItem("No, just kidding", new MenuActionLeaveMenu(this)));
	return menu;
}

BaseMenu *DuckmanMenuSystem::createSaveCompleteMenu() {
	BaseMenu *menu = new BaseMenu(this, 0x00120003, 12, 17, 11, 27, 1);
	menu->addText("Game Saved");
	menu->addText("-------------");
	menu->addMenuItem(new MenuItem("Continue", new MenuActionReturnChoice(this, 1)));
	return menu;
}

int DuckmanMenuSystem::convertRootMenuId(uint32 menuId) {
	switch (menuId) {
	case 0x180001:
		return kDuckmanMainMenu;
	case 0x180002:
		return kDuckmanPauseMenu;
	case 0x180005:
		return kDuckmanSaveCompleteMenu;
	/*
	case 0x180006: // save game failed menu
	case 0x180007: // load game failed menu
	*/
	/* TODO CHECKME Another pause menu?
	case 0x180008:
		menuData = &g_menuDataPause;
	*/
	default:
		error("DuckmanMenuSystem() Menu ID %08X not found", menuId);
	}
}

bool DuckmanMenuSystem::initMenuCursor() {
	bool cursorInitialVisibleFlag = false;
	Control *cursorControl = _vm->getObjectControl(Illusions::CURSOR_OBJECT_ID);
	if (cursorControl) {
		if (cursorControl->_flags & 1)
			cursorInitialVisibleFlag = false;
		cursorControl->appearActor();
	} else {
		Common::Point pos = _vm->getNamedPointPosition(0x70001);
		_vm->_controls->placeActor(0x50001, pos, 0x60001, Illusions::CURSOR_OBJECT_ID, 0);
		cursorControl = _vm->getObjectControl(Illusions::CURSOR_OBJECT_ID);
	}
	return cursorInitialVisibleFlag;
}

int DuckmanMenuSystem::getGameState() {
	return _vm->_cursor._gameState;
}

void DuckmanMenuSystem::setMenuCursorNum(int cursorNum) {
	Control *mouseCursor = _vm->getObjectControl(Illusions::CURSOR_OBJECT_ID);
	_vm->setCursorActorIndex(5, cursorNum, 0);
	mouseCursor->startSequenceActor(0x60001, 2, 0);
}

void DuckmanMenuSystem::setGameState(int gameState) {
	_vm->_cursor._gameState = gameState;
}

} // End of namespace Illusions