New Item scene, in preparation for a 2D world

This commit is contained in:
blinry 2020-11-17 16:27:16 +01:00
parent 04e48a8bf2
commit e97af81c0f
5 changed files with 104 additions and 31 deletions

View file

@ -15,7 +15,7 @@ var repository
var open_file 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 text_edit = $Panel/TextEdit
onready var save_button = $Panel/TextEdit/SaveButton onready var save_button = $Panel/TextEdit/SaveButton
onready var title_label = $Panel/Margin/Rows/Title onready var title_label = $Panel/Margin/Rows/Title
@ -32,14 +32,15 @@ func _input(event):
save() save()
func clear(): func clear():
for item in grid.get_children(): pass
item.queue_free() # for item in grid.get_children():
# item.queue_free()
func substr2(s): func substr2(s):
return s.substr(2) return s.substr(2)
func update(): func update():
if grid: if true:#grid:
clear() clear()
match mode: match mode:
FileBrowserMode.WORKING_DIRECTORY: FileBrowserMode.WORKING_DIRECTORY:
@ -68,7 +69,7 @@ func update():
item.connect("deleted", self, "item_deleted") item.connect("deleted", self, "item_deleted")
item.status = get_file_status(file_path, shell, 1) item.status = get_file_status(file_path, shell, 1)
grid.add_child(item) #grid.add_child(item)
#visible = is_visible #visible = is_visible
FileBrowserMode.COMMIT: FileBrowserMode.COMMIT:
@ -80,7 +81,7 @@ func update():
var item = preload("res://scenes/file_browser_item.tscn").instance() var item = preload("res://scenes/file_browser_item.tscn").instance()
item.label = file_path item.label = file_path
item.connect("clicked", self, "item_clicked") item.connect("clicked", self, "item_clicked")
grid.add_child(item) #grid.add_child(item)
FileBrowserMode.INDEX: FileBrowserMode.INDEX:
#var is_visible = false #var is_visible = false
if repository and repository.there_is_a_git(): if repository and repository.there_is_a_git():
@ -95,7 +96,7 @@ func update():
item.label = file_path item.label = file_path
item.connect("clicked", self, "item_clicked") item.connect("clicked", self, "item_clicked")
item.status = get_file_status(file_path, repository.shell, 0) item.status = get_file_status(file_path, repository.shell, 0)
grid.add_child(item) #grid.add_child(item)
#if item.status != item.IconStatus.NONE: #if item.status != item.IconStatus.NONE:
# is_visible = true # is_visible = true
#visible = is_visible #visible = is_visible

View file

@ -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://scenes/file_browser.gd" type="Script" id=1]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2] [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://styles/theme.tres" type="Theme" id=3]
[ext_resource path="res://scenes/item.tscn" type="PackedScene" id=6]
[node name="FileBrowser" type="Control" groups=[ [node name="FileBrowser" type="Control" groups=[
"editors", "editors",
@ -52,41 +53,30 @@ align = 1
[node name="Breadcrumbs" type="HBoxContainer" parent="Panel/Margin/Rows"] [node name="Breadcrumbs" type="HBoxContainer" parent="Panel/Margin/Rows"]
visible = false visible = false
margin_right = 1856.0 margin_top = 29.0
margin_bottom = 50.0 margin_right = 1904.0
margin_bottom = 79.0
rect_min_size = Vector2( 0, 50 ) rect_min_size = Vector2( 0, 50 )
custom_constants/separation = 8 custom_constants/separation = 8
[node name="Button" type="Button" parent="Panel/Margin/Rows/Breadcrumbs"] [node name="Button" type="Button" parent="Panel/Margin/Rows/Breadcrumbs"]
margin_right = 55.0 margin_right = 61.0
margin_bottom = 50.0 margin_bottom = 50.0
text = "root" text = "root"
[node name="Button2" type="Button" parent="Panel/Margin/Rows/Breadcrumbs"] [node name="Button2" type="Button" parent="Panel/Margin/Rows/Breadcrumbs"]
margin_left = 63.0 margin_left = 69.0
margin_right = 104.0 margin_right = 114.0
margin_bottom = 50.0 margin_bottom = 50.0
text = "dir" 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_top = 29.0
margin_right = 1904.0 margin_right = 1904.0
margin_bottom = 1064.0 margin_bottom = 1064.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 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"] [node name="TextEdit" type="TextEdit" parent="Panel"]
visible = false visible = false
anchor_right = 1.0 anchor_right = 1.0
@ -131,5 +121,10 @@ __meta__ = {
[node name="PopupMenu" type="PopupMenu" parent="."] [node name="PopupMenu" type="PopupMenu" parent="."]
margin_right = 20.0 margin_right = 20.0
margin_bottom = 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/SaveButton" to="." method="save"]
[connection signal="pressed" from="Panel/TextEdit/CloseButton" to="." method="close"] [connection signal="pressed" from="Panel/TextEdit/CloseButton" to="." method="close"]

49
scenes/item.gd Normal file
View file

@ -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

28
scenes/item.tscn Normal file
View file

@ -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 )

View file

@ -84,7 +84,7 @@ custom_constants/separation = 8
[node name="LevelInfo" type="VBoxContainer" parent="Rows/Columns/RightSide"] [node name="LevelInfo" type="VBoxContainer" parent="Rows/Columns/RightSide"]
margin_right = 633.0 margin_right = 633.0
margin_bottom = 383.0 margin_bottom = 387.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
custom_constants/separation = 8 custom_constants/separation = 8
@ -149,7 +149,7 @@ __meta__ = {
[node name="LevelPanel" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"] [node name="LevelPanel" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"]
margin_top = 47.0 margin_top = 47.0
margin_right = 633.0 margin_right = 633.0
margin_bottom = 383.0 margin_bottom = 387.0
size_flags_vertical = 3 size_flags_vertical = 3
[node name="LevelName" type="RichTextLabel" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"] [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"] [node name="Text" type="Control" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"]
margin_right = 633.0 margin_right = 633.0
margin_bottom = 336.0 margin_bottom = 340.0
size_flags_vertical = 3 size_flags_vertical = 3
[node name="LevelDescription" type="RichTextLabel" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel/Text"] [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 )] [node name="Index" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )]
visible = false
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_top = 391.0 margin_top = 391.0
@ -205,11 +206,10 @@ mode = 2
[node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )] [node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )]
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_top = 590.0 margin_top = 395.0
margin_right = 633.0 margin_right = 633.0
margin_bottom = 782.0 margin_bottom = 782.0
size_flags_vertical = 3 size_flags_vertical = 3
size_flags_stretch_ratio = 0.5
title = "Current environment" title = "Current environment"
[node name="Controls" type="HBoxContainer" parent="Rows"] [node name="Controls" type="HBoxContainer" parent="Rows"]