Add Shop toggles poke
This commit is contained in:
@@ -111,11 +111,13 @@ bones/21/rotation = Quaternion(-0.06251818, -0.00022572002, -0.115392834, 0.9913
|
||||
bones/22/rotation = Quaternion(0.058578636, 0.021648303, -0.26990518, 0.9608596)
|
||||
bones/23/rotation = Quaternion(0.006871769, -0.0035727466, -0.21195254, 0.97724926)
|
||||
|
||||
[node name="BoneAttachment3D" type="BoneAttachment3D" parent="XRControllerLeftHand/LeftHand/Hand_low_L/Armature/Skeleton3D" index="1" unique_id=506224189]
|
||||
[node name="BoneAttachment3D" type="BoneAttachment3D" parent="XRControllerLeftHand/LeftHand/Hand_low_L/Armature/Skeleton3D" index="1" unique_id=774348011]
|
||||
transform = Transform3D(0.5408296, 0.8408128, -0.023173608, -0.08262672, 0.08052427, 0.99332196, 0.83706397, -0.5353032, 0.11302349, 0.039901964, 0.040282845, -0.15009598)
|
||||
bone_name = "Index_Tip_L"
|
||||
bone_idx = 9
|
||||
|
||||
[node name="Poke" parent="XRControllerLeftHand/LeftHand/Hand_low_L/Armature/Skeleton3D/BoneAttachment3D" unique_id=259928841 instance=ExtResource("7_1fmci")]
|
||||
|
||||
[node name="AnimationTree" parent="XRControllerLeftHand/LeftHand" index="1"]
|
||||
tree_root = SubResource("AnimationNodeBlendTree_yfij0")
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _on_game_state_changed(new_state: GameManager.GameState) -> void:
|
||||
print("BuildModeController: game_state_changed to %s" % new_state)
|
||||
print("BuildModeController: game_state_changed to %s" % GameManager.GameState.keys()[new_state])
|
||||
if new_state == GameManager.GameState.BUILDING:
|
||||
despawn_unheld_pickables()
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ func _ready() -> void:
|
||||
$"..".visible = false
|
||||
|
||||
# Listen for the game over signal from GameManager
|
||||
Signals.game_over.connect(_on_game_over)
|
||||
Signals.game_state_changed.connect(_on_game_state_changed)
|
||||
|
||||
func _on_game_over() -> void:
|
||||
$"..".visible = true
|
||||
func _on_game_state_changed(new_state: GameManager.GameState) -> void:
|
||||
if new_state == GameManager.GameState.GAME_OVER:
|
||||
$"..".visible = true
|
||||
else:
|
||||
$"..".visible = false
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
[ext_resource type="Script" uid="uid://bsdpd18i1i17s" path="res://prefabs/build_mode_controller.gd" id="9_atgwk"]
|
||||
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="10_dhas4"]
|
||||
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://stations/table.tscn" id="11_gaw43"]
|
||||
[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="12_n58f2"]
|
||||
[ext_resource type="PackedScene" uid="uid://xtcei2uvd5li" path="res://UI/game_over_panel.tscn" id="13_hooyg"]
|
||||
[ext_resource type="Script" uid="uid://cwijoksyou1ey" path="res://scenes/GameOvercontroler.gd" id="14_cqmpj"]
|
||||
|
||||
[sub_resource type="Environment" id="Environment_bvwq1"]
|
||||
background_mode = 2
|
||||
@@ -111,3 +114,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.2, 0.5, 0)
|
||||
|
||||
[node name="Table" parent="." unique_id=1863572470 instance=ExtResource("11_gaw43")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.4, 0.5, 1.8)
|
||||
|
||||
[node name="GameOverPanel" parent="." unique_id=522901881 instance=ExtResource("12_n58f2")]
|
||||
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -4.428178, 2.8122003, 3)
|
||||
scene = ExtResource("13_hooyg")
|
||||
viewport_size = Vector2(900, 600)
|
||||
transparent = 0
|
||||
filter = false
|
||||
scene_properties_keys = PackedStringArray("game_over_panel.gd")
|
||||
|
||||
[node name="controler" type="Node" parent="GameOverPanel" unique_id=1442195864]
|
||||
script = ExtResource("14_cqmpj")
|
||||
|
||||
+44
-15
@@ -4,6 +4,7 @@ extends Panel
|
||||
@onready var money_label: Label = $Money
|
||||
|
||||
var controller: XRController3D = null
|
||||
var other_controller: XRController3D = null
|
||||
const INPUT_TOGGLE_COOLDOWN := 0.15
|
||||
|
||||
var enabled: bool = false: set = _set_enabled
|
||||
@@ -13,8 +14,12 @@ var viewport: XRToolsViewport2DIn3D
|
||||
|
||||
func _ready() -> void:
|
||||
detect_hand_from_xr_ancestor()
|
||||
|
||||
if controller:
|
||||
controller.button_pressed.connect(_on_tracker_button_pressed)
|
||||
controller.button_pressed.connect(_on_controller_button_pressed)
|
||||
if other_controller:
|
||||
other_controller.button_pressed.connect(_on_other_controller_button_pressed)
|
||||
|
||||
viewport = get_parent().get_parent() as XRToolsViewport2DIn3D
|
||||
if not viewport:
|
||||
push_error("Shop UI could not find XRToolsViewport2DIn3D grand parent")
|
||||
@@ -32,13 +37,30 @@ func toggle_shop():
|
||||
|
||||
|
||||
func _set_enabled(value: bool) -> void:
|
||||
enabled = value
|
||||
visible = value
|
||||
enabled = value
|
||||
visible = value
|
||||
if viewport:
|
||||
viewport.enabled = value
|
||||
|
||||
_set_poke_enabled_for_controller(other_controller, value)
|
||||
|
||||
func _on_tracker_button_pressed(button_name: String) -> void:
|
||||
print("Shop _on_tracker_button_pressed, button: ", button_name)
|
||||
|
||||
|
||||
func _set_poke_enabled_for_controller(controller_node: XRController3D, value: bool) -> void:
|
||||
if not controller_node:
|
||||
return
|
||||
|
||||
var poke_node = Helper.find_first_child_of_type(controller_node, XRToolsPoke)
|
||||
if poke_node:
|
||||
print("Shop UI _set_poke_enabled_for_controller: ", poke_node.get_path(), " poke enabled: ", value)
|
||||
poke_node.enabled = value
|
||||
poke_node.visible = value
|
||||
else:
|
||||
print("Shop UI _set_poke_enabled_for_controller: ", controller_node.name, " poke not found")
|
||||
|
||||
# For some reason, this is called every frame the button is down. So we need our own timer.
|
||||
func _on_controller_button_pressed(button_name: String) -> void:
|
||||
print("Shop _on_controller_button_pressed, button: ", button_name)
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
if now - _last_toggle_time < INPUT_TOGGLE_COOLDOWN:
|
||||
return
|
||||
@@ -48,16 +70,23 @@ func _on_tracker_button_pressed(button_name: String) -> void:
|
||||
toggle_shop()
|
||||
|
||||
|
||||
func _on_other_controller_button_pressed(button_name: String) -> void:
|
||||
# If user opens menu on other hand. Close this one.
|
||||
if enabled and button_name == "ax_button":
|
||||
enabled = false
|
||||
|
||||
|
||||
func detect_hand_from_xr_ancestor() -> void:
|
||||
var curr: Node = get_parent()
|
||||
# Climb up the tree until we find an XRNode3D/XRController3D or hit root
|
||||
while curr != null:
|
||||
if curr is XRController3D:
|
||||
controller = curr
|
||||
break
|
||||
curr = curr.get_parent()
|
||||
|
||||
controller = XRHelpers.get_xr_controller(self)
|
||||
if not controller:
|
||||
push_error("Shop UI could not find XRController3D ancestor")
|
||||
else:
|
||||
print ("Shop UI detected hand: ", controller.get_tracker_hand())
|
||||
return
|
||||
|
||||
var left_controller := XRHelpers.get_left_controller(self)
|
||||
var right_controller := XRHelpers.get_right_controller(self)
|
||||
|
||||
if controller == left_controller:
|
||||
other_controller = right_controller
|
||||
elif controller == right_controller:
|
||||
other_controller = left_controller
|
||||
print("Shop UI detected hand: ", controller.get_tracker_hand())
|
||||
|
||||
@@ -8,3 +8,12 @@ static func find_food_item(node: Node) -> FoodItem:
|
||||
if child is FoodItem:
|
||||
return child
|
||||
return null
|
||||
|
||||
static func find_first_child_of_type(node: Node, type: Variant) -> Node:
|
||||
for child in node.get_children():
|
||||
if is_instance_of(child, type):
|
||||
return child
|
||||
var nested := find_first_child_of_type(child, type)
|
||||
if nested:
|
||||
return nested
|
||||
return null
|
||||
Reference in New Issue
Block a user