From 0fdc6cd69cc6bcf976fe8f824fdba82f7d00536e Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Mon, 21 Sep 2020 18:33:34 +0200 Subject: [PATCH] Fix drag and drop For the input event to reach the nodes, all Controls need to set mouse_filter to "ignore" it seems? --- main.tscn | 2 ++ node.gd | 5 +++- project.godot | 2 +- repository.gd | 12 ++++---- styles/theme.tres | 72 +++++++++++++++++++++++------------------------ terminal.gd | 30 ++++++++++---------- terminal.tscn | 17 ++++++----- 7 files changed, 72 insertions(+), 68 deletions(-) diff --git a/main.tscn b/main.tscn index 6871f6b..f9eda01 100644 --- a/main.tscn +++ b/main.tscn @@ -23,6 +23,7 @@ corner_radius_bottom_left = 3 [node name="Main" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 +mouse_filter = 2 theme = ExtResource( 6 ) script = ExtResource( 2 ) __meta__ = { @@ -53,6 +54,7 @@ margin_left = 5.0 margin_top = 5.0 margin_right = -5.0 margin_bottom = -5.0 +mouse_filter = 2 __meta__ = { "_edit_use_anchors_": false } diff --git a/node.gd b/node.gd index 3ff03f1..b66428f 100644 --- a/node.gd +++ b/node.gd @@ -17,7 +17,10 @@ func _ready(): func _process(_delta): if held: - global_position = get_global_mouse_position() + if not Input.is_action_pressed("click"): + held = false + else: + global_position = get_global_mouse_position() if visible: apply_forces() diff --git a/project.godot b/project.godot index d68471c..afa8255 100644 --- a/project.godot +++ b/project.godot @@ -32,7 +32,7 @@ game="*res://game.gd" window/size/width=1920 window/size/height=1080 window/stretch/mode="2d" -window/stretch/aspect="expand" +window/stretch/aspect="keep" [input] diff --git a/repository.gd b/repository.gd index 3941f03..36d97ee 100644 --- a/repository.gd +++ b/repository.gd @@ -18,12 +18,12 @@ func _process(_delta): if path: apply_forces() -func _input(event): - if mouse_inside: - if event.is_action_pressed("zoom_out") and $Nodes.rect_scale.x > 0.3: - $Nodes.rect_scale -= Vector2(0.05, 0.05) - if event.is_action_pressed("zoom_in") and $Nodes.rect_scale.x < 2: - $Nodes.rect_scale += Vector2(0.05, 0.05) +#func _input(event): +# if mouse_inside: +# if event.is_action_pressed("zoom_out") and $Nodes.rect_scale.x > 0.3: +# $Nodes.rect_scale -= Vector2(0.05, 0.05) +# if event.is_action_pressed("zoom_in") and $Nodes.rect_scale.x < 2: +# $Nodes.rect_scale += Vector2(0.05, 0.05) func update_everything(): if shell.run("test -d .git && echo yes || echo no") == "yes\n": diff --git a/styles/theme.tres b/styles/theme.tres index 02dd128..2a8d6c7 100644 --- a/styles/theme.tres +++ b/styles/theme.tres @@ -3,14 +3,14 @@ [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1] [ext_resource path="res://fonts/monospace.tres" type="DynamicFont" id=2] -[sub_resource type="StyleBoxFlat" id=2] +[sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.223529, 0.223529, 0.223529, 1 ) corner_radius_top_left = 5 corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[sub_resource type="StyleBoxFlat" id=3] +[sub_resource type="StyleBoxFlat" id=2] bg_color = Color( 0.207843, 0.207843, 0.207843, 1 ) border_width_left = 2 border_width_top = 2 @@ -22,14 +22,14 @@ corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[sub_resource type="StyleBoxFlat" id=4] +[sub_resource type="StyleBoxFlat" id=3] bg_color = Color( 0.278431, 0.278431, 0.278431, 1 ) corner_radius_top_left = 5 corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[sub_resource type="StyleBoxFlat" id=1] +[sub_resource type="StyleBoxFlat" id=4] content_margin_left = 10.0 content_margin_right = 10.0 content_margin_top = 5.0 @@ -47,19 +47,19 @@ corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 +[sub_resource type="StyleBoxEmpty" id=6] + +[sub_resource type="StyleBoxEmpty" id=7] + +[sub_resource type="StyleBoxEmpty" id=8] + +[sub_resource type="StyleBoxEmpty" id=9] + [sub_resource type="StyleBoxEmpty" id=10] [sub_resource type="StyleBoxEmpty" id=11] -[sub_resource type="StyleBoxEmpty" id=12] - -[sub_resource type="StyleBoxEmpty" id=13] - -[sub_resource type="StyleBoxEmpty" id=14] - -[sub_resource type="StyleBoxEmpty" id=15] - -[sub_resource type="StyleBoxFlat" id=9] +[sub_resource type="StyleBoxFlat" id=12] bg_color = Color( 0, 0, 0, 1 ) border_width_left = 2 border_width_top = 2 @@ -71,7 +71,7 @@ corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[sub_resource type="StyleBoxFlat" id=7] +[sub_resource type="StyleBoxFlat" id=13] content_margin_left = 7.0 content_margin_right = 7.0 content_margin_top = 5.0 @@ -82,7 +82,7 @@ corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[sub_resource type="StyleBoxFlat" id=8] +[sub_resource type="StyleBoxFlat" id=14] content_margin_left = 7.0 content_margin_right = 7.0 content_margin_top = 5.0 @@ -93,13 +93,13 @@ corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[sub_resource type="StyleBoxFlat" id=18] +[sub_resource type="StyleBoxFlat" id=15] bg_color = Color( 0.294118, 0.294118, 0.294118, 1 ) -[sub_resource type="StyleBoxFlat" id=19] +[sub_resource type="StyleBoxFlat" id=16] bg_color = Color( 0.172549, 0.172549, 0.172549, 1 ) -[sub_resource type="StyleBoxFlat" id=16] +[sub_resource type="StyleBoxFlat" id=17] content_margin_left = 5.0 content_margin_right = 5.0 content_margin_top = 5.0 @@ -114,7 +114,7 @@ corner_radius_top_left = 5 corner_radius_top_right = 5 corner_radius_bottom_right = 5 -[sub_resource type="StyleBoxFlat" id=17] +[sub_resource type="StyleBoxFlat" id=18] content_margin_left = 5.0 content_margin_right = 5.0 content_margin_top = 5.0 @@ -133,10 +133,10 @@ Button/colors/font_color_hover = Color( 0.94, 0.94, 0.94, 1 ) Button/colors/font_color_pressed = Color( 1, 1, 1, 1 ) Button/constants/hseparation = 2 Button/fonts/font = null -Button/styles/disabled = SubResource( 2 ) -Button/styles/focus = SubResource( 3 ) -Button/styles/hover = SubResource( 4 ) -Button/styles/normal = SubResource( 1 ) +Button/styles/disabled = SubResource( 1 ) +Button/styles/focus = SubResource( 2 ) +Button/styles/hover = SubResource( 3 ) +Button/styles/normal = SubResource( 4 ) Button/styles/pressed = SubResource( 5 ) CheckBox/colors/font_color = Color( 0.88, 0.88, 0.88, 1 ) CheckBox/colors/font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 ) @@ -150,12 +150,12 @@ CheckBox/icons/checked = null CheckBox/icons/radio_checked = null CheckBox/icons/radio_unchecked = null CheckBox/icons/unchecked = null -CheckBox/styles/disabled = SubResource( 10 ) -CheckBox/styles/focus = SubResource( 11 ) -CheckBox/styles/hover = SubResource( 12 ) -CheckBox/styles/hover_pressed = SubResource( 13 ) -CheckBox/styles/normal = SubResource( 14 ) -CheckBox/styles/pressed = SubResource( 15 ) +CheckBox/styles/disabled = SubResource( 6 ) +CheckBox/styles/focus = SubResource( 7 ) +CheckBox/styles/hover = SubResource( 8 ) +CheckBox/styles/hover_pressed = SubResource( 9 ) +CheckBox/styles/normal = SubResource( 10 ) +CheckBox/styles/pressed = SubResource( 11 ) LineEdit/colors/clear_button_color = Color( 0.878431, 0.878431, 0.878431, 1 ) LineEdit/colors/clear_button_color_pressed = Color( 1, 1, 1, 1 ) LineEdit/colors/cursor_color = Color( 0.94, 0.94, 0.94, 1 ) @@ -166,9 +166,9 @@ LineEdit/colors/selection_color = Color( 0.584314, 0.415686, 0.972549, 0.462745 LineEdit/constants/minimum_spaces = 12 LineEdit/fonts/font = ExtResource( 2 ) LineEdit/icons/clear = null -LineEdit/styles/focus = SubResource( 9 ) -LineEdit/styles/normal = SubResource( 7 ) -LineEdit/styles/read_only = SubResource( 8 ) +LineEdit/styles/focus = SubResource( 12 ) +LineEdit/styles/normal = SubResource( 13 ) +LineEdit/styles/read_only = SubResource( 14 ) PopupMenu/colors/font_color = Color( 0.88, 0.88, 0.88, 1 ) PopupMenu/colors/font_color_accel = Color( 0.7, 0.7, 0.7, 0.8 ) PopupMenu/colors/font_color_disabled = Color( 0.4, 0.4, 0.4, 0.8 ) @@ -181,10 +181,10 @@ PopupMenu/icons/radio_checked = null PopupMenu/icons/radio_unchecked = null PopupMenu/icons/submenu = null PopupMenu/icons/unchecked = null -PopupMenu/styles/hover = SubResource( 18 ) +PopupMenu/styles/hover = SubResource( 15 ) PopupMenu/styles/labeled_separator_left = null PopupMenu/styles/labeled_separator_right = null -PopupMenu/styles/panel = SubResource( 19 ) +PopupMenu/styles/panel = SubResource( 16 ) PopupMenu/styles/panel_disabled = null PopupMenu/styles/separator = null TextEdit/colors/background_color = Color( 0, 0, 0, 0 ) @@ -223,6 +223,6 @@ TextEdit/icons/folded = null TextEdit/icons/space = null TextEdit/icons/tab = null TextEdit/styles/completion = null -TextEdit/styles/focus = SubResource( 16 ) -TextEdit/styles/normal = SubResource( 17 ) +TextEdit/styles/focus = SubResource( 17 ) +TextEdit/styles/normal = SubResource( 18 ) TextEdit/styles/read_only = null diff --git a/terminal.gd b/terminal.gd index 225e1c1..5cb40c6 100644 --- a/terminal.gd +++ b/terminal.gd @@ -27,21 +27,21 @@ func _ready(): command_dropdown.theme = Theme.new() command_dropdown.theme.default_font = load("res://fonts/default.tres") -func _input(event): - if history.size() > 0: - if event.is_action_pressed("ui_up"): - if history_position > 0: - history_position -= 1 - input.text = history[history_position] - input.caret_position = input.text.length() - # This prevents the Input taking the arrow as a "skip to beginning" command. - get_tree().set_input_as_handled() - if event.is_action_pressed("ui_down"): - if history_position < history.size()-1: - history_position += 1 - input.text = history[history_position] - input.caret_position = input.text.length() - get_tree().set_input_as_handled() +#func _input(event): +# if history.size() > 0: +# if event.is_action_pressed("ui_up"): +# if history_position > 0: +# history_position -= 1 +# input.text = history[history_position] +# input.caret_position = input.text.length() +# # This prevents the Input taking the arrow as a "skip to beginning" command. +# get_tree().set_input_as_handled() +# if event.is_action_pressed("ui_down"): +# if history_position < history.size()-1: +# history_position += 1 +# input.text = history[history_position] +# input.caret_position = input.text.length() +# get_tree().set_input_as_handled() func load_command(id): input.text = premade_commands[id] diff --git a/terminal.tscn b/terminal.tscn index def8fac..6e8d43d 100644 --- a/terminal.tscn +++ b/terminal.tscn @@ -2,23 +2,21 @@ [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1] [ext_resource path="res://terminal.gd" type="Script" id=2] +[ext_resource path="res://fonts/monospace.tres" type="DynamicFont" id=4] [ext_resource path="res://text_editor.tscn" type="PackedScene" id=5] -[sub_resource type="StyleBoxFlat" id=1] -bg_color = Color( 0, 0, 0, 1 ) -border_width_left = 2 -border_width_top = 2 -border_width_right = 2 -border_width_bottom = 2 -border_color = Color( 0.145098, 0.388235, 0.937255, 1 ) - [sub_resource type="StyleBoxFlat" id=2] +content_margin_left = 5.0 +content_margin_right = 5.0 +content_margin_top = 5.0 +content_margin_bottom = 5.0 bg_color = Color( 0, 0, 0, 1 ) border_color = Color( 0.415686, 0.333333, 1, 1 ) [node name="Terminal" type="Container"] anchor_right = 1.0 anchor_bottom = 1.0 +mouse_filter = 1 script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false @@ -36,8 +34,8 @@ __meta__ = { margin_right = 1920.0 margin_bottom = 1049.0 size_flags_vertical = 3 -custom_styles/focus = SubResource( 1 ) custom_styles/normal = SubResource( 2 ) +custom_fonts/normal_font = ExtResource( 4 ) scroll_following = true [node name="InputLine" type="HBoxContainer" parent="Control"] @@ -74,6 +72,7 @@ text = "Clear" [node name="TextEditor" parent="." instance=ExtResource( 5 )] visible = false +mouse_filter = 1 syntax_highlighting = false [connection signal="text_entered" from="Control/InputLine/Input" to="." method="send_command"] [connection signal="pressed" from="ClearButton" to="." method="clear"]