beta-1.1
This commit is contained in:
@@ -6,17 +6,41 @@ signal DialogueEnded
|
||||
|
||||
@onready var label: Label = $ColorRect/MarginContainer/Label
|
||||
|
||||
var _dialogue_arr: PackedStringArray
|
||||
var _dialogue_idx := 0
|
||||
var _dialogue_count := 0
|
||||
|
||||
# Public Methods
|
||||
func OnDialogueTriggered(dialogue_name: String) -> void:
|
||||
label.text = tr(dialogue_name)
|
||||
var text_arr := tr(dialogue_name).split("<nm>")
|
||||
_init_dialogue_box(text_arr)
|
||||
visible = true
|
||||
DialogueStarted.emit()
|
||||
|
||||
|
||||
# Private Methods
|
||||
func _init_dialogue_box(text_arr: PackedStringArray) -> void:
|
||||
_dialogue_arr = text_arr
|
||||
_dialogue_idx = 0
|
||||
_dialogue_count = len(text_arr)
|
||||
|
||||
label.text = _dialogue_arr[_dialogue_idx]
|
||||
|
||||
|
||||
func _proceed_dialogue() -> bool: # Returns true if no more dialogue
|
||||
_dialogue_idx += 1
|
||||
if _dialogue_idx == _dialogue_count:
|
||||
return true
|
||||
label.text = _dialogue_arr[_dialogue_idx]
|
||||
return false
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if !visible:
|
||||
return
|
||||
|
||||
if Input.is_action_just_pressed("player_interact") and !InputManager.ShouldIgnoreAction("player_interact"):
|
||||
visible = false
|
||||
DialogueEnded.emit()
|
||||
var finished := _proceed_dialogue()
|
||||
if finished:
|
||||
visible = false
|
||||
DialogueEnded.emit()
|
||||
|
||||
Reference in New Issue
Block a user