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;
|
||||
}
|
||||
}
|
||||
1
menus/scenes/components/AbilitySelection.cs.uid
Normal file
1
menus/scenes/components/AbilitySelection.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://5emed8iegtui
|
||||
45
menus/scenes/components/ability_selection.tscn
Normal file
45
menus/scenes/components/ability_selection.tscn
Normal file
@@ -0,0 +1,45 @@
|
||||
[gd_scene format=3 uid="uid://dmv685sskgh3l"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://5emed8iegtui" path="res://menus/scenes/components/AbilitySelection.cs" id="1_fcxyu"]
|
||||
[ext_resource type="Texture2D" uid="uid://by5v33lu8v1fm" path="res://assets/ui/input-prompts/Flairs/Vector/flair_plus.svg" id="2_uf3m5"]
|
||||
[ext_resource type="Texture2D" uid="uid://c2akxlg7tdb67" path="res://assets/ui/IconGodotNode/node/icon_projectile.png" id="3_41pdy"]
|
||||
|
||||
[node name="AbilitySelection" type="MarginContainer" unique_id=1373426933]
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/margin_left = 4
|
||||
theme_override_constants/margin_top = 4
|
||||
theme_override_constants/margin_right = 4
|
||||
theme_override_constants/margin_bottom = 4
|
||||
script = ExtResource("1_fcxyu")
|
||||
|
||||
[node name="HBoxContainer" type="VBoxContainer" parent="." unique_id=364343452]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="HBoxContainer" unique_id=8350369]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SelectedAbilities" type="VBoxContainer" parent="HBoxContainer" unique_id=1173689490]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="HBoxContainer" unique_id=51872459]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 4
|
||||
theme_override_constants/margin_top = 4
|
||||
theme_override_constants/margin_right = 4
|
||||
theme_override_constants/margin_bottom = 4
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="HBoxContainer/MarginContainer" unique_id=886085404]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="AddAbility" type="MenuButton" parent="HBoxContainer/MarginContainer/PanelContainer" unique_id=1898027483]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
focus_mode = 2
|
||||
text = "Add ability"
|
||||
icon = ExtResource("2_uf3m5")
|
||||
item_count = 1
|
||||
popup/item_0/text = "Weapon explosion"
|
||||
popup/item_0/icon = ExtResource("3_41pdy")
|
||||
popup/item_0/id = 0
|
||||
Reference in New Issue
Block a user