drag and drop files between invetory and world

caution: breaks card drag and drop
This commit is contained in:
bleeptrack 2020-11-24 17:34:46 +01:00
parent c1fd2e0f45
commit abbfc4f1d6
7 changed files with 59 additions and 9 deletions

View file

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

View file

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

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://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"]

View file

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

View file

@ -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="."]

View file

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

View file

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