mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-03 19:04:40 +01:00
Make drop areas react to collision with "cursor" scene
This is a preparation to allow drop areas on GUI elements.
This commit is contained in:
parent
f6c7ef90d8
commit
38faac5485
10 changed files with 53 additions and 12 deletions
|
@ -63,5 +63,10 @@
|
|||
"id": "bisect-bad",
|
||||
"command": "git bisect bad",
|
||||
"description": "State that the current commit is bad! When you're automatically transferred, keep playing the `good` and `bad` cards!"
|
||||
},
|
||||
{
|
||||
"id": "add",
|
||||
"command": "git add [file]",
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
|
|
|
@ -106,9 +106,14 @@ func move_back():
|
|||
|
||||
func dropped_on(other):
|
||||
if "[" in command:
|
||||
var argument = other.id
|
||||
if (command.begins_with("git checkout") or command.begins_with("git rebase")) and other.id.begins_with("refs/heads"):
|
||||
argument = Array(other.id.split("/")).pop_back()
|
||||
var argument
|
||||
if other.type == "file":
|
||||
argument = other.label
|
||||
else:
|
||||
argument = other.id
|
||||
|
||||
if (command.begins_with("git checkout") or command.begins_with("git rebase")) and argument.begins_with("refs/heads"):
|
||||
argument = Array(argument.split("/")).pop_back()
|
||||
|
||||
var arg_regex = RegEx.new()
|
||||
arg_regex.compile("\\[(.*)\\]")
|
||||
|
|
4
scenes/cursor.gd
Normal file
4
scenes/cursor.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends Node2D
|
||||
|
||||
func _process(delta):
|
||||
global_position = get_global_mouse_position()
|
|
@ -6,10 +6,10 @@ var highlighted = false setget _set_highlighted
|
|||
func _ready():
|
||||
_set_highlighted(false)
|
||||
|
||||
func _mouse_entered():
|
||||
func _mouse_entered(_area):
|
||||
hovered = true
|
||||
|
||||
func _mouse_exited():
|
||||
func _mouse_exited(_area):
|
||||
hovered = false
|
||||
|
||||
func _input(event):
|
||||
|
|
|
@ -10,10 +10,13 @@ radius = 23.5871
|
|||
"drop_areas",
|
||||
]]
|
||||
position = Vector2( -0.197731, 0.0673599 )
|
||||
z_index = -2
|
||||
z_index = 2
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
input_pickable = false
|
||||
collision_layer = 0
|
||||
collision_mask = 524288
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
shape = SubResource( 1 )
|
||||
|
@ -25,5 +28,5 @@ modulate = Color( 0.847059, 0.788235, 0.996078, 0.533333 )
|
|||
position = Vector2( 0.177797, -0.65835 )
|
||||
scale = Vector2( 1.23678, 1.23678 )
|
||||
texture = ExtResource( 2 )
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_mouse_exited"]
|
||||
[connection signal="area_entered" from="Area2D" to="." method="_mouse_entered"]
|
||||
[connection signal="area_exited" from="Area2D" to="." method="_mouse_exited"]
|
||||
|
|
|
@ -46,12 +46,12 @@ func update():
|
|||
# The last entry is an empty string, remove it.
|
||||
files.pop_back()
|
||||
files.sort_custom(self, "very_best_sort")
|
||||
visible = false
|
||||
var is_visible = false
|
||||
for file_path in files:
|
||||
file_path = file_path.substr(2)
|
||||
if file_path.substr(0, 5) == ".git/":
|
||||
continue
|
||||
visible = true
|
||||
is_visible = true
|
||||
var item = preload("res://scenes/file_browser_item.tscn").instance()
|
||||
item.label = file_path
|
||||
item.connect("clicked", self, "item_clicked")
|
||||
|
@ -59,6 +59,8 @@ func update():
|
|||
item.status = get_file_status(file_path, shell, 1)
|
||||
|
||||
grid.add_child(item)
|
||||
visible = is_visible
|
||||
|
||||
FileBrowserMode.COMMIT:
|
||||
if commit:
|
||||
var files = Array(commit.repository.shell.run("git ls-tree --name-only -r %s" % commit.id).split("\n"))
|
||||
|
@ -70,6 +72,7 @@ func update():
|
|||
item.connect("clicked", self, "item_clicked")
|
||||
grid.add_child(item)
|
||||
FileBrowserMode.INDEX:
|
||||
var is_visible = false
|
||||
if repository and repository.there_is_a_git():
|
||||
var files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n"))
|
||||
# The last entry is an empty string, remove it.
|
||||
|
@ -80,6 +83,9 @@ func update():
|
|||
item.connect("clicked", self, "item_clicked")
|
||||
item.status = get_file_status(file_path, repository.shell, 0)
|
||||
grid.add_child(item)
|
||||
if item.status != item.IconStatus.NONE:
|
||||
is_visible = true
|
||||
visible = is_visible
|
||||
|
||||
func get_file_status(file_path, shell, idx):
|
||||
var file_status = shell.run("git status -s '%s'" % file_path)
|
||||
|
|
|
@ -6,6 +6,7 @@ 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
|
||||
var type = "file"
|
||||
|
||||
onready var label_node = $VBoxContainer/Label
|
||||
onready var status_icon = $VBoxContainer/Control/TextureRect/StatusIcon
|
||||
|
|
|
@ -10,6 +10,7 @@ anchor_bottom = 0.126
|
|||
margin_right = 0.319992
|
||||
margin_bottom = -0.0800018
|
||||
rect_min_size = Vector2( 175, 150 )
|
||||
mouse_filter = 1
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
|
|
@ -21,7 +21,7 @@ func load(path):
|
|||
title = config.get("title", slug)
|
||||
description = config.get("description", "(no description)")
|
||||
congrats = config.get("congrats", "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next level'.")
|
||||
cards = Array(config.get("cards", "checkout commit-auto merge rebase rebase-interactive reset-hard cherry-pick").split(" "))
|
||||
cards = Array(config.get("cards", "checkout commit-auto merge rebase rebase-interactive reset-hard cherry-pick add").split(" "))
|
||||
|
||||
var keys = config.keys()
|
||||
var repo_setups = []
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=10 format=2]
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/terminal.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://scenes/main.gd" type="Script" id=2]
|
||||
|
@ -8,6 +8,7 @@
|
|||
[ext_resource path="res://styles/theme.tres" type="Theme" id=6]
|
||||
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=7]
|
||||
[ext_resource path="res://sounds/success.wav" type="AudioStream" id=8]
|
||||
[ext_resource path="res://scenes/cursor.gd" type="Script" id=9]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
content_margin_left = 10.0
|
||||
|
@ -20,6 +21,9 @@ corner_radius_top_right = 3
|
|||
corner_radius_bottom_right = 3
|
||||
corner_radius_bottom_left = 3
|
||||
|
||||
[sub_resource type="CircleShape2D" id=2]
|
||||
radius = 1.0
|
||||
|
||||
[node name="Main" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -235,6 +239,18 @@ size_flags_vertical = 3
|
|||
[node name="SuccessSound" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 8 )
|
||||
volume_db = -10.0
|
||||
|
||||
[node name="Cursor" type="Node2D" parent="."]
|
||||
position = Vector2( 68.6342, 59.1206 )
|
||||
script = ExtResource( 9 )
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="Cursor"]
|
||||
input_pickable = false
|
||||
collision_layer = 524288
|
||||
collision_mask = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Cursor/Area2D"]
|
||||
shape = SubResource( 2 )
|
||||
[connection signal="button_down" from="Rows/Columns/RightSide/LevelInfo/Menu/ChapterSelect" to="." method="repopulate_chapters"]
|
||||
[connection signal="button_down" from="Rows/Columns/RightSide/LevelInfo/Menu/LevelSelect" to="." method="repopulate_levels"]
|
||||
[connection signal="pressed" from="Rows/Columns/RightSide/LevelInfo/Menu/ReloadButton" to="." method="reload_level"]
|
||||
|
|
Loading…
Reference in a new issue