Add Shop menu on each hand

This commit is contained in:
JonShard
2026-08-04 12:38:21 +02:00
parent 2e8c12cb8a
commit 661210eac8
12 changed files with 247 additions and 36 deletions
+3 -3
View File
@@ -36,7 +36,7 @@ offset_top = 20.0
offset_right = -20.0
grow_horizontal = 0
pivot_offset_ratio = Vector2(1, 0)
text = "X $"
text = "9999 $"
label_settings = SubResource("LabelSettings_vlqg6")
horizontal_alignment = 2
@@ -49,9 +49,10 @@ offset_left = 20.0
offset_top = 80.0
offset_right = -20.0
offset_bottom = -20.0
current_tab = 0
current_tab = 1
[node name="Stations" type="GridContainer" parent="TabContainer" unique_id=189446761]
visible = false
layout_mode = 2
columns = 6
metadata/_tab_index = 0
@@ -267,7 +268,6 @@ station_name = "Sink"
cost = 40
[node name="Food" type="GridContainer" parent="TabContainer" unique_id=422899445]
visible = false
layout_mode = 2
columns = 6
metadata/_tab_index = 1
+2 -1
View File
@@ -7,7 +7,8 @@
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0, 0)
[node name="Viewport2Din3D" parent="." unique_id=651579338 instance=ExtResource("1_qtkxm")]
collision_layer = 5242880
scene = ExtResource("1_e5js8")
viewport_size = Vector2(1185.485, 733.795)
viewport_size = Vector2(807.655, 559.085)
transparent = 1
scene_properties_keys = PackedStringArray("shop_ui.gd")
+4
View File
@@ -19,3 +19,7 @@ func _ready() -> void:
func _on_button_pressed() -> void:
print("ShopStationButton buy ", station_name)
func _process(_delta: float) -> void:
button.disabled = GameManager.money < cost
+1 -5
View File
@@ -30,13 +30,9 @@ button = NodePath("Button")
[node name="Button" type="Button" parent="." unique_id=1482490300]
layout_mode = 1
anchors_preset = -1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 3.0
offset_top = 3.0
offset_right = -3.0
offset_bottom = -3.0
grow_horizontal = 2
grow_vertical = 2
icon = ExtResource("2_e1k4i")
+57 -6
View File
@@ -1,12 +1,63 @@
class_name ShopUI
extends Panel
@onready var money_label: Label = $Money
# Called when the node enters the scene tree for the first time.
var controller: XRController3D = null
const INPUT_TOGGLE_COOLDOWN := 0.15
var enabled: bool = false: set = _set_enabled
var _last_toggle_time := 0.0
var viewport: XRToolsViewport2DIn3D
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
detect_hand_from_xr_ancestor()
if controller:
controller.button_pressed.connect(_on_tracker_button_pressed)
viewport = get_parent().get_parent() as XRToolsViewport2DIn3D
if not viewport:
push_error("Shop UI could not find XRToolsViewport2DIn3D grand parent")
enabled = false
func _process(_delta: float) -> void:
money_label.text = str(GameManager.money) + "$"
func toggle_shop():
if GameManager.game_state == GameManager.GameState.BUILDING:
print("Shop UI toggle shop")
enabled = !enabled
func _set_enabled(value: bool) -> void:
enabled = value
visible = value
viewport.enabled = value
func _on_tracker_button_pressed(button_name: String) -> void:
print("Shop _on_tracker_button_pressed, button: ", button_name)
var now := Time.get_ticks_msec() / 1000.0
if now - _last_toggle_time < INPUT_TOGGLE_COOLDOWN:
return
_last_toggle_time = now
if button_name == "ax_button":
toggle_shop()
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()
if not controller:
push_error("Shop UI could not find XRController3D ancestor")
else:
print ("Shop UI detected hand: ", controller.get_tracker_hand())