From 6d0fff27adf6081fc452f445ce5bcc0e341e9372 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Mon, 14 Sep 2020 16:03:01 +0200 Subject: [PATCH] Add checkbox to hide trees and blobs --- arrow.gd | 4 +++- main.tscn | 14 +++++++------- node.gd | 19 +++++++++++------- repository.gd | 51 +++++++++++++++++++++++++++++++++---------------- repository.tscn | 9 +++++++++ terminal.gd | 3 ++- terminal.tscn | 3 +++ 7 files changed, 71 insertions(+), 32 deletions(-) diff --git a/arrow.gd b/arrow.gd index ce919b2..6a88f01 100644 --- a/arrow.gd +++ b/arrow.gd @@ -9,12 +9,14 @@ func _ready(): func _process(_delta): var end = global_position + Vector2(0, 50) - if repository and repository.objects.has(target): + if repository and repository.objects.has(target) and repository.objects[target].visible: var t = repository.objects[target] end = t.global_position $Target.hide() else: $Target.text = target + if $Target.text.substr(0, 5) != "refs/": + $Target.text = ""#$Target.text.substr(0,8) $Target.show() $Line.points[1] = end - global_position $Label.position = ($Line.points[0] + $Line.points[1])/2 diff --git a/main.tscn b/main.tscn index 39c7f85..65d5ce1 100644 --- a/main.tscn +++ b/main.tscn @@ -74,8 +74,8 @@ __meta__ = { [node name="Repositories" type="HBoxContainer" parent="."] margin_left = 5.0 margin_top = 5.0 -margin_right = 1203.0 -margin_bottom = 1038.0 +margin_right = 1218.0 +margin_bottom = 1076.0 mouse_filter = 2 custom_constants/separation = 0 __meta__ = { @@ -87,8 +87,8 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 0.0 margin_top = 0.0 -margin_right = 599.0 -margin_bottom = 1033.0 +margin_right = 606.0 +margin_bottom = 1071.0 size_flags_horizontal = 3 size_flags_vertical = 3 label = "Goal" @@ -96,10 +96,10 @@ label = "Goal" [node name="ActiveRepository" parent="Repositories" instance=ExtResource( 3 )] anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 599.0 +margin_left = 606.0 margin_top = 0.0 -margin_right = 1198.0 -margin_bottom = 1033.0 +margin_right = 1213.0 +margin_bottom = 1071.0 size_flags_horizontal = 3 size_flags_vertical = 3 label = "Your repository" diff --git a/node.gd b/node.gd index 61747bc..122f100 100644 --- a/node.gd +++ b/node.gd @@ -17,17 +17,22 @@ func _ready(): func _process(_delta): if held: global_position = get_global_mouse_position() - + + if visible: + apply_forces() + +func apply_forces(): var offset = Vector2(0, 80) - + for c in children.keys(): if get_node("..").objects.has(c): var other = get_node("..").objects[c] - var d = other.position.distance_to(position+offset) - var dir = (other.position - (position+offset)).normalized() - var f = (d*0.03) - position += dir*f - other.position -= dir*f + if other.visible: + var d = other.position.distance_to(position+offset) + var dir = (other.position - (position+offset)).normalized() + var f = (d*0.03) + position += dir*f + other.position -= dir*f func id_set(new_id): id = new_id diff --git a/repository.gd b/repository.gd index a204e32..da61d25 100644 --- a/repository.gd +++ b/repository.gd @@ -8,6 +8,8 @@ var node = preload("res://node.tscn") var shell = Shell.new() var objects = {} +var _simplified_view = false + func _ready(): pass @@ -46,27 +48,31 @@ func update_objects(): for o in all_objects(): if objects.has(o): continue + + var type = object_type(o) + if _simplified_view: + if type == "tree" or type == "blob": + continue + var n = node.instance() n.id = o n.type = object_type(o) n.content = object_content(o) n.repository = self - if true: - var type = object_type(o) - match type: - "blob": - pass - "tree": - n.children = tree_children(o) - "commit": - var c = {} - c[commit_tree(o)] = "" - for p in commit_parents(o): - c[p] = "" - n.children = c - "tag": - n.children = tag_target(o) + match type: + "blob": + pass + "tree": + n.children = tree_children(o) + "commit": + var c = {} + c[commit_tree(o)] = "" + for p in commit_parents(o): + c[p] = "" + n.children = c + "tag": + n.children = tag_target(o) n.position = find_position(n) add_child(n) @@ -89,8 +95,10 @@ func update_refs(): func apply_forces(): for o in objects.values(): + if not o.visible: + continue for o2 in objects.values(): - if o == o2: + if o == o2 or not o2.visible: continue var d = o.position.distance_to(o2.position) var dir = (o.global_position - o2.global_position).normalized() @@ -203,3 +211,14 @@ func ref_target(ref): else: ret = git("show-ref "+ref).split(" ")[0] return ret + + +func simplify_view(pressed): + _simplified_view = pressed + + for o in objects: + var obj = objects[o] + if obj.type == "tree" or obj.type == "blob": + obj.visible = not pressed + + update_objects() diff --git a/repository.tscn b/repository.tscn index 2a36ef0..3e15bb3 100644 --- a/repository.tscn +++ b/repository.tscn @@ -56,4 +56,13 @@ margin_left = 20.0 margin_top = 20.0 custom_fonts/font = ExtResource( 3 ) text = "Repo name" + +[node name="SimplifyCheckbox" type="CheckBox" parent="."] +anchor_top = 0.968 +anchor_bottom = 0.968 +margin_right = 24.0 +margin_bottom = 24.0 +custom_fonts/font = ExtResource( 2 ) +text = "Hide trees and blobs" [connection signal="pressed" from="Button" to="." method="update_everything"] +[connection signal="toggled" from="SimplifyCheckbox" to="." method="simplify_view"] diff --git a/terminal.gd b/terminal.gd index 065f7a7..0f3a3da 100644 --- a/terminal.gd +++ b/terminal.gd @@ -14,6 +14,8 @@ func _ready(): repo.shell.connect("output", self, "receive_output") func _input(event): + if event is InputEventKey: + input.grab_focus() if history.size() > 0: if event.is_action_pressed("ui_up"): if history_position > 0: @@ -57,7 +59,6 @@ func receive_output(text): output.text += text func clear(): - input.text = "" output.text = "" func check_win_condition(): diff --git a/terminal.tscn b/terminal.tscn index 5702956..fb91086 100644 --- a/terminal.tscn +++ b/terminal.tscn @@ -44,10 +44,13 @@ __meta__ = { [node name="Output" type="RichTextLabel" parent="Control"] margin_right = 1920.0 margin_bottom = 979.0 +focus_mode = 2 size_flags_vertical = 3 custom_styles/normal = SubResource( 1 ) custom_fonts/normal_font = ExtResource( 1 ) +custom_colors/selection_color = Color( 0.14902, 0.368627, 0.168627, 0.690196 ) scroll_following = true +selection_enabled = true [node name="Button" parent="Control" instance=ExtResource( 4 )] margin_left = 0.0