UI dialog and HUD switch implemented with singleton controller.

This commit is contained in:
Nitsud Yarg 2024-06-08 14:21:47 -07:00
parent 893bdb9017
commit 6961eec7de
8 changed files with 123 additions and 9 deletions

View File

@ -8,7 +8,7 @@
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/enemyC/EnemyC.tscn" type="PackedScene" id=7]
[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=8]
[ext_resource path="res://src/UI_Dialog.tscn" type="PackedScene" id=9]
[ext_resource path="res://src/UI_Layer.gd" type="Script" id=9]
[ext_resource path="res://assets/UI/Healthbar.png" type="Texture" id=10]
[ext_resource path="res://assets/UI/Healthbar-Indicator.png" type="Texture" id=11]
[ext_resource path="res://src/UI/HealthBar.gd" type="Script" id=12]
@ -223,14 +223,11 @@ position = Vector2( 492, 27 )
position = Vector2( 262, 44 )
actor_type = "NPC"
[node name="UI_Dialog" parent="." instance=ExtResource( 9 )]
visible = false
[node name="UI_Layer" type="CanvasLayer" parent="."]
layer = 2
script = ExtResource( 9 )
[node name="PanelContainer" type="PanelContainer" parent="UI_Layer"]
visible = false
margin_left = 2.0
margin_top = 2.0
margin_right = 318.0

BIN
assets/MManPortrait.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/MManPortrait.png-4e2ec0d6412baee3672a65d68519d9e1.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/MManPortrait.png"
dest_files=[ "res://.import/MManPortrait.png-4e2ec0d6412baee3672a65d68519d9e1.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -1,3 +0,0 @@
[gd_resource type="StreamTexture" format=2]
[resource]

View File

@ -53,6 +53,11 @@ _global_script_classes=[ {
"class": "StateModifier",
"language": "GDScript",
"path": "res://src/state_modifier.gd"
}, {
"base": "CanvasLayer",
"class": "UIComponent",
"language": "GDScript",
"path": "res://src/UI_Layer.gd"
} ]
_global_script_class_icons={
"Actor": "",
@ -63,7 +68,8 @@ _global_script_class_icons={
"StateAnimatedActor": "",
"StateMachine": "",
"StateMachineAnimatedActor": "",
"StateModifier": ""
"StateModifier": "",
"UIComponent": ""
}
[application]
@ -75,6 +81,7 @@ config/icon="res://icon.png"
[autoload]
PlayerInfo="*res://src/singleton_autoloads/PlayerInfo.gd"
UiManager="*res://src/singleton_autoloads/UIManager.gd"
[debug]

49
src/UI_Layer.gd Normal file
View File

@ -0,0 +1,49 @@
class_name UIComponent
extends CanvasLayer
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
onready var DialogContainer = $PanelContainer
onready var DialogContainerPortrait = $PanelContainer/HSplitContainer/TextureRect
onready var DialogContainerText = $PanelContainer/HSplitContainer/Label
onready var HUD = $HealthBar
var current_pane
# Called when the node enters the scene tree for the first time.
func _ready():
# How to change to a differant portrait picture.
#DialogContainerPortrait.texture = UiManager.dialog_portrait
#DialogContainerText.text = UiManager.dialog_text
UiManager.current_pane = UiManager.UI_PANES.HUD
#DialogContainer.visible = false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if (UiManager.current_pane != current_pane):
print("UI Switch detected")
current_pane = UiManager.current_pane
DialogContainer.visible = false
HUD.visible = false
match current_pane:
UiManager.UI_PANES.HUD:
print("Enable HUD")
HUD.visible = true
UiManager.UI_PANES.DIALOG:
print("Enable Dialog")
DialogContainerPortrait.texture = UiManager.dialog_portrait
DialogContainerText.text = UiManager.dialog_text
DialogContainer.visible = true
_: # Implicitly off
print("UI Turned off")
func _unhandled_input(event):
if current_pane == UiManager.UI_PANES.DIALOG and Input.is_action_just_pressed("ui_accept"):
UiManager.current_pane = UiManager.UI_PANES.HUD

View File

@ -9,6 +9,8 @@ onready var gun = $Gun
func _ready() -> void:
PlayerInfo.player_health = $Health_Component.health
var portrait = preload("res://assets/MManPortrait.png")
#var sound_effects = preload("res://src/playerC/resources/sound_effects.tres")
@ -58,3 +60,6 @@ func _on_Health_Component_health_depleted():
func heylookatme(sender):
print("does it work!")
UiManager.current_pane = UiManager.UI_PANES.DIALOG
UiManager.dialog_text = "Hey there. I'm glad we can see you."
UiManager.dialog_portrait = portrait

View File

@ -0,0 +1,24 @@
extends Node
## This singleton sits in the middle allowing multiple game areas to call and
# manipulate the UI
enum UI_PANES {OFF, HUD, DIALOG}
var dialog_text = 'foo'
var dialog_portrait = preload("res://icon.png")
var current_pane = UI_PANES.OFF
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass