Просмотр исходного кода

Add an editor setting to enable/disable TouchActionsPanel

Adds an editor setting to enable/disable TouchActionsPanel.

Automatically hide the panel when hardware keyboard is connected.
Anish Mishra 5 месяцев назад
Родитель
Сommit
a5c03dcd08

+ 4 - 0
doc/classes/EditorSettings.xml

@@ -1102,6 +1102,10 @@
 			If [code]true[/code], enable two finger pan and scale gestures on touchscreen devices.
 			[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.
 		</member>
+		<member name="interface/touchscreen/enable_touch_actions_panel" type="bool" setter="" getter="">
+			If [code]true[/code], enables the TouchActionsPanel to provide easy access to keyboard shortcuts on touchscreen devices.
+			[b]Note:[/b] Only available in the Android editor.
+		</member>
 		<member name="interface/touchscreen/increase_scrollbar_touch_area" type="bool" setter="" getter="">
 			If [code]true[/code], increases the scrollbar touch area to improve usability on touchscreen devices.
 			[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.

+ 4 - 1
editor/editor_node.cpp

@@ -7931,7 +7931,10 @@ EditorNode::EditorNode() {
 
 #ifdef ANDROID_ENABLED
 	// Add TouchActionsPanel node.
-	add_child(memnew(TouchActionsPanel));
+	bool is_enabled = EDITOR_GET("interface/touchscreen/enable_touch_actions_panel");
+	if (is_enabled) {
+		add_child(memnew(TouchActionsPanel));
+	}
 #endif
 
 	// Bottom panels.

+ 4 - 0
editor/editor_settings.cpp

@@ -584,6 +584,10 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
 	EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/touchscreen/scale_gizmo_handles", has_touchscreen_ui ? 3 : 1, "1,5,1")
 	set_restart_if_changed("interface/touchscreen/scale_gizmo_handles", true);
 
+	// Only available in the Android editor.
+	EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_touch_actions_panel", true, "")
+	set_restart_if_changed("interface/touchscreen/enable_touch_actions_panel", true);
+
 	// Disable some touchscreen settings by default for the XR Editor.
 	bool is_native_touchscreen = has_touchscreen_ui && !OS::get_singleton()->has_feature("xr_editor");
 	EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_long_press_as_right_click", is_native_touchscreen, "")

+ 8 - 0
editor/gui/touch_actions_panel.cpp

@@ -41,6 +41,10 @@
 
 void TouchActionsPanel::_notification(int p_what) {
 	switch (p_what) {
+		case NOTIFICATION_ENTER_TREE: {
+			DisplayServer::get_singleton()->set_hardware_keyboard_connection_change_callback(callable_mp(this, &TouchActionsPanel::_hardware_keyboard_connected));
+			_hardware_keyboard_connected(DisplayServer::get_singleton()->has_hardware_keyboard());
+		} break;
 		case NOTIFICATION_THEME_CHANGED: {
 			drag_handle->set_texture(get_editor_theme_icon(SNAME("DragHandle")));
 			layout_toggle_button->set_button_icon(get_editor_theme_icon(SNAME("Orientation")));
@@ -53,6 +57,10 @@ void TouchActionsPanel::_notification(int p_what) {
 	}
 }
 
+void TouchActionsPanel::_hardware_keyboard_connected(bool p_connected) {
+	set_visible(!p_connected);
+}
+
 void TouchActionsPanel::_simulate_editor_shortcut(const String &p_shortcut_name) {
 	Ref<Shortcut> shortcut = ED_GET_SHORTCUT(p_shortcut_name);
 

+ 2 - 0
editor/gui/touch_actions_panel.h

@@ -63,6 +63,8 @@ private:
 	void _lock_panel_toggled(bool p_pressed);
 	Button *_add_new_action_button(const String &p_shortcut, Key p_keycode = Key::NONE);
 
+	void _hardware_keyboard_connected(bool p_connected);
+
 public:
 	TouchActionsPanel();
 };