Changed Action constructor to take a pointer to the Keymap it belongs too, meaning Keymap::addAction is automatically called
svn-id: r33885
This commit is contained in:
parent
6d0ed23b44
commit
c61294e70f
5 changed files with 29 additions and 49 deletions
|
@ -28,29 +28,18 @@
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
Action::Action(int32 i, String des,
|
Action::Action(Keymap *boss, int32 i, String des, ActionCategory cat,
|
||||||
ActionCategory cat, ActionType typ,
|
ActionType typ, int pri, int grp, int flg)
|
||||||
int pri, int grp, int flg) {
|
: _boss(boss), id(i), description(des), category(cat), type(typ),
|
||||||
id = i;
|
priority(pri), group(grp), flags(flg), _hwKey(0) {
|
||||||
description = des;
|
assert(_boss);
|
||||||
category = cat;
|
_boss->addAction(this);
|
||||||
type = typ;
|
|
||||||
priority = pri;
|
|
||||||
group = grp;
|
|
||||||
flags = flg;
|
|
||||||
_hwKey = 0;
|
|
||||||
_parent = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Action::setParent(Keymap *parent) {
|
|
||||||
_parent = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::mapKey(const HardwareKey *key) {
|
void Action::mapKey(const HardwareKey *key) {
|
||||||
assert(_parent);
|
if (_hwKey) _boss->unregisterMapping(this);
|
||||||
if (_hwKey) _parent->unregisterMapping(this);
|
|
||||||
_hwKey = key;
|
_hwKey = key;
|
||||||
if (_hwKey) _parent->registerMapping(this, _hwKey);
|
if (_hwKey) _boss->registerMapping(this, _hwKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
const HardwareKey *Action::getMappedKey() const {
|
const HardwareKey *Action::getMappedKey() const {
|
||||||
|
|
|
@ -85,18 +85,16 @@ struct Action {
|
||||||
private:
|
private:
|
||||||
/** Hardware key that is mapped to this Action */
|
/** Hardware key that is mapped to this Action */
|
||||||
const HardwareKey *_hwKey;
|
const HardwareKey *_hwKey;
|
||||||
Keymap *_parent;
|
Keymap *_boss;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Action( int32 id,
|
Action(Keymap *boss, int32 id, String des = "",
|
||||||
String des = "",
|
|
||||||
ActionCategory cat = kGenericActionCategory,
|
ActionCategory cat = kGenericActionCategory,
|
||||||
ActionType typ = kGenericActionType,
|
ActionType typ = kGenericActionType,
|
||||||
int pri = 0, int grp = 0, int flg = 0 );
|
int pri = 0, int grp = 0, int flg = 0 );
|
||||||
|
|
||||||
void addEvent(const Event &evt) { events.push_back(evt); }
|
void addEvent(const Event &evt) { events.push_back(evt); }
|
||||||
void setParent(Keymap *parent);
|
Keymap *getBoss() { return _boss; }
|
||||||
Keymap *getParent() { return _parent; }
|
|
||||||
void mapKey(const HardwareKey *key);
|
void mapKey(const HardwareKey *key);
|
||||||
const HardwareKey *getMappedKey() const;
|
const HardwareKey *getMappedKey() const;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ Keymap::~Keymap() {
|
||||||
void Keymap::addAction(Action *action) {
|
void Keymap::addAction(Action *action) {
|
||||||
if (findAction(action->id))
|
if (findAction(action->id))
|
||||||
error("Action with id %d already in KeyMap!", action->id);
|
error("Action with id %d already in KeyMap!", action->id);
|
||||||
action->setParent(this);
|
|
||||||
_actions.push_back(action);
|
_actions.push_back(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,6 @@ public:
|
||||||
~Keymap();
|
~Keymap();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Adds a new Action to this Map,
|
|
||||||
* adding it at the back of the internal array
|
|
||||||
* @param action the Action to add
|
|
||||||
*/
|
|
||||||
void addAction(Action *action);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the Action with the given id
|
* Retrieves the Action with the given id
|
||||||
* @param id id of Action to retrieve
|
* @param id id of Action to retrieve
|
||||||
|
@ -108,6 +101,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend struct Action;
|
friend struct Action;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new Action to this Map,
|
||||||
|
* adding it at the back of the internal array
|
||||||
|
* @param action the Action to add
|
||||||
|
*/
|
||||||
|
void addAction(Action *action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a HardwareKey to the given Action
|
* Registers a HardwareKey to the given Action
|
||||||
* @param action Action in this Keymap
|
* @param action Action in this Keymap
|
||||||
|
|
|
@ -542,33 +542,26 @@ void OSystem_SDL::setupKeymapper() {
|
||||||
evt.kbd = KeyState(kc, asc, flags); \
|
evt.kbd = KeyState(kc, asc, flags); \
|
||||||
act->events.push_back(evt);
|
act->events.push_back(evt);
|
||||||
|
|
||||||
act = new Action('MENU', "Menu", kGenericActionCategory, kMenuAction);
|
act = new Action(global, 'MENU', "Menu", kGenericActionCategory, kMenuAction);
|
||||||
ADD_KEYDOWN_EVENT(KEYCODE_F5, ASCII_F5, 0)
|
ADD_KEYDOWN_EVENT(KEYCODE_F5, ASCII_F5, 0)
|
||||||
global->addAction(act);
|
|
||||||
|
|
||||||
act = new Action('SKCT', "Skip");
|
act = new Action(global, 'SKCT', "Skip");
|
||||||
ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
|
ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
|
||||||
global->addAction(act);
|
|
||||||
|
|
||||||
act = new Action('PAUS', "Pause");
|
act = new Action(global, 'PAUS', "Pause");
|
||||||
ADD_KEYDOWN_EVENT(KEYCODE_SPACE, ' ', 0)
|
ADD_KEYDOWN_EVENT(KEYCODE_SPACE, ' ', 0)
|
||||||
global->addAction(act);
|
|
||||||
|
|
||||||
act = new Action('SKLI', "Skip line");
|
act = new Action(global, 'SKLI', "Skip line");
|
||||||
ADD_KEYDOWN_EVENT(Common::KEYCODE_PERIOD, '.', 0);
|
ADD_KEYDOWN_EVENT(Common::KEYCODE_PERIOD, '.', 0);
|
||||||
global->addAction(act);
|
|
||||||
|
|
||||||
act = new Action('JUMP', "Jump");
|
act = new Action(specific, 'JUMP', "Jump");
|
||||||
ADD_KEYDOWN_EVENT(KEYCODE_j, 'j', 0);
|
ADD_KEYDOWN_EVENT(KEYCODE_j, 'j', 0);
|
||||||
specific->addAction(act);
|
|
||||||
|
|
||||||
act = new Action('DUCK', "Duck");
|
act = new Action(specific, 'DUCK', "Duck");
|
||||||
ADD_KEYDOWN_EVENT(KEYCODE_d, 'd', 0);
|
ADD_KEYDOWN_EVENT(KEYCODE_d, 'd', 0);
|
||||||
specific->addAction(act);
|
|
||||||
|
|
||||||
act = new Action('RUN_', "Run");
|
act = new Action(specific, 'RUN_', "Run");
|
||||||
ADD_KEYDOWN_EVENT(KEYCODE_r, 'r', 0);
|
ADD_KEYDOWN_EVENT(KEYCODE_r, 'r', 0);
|
||||||
specific->addAction(act);
|
|
||||||
|
|
||||||
#undef ADD_KEYDOWN_EVENT
|
#undef ADD_KEYDOWN_EVENT
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue