73 lines
2.1 KiB
GDScript3
73 lines
2.1 KiB
GDScript3
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
|
|
|
|
var debug_text :String
|
|
|
|
var _dialog_item :DialogItem
|
|
|
|
var playing_dialog :bool = false
|
|
var playing_dialog_char_timer :float
|
|
var current_dialog_index :int
|
|
|
|
signal ui_change()
|
|
|
|
# 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.
|
|
|
|
func play_dialog_item(dialog_item :DialogItem, dialog_index :int = 0):
|
|
_dialog_item = dialog_item
|
|
if _dialog_item.text_lines.size() > 0:
|
|
current_dialog_index = dialog_index
|
|
playing_dialog = true
|
|
playing_dialog_char_timer = 0.0
|
|
dialog_text = '' #_dialog_item.text_lines[current_dialog_index]
|
|
dialog_portrait = _dialog_item.portrait
|
|
current_pane = UI_PANES.DIALOG
|
|
emit_signal("ui_change")
|
|
|
|
|
|
func stop_dialog():
|
|
dialog_text = 'foo'
|
|
#call_deferred("set", dialog_text, 'foo')
|
|
current_pane = UI_PANES.HUD
|
|
#call_deferred("set", current_pane, UI_PANES.HUD )
|
|
playing_dialog = false
|
|
playing_dialog_char_timer = 0.0
|
|
emit_signal("ui_change")
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if playing_dialog:
|
|
playing_dialog_char_timer += delta
|
|
var char_count :int = floor(playing_dialog_char_timer * _dialog_item.chars_per_second )
|
|
var text_line :String = _dialog_item.text_lines[current_dialog_index]
|
|
if char_count <= text_line.length():
|
|
dialog_text = text_line.substr(0, char_count )
|
|
#emit_signal("ui_change")
|
|
|
|
##TODO: Lockout input on player before dialog happens.
|
|
if Input.is_action_just_pressed("ui_accept"):
|
|
if _dialog_item.text_lines.size() > (current_dialog_index + 1):
|
|
current_dialog_index += 1
|
|
playing_dialog_char_timer = 0.0
|
|
dialog_text = '' #_dialog_item.text_lines[current_dialog_index]
|
|
dialog_portrait = _dialog_item.portrait
|
|
emit_signal("ui_change")
|
|
else:
|
|
#stop_dialog()
|
|
call_deferred("stop_dialog")
|