Ticket #8711: backends-lib.v5.4

File backends-lib.v5.4, 50.3 KB (added by SF/sbatyuk, 13 years ago)

prefinal key mapper patch

Line 
1Index: backends/events/default/default-events.cpp
2===================================================================
3--- backends/events/default/default-events.cpp (revision 28773)
4+++ backends/events/default/default-events.cpp (working copy)
5@@ -37,14 +37,17 @@
6 _boss(boss),
7 _buttonState(0),
8 _modifierState(0),
9- _shouldQuit(false) {
10+ _shouldQuit(false),
11+ _keyMapper(boss->getKeyMapper()) {
12
13 assert(_boss);
14
15 // Reset key repeat
16 _currentKeyDown.keycode = 0;
17 }
18-
19+Mapping::KeyMapper *DefaultEventManager::getKeyMapper() {
20+ return _keyMapper;
21+}
22 bool DefaultEventManager::pollEvent(Common::Event &event) {
23 uint32 time = _boss->getMillis();
24 bool result;
25@@ -52,6 +55,14 @@
26 result = _boss->pollEvent(event);
27
28 if (result) {
29+ // check if we have to resolve key mapping
30+ if (_keyMapper) {
31+ bool isMapped = _keyMapper->resolve(event);
32+ if (!isMapped) {
33+ return false;
34+ }
35+ }
36+
37 event.synthetic = false;
38 switch (event.type) {
39 case Common::EVENT_KEYDOWN:
40Index: backends/events/default/default-events.h
41===================================================================
42--- backends/events/default/default-events.h (revision 28773)
43+++ backends/events/default/default-events.h (working copy)
44@@ -48,6 +48,7 @@
45 int _buttonState;
46 int _modifierState;
47 bool _shouldQuit;
48+ Mapping::KeyMapper *_keyMapper;
49
50 // for continuous events (keyDown)
51 enum {
52@@ -70,6 +71,7 @@
53 virtual Common::Point getMousePos() const { return _mousePos; }
54 virtual int getButtonState() const { return _buttonState; }
55 virtual int getModifierState() const { return _modifierState; }
56+ virtual Mapping::KeyMapper *getKeyMapper();
57 virtual int shouldQuit() const { return _shouldQuit; }
58 };
59
60Index: backends/platform/sdl/sdl.cpp
61===================================================================
62--- backends/platform/sdl/sdl.cpp (revision 28773)
63+++ backends/platform/sdl/sdl.cpp (working copy)
64@@ -170,6 +170,8 @@
65 memset(&_mouseCurState, 0, sizeof(_mouseCurState));
66
67 _inited = false;
68+
69+ _keyMapper = NULL;
70 }
71
72 OSystem_SDL::~OSystem_SDL() {
73Index: backends/platform/sdl/sdl.h
74===================================================================
75--- backends/platform/sdl/sdl.h (revision 28773)
76+++ backends/platform/sdl/sdl.h (working copy)
77@@ -410,6 +410,23 @@
78 virtual bool remapKey(SDL_Event &ev, Common::Event &event);
79
80 void handleScalerHotkeys(const SDL_KeyboardEvent &key);
81+
82+ // backend lib methods
83+
84+private:
85+ Mapping::KeyMapper *_keyMapper;
86+
87+public:
88+ virtual Common::String keyNameResolve(Common::KeyCode key){
89+ return Common::String(SDL_GetKeyName((SDLKey)key));
90+ }
91+
92+ virtual Mapping::KeyMapper *getKeyMapper() {
93+ if(_keyMapper == NULL){
94+ _keyMapper = new Mapping::KeyMapper();
95+ }
96+ return _keyMapper;
97+ }
98 };
99
100 #endif
101Index: backends/platform/common/key-mapper.h
102===================================================================
103--- backends/platform/common/key-mapper.h (revision 0)
104+++ backends/platform/common/key-mapper.h (revision 0)
105@@ -0,0 +1,94 @@
106+/* ScummVM - Graphic Adventure Engine
107+ *
108+ * ScummVM is the legal property of its developers, whose names
109+ * are too numerous to list here. Please refer to the COPYRIGHT
110+ * file distributed with this source distribution.
111+ *
112+ * This program is free software; you can redistribute it and/or
113+ * modify it under the terms of the GNU General Public License
114+ * as published by the Free Software Foundation; either version 2
115+ * of the License, or (at your option) any later version.
116+ *
117+ * This program is distributed in the hope that it will be useful,
118+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
119+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120+ * GNU General Public License for more details.
121+ *
122+ * You should have received a copy of the GNU General Public License
123+ * along with this program; if not, write to the Free Software
124+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
125+ *
126+ */
127+
128+#ifndef COMMON_KEY_MAPPER_H
129+#define COMMON_KEY_MAPPER_H
130+
131+#include "common/hashmap.h"
132+#include "backends/platform/common/gameactions.h"
133+
134+namespace Mapping {
135+
136+typedef Common::HashMap<Common::KeyState, Common::UserAction, Common::KeyState_Hash> KeyActionMap;
137+typedef Common::HashMap<Common::UserAction, Common::KeysList, Common::UserAction_Hash> ActionKeysMap;
138+
139+enum Errors {
140+ NOERRORS = 0,
141+ ACTIONS_WITH_SAME_KEY = 1,
142+ PRIORITY_ERROR = 2,
143+ MEMORY_ALLOCATION_ERROR = 3,
144+ BAD_KEY_MAPPER_VERSION = 4,
145+ SAVE_ERROR = 5
146+};
147+
148+/**
149+ * Default key mapper implementation, base class for custom extensions.
150+ */
151+class KeyMapper {
152+
153+public:
154+
155+ KeyMapper();
156+
157+ virtual Mapping::Errors setGame(Common::String domain);
158+
159+ virtual Mapping::Errors editMapping(const Common::KeyState, const Common::UserAction);
160+
161+ virtual Mapping::Errors saveKeyMaps();
162+
163+ virtual Mapping::ActionKeysMap getKeyMaps();
164+
165+ virtual Mapping::ActionKeysMap getDefaultKeyMaps();
166+
167+ virtual Mapping::Errors switchKeyMaps(uint active);
168+
169+ virtual bool enabled();
170+
171+ virtual bool enabled(bool f);
172+
173+ virtual uint getKeyMapsNumber() {return _keyMaps;}
174+
175+ virtual uint32 getCurrentKeyMap() {return _active;}
176+
177+ /**
178+ * Tries to find a corresponding mapping for event.kbd. If successful,
179+ * replaces the event.kbd with a defaultKey from mapped action. If the actionType of
180+ * mapped action type is not Common::ACTION_INVALID, also substitutes the event.actionType.
181+ */
182+ virtual bool resolve(Common::Event &event);
183+
184+private:
185+
186+ Mapping::KeyActionMap _mapKeyAction[Mapping::maxKeyMaps]; // action mappings
187+ Mapping::ActionKeysMap _mapActionKeys[Mapping::maxKeyMaps]; // default action mappings
188+ bool _loaded;
189+ bool _enabled;
190+ uint _active;
191+ uint _keyMaps;
192+ Common::String _domain;
193+ Mapping::gameID _game;
194+ Mapping::Errors loadKeyMaps(bool defaultKeyMaps = false);
195+
196+};
197+} //end namespace Mapping
198+
199+#endif
200\ No newline at end of file
201Index: backends/platform/common/gameactions.h
202===================================================================
203--- backends/platform/common/gameactions.h (revision 0)
204+++ backends/platform/common/gameactions.h (revision 0)
205@@ -0,0 +1,56 @@
206+/* ScummVM - Graphic Adventure Engine
207+ *
208+ * ScummVM is the legal property of its developers, whose names
209+ * are too numerous to list here. Please refer to the COPYRIGHT
210+ * file distributed with this source distribution.
211+ *
212+ * This program is free software; you can redistribute it and/or
213+ * modify it under the terms of the GNU General Public License
214+ * as published by the Free Software Foundation; either version 2
215+ * of the License, or (at your option) any later version.
216+ *
217+ * This program is distributed in the hope that it will be useful,
218+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
219+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
220+ * GNU General Public License for more details.
221+ *
222+ * You should have received a copy of the GNU General Public License
223+ * along with this program; if not, write to the Free Software
224+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
225+ *
226+ */
227+
228+#ifndef MAPPING_GAMEACTIONS_H
229+#define MAPPING_GAMEACTIONS_H
230+
231+#include "common/events.h"
232+
233+namespace Mapping {
234+
235+const unsigned int maxKeyMaps = 2;
236+
237+enum engineID {
238+ AGI = 0x0000,
239+ AGOS = 0x0100,
240+ SKY = 0x0200,
241+ UNKNOWN_ENGINE = 0xff00
242+};
243+
244+//first part of 0xffff is engine ID
245+//second part is game ID
246+enum gameID {
247+ game_agi = 0x0000,
248+ game2_agi = 0x0001,
249+ game_agos = 0x0100,
250+ GAME_SKY = 0x0200,
251+ UNKNOWN_GAME = 0xffff
252+};
253+
254+Mapping::gameID getGameIDFromDomain(Common::String domain);
255+Common::Array<Common::UserAction> mergeUserActions(Common::Array<Common::UserAction> base, Common::Array<Common::UserAction> add);
256+Common::Array<Common::Array<Common::UserAction>> getActions(Mapping::gameID game);
257+int findActionNumber(Common::Array<Common::UserAction> actions, Common::UserAction action);
258+
259+}
260+
261+#endif
262\ No newline at end of file
263Index: backends/platform/common/gameactions.cpp
264===================================================================
265--- backends/platform/common/gameactions.cpp (revision 0)
266+++ backends/platform/common/gameactions.cpp (revision 0)
267@@ -0,0 +1,83 @@
268+ /* ScummVM - Graphic Adventure Engine
269+ *
270+ * ScummVM is the legal property of its developers, whose names
271+ * are too numerous to list here. Please refer to the COPYRIGHT
272+ * file distributed with this source distribution.
273+ *
274+ * This program is free software; you can redistribute it and/or
275+ * modify it under the terms of the GNU General Public License
276+ * as published by the Free Software Foundation; either version 2
277+ * of the License, or (at your option) any later version.
278+ *
279+ * This program is distributed in the hope that it will be useful,
280+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
281+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
282+ * GNU General Public License for more details.
283+ *
284+ * You should have received a copy of the GNU General Public License
285+ * along with this program; if not, write to the Free Software
286+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
287+ *
288+ */
289+
290+#include "backends/platform/common/gameactions.h"
291+
292+Mapping::gameID Mapping::getGameIDFromDomain(Common::String domain){
293+ if (domain.equals("sky")) {
294+ return Mapping::GAME_SKY;
295+ }
296+ return Mapping::UNKNOWN_GAME;
297+}
298+int Mapping::findActionNumber(Common::Array<Common::UserAction> actions, Common::UserAction action){
299+ Common::Array<Common::UserAction>::const_iterator i;
300+ int c = 0;
301+ for(i = actions.begin();i != actions.end();i++,c++){
302+ if(i->actionType == action.actionType){
303+ return c;
304+ }
305+ }
306+ return -1;
307+}
308+
309+Common::Array<Common::UserAction> Mapping::mergeUserActions(Common::Array<Common::UserAction> base, Common::Array<Common::UserAction> add){
310+ Common::Array<Common::UserAction>::const_iterator i;
311+ for(i = add.begin(); i != add.end(); i++) {
312+ if (findActionNumber(base,*i) == -1) {
313+ base.push_back(*i);
314+ }
315+ }
316+ return base;
317+}
318+Common::Array<Common::Array<Common::UserAction>> Mapping::getActions(Mapping::gameID game){
319+ Common::Array<Common::UserAction> globalActions;
320+ globalActions.push_back(Common::UserAction(Common::KEYCODE_ESCAPE,Common::ACTION_QUIT,"Quit",Common::PRIORITY_CRITICAL));
321+
322+ Common::Array<Common::UserAction> engineActions;
323+ Mapping::engineID engine = (Mapping::engineID)(game & 0xff00);
324+ switch(engine) {
325+ case SKY:
326+ engineActions.push_back(Common::UserAction(Common::KEYCODE_p,Common::ACTION_SAVE,"Pause",Common::PRIORITY_OPTIONAL));
327+ break;
328+ }//end of switch(engine)
329+
330+ Common::Array<Common::UserAction> gameActions[maxKeyMaps];
331+ switch (game) {
332+ case GAME_SKY:
333+ gameActions[0].push_back(Common::UserAction(Common::KEYCODE_F5,Common::ACTION_INVALID,"Menu",Common::PRIORITY_PREFERED));
334+ break;
335+ } //end of switch(game)
336+
337+
338+ Common::Array<Common::Array<Common::UserAction>> actions;
339+ for (int i=0; !gameActions[i].empty(); i++){
340+ if (!engineActions.empty()) {
341+ gameActions[i] = mergeUserActions(gameActions[i],engineActions);
342+ }
343+ if (!globalActions.empty()) {
344+ gameActions[i] = mergeUserActions(gameActions[i],globalActions);
345+ }
346+ actions.push_back(gameActions[i]);
347+ }
348+
349+ return actions;
350+}
351\ No newline at end of file
352Index: backends/platform/common/module.mk
353===================================================================
354--- backends/platform/common/module.mk (revision 0)
355+++ backends/platform/common/module.mk (revision 0)
356@@ -0,0 +1,11 @@
357+MODULE := backends/platform/common
358+
359+MODULE_OBJS := \
360+ key-mapper.o \
361+ gameactions.o
362+
363+MODULE_DIRS += \
364+ backends/platform/common/
365+
366+# We don't use the rules.mk here on purpose
367+OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS)
368Index: backends/platform/common/key-mapper.cpp
369===================================================================
370--- backends/platform/common/key-mapper.cpp (revision 0)
371+++ backends/platform/common/key-mapper.cpp (revision 0)
372@@ -0,0 +1,272 @@
373+ /* ScummVM - Graphic Adventure Engine
374+ *
375+ * ScummVM is the legal property of its developers, whose names
376+ * are too numerous to list here. Please refer to the COPYRIGHT
377+ * file distributed with this source distribution.
378+ *
379+ * This program is free software; you can redistribute it and/or
380+ * modify it under the terms of the GNU General Public License
381+ * as published by the Free Software Foundation; either version 2
382+ * of the License, or (at your option) any later version.
383+ *
384+ * This program is distributed in the hope that it will be useful,
385+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
386+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
387+ * GNU General Public License for more details.
388+ *
389+ * You should have received a copy of the GNU General Public License
390+ * along with this program; if not, write to the Free Software
391+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
392+ *
393+ */
394+
395+#include "backends/platform/common/key-mapper.h"
396+#include "common/config-manager.h"
397+
398+#define version 1 // TODO add backend identification here
399+namespace Mapping {
400+KeyMapper::KeyMapper()
401+:_active(0), _loaded(false), _enabled(false), _game(Mapping::UNKNOWN_GAME),
402+ _keyMaps(0)
403+{
404+}
405+
406+Mapping::Errors KeyMapper::setGame(Common::String domain) {
407+ _domain = domain;
408+ _game = getGameIDFromDomain(_domain);
409+ _loaded = false;
410+ _enabled = false;
411+ return Mapping::NOERRORS;
412+}
413+
414+Mapping::Errors KeyMapper::editMapping(const Common::KeyState key, const Common::UserAction action) {
415+ if (!_loaded) {
416+ loadKeyMaps();
417+ _loaded = true;
418+ }
419+ if (_mapKeyAction[_active][key] == action) {
420+ return Mapping::NOERRORS;
421+ }
422+ Common::UserAction act = _mapKeyAction[_active][key];
423+ if (_mapKeyAction[_active][key] == Common::UserAction()) {
424+ _mapKeyAction[_active][key] = action;
425+ _mapKeyAction[_active].erase(*_mapActionKeys[_active][action].begin());
426+ _mapActionKeys[_active][action].clear();
427+ _mapActionKeys[_active][action].push_back(key);
428+ return Mapping::NOERRORS;
429+ }
430+ if (_mapKeyAction[_active].contains(key) && !(_mapKeyAction[_active][key] == action)) {
431+ if (action.priority <= _mapKeyAction[_active][key].priority){
432+ _mapKeyAction[_active].erase(*_mapActionKeys[_active][action].begin());
433+ _mapActionKeys[_active][_mapKeyAction[_active][key]].clear();
434+ Common::KeyState ks;
435+ ks.keycode = Common::KEYCODE_INVALID;
436+ _mapActionKeys[_active][_mapKeyAction[_active][key]].push_back(ks);
437+ _mapActionKeys[_active][action].clear();
438+ _mapActionKeys[_active][action].push_back(key);
439+ _mapKeyAction[_active][key] = action;
440+ }
441+ // TODO if higher priority action is not mapped -> show priority error popup
442+ else {
443+ return Mapping::PRIORITY_ERROR;
444+ }
445+ }
446+ /*
447+ _mapKeyAction[_active][key] = action;
448+ _mapActionKeys[_active][action].push_back(key);
449+ */
450+ return Mapping::NOERRORS;
451+}
452+
453+Mapping::Errors KeyMapper::saveKeyMaps() {
454+ if (!_loaded) {
455+ return Mapping::SAVE_ERROR;
456+ }
457+ ConfMan.setInt("action_mapping_version", version, ConfMan.kApplicationDomain);
458+ ConfMan.setInt("keyMaps", _keyMaps, _domain);
459+ for (uint32 i=0; i < _keyMaps; i++) {
460+ char *tempo = (char *) malloc(_mapKeyAction[i].size() * 15 + 1); // 15 is the size required to write one mapping
461+ if (tempo == NULL) {
462+ return Mapping::MEMORY_ALLOCATION_ERROR;
463+ }
464+ tempo[0] = '\0';
465+ int c=0;
466+ for (KeyActionMap::const_iterator mIt = _mapKeyAction[i].begin(); mIt != _mapKeyAction[i].end(); ++mIt) {
467+ char s[15];
468+ Common::UserAction ac = mIt->_value;
469+ Common::KeyState key = mIt->_key;
470+ if (mIt->_value == Common::UserAction()) {
471+ continue;
472+ }
473+ sprintf(s, "%.4x%.2x,%.4x%.2x;", mIt->_key.keycode, mIt->_key.flags, mIt->_value.defaultKey.keycode, mIt->_value.defaultKey.flags);
474+ strcat(tempo, s);
475+ c++;
476+ }
477+ char st[25];
478+ sprintf(st, "%s_%u", "keyMapSize", i);
479+ ConfMan.setInt(Common::String(st), c, _domain);
480+ sprintf(st, "%s_%u", "keyMap", i);
481+ ConfMan.set(Common::String(st), tempo, _domain);
482+ free(tempo);
483+ ConfMan.flushToDisk();
484+ }
485+ return Mapping::NOERRORS;
486+}
487+
488+Mapping::ActionKeysMap KeyMapper::getKeyMaps() {
489+ if (!_loaded) {
490+ loadKeyMaps();
491+ _loaded = true;
492+ }
493+ return _mapActionKeys[_active];
494+}
495+
496+Mapping::ActionKeysMap KeyMapper::getDefaultKeyMaps() {
497+ loadKeyMaps(true);
498+ _loaded = true;
499+ _active = 0;
500+ return _mapActionKeys[_active];
501+}
502+
503+Mapping::Errors KeyMapper::switchKeyMaps(uint32 active) {
504+ if (active < _keyMaps) {
505+ _active = active;
506+ }
507+ return Mapping::NOERRORS;
508+}
509+
510+bool KeyMapper::enabled() {
511+ return _enabled;
512+}
513+
514+bool KeyMapper::enabled(bool enabled) {
515+ return _enabled = enabled;
516+}
517+bool KeyMapper::resolve(Common::Event &event) {
518+ if(_enabled){
519+ if (!_loaded) {
520+ loadKeyMaps();
521+ _loaded = true;
522+ }
523+
524+ bool result = true;
525+ bool keyEvent = (event.type == Common::EVENT_KEYDOWN) || (event.type == Common::EVENT_KEYUP);
526+ if (keyEvent) {
527+ if (_mapKeyAction[_active].contains(event.kbd)) {
528+ event.kbd = _mapKeyAction[_active][event.kbd].defaultKey;
529+ Common::ActionType actionType = _mapKeyAction[_active][event.kbd].actionType;
530+ if (actionType != Common::ACTION_INVALID) {
531+ event.actionType = actionType;
532+ }
533+ } else {
534+ result = false;
535+ }
536+ }
537+ return result;
538+ }
539+ return true;
540+}
541+
542+Mapping::Errors KeyMapper::loadKeyMaps(bool defaultKeyMaps) {
543+ if (_loaded) {
544+ for(int i=0; i < maxKeyMaps; i++) {
545+ _mapKeyAction[i].clear();
546+ _mapActionKeys[i].clear();
547+ }
548+ _keyMaps = 0;
549+ }
550+
551+ Common::Array<Common::Array<Common::UserAction>> actions;
552+ actions = getActions(_game);
553+ Common::Array<Common::Array<Common::UserAction>>::iterator i;
554+ for (i = actions.begin(); i != actions.end(); i++) {
555+ Common::Array<Common::UserAction>::iterator j;
556+ for (j = i->begin(); j != i->end(); j++) {
557+ _mapKeyAction[_keyMaps][j->defaultKey] = *j;
558+ _mapActionKeys[_keyMaps][*j].push_back(j->defaultKey);
559+ }
560+ if (!i->empty()) {
561+ _keyMaps++;
562+ }
563+ }
564+
565+
566+ int current_version = ConfMan.getInt("action_mapping_version", ConfMan.kApplicationDomain);
567+ if (!defaultKeyMaps && current_version != 0){
568+
569+ if (current_version != version) {
570+ return BAD_KEY_MAPPER_VERSION;
571+ }
572+
573+ _keyMaps = ConfMan.getInt("keyMaps", _domain);
574+ if (_keyMaps != 0 && _keyMaps <= maxKeyMaps) {
575+ int size = 0;
576+ for (uint32 kMap = 0; kMap < _keyMaps; kMap++){
577+ // clear current mappings
578+ _mapKeyAction[kMap].clear();
579+ Common::List<Common::UserAction> list;
580+ for (ActionKeysMap::const_iterator mIt = _mapActionKeys[kMap].begin(); mIt != _mapActionKeys[kMap].end(); ++mIt) {
581+ list.push_back(mIt->_key);
582+ }
583+ for (Common::List<Common::UserAction>::iterator it = list.begin(); it != list.end(); ++it) {
584+ _mapActionKeys[kMap][*it].clear();
585+ }
586+ char st[25];
587+ sprintf(st, "%s_%u", "keyMapSize", kMap);
588+ size = ConfMan.getInt(Common::String(st), _domain);
589+ sprintf(st, "%s_%u", "keyMap", kMap);
590+ const char *tempo = ConfMan.get(st, _domain).c_str();
591+ if (tempo && strlen(tempo)) {
592+ for (int i = 0; i < size; i++) {
593+ char x[4];
594+ int offset = 14 * i;
595+ uint32 buf;
596+ Common::KeyState key;
597+ Common::KeyState defaultKey;
598+
599+ memset(x, 0, sizeof(uint32));
600+ memcpy(x, tempo + offset, 4);
601+ sscanf(x, "%x", &buf);
602+ key.keycode = (Common::KeyCode) buf;
603+
604+ memset(x, 0, sizeof(uint32));
605+ memcpy(x, tempo + offset + 4, 2);
606+ sscanf(x, "%x", &buf);
607+ key.flags = (byte) buf;
608+
609+ // TODO write comment
610+ if (_mapKeyAction[kMap].contains(key)) {
611+ continue;
612+ }
613+
614+ memset(x, 0, sizeof(uint32));
615+ memcpy(x, tempo + offset + 7, 4);
616+ sscanf(x, "%x", &buf);
617+ defaultKey.keycode = (Common::KeyCode) buf;
618+
619+ memset(x, 0, sizeof(uint32));
620+ memcpy(x, tempo + offset + 11, 2);
621+ sscanf(x, "%x", &buf);
622+ defaultKey.flags = (byte) buf;
623+
624+ // TODO can actions have the same default keys? here it is assumed that they can not
625+ Common::UserAction action;
626+ for (ActionKeysMap::const_iterator mIt = _mapActionKeys[kMap].begin(); mIt != _mapActionKeys[kMap].end(); ++mIt) {
627+ if (mIt->_key.defaultKey == defaultKey) {
628+ action = mIt->_key;
629+ break;
630+ }
631+ }
632+ _mapKeyAction[kMap][key] = action;
633+ _mapActionKeys[kMap][action].push_back(key);
634+ }
635+ }
636+ }
637+
638+ }
639+ }
640+
641+ return Mapping::NOERRORS;
642+}
643+
644+} //end namespace Mapping
645\ No newline at end of file
646Index: base/main.cpp
647===================================================================
648--- base/main.cpp (revision 28773)
649+++ base/main.cpp (working copy)
650@@ -314,8 +314,14 @@
651 // to save memory
652 PluginManager::instance().unloadPluginsExcept(plugin);
653
654+ g_system->getKeyMapper()->setGame(ConfMan.getActiveDomainName());
655+ g_system->getKeyMapper()->enabled(true);
656+
657 // Try to run the game
658 int result = runGame(plugin, system, specialDebug);
659+
660+ g_system->getKeyMapper()->enabled(false);
661+
662 // TODO: We should keep running if starting the selected game failed
663 // (so instead of just quitting, show a nice error dialog to the
664 // user and let him pick another game).
665Index: common/event-manager.h
666===================================================================
667--- common/event-manager.h (revision 0)
668+++ common/event-manager.h (revision 0)
669@@ -0,0 +1,86 @@
670+/* ScummVM - Graphic Adventure Engine
671+ *
672+ * ScummVM is the legal property of its developers, whose names
673+ * are too numerous to list here. Please refer to the COPYRIGHT
674+ * file distributed with this source distribution.
675+ *
676+ * This program is free software; you can redistribute it and/or
677+ * modify it under the terms of the GNU General Public License
678+ * as published by the Free Software Foundation; either version 2
679+ * of the License, or (at your option) any later version.
680+
681+ * This program is distributed in the hope that it will be useful,
682+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
683+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
684+ * GNU General Public License for more details.
685+
686+ * You should have received a copy of the GNU General Public License
687+ * along with this program; if not, write to the Free Software
688+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
689+ *
690+ */
691+
692+#ifndef COMMON_EVENT_MANAGER_H
693+#define COMMON_EVENT_MANAGER_H
694+
695+#include "common/events.h"
696+#include "backends/platform/common/key-mapper.h"
697+
698+namespace Common {
699+
700+/**
701+ * The EventManager provides user input events to the client code.
702+ * In addition, it keeps track of the state of various input devices,
703+ * like keys, mouse position and buttons.
704+ */
705+class EventManager : NonCopyable {
706+public:
707+ EventManager() {}
708+ virtual ~EventManager() {}
709+
710+ enum {
711+ LBUTTON = 1 << 0,
712+ RBUTTON = 1 << 1
713+ };
714+
715+ /**
716+ * Get the next event in the event queue.
717+ * @param event point to an Event struct, which will be filled with the event data.
718+ * @return true if an event was retrieved.
719+ */
720+ virtual bool pollEvent(Common::Event &event) = 0;
721+
722+
723+ /** Return the current key state */
724+ virtual Common::Point getMousePos() const = 0;
725+
726+ /**
727+ * Return a bitmask with the button states:
728+ * - bit 0: left button up=1, down=0
729+ * - bit 1: right button up=1, down=0
730+ */
731+ virtual int getButtonState() const = 0;
732+
733+ /** Get a bitmask with the current modifier state */
734+ virtual int getModifierState() const = 0;
735+
736+ /**
737+ * Should the application terminate? Set to true if we
738+ * received an EVENT_QUIT.
739+ */
740+ virtual int shouldQuit() const = 0;
741+
742+ // Optional: check whether a given key is currently pressed ????
743+ //virtual bool isKeyPressed(int keycode) = 0;
744+
745+ // TODO: Keyboard repeat support?
746+
747+ // TODO: Consider removing OSystem::getScreenChangeID and
748+ // replacing it by a generic getScreenChaneID method here
749+
750+ virtual Mapping::KeyMapper *getKeyMapper() = 0;
751+};
752+
753+} // End of namespace Common
754+
755+#endif
756\ No newline at end of file
757Index: common/keyboard.h
758===================================================================
759--- common/keyboard.h (revision 28773)
760+++ common/keyboard.h (working copy)
761@@ -27,6 +27,7 @@
762 #define COMMON_KEYBOARD_H
763
764 #include "common/scummsys.h"
765+#include "common/list.h"
766
767 namespace Common {
768
769@@ -259,8 +260,35 @@
770 keycode = KEYCODE_INVALID;
771 ascii = flags = 0;
772 }
773+
774+ bool operator <(const KeyState keyState) const {
775+ bool result;
776+ if (keycode != keyState.keycode) {
777+ result = keycode < keyState.keycode;
778+ } else {
779+ result = flags < keyState.flags;
780+ }
781+
782+ return result;
783+ }
784+
785+ bool operator ==(const KeyState keyState) const {
786+ return (keycode == keyState.keycode) && (flags == keyState.flags);
787+ }
788+
789+ uint hash() const {
790+ uint hash = 7;
791+ hash = hash * 31 + keycode;
792+ hash = hash * 31 + flags;
793+ return hash;
794+ }
795 };
796
797+typedef Common::List<Common::KeyState> KeysList;
798+
799+struct KeyState_Hash {
800+ uint operator()(const KeyState& ks) const { return ks.hash(); }
801+};
802 } // End of namespace Common
803
804 #endif
805Index: common/scummsys.h
806===================================================================
807--- common/scummsys.h (revision 28773)
808+++ common/scummsys.h (working copy)
809@@ -26,6 +26,8 @@
810 #ifndef COMMON_SCUMMSYS_H
811 #define COMMON_SCUMMSYS_H
812
813+#include "common/stdafx.h"
814+
815 #if !defined(COMMON_STDAFX_H) && !defined(__PLAYSTATION2__)
816 #error Included scummsys.h without including stdafx.h first!
817 #endif
818Index: common/system.h
819===================================================================
820--- common/system.h (revision 28773)
821+++ common/system.h (working copy)
822@@ -30,6 +30,9 @@
823 #include "common/mutex.h"
824 #include "common/noncopyable.h"
825 #include "common/rect.h"
826+#include "common/event-manager.h"
827+#include "common/keyboard.h"
828+#include "backends/platform/common/key-mapper.h"
829
830 namespace Audio {
831 class Mixer;
832@@ -733,6 +736,8 @@
833 */
834 virtual Common::EventManager *getEventManager();
835
836+ virtual Mapping::KeyMapper *getKeyMapper() { return NULL; }
837+
838 //@}
839
840
841@@ -885,6 +890,9 @@
842 */
843 virtual Common::SaveFileManager *getSavefileManager() = 0;
844
845+ virtual Common::String keyNameResolve(Common::KeyCode key){
846+ return "";
847+ }
848 //@}
849 };
850
851Index: common/events.h
852===================================================================
853--- common/events.h (revision 28773)
854+++ common/events.h (working copy)
855@@ -28,11 +28,23 @@
856
857 #include "common/keyboard.h"
858 #include "common/rect.h"
859-#include "common/system.h"
860+//#include "common/system.h"
861 #include "common/noncopyable.h"
862
863+#include "common/list.h"
864+
865 namespace Common {
866
867+
868+enum ActionType {
869+
870+ ACTION_INVALID = 0,
871+ ACTION_QUIT = 1,
872+ ACTION_SAVE = 2,
873+ ACTION_LOAD = 3
874+
875+};
876+
877 /**
878 * The types of events backends may generate.
879 * @see Event
880@@ -115,60 +127,86 @@
881 * screen area as defined by the most recent call to initSize().
882 */
883 Common::Point mouse;
884+ /**
885+ * Event type like quit, save/load, etc.
886+ */
887+ Common::ActionType actionType;
888 };
889
890
891-/**
892- * The EventManager provides user input events to the client code.
893- * In addition, it keeps track of the state of various input devices,
894- * like keys, mouse position and buttons.
895- */
896-class EventManager : NonCopyable {
897-public:
898- EventManager() {}
899- virtual ~EventManager() {}
900-
901- enum {
902- LBUTTON = 1 << 0,
903- RBUTTON = 1 << 1
904- };
905+enum Priority {
906+ PRIORITY_CRITICAL = 1,
907+ PRIORITY_PREFERED = 2,
908+ PRIORITY_OPTIONAL = 3
909+};
910
911+
912+struct UserAction {
913+
914 /**
915- * Get the next event in the event queue.
916- * @param event point to an Event struct, which will be filled with the event data.
917- * @return true if an event was retrieved.
918+ * Default key used in the egines an games for this action.
919 */
920- virtual bool pollEvent(Common::Event &event) = 0;
921+ Common::KeyState defaultKey;
922
923+ /**
924+ * Event type like quit, save/load, etc.
925+ */
926+ Common::ActionType actionType;
927
928- /** Return the current key state */
929- virtual Common::Point getMousePos() const = 0;
930-
931 /**
932- * Return a bitmask with the button states:
933- * - bit 0: left button up=1, down=0
934- * - bit 1: right button up=1, down=0
935+ * Human readable description for a GUI keymapping config dialog
936 */
937- virtual int getButtonState() const = 0;
938-
939- /** Get a bitmask with the current modifier state */
940- virtual int getModifierState() const = 0;
941+ String description;
942
943 /**
944- * Should the application terminate? Set to true if we
945- * received an EVENT_QUIT.
946+ * Mapping priority. Actions with higher priority will be given preference for mapping
947+ * in case of limited inputs.
948 */
949- virtual int shouldQuit() const = 0;
950-
951- // Optional: check whether a given key is currently pressed ????
952- //virtual bool isKeyPressed(int keycode) = 0;
953+ Common::Priority priority;
954
955- // TODO: Keyboard repeat support?
956-
957- // TODO: Consider removing OSystem::getScreenChangeID and
958- // replacing it by a generic getScreenChangeID method here
959+ UserAction(Common::KeyState ks = Common::KeyState(Common::KEYCODE_ESCAPE),
960+ Common::ActionType at = Common::ACTION_INVALID,
961+ String d = "Action name", Common::Priority p = Common::PRIORITY_OPTIONAL) {
962+
963+ defaultKey = ks;
964+ actionType = at;
965+ description = d;
966+ priority = p;
967+ }
968+
969+ UserAction(Common::KeyState ks, String d, Common::Priority p = Common::PRIORITY_OPTIONAL) {
970+ defaultKey = ks;
971+ actionType = Common::ACTION_INVALID;
972+ description = d;
973+ priority = p;
974+ }
975+
976+ bool operator ==(const UserAction action) const {
977+ return (defaultKey == action.defaultKey) && (actionType == action.actionType) && (description == action.description);
978+ }
979+
980+ bool operator <(const UserAction action) const {
981+ return priority < action.priority;
982+ }
983+
984+ uint hash() const {
985+ uint hash = 7;
986+ hash = hash * 31 + defaultKey.hash();
987+ hash = hash * 31 + actionType;
988+ hash = hash * 31 + description.hash();
989+ hash = hash * 31 + priority;
990+ return hash;
991+ }
992+
993 };
994
995+struct UserAction_Hash {
996+ uint operator()(const UserAction& ua) const { return ua.hash(); }
997+};
998+
999+typedef Common::List<Common::UserAction> ActionList;
1000+
1001+
1002 } // End of namespace Common
1003
1004 #endif
1005 Index: engines/sword1/sword1.cpp
1006===================================================================
1007--- engines/sword1/sword1.cpp (revision 28773)
1008+++ engines/sword1/sword1.cpp (working copy)
1009@@ -31,7 +31,7 @@
1010 #include "common/file.h"
1011 #include "common/fs.h"
1012 #include "common/timer.h"
1013-#include "common/events.h"
1014+#include "common/event-manager.h"
1015 #include "common/system.h"
1016
1017 #include "sword1/resman.h"
1018Index: engines/sword1/credits.cpp
1019===================================================================
1020--- engines/sword1/credits.cpp (revision 28773)
1021+++ engines/sword1/credits.cpp (working copy)
1022@@ -35,7 +35,7 @@
1023
1024 #include "common/file.h"
1025 #include "common/util.h"
1026-#include "common/events.h"
1027+#include "common/event-manager.h"
1028 #include "common/system.h"
1029
1030
1031Index: engines/sword1/animation.cpp
1032===================================================================
1033--- engines/sword1/animation.cpp (revision 28773)
1034+++ engines/sword1/animation.cpp (working copy)
1035@@ -34,7 +34,7 @@
1036 #include "common/config-manager.h"
1037 #include "common/endian.h"
1038 #include "common/str.h"
1039-#include "common/events.h"
1040+#include "common/event-manager.h"
1041 #include "common/system.h"
1042
1043 namespace Sword1 {
1044Index: engines/sword1/control.cpp
1045===================================================================
1046--- engines/sword1/control.cpp (revision 28773)
1047+++ engines/sword1/control.cpp (working copy)
1048@@ -27,7 +27,7 @@
1049 #include "common/file.h"
1050 #include "common/util.h"
1051 #include "common/savefile.h"
1052-#include "common/events.h"
1053+#include "common/event-manager.h"
1054 #include "common/system.h"
1055
1056 #include "gui/message.h"
1057Index: engines/sword2/animation.cpp
1058===================================================================
1059--- engines/sword2/animation.cpp (revision 28773)
1060+++ engines/sword2/animation.cpp (working copy)
1061@@ -28,7 +28,7 @@
1062 #include "common/stdafx.h"
1063 #include "common/config-manager.h"
1064 #include "common/file.h"
1065-#include "common/events.h"
1066+#include "common/event-manager.h"
1067 #include "common/system.h"
1068
1069 #include "sword2/sword2.h"
1070Index: engines/scumm/input.cpp
1071===================================================================
1072--- engines/scumm/input.cpp (revision 28773)
1073+++ engines/scumm/input.cpp (working copy)
1074@@ -26,7 +26,7 @@
1075 #include "common/stdafx.h"
1076
1077 #include "common/config-manager.h"
1078-#include "common/events.h"
1079+#include "common/event-manager.h"
1080 #include "common/system.h"
1081
1082 #include "gui/message.h"
1083Index: engines/scumm/scumm.cpp
1084===================================================================
1085--- engines/scumm/scumm.cpp (revision 28773)
1086+++ engines/scumm/scumm.cpp (working copy)
1087@@ -27,7 +27,7 @@
1088
1089 #include "common/config-manager.h"
1090 #include "common/md5.h"
1091-#include "common/events.h"
1092+#include "common/event-manager.h"
1093 #include "common/system.h"
1094
1095 #include "gui/message.h"
1096Index: engines/touche/touche.cpp
1097===================================================================
1098--- engines/touche/touche.cpp (revision 28773)
1099+++ engines/touche/touche.cpp (working copy)
1100@@ -25,7 +25,7 @@
1101
1102 #include "common/stdafx.h"
1103 #include "common/config-manager.h"
1104-#include "common/events.h"
1105+#include "common/event-manager.h"
1106 #include "common/system.h"
1107
1108 #include "graphics/cursorman.h"
1109Index: engines/touche/ui.cpp
1110===================================================================
1111--- engines/touche/ui.cpp (revision 28773)
1112+++ engines/touche/ui.cpp (working copy)
1113@@ -24,7 +24,7 @@
1114 */
1115
1116 #include "common/stdafx.h"
1117-#include "common/events.h"
1118+#include "common/event-manager.h"
1119 #include "common/system.h"
1120 #include "common/savefile.h"
1121
1122Index: engines/agos/cursor.cpp
1123===================================================================
1124--- engines/agos/cursor.cpp (revision 28773)
1125+++ engines/agos/cursor.cpp (working copy)
1126@@ -25,7 +25,7 @@
1127
1128 #include "common/stdafx.h"
1129
1130-#include "common/events.h"
1131+#include "common/event-manager.h"
1132 #include "common/system.h"
1133
1134 #include "graphics/cursorman.h"
1135Index: engines/agos/event.cpp
1136===================================================================
1137--- engines/agos/event.cpp (revision 28773)
1138+++ engines/agos/event.cpp (working copy)
1139@@ -29,7 +29,7 @@
1140 #include "agos/debugger.h"
1141 #include "agos/intern.h"
1142
1143-#include "common/events.h"
1144+#include "common/event-manager.h"
1145 #include "common/system.h"
1146
1147 #include "gui/about.h"
1148Index: engines/agos/animation.cpp
1149===================================================================
1150--- engines/agos/animation.cpp (revision 28773)
1151+++ engines/agos/animation.cpp (working copy)
1152@@ -26,7 +26,7 @@
1153 #include "common/stdafx.h"
1154
1155 #include "common/endian.h"
1156-#include "common/events.h"
1157+#include "common/event-manager.h"
1158 #include "common/system.h"
1159
1160 #include "graphics/cursorman.h"
1161Index: engines/cruise/cruise_main.cpp
1162===================================================================
1163--- engines/cruise/cruise_main.cpp (revision 28773)
1164+++ engines/cruise/cruise_main.cpp (working copy)
1165@@ -25,7 +25,8 @@
1166
1167 #include "common/stdafx.h"
1168 #include "common/endian.h"
1169-#include "common/events.h"
1170+#include "common/event-manager.h"
1171+#include "common/system.h"
1172
1173 #include "cruise/cruise_main.h"
1174 #include "cruise/cell.h"
1175Index: engines/drascula/drascula.cpp
1176===================================================================
1177--- engines/drascula/drascula.cpp (revision 28773)
1178+++ engines/drascula/drascula.cpp (working copy)
1179@@ -25,7 +25,7 @@
1180
1181 #include "common/stdafx.h"
1182
1183-#include "common/events.h"
1184+#include "common/event-manager.h"
1185 #include "common/keyboard.h"
1186 #include "common/file.h"
1187 #include "common/savefile.h"
1188Index: engines/agi/agi.cpp
1189===================================================================
1190--- engines/agi/agi.cpp (revision 28773)
1191+++ engines/agi/agi.cpp (working copy)
1192@@ -25,7 +25,7 @@
1193
1194 #include "common/stdafx.h"
1195
1196-#include "common/events.h"
1197+#include "common/event-manager.h"
1198 #include "common/file.h"
1199 #include "common/savefile.h"
1200 #include "common/config-manager.h"
1201Index: engines/kyra/kyra.cpp
1202===================================================================
1203--- engines/kyra/kyra.cpp (revision 28773)
1204+++ engines/kyra/kyra.cpp (working copy)
1205@@ -26,6 +26,7 @@
1206 #include "common/stdafx.h"
1207
1208 #include "common/config-manager.h"
1209+#include "common/event-manager.h"
1210
1211 #include "sound/mididrv.h"
1212 #include "sound/mixer.h"
1213Index: engines/kyra/vqa.cpp
1214===================================================================
1215--- engines/kyra/vqa.cpp (revision 28773)
1216+++ engines/kyra/vqa.cpp (working copy)
1217@@ -32,7 +32,7 @@
1218 // The jung2.vqa movie does work, but only thanks to a grotesque hack.
1219
1220 #include "common/stdafx.h"
1221-#include "common/events.h"
1222+#include "common/event-manager.h"
1223 #include "common/system.h"
1224 #include "sound/audiostream.h"
1225 #include "sound/mixer.h"
1226Index: engines/kyra/text_v1.cpp
1227===================================================================
1228--- engines/kyra/text_v1.cpp (revision 28773)
1229+++ engines/kyra/text_v1.cpp (working copy)
1230@@ -29,6 +29,7 @@
1231 #include "kyra/animator_v1.h"
1232 #include "kyra/sprites.h"
1233 #include "kyra/timer.h"
1234+#include "common/event-manager.h"
1235
1236 namespace Kyra {
1237
1238Index: engines/kyra/sequences_v1.cpp
1239===================================================================
1240--- engines/kyra/sequences_v1.cpp (revision 28773)
1241+++ engines/kyra/sequences_v1.cpp (working copy)
1242@@ -34,7 +34,7 @@
1243 #include "kyra/text.h"
1244 #include "kyra/timer.h"
1245
1246-#include "common/events.h"
1247+#include "common/event-manager.h"
1248 #include "common/system.h"
1249 #include "common/savefile.h"
1250
1251Index: engines/kyra/kyra.h
1252===================================================================
1253--- engines/kyra/kyra.h (revision 28773)
1254+++ engines/kyra/kyra.h (working copy)
1255@@ -30,6 +30,7 @@
1256 #include "common/rect.h"
1257 #include "common/array.h"
1258 #include "common/events.h"
1259+#include "common/system.h"
1260
1261 #include "kyra/util.h"
1262
1263Index: engines/kyra/kyra_v1.cpp
1264===================================================================
1265--- engines/kyra/kyra_v1.cpp (revision 28773)
1266+++ engines/kyra/kyra_v1.cpp (working copy)
1267@@ -26,7 +26,7 @@
1268 #include "kyra/kyra_v1.h"
1269
1270 #include "common/file.h"
1271-#include "common/events.h"
1272+#include "common/event-manager.h"
1273 #include "common/system.h"
1274 #include "common/savefile.h"
1275
1276Index: engines/kyra/kyra_v2.cpp
1277===================================================================
1278--- engines/kyra/kyra_v2.cpp (revision 28773)
1279+++ engines/kyra/kyra_v2.cpp (working copy)
1280@@ -34,6 +34,7 @@
1281 #include "kyra/timer.h"
1282
1283 #include "common/system.h"
1284+#include "common/event-manager.h"
1285
1286 namespace Kyra {
1287
1288Index: engines/kyra/gui_v1.cpp
1289===================================================================
1290--- engines/kyra/gui_v1.cpp (revision 28773)
1291+++ engines/kyra/gui_v1.cpp (working copy)
1292@@ -32,7 +32,7 @@
1293
1294 #include "common/config-manager.h"
1295 #include "common/savefile.h"
1296-#include "common/events.h"
1297+#include "common/event-manager.h"
1298 #include "common/system.h"
1299
1300 namespace Kyra {
1301Index: engines/kyra/gui_v2.cpp
1302===================================================================
1303--- engines/kyra/gui_v2.cpp (revision 28773)
1304+++ engines/kyra/gui_v2.cpp (working copy)
1305@@ -26,6 +26,7 @@
1306 #include "kyra/kyra.h"
1307 #include "kyra/kyra_v2.h"
1308 #include "kyra/screen.h"
1309+#include "common/event-manager.h"
1310
1311 namespace Kyra {
1312
1313Index: engines/sky/mouse.cpp
1314===================================================================
1315--- engines/sky/mouse.cpp (revision 28773)
1316+++ engines/sky/mouse.cpp (working copy)
1317@@ -24,7 +24,7 @@
1318 */
1319
1320 #include "common/stdafx.h"
1321-#include "common/events.h"
1322+#include "common/event-manager.h"
1323 #include "common/system.h"
1324 #include "graphics/cursorman.h"
1325 #include "sky/disk.h"
1326Index: engines/sky/intro.cpp
1327===================================================================
1328--- engines/sky/intro.cpp (revision 28773)
1329+++ engines/sky/intro.cpp (working copy)
1330@@ -26,7 +26,7 @@
1331 #include "common/stdafx.h"
1332 #include "common/endian.h"
1333 #include "common/util.h"
1334-#include "common/events.h"
1335+#include "common/event-manager.h"
1336 #include "common/system.h"
1337
1338 #include "sky/disk.h"
1339Index: engines/sky/sky.cpp
1340===================================================================
1341--- engines/sky/sky.cpp (revision 28773)
1342+++ engines/sky/sky.cpp (working copy)
1343@@ -30,7 +30,7 @@
1344 #include "common/config-manager.h"
1345 #include "common/file.h"
1346 #include "common/fs.h"
1347-#include "common/events.h"
1348+#include "common/event-manager.h"
1349 #include "common/system.h"
1350 #include "common/timer.h"
1351
1352Index: engines/sky/screen.cpp
1353===================================================================
1354--- engines/sky/screen.cpp (revision 28773)
1355+++ engines/sky/screen.cpp (working copy)
1356@@ -25,7 +25,7 @@
1357
1358 #include "common/stdafx.h"
1359 #include "common/endian.h"
1360-#include "common/events.h"
1361+#include "common/event-manager.h"
1362 #include "common/system.h"
1363
1364 #include "sky/disk.h"
1365Index: engines/sky/control.cpp
1366===================================================================
1367--- engines/sky/control.cpp (revision 28773)
1368+++ engines/sky/control.cpp (working copy)
1369@@ -27,7 +27,7 @@
1370 #include "common/endian.h"
1371 #include "common/config-manager.h"
1372 #include "common/file.h"
1373-#include "common/events.h"
1374+#include "common/event-manager.h"
1375 #include "common/system.h"
1376 #include "common/savefile.h"
1377 #include "common/util.h"
1378Index: engines/gob/util.cpp
1379===================================================================
1380--- engines/gob/util.cpp (revision 28773)
1381+++ engines/gob/util.cpp (working copy)
1382@@ -24,7 +24,7 @@
1383 */
1384
1385 #include "common/stdafx.h"
1386-#include "common/events.h"
1387+#include "common/event-manager.h"
1388
1389 #include "gob/gob.h"
1390 #include "gob/util.h"
1391Index: engines/lure/events.cpp
1392===================================================================
1393--- engines/lure/events.cpp (revision 28773)
1394+++ engines/lure/events.cpp (working copy)
1395@@ -24,7 +24,7 @@
1396 */
1397
1398 #include "common/stdafx.h"
1399-#include "common/events.h"
1400+#include "common/event-manager.h"
1401
1402 #include "graphics/cursorman.h"
1403
1404Index: engines/saga/input.cpp
1405===================================================================
1406--- engines/saga/input.cpp (revision 28773)
1407+++ engines/saga/input.cpp (working copy)
1408@@ -33,7 +33,7 @@
1409 #include "saga/script.h"
1410 #include "saga/isomap.h"
1411
1412-#include "common/events.h"
1413+#include "common/event-manager.h"
1414 #include "common/system.h"
1415
1416 namespace Saga {
1417Index: engines/saga/ihnm_introproc.cpp
1418===================================================================
1419--- engines/saga/ihnm_introproc.cpp (revision 28773)
1420+++ engines/saga/ihnm_introproc.cpp (working copy)
1421@@ -38,7 +38,8 @@
1422
1423 #include "saga/scene.h"
1424
1425-#include "common/events.h"
1426+#include "common/event-manager.h"
1427+#include "common/system.h"
1428
1429 namespace Saga {
1430
1431Index: engines/queen/input.h
1432===================================================================
1433--- engines/queen/input.h (revision 28773)
1434+++ engines/queen/input.h (working copy)
1435@@ -28,7 +28,7 @@
1436
1437 #include "common/util.h"
1438 #include "common/rect.h"
1439-#include "common/events.h"
1440+#include "common/event-manager.h"
1441 #include "queen/defs.h"
1442
1443 class OSystem;
1444Index: engines/queen/journal.cpp
1445===================================================================
1446--- engines/queen/journal.cpp (revision 28773)
1447+++ engines/queen/journal.cpp (working copy)
1448@@ -24,7 +24,7 @@
1449 */
1450
1451 #include "common/stdafx.h"
1452-#include "common/events.h"
1453+#include "common/event-manager.h"
1454 #include "common/system.h"
1455 #include "queen/journal.h"
1456
1457Index: engines/cine/main_loop.cpp
1458===================================================================
1459--- engines/cine/main_loop.cpp (revision 28773)
1460+++ engines/cine/main_loop.cpp (working copy)
1461@@ -25,7 +25,7 @@
1462
1463 #include "common/stdafx.h"
1464 #include "common/scummsys.h"
1465-#include "common/events.h"
1466+#include "common/event-manager.h"
1467 #include "common/system.h"
1468
1469 #include "cine/main_loop.h"
1470 Index: gui/launcher.h
1471===================================================================
1472--- gui/launcher.h (revision 28773)
1473+++ gui/launcher.h (working copy)
1474@@ -76,6 +76,17 @@
1475 void selectGame(const String &name);
1476 };
1477
1478+class KeyInputDialog : public Dialog {
1479+public:
1480+ KeyInputDialog(Common::UserAction action);
1481+ virtual void handleKeyUp(Common::KeyState state);
1482+ virtual void handleKeyDown(Common::KeyState state) {}
1483+private:
1484+ GUI::StaticTextWidget *_input;
1485+ Common::KeyState _key;
1486+ Common::UserAction _action;
1487+};
1488+
1489 } // End of namespace GUI
1490
1491 #endif
1492Index: gui/launcher.cpp
1493===================================================================
1494--- gui/launcher.cpp (revision 28773)
1495+++ gui/launcher.cpp (working copy)
1496@@ -34,6 +34,7 @@
1497 #include "common/fs.h"
1498 #include "common/util.h"
1499 #include "common/system.h"
1500+#include "common/keyboard.h"
1501
1502 #include "gui/about.h"
1503 #include "gui/browser.h"
1504@@ -76,7 +77,11 @@
1505
1506 kCmdExtraBrowser = 'PEXT',
1507 kCmdGameBrowser = 'PGME',
1508- kCmdSaveBrowser = 'PSAV'
1509+ kCmdSaveBrowser = 'PSAV',
1510+
1511+ kCmdUseDefaultKeys = 'DFTK',
1512+ kCmdEditKey = 'EDTK',
1513+ kCmdClearKey = 'CLRK',
1514 };
1515
1516 /*
1517@@ -143,6 +148,8 @@
1518 CheckboxWidget *_globalAudioOverride;
1519 CheckboxWidget *_globalMIDIOverride;
1520 CheckboxWidget *_globalVolumeOverride;
1521+
1522+ ListWidget *_actionsList;
1523 };
1524
1525 EditGameDialog::EditGameDialog(const String &domain, const String &desc)
1526@@ -197,6 +204,31 @@
1527 }
1528
1529 //
1530+ // 2) The keys tab
1531+ //
1532+ tab->addTab("Keys");
1533+ ButtonWidget *defaultKeys = new ButtonWidget(tab, "gameoptions_defaultkeys", "Use default", kCmdUseDefaultKeys, 0);
1534+ ButtonWidget *editKey = new ButtonWidget(tab, "gameoptions_editkey", "Edit key", kCmdEditKey, 0);
1535+ ButtonWidget *clearKey = new ButtonWidget(tab, "gameoptions_clearkey", "Clear key", kCmdClearKey, 0);
1536+
1537+ _actionsList = new ListWidget(tab, "gameoptions_actionslist");
1538+ Mapping::KeyMapper *kMapper = g_system->getKeyMapper();
1539+ kMapper->setGame(domain);
1540+ Mapping::ActionKeysMap keyMap = kMapper->getKeyMaps();
1541+ Mapping::ActionKeysMap::const_iterator it;
1542+ Common::StringList *s = new Common::StringList();
1543+ char st[50];
1544+ for (it = keyMap.begin(); it != keyMap.end(); ++it){
1545+ Common::UserAction action = it->_key;
1546+ Common::KeysList keys = it->_value;
1547+ sprintf(st, "%s\t\t\t\t\t\t%s", action.description.c_str(), g_system->keyNameResolve(keys.begin()->keycode).c_str());
1548+ s->push_back(st);
1549+ }
1550+ _actionsList->setList(*s);
1551+ _actionsList->draw();
1552+
1553+
1554+ //
1555 // 3) The graphics tab
1556 //
1557 tab->addTab("Graphics");
1558@@ -448,7 +480,48 @@
1559 draw();
1560 break;
1561 }
1562-
1563+ case kCmdUseDefaultKeys:{
1564+ Mapping::ActionKeysMap keyMap = g_system->getKeyMapper()->getDefaultKeyMaps();
1565+ Mapping::ActionKeysMap::const_iterator it;
1566+ Common::StringList *s = new Common::StringList();
1567+ char st[50];
1568+ for (it = keyMap.begin(); it != keyMap.end(); ++it){
1569+ Common::UserAction action = it->_key;
1570+ Common::KeysList keys = it->_value;
1571+ sprintf(st, "%s\t\t\t\t\t\t%s", action.description.c_str(), g_system->keyNameResolve(keys.begin()->keycode).c_str());
1572+ s->push_back(st);
1573+ }
1574+ _actionsList->setList(*s);
1575+ _actionsList->draw();
1576+ }
1577+ break;
1578+ case kCmdEditKey:
1579+ break;
1580+ case kCmdClearKey:
1581+ break;
1582+ case kListItemDoubleClickedCmd:{
1583+ Mapping::ActionKeysMap _actionKeysMap = g_system->getKeyMapper()->getKeyMaps();
1584+ Mapping::ActionKeysMap::const_iterator it = _actionKeysMap.begin();
1585+ int n = _actionsList->getSelected();
1586+ for(int i=0; i < n; i++) {
1587+ ++it;
1588+ }
1589+ Common::UserAction action = it->_key;
1590+ KeyInputDialog *dlg = new KeyInputDialog(action);
1591+ dlg->runModal();
1592+ _actionKeysMap = g_system->getKeyMapper()->getKeyMaps();
1593+ Common::StringList *s = new Common::StringList();
1594+ char st[50];
1595+ for (it = _actionKeysMap.begin(); it != _actionKeysMap.end(); ++it) {
1596+ Common::UserAction action = it->_key;
1597+ Common::KeysList keys = it->_value;
1598+ sprintf(st, "%s\t\t\t\t\t\t%s", action.description.c_str(), g_system->keyNameResolve(keys.begin()->keycode).c_str());
1599+ s->push_back(st);
1600+ }
1601+ _actionsList->setList(*s);
1602+ _actionsList->draw();
1603+ }
1604+ break;
1605 case kOKCmd: {
1606 // Write back changes made to config object
1607 String newDomain(_domainWidget->getEditString());
1608@@ -461,6 +534,7 @@
1609 ConfMan.renameGameDomain(_domain, newDomain);
1610 _domain = newDomain;
1611 }
1612+ g_system->getKeyMapper()->saveKeyMaps();
1613 }
1614 // FALL THROUGH to default case
1615 default:
1616@@ -917,4 +991,28 @@
1617 Dialog::reflowLayout();
1618 }
1619
1620+KeyInputDialog::KeyInputDialog(Common::UserAction action)
1621+ : Dialog("KeyInputDialog") {
1622+ _key.keycode = Common::KEYCODE_INVALID;
1623+ _action = action;
1624+ char st[50];
1625+ sprintf(st, "Key for %s action: ", _action.description.c_str());
1626+ _input = new GUI::StaticTextWidget(this, "KeyInput", Common::String(st));
1627+}
1628+
1629+void KeyInputDialog::handleKeyUp(Common::KeyState state){
1630+ if( (state.keycode == Common::KEYCODE_RETURN && _key.keycode == Common::KEYCODE_RETURN) ||
1631+ (state.keycode == Common::KEYCODE_RETURN && _key.keycode != Common::KEYCODE_INVALID) ) {
1632+ g_system->getKeyMapper()->editMapping(_key, _action);
1633+ this->close();
1634+ }
1635+ _key = state;
1636+ char st[50];
1637+ sprintf(st, "Key for %s action: %s", _action.description.c_str(), g_system->keyNameResolve(_key.keycode).c_str());
1638+ _input->setLabel(Common::String(st));
1639+ _input->draw();
1640+
1641+ //Dialog::handleKeyUp(state);
1642+}
1643+
1644 } // End of namespace GUI
1645Index: gui/theme-config.cpp
1646===================================================================
1647--- gui/theme-config.cpp (revision 28773)
1648+++ gui/theme-config.cpp (working copy)
1649@@ -102,6 +102,12 @@
1650 "useAsIs=320xY\n"
1651 "\n"
1652 "[XxY]\n"
1653+"KeyInputDialog=50 50 250 30\n"
1654+"KeyInput=0 0 250 30\n"
1655+"gameoptions_defaultkeys=200 10 80 30\n"
1656+"gameoptions_editkey=200 10+2*30 80 30\n"
1657+"gameoptions_clearkey=200 20+3*30 80 30\n"
1658+"gameoptions_actionslist=10 10 180 200\n"
1659 "def_widgetSize=kBigWidgetSize\n"
1660 "def_buttonWidth=kBigButtonWidth\n"
1661 "def_buttonHeight=kBigButtonHeight\n"
1662