added InGameUI.gd

attached InGameUI script to the InGameUI node
updated logic in NPC_base to run the dialog popup
moved NPC position in world for easier access
master
Zac 5 years ago
parent e2ba115c8f
commit 8055346322

@ -1,4 +1,6 @@
[gd_scene format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/InGameUI.gd" type="Script" id=1]
[node name="InGameUI" type="CanvasLayer"]
@ -8,6 +10,7 @@ offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )
script = ExtResource( 1 )
[node name="Container" type="Container" parent="." index="0"]
@ -38,4 +41,24 @@ size_flags_vertical = 1
popup_exclusive = true
_sections_unfolded = [ "Popup" ]
[node name="Text" type="Label" parent="Container/DialogWindow" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 45.0
margin_top = 29.0
margin_right = -44.0
margin_bottom = -28.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1

@ -56,7 +56,7 @@ _sections_unfolded = [ "Collision" ]
[node name="NPC" parent="NPCs" index="0" instance=ExtResource( 2 )]
position = Vector2( 544.265, 95.9369 )
position = Vector2( -159.894, 95.4438 )
[node name="Player" parent="." index="2" instance=ExtResource( 3 )]
@ -64,4 +64,6 @@ Speed = 20
[node name="InGameUI" parent="." index="3" instance=ExtResource( 4 )]
_sections_unfolded = [ "Pause" ]

@ -0,0 +1,47 @@
# having the UI be a canvaslayer means that it will always stay with the camera
extends CanvasLayer
onready var DialogWin = $Container/DialogWindow
onready var DialogText = $Container/DialogWindow/Text
# setget is a way to have functions called when setting or getting a variable
# here i only want a getter so i use a comma before writing a function name
# so the interpreter reads it as null,<func name>
var displaying setget ,is_dialog_displaying
# if the game is paused, then we can bet that dialog is being shown
# so, if the player "interacts" again then we advance the text
# and if thats all the text, we hide the window and unpause the game!
func _input(event):
var tree = get_tree()
if tree.paused and event.is_action_pressed("interact"):
# unpause the game
pause(false)
# this is stupid and complicated, sorry :|
# so, we have a race condition when hitting interact to advance the text
# we get around this by creating a timer, and setting it to go off after
# a very small amount (like, a little bit longer than the typical frame delta)
# then we connect it's "timeout" signal to run the "hide" function of DialogWin
#
# this solves the issue, but I'm not totally happy with this, and it will
# need some reworking as soon as the text that's being displayed is paginated
var timer = get_tree().create_timer(.02)
timer.connect("timeout", DialogWin, "hide")
func prepare_dialog(text):
DialogText.text = text
DialogWin.popup()
# pause the game so that the player can't just walk away while talking (rude)
pause()
# a little function that makes it easier to pause/unpause the game
func pause(t=true):
get_tree().paused = t
# this is called when anything references displayed (see NPC_base.gd line 16)
func is_dialog_displaying():
return DialogWin.visible

@ -4,7 +4,7 @@ extends Node2D
# happens *after* _ready() runs.
# the $"" notation is a shorthand for getting a node.
# a longer way would be to write get_node("/root")
onready var DialogWindow = $"/root".find_node("InGameUI", true, false)
onready var UI = $"/root".find_node("InGameUI", true, false)
# start off not ready for interaction, gotta wait until the player is near us
var interact_ready = false
@ -13,8 +13,8 @@ var interact_ready = false
func _process(delta):
# if we're ready for interaction then we should check every frame if "interact" has been pressed
if interact_ready and Input.is_action_just_pressed("interact"):
print("INTERACTION")
if interact_ready and Input.is_action_just_pressed("interact") and not UI.displaying:
UI.prepare_dialog("Hello, Player!")
# this function gets called when a physics body enters into the interact_area node's area

Loading…
Cancel
Save