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:
@@ -148,11 +148,6 @@ void TouchScreenButton::_notification(int p_what) {
|
||||
if (!get_tree()->is_editor_hint())
|
||||
set_process_input(is_visible_in_tree());
|
||||
|
||||
if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
|
||||
action_id = InputMap::get_singleton()->get_action_id(action);
|
||||
} else {
|
||||
action_id = -1;
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
if (is_pressed())
|
||||
@@ -184,11 +179,6 @@ bool TouchScreenButton::is_pressed() const {
|
||||
void TouchScreenButton::set_action(const String &p_action) {
|
||||
|
||||
action = p_action;
|
||||
if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
|
||||
action_id = InputMap::get_singleton()->get_action_id(action);
|
||||
} else {
|
||||
action_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
String TouchScreenButton::get_action() const {
|
||||
@@ -196,26 +186,32 @@ String TouchScreenButton::get_action() const {
|
||||
return action;
|
||||
}
|
||||
|
||||
void TouchScreenButton::_input(const InputEvent &p_event) {
|
||||
void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
|
||||
|
||||
if (!get_tree())
|
||||
return;
|
||||
|
||||
if (p_event.device != 0)
|
||||
if (p_event->get_device() != 0)
|
||||
return;
|
||||
|
||||
if (passby_press) {
|
||||
|
||||
if (p_event.type == InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed == p_event.screen_touch.index) {
|
||||
Ref<InputEventScreenTouch> st = p_event;
|
||||
Ref<InputEventScreenTouch> sd = p_event;
|
||||
|
||||
if (st.is_valid() && !st->is_pressed() && finger_pressed == st->get_index()) {
|
||||
|
||||
_release();
|
||||
}
|
||||
|
||||
if ((p_event.type == InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed) || p_event.type == InputEvent::SCREEN_DRAG) {
|
||||
if ((st.is_valid() && st->is_pressed()) || sd.is_valid()) {
|
||||
|
||||
if (finger_pressed == -1 || p_event.screen_touch.index == finger_pressed) {
|
||||
int index = st.is_valid() ? st->get_index() : sd->get_index();
|
||||
Vector2 coord = st.is_valid() ? st->get_pos() : sd->get_pos();
|
||||
|
||||
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
|
||||
if (finger_pressed == -1 || index == finger_pressed) {
|
||||
|
||||
coord = (get_global_transform_with_canvas()).affine_inverse().xform(coord);
|
||||
|
||||
bool touched = false;
|
||||
if (bitmask.is_valid()) {
|
||||
@@ -233,7 +229,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
|
||||
|
||||
if (touched) {
|
||||
if (finger_pressed == -1) {
|
||||
_press(p_event.screen_touch.index);
|
||||
_press(index);
|
||||
}
|
||||
} else {
|
||||
if (finger_pressed != -1) {
|
||||
@@ -245,9 +241,11 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
|
||||
|
||||
} else {
|
||||
|
||||
if (p_event.type == InputEvent::SCREEN_TOUCH) {
|
||||
Ref<InputEventScreenTouch> st = p_event;
|
||||
|
||||
if (p_event.screen_touch.pressed) {
|
||||
if (st.is_valid()) {
|
||||
|
||||
if (st->is_pressed()) {
|
||||
|
||||
if (!is_visible_in_tree())
|
||||
return;
|
||||
@@ -256,7 +254,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
|
||||
if (!can_press)
|
||||
return; //already fingering
|
||||
|
||||
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
|
||||
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(st->get_pos());
|
||||
Rect2 item_rect = get_item_rect();
|
||||
|
||||
bool touched = false;
|
||||
@@ -284,10 +282,10 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
|
||||
}
|
||||
|
||||
if (touched) {
|
||||
_press(p_event.screen_touch.index);
|
||||
_press(st->get_index());
|
||||
}
|
||||
} else {
|
||||
if (p_event.screen_touch.index == finger_pressed) {
|
||||
if (st->get_index() == finger_pressed) {
|
||||
_release();
|
||||
}
|
||||
}
|
||||
@@ -299,15 +297,14 @@ void TouchScreenButton::_press(int p_finger_pressed) {
|
||||
|
||||
finger_pressed = p_finger_pressed;
|
||||
|
||||
if (action_id != -1) {
|
||||
if (action != StringName()) {
|
||||
|
||||
Input::get_singleton()->action_press(action);
|
||||
InputEvent ie;
|
||||
ie.type = InputEvent::ACTION;
|
||||
ie.ID = 0;
|
||||
ie.action.action = action_id;
|
||||
ie.action.pressed = true;
|
||||
get_tree()->input_event(ie);
|
||||
Ref<InputEventAction> iea;
|
||||
iea.instance();
|
||||
iea->set_action(action);
|
||||
iea->set_pressed(true);
|
||||
get_tree()->input_event(iea);
|
||||
}
|
||||
|
||||
emit_signal("pressed");
|
||||
@@ -318,16 +315,16 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
|
||||
|
||||
finger_pressed = -1;
|
||||
|
||||
if (action_id != -1) {
|
||||
if (action != StringName()) {
|
||||
|
||||
Input::get_singleton()->action_release(action);
|
||||
if (!p_exiting_tree) {
|
||||
InputEvent ie;
|
||||
ie.type = InputEvent::ACTION;
|
||||
ie.ID = 0;
|
||||
ie.action.action = action_id;
|
||||
ie.action.pressed = false;
|
||||
get_tree()->input_event(ie);
|
||||
|
||||
Ref<InputEventAction> iea;
|
||||
iea.instance();
|
||||
iea->set_action(action);
|
||||
iea->set_pressed(false);
|
||||
get_tree()->input_event(iea);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +416,6 @@ void TouchScreenButton::_bind_methods() {
|
||||
TouchScreenButton::TouchScreenButton() {
|
||||
|
||||
finger_pressed = -1;
|
||||
action_id = -1;
|
||||
passby_press = false;
|
||||
visibility = VISIBILITY_ALWAYS;
|
||||
shape_centered = true;
|
||||
|
||||
Reference in New Issue
Block a user