mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-02 10:52:00 +03:00
Index Status Icons
This commit is contained in:
parent
3bb62a5d84
commit
a725508dc8
@ -14,6 +14,11 @@ _global_script_classes=[ {
|
|||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://scenes/chapter.gd"
|
"path": "res://scenes/chapter.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Control",
|
||||||
|
"class": "FileBrowserItem",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://scenes/file_browser_item.gd"
|
||||||
|
}, {
|
||||||
"base": "Node",
|
"base": "Node",
|
||||||
"class": "Level",
|
"class": "Level",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
@ -36,6 +41,7 @@ _global_script_classes=[ {
|
|||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"Chapter": "",
|
"Chapter": "",
|
||||||
|
"FileBrowserItem": "",
|
||||||
"Level": "",
|
"Level": "",
|
||||||
"LevelRepo": "",
|
"LevelRepo": "",
|
||||||
"Shell": "",
|
"Shell": "",
|
||||||
|
@ -55,6 +55,9 @@ 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")
|
||||||
|
|
||||||
|
item.status = get_file_status(file_path, shell, 1)
|
||||||
|
|
||||||
grid.add_child(item)
|
grid.add_child(item)
|
||||||
FileBrowserMode.COMMIT:
|
FileBrowserMode.COMMIT:
|
||||||
if commit:
|
if commit:
|
||||||
@ -67,25 +70,48 @@ func update():
|
|||||||
item.connect("clicked", self, "item_clicked")
|
item.connect("clicked", self, "item_clicked")
|
||||||
grid.add_child(item)
|
grid.add_child(item)
|
||||||
FileBrowserMode.INDEX:
|
FileBrowserMode.INDEX:
|
||||||
if repository:
|
if repository and repository.there_is_a_git():
|
||||||
var files = Array(repository.shell.run("git ls-files -s | cut -f2").split("\n"))
|
var files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n"))
|
||||||
# The last entry is an empty string, remove it.
|
# The last entry is an empty string, remove it.
|
||||||
files.pop_back()
|
files.pop_back()
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
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")
|
||||||
|
item.status = get_file_status(file_path, repository.shell, 0)
|
||||||
grid.add_child(item)
|
grid.add_child(item)
|
||||||
|
|
||||||
|
func get_file_status(file_path, shell, idx):
|
||||||
|
var file_status = shell.run("git status -s '%s'" % file_path)
|
||||||
|
if file_status.length()>0:
|
||||||
|
match file_status[idx]:
|
||||||
|
"D":
|
||||||
|
return FileBrowserItem.IconStatus.REMOVED
|
||||||
|
"M":
|
||||||
|
return FileBrowserItem.IconStatus.EDIT
|
||||||
|
"U":
|
||||||
|
return FileBrowserItem.IconStatus.CONFLICT
|
||||||
|
" ":
|
||||||
|
return FileBrowserItem.IconStatus.NONE
|
||||||
|
"A":
|
||||||
|
return FileBrowserItem.IconStatus.NEW
|
||||||
|
"?":
|
||||||
|
return FileBrowserItem.IconStatus.UNTRACKED
|
||||||
|
else:
|
||||||
|
return FileBrowserItem.IconStatus.NONE
|
||||||
|
|
||||||
func item_clicked(item):
|
func item_clicked(item):
|
||||||
open_file = item.label
|
|
||||||
match mode:
|
match mode:
|
||||||
FileBrowserMode.WORKING_DIRECTORY:
|
FileBrowserMode.WORKING_DIRECTORY:
|
||||||
text_edit.text = helpers.read_file(shell._cwd + item.label)
|
text_edit.text = helpers.read_file(shell._cwd + item.label)
|
||||||
FileBrowserMode.COMMIT:
|
FileBrowserMode.COMMIT:
|
||||||
text_edit.text = commit.repository.shell.run("git show %s:\"%s\"" % [commit.id, item.label])
|
text_edit.text = commit.repository.shell.run("git show %s:\"%s\"" % [commit.id, item.label])
|
||||||
FileBrowserMode.INDEX:
|
FileBrowserMode.INDEX:
|
||||||
|
if item.status == item.IconStatus.CONFLICT:
|
||||||
|
return
|
||||||
text_edit.text = repository.shell.run("git show :\"%s\"" % [item.label])
|
text_edit.text = repository.shell.run("git show :\"%s\"" % [item.label])
|
||||||
|
|
||||||
|
open_file = item.label
|
||||||
text_edit.show()
|
text_edit.show()
|
||||||
text_edit.grab_focus()
|
text_edit.grab_focus()
|
||||||
|
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
|
class_name FileBrowserItem
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
signal clicked(what)
|
signal clicked(what)
|
||||||
|
|
||||||
|
enum IconStatus {NONE, NEW, REMOVED, CONFLICT, EDIT, UNTRACKED}
|
||||||
|
export(IconStatus) var status setget _set_status
|
||||||
export var label: String setget _set_label
|
export var label: String setget _set_label
|
||||||
|
|
||||||
onready var label_node = $VBoxContainer/Label
|
onready var label_node = $VBoxContainer/Label
|
||||||
|
onready var status_icon = $VBoxContainer/Control/TextureRect/StatusIcon
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
_set_label(label)
|
_set_label(label)
|
||||||
|
_set_status(status)
|
||||||
|
|
||||||
func _set_label(new_label):
|
func _set_label(new_label):
|
||||||
label = new_label
|
label = new_label
|
||||||
@ -17,3 +22,27 @@ func _set_label(new_label):
|
|||||||
func _gui_input(event):
|
func _gui_input(event):
|
||||||
if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:
|
if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:
|
||||||
emit_signal("clicked", self)
|
emit_signal("clicked", self)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -53,6 +53,21 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="StatusIcon" type="TextureRect" parent="VBoxContainer/Control/TextureRect"]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
margin_left = -11.2842
|
||||||
|
margin_top = 0.810516
|
||||||
|
margin_right = 13.7158
|
||||||
|
margin_bottom = 25.8105
|
||||||
|
expand = true
|
||||||
|
stretch_mode = 6
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="VBoxContainer"]
|
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||||
margin_top = 98.0
|
margin_top = 98.0
|
||||||
margin_right = 200.0
|
margin_right = 200.0
|
||||||
|
@ -18,6 +18,7 @@ onready var level_description = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Tex
|
|||||||
onready var level_congrats = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Text/LevelCongrats
|
onready var level_congrats = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Text/LevelCongrats
|
||||||
onready var cards = $Rows/Controls/Cards
|
onready var cards = $Rows/Controls/Cards
|
||||||
onready var file_browser = $Rows/Columns/RightSide/FileBrowser
|
onready var file_browser = $Rows/Columns/RightSide/FileBrowser
|
||||||
|
onready var index = $Rows/Columns/RightSide/Index
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var args = helpers.parse_args()
|
var args = helpers.parse_args()
|
||||||
@ -83,6 +84,8 @@ func load_level(level_id):
|
|||||||
if new_repo.label == "yours":
|
if new_repo.label == "yours":
|
||||||
file_browser.shell = new_repo.shell
|
file_browser.shell = new_repo.shell
|
||||||
file_browser.update()
|
file_browser.update()
|
||||||
|
index.repository = new_repo
|
||||||
|
index.update()
|
||||||
repositories_node.add_child(new_repo)
|
repositories_node.add_child(new_repo)
|
||||||
repositories[r] = new_repo
|
repositories[r] = new_repo
|
||||||
|
|
||||||
@ -137,6 +140,7 @@ func update_repos():
|
|||||||
var repo = repositories[r]
|
var repo = repositories[r]
|
||||||
repo.update_everything()
|
repo.update_everything()
|
||||||
file_browser.update()
|
file_browser.update()
|
||||||
|
index.update()
|
||||||
|
|
||||||
if levels.chapters[current_chapter].levels[current_level].check_win():
|
if levels.chapters[current_chapter].levels[current_level].check_win():
|
||||||
show_win_status()
|
show_win_status()
|
||||||
|
@ -80,7 +80,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 = 442.0
|
margin_bottom = 383.0
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ __meta__ = {
|
|||||||
[node name="LevelPanel" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"]
|
[node name="LevelPanel" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo"]
|
||||||
margin_top = 40.0
|
margin_top = 40.0
|
||||||
margin_right = 633.0
|
margin_right = 633.0
|
||||||
margin_bottom = 442.0
|
margin_bottom = 383.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"]
|
||||||
@ -159,7 +159,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_top = 65.0
|
margin_top = 65.0
|
||||||
margin_right = 633.0
|
margin_right = 633.0
|
||||||
margin_bottom = 402.0
|
margin_bottom = 343.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"]
|
||||||
@ -185,14 +185,25 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="Index" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )]
|
||||||
|
anchor_right = 0.0
|
||||||
|
anchor_bottom = 0.0
|
||||||
|
margin_top = 391.0
|
||||||
|
margin_right = 633.0
|
||||||
|
margin_bottom = 582.0
|
||||||
|
size_flags_vertical = 3
|
||||||
|
size_flags_stretch_ratio = 0.5
|
||||||
|
title = "Next Commit:"
|
||||||
|
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 = 450.0
|
margin_top = 590.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.75
|
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"]
|
||||||
|
Loading…
Reference in New Issue
Block a user