2026-07-29 00:05:40 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
@export_category("UI")
|
|
|
|
|
@export var UI_SCALE: float = 1 ##rational scale of the ui
|
|
|
|
|
@export var UI_MOVEMENT_SENSITIVITY = 0.5 ##how much the UI moves when you move the camera
|
|
|
|
|
@export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera
|
|
|
|
|
@export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing
|
|
|
|
|
|
|
|
|
|
@export var GRAB_PANEL: PackedScene
|
|
|
|
|
|
|
|
|
|
@onready var in_game_menu: Control = %InGameMenu
|
|
|
|
|
@onready var ui: Control = %PlayerUi
|
|
|
|
|
@onready var popup_panels: Control = %PopupPanels
|
|
|
|
|
@onready var player_state: Node = %PlayerState
|
|
|
|
|
@onready var player_properties: Node = %PlayerProperties
|
|
|
|
|
@onready var player: PlayerCharacter = $"../.."
|
|
|
|
|
@onready var cursor: TextureRect = %Cursor
|
|
|
|
|
@onready var player_camera: Camera3D = %PlayerCamera
|
|
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
const SELECTED_COLOR = 0xcfcfcf78
|
|
|
|
|
const UNSELECTED_COLOR = 0x3d3d3d78
|
|
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
var grabbable_panel = null
|
|
|
|
|
var grabbable_panel_body = null
|
|
|
|
|
|
|
|
|
|
func _on_grabbable_finder_body_entered(body: Node3D) -> void:
|
|
|
|
|
if body.is_in_group("grabbable"):
|
|
|
|
|
grabbable_panel = GRAB_PANEL.instantiate()
|
|
|
|
|
popup_panels.add_child(grabbable_panel)
|
|
|
|
|
grabbable_panel_body = body
|
|
|
|
|
|
|
|
|
|
func _on_grabbable_finder_body_exited(body: Node3D) -> void:
|
|
|
|
|
if body == grabbable_panel_body:
|
|
|
|
|
popup_panels.remove_child(grabbable_panel)
|
|
|
|
|
grabbable_panel = null
|
|
|
|
|
grabbable_panel_body = null
|
|
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
func update_inventory_ui():
|
|
|
|
|
set_selected_item(player_properties.selected_item)
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
player_properties.selected_item_changed.connect(update_inventory_ui)
|
|
|
|
|
update_inventory_ui()
|
|
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
func _process(delta: float) -> void:
|
2026-07-29 13:52:14 +02:00
|
|
|
ui.stamina_bar.value = lerpf(ui.stamina_bar.value, player_properties.stamina, delta * 5)
|
2026-07-29 00:05:40 +02:00
|
|
|
if grabbable_panel != null:
|
|
|
|
|
var target_position = cursor.position - player_camera.unproject_position(grabbable_panel_body.global_position)
|
|
|
|
|
grabbable_panel.position = grabbable_panel.position.lerp(-target_position / 2, delta * 50)
|
|
|
|
|
|
|
|
|
|
func toggle_menu():
|
|
|
|
|
if !in_game_menu.visible:
|
|
|
|
|
ui.visible = false
|
|
|
|
|
popup_panels.visible = false
|
|
|
|
|
in_game_menu.visible = true
|
|
|
|
|
cursor.visible = false
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
player_state.in_menu = true
|
|
|
|
|
else:
|
|
|
|
|
ui.visible = true
|
|
|
|
|
popup_panels.visible = true
|
|
|
|
|
in_game_menu.visible = false
|
|
|
|
|
cursor.visible = true
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
player_state.in_menu = false
|
|
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
func set_stamina_bar(value:float):
|
|
|
|
|
ui.stamina_bar.value = value
|
|
|
|
|
|
|
|
|
|
func set_selected_item(index: int):
|
|
|
|
|
for i in len(ui.inventory_slots_panels):
|
|
|
|
|
if i == player_properties.selected_item:
|
|
|
|
|
ui.inventory_slots_panels[i].color = Color.hex(SELECTED_COLOR)
|
|
|
|
|
else:
|
|
|
|
|
ui.inventory_slots_panels[i].color = Color.hex(UNSELECTED_COLOR)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
func put_item(index: int, item: PackedScene):
|
|
|
|
|
player_properties.inventory[index] = item
|
|
|
|
|
|
|
|
|
|
func set_ui_scale(scale:float) -> void:
|
|
|
|
|
pass
|