2026-08-09 03:24:28 +02:00
|
|
|
class_name PlayerUI extends Control
|
2026-07-31 02:38:02 +02:00
|
|
|
|
|
|
|
|
@onready var stamina_bar: ProgressBar = %StaminaBar
|
|
|
|
|
@onready var flashlight_bar: ProgressBar = %FlashlightBar
|
2026-08-09 03:24:28 +02:00
|
|
|
|
2026-08-06 01:00:09 +02:00
|
|
|
@onready var inventory_slots_panels: Array[TextureRect] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5]
|
2026-07-31 02:38:02 +02:00
|
|
|
|
2026-08-10 01:25:55 +02:00
|
|
|
@export var cursor: AspectRatioContainer
|
|
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
var inventory_size: int = 2
|
2026-07-31 02:38:02 +02:00
|
|
|
|
|
|
|
|
## returns true if successful
|
2026-08-12 01:47:15 +02:00
|
|
|
func add_inventory_slot(success:bool):
|
|
|
|
|
if success:
|
2026-08-09 03:24:28 +02:00
|
|
|
inventory_size += 1
|
2026-08-12 01:47:15 +02:00
|
|
|
inventory_slots_panels[inventory_size - 1].get_parent().get_parent().visible = true
|
|
|
|
|
inventory_slots_panels[inventory_size - 1].texture = null
|
2026-07-31 02:38:02 +02:00
|
|
|
|
|
|
|
|
## returns true if successful
|
2026-08-12 01:47:15 +02:00
|
|
|
func remove_inventory_slot(success:bool):
|
|
|
|
|
if success:
|
|
|
|
|
inventory_slots_panels[inventory_size - 1].get_parent().get_parent().visible = false
|
2026-08-09 03:24:28 +02:00
|
|
|
inventory_size -= 1
|
2026-07-31 02:38:02 +02:00
|
|
|
|
|
|
|
|
const SELECTED_COLOR = 0xcfcfcf78
|
|
|
|
|
const UNSELECTED_COLOR = 0x3d3d3d78
|
|
|
|
|
|
|
|
|
|
var selected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
|
|
|
|
|
var unselected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
|
|
|
|
|
|
2026-08-10 01:25:55 +02:00
|
|
|
func toggle_cursor():
|
|
|
|
|
cursor.visible = !cursor.visible
|
|
|
|
|
|
2026-07-31 02:38:02 +02:00
|
|
|
func _ready():
|
|
|
|
|
selected_stylebox.bg_color = SELECTED_COLOR
|
|
|
|
|
unselected_stylebox.bg_color = UNSELECTED_COLOR
|
2026-08-09 23:18:13 +02:00
|
|
|
pivot_offset = get_viewport_rect().size / 2
|
2026-08-10 01:25:55 +02:00
|
|
|
visibility_changed.connect(toggle_cursor)
|
2026-08-12 01:47:15 +02:00
|
|
|
UiManager.in_game_menu.visibility_changed.connect(func():visible = !visible)
|
2026-07-31 02:38:02 +02:00
|
|
|
|
|
|
|
|
func select_item(index):
|
2026-08-09 03:24:28 +02:00
|
|
|
if index >= 0 and index < inventory_size:
|
2026-07-31 02:38:02 +02:00
|
|
|
for i in inventory_slots_panels:
|
2026-08-06 01:00:09 +02:00
|
|
|
i.get_parent().add_theme_stylebox_override("panel", unselected_stylebox)
|
2026-08-09 03:24:28 +02:00
|
|
|
if index >= 0 and index < inventory_size:
|
2026-08-06 01:00:09 +02:00
|
|
|
inventory_slots_panels[index].get_parent().add_theme_stylebox_override("panel", selected_stylebox)
|
2026-08-12 01:47:15 +02:00
|
|
|
|
2026-08-05 23:37:19 +02:00
|
|
|
func add_item(index: int, object: RigidBody3D):
|
2026-08-09 03:24:28 +02:00
|
|
|
if index >= 0 and index < inventory_size:
|
2026-08-05 23:37:19 +02:00
|
|
|
var meshes = object.get_children()
|
|
|
|
|
var texture = null
|
|
|
|
|
for i in meshes:
|
|
|
|
|
if i is MeshInstance3D:
|
|
|
|
|
texture = await GrabbableBase.create_icon_from_mesh(i.mesh)
|
2026-08-06 01:00:09 +02:00
|
|
|
inventory_slots_panels[index].texture = texture
|
|
|
|
|
|
|
|
|
|
func remove_item(index: int):
|
2026-08-09 03:24:28 +02:00
|
|
|
if index >= 0 and index < inventory_size:
|
2026-08-06 01:00:09 +02:00
|
|
|
inventory_slots_panels[index].texture = null
|
|
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
var stamina: float = 100.0
|
|
|
|
|
var flashlight: float = 100.0
|
|
|
|
|
|
|
|
|
|
func set_stamina(value:float):
|
|
|
|
|
stamina = value
|
|
|
|
|
|
|
|
|
|
func set_flashlight(value:float):
|
|
|
|
|
flashlight = value
|
|
|
|
|
|
2026-07-31 02:38:02 +02:00
|
|
|
func _process(delta: float) -> void:
|
2026-08-09 03:24:28 +02:00
|
|
|
stamina_bar.value = lerpf(stamina_bar.value, stamina, delta * 5)
|
|
|
|
|
flashlight_bar.value = lerpf(flashlight_bar.value, flashlight, delta * 5)
|