summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Start.gd56
-rw-r--r--Start.tscn4
-rw-r--r--Tray.gd4
-rw-r--r--Tray.tscn7
-rw-r--r--TrayItem.gd2
-rw-r--r--export_presets.cfg37
-rw-r--r--project.godot5
8 files changed, 107 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 4709183..fd2bfce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
# Godot 4+ specific ignores
.godot/
+.build/
diff --git a/Start.gd b/Start.gd
index e7b0896..2ae2895 100644
--- a/Start.gd
+++ b/Start.gd
@@ -1,21 +1,47 @@
extends Node2D
+static var can_drag = true # necessary because separate CanvasLayers
+var is_dragging = false
var drag_anchor = Vector2(0,0)
+var is_touch_drag = false
+var last_touch_distance = 0
+var last_touch_first = null
+var last_touch_second = null
+var current_touch_distance = 0
+
# todo: set camera base limit and adjust based on zoom
func _input(event):
+ # open / close Tray
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()
+ # drag screen
+ if can_drag and event.is_action_pressed("drag_screen"):
+ var query1 = PhysicsPointQueryParameters2D.new()
+ query1.collide_with_areas = true
+ query1.position = get_global_mouse_position()
+ query1.canvas_instance_id = $Map.get_instance_id()
+ var collision1 = get_world_2d().direct_space_state.intersect_point(query1)
+ var query2 = PhysicsPointQueryParameters2D.new()
+ query2.collide_with_areas = true
+ query2.position = get_global_mouse_position()
+ query2.canvas_instance_id = $Menu.get_instance_id()
+ var collision2 = get_world_2d().direct_space_state.intersect_point(query2)
+ # todo: figure out how to collide with Tray (solved by can_drag currently)
+ if not collision1 and not collision2:
+ drag_anchor = get_global_mouse_position()
+ is_dragging = true
+ elif event.is_action_released("drag_screen"):
+ is_dragging = false
+ # zoom screen
if event is InputEventMouseButton:
if event.is_pressed():
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
@@ -24,10 +50,34 @@ func _input(event):
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
var zoom = max(%Viewport/Camera2D.zoom.x - 0.1, 1)
%Viewport/Camera2D.zoom = Vector2(zoom, zoom)
+
+ # touch magnify/pan until https://github.com/godotengine/godot/issues/13139
+ if event is InputEventScreenTouch and event.index == 1:
+ if event.is_pressed():
+ is_touch_drag = true
+ else:
+ is_touch_drag = false
+ last_touch_first = null
+ last_touch_second = null
+ if event is InputEventScreenDrag:
+ if event.index == 0:
+ last_touch_first = event
+ elif event.index == 1:
+ last_touch_second = event
+ if is_touch_drag and last_touch_first and last_touch_second:
+ current_touch_distance = last_touch_first.position.distance_to(last_touch_second.position)
+ if last_touch_distance != 0:
+ if current_touch_distance > last_touch_distance:
+ var zoom = min(%Viewport/Camera2D.zoom.x + 0.1, 2)
+ %Viewport/Camera2D.zoom = Vector2(zoom, zoom)
+ elif current_touch_distance < last_touch_distance:
+ var zoom = max(%Viewport/Camera2D.zoom.x - 0.1, 1)
+ %Viewport/Camera2D.zoom = Vector2(zoom, zoom)
+ last_touch_distance = current_touch_distance
func _process(_delta):
- if Input.is_action_pressed("drag_screen"):
+ if can_drag and is_dragging:
%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)
diff --git a/Start.tscn b/Start.tscn
index bf80f1b..69324fc 100644
--- a/Start.tscn
+++ b/Start.tscn
@@ -17,7 +17,7 @@ anchors_preset = 11
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
-offset_left = -4.0
+offset_left = -100.0
grow_horizontal = 0
grow_vertical = 2
size_flags_vertical = 3
@@ -32,7 +32,7 @@ layer = -2
follow_viewport_enabled = true
[node name="Sprite2D" type="Sprite2D" parent="Map"]
-position = Vector2(474, 65)
+position = Vector2(466, 56)
scale = Vector2(29.75, 25.875)
texture = ExtResource("4_kyq1e")
diff --git a/Tray.gd b/Tray.gd
index 2ff15a9..9936ef1 100644
--- a/Tray.gd
+++ b/Tray.gd
@@ -46,8 +46,8 @@ func _on_resized():
var shape = RectangleShape2D.new()
shape.size = size
- $Area2D/CollisionShape2D.shape = shape
- $Area2D/CollisionShape2D.position = size / 2
+ %TrayCollision/CollisionShape2D.shape = shape
+ %TrayCollision/CollisionShape2D.position = size / 2
func _on_button_pressed():
diff --git a/Tray.tscn b/Tray.tscn
index e0cb6ba..9a4765b 100644
--- a/Tray.tscn
+++ b/Tray.tscn
@@ -52,9 +52,12 @@ size_flags_horizontal = 0
size_flags_vertical = 0
text = "<"
-[node name="Area2D" type="Area2D" parent="."]
+[node name="TrayCollision" type="Area2D" parent="."]
+unique_name_in_owner = true
+collision_layer = 3
+collision_mask = 3
-[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
+[node name="CollisionShape2D" type="CollisionShape2D" parent="TrayCollision"]
[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 a6ffcaa..2cdb5f2 100644
--- a/TrayItem.gd
+++ b/TrayItem.gd
@@ -19,9 +19,11 @@ func _ready():
func _on_gui_input(event: InputEvent):
if event.is_action_pressed("drag_start"):
+ get_tree().current_scene.can_drag = false
preview = object.duplicate()
preview.drag_start()
get_tree().current_scene.get_node("%DropTarget").add_child(preview)
if event.is_action_released("drag_start"):
+ get_tree().current_scene.can_drag = true
preview.drag_end()
preview = null
diff --git a/export_presets.cfg b/export_presets.cfg
new file mode 100644
index 0000000..542cb18
--- /dev/null
+++ b/export_presets.cfg
@@ -0,0 +1,37 @@
+[preset.0]
+
+name="Web"
+platform="Web"
+runnable=true
+dedicated_server=false
+custom_features=""
+export_filter="all_resources"
+include_filter=""
+exclude_filter=""
+export_path=".build/CityBuilder.html"
+encryption_include_filters=""
+encryption_exclude_filters=""
+encrypt_pck=false
+encrypt_directory=false
+
+[preset.0.options]
+
+custom_template/debug=""
+custom_template/release=""
+variant/extensions_support=false
+vram_texture_compression/for_desktop=true
+vram_texture_compression/for_mobile=false
+html/export_icon=true
+html/custom_html_shell=""
+html/head_include=""
+html/canvas_resize_policy=2
+html/focus_canvas_on_start=true
+html/experimental_virtual_keyboard=false
+progressive_web_app/enabled=false
+progressive_web_app/offline_page=""
+progressive_web_app/display=1
+progressive_web_app/orientation=0
+progressive_web_app/icon_144x144=""
+progressive_web_app/icon_180x180=""
+progressive_web_app/icon_512x512=""
+progressive_web_app/background_color=Color(0, 0, 0, 1)
diff --git a/project.godot b/project.godot
index 88afd2d..2f94abc 100644
--- a/project.godot
+++ b/project.godot
@@ -26,6 +26,7 @@ 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)
+, 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(99, 20),"global_position":Vector2(103, 61),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
rotate_start={
@@ -34,6 +35,10 @@ rotate_start={
]
}
+[input_devices]
+
+pointing/android/enable_pan_and_scale_gestures=true
+
[rendering]
renderer/rendering_method="gl_compatibility"