blob: ecd89a3c06a408a915187679497678c18550905b (
plain)
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
|
using Godot;
using System;
using TheLegendOfGustav.Magic;
namespace TheLegendOfGustav.GUI;
public partial class SpellBookMenu : CanvasLayer
{
private static readonly PackedScene spellMenuEntryScene = GD.Load<PackedScene>("res://scenes/GUI/spell_menu_entry.tscn");
private VBoxContainer spellsNode;
[Signal]
public delegate void SpellSelectedEventHandler(SpellResource spell);
public override void _Ready()
{
base._Ready();
spellsNode = GetNode<VBoxContainer>("CenterContainer/PanelContainer/VBoxContainer/Spells");
Hide();
}
public void OnCast(SpellResource spell)
{
EmitSignal(SignalName.SpellSelected, spell);
}
public void Initialize(SpellBook spellBook)
{
for (int i = 0; i < spellBook.KnownSpells.Count; i++)
{
RegisterSpell(i, spellBook.KnownSpells[i]);
}
Show();
}
private void RegisterSpell(int index, SpellResource spell)
{
char? shortcut = null;
// Só terá atalho para as letras do alfabeto.
if (index < 26)
{
shortcut = (char)('a' + index);
}
SpellMenuEntry spellEntry = spellMenuEntryScene.Instantiate<SpellMenuEntry>();
spellsNode.AddChild(spellEntry);
spellEntry.Initialize(spell, shortcut);
spellEntry.Cast += OnCast;
}
}
|