diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 5030589f5d87..ff582fbab16a 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -62,6 +62,9 @@ #include "scene/gui/rich_text_label.h" #include "scene/gui/split_container.h" #include "scene/gui/tab_container.h" +#ifdef ANDROID_ENABLED +#include "editor/gui/touch_actions_panel.h" +#endif #include "scene/main/window.h" #include "scene/property_utils.h" #include "scene/resources/image_texture.h" @@ -7601,6 +7604,12 @@ EditorNode::EditorNode() { _update_layouts_menu(); +#ifdef ANDROID_ENABLED + // Add floating TouchActionsPanel. + TouchActionsPanel *touch_actions_panel = memnew(TouchActionsPanel); + add_child(touch_actions_panel); +#endif + // Bottom panels. bottom_panel = memnew(EditorBottomPanel); diff --git a/editor/gui/editor_bottom_panel.cpp b/editor/gui/editor_bottom_panel.cpp index b8e751917bac..3cc1e37be06a 100644 --- a/editor/gui/editor_bottom_panel.cpp +++ b/editor/gui/editor_bottom_panel.cpp @@ -36,9 +36,6 @@ #include "editor/editor_string_names.h" #include "editor/gui/editor_toaster.h" #include "editor/gui/editor_version_button.h" -#ifdef ANDROID_ENABLED -#include "editor/gui/touch_actions_panel.h" -#endif #include "editor/themes/editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" @@ -266,12 +263,6 @@ EditorBottomPanel::EditorBottomPanel() { button_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL); bottom_hbox->add_child(button_hbox); -#ifdef ANDROID_ENABLED - TouchActionsPanel *touch_actions_panel = memnew(TouchActionsPanel); - touch_actions_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL); - bottom_hbox->add_child(touch_actions_panel); -#endif - editor_toaster = memnew(EditorToaster); bottom_hbox->add_child(editor_toaster); diff --git a/editor/gui/touch_actions_panel.cpp b/editor/gui/touch_actions_panel.cpp index 82e91d0e5fbf..04bfb8c622a1 100644 --- a/editor/gui/touch_actions_panel.cpp +++ b/editor/gui/touch_actions_panel.cpp @@ -31,6 +31,21 @@ #include "touch_actions_panel.h" #include "core/input/input.h" #include "editor/editor_settings.h" +#include "editor/editor_string_names.h" +#include "scene/resources/style_box_flat.h" + +void TouchActionsPanel::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_THEME_CHANGED: { + drag_handle->set_texture(get_editor_theme_icon(SNAME("DragHandle"))); + save_button->set_button_icon(get_editor_theme_icon(SNAME("Save"))); + undo_button->set_button_icon(get_editor_theme_icon(SNAME("UndoRedo"))); + redo_button->set_button_icon(get_editor_theme_icon(SNAME("UndoRedo"))); + } break; + default: + break; + } +} void TouchActionsPanel::_simulate_action(const String &action_name) { Ref shortcut = ED_GET_SHORTCUT(action_name); @@ -44,12 +59,66 @@ void TouchActionsPanel::_simulate_action(const String &action_name) { } } +void TouchActionsPanel::_on_drag_handle_gui_input(const Ref &event) { + Ref mouse_button_event = event; + if (mouse_button_event.is_valid() && mouse_button_event->get_button_index() == MouseButton::LEFT) { + if (mouse_button_event->is_pressed()) { + dragging = true; + drag_offset = mouse_button_event->get_position(); + } else { + dragging = false; + } + } + + Ref mouse_motion_event = event; + if (mouse_motion_event.is_valid() && dragging) { + Vector2 new_position = get_position() + mouse_motion_event->get_relative(); + // Clamp the position to parent bounds + Vector2 parent_size = get_parent_area_size(); + Vector2 panel_size = get_size(); + new_position.x = CLAMP(new_position.x, 0, parent_size.x - panel_size.x); + new_position.y = CLAMP(new_position.y, 0, parent_size.y - panel_size.y); + set_position(new_position); + } +} + TouchActionsPanel::TouchActionsPanel() { + dragging = false; + + //set_custom_minimum_size(Size2(300, 50)); + + // Add a StyleBoxFlat for padding and rounded corners + Ref panel_style = memnew(StyleBoxFlat); + panel_style->set_bg_color(Color(0.1, 0.1, 0.1, 0.95)); + panel_style->set_border_color(Color(0.3, 0.3, 0.3, 1)); + panel_style->set_border_width_all(3); + panel_style->set_corner_radius_all(10); + panel_style->set_content_margin_all(12); + add_theme_style_override("panel", panel_style); + + //set_anchors_preset(Control::PRESET_CENTER_BOTTOM); + hbox = memnew(HBoxContainer); hbox->set_alignment(BoxContainer::ALIGNMENT_CENTER); - hbox->add_theme_constant_override("separation", 30); + hbox->add_theme_constant_override("separation", 10); add_child(hbox); + // Create drag handle + drag_handle = memnew(TextureRect); + drag_handle->set_custom_minimum_size(Size2(50, 30)); + drag_handle->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); + drag_handle->connect(SceneStringName(gui_input), callable_mp(this, &TouchActionsPanel::_on_drag_handle_gui_input)); + hbox->add_child(drag_handle); + + // Add a dummy control node for horizontal spacing. + Control *spacer = memnew(Control); + hbox->add_child(spacer); + + save_button = memnew(Button); + save_button->set_focus_mode(Control::FOCUS_NONE); + save_button->connect(SceneStringName(pressed), callable_mp(this, &TouchActionsPanel::_simulate_action).bind("editor/save_scene")); + hbox->add_child(save_button); + undo_button = memnew(Button); undo_button->set_text(TTR("Undo")); undo_button->set_focus_mode(Control::FOCUS_NONE); @@ -59,6 +128,7 @@ TouchActionsPanel::TouchActionsPanel() { redo_button = memnew(Button); redo_button->set_text(TTR("Redo")); redo_button->set_focus_mode(Control::FOCUS_NONE); + redo_button->set_icon_alignment(HORIZONTAL_ALIGNMENT_RIGHT); redo_button->connect(SceneStringName(pressed), callable_mp(this, &TouchActionsPanel::_simulate_action).bind("ui_redo")); hbox->add_child(redo_button); } diff --git a/editor/gui/touch_actions_panel.h b/editor/gui/touch_actions_panel.h index 353eed770000..c30d04e83bd7 100644 --- a/editor/gui/touch_actions_panel.h +++ b/editor/gui/touch_actions_panel.h @@ -34,16 +34,25 @@ #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/panel_container.h" +#include "scene/gui/texture_rect.h" class TouchActionsPanel : public PanelContainer { GDCLASS(TouchActionsPanel, PanelContainer); private: HBoxContainer *hbox; + Button *save_button; Button *undo_button; Button *redo_button; + TextureRect *drag_handle; + + bool dragging; + Vector2 drag_offset; + + void _notification(int p_what); void _simulate_action(const String &action_name); + void _on_drag_handle_gui_input(const Ref &event); public: TouchActionsPanel(); diff --git a/editor/icons/DragHandle.svg b/editor/icons/DragHandle.svg new file mode 100644 index 000000000000..26c6cdf7ec3b --- /dev/null +++ b/editor/icons/DragHandle.svg @@ -0,0 +1 @@ + \ No newline at end of file