End of chapter 6. A lot of problems took to much time to solve. It was good to know better Godot internal mechanism.

This commit is contained in:
2025-04-06 18:07:29 -03:00
parent 909c385dee
commit db55b2af02
21 changed files with 202 additions and 70 deletions

View File

@@ -0,0 +1,63 @@
extends MarginContainer
@export var scrollContainer:ScrollContainer
@export var messages:VBoxContainer
@export var messageHistory := 10
var messageLinePrefab = preload("res://scenes/ui/MessageLine.tscn")
func _ready():
CommandDispatcher.DISPLAY_MESSAGE.connect(_onMessageReceived)
CommandDispatcher.DISPLAY_COMMAND_PROMPT.connect(displayCommandPrompt)
CommandDispatcher.DISPLAY_CLEAR.connect(clearWindow)
func _on_command(text):
displayCommand(text)
func _onMessageReceived(message):
displayMessage(message)
func displayCommandPrompt():
messages.add_child(messageLinePrefab.instantiate())
func clearWindow():
for item in messages.get_children():
messages.remove_child(item)
item.queue_free()
func scrollToEnd():
await scrollContainer.get_v_scroll_bar().changed
if (messages.get_child_count() > messageHistory):
messages.get_child(0).queue_free()
scrollContainer.scroll_vertical = scrollContainer.get_v_scroll_bar().max_value
func displayMessage(message):
var messageLine = messageLinePrefab.instantiate()
messageLine.text = "%s\n" % message
messages.add_child(messageLine)
scrollToEnd()
func displayCommand(message):
var currentMessageLine:RichTextLabel
if (messages.get_child_count() == 0):
displayCommandPrompt()
currentMessageLine = messages.get_children()[messages.get_children().size() - 1]
currentMessageLine.text = currentMessageLine.text.insert(currentMessageLine.text.length() - 2, message)
scrollToEnd()

View File

@@ -0,0 +1 @@
uid://dv3fd112uj8o1

View File

@@ -1,11 +1,11 @@
extends Control
@export var loadingBar: TextureProgressBar
@export var loadingBar:TextureProgressBar
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
func _ready():
Loader.LOADING_PROGRESS_UPDATED.connect(_on_progress_updated)
func _on_progress_updated(percentage: float) -> void:
loadingBar.value = percentage
func _on_progress_updated(percentage):
loadingBar.value = percentage * 100