Working dialogue system

This commit is contained in:
2ndbeam 2024-05-19 17:14:52 +03:00
commit c0c68c8662
16 changed files with 267 additions and 103 deletions

View file

@ -0,0 +1,7 @@
extends NinePatchRect
@onready var dialogue = $DialogueView
func send_message(msg: Message):
var new_msg = tr(msg.fact + "_RECEIVED")
dialogue.append_text(new_msg)

View file

@ -1,7 +1,19 @@
extends MenuAction
class_name MessageSenderAction
var dialogue
## Message which will be send on click
var msg: Message
## Gets message and translates it on display.
## Shown message should end with _LOCAL
func _ready():
var item_id = get_parent().menu.item_ids[id]
msg = Message.create(item_id, tr(item_id + "_LOCAL"))
text = msg.shown
super._ready()
func action():
dialogue.send_message(msg)
get_parent().transit_menu(id)

View file

@ -40,7 +40,10 @@ func load_menu():
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
if "id" in actions[i]:
actions[i].id = i
if "dialogue" in actions[i]:
actions[i].dialogue = $"../../Dialogue"
## Called with transit_button, changes current menu
func transit_menu(id: int):

View file

@ -2,9 +2,9 @@
class_name Message
## Fact value
var fact: String
@export var fact: String
## Display value
var shown: String
@export var shown: String
## Returns message with set fact and shown strings
static func create(fact: String, shown: String) -> Message: