-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDialogueManager.cs
More file actions
64 lines (56 loc) · 1.75 KB
/
Copy pathDialogueManager.cs
File metadata and controls
64 lines (56 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Godot;
using System;
public class DialogueManager : Control
{
[Export]
private NodePath _dialogTextPath;
[Export]
private NodePath _avatarPath;
[Export]
private Resource _currentDialogueTres;
private Label _dialogText;
private TextureRect _avatar;
private int _currentSlideIndex = 0;
private GameEvents _gameEvents;
public override void _Ready()
{
_dialogText = GetNode<Label>(_dialogTextPath);
_avatar = GetNode<TextureRect>(_avatarPath);
// todo: this breaks if the fs is changed, should I just attach a reference of the script on the editor(?)
_gameEvents = GetNode<GameEvents>("/root/GameEvents");
_gameEvents.Connect(nameof(GameEvents.DialogInitiated), this, nameof(_OnDialogInitiated));
if (_currentDialogueTres is Dialogue dialogue)
{
_avatar.Texture = dialogue.AvatarTexture;
ShowSlide();
}
}
public override void _Input(InputEvent evt)
{
if (Input.IsActionJustPressed("advance_slide") && _currentDialogueTres is Dialogue dialogue)
{
if (_currentSlideIndex >= dialogue.DialogueSlides.Length - 1)
{
this.Visible = false;
return;
}
_currentSlideIndex++;
ShowSlide();
}
}
private void ShowSlide()
{
if (_currentDialogueTres is Dialogue dialogue)
{
_dialogText.Text = dialogue.DialogueSlides[_currentSlideIndex];
}
}
private void _OnDialogInitiated(Dialogue dialogue)
{
_currentDialogueTres = dialogue;
this.Visible = true;
_currentSlideIndex = 0;
_avatar.Texture = dialogue.AvatarTexture;
ShowSlide();
}
}