Work on fixing the compile for 4.0.

This commit is contained in:
Relintai 2022-02-08 11:52:10 +01:00
parent 992b322266
commit 9cbe84ae27
3 changed files with 146 additions and 19 deletions

View File

@ -25,11 +25,19 @@ SOFTWARE.
void BSInputEventKey::from_input_event_key(const Ref<InputEventKey> event) { void BSInputEventKey::from_input_event_key(const Ref<InputEventKey> event) {
set_device(event->get_device()); set_device(event->get_device());
#if VERSION_MAJOR < 4
set_shift(event->get_shift()); set_shift(event->get_shift());
set_alt(event->get_alt()); set_alt(event->get_alt());
set_control(event->get_control()); set_control(event->get_control());
set_metakey(event->get_metakey()); set_metakey(event->get_metakey());
set_command(event->get_command()); set_command(event->get_command());
#else
set_shift_pressed(event->is_shift_pressed());
set_alt_pressed(event->is_alt_pressed());
set_ctrl_pressed(event->is_ctrl_pressed());
set_meta_pressed(event->is_meta_pressed());
set_command_pressed(event->is_command_pressed());
#endif
set_pressed(event->is_pressed()); set_pressed(event->is_pressed());
@ -53,11 +61,11 @@ bool BSInputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_press
uint32_t code = get_scancode_with_modifiers(); uint32_t code = get_scancode_with_modifiers();
uint32_t event_code = key->get_scancode_with_modifiers(); uint32_t event_code = key->get_scancode_with_modifiers();
#else #else
uint32_t code = get_keycode_with_modifiers(); Key code = get_keycode_with_modifiers();
uint32_t event_code = key->get_keycode_with_modifiers(); Key event_code = key->get_keycode_with_modifiers();
#endif #endif
bool match = code == event_code; bool match = (code == event_code);
if (match) { if (match) {
if (p_pressed != NULL) if (p_pressed != NULL)
*p_pressed = key->is_pressed(); *p_pressed = key->is_pressed();

View File

@ -57,7 +57,11 @@
#define CONNECT(sig, obj, target_method_class, method) connect(sig, callable_mp(obj, &target_method_class::method)) #define CONNECT(sig, obj, target_method_class, method) connect(sig, callable_mp(obj, &target_method_class::method))
#endif #endif
#if VERSION_MAJOR < 4
static const char *_button_names[JOY_BUTTON_MAX] = { static const char *_button_names[JOY_BUTTON_MAX] = {
#else
static const char *_button_names[static_cast<int>(JoyButton::MAX)] = {
#endif
"DualShock Cross, Xbox A, Nintendo B", "DualShock Cross, Xbox A, Nintendo B",
"DualShock Circle, Xbox B, Nintendo A", "DualShock Circle, Xbox B, Nintendo A",
"DualShock Square, Xbox X, Nintendo Y", "DualShock Square, Xbox X, Nintendo Y",
@ -76,7 +80,11 @@ static const char *_button_names[JOY_BUTTON_MAX] = {
"D-Pad Right" "D-Pad Right"
}; };
#if VERSION_MAJOR < 4
static const char *_axis_names[JOY_AXIS_MAX * 2] = { static const char *_axis_names[JOY_AXIS_MAX * 2] = {
#else
static const char *_axis_names[static_cast<int>(JoyAxis::MAX) * 2] = {
#endif
" (Left Stick Left)", " (Left Stick Left)",
" (Left Stick Right)", " (Left Stick Right)",
" (Left Stick Up)", " (Left Stick Up)",
@ -194,8 +202,13 @@ void InputMapEditor::_device_input_add() {
switch (add_type) { switch (add_type) {
case INPUT_MOUSE_BUTTON: { case INPUT_MOUSE_BUTTON: {
Ref<InputEventMouseButton> mb; Ref<InputEventMouseButton> mb;
#if VERSION_MAJOR < 4
mb.instance(); mb.instance();
mb->set_button_index(device_index->get_selected() + 1); mb->set_button_index(device_index->get_selected() + 1);
#else
mb.instantiate();
mb->set_button_index(static_cast<MouseButton>(device_index->get_selected() + 1));
#endif
mb->set_device(_get_current_device()); mb->set_device(_get_current_device());
for (int i = 0; i < events.size(); i++) { for (int i = 0; i < events.size(); i++) {
@ -212,8 +225,13 @@ void InputMapEditor::_device_input_add() {
} break; } break;
case INPUT_JOY_MOTION: { case INPUT_JOY_MOTION: {
Ref<InputEventJoypadMotion> jm; Ref<InputEventJoypadMotion> jm;
#if VERSION_MAJOR < 4
jm.instance(); jm.instance();
jm->set_axis(device_index->get_selected() >> 1); jm->set_axis(device_index->get_selected() >> 1);
#else
jm.instantiate();
jm->set_axis(static_cast<JoyAxis>(device_index->get_selected() >> 1));
#endif
jm->set_axis_value((device_index->get_selected() & 1) ? 1 : -1); jm->set_axis_value((device_index->get_selected() & 1) ? 1 : -1);
jm->set_device(_get_current_device()); jm->set_device(_get_current_device());
@ -232,9 +250,13 @@ void InputMapEditor::_device_input_add() {
} break; } break;
case INPUT_JOY_BUTTON: { case INPUT_JOY_BUTTON: {
Ref<InputEventJoypadButton> jb; Ref<InputEventJoypadButton> jb;
#if VERSION_MAJOR < 4
jb.instance(); jb.instance();
jb->set_button_index(device_index->get_selected()); jb->set_button_index(device_index->get_selected());
#else
jb.instantiate();
jb->set_button_index(static_cast<JoyButton>(device_index->get_selected()));
#endif
jb->set_device(_get_current_device()); jb->set_device(_get_current_device());
for (int i = 0; i < events.size(); i++) { for (int i = 0; i < events.size(); i++) {
@ -286,18 +308,22 @@ void InputMapEditor::_press_a_key_confirm() {
return; return;
Ref<BSInputEventKey> ie; Ref<BSInputEventKey> ie;
ie.instance();
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
ie.instance();
ie->set_scancode(last_wait_for_key->get_scancode()); ie->set_scancode(last_wait_for_key->get_scancode());
#else
ie->set_keycode(last_wait_for_key->get_keycode());
#endif
ie->set_shift(last_wait_for_key->get_shift()); ie->set_shift(last_wait_for_key->get_shift());
ie->set_alt(last_wait_for_key->get_alt()); ie->set_alt(last_wait_for_key->get_alt());
ie->set_control(last_wait_for_key->get_control()); ie->set_control(last_wait_for_key->get_control());
ie->set_metakey(last_wait_for_key->get_metakey()); ie->set_metakey(last_wait_for_key->get_metakey());
#else
ie.instantiate();
ie->set_keycode(last_wait_for_key->get_keycode());
ie->set_shift_pressed(last_wait_for_key->is_shift_pressed());
ie->set_alt_pressed(last_wait_for_key->is_alt_pressed());
ie->set_ctrl_pressed(last_wait_for_key->is_ctrl_pressed());
ie->set_meta_pressed(last_wait_for_key->is_meta_pressed());
#endif
String name = add_at; String name = add_at;
int idx = edit_idx; int idx = edit_idx;
@ -343,7 +369,13 @@ void InputMapEditor::_show_last_added(const Ref<InputEvent> &p_event, const Stri
name.erase(0, 6); name.erase(0, 6);
if (!r) if (!r)
return; return;
#if VERSION_MAJOR < 4
r = r->get_children(); r = r->get_children();
#else
r = r->get_first_child();
#endif
if (!r) if (!r)
return; return;
bool found = false; bool found = false;
@ -352,7 +384,13 @@ void InputMapEditor::_show_last_added(const Ref<InputEvent> &p_event, const Stri
r = r->get_next(); r = r->get_next();
continue; continue;
} }
#if VERSION_MAJOR < 4
TreeItem *child = r->get_children(); TreeItem *child = r->get_children();
#else
TreeItem *child = r->get_first_child();
#endif
while (child) { while (child) {
Variant input = child->get_meta("__input"); Variant input = child->get_meta("__input");
if (p_event == input) { if (p_event == input) {
@ -378,7 +416,7 @@ void InputMapEditor::_wait_for_key(const Ref<InputEvent> &p_event) {
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
if (k.is_valid() && k->is_pressed() && k->get_scancode() != 0) { if (k.is_valid() && k->is_pressed() && k->get_scancode() != 0) {
#else #else
if (k.is_valid() && k->is_pressed() && k->get_keycode() != 0) { if (k.is_valid() && k->is_pressed() && k->get_keycode() != Key::NONE) {
#endif #endif
last_wait_for_key = p_event; last_wait_for_key = p_event;
@ -444,7 +482,12 @@ void InputMapEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
Ref<InputEventMouseButton> mb = p_exiting_event; Ref<InputEventMouseButton> mb = p_exiting_event;
if (mb.is_valid()) { if (mb.is_valid()) {
#if VERSION_MAJOR < 4
device_index->select(mb->get_button_index() - 1); device_index->select(mb->get_button_index() - 1);
#else
device_index->select(static_cast<int>(mb->get_button_index()) - 1);
#endif
_set_current_device(mb->get_device()); _set_current_device(mb->get_device());
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
@ -467,7 +510,12 @@ void InputMapEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
case INPUT_JOY_MOTION: { case INPUT_JOY_MOTION: {
device_index_label->set_text("Joypad Axis Index:"); device_index_label->set_text("Joypad Axis Index:");
device_index->clear(); device_index->clear();
#if VERSION_MAJOR < 4
for (int i = 0; i < JOY_AXIS_MAX * 2; i++) { for (int i = 0; i < JOY_AXIS_MAX * 2; i++) {
#else
for (int i = 0; i < static_cast<int>(JoyAxis::MAX) * 2; i++) {
#endif
String desc = _axis_names[i]; String desc = _axis_names[i];
device_index->add_item("Axis " + itos(i / 2) + " " + ((i & 1) ? "+" : "-") + desc); device_index->add_item("Axis " + itos(i / 2) + " " + ((i & 1) ? "+" : "-") + desc);
} }
@ -480,7 +528,12 @@ void InputMapEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
Ref<InputEventJoypadMotion> jm = p_exiting_event; Ref<InputEventJoypadMotion> jm = p_exiting_event;
if (jm.is_valid()) { if (jm.is_valid()) {
#if VERSION_MAJOR < 4
device_index->select(jm->get_axis() * 2 + (jm->get_axis_value() > 0 ? 1 : 0)); device_index->select(jm->get_axis() * 2 + (jm->get_axis_value() > 0 ? 1 : 0));
#else
device_index->select(static_cast<int>(jm->get_axis()) * 2 + (jm->get_axis_value() > 0 ? 1 : 0));
#endif
_set_current_device(jm->get_device()); _set_current_device(jm->get_device());
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
@ -504,7 +557,11 @@ void InputMapEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
device_index_label->set_text("Joypad Button Index:"); device_index_label->set_text("Joypad Button Index:");
device_index->clear(); device_index->clear();
#if VERSION_MAJOR < 4
for (int i = 0; i < JOY_BUTTON_MAX; i++) { for (int i = 0; i < JOY_BUTTON_MAX; i++) {
#else
for (int i = 0; i < static_cast<int>(JoyButton::MAX); i++) {
#endif
device_index->add_item(itos(i) + ": " + String(_button_names[i])); device_index->add_item(itos(i) + ": " + String(_button_names[i]));
} }
@ -516,7 +573,11 @@ void InputMapEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
Ref<InputEventJoypadButton> jb = p_exiting_event; Ref<InputEventJoypadButton> jb = p_exiting_event;
if (jb.is_valid()) { if (jb.is_valid()) {
#if VERSION_MAJOR < 4
device_index->select(jb->get_button_index()); device_index->select(jb->get_button_index());
#else
device_index->select(static_cast<int>(jb->get_button_index()));
#endif
_set_current_device(jb->get_device()); _set_current_device(jb->get_device());
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
@ -524,7 +585,6 @@ void InputMapEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
#else #else
device_input->get_ok_button()->set_text("Change"); device_input->get_ok_button()->set_text("Change");
#endif #endif
} else { } else {
_set_current_device(0); _set_current_device(0);
@ -622,7 +682,11 @@ void InputMapEditor::_action_button_pressed(Object *p_obj, int p_column, int p_i
Array events = action["events"]; Array events = action["events"];
ERR_FAIL_INDEX(idx, events.size()); ERR_FAIL_INDEX(idx, events.size());
#if VERSION_MAJOR < 4
events.remove(idx); events.remove(idx);
#else
events.remove_at(idx);
#endif
action["events"] = events; action["events"] = events;
ProjectSettings::get_singleton()->set(name, action); ProjectSettings::get_singleton()->set(name, action);
@ -665,8 +729,13 @@ void InputMapEditor::_update_actions() {
Map<String, bool> collapsed; Map<String, bool> collapsed;
#if VERSION_MAJOR < 4
if (input_editor->get_root() && input_editor->get_root()->get_children()) { if (input_editor->get_root() && input_editor->get_root()->get_children()) {
for (TreeItem *item = input_editor->get_root()->get_children(); item; item = item->get_next()) { for (TreeItem *item = input_editor->get_root()->get_children(); item; item = item->get_next()) {
#else
if (input_editor->get_root() && input_editor->get_root()->get_first_child()) {
for (TreeItem *item = input_editor->get_root()->get_first_child(); item; item = item->get_next()) {
#endif
collapsed[item->get_text(0)] = item->is_collapsed(); collapsed[item->get_text(0)] = item->is_collapsed();
} }
} }
@ -737,9 +806,13 @@ void InputMapEditor::_update_actions() {
Ref<InputEventJoypadButton> jb = event; Ref<InputEventJoypadButton> jb = event;
if (jb.is_valid()) { if (jb.is_valid()) {
String str = _get_device_string(jb->get_device()) + ", Button " + itos(jb->get_button_index()); String str = _get_device_string(jb->get_device()) + ", Button " + itos(static_cast<int>(jb->get_button_index()));
#if VERSION_MAJOR < 4
if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_BUTTON_MAX) if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_BUTTON_MAX)
str += String() + " (" + _button_names[jb->get_button_index()] + ")."; #else
if (static_cast<int>(jb->get_button_index()) >= 0 && static_cast<int>(jb->get_button_index()) < static_cast<int>(JoyButton::MAX))
#endif
str += String() + " (" + _button_names[static_cast<int>(jb->get_button_index())] + ").";
else else
str += "."; str += ".";
@ -749,6 +822,7 @@ void InputMapEditor::_update_actions() {
Ref<InputEventMouseButton> mb = event; Ref<InputEventMouseButton> mb = event;
#if VERSION_MAJOR < 4
if (mb.is_valid()) { if (mb.is_valid()) {
String str = _get_device_string(mb->get_device()) + ", "; String str = _get_device_string(mb->get_device()) + ", ";
switch (mb->get_button_index()) { switch (mb->get_button_index()) {
@ -770,6 +844,29 @@ void InputMapEditor::_update_actions() {
default: default:
str += "Button " + itos(mb->get_button_index()) + "."; str += "Button " + itos(mb->get_button_index()) + ".";
} }
#else
if (mb.is_valid()) {
String str = _get_device_string(mb->get_device()) + ", ";
switch (mb->get_button_index()) {
case MouseButton::LEFT:
str += "Left Button.";
break;
case MouseButton::RIGHT:
str += "Right Button.";
break;
case MouseButton::MIDDLE:
str += "Middle Button.";
break;
case MouseButton::WHEEL_UP:
str += "Wheel Up.";
break;
case MouseButton::WHEEL_DOWN:
str += "Wheel Down.";
break;
default:
str += "Button " + itos(static_cast<int>(mb->get_button_index())) + ".";
}
#endif
action2->set_text(0, str); action2->set_text(0, str);
action2->set_icon(0, _mouse_texture); action2->set_icon(0, _mouse_texture);
@ -778,7 +875,7 @@ void InputMapEditor::_update_actions() {
Ref<InputEventJoypadMotion> jm = event; Ref<InputEventJoypadMotion> jm = event;
if (jm.is_valid()) { if (jm.is_valid()) {
int ax = jm->get_axis(); int ax = static_cast<int>(jm->get_axis());
int n = 2 * ax + (jm->get_axis_value() < 0 ? 0 : 1); int n = 2 * ax + (jm->get_axis_value() < 0 ? 0 : 1);
String desc = _axis_names[n]; String desc = _axis_names[n];
String str = _get_device_string(jm->get_device()) + ", " + "Axis" + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") + desc + "."; String str = _get_device_string(jm->get_device()) + ", " + "Axis" + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") + desc + ".";
@ -1006,9 +1103,18 @@ InputMapEditor::InputMapEditor() {
input_editor->set_column_title(0, "Action"); input_editor->set_column_title(0, "Action");
input_editor->set_column_title(1, "Deadzone"); input_editor->set_column_title(1, "Deadzone");
input_editor->set_column_expand(1, false); input_editor->set_column_expand(1, false);
#if VERSION_MAJOR < 4
input_editor->set_column_min_width(1, 80); input_editor->set_column_min_width(1, 80);
#else
input_editor->set_column_custom_minimum_width(1, 80);
#endif
input_editor->set_column_expand(2, false); input_editor->set_column_expand(2, false);
#if VERSION_MAJOR < 4
input_editor->set_column_min_width(2, 50); input_editor->set_column_min_width(2, 50);
#else
input_editor->set_column_custom_minimum_width(2, 50);
#endif
input_editor->CONNECT("item_edited", this, InputMapEditor, _action_edited); input_editor->CONNECT("item_edited", this, InputMapEditor, _action_edited);
input_editor->CONNECT("item_activated", this, InputMapEditor, _action_activated); input_editor->CONNECT("item_activated", this, InputMapEditor, _action_activated);
input_editor->CONNECT("cell_selected", this, InputMapEditor, _action_selected); input_editor->CONNECT("cell_selected", this, InputMapEditor, _action_selected);
@ -1027,7 +1133,12 @@ InputMapEditor::InputMapEditor() {
Label *l = memnew(Label); Label *l = memnew(Label);
l->set_text("Press a Key..."); l->set_text("Press a Key...");
#if VERSION_MAJOR < 4
l->set_align(Label::ALIGN_CENTER); l->set_align(Label::ALIGN_CENTER);
#else
l->set_vertical_alignment(VerticalAlignment::VERTICAL_ALIGNMENT_CENTER);
#endif
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
l->set_anchors_and_margins_preset(Control::PRESET_WIDE); l->set_anchors_and_margins_preset(Control::PRESET_WIDE);

View File

@ -25,10 +25,8 @@ SOFTWARE.
#include "core/version.h" #include "core/version.h"
void TouchButton::_notification(int p_what) { void TouchButton::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: { case NOTIFICATION_ENTER_TREE: {
if (!Engine::get_singleton()->is_editor_hint()) { if (!Engine::get_singleton()->is_editor_hint()) {
set_process_input(is_visible_in_tree()); set_process_input(is_visible_in_tree());
} }
@ -49,7 +47,6 @@ void TouchButton::_notification(int p_what) {
} }
void TouchButton::_input(Ref<InputEvent> p_event) { void TouchButton::_input(Ref<InputEvent> p_event) {
if (!get_tree()) if (!get_tree())
return; return;
@ -67,14 +64,24 @@ void TouchButton::_input(Ref<InputEvent> p_event) {
get_viewport()->set_input_as_handled(); get_viewport()->set_input_as_handled();
Ref<InputEventMouseButton> ev; Ref<InputEventMouseButton> ev;
#if VERSION_MAJOR < 4
ev.instance(); ev.instance();
#else
ev.instantiate();
#endif
#if VERSION_MAJOR < 4
ev->set_button_index(BUTTON_LEFT); ev->set_button_index(BUTTON_LEFT);
#else
ev->set_button_index(MouseButton::LEFT);
#endif
ev->set_pressed(b->is_pressed()); ev->set_pressed(b->is_pressed());
ev->set_position(b->get_position()); ev->set_position(b->get_position());
ev->set_global_position(b->get_position()); ev->set_global_position(b->get_position());
#if VERSION_MAJOR <= 3
BaseButton::_gui_input(ev); BaseButton::_gui_input(ev);
#endif
update(); update();
} }
/* /*
@ -100,11 +107,12 @@ void TouchButton::_gui_input(Ref<InputEvent> p_event) {
return; return;
} }
BaseButton::_gui_input(p_event); #if VERSION_MAJOR <= 3
BaseButton::_gui_input(ev);
#endif
} }
void TouchButton::_unhandled_input(Ref<InputEvent> p_event) { void TouchButton::_unhandled_input(Ref<InputEvent> p_event) {
if (p_event->get_device() == -1) { if (p_event->get_device() == -1) {
//accept_event(); //accept_event();
return; return;