Working on menu system - First button does not work

Probably switch to implementing a UI system instead of using the built-in one
combat_refactor
Joey Pollack 2 years ago
parent 900a5bb30f
commit f870ed8003

@ -3,13 +3,13 @@ class_name Combatant
# @export var Behavior:
@export var Menu: BattleMenu
@export var Stats: CombatStats
@export var Actions: Array[Action] = []
var is_init = false
func _ready():
pass
# var idx = 0
# for node in get_children():
# if node.name == "Actions":
@ -18,8 +18,8 @@ func _ready():
# Menu.add_action(action)
# Actions.append(action)
# idx += 1
for action in Actions:
Menu.add_action(action)
# for action in Actions:
# Menu.add_action(action)
func execute_action(index: int):

@ -0,0 +1,25 @@
extends Control
class_name BattleMenu
var items: Array[MenuItem] = []
var top_margin = 100
var item_padding = 10
var next_y_pos = 0
func _ready():
next_y_pos = top_margin
func add_action(action: Action):
var item = preload("res://Systems/UI/Menu System/menu_item.tscn").instantiate()
items.push_back(item)
item.label = action.ActionName
item.action = action
var button = item.get_node("Button")
button.position.y = next_y_pos
next_y_pos += button.size.y + item_padding
var panel = $Panel
# var button = item.get_node("Button")
panel.add_child(item)

@ -0,0 +1,17 @@
extends Control
class_name MenuItem
@export var label = ""
@export var action: Action
@onready var button = $Button
signal action_selected(action)
# Called when the node enters the scene tree for the first time.
func _ready():
button.text = label
func _on_button_pressed():
emit_signal("action_selected", action)

@ -0,0 +1,39 @@
[gd_scene load_steps=2 format=3 uid="uid://cl5d768roh8ir"]
[ext_resource type="Script" path="res://Systems/UI/Menu System/Scripts/battle_menu.gd" id="1_fije1"]
[node name="battle_menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_fije1")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -100.0
offset_top = -86.0
offset_right = 108.0
offset_bottom = 184.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="Panel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -60.0
offset_top = 16.0
offset_right = 53.0
offset_bottom = 45.0
grow_horizontal = 2
text = "Battle Menu"
horizontal_alignment = 1

@ -0,0 +1,25 @@
[gd_scene load_steps=2 format=3 uid="uid://l1bdgx07seai"]
[ext_resource type="Script" path="res://Systems/UI/Menu System/Scripts/menu_item.gd" id="1_paamu"]
[node name="MenuItem" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_paamu")
[node name="Button" type="Button" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -36.0
offset_right = 36.0
offset_bottom = 34.0
grow_horizontal = 2
text = "TEST"
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]

@ -1,7 +0,0 @@
extends Control
class_name BattleMenu
@onready var text = $Text
func add_action(action: Action):
text.text += "\n%d) %s" % [action.ActionIndex + 1, action.ActionName]

@ -1,18 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://cl5d768roh8ir"]
[ext_resource type="Script" path="res://Systems/UI/Scripts/battle_menu.gd" id="1_ng8au"]
[node name="battle_menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ng8au")
[node name="Text" type="Label" parent="."]
layout_mode = 0
offset_right = 299.0
offset_bottom = 142.0
text = "Battle Menu:"

@ -0,0 +1,7 @@
extends Sprite2D
func _ready():
var menu = $battle_menu
menu.add_action($Combatant/Actions/attack)
menu.add_action($Combatant/Actions/spin_attack)

File diff suppressed because one or more lines are too long

@ -1,41 +0,0 @@
[gd_scene load_steps=8 format=3 uid="uid://cnnvxd4gefp4o"]
[ext_resource type="PackedScene" uid="uid://ch1sc85jxy1r7" path="res://Systems/Combat/Combatant.tscn" id="1_701ur"]
[ext_resource type="Script" path="res://Test Scenes/test_player.gd" id="1_fstsi"]
[ext_resource type="Script" path="res://Systems/Combat/Scripts/combat_stats.gd" id="3_axh6y"]
[ext_resource type="PackedScene" uid="uid://bbbyup8pp6uam" path="res://Test Scenes/Test Player Actions/attack.tscn" id="3_ywlre"]
[ext_resource type="PackedScene" uid="uid://bmot4y61f1r8f" path="res://Test Scenes/Test Player Actions/spin_attack.tscn" id="4_sr4bi"]
[ext_resource type="PackedScene" uid="uid://cl5d768roh8ir" path="res://Systems/UI/battle_menu.tscn" id="5_2vin1"]
[sub_resource type="Resource" id="Resource_l1ix6"]
script = ExtResource("3_axh6y")
MaxHP = 10
MaxPhysicalStamina = 10
MaxMentalStamina = 10
Strength = 1
Wisdom = 1
Constitution = 1
Willpower = 1
Speed = 1
Focus = 1
Accuracy = 1
Agility = 1
[node name="test_player" type="Node2D"]
script = ExtResource("1_fstsi")
[node name="battle_menu" parent="." instance=ExtResource("5_2vin1")]
[node name="Combatant" parent="." node_paths=PackedStringArray("Menu", "Actions") instance=ExtResource("1_701ur")]
Menu = NodePath("../battle_menu")
Stats = SubResource("Resource_l1ix6")
Actions = [NodePath("Actions/attack"), NodePath("Actions/spin_attack")]
[node name="Actions" type="Node" parent="Combatant"]
[node name="attack" parent="Combatant/Actions" instance=ExtResource("3_ywlre")]
ActionName = "Attack"
ActionText = "Attack"
[node name="spin_attack" parent="Combatant/Actions" instance=ExtResource("4_sr4bi")]
ActionName = "Spin Attack"
Loading…
Cancel
Save