Add progress bar to Sink
This commit is contained in:
+47
-28
@@ -1,40 +1,59 @@
|
||||
extends StaticBody3D
|
||||
|
||||
const plate_wash_time: float = 3.0
|
||||
@export var plate_scene : PackedScene
|
||||
@export_range(0.0, 10.0, 0.1) var wash_speed: float = 1.0
|
||||
|
||||
@onready var snap_zone: XRToolsSnapZone = $XRToolsSnapZone
|
||||
@onready var progress_bar: ProgressBar3D = $ProgressBar3D
|
||||
|
||||
var progress: float = 0.0
|
||||
var time_washed: float = 0.0
|
||||
var is_washing: bool = false
|
||||
var plate: PlateController = null
|
||||
|
||||
func _ready() -> void:
|
||||
if not plate_scene:
|
||||
push_error("Sink is missing reference to plate scene")
|
||||
if not progress_bar or progress_bar is not ProgressBar3D:
|
||||
push_error("Sink missing reference to progressbar, or wrong type:", progress_bar)
|
||||
|
||||
snap_zone.has_picked_up.connect(_on_object_picked_up)
|
||||
snap_zone.has_dropped.connect(_on_object_dropped)
|
||||
progress_bar.override_fill_color(Color.DODGER_BLUE)
|
||||
_refresh_progress_bar()
|
||||
|
||||
|
||||
func _refresh_progress_bar() -> void:
|
||||
progress_bar.set_progress(clampf(float(time_washed) / plate_wash_time, 0.0, 1.0))
|
||||
progress_bar.set_bar_visible(is_washing)
|
||||
|
||||
|
||||
func _on_object_picked_up(_item) -> void:
|
||||
print("Sink: object picked up: ", _item)
|
||||
plate = _item.get_node_or_null("PlateController") as PlateController
|
||||
if plate:
|
||||
is_washing = plate.is_dirty
|
||||
|
||||
|
||||
func _on_object_dropped() -> void:
|
||||
print("Sink: object drop ")
|
||||
_reset_sink()
|
||||
|
||||
|
||||
func _reset_sink():
|
||||
time_washed = 0
|
||||
is_washing = false
|
||||
plate = null
|
||||
_refresh_progress_bar()
|
||||
|
||||
func complete_washing():
|
||||
plate.is_dirty = false
|
||||
_reset_sink()
|
||||
print("Sink washing complete!")
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var item = snap_zone.picked_up_object
|
||||
|
||||
if not item:
|
||||
progress = 0
|
||||
return # Exit early since there's nothing to process
|
||||
|
||||
|
||||
var plate: PlateController = item.get_node_or_null("PlateController") as PlateController
|
||||
if plate:
|
||||
# Not dirty? Nothing to wash
|
||||
if not plate.is_dirty:
|
||||
return
|
||||
|
||||
# Washing logic using the encapsulated property
|
||||
if progress >= plate_wash_time:
|
||||
plate.is_dirty = false # This automatically updates visibility and the container state!
|
||||
print("Sink washing complete!")
|
||||
else:
|
||||
progress += wash_speed * delta
|
||||
print("Sink washing plate: ", progress)
|
||||
|
||||
# Sink empty, reset progress
|
||||
if not snap_zone.picked_up_object:
|
||||
progress = 0
|
||||
if is_washing:
|
||||
time_washed += wash_speed * delta
|
||||
_refresh_progress_bar()
|
||||
print("Sink washing plate: ", time_washed)
|
||||
|
||||
if time_washed >= plate_wash_time:
|
||||
complete_washing()
|
||||
|
||||
+6
-4
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://byh5j25mwt3oc" path="res://Stations/sink.gd" id="1_7hh4b"]
|
||||
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="2_3ocod"]
|
||||
[ext_resource type="PackedScene" uid="uid://bp3v1jl8pctro" path="res://Containers/plate.tscn" id="2_ai6d4"]
|
||||
[ext_resource type="PackedScene" uid="uid://bxbocxdaayvwx" path="res://UI/progress_bar.tscn" id="4_1pinr"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
|
||||
|
||||
@@ -16,7 +16,6 @@ properties/0/replication_mode = 1
|
||||
|
||||
[node name="Sink" type="StaticBody3D" unique_id=2055277359 groups=["station"]]
|
||||
script = ExtResource("1_7hh4b")
|
||||
plate_scene = ExtResource("2_ai6d4")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=964735164]
|
||||
shape = SubResource("BoxShape3D_24d3s")
|
||||
@@ -41,6 +40,7 @@ shape = SubResource("SphereShape3D_dlkho")
|
||||
transform = Transform3D(1.1506689, 0, 0, 0, 2.334253, 0, 0, 0, 1, 0, 1.2831618, 0.06031096)
|
||||
operation = 2
|
||||
radial_segments = 20
|
||||
smooth_faces = false
|
||||
|
||||
[node name="CSGTorus3D" type="CSGTorus3D" parent="CSGCombiner3D" unique_id=2055166617]
|
||||
transform = Transform3D(-4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0, 0.84928787, 0, 0.5107032, -0.20686007)
|
||||
@@ -81,6 +81,8 @@ transform = Transform3D(1.3113414e-07, 0.12955962, 0.99157166, 8.8817837e-16, 0.
|
||||
operation = 2
|
||||
size = Vector3(1.4033203, 1.2053223, 0.352417)
|
||||
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
|
||||
root_path = NodePath("..")
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="." unique_id=1601242574]
|
||||
replication_config = SubResource("SceneReplicationConfig_np_sink")
|
||||
|
||||
[node name="ProgressBar3D" parent="." unique_id=654673176 instance=ExtResource("4_1pinr")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8164611, -0.035980098)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
[gd_scene format=3 uid="uid://bxbocxdaayvwx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bv7oracwmgre8" path="res://UI/progress_bar_3d.gd" id="1_ng8tm"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_copv3"]
|
||||
viewport_path = NodePath("Sprite3D/SubViewport")
|
||||
|
||||
[node name="ProgressBar3D" type="Node3D" unique_id=654673176]
|
||||
script = ExtResource("1_ng8tm")
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="." unique_id=1484008334]
|
||||
pixel_size = 0.002
|
||||
|
||||
Reference in New Issue
Block a user