Reorganize file structure of project
This commit is contained in:
46
UI/Scripts/dialogue_box.gd
Normal file
46
UI/Scripts/dialogue_box.gd
Normal file
@@ -0,0 +1,46 @@
|
||||
extends Control
|
||||
class_name DialogueBox
|
||||
|
||||
signal DialogueStarted
|
||||
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:
|
||||
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"):
|
||||
var finished := _proceed_dialogue()
|
||||
if finished:
|
||||
visible = false
|
||||
DialogueEnded.emit()
|
||||
1
UI/Scripts/dialogue_box.gd.uid
Normal file
1
UI/Scripts/dialogue_box.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d0mlugcfvyksn
|
||||
Reference in New Issue
Block a user