Added menu resource and menu node
This commit is contained in:
parent
3d31b2ec50
commit
1fa10004b3
4 changed files with 126 additions and 1 deletions
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://crq284yed2if5"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://crq284yed2if5"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Base/base_menu.gd" id="1_3hgu4"]
|
||||
[ext_resource type="Theme" uid="uid://dmb8bcdghdjd" path="res://main_theme.tres" id="1_p1gsn"]
|
||||
[ext_resource type="Texture2D" uid="uid://db4euprxhape0" path="res://sprites/9s.png" id="1_uf5rv"]
|
||||
[ext_resource type="Texture2D" uid="uid://hxrx87gda3uf" path="res://sprites/Bases/Menu/end_communications.png" id="2_ceeiv"]
|
||||
[ext_resource type="Script" path="res://scripts/Base/actions_menu.gd" id="4_3gtyd"]
|
||||
[ext_resource type="Script" path="res://scripts/Base/close_button.gd" id="4_68ool"]
|
||||
|
||||
[node name="BaseMenu" type="Control"]
|
||||
|
|
@ -101,6 +102,59 @@ patch_margin_top = 2
|
|||
patch_margin_right = 2
|
||||
patch_margin_bottom = 2
|
||||
|
||||
[node name="ActionsMenu" type="GridContainer" parent="MenuBackground/ActionsBackground"]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.00114548
|
||||
anchor_top = 0.00505051
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.99495
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
columns = 2
|
||||
script = ExtResource("4_3gtyd")
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="Action1" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action5" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action2" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action6" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action3" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action7" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action4" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Action8" type="Button" parent="MenuBackground/ActionsBackground/ActionsMenu"]
|
||||
clip_contents = true
|
||||
custom_minimum_size = Vector2(434, 46)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="CloseButtonBackground" type="NinePatchRect" parent="MenuBackground"]
|
||||
layout_mode = 0
|
||||
offset_left = 1124.0
|
||||
|
|
|
|||
37
scripts/Base/actions_menu.gd
Normal file
37
scripts/Base/actions_menu.gd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
extends Node
|
||||
|
||||
@onready var actions: Array[Button] = [
|
||||
$Action1,
|
||||
$Action2,
|
||||
$Action3,
|
||||
$Action4,
|
||||
$Action5,
|
||||
$Action6,
|
||||
$Action7,
|
||||
$Action8
|
||||
]
|
||||
|
||||
@export var menu: Menu
|
||||
|
||||
func _ready():
|
||||
load_menu()
|
||||
|
||||
## Called when menu is changed
|
||||
func load_menu():
|
||||
for i in range(len(menu.item_ids)):
|
||||
if actions[i] is TransitButton:
|
||||
actions[i].button_up.disconnect(transit_menu)
|
||||
match menu.item_actions[i]:
|
||||
Menu.Action.TransitAction:
|
||||
actions[i].set_script("res://scripts/Classes/transit_button.gd")
|
||||
actions[i].text = menu.item_ids[i]
|
||||
Menu.Action.ButtonAction:
|
||||
actions[i].set_script(menu.item_data[i])
|
||||
actions[i].text = menu.item_ids[i]
|
||||
|
||||
## Called with transit_button, changes current menu
|
||||
func transit_menu(id: int):
|
||||
assert(id < len(menu.item_ids) and id > 0)
|
||||
var new_menu = menu.item_data[id].duplicate()
|
||||
menu = new_menu
|
||||
load_menu()
|
||||
24
scripts/Classes/menu.gd
Normal file
24
scripts/Classes/menu.gd
Normal 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
|
||||
10
scripts/Classes/transit_button.gd
Normal file
10
scripts/Classes/transit_button.gd
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
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 _ready():
|
||||
button_up.connect(get_parent().transit_menu.bind(id))
|
||||
Loading…
Add table
Add a link
Reference in a new issue