aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/PalmOS/Src/launcher/forms/formSelect.cpp
blob: 641d646bb2f96e8e7275723f4538a6758a8abf1e (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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include <PalmOS.h>
#include "StarterRsc.h"
#include "formUtil.h"
#include "games.h"
#include "start.h"

#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))

static Char **items = NULL;
Int16 selectedEngine = -1;

// Supported games
static const char *engine_agos[] = {
	"Demon in my Pocket",
	"Elvira - Mistress of the Dark",
	"Elvira II - The Jaws of Cerberus",
	"Jumble",
	"NoPatience",
	"Simon the Sorcerer I",
	"Simon the Sorcerer II",
	"Swampy Adventures",
	"The Feeble Files",
	"Waxworks"
};

static const char *engine_sky[] = {
	"Floppy, CD and Demo"
};

static const char *engine_sword1[] = {
	"The Shadow of the Templars (PC/Mac)",
	"The Shadow of the Templars (Demo)"
};

static const char *engine_sword2[] = {
	"The Smoking Mirror",
	"The Smoking Mirror (Demo)"
};

static const char *engine_cine[] = {
	"Future Wars",
	"Operation Stealth"
};

static const char *engine_queen[] = {
	"Flight of the Amazon Queen"
};

static const char *engine_lure[] = {
	"Lure of the Tempress"
};

static const char *engine_gob[] = {
	"Bargon Attack",
	"Gobliiins",
	"Gobliins 2",
	"Goblins Quest 3",
	"The Bizarre Adventures of Woodruff and the Schnibble",
	"Ween: The Prophecy",
};

static const char *engine_kyra[] = {
	"The Legend of Kyrandia",
	"The Legend of Kyrandia: The Hand of Fate",
	"The Legend of Kyrandia: Malcolm's Revenge"
};

static const char *engine_parallaction[] = {
	"Nippon Safes Inc."
};

static const char *engine_saga[] = {
	"I Have No Mouth And I Must Scream",
	"Inherit the earth"
};

static const char *engine_scumm[] = {
	"Day of the Tentacle",
	"Indiana Jones and the Fate of Atlantis",
	"Indiana Jones and the Last Crusade",
	"Loom",
	"Maniac Mansion",
	"Monkey Island 2: LeChuck's Revenge",
	"Passport to Adventure",
	"Sam & Max Hit the Road",
	"The Secret of Monkey Island"
	"Zak McKracken and the Alien Mindbenders"
};

static const char *engine_agi[] = {
	"AGI Tetris",
	"Caitlyn's Destiny",
	"Donald Duck's Playground",
	"Fanmade AGI game",
	"Gold Rush!",
	"King's Quest I: Quest for the Crown",
	"King's Quest II: Romancing the Throne",
	"King's Quest III: To Heir Is Human",
	"King's Quest IV: The Perils of Rosella",
	"Leisure Suit Larry in the Land of the Lounge Lizards",
	"Mixed-Up Mother Goose",
	"Manhunter 1: New York",
	"Manhunter 2: San Francisco",
	"Police Quest I: In Pursuit of the Death Angel",
	"Serguei's Destiny 1",
	"Serguei's Destiny 2",
	"Space Quest 0: Replicated",
	"Space Quest I: The Sarien Encounter",
	"Space Quest II: Vohaul's Revenge",
	"Space Quest X: The Lost Chapter",
	"The Black Cauldron",
	"Xmas Card"
};

static const char *engine_touche[] = {
	"Touche: The Adventures of the Fifth Musketeer"
};

static const char *engine_cruise[] = {
	"Cruise for a Corpse"
};

static const struct {
	int size;
	const char **listP;
} supported[] = {
	{ ARRAYSIZE(engine_agos), engine_agos },
	{ ARRAYSIZE(engine_sky), engine_sky },
	{ ARRAYSIZE(engine_sword1), engine_sword1 },
	{ ARRAYSIZE(engine_sword2), engine_sword2 },
	{ ARRAYSIZE(engine_cine), engine_cine },
	{ ARRAYSIZE(engine_queen), engine_queen },
	{ ARRAYSIZE(engine_lure), engine_lure },
	{ ARRAYSIZE(engine_gob), engine_gob },
	{ ARRAYSIZE(engine_kyra), engine_kyra },
	{ ARRAYSIZE(engine_parallaction), engine_parallaction },
	{ ARRAYSIZE(engine_saga), engine_saga },
	{ ARRAYSIZE(engine_scumm), engine_scumm },
	{ ARRAYSIZE(engine_agi), engine_agi },
	{ ARRAYSIZE(engine_touche), engine_touche },
	{ ARRAYSIZE(engine_cruise), engine_cruise }
};

static void SelectorSetList(Int16 sel) {
	ListType *listP;
	FormPtr frmP = FrmGetActiveForm();

	Boolean toBeDrawn = (items != NULL);
	if (items)
		MemPtrFree(items);

	listP = (ListType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, EngineSupportedList));
	items = (Char **)MemPtrNew(supported[sel].size * sizeof(Char *));

	for (int i = 0; i < supported[sel].size; i++)
		items[i] = (Char *)supported[sel].listP[i];

	LstSetListChoices (listP, items, supported[sel].size);
	LstSetTopItem(listP, 0);
	LstSetSelection(listP, -1);

	if (toBeDrawn) {
		WinScreenLock(winLockCopy);
		LstDrawList(listP);
		WinScreenUnlock();
	}
}

static void SelectorFormInit() {
	ListType *listP;
	FormPtr frmP = FrmGetActiveForm();

	listP = (ListType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, EngineListList));
	itemsText = (Char **)MemPtrNew(ENGINE_COUNT * sizeof(Char *));
	
	for (int i = 0; i < ENGINE_COUNT; i++)
		itemsText[i] = (Char *)engines[i].nameP;
		
	LstSetListChoices (listP, itemsText, ENGINE_COUNT);
	LstSetSelection(listP, 0);

	SelectorSetList(0);

	FrmDrawForm(frmP);
}

static void SelectorFormFree(bool quit) {
	items = NULL;

	if (!quit) {
		ListType *listP = (ListType *)GetObjectPtr(EngineListList);
		Int16 sel = LstGetSelection(listP);

		FrmReturnToMain();
		StartScummVM(sel);

	} else {
		FrmReturnToMain();

		if (bDirectMode) {
			// force exit if nothing selected
			EventType event;
			event.eType = keyDownEvent;
			event.data.keyDown.chr = vchrLaunch;
			event.data.keyDown.modifiers = commandKeyMask;
			EvtAddUniqueEventToQueue(&event, 0, true);
		}
	}
}

Boolean SelectorFormHandleEvent(EventPtr eventP) {
	FormPtr frmP = FrmGetActiveForm();
	Boolean handled = false;

	switch (eventP->eType) {
		case frmOpenEvent:
			SelectorFormInit();
			handled = true;
			break;

		case frmCloseEvent:
			SelectorFormFree(true);
			handled = true;
			break;

		case lstSelectEvent:
			if (eventP->data.lstSelect.listID == EngineSupportedList)
				LstSetSelection(eventP->data.lstSelect.pList, -1);
			else 
				SelectorSetList(eventP->data.lstSelect.selection);
			handled = true;
			break;

		case ctlSelectEvent:
			switch (eventP->data.ctlSelect.controlID)
			{
				case EngineOkButton:
					SelectorFormFree(false);
					break;

				case EngineCancelButton:
					SelectorFormFree(true);
					break;
			}
			handled = true;
			break;

		default:
			break;
	}
	
	return handled;
}