mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
This commit is contained in:
@@ -37,8 +37,6 @@ InputMap *InputMap::singleton = NULL;
|
||||
void InputMap::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
|
||||
ClassDB::bind_method(D_METHOD("get_action_id", "action"), &InputMap::get_action_id);
|
||||
ClassDB::bind_method(D_METHOD("get_action_from_id", "id"), &InputMap::get_action_from_id);
|
||||
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
|
||||
ClassDB::bind_method(D_METHOD("add_action", "action"), &InputMap::add_action);
|
||||
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
|
||||
@@ -57,23 +55,15 @@ void InputMap::add_action(const StringName &p_action) {
|
||||
input_map[p_action] = Action();
|
||||
static int last_id = 1;
|
||||
input_map[p_action].id = last_id;
|
||||
input_id_map[last_id] = p_action;
|
||||
last_id++;
|
||||
}
|
||||
|
||||
void InputMap::erase_action(const StringName &p_action) {
|
||||
|
||||
ERR_FAIL_COND(!input_map.has(p_action));
|
||||
input_id_map.erase(input_map[p_action].id);
|
||||
input_map.erase(p_action);
|
||||
}
|
||||
|
||||
StringName InputMap::get_action_from_id(int p_id) const {
|
||||
|
||||
ERR_FAIL_COND_V(!input_id_map.has(p_id), StringName());
|
||||
return input_id_map[p_id];
|
||||
}
|
||||
|
||||
Array InputMap::_get_actions() {
|
||||
|
||||
Array ret;
|
||||
@@ -103,49 +93,18 @@ List<StringName> InputMap::get_actions() const {
|
||||
return actions;
|
||||
}
|
||||
|
||||
List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list, const InputEvent &p_event, bool p_action_test) const {
|
||||
List<Ref<InputEvent> >::Element *InputMap::_find_event(List<Ref<InputEvent> > &p_list, const Ref<InputEvent> &p_event, bool p_action_test) const {
|
||||
|
||||
for (List<InputEvent>::Element *E = p_list.front(); E; E = E->next()) {
|
||||
for (List<Ref<InputEvent> >::Element *E = p_list.front(); E; E = E->next()) {
|
||||
|
||||
const InputEvent &e = E->get();
|
||||
if (e.type != p_event.type)
|
||||
const Ref<InputEvent> e = E->get();
|
||||
|
||||
//if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
|
||||
// continue;
|
||||
|
||||
if (e->get_device() != p_event->get_device())
|
||||
continue;
|
||||
if (e.type != InputEvent::KEY && e.device != p_event.device)
|
||||
continue;
|
||||
|
||||
bool same = false;
|
||||
|
||||
switch (p_event.type) {
|
||||
|
||||
case InputEvent::KEY: {
|
||||
|
||||
if (p_action_test) {
|
||||
uint32_t code = e.key.get_scancode_with_modifiers();
|
||||
uint32_t event_code = p_event.key.get_scancode_with_modifiers();
|
||||
same = (e.key.scancode == p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code)));
|
||||
} else {
|
||||
same = (e.key.scancode == p_event.key.scancode && e.key.mod == p_event.key.mod);
|
||||
}
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYPAD_BUTTON: {
|
||||
|
||||
same = (e.joy_button.button_index == p_event.joy_button.button_index);
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
same = (e.mouse_button.button_index == p_event.mouse_button.button_index);
|
||||
|
||||
} break;
|
||||
case InputEvent::JOYPAD_MOTION: {
|
||||
|
||||
same = (e.joy_motion.axis == p_event.joy_motion.axis && (e.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
if (same)
|
||||
if (e->action_match(p_event))
|
||||
return E;
|
||||
}
|
||||
|
||||
@@ -157,9 +116,9 @@ bool InputMap::has_action(const StringName &p_action) const {
|
||||
return input_map.has(p_action);
|
||||
}
|
||||
|
||||
void InputMap::action_add_event(const StringName &p_action, const InputEvent &p_event) {
|
||||
void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
|
||||
|
||||
ERR_FAIL_COND(p_event.type == InputEvent::ACTION);
|
||||
ERR_FAIL_COND(p_event.is_null());
|
||||
ERR_FAIL_COND(!input_map.has(p_action));
|
||||
if (_find_event(input_map[p_action].inputs, p_event))
|
||||
return; //already gots
|
||||
@@ -167,23 +126,17 @@ void InputMap::action_add_event(const StringName &p_action, const InputEvent &p_
|
||||
input_map[p_action].inputs.push_back(p_event);
|
||||
}
|
||||
|
||||
int InputMap::get_action_id(const StringName &p_action) const {
|
||||
|
||||
ERR_FAIL_COND_V(!input_map.has(p_action), -1);
|
||||
return input_map[p_action].id;
|
||||
}
|
||||
|
||||
bool InputMap::action_has_event(const StringName &p_action, const InputEvent &p_event) {
|
||||
bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
|
||||
|
||||
ERR_FAIL_COND_V(!input_map.has(p_action), false);
|
||||
return (_find_event(input_map[p_action].inputs, p_event) != NULL);
|
||||
}
|
||||
|
||||
void InputMap::action_erase_event(const StringName &p_action, const InputEvent &p_event) {
|
||||
void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
|
||||
|
||||
ERR_FAIL_COND(!input_map.has(p_action));
|
||||
|
||||
List<InputEvent>::Element *E = _find_event(input_map[p_action].inputs, p_event);
|
||||
List<Ref<InputEvent> >::Element *E = _find_event(input_map[p_action].inputs, p_event);
|
||||
if (E)
|
||||
input_map[p_action].inputs.erase(E);
|
||||
}
|
||||
@@ -191,9 +144,9 @@ void InputMap::action_erase_event(const StringName &p_action, const InputEvent &
|
||||
Array InputMap::_get_action_list(const StringName &p_action) {
|
||||
|
||||
Array ret;
|
||||
const List<InputEvent> *al = get_action_list(p_action);
|
||||
const List<Ref<InputEvent> > *al = get_action_list(p_action);
|
||||
if (al) {
|
||||
for (const List<InputEvent>::Element *E = al->front(); E; E = E->next()) {
|
||||
for (const List<Ref<InputEvent> >::Element *E = al->front(); E; E = E->next()) {
|
||||
|
||||
ret.push_back(E->get());
|
||||
}
|
||||
@@ -202,7 +155,7 @@ Array InputMap::_get_action_list(const StringName &p_action) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
|
||||
const List<Ref<InputEvent> > *InputMap::get_action_list(const StringName &p_action) {
|
||||
|
||||
const Map<StringName, Action>::Element *E = input_map.find(p_action);
|
||||
if (!E)
|
||||
@@ -211,7 +164,7 @@ const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
|
||||
return &E->get().inputs;
|
||||
}
|
||||
|
||||
bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_action) const {
|
||||
bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const {
|
||||
|
||||
Map<StringName, Action>::Element *E = input_map.find(p_action);
|
||||
if (!E) {
|
||||
@@ -219,9 +172,9 @@ bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_ac
|
||||
ERR_FAIL_COND_V(!E, false);
|
||||
}
|
||||
|
||||
if (p_event.type == InputEvent::ACTION) {
|
||||
|
||||
return p_event.action.action == E->get().id;
|
||||
Ref<InputEventAction> iea = p_event;
|
||||
if (iea.is_valid()) {
|
||||
return iea->get_action() == p_action;
|
||||
}
|
||||
|
||||
return _find_event(E->get().inputs, p_event, true) != NULL;
|
||||
@@ -252,8 +205,8 @@ void InputMap::load_from_globals() {
|
||||
|
||||
for (int i = 0; i < va.size(); i++) {
|
||||
|
||||
InputEvent ie = va[i];
|
||||
if (ie.type == InputEvent::NONE)
|
||||
Ref<InputEvent> ie = va[i];
|
||||
if (ie.is_null())
|
||||
continue;
|
||||
action_add_event(name, ie);
|
||||
}
|
||||
@@ -262,57 +215,70 @@ void InputMap::load_from_globals() {
|
||||
|
||||
void InputMap::load_default() {
|
||||
|
||||
InputEvent key;
|
||||
key.type = InputEvent::KEY;
|
||||
Ref<InputEventKey> key;
|
||||
|
||||
add_action("ui_accept");
|
||||
key.key.scancode = KEY_RETURN;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_RETURN);
|
||||
action_add_event("ui_accept", key);
|
||||
key.key.scancode = KEY_ENTER;
|
||||
|
||||
key.instance();
|
||||
key->set_scancode(KEY_ENTER);
|
||||
action_add_event("ui_accept", key);
|
||||
key.key.scancode = KEY_SPACE;
|
||||
|
||||
key.instance();
|
||||
key->set_scancode(KEY_SPACE);
|
||||
action_add_event("ui_accept", key);
|
||||
|
||||
add_action("ui_select");
|
||||
key.key.scancode = KEY_SPACE;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_SPACE);
|
||||
action_add_event("ui_select", key);
|
||||
|
||||
add_action("ui_cancel");
|
||||
key.key.scancode = KEY_ESCAPE;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_ESCAPE);
|
||||
action_add_event("ui_cancel", key);
|
||||
|
||||
add_action("ui_focus_next");
|
||||
key.key.scancode = KEY_TAB;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_TAB);
|
||||
action_add_event("ui_focus_next", key);
|
||||
|
||||
add_action("ui_focus_prev");
|
||||
key.key.scancode = KEY_TAB;
|
||||
key.key.mod.shift = true;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_TAB);
|
||||
key->set_shift(true);
|
||||
action_add_event("ui_focus_prev", key);
|
||||
key.key.mod.shift = false;
|
||||
|
||||
add_action("ui_left");
|
||||
key.key.scancode = KEY_LEFT;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_LEFT);
|
||||
action_add_event("ui_left", key);
|
||||
|
||||
add_action("ui_right");
|
||||
key.key.scancode = KEY_RIGHT;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_RIGHT);
|
||||
action_add_event("ui_right", key);
|
||||
|
||||
add_action("ui_up");
|
||||
key.key.scancode = KEY_UP;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_UP);
|
||||
action_add_event("ui_up", key);
|
||||
|
||||
add_action("ui_down");
|
||||
key.key.scancode = KEY_DOWN;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_DOWN);
|
||||
action_add_event("ui_down", key);
|
||||
|
||||
add_action("ui_page_up");
|
||||
key.key.scancode = KEY_PAGEUP;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_PAGEUP);
|
||||
action_add_event("ui_page_up", key);
|
||||
|
||||
add_action("ui_page_down");
|
||||
key.key.scancode = KEY_PAGEDOWN;
|
||||
key.instance();
|
||||
key->set_scancode(KEY_PAGEDOWN);
|
||||
action_add_event("ui_page_down", key);
|
||||
|
||||
//set("display/handheld/orientation", "landscape");
|
||||
|
||||
Reference in New Issue
Block a user