diff --git a/Main.tscn b/Main.tscn index 3b8a639..34dc1cf 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://src/actors/players/playerE/PlayerE.tscn" type="PackedScene" id=1] [ext_resource path="res://src/levels/TestBox.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/UI/HUD.tscn" type="PackedScene" id=3] [node name="Main" type="Node2D"] @@ -12,3 +13,5 @@ __meta__ = { [node name="PlayerE" parent="." instance=ExtResource( 1 )] position = Vector2( 112, 56 ) + +[node name="UI_Layer" parent="." instance=ExtResource( 3 )] diff --git a/assets/Fonts/QuinqueFive.tres b/assets/Fonts/QuinqueFive.tres new file mode 100644 index 0000000..958242b --- /dev/null +++ b/assets/Fonts/QuinqueFive.tres @@ -0,0 +1,8 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[sub_resource type="DynamicFontData" id=1] +font_path = "res://assets/Fonts/QuinqueFive.ttf" + +[resource] +size = 5 +font_data = SubResource( 1 ) diff --git a/assets/Fonts/QuinqueFive.ttf b/assets/Fonts/QuinqueFive.ttf new file mode 100644 index 0000000..a89a6e9 Binary files /dev/null and b/assets/Fonts/QuinqueFive.ttf differ diff --git a/assets/UI/Healthbar-Indicator.png b/assets/UI/Healthbar-Indicator.png new file mode 100644 index 0000000..071fb87 Binary files /dev/null and b/assets/UI/Healthbar-Indicator.png differ diff --git a/assets/UI/Healthbar-Indicator.png.import b/assets/UI/Healthbar-Indicator.png.import new file mode 100644 index 0000000..8f5cca8 --- /dev/null +++ b/assets/UI/Healthbar-Indicator.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Healthbar-Indicator.png-cbbde6797adcb3b0445dfd4f9ab1961a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/UI/Healthbar-Indicator.png" +dest_files=[ "res://.import/Healthbar-Indicator.png-cbbde6797adcb3b0445dfd4f9ab1961a.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 diff --git a/assets/UI/Healthbar.png b/assets/UI/Healthbar.png new file mode 100644 index 0000000..b1c74da Binary files /dev/null and b/assets/UI/Healthbar.png differ diff --git a/assets/UI/Healthbar.png.import b/assets/UI/Healthbar.png.import new file mode 100644 index 0000000..224bce8 --- /dev/null +++ b/assets/UI/Healthbar.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Healthbar.png-838f5c013355fbdfe1abb6dec9197215.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/UI/Healthbar.png" +dest_files=[ "res://.import/Healthbar.png-838f5c013355fbdfe1abb6dec9197215.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 diff --git a/project.godot b/project.godot index a2ba1f3..2f30051 100644 --- a/project.godot +++ b/project.godot @@ -103,6 +103,11 @@ _global_script_classes=[ { "class": "StateModifierAnimatedActor", "language": "GDScript", "path": "res://lib/classes/state_modifier_animation.gd" +}, { +"base": "Reference", +"class": "UIComponent", +"language": "GDScript", +"path": "res://src/UI/UI_Layer.gd" } ] _global_script_class_icons={ "Actor": "", @@ -123,7 +128,8 @@ _global_script_class_icons={ "StateMachine": "", "StateMachineAnimatedActor": "", "StateModifier": "", -"StateModifierAnimatedActor": "" +"StateModifierAnimatedActor": "", +"UIComponent": "" } [application] diff --git a/src/UI/HUD.tscn b/src/UI/HUD.tscn new file mode 100644 index 0000000..34e499f --- /dev/null +++ b/src/UI/HUD.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=2] +[ext_resource path="res://src/UI/UI_Layer.gd" type="Script" id=3] +[ext_resource path="res://assets/UI/Healthbar.png" type="Texture" id=4] +[ext_resource path="res://src/UI/HealthBar.gd" type="Script" id=5] +[ext_resource path="res://assets/UI/Healthbar-Indicator.png" type="Texture" id=6] + +[node name="UI_Layer" type="CanvasLayer"] +pause_mode = 2 +layer = 2 +script = ExtResource( 3 ) + +[node name="PanelContainer" type="PanelContainer" parent="."] +margin_left = 2.0 +margin_top = 2.0 +margin_right = 318.0 +margin_bottom = 80.0 + +[node name="HSplitContainer" type="HSplitContainer" parent="PanelContainer"] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 309.0 +margin_bottom = 71.0 +size_flags_vertical = 0 +split_offset = 1 + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/HSplitContainer"] +margin_right = 65.0 +margin_bottom = 64.0 +grow_vertical = 2 +size_flags_vertical = 5 +texture = ExtResource( 1 ) + +[node name="Label" type="Label" parent="PanelContainer/HSplitContainer"] +margin_left = 77.0 +margin_right = 302.0 +margin_bottom = 64.0 +size_flags_vertical = 1 +size_flags_stretch_ratio = 5.0 +custom_fonts/font = ExtResource( 2 ) +text = "In a world where danger lurks in your plumbing. One thing decides to do another thing and we all determine it wasn't worth it. Hello World" +autowrap = true + +[node name="Polygon2D" type="Polygon2D" parent="PanelContainer"] +position = Vector2( 75, 16.5 ) +scale = Vector2( 0.769547, 0.833333 ) +color = Color( 0.533333, 0.533333, 0.533333, 1 ) +polygon = PoolVector2Array( 294, 63, 300.177, 63, 307, 63, 300.503, 69 ) + +[node name="HealthBar" type="TextureProgress" parent="."] +margin_left = 2.0 +margin_top = 2.0 +margin_right = 104.0 +margin_bottom = 14.0 +value = 50.0 +texture_under = ExtResource( 4 ) +texture_progress = ExtResource( 6 ) +texture_progress_offset = Vector2( 1, 1 ) +script = ExtResource( 5 ) + +[node name="Debug" type="Label" parent="."] +anchor_left = 1.0 +anchor_right = 1.0 +margin_left = -192.0 +margin_top = 3.0 +margin_right = -3.0 +margin_bottom = 17.0 +text = "Foo" +align = 2 diff --git a/src/UI/HealthBar.gd b/src/UI/HealthBar.gd new file mode 100644 index 0000000..bdf8f3b --- /dev/null +++ b/src/UI/HealthBar.gd @@ -0,0 +1,16 @@ +extends TextureProgress + + +# 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): + value = PlayerInfo.player_health diff --git a/src/UI/UI_Dialog.tscn b/src/UI/UI_Dialog.tscn new file mode 100644 index 0000000..354706e --- /dev/null +++ b/src/UI/UI_Dialog.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=1] +[ext_resource path="res://icon.png" type="Texture" id=2] + +[node name="UI_Dialog" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="PanelContainer" type="PanelContainer" parent="."] +margin_left = 2.0 +margin_top = 2.0 +margin_right = 318.0 +margin_bottom = 80.0 + +[node name="HSplitContainer" type="HSplitContainer" parent="PanelContainer"] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 309.0 +margin_bottom = 71.0 +size_flags_vertical = 0 +split_offset = 1 + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/HSplitContainer"] +margin_right = 65.0 +margin_bottom = 64.0 +grow_vertical = 2 +size_flags_vertical = 5 +texture = ExtResource( 2 ) + +[node name="Label" type="Label" parent="PanelContainer/HSplitContainer"] +margin_left = 77.0 +margin_right = 302.0 +margin_bottom = 64.0 +size_flags_vertical = 1 +size_flags_stretch_ratio = 5.0 +custom_fonts/font = ExtResource( 1 ) +text = "In a world where danger lurks in your plumbing. One thing decides to do another thing and we all determine it wasn't worth it. Hello World" +autowrap = true diff --git a/src/UI/UI_Layer.gd b/src/UI/UI_Layer.gd new file mode 100644 index 0000000..757c3bf --- /dev/null +++ b/src/UI/UI_Layer.gd @@ -0,0 +1,60 @@ +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 DialogIndicator = $PanelContainer/Polygon2D + +onready var HUD = $HealthBar + +var current_pane + +var tween + +# 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 + tween = get_tree().create_tween().set_loops() + tween.tween_property(DialogIndicator, "modulate", Color.darkgray, 1) + tween.tween_property(DialogIndicator, "modulate", Color.white , 1) + ##tween.tween_property(DialogIndicator, "modulate", Color.RED, 1) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + $Debug.text = UiManager.debug_text + 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 + #get_tree().paused = 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 + #get_tree().paused = false