beta-1.3/restructure-files (#2)
Reviewed-on: #2
This commit was merged in pull request #2.
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
|
||||
39
UI/dialogue_box.tscn
Normal file
39
UI/dialogue_box.tscn
Normal file
@@ -0,0 +1,39 @@
|
||||
[gd_scene format=3 uid="uid://cxc4x4yp7l3hg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://d0mlugcfvyksn" path="res://UI/Scripts/dialogue_box.gd" id="1_tpmx7"]
|
||||
|
||||
[node name="Dialogue Box" type="Control" unique_id=586562815]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_tpmx7")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="." unique_id=2046069713]
|
||||
layout_mode = 1
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -163.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
color = Color(0.15294118, 0.15294118, 0.15294118, 0.6313726)
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="ColorRect" unique_id=992506053]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 20
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="Label" type="Label" parent="ColorRect/MarginContainer" unique_id=908108367]
|
||||
layout_mode = 2
|
||||
text = "Sample Text"
|
||||
Reference in New Issue
Block a user