Made a menu to select abilities and grant them (with a few hardcoded stuff)
This commit is contained in:
55
menus/scenes/components/AbilitySelection.cs
Normal file
55
menus/scenes/components/AbilitySelection.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user