From e2679fcec9403a30344f8464c1c12c988c302a68 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 14 Oct 2020 00:04:47 +0200 Subject: [PATCH] Add tweening to the card arrangement --- card.gd | 8 ++++---- card.tscn | 25 ++++++++++++++++++++++++- cardgame.gd | 23 ++++++++++++++++++----- cardgame.tscn | 10 +++++++++- terminal.tscn | 3 ++- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/card.gd b/card.gd index 4ffd834..76f4091 100644 --- a/card.gd +++ b/card.gd @@ -11,7 +11,7 @@ var _home_position = null func _ready(): set_process_unhandled_input(true) - _home_position = position + position = get_viewport_rect().size func _process(delta): if dragged: @@ -39,7 +39,7 @@ func _unhandled_input(event): else: move_back() else: - _home_position = get_viewport().get_mouse_position() + drag_offset + move_back() func _mouse_entered(): hovered = true @@ -56,10 +56,10 @@ func move_back(): func buuurn(): queue_free() - $"..".draw_rand_card() + #$"..".draw_rand_card() + $"..".arrange_cards() func dropped_on(other): - #print("I have been dropped on "+str(other.id)) var full_command = "" match arg_number: 1: diff --git a/card.tscn b/card.tscn index 4040530..2dcbdb6 100644 --- a/card.tscn +++ b/card.tscn @@ -1,8 +1,19 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://card.gd" type="Script" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] +[sub_resource type="StyleBoxFlat" id=2] +bg_color = Color( 0.145098, 0.529412, 0.682353, 1 ) +border_color = Color( 0.0627451, 0.141176, 0.176471, 1 ) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 +shadow_color = Color( 0, 0, 0, 0.392157 ) +shadow_size = 4 +shadow_offset = Vector2( -2, 2 ) + [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 105.74, 143.46 ) @@ -11,7 +22,19 @@ extents = Vector2( 105.74, 143.46 ) ]] script = ExtResource( 1 ) +[node name="Panel" type="Panel" parent="."] +margin_left = -105.0 +margin_top = -291.0 +margin_right = 104.0 +margin_bottom = -2.0 +mouse_filter = 2 +custom_styles/panel = SubResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + [node name="ColorRect" type="ColorRect" parent="."] +visible = false margin_left = -103.0 margin_top = -290.336 margin_right = 103.0 diff --git a/cardgame.gd b/cardgame.gd index 96d03d0..e69e264 100644 --- a/cardgame.gd +++ b/cardgame.gd @@ -12,7 +12,6 @@ var cards = [ {"command": 'git reflog expire --expire=now --all; git prune', "arg_number": 0}, {"command": 'git rebase', "arg_number": 1} ] -var total_angle = 45 func _ready(): @@ -45,18 +44,32 @@ func draw_rand_card(): arrange_cards() func arrange_cards(): + var t = Timer.new() + t.wait_time = 0.05 + add_child(t) + t.start() + yield(t, "timeout") + var amount_cards = get_tree().get_nodes_in_group("cards").size() + var total_angle = 45.0/7*amount_cards var angle_between_cards = 0 if amount_cards > 1: angle_between_cards = total_angle / (amount_cards-1) + var current_angle = -total_angle/2 for card in get_tree().get_nodes_in_group("cards"): - card.position = Vector2(get_viewport_rect().size.x/2, get_viewport_rect().size.y + 1500) - card.rotation_degrees = current_angle + var target_position = Vector2(get_viewport_rect().size.x/2, get_viewport_rect().size.y + 1500) + var target_rotation = current_angle var translation_vec = Vector2(0,-1500).rotated(current_angle/180.0*PI) - card.position += translation_vec - print(current_angle) + target_position += translation_vec current_angle += angle_between_cards + card._home_position = target_position + + var tween = Tween.new() + tween.interpolate_property(card, "position", card.position, target_position, 0.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) + tween.interpolate_property(card, "rotation_degrees", card.rotation_degrees, target_rotation, 0.5, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) + add_child(tween) + tween.start() func redraw_all_cards(): for card in get_tree().get_nodes_in_group("cards"): diff --git a/cardgame.tscn b/cardgame.tscn index 8b7ce82..e6f8169 100644 --- a/cardgame.tscn +++ b/cardgame.tscn @@ -8,10 +8,18 @@ [node name="Cardgame" type="Node2D"] script = ExtResource( 4 ) +[node name="ColorRect" type="ColorRect" parent="."] +margin_right = 1922.0 +margin_bottom = 1083.0 +mouse_filter = 2 +color = Color( 0.0823529, 0.0823529, 0.0823529, 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + [node name="Repository" parent="." instance=ExtResource( 3 )] margin_right = 1481.0 margin_bottom = 592.0 -file_browser_active = false simplified_view = true [node name="DropArea" parent="." instance=ExtResource( 2 )] diff --git a/terminal.tscn b/terminal.tscn index 211e580..ce6b697 100644 --- a/terminal.tscn +++ b/terminal.tscn @@ -37,7 +37,7 @@ __meta__ = { [node name="TopHalf" type="Control" parent="Rows"] margin_right = 1920.0 -margin_bottom = 980.0 +margin_bottom = 1052.0 size_flags_vertical = 3 [node name="Output" type="RichTextLabel" parent="Rows/TopHalf"] @@ -65,6 +65,7 @@ __meta__ = { } [node name="VBoxContainer" type="VBoxContainer" parent="Rows"] +visible = false margin_top = 984.0 margin_right = 1920.0 margin_bottom = 1052.0