Created message class and updated menu system
This commit is contained in:
parent
6963cab2af
commit
7134891e55
12 changed files with 62 additions and 13 deletions
|
|
@ -15,5 +15,5 @@ item = &"res://scripts/Base/Menu/test.gd"
|
|||
[resource]
|
||||
script = ExtResource("3_ow6va")
|
||||
item_ids = Array[String](["BASE_TEST_TRANSIT", "BASE_TEST_BLANK", "BASE_TEST_BLANK", "BASE_TEST_BLANK", "BASE_TEST_BUTTON", "BASE_TEST_BLANK", "BASE_TEST_BLANK", "BASE_TEST_BLANK"])
|
||||
item_actions = Array[int]([0, 3, 3, 3, 1, 3, 3, 3])
|
||||
item_actions = Array[int]([1, 0, 0, 0, 2, 0, 0, 0])
|
||||
item_data = Array[Resource("res://scripts/Classes/Menu/menu_resource.gd")]([SubResource("Resource_jjcgb"), null, null, null, SubResource("Resource_b58fs"), null, null, null])
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@ item = &"res://menus/Base Menu/test_menu_1.tres"
|
|||
[resource]
|
||||
script = ExtResource("3_frt6d")
|
||||
item_ids = Array[String](["BASE_TEST_BLANK", "BASE_TEST_BUTTON", "BASE_TEST_BLANK", "BASE_TEST_BLANK", "BASE_TEST_BLANK", "BASE_TEST_TRANSIT", "BASE_TEST_BLANK", "BASE_TEST_BLANK"])
|
||||
item_actions = Array[int]([3, 1, 3, 3, 3, 0, 3, 3])
|
||||
item_actions = Array[int]([0, 2, 0, 0, 0, 1, 0, 0])
|
||||
item_data = Array[Resource("res://scripts/Classes/Menu/menu_resource.gd")]([null, SubResource("Resource_dbknc"), null, null, null, SubResource("Resource_rxr54"), null, null])
|
||||
|
|
|
|||
7
scripts/Base/Menu/send_message.gd
Normal file
7
scripts/Base/Menu/send_message.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends MenuAction
|
||||
|
||||
## Message which will be send on click
|
||||
var msg: Message
|
||||
|
||||
func action():
|
||||
get_parent().transit_menu(id)
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
extends Node
|
||||
|
||||
## Array of menu actions represented as buttons
|
||||
@onready var actions: Array[Button] = [
|
||||
$Action1,
|
||||
$Action2,
|
||||
|
|
@ -11,6 +12,7 @@ extends Node
|
|||
$Action8
|
||||
]
|
||||
|
||||
## Script attached to transit buttons
|
||||
const TRANSIT_BUTTON_SCRIPT = preload("res://scripts/Classes/Menu/transit_button.gd")
|
||||
|
||||
@export var menu: Menu = null
|
||||
|
|
@ -22,22 +24,27 @@ func _ready():
|
|||
func load_menu():
|
||||
# iterating through all actions
|
||||
for i in range(len(menu.item_ids)):
|
||||
# disconnect previous action
|
||||
if actions[i] is TransitButton:
|
||||
actions[i].button_up.disconnect(transit_menu)
|
||||
elif actions[i] is MenuAction:
|
||||
actions[i].button_up.disconnect(actions[i].action)
|
||||
# disconnect previous script
|
||||
actions[i].set_script(null)
|
||||
actions[i].text = menu.item_ids[i]
|
||||
# assign new script
|
||||
match menu.item_actions[i]:
|
||||
Menu.Action.TransitAction:
|
||||
actions[i].set_script(TRANSIT_BUTTON_SCRIPT)
|
||||
actions[i].id = i
|
||||
Menu.Action.ButtonAction:
|
||||
actions[i].set_script(menu.item_data[i].load())
|
||||
actions[i].set_script(menu.item_data[i].load_script())
|
||||
Menu.Action.ComboAction:
|
||||
actions[i].set_script(menu.item_data[i].load_script())
|
||||
actions[i].id = 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].load().duplicate()
|
||||
var new_menu = menu.item_data[id].load_menu().duplicate()
|
||||
menu = new_menu
|
||||
load_menu()
|
||||
|
|
|
|||
16
scripts/Classes/Menu/combo_menu_resource.gd
Normal file
16
scripts/Classes/Menu/combo_menu_resource.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
extends MenuResource
|
||||
|
||||
class_name ComboMenuResource
|
||||
|
||||
## Script path
|
||||
@export var item_script: StringName
|
||||
## Menu that will be transitioned to
|
||||
@export var item_menu: StringName
|
||||
|
||||
## Returns script resource
|
||||
func load_script() -> GDScript:
|
||||
return ResourceLoader.load(item_script)
|
||||
|
||||
## Returns menu resource
|
||||
func load_menu() -> Menu:
|
||||
return ResourceLoader.load(item_menu)
|
||||
|
|
@ -4,16 +4,17 @@ extends Resource
|
|||
class_name Menu
|
||||
|
||||
enum Action {
|
||||
## Represents lack of action, should not have resource in item_data
|
||||
NoneAction,
|
||||
## Represents when this menu should be replaced with another.
|
||||
## Attach Menu next to it in item_data
|
||||
## Attach MenuMenuResource 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
|
||||
## Attach ScriptMenuResource next to it in item_data
|
||||
ButtonAction,
|
||||
## WIP, should represent LineEdit or some other input control
|
||||
InputAction,
|
||||
## WIP
|
||||
OtherAction
|
||||
## Represents button script with transition after its execution
|
||||
## Attach ComboMenuResource next to it in item_data
|
||||
ComboAction
|
||||
}
|
||||
|
||||
## Action string IDs. Should have same size as item_actions
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ extends Button
|
|||
|
||||
class_name MenuAction
|
||||
|
||||
var id: int = -1
|
||||
|
||||
func _init():
|
||||
get_tree().create_timer(0.05).timeout.connect(_ready)
|
||||
|
||||
|
|
@ -4,5 +4,6 @@ class_name MenuMenuResource
|
|||
|
||||
@export var item: StringName
|
||||
|
||||
func load() -> Menu:
|
||||
## Returns menu resource
|
||||
func load_menu() -> Menu:
|
||||
return ResourceLoader.load(item)
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ class_name ScriptMenuResource
|
|||
|
||||
@export var item: StringName
|
||||
|
||||
func load() -> GDScript:
|
||||
## Returns script resource
|
||||
func load_script() -> GDScript:
|
||||
return ResourceLoader.load(item)
|
||||
|
|
|
|||
14
scripts/Classes/message.gd
Normal file
14
scripts/Classes/message.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
## Represents string that differs in fact value and a value which should be displayed to player
|
||||
class_name Message
|
||||
|
||||
## Fact value
|
||||
var fact: String
|
||||
## Display value
|
||||
var shown: String
|
||||
|
||||
## Returns message with set fact and shown strings
|
||||
static func create(fact: String, shown: String) -> Message:
|
||||
var msg = Message.new()
|
||||
msg.fact = fact
|
||||
msg.shown = shown
|
||||
return msg
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue