somewhat working console, fully developed from the ground up some things work with it, but its still pretty buggy currently runs on global autoload because its the easiest way rn, later on have to change it so that only if the player is in the game and console is enabled it can be toggled
59 lines
2.2 KiB
GDScript
59 lines
2.2 KiB
GDScript
extends Control
|
|
|
|
@onready var stamina_bar: ProgressBar = %StaminaBar
|
|
@onready var flashlight_bar: ProgressBar = %FlashlightBar
|
|
@onready var inventory_slots_panels: Array[PanelContainer] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5]
|
|
|
|
@onready var player_manager: Node = %PlayerManager
|
|
|
|
## returns true if successful
|
|
func add_inventory_slot() -> bool:
|
|
if len(player_manager.inventory) < 5:
|
|
player_manager.inventory.append(null)
|
|
var aspect = %InventoryPanels.get_child(len(player_manager.inventory) - 1)
|
|
if aspect is AspectRatioContainer:
|
|
aspect.visible = true
|
|
return true
|
|
return false
|
|
|
|
func add_inventory_slot_console():
|
|
Console.print_to_console(false, "Success" if add_inventory_slot() else "Failed")
|
|
|
|
## returns true if successful
|
|
func remove_inventory_slot() -> bool:
|
|
if len(player_manager.inventory) > 2:
|
|
var aspect = %InventoryPanels.get_child(len(player_manager.inventory) - 1)
|
|
if aspect is AspectRatioContainer:
|
|
aspect.visible = false
|
|
player_manager.inventory.remove_at(len(player_manager.inventory) - 1)
|
|
return true
|
|
return false
|
|
|
|
func remove_inventory_slot_console():
|
|
Console.print_to_console(false, "Success" if remove_inventory_slot() else "Failed")
|
|
|
|
|
|
const SELECTED_COLOR = 0xcfcfcf78
|
|
const UNSELECTED_COLOR = 0x3d3d3d78
|
|
|
|
var selected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
|
|
var unselected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
|
|
|
|
func _ready():
|
|
selected_stylebox.bg_color = SELECTED_COLOR
|
|
unselected_stylebox.bg_color = UNSELECTED_COLOR
|
|
Console.add_inventory.connect(add_inventory_slot_console)
|
|
Console.remove_inventory.connect(remove_inventory_slot_console)
|
|
|
|
func select_item(index):
|
|
if inventory_slots_panels != [] and index >= 0 and index < len(player_manager.inventory):
|
|
print("selected item ", index)
|
|
for i in inventory_slots_panels:
|
|
i.add_theme_stylebox_override("panel", unselected_stylebox)
|
|
if index >= 0 and index < len(player_manager.inventory):
|
|
inventory_slots_panels[index].add_theme_stylebox_override("panel", selected_stylebox)
|
|
|
|
func _process(delta: float) -> void:
|
|
if player_manager != null:
|
|
stamina_bar.value = lerpf(stamina_bar.value, player_manager.stamina, delta * 5)
|
|
flashlight_bar.value = lerpf(flashlight_bar.value, player_manager.flashlight_power, delta * 5)
|