attached InGameUI script to the InGameUI node updated logic in NPC_base to run the dialog popup moved NPC position in world for easier accessmaster
parent
e2ba115c8f
commit
8055346322
@ -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
|
Loading…
Reference in new issue