Add Progress bar to Hob

This commit is contained in:
JonShard
2026-07-27 10:16:44 +02:00
parent 34a649f507
commit f4b2e687b5
8 changed files with 117 additions and 21 deletions
+6 -3
View File
@@ -3,6 +3,7 @@
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="1_dlkho"]
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
size = Vector3(1, 1, 1.0517578)
[sub_resource type="SphereShape3D" id="SphereShape3D_dlkho"]
radius = 0.3
@@ -15,7 +16,8 @@ albedo_color = Color(1.1759251, 0.741115, 0.5692133, 1)
[node name="Counter" type="StaticBody3D" unique_id=1487893288 groups=["station"]]
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=692568688]
[node name="CollisionShape3DCuttingBoard" type="CollisionShape3D" parent="." unique_id=706340473]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.025878906)
shape = SubResource("BoxShape3D_24d3s")
[node name="XRToolsSnapZone" type="Area3D" parent="." unique_id=1647380272 groups=["station"]]
@@ -31,6 +33,7 @@ transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.000975132, 0)
shape = SubResource("SphereShape3D_dlkho")
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="." unique_id=451757283]
use_collision = true
[node name="CSGBox3D" type="CSGBox3D" parent="CSGCombiner3D" unique_id=305755330]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.045776367, 0)
@@ -64,8 +67,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.060837455, 0.12459713, 0.55
radius = 0.025492515
[node name="CSGBox3D6" type="CSGBox3D" parent="CSGCombiner3D" unique_id=187377667]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.060742255, 0.4885016, 0.0011152327)
size = Vector3(0.56365967, 0.092285156, 0.42160034)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.060742255, 0.51602846, 0.0011152327)
size = Vector3(0.56365967, 0.037231445, 0.42160034)
material = SubResource("StandardMaterial3D_vlqg6")
[node name="CSGBox3D6" type="CSGBox3D" parent="CSGCombiner3D/CSGBox3D6" unique_id=1146824846]
+9 -4
View File
@@ -2,8 +2,10 @@
[ext_resource type="Script" uid="uid://bsn8vhv5adxdo" path="res://Stations/hob.gd" id="1_7jc4g"]
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="2_er1dp"]
[ext_resource type="PackedScene" uid="uid://bxbocxdaayvwx" path="res://UI/progress_bar.tscn" id="3_7uuqv"]
[ext_resource type="Script" uid="uid://bv7oracwmgre8" path="res://UI/progress_bar_3d.gd" id="3_zz9kp"]
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
[sub_resource type="BoxShape3D" id="BoxShape3D_kdxnr"]
[sub_resource type="SphereShape3D" id="SphereShape3D_vlqg6"]
radius = 0.3
@@ -20,7 +22,7 @@ properties/1/replication_mode = 1
script = ExtResource("1_7jc4g")
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1283846023]
shape = SubResource("BoxShape3D_24d3s")
shape = SubResource("BoxShape3D_kdxnr")
[node name="XRToolsSnapZone" type="Area3D" parent="." unique_id=538157739]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5270121, 0)
@@ -112,6 +114,9 @@ transform = Transform3D(0.94465846, 0, 0, 0, 0.94465846, 0, 0, 0, 0.94465846, -0
operation = 2
size = Vector3(0.9842529, 0.8349304, 0.072387695)
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
root_path = NodePath("..")
[node name="Sync" type="MultiplayerSynchronizer" parent="." unique_id=768992259]
replication_config = SubResource("SceneReplicationConfig_np_hob")
[node name="ProgressBar3D" parent="." unique_id=654673176 instance=ExtResource("3_7uuqv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.74736404, -0.09216304)
script = ExtResource("3_zz9kp")
+30 -9
View File
@@ -4,14 +4,29 @@ const RECIPE_MANAGER = preload("res://RecipeManager.gd")
@export var cook_speed = 1
@onready var snap_zone: XRToolsSnapZone = $XRToolsSnapZone
@onready var progress_bar: ProgressBar3D = $ProgressBar3D
var time_cooked = 0
var cooking_result = null
var cooking_result: String
var cooking_result_time = 0
func _ready() -> void:
if not progress_bar or progress_bar is not ProgressBar3D:
push_error("Hob 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)
_refresh_progress_bar()
func _refresh_progress_bar() -> void:
var progress := 0.0
if cooking_result and cooking_result_time > 0:
progress = clampf(float(time_cooked) / cooking_result_time, 0.0, 1.0)
#print("time_cooked: %s / cooking_result_time: %s = progress: %s" % [time_cooked, cooking_result_time, progress])
progress_bar.set_progress(progress)
progress_bar.set_bar_visible(not cooking_result.is_empty())
progress_bar.override_fill_color(Color.RED if cooking_result == "charcoal" else Color.GREEN)
func _on_object_picked_up(_item) -> void:
print("Hob: object picked up: ", _item)
@@ -23,21 +38,24 @@ func _on_object_picked_up(_item) -> void:
return
var result = RECIPE_MANAGER.get_cooking_result(_food_item.id)
if not result:
print("Hob: held a FoodItem that is not cookable, id: ", _food_item.id)
print("Hob: held a FoodItem that is not cookable, id: %s result: %s" % [_food_item.id, result])
return
cooking_result = result
cooking_result_time = RECIPE_MANAGER.get_cooking_time(_food_item.id)
cooking_result_time = RECIPE_MANAGER.get_cooking_time(_food_item.id)
print("Hob: set cooking_result ", cooking_result)
_refresh_progress_bar()
func _on_object_dropped() -> void:
print("Hob: object drop ")
time_cooked = 0
cooking_result = null
cooking_result_time = 0
cooking_result = ""
cooking_result_time = 0
_refresh_progress_bar()
func convert_held_to_item(_item: PackedScene) -> void:
func convert_held_to_item(_item: String) -> void:
if not NetworkManager.owns_world():
return
print("Hob converting ", _item)
@@ -50,20 +68,23 @@ func convert_held_to_item(_item: PackedScene) -> void:
# Spawn the new item through the server so it replicates to every peer
# (including late joiners), in the old item's position.
var original_transform = old_pickable.global_transform
var new_scene_instance = NetworkManager.spawn_item(_item.resource_path, original_transform)
var new_scene_instance = NetworkManager.spawn_item(RECIPE_MANAGER.get_item_scene(_item).resource_path, original_transform)
# Drop and free the old item and pick up the new one
print("Hob freeing old_pickable ", old_pickable)
snap_zone.drop_object()
NetworkManager.despawn_item(old_pickable)
snap_zone.pick_up_object(new_scene_instance)
# If cooking something, progress cooking, when done, convert item
func _process(delta: float) -> void:
func _process(delta: float) -> void:
if cooking_result:
#print("Hob cooking_result: ", cooking_result)
time_cooked += cook_speed * delta
_refresh_progress_bar()
if time_cooked >= cooking_result_time:
time_cooked = 0
convert_held_to_item(cooking_result)