From abbfc4f1d629118c36a079c1e4529bbd79cbc459 Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 24 Nov 2020 17:34:46 +0100 Subject: [PATCH] drag and drop files between invetory and world caution: breaks card drag and drop --- scenes/drop_area.gd | 27 +++++++++++++++++++++++---- scenes/file_browser.gd | 1 + scenes/file_browser.tscn | 6 +++++- scenes/item.gd | 10 ++++++++++ scenes/item.tscn | 1 + scenes/main.gd | 5 +++++ scenes/main.tscn | 18 ++++++++++++++---- 7 files changed, 59 insertions(+), 9 deletions(-) diff --git a/scenes/drop_area.gd b/scenes/drop_area.gd index 2903b34..187faaa 100644 --- a/scenes/drop_area.gd +++ b/scenes/drop_area.gd @@ -30,13 +30,19 @@ func _mouse_exited(_area): func _input(event): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT and !event.pressed: - if hovered: - if highlighted and game.dragged_object: - game.dragged_object.dropped_on(get_parent_with_type()) - dragged = false + if dragged: + for area in get_tree().get_nodes_in_group("drop_areas"): + if area.hovered: + if area.highlighted and game.dragged_object: + game.dragged_object.dropped_on(area.get_parent_with_type()) + _turn_off_highlights() + dragged = false + if event.button_index == BUTTON_LEFT and event.pressed and hovered: if get_parent().type == "file" and get_parent().item_type == "wd": dragged = true + game.dragged_object = get_parent_with_type() + _turn_on_highlights() func _set_highlighted(new_highlighted): highlighted = new_highlighted @@ -51,3 +57,16 @@ func get_parent_with_type(): func highlight(type): if get_parent_with_type().type == type: _set_highlighted(true) + +func _turn_on_highlights(): + var parent_type = get_parent_with_type().file_browser.type + var highlight_type = "inventory" + if parent_type == "inventory": + highlight_type = "world" + + for area in get_tree().get_nodes_in_group("drop_areas"): + area.highlight(highlight_type) + +func _turn_off_highlights(): + for area in get_tree().get_nodes_in_group("drop_areas"): + area.highlighted = false diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 0766bc5..5d4475f 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -8,6 +8,7 @@ enum FileBrowserMode { export(String) var title setget _set_title export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY setget _set_mode +export(String) var type = "world" var shell var commit setget _set_commit diff --git a/scenes/file_browser.tscn b/scenes/file_browser.tscn index b5b8d6d..74a31ef 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/drop_area.tscn" type="PackedScene" id=4] [node name="FileBrowser" type="Control" groups=[ "editors", @@ -124,5 +125,8 @@ __meta__ = { [node name="PopupMenu" type="PopupMenu" parent="."] margin_right = 20.0 margin_bottom = 20.0 + +[node name="DropArea" parent="." instance=ExtResource( 4 )] +position = Vector2( 121.101, 116.61 ) [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 index 586484d..6628fb6 100644 --- a/scenes/item.gd +++ b/scenes/item.gd @@ -111,3 +111,13 @@ func move(diff): write_to_file() if held: held.move(diff) + +func dropped_on(other): + #if other is + print("other type:", other.type) + if other.type == "inventory": + file_browser.shell.run("take '%s'" % label) + else: + other.shell.run("drop '%s'" % label) + file_browser.update() + other.update() diff --git a/scenes/item.tscn b/scenes/item.tscn index 5754ea7..47c6f8c 100644 --- a/scenes/item.tscn +++ b/scenes/item.tscn @@ -6,6 +6,7 @@ [ext_resource path="res://scenes/drop_area.tscn" type="PackedScene" id=4] [node name="Item" type="Node2D"] +z_index = 10 script = ExtResource( 3 ) [node name="Sprite" type="Sprite" parent="."] diff --git a/scenes/main.gd b/scenes/main.gd index db5ea71..ba57cba 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -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 cards = $Rows/Controls/Cards onready var file_browser = $Rows/Columns/RightSide/FileBrowser +onready var inventory = $Rows/Columns/RightSide/Inventory #onready var index = $Rows/Columns/RightSide/Index func _ready(): @@ -46,6 +47,10 @@ func _ready(): load_chapter(current_chapter) file_browser.grab_focus() + inventory.shell = Shell.new() + inventory.shell.cd(game.tmp_prefix + "inventory") + + func _input(event): if event.is_action_pressed("tab"): print("ha") diff --git a/scenes/main.tscn b/scenes/main.tscn index ce13e1e..84efa24 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 = 387.0 +margin_bottom = 255.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 = 387.0 +margin_bottom = 255.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 = 340.0 +margin_bottom = 208.0 size_flags_vertical = 3 [node name="LevelDescription" type="RichTextLabel" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel/Text"] @@ -194,11 +194,21 @@ __meta__ = { [node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )] anchor_right = 0.0 anchor_bottom = 0.0 -margin_top = 395.0 +margin_top = 263.0 +margin_right = 633.0 +margin_bottom = 518.0 +size_flags_vertical = 3 +title = "Current environment" + +[node name="Inventory" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )] +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_top = 526.0 margin_right = 633.0 margin_bottom = 782.0 size_flags_vertical = 3 title = "Current environment" +type = "inventory" [node name="Controls" type="HBoxContainer" parent="Rows"] margin_top = 790.0