From e97af81c0f7e8f227077b27764ebaa15e47b6401 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 17 Nov 2020 16:27:16 +0100 Subject: [PATCH] New Item scene, in preparation for a 2D world --- scenes/file_browser.gd | 15 ++++++------ scenes/file_browser.tscn | 33 ++++++++++++--------------- scenes/item.gd | 49 ++++++++++++++++++++++++++++++++++++++++ scenes/item.tscn | 28 +++++++++++++++++++++++ scenes/main.tscn | 10 ++++---- 5 files changed, 104 insertions(+), 31 deletions(-) create mode 100644 scenes/item.gd create mode 100644 scenes/item.tscn diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index da0a284..716d497 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -15,7 +15,7 @@ var repository var open_file -onready var grid = $Panel/Margin/Rows/Scroll/Grid +#onready var grid = $Panel/Margin/Rows/Scroll/Grid onready var text_edit = $Panel/TextEdit onready var save_button = $Panel/TextEdit/SaveButton onready var title_label = $Panel/Margin/Rows/Title @@ -32,14 +32,15 @@ func _input(event): save() func clear(): - for item in grid.get_children(): - item.queue_free() + pass +# for item in grid.get_children(): +# item.queue_free() func substr2(s): return s.substr(2) func update(): - if grid: + if true:#grid: clear() match mode: FileBrowserMode.WORKING_DIRECTORY: @@ -68,7 +69,7 @@ func update(): item.connect("deleted", self, "item_deleted") item.status = get_file_status(file_path, shell, 1) - grid.add_child(item) + #grid.add_child(item) #visible = is_visible FileBrowserMode.COMMIT: @@ -80,7 +81,7 @@ func update(): var item = preload("res://scenes/file_browser_item.tscn").instance() item.label = file_path item.connect("clicked", self, "item_clicked") - grid.add_child(item) + #grid.add_child(item) FileBrowserMode.INDEX: #var is_visible = false if repository and repository.there_is_a_git(): @@ -95,7 +96,7 @@ func update(): item.label = file_path item.connect("clicked", self, "item_clicked") item.status = get_file_status(file_path, repository.shell, 0) - grid.add_child(item) + #grid.add_child(item) #if item.status != item.IconStatus.NONE: # is_visible = true #visible = is_visible diff --git a/scenes/file_browser.tscn b/scenes/file_browser.tscn index 844953d..9182675 100644 --- a/scenes/file_browser.tscn +++ b/scenes/file_browser.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://scenes/file_browser.gd" type="Script" id=1] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] [ext_resource path="res://styles/theme.tres" type="Theme" id=3] +[ext_resource path="res://scenes/item.tscn" type="PackedScene" id=6] [node name="FileBrowser" type="Control" groups=[ "editors", @@ -52,41 +53,30 @@ align = 1 [node name="Breadcrumbs" type="HBoxContainer" parent="Panel/Margin/Rows"] visible = false -margin_right = 1856.0 -margin_bottom = 50.0 +margin_top = 29.0 +margin_right = 1904.0 +margin_bottom = 79.0 rect_min_size = Vector2( 0, 50 ) custom_constants/separation = 8 [node name="Button" type="Button" parent="Panel/Margin/Rows/Breadcrumbs"] -margin_right = 55.0 +margin_right = 61.0 margin_bottom = 50.0 text = "root" [node name="Button2" type="Button" parent="Panel/Margin/Rows/Breadcrumbs"] -margin_left = 63.0 -margin_right = 104.0 +margin_left = 69.0 +margin_right = 114.0 margin_bottom = 50.0 text = "dir" -[node name="Scroll" type="ScrollContainer" parent="Panel/Margin/Rows"] +[node name="World" type="Control" parent="Panel/Margin/Rows"] margin_top = 29.0 margin_right = 1904.0 margin_bottom = 1064.0 size_flags_horizontal = 3 size_flags_vertical = 3 -[node name="Grid" type="GridContainer" parent="Panel/Margin/Rows/Scroll"] -margin_right = 1904.0 -margin_bottom = 1035.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -custom_constants/vseparation = 16 -custom_constants/hseparation = 16 -columns = 4 -__meta__ = { -"_edit_use_anchors_": false -} - [node name="TextEdit" type="TextEdit" parent="Panel"] visible = false anchor_right = 1.0 @@ -131,5 +121,10 @@ __meta__ = { [node name="PopupMenu" type="PopupMenu" parent="."] margin_right = 20.0 margin_bottom = 20.0 + +[node name="You" parent="." instance=ExtResource( 6 )] +position = Vector2( 175.746, 148.807 ) +status = 5 +label = "me" [connection signal="pressed" from="Panel/TextEdit/SaveButton" to="." method="save"] [connection signal="pressed" from="Panel/TextEdit/CloseButton" to="." method="close"] diff --git a/scenes/item.gd b/scenes/item.gd new file mode 100644 index 0000000..34b3dab --- /dev/null +++ b/scenes/item.gd @@ -0,0 +1,49 @@ +extends Node2D + +enum IconStatus {NONE, NEW, REMOVED, CONFLICT, EDIT, UNTRACKED} +export(IconStatus) var status setget _set_status +export var label: String setget _set_label +var type = "file" + +onready var label_node = $Label +onready var status_icon = $Status + +func _ready(): + _set_label(label) + _set_status(status) + #$PopupMenu.add_item("Delete file", 0) + +func _set_label(new_label): + label = new_label + if label_node: + label_node.text = helpers.abbreviate(new_label, 30) + +#func _gui_input(event): +# if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT: +# emit_signal("clicked", self) +# if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_RIGHT and status != IconStatus.REMOVED: +# $PopupMenu.set_position(get_global_mouse_position()) +# $PopupMenu.popup() + +func _set_status(new_status): + if status_icon: + match new_status: + IconStatus.NEW: + status_icon.texture = preload("res://images/new.svg") + status_icon.modulate = Color("33BB33") + IconStatus.REMOVED: + status_icon.texture = preload("res://images/removed.svg") + status_icon.modulate = Color("D10F0F") + IconStatus.CONFLICT: + status_icon.texture = preload("res://images/conflict.svg") + status_icon.modulate = Color("DE5E09") + IconStatus.EDIT: + status_icon.texture = preload("res://images/modified.svg") + status_icon.modulate = Color("344DED") + IconStatus.UNTRACKED: + status_icon.texture = preload("res://images/untracked.svg") + status_icon.modulate = Color("9209B8") + IconStatus.NONE: + status_icon.texture = null + + status = new_status diff --git a/scenes/item.tscn b/scenes/item.tscn new file mode 100644 index 0000000..17d24d8 --- /dev/null +++ b/scenes/item.tscn @@ -0,0 +1,28 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://nodes/head.svg" type="Texture" id=1] +[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] +[ext_resource path="res://scenes/item.gd" type="Script" id=3] + +[node name="Item" type="Node2D"] +script = ExtResource( 3 ) + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 0.763641, 1.03008 ) +scale = Vector2( 0.700258, 0.700258 ) +texture = ExtResource( 1 ) + +[node name="Label" type="Label" parent="."] +margin_left = -63.2723 +margin_top = 42.4548 +margin_right = 62.7277 +margin_bottom = 71.4548 +custom_fonts/font = ExtResource( 2 ) +text = "you" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Status" type="Sprite" parent="."] +position = Vector2( 34.3633, -34.3633 ) diff --git a/scenes/main.tscn b/scenes/main.tscn index 7cf970e..0c9bfb5 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -84,7 +84,7 @@ custom_constants/separation = 8 [node name="LevelInfo" type="VBoxContainer" parent="Rows/Columns/RightSide"] margin_right = 633.0 -margin_bottom = 383.0 +margin_bottom = 387.0 size_flags_horizontal = 3 size_flags_vertical = 3 custom_constants/separation = 8 @@ -149,7 +149,7 @@ __meta__ = { [node name="LevelPanel" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"] margin_top = 47.0 margin_right = 633.0 -margin_bottom = 383.0 +margin_bottom = 387.0 size_flags_vertical = 3 [node name="LevelName" type="RichTextLabel" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"] @@ -165,7 +165,7 @@ __meta__ = { [node name="Text" type="Control" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"] margin_right = 633.0 -margin_bottom = 336.0 +margin_bottom = 340.0 size_flags_vertical = 3 [node name="LevelDescription" type="RichTextLabel" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel/Text"] @@ -192,6 +192,7 @@ __meta__ = { } [node name="Index" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )] +visible = false anchor_right = 0.0 anchor_bottom = 0.0 margin_top = 391.0 @@ -205,11 +206,10 @@ mode = 2 [node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )] anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 590.0 +margin_top = 395.0 margin_right = 633.0 margin_bottom = 782.0 size_flags_vertical = 3 -size_flags_stretch_ratio = 0.5 title = "Current environment" [node name="Controls" type="HBoxContainer" parent="Rows"]