class_name PlayerUI extends Control @onready var stamina_bar: ProgressBar = %StaminaBar @onready var flashlight_bar: ProgressBar = %FlashlightBar @onready var inventory_slots_panels: Array[TextureRect] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5] @export var cursor: AspectRatioContainer var inventory_size: int = 2 ## returns true if successful func add_inventory_slot(success:bool): if success: inventory_size += 1 inventory_slots_panels[inventory_size - 1].get_parent().get_parent().visible = true inventory_slots_panels[inventory_size - 1].texture = null ## returns true if successful func remove_inventory_slot(success:bool): if success: inventory_slots_panels[inventory_size - 1].get_parent().get_parent().visible = false inventory_size -= 1 const SELECTED_COLOR = 0xcfcfcf78 const UNSELECTED_COLOR = 0x3d3d3d78 var selected_stylebox: StyleBoxFlat = StyleBoxFlat.new() var unselected_stylebox: StyleBoxFlat = StyleBoxFlat.new() func toggle_cursor(): cursor.visible = !cursor.visible func _ready(): selected_stylebox.bg_color = SELECTED_COLOR unselected_stylebox.bg_color = UNSELECTED_COLOR pivot_offset = get_viewport_rect().size / 2 visibility_changed.connect(toggle_cursor) UiManager.in_game_menu.visibility_changed.connect(func():visible = !visible) func select_item(index): if index >= 0 and index < inventory_size: for i in inventory_slots_panels: i.get_parent().add_theme_stylebox_override("panel", unselected_stylebox) if index >= 0 and index < inventory_size: inventory_slots_panels[index].get_parent().add_theme_stylebox_override("panel", selected_stylebox) func add_item(index: int, object: ItemData): if index >= 0 and index < inventory_size: inventory_slots_panels[index].texture = object.ui_icon func remove_item(index: int): if index >= 0 and index < inventory_size: inventory_slots_panels[index].texture = null var stamina: float = 100.0 var flashlight: float = 100.0 func set_stamina(value:float): stamina = value func set_flashlight(value:float): flashlight = value # i hate myself func anti_toggle(on:bool): visible = !on func toggle(on:bool): visible = on func _process(delta: float) -> void: stamina_bar.value = lerpf(stamina_bar.value, stamina, delta * 5) flashlight_bar.value = lerpf(flashlight_bar.value, flashlight, delta * 5)