56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System;
|
|
using Godot;
|
|
using Movementtests.systems;
|
|
|
|
[Tool, GlobalClass]
|
|
public partial class AbilitySelection : Control
|
|
{
|
|
[Signal] public delegate void AbilityAddedEventHandler(WeaponSystem.WeaponEvent forEvent, string abilityName);
|
|
|
|
[Export] public WeaponSystem.WeaponEvent ForEvent { get; set; } = WeaponSystem.WeaponEvent.StartedFlying;
|
|
|
|
private string _title = string.Empty;
|
|
[Export] public string Title {
|
|
get => _title;
|
|
set
|
|
{
|
|
_title = value;
|
|
TitleChanged();
|
|
}
|
|
}
|
|
|
|
[Export] public PackedScene AbilitySelectionItem { get; set; }
|
|
|
|
private VBoxContainer _abilities;
|
|
private MenuButton _addAbility;
|
|
private PopupMenu _addAbilityMenu;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_abilities = GetNode<VBoxContainer>("%SelectedAbilities");
|
|
_addAbility = GetNode<MenuButton>("%AddAbility");
|
|
_addAbilityMenu = _addAbility.GetPopup();
|
|
|
|
_addAbilityMenu.IdPressed += AddAbilityMenuOnIdPressed;
|
|
_addAbilityMenu.IndexPressed += AddAbilityMenuOnIndexPressed;
|
|
}
|
|
|
|
private void AddAbilityMenuOnIndexPressed(long index)
|
|
{
|
|
var indexInt = Convert.ToInt32(index);
|
|
var metadata = _addAbilityMenu.GetItemMetadata(indexInt);
|
|
var name = _addAbilityMenu.GetItemText(indexInt);
|
|
EmitSignalAbilityAdded(ForEvent, name);
|
|
}
|
|
|
|
private void AddAbilityMenuOnIdPressed(long id)
|
|
{
|
|
}
|
|
|
|
public void TitleChanged()
|
|
{
|
|
var titleLabel = GetNode<Label>("%TitleLabel");
|
|
titleLabel.Text = Title;
|
|
}
|
|
}
|