summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-05-12 12:38:10 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-05-12 12:38:10 +0200
commitf5593483ba906b66779cb4466a7f2c5b2ed004a8 (patch)
tree361c71e6318d1e83f9afcaa40aaddac5c190b240
parent7f3caaf1a254880b86bb4706f36505514c0a24d4 (diff)
screen drag + visible object collision shapes
-rw-r--r--Assets/wooden_bench/32x32/bench-wood-2.pngbin0 -> 1258 bytes
-rw-r--r--Assets/wooden_bench/32x32/bench-wood-2.png.import34
-rw-r--r--Objects/BuilderObject.gd10
-rw-r--r--Objects/BuilderObject.tscn14
-rw-r--r--Start.gd35
-rw-r--r--Start.tscn42
-rw-r--r--Tray.gd46
-rw-r--r--Tray.tscn56
-rw-r--r--TrayItem.gd11
-rw-r--r--TrayItem.tscn40
-rw-r--r--project.godot6
11 files changed, 263 insertions, 31 deletions
diff --git a/Assets/wooden_bench/32x32/bench-wood-2.png b/Assets/wooden_bench/32x32/bench-wood-2.png
new file mode 100644
index 0000000..a34994a
--- /dev/null
+++ b/Assets/wooden_bench/32x32/bench-wood-2.png
Binary files differ
diff --git a/Assets/wooden_bench/32x32/bench-wood-2.png.import b/Assets/wooden_bench/32x32/bench-wood-2.png.import
new file mode 100644
index 0000000..23f6b70
--- /dev/null
+++ b/Assets/wooden_bench/32x32/bench-wood-2.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bil1toethjbpb"
+path="res://.godot/imported/bench-wood-2.png-06d1ab0f1623f7e808baa388482eb32f.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://Assets/wooden_bench/32x32/bench-wood-2.png"
+dest_files=["res://.godot/imported/bench-wood-2.png-06d1ab0f1623f7e808baa388482eb32f.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/Objects/BuilderObject.gd b/Objects/BuilderObject.gd
index 04ff0b8..2be50da 100644
--- a/Objects/BuilderObject.gd
+++ b/Objects/BuilderObject.gd
@@ -9,6 +9,10 @@ var mouse_offset = Vector2(0,0)
var last_position = Vector2(0,0)
+func _ready():
+ $CollisionShape.texture.width = $Area2D/CollisionShape2D.shape.size.x
+
+
func _process(_delta):
if is_dragged:
position = get_global_mouse_position() + mouse_offset
@@ -44,6 +48,6 @@ func _on_area_2d_area_entered(_area):
func _on_area_2d_area_exited(_area):
- if $Area2D.get_overlapping_areas().size() == 0:
- is_colliding = false
- modulate = Color("fff")
+ #if $Area2D.get_overlapping_areas().size() == 0:
+ is_colliding = false
+ modulate = Color("fff")
diff --git a/Objects/BuilderObject.tscn b/Objects/BuilderObject.tscn
index aae66c7..749ad2a 100644
--- a/Objects/BuilderObject.tscn
+++ b/Objects/BuilderObject.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=4 format=3 uid="uid://p0ay1mp7v772"]
+[gd_scene load_steps=6 format=3 uid="uid://p0ay1mp7v772"]
[ext_resource type="Script" path="res://Objects/BuilderObject.gd" id="1_wjk1m"]
[ext_resource type="Texture2D" uid="uid://dfjrmruj2mk0n" path="res://Assets/wooden_bench/32x32/bench-wood.png" id="2_hvvj8"]
@@ -6,6 +6,13 @@
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vqo4b"]
size = Vector2(80, 64)
+[sub_resource type="Gradient" id="Gradient_yqbes"]
+offsets = PackedFloat32Array(0, 0.753247)
+colors = PackedColorArray(0.236458, 0.753008, 0.820768, 1, 0.755346, 0.317619, 0.61568, 1)
+
+[sub_resource type="GradientTexture2D" id="GradientTexture2D_lc0p3"]
+gradient = SubResource("Gradient_yqbes")
+
[node name="BuilderObject" type="Node2D"]
script = ExtResource("1_wjk1m")
@@ -16,6 +23,11 @@ collision_mask = 3
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_vqo4b")
+[node name="CollisionShape" type="Sprite2D" parent="."]
+self_modulate = Color(1, 1, 1, 0.490196)
+position = Vector2(-1.90735e-06, 0)
+texture = SubResource("GradientTexture2D_lc0p3")
+
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_hvvj8")
region_enabled = true
diff --git a/Start.gd b/Start.gd
new file mode 100644
index 0000000..e7b0896
--- /dev/null
+++ b/Start.gd
@@ -0,0 +1,35 @@
+extends Node2D
+
+
+var drag_anchor = Vector2(0,0)
+
+# todo: set camera base limit and adjust based on zoom
+
+
+func _input(event):
+ if event.is_action_pressed("ui_cancel"):
+ if %Tray.is_open:
+ %Tray.close()
+ else:
+ %Tray.open()
+
+ if event.is_action_pressed("drag_screen"):
+ drag_anchor = get_global_mouse_position()
+
+ if event is InputEventMouseButton:
+ if event.is_pressed():
+ if event.button_index == MOUSE_BUTTON_WHEEL_UP:
+ var zoom = min(%Viewport/Camera2D.zoom.x + 0.1, 2)
+ %Viewport/Camera2D.zoom = Vector2(zoom, zoom)
+ if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
+ var zoom = max(%Viewport/Camera2D.zoom.x - 0.1, 1)
+ %Viewport/Camera2D.zoom = Vector2(zoom, zoom)
+
+
+func _process(_delta):
+ if Input.is_action_pressed("drag_screen"):
+ %Viewport.position += drag_anchor - get_global_mouse_position()
+ %Viewport.position.x = min(%Viewport.position.x, %Viewport/Camera2D.limit_right - get_viewport_rect().size.x/2)
+ %Viewport.position.x = max(%Viewport.position.x, %Viewport/Camera2D.limit_left + get_viewport_rect().size.x/2)
+ %Viewport.position.y = min(%Viewport.position.y, %Viewport/Camera2D.limit_bottom - get_viewport_rect().size.y/2)
+ %Viewport.position.y = max(%Viewport.position.y, %Viewport/Camera2D.limit_top + get_viewport_rect().size.y/2)
diff --git a/Start.tscn b/Start.tscn
index 560eb9b..bf80f1b 100644
--- a/Start.tscn
+++ b/Start.tscn
@@ -1,16 +1,17 @@
-[gd_scene load_steps=3 format=3 uid="uid://bdyngwtm3rowr"]
+[gd_scene load_steps=5 format=3 uid="uid://bdyngwtm3rowr"]
+[ext_resource type="Script" path="res://Start.gd" id="1_k0odd"]
[ext_resource type="PackedScene" uid="uid://p0ay1mp7v772" path="res://Objects/BuilderObject.tscn" id="3_skats"]
[ext_resource type="PackedScene" uid="uid://3vuctgbcjqi7" path="res://Tray.tscn" id="3_u4wpj"]
+[ext_resource type="Texture2D" uid="uid://djasmoqj87h1r" path="res://icon.svg" id="4_kyq1e"]
[node name="Start" type="Node2D"]
+script = ExtResource("1_k0odd")
-[node name="BuilderObject" parent="." instance=ExtResource("3_skats")]
-position = Vector2(155, 109)
-
-[node name="CanvasLayer" type="CanvasLayer" parent="."]
+[node name="Menu" type="CanvasLayer" parent="."]
+layer = -1
-[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer"]
+[node name="HBoxContainer" type="HBoxContainer" parent="Menu"]
custom_minimum_size = Vector2(80, 0)
anchors_preset = 11
anchor_left = 1.0
@@ -21,7 +22,32 @@ grow_horizontal = 0
grow_vertical = 2
size_flags_vertical = 3
-[node name="Tray" parent="CanvasLayer/HBoxContainer" instance=ExtResource("3_u4wpj")]
+[node name="Tray" parent="Menu/HBoxContainer" instance=ExtResource("3_u4wpj")]
+unique_name_in_owner = true
layout_mode = 2
-size_flags_horizontal = 3
size_flags_stretch_ratio = 0.1
+
+[node name="Map" type="CanvasLayer" parent="."]
+layer = -2
+follow_viewport_enabled = true
+
+[node name="Sprite2D" type="Sprite2D" parent="Map"]
+position = Vector2(474, 65)
+scale = Vector2(29.75, 25.875)
+texture = ExtResource("4_kyq1e")
+
+[node name="DropTarget" type="Node2D" parent="Map"]
+unique_name_in_owner = true
+
+[node name="BuilderObject" parent="Map/DropTarget" instance=ExtResource("3_skats")]
+position = Vector2(155, 109)
+
+[node name="Viewport" type="Node2D" parent="."]
+unique_name_in_owner = true
+
+[node name="Camera2D" type="Camera2D" parent="Viewport"]
+limit_left = -1440
+limit_top = -1601
+limit_right = 2400
+limit_bottom = 1700
+editor_draw_limits = true
diff --git a/Tray.gd b/Tray.gd
index 136cf55..2ff15a9 100644
--- a/Tray.gd
+++ b/Tray.gd
@@ -1,15 +1,57 @@
-extends VBoxContainer
+extends Control
var TrayItemScene = preload("res://TrayItem.tscn")
+var is_open = true
+
-# Called when the node enters the scene tree for the first time.
func _ready():
for i in range(5):
add_item()
+
+ await get_tree().process_frame
+ _on_resized()
func add_item():
var tray_item = TrayItemScene.instantiate()
%Items.add_child(tray_item)
+
+
+func open():
+ is_open = true
+ var tween = create_tween()
+ tween.tween_property(
+ self,
+ "global_position",
+ Vector2(get_viewport_rect().end.x - size.x, position.y),
+ 0.25
+ )
+
+
+func close():
+ is_open = false
+ var tween = create_tween()
+ tween.tween_property(
+ self,
+ "global_position",
+ Vector2(get_viewport_rect().end.x, position.y),
+ 0.25
+ )
+
+
+func _on_resized():
+ %Button.global_position = global_position - Vector2(%Button.size.x, 0)
+
+ var shape = RectangleShape2D.new()
+ shape.size = size
+ $Area2D/CollisionShape2D.shape = shape
+ $Area2D/CollisionShape2D.position = size / 2
+
+
+func _on_button_pressed():
+ if is_open:
+ close()
+ else:
+ open()
diff --git a/Tray.tscn b/Tray.tscn
index 18f8310..e0cb6ba 100644
--- a/Tray.tscn
+++ b/Tray.tscn
@@ -1,24 +1,60 @@
-[gd_scene load_steps=2 format=3 uid="uid://3vuctgbcjqi7"]
+[gd_scene load_steps=3 format=3 uid="uid://3vuctgbcjqi7"]
[ext_resource type="Script" path="res://Tray.gd" id="1_lo4w7"]
-[node name="Tray" type="VBoxContainer"]
-anchors_preset = 11
-anchor_left = 1.0
-anchor_right = 1.0
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_33t84"]
+bg_color = Color(0.133333, 0.133333, 0.133333, 1)
+
+[node name="Tray" type="PanelContainer"]
+custom_minimum_size = Vector2(100, 0)
+anchors_preset = 9
anchor_bottom = 1.0
-offset_left = -80.0
-grow_horizontal = 0
+offset_right = 10.0
grow_vertical = 2
size_flags_vertical = 3
+theme_override_styles/panel = SubResource("StyleBoxFlat_33t84")
script = ExtResource("1_lo4w7")
-[node name="ScrollContainer" type="ScrollContainer" parent="."]
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
+layout_mode = 2
+size_flags_horizontal = 3
+size_flags_vertical = 3
+
+[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
+layout_mode = 2
+size_flags_vertical = 3
+theme_override_constants/margin_left = 5
+theme_override_constants/margin_top = 5
+theme_override_constants/margin_right = 5
+theme_override_constants/margin_bottom = 5
+
+[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer/MarginContainer"]
layout_mode = 2
size_flags_vertical = 3
-[node name="Items" type="VBoxContainer" parent="ScrollContainer"]
+[node name="Items" type="VBoxContainer" parent="VBoxContainer/MarginContainer/ScrollContainer"]
unique_name_in_owner = true
-custom_minimum_size = Vector2(80, 0)
layout_mode = 2
+size_flags_horizontal = 3
size_flags_vertical = 3
+
+[node name="Control" type="Control" parent="."]
+layout_mode = 2
+size_flags_horizontal = 0
+size_flags_vertical = 0
+
+[node name="Button" type="Button" parent="Control"]
+unique_name_in_owner = true
+layout_mode = 0
+offset_right = 8.0
+offset_bottom = 8.0
+size_flags_horizontal = 0
+size_flags_vertical = 0
+text = "<"
+
+[node name="Area2D" type="Area2D" parent="."]
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
+
+[connection signal="resized" from="." to="." method="_on_resized"]
+[connection signal="pressed" from="Control/Button" to="." method="_on_button_pressed"]
diff --git a/TrayItem.gd b/TrayItem.gd
index 12f7041..a6ffcaa 100644
--- a/TrayItem.gd
+++ b/TrayItem.gd
@@ -8,11 +8,20 @@ extends Control
var preview: BuilderObject
+func _ready():
+ var sprite: Sprite2D = object.get_node("Sprite2D")
+ var texture = AtlasTexture.new()
+ texture.atlas = sprite.texture
+ texture.region = sprite.region_rect
+ %Image.texture = texture
+ await get_tree().process_frame
+
+
func _on_gui_input(event: InputEvent):
if event.is_action_pressed("drag_start"):
preview = object.duplicate()
preview.drag_start()
- get_tree().current_scene.add_child(preview)
+ get_tree().current_scene.get_node("%DropTarget").add_child(preview)
if event.is_action_released("drag_start"):
preview.drag_end()
preview = null
diff --git a/TrayItem.tscn b/TrayItem.tscn
index af5f535..213a34a 100644
--- a/TrayItem.tscn
+++ b/TrayItem.tscn
@@ -1,15 +1,43 @@
-[gd_scene load_steps=2 format=3 uid="uid://0hxby7k5m7b0"]
+[gd_scene load_steps=4 format=3 uid="uid://0hxby7k5m7b0"]
[ext_resource type="Script" path="res://TrayItem.gd" id="1_kkc4o"]
+[ext_resource type="Texture2D" uid="uid://bil1toethjbpb" path="res://Assets/wooden_bench/32x32/bench-wood-2.png" id="2_5x3va"]
-[node name="TrayItem" type="VBoxContainer"]
-offset_right = 40.0
-offset_bottom = 23.0
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1pc52"]
+bg_color = Color(0.6, 0.6, 0.6, 0)
+border_width_bottom = 1
+border_color = Color(1, 1, 1, 0.490196)
+
+[node name="MarginContainer" type="MarginContainer"]
+offset_right = 60.0
+offset_bottom = 112.0
+theme_override_constants/margin_top = 10
+theme_override_constants/margin_bottom = 5
script = ExtResource("1_kkc4o")
object_path = "res://Objects/BuilderObject.tscn"
-[node name="Label" type="Label" parent="."]
+[node name="PanelContainer" type="PanelContainer" parent="."]
+layout_mode = 2
+theme_override_styles/panel = SubResource("StyleBoxFlat_1pc52")
+
+[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 20
+
+[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Bank"
+horizontal_alignment = 1
+
+[node name="CenterContainer" type="CenterContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
+layout_mode = 2
+
+[node name="Image" type="TextureRect" parent="PanelContainer/MarginContainer/VBoxContainer/CenterContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+texture = ExtResource("2_5x3va")
-[connection signal="gui_input" from="." to="." method="_on_gui_input"]
+[connection signal="gui_input" from="PanelContainer" to="." method="_on_gui_input"]
diff --git a/project.godot b/project.godot
index def1ff9..8c671f6 100644
--- a/project.godot
+++ b/project.godot
@@ -22,6 +22,12 @@ drag_start={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(106, 14),"global_position":Vector2(110, 55),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
+drag_screen={
+"deadzone": 0.5,
+"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(232, 25),"global_position":Vector2(236, 66),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
+, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":4,"position":Vector2(275, 14),"global_position":Vector2(279, 55),"factor":1.0,"button_index":3,"canceled":false,"pressed":true,"double_click":false,"script":null)
+]
+}
[rendering]