Fully working menu system

This commit is contained in:
2ndbeam 2024-05-18 12:37:36 +03:00
commit 6eef2c781c
11 changed files with 93 additions and 9 deletions

View file

@ -0,0 +1,24 @@
extends Resource
## Represents menu with actions, each action should map to a string id and data (if needed)
class_name Menu
enum Action {
## Represents when this menu should be replaced with another.
## Attach Menu next to it in item_data
TransitAction,
## Represents scripts which should be attached to button on menu startup
## Attach Script next to it in item_data
ButtonAction,
## WIP, should represent LineEdit or some other input control
InputAction,
## WIP
OtherAction
}
## Action string IDs. Should have same size as item_actions
@export var item_ids: Array[String]
## Action type. Should have same size as item_ids
@export var item_actions: Array[Action]
## Should have same size as other arrays
@export var item_data: Array[MenuResource]

View file

@ -0,0 +1,8 @@
extends MenuResource
class_name MenuMenuResource
@export var item: StringName
func load() -> Menu:
return ResourceLoader.load(item)

View file

@ -0,0 +1,3 @@
extends Resource
class_name MenuResource

View file

@ -0,0 +1,8 @@
extends MenuResource
class_name ScriptMenuResource
@export var item: StringName
func load() -> GDScript:
return ResourceLoader.load(item)

View file

@ -0,0 +1,13 @@
extends Button
## Represents button which changes menu resource on parent Menu
class_name TransitButton
## This is used when button_up is activated
var id: int = -1
func _init():
get_tree().create_timer(0.05).timeout.connect(_ready)
func _ready():
button_up.connect(get_parent().transit_menu.bind(id))