Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cogito_Switch style changes and Player Hud Style Changes #162

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions COGITO/CogitoObjects/Cogito_Switch.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@icon("res://COGITO/Assets/Graphics/Editor/CogitoNodeIcon.svg")
class_name CogitoSwitch
extends Node3D

signal object_state_updated(interaction_text: String) #used to display correct interaction prompts
signal switched(is_on: bool)
signal damage_received(damage_value:float)

@onready var audio_stream_player_3d = $AudioStreamPlayer3D
#region Variables

## Sets if object starts as on or off.
@export var is_on : bool = false
Expand Down Expand Up @@ -35,6 +36,11 @@ var interaction_text : String
var player_interaction_component : PlayerInteractionComponent
var interaction_nodes : Array[Node]

@onready var audio_stream_player_3d = $AudioStreamPlayer3D

#endregion


func _ready():
self.add_to_group("interactable")
add_to_group("save_object_state")
Expand All @@ -47,6 +53,7 @@ func _ready():
else:
switch_off()


func interact(_player_interaction_component):
player_interaction_component = _player_interaction_component
if !allows_repeated_interaction and is_on:
Expand All @@ -58,6 +65,7 @@ func interact(_player_interaction_component):
else:
switch()


func switch():
audio_stream_player_3d.play()

Expand Down Expand Up @@ -100,7 +108,7 @@ func switch_off():
object_state_updated.emit(interaction_text)
switched.emit(is_on)


func check_for_item() -> bool:
var inventory = player_interaction_component.get_parent().inventory_data
for slot_data in inventory.inventory_slots:
Expand All @@ -113,8 +121,8 @@ func check_for_item() -> bool:
if item_hint != "":
player_interaction_component.send_hint(null,item_hint) # Sends the key hint with the default hint icon.
return false


func set_state():
if is_on:
for node in nodes_to_show_when_on:
Expand All @@ -134,7 +142,7 @@ func set_state():
interaction_text = interaction_text_when_off

object_state_updated.emit(interaction_text)


func save():
var state_dict = {
Expand Down
63 changes: 42 additions & 21 deletions COGITO/Scripts/Player_Hud_Manager.gd
Original file line number Diff line number Diff line change
@@ -1,48 +1,76 @@
class_name CogitoPlayerHudManager
extends Control

signal show_inventory
signal hide_inventory

@onready var damage_overlay = $DamageOverlay
@onready var inventory_interface = $InventoryInterface
@onready var wieldable_hud: PanelContainer = $MarginContainer_BottomUI/WieldableHud # Displays wieldable icons and data. Hides when no wieldable equipped.
#region Variables

## Reference to the Node that has the player.gd script.
@export var player : Node

var hurt_tween : Tween
var is_inventory_open : bool = false
var device_id : int = -1
var interaction_texture : Texture2D

## Used to reset icons etc, useful to have.
@export var empty_texture : Texture2D
## The hint icon that displays when no other icon is passed.
@export var default_hint_icon : Texture2D

## PackedScene/Prefab for Interaction Prompts
@export var prompt_component : PackedScene
@onready var prompt_area: Control = $PromptArea

## PackedScene/Prefab for Hints
@export var hint_component : PackedScene
@onready var hint_area: Control = $HintArea

## This sets how far away from the player dropped items appear. 0 = items appear on the tip of the player interaction raycast. Negative values mean closer, positive values mean further away that this.
@export var item_drop_distance_offset : float = -1

## Reference to PackedScene that gets instantiated for each player attribute.
@export var ui_attribute_prefab : PackedScene

var hurt_tween : Tween
var is_inventory_open : bool = false
var device_id : int = -1
var interaction_texture : Texture2D

@onready var damage_overlay = $DamageOverlay
@onready var inventory_interface = $InventoryInterface
@onready var wieldable_hud: PanelContainer = $MarginContainer_BottomUI/WieldableHud # Displays wieldable icons and data. Hides when no wieldable equipped.
@onready var prompt_area: Control = $PromptArea
@onready var hint_area: Control = $HintArea
@onready var ui_attribute_area : VBoxContainer = $MarginContainer_BottomUI/PlayerAttributes/MarginContainer/VBoxContainer

#endregion


func _ready():
# Connect to signal that detects change of input device
InputHelper.device_changed.connect(_on_input_device_change)
# Calling this function once to set proper input icons
_on_input_device_change(InputHelper.device,InputHelper.device_index)

$DeathScreen.hide()
damage_overlay.modulate = Color.TRANSPARENT

# Set up for HUD elements for wieldables
wieldable_hud.hide()

_setup_player()

connect_to_external_inventories.call_deferred()


func setup_player(new_player : Node):
player = new_player
_setup_player()


func _setup_player():
### NEW ATTRIBUTE SYSTEM:

## remove any previous attributes in cases where the player has been changed
for n in ui_attribute_area.get_children():
ui_attribute_area.remove_child(n)
n.queue_free()

for attribute in player.player_attributes:
var spawned_attribute_ui = ui_attribute_prefab.instantiate()
ui_attribute_area.add_child(spawned_attribute_ui)
Expand All @@ -51,14 +79,9 @@ func _ready():
attribute.death.connect(_on_player_death)

spawned_attribute_ui.initiate_attribute_ui(attribute)


$DeathScreen.hide()
damage_overlay.modulate = Color.TRANSPARENT


# Set up for HUD elements for wieldables
wieldable_hud.hide()
#prevent stuck prompts when changing players
delete_interaction_prompts()

# Fill inventory HUD with player inventory
inventory_interface.set_player_inventory_data(player.inventory_data)
Expand All @@ -75,8 +98,6 @@ func _ready():
player.player_state_loaded.connect(_on_player_state_load)
player.player_interaction_component.updated_wieldable_data.connect(_on_update_wieldable_data)

connect_to_external_inventories.call_deferred()


func connect_to_external_inventories(): # Grabbing external inventories in scene.
for node in get_tree().get_nodes_in_group("external_inventory"):
Expand Down Expand Up @@ -133,8 +154,8 @@ func set_interaction_prompts(passed_interaction_nodes : Array[Node]):
var instanced_prompt = prompt_component.instantiate()
prompt_area.add_child(instanced_prompt)
instanced_prompt.set_prompt(node.interaction_text, node.input_map_action)


func delete_interaction_prompts():
var current_prompts = prompt_area.get_children()
if current_prompts:
Expand Down