aboutsummaryrefslogtreecommitdiff
path: root/backends/wince/CEActions.cpp
blob: ed5b1b47c204b71926a54f6243d59cc785b5a1fd (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
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001-2004 The ScummVM project
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */


#include "stdafx.h"
#include "CEActions.h"
#include "KeysBuffer.h"

#include "gui/message.h"

#include "scumm/scumm.h"

#include "common/config-manager.h"

const String actionNames[] = { 
	"none", 
	"Pause", 
	"Save", 
	"Quit",
	"Skip",
	"Hide",
	"Keyboard",
	"Sound",
	"Right click",
	"Cursor",
	"Free look"
};

CEActions* CEActions::Instance() {		
	return _instance;		
}

String CEActions::actionName(ActionType action) {
	return actionNames[action];
}

int CEActions::size() {
	return ACTION_LAST - 1;
}

CEActions::CEActions(OSystem_WINCE3 *mainSystem, GameDetector &detector) :
	_mainSystem(mainSystem), _mapping_active(false), _right_click_needed(false) {
	int i;
	bool is_simon = (strcmp(detector._targetName.c_str(), "simon") == 0);
	bool is_sword1 = (detector._targetName == "sword1");
	bool is_sword2 = (strcmp(detector._targetName.c_str(), "sword2") == 0);
	bool is_queen = (detector._targetName == "queen");
	bool is_sky = (detector._targetName == "sky");

	for (i=0; i<ACTION_LAST; i++)
		_action_mapping[i] = 0;

	// See if a right click mapping could be needed
	if (is_sword1 || is_sword2 || is_sky || is_queen || detector._targetName == "comi" ||
		detector._targetName == "samnmax")
		_right_click_needed = true;

	// Initialize keys for different actions
	// Pause
	_key_action[ACTION_PAUSE].setAscii(VK_SPACE);
	_action_enabled[ACTION_PAUSE] = true;
	// Save
	if (is_simon) 
		_action_enabled[ACTION_SAVE] = false;
	else
	if (is_queen) {
		_action_enabled[ACTION_SAVE] = true;
		_key_action[ACTION_SAVE].setAscii(282); // F1 key
	}
	else
	if (is_sky) {
		_action_enabled[ACTION_SAVE] = true;
		_key_action[ACTION_SAVE].setAscii(63); 
	}
	else {
		_action_enabled[ACTION_SAVE] = true;
		_key_action[ACTION_SAVE].setAscii(319); // F5 key
	}
	// Quit
	_action_enabled[ACTION_QUIT] = true;
	// Skip
	_action_enabled[ACTION_SKIP] = true;
	if (is_simon || is_sky || is_sword2 || is_queen || is_sword1)
		_key_action[ACTION_SKIP].setAscii(VK_ESCAPE);
	else
		_key_action[ACTION_SKIP].setAscii(Scumm::KEY_ALL_SKIP);
	// Hide
	_action_enabled[ACTION_HIDE] = true;
	// Keyboard 
	_action_enabled[ACTION_KEYBOARD] = true;
	// Sound
	_action_enabled[ACTION_SOUND] = true;
	// RightClick
	_action_enabled[ACTION_RIGHTCLICK] = true;
	// Cursor
	_action_enabled[ACTION_CURSOR] = true;
	// Freelook
	_action_enabled[ACTION_FREELOOK] = true;
}


CEActions::~CEActions() {
}

void CEActions::init(OSystem_WINCE3 *mainSystem, GameDetector &detector) {
	_instance = new CEActions(mainSystem, detector);
}

bool CEActions::perform(ActionType action) {
	switch (action) {
		case ACTION_PAUSE:
		case ACTION_SAVE:
		case ACTION_SKIP:
			KeysBuffer::Instance()->simulate(&_key_action[action]);
			return true;
		case ACTION_KEYBOARD:
			_mainSystem->swap_panel();
			return true;
		case ACTION_HIDE:
			_mainSystem->swap_panel_visibility();
			return true;
		case ACTION_SOUND:
			_mainSystem->swap_sound_master();
			return true;
		case ACTION_RIGHTCLICK:
			_mainSystem->add_right_click();
			return true;
		case ACTION_CURSOR:
			_mainSystem->swap_mouse_visibility();
			return true;
		case ACTION_QUIT:
			GUI::MessageDialog alert("Do you want to quit ?", "Yes", "No");
			if (alert.runModal() == 1)
				_mainSystem->quit();
			return true;
	}
	return false;
}

bool CEActions::isActive(ActionType action) {
	return false;
}

bool CEActions::isEnabled(ActionType action) {
	return _action_enabled[action];
}

void CEActions::beginMapping(bool start) {
	_mapping_active = start;
}

bool CEActions::mappingActive() {
	return _mapping_active;
}

bool CEActions::performMapped(unsigned int keyCode, bool pushed) {
	int i;
	
	for (i=0; i<ACTION_LAST; i++) {
		if (_action_mapping[i] == keyCode) {
			if (pushed)
				return perform((ActionType)(i + 1));
			else
				return true;
		}
	}

	return false;
}

bool CEActions::loadMapping() {
	const char *tempo;
	int version;
	int i;
	version = ConfMan.getInt("CE_mapping_version");
	if (version != ACTIONS_VERSION)
		return false;
	tempo = ConfMan.get("CE_mapping").c_str();
	if (tempo && strlen(tempo)) {
		for (i=0; i<ACTION_LAST; i++) {
			char x[6];
			int j;
			memset(x, 0, sizeof(x));
			memcpy(x, tempo + 5 * i, 4);
			sscanf(x, "%x", &j);
			_action_mapping[i] = j;
		}
		return true;
	}
	else
		return false;
}

bool CEActions::saveMapping() {
	char tempo[200];
	int i;
	tempo[0] = '\0';
	ConfMan.set("CE_mapping_version", ACTIONS_VERSION);
	for (i=0; i<ACTION_LAST; i++) {
		char x[4];
		sprintf(x, "%.4x ", _action_mapping[i]);
		strcat(tempo, x);
	}
	ConfMan.set("CE_mapping", tempo);
	ConfMan.flushToDisk();
	return true;
}

unsigned int CEActions::getMapping(ActionType action) {
	return _action_mapping[action - 1];
}


void CEActions::setMapping(ActionType action, unsigned int keyCode) {
	int i;

	for (i=0; i<ACTION_LAST; i++) {
		if (_action_mapping[i] == keyCode)
			_action_mapping[i] = 0;
	}

	_action_mapping[action - 1] = keyCode;
}

bool CEActions::needsRightClickMapping() {
	if (!_right_click_needed)
		return false;
	else
		return (_action_mapping[ACTION_RIGHTCLICK] == 0);
}

CEActions *CEActions::_instance = NULL;