Fixed VN Textbox

This commit is contained in:
2026-01-09 21:02:01 -06:00
parent bcf5249067
commit db15eeb672
3 changed files with 33 additions and 13 deletions

View File

@@ -11,6 +11,8 @@ var newlineIndexes:Array[int] = [];
var currentViewScrolled = true;
var isSpeedupDown = false;
var hasLetGoOfInteract:bool = true;
var isClosed:bool = false:
get():
return !self.visible;
@@ -24,14 +26,22 @@ func _ready() -> void:
isClosed = true
func _process(delta: float) -> void:
if isClosed:
return;
if label.getFinalText() == "":
isClosed = true;
return;
if Input.is_action_just_released("interact") && !hasLetGoOfInteract:
hasLetGoOfInteract = true;
return
# Have we finished displaying the current page?
if label.visible_characters >= label.getCharactersDisplayedCount():
# Not finished displaying current page
if (label.maxLines + label.startLine) < label.getTotalLineCount():
# Not on last page.
if Input.is_action_just_pressed("interact"):
if Input.is_action_just_pressed("interact") && hasLetGoOfInteract:
label.startLine += label.maxLines;
label.visible_characters = 0;
currentViewScrolled = false;
@@ -40,17 +50,19 @@ func _process(delta: float) -> void:
currentViewScrolled = true;
else:
# On last page
if Input.is_action_just_released("interact"):
if Input.is_action_just_released("interact") && hasLetGoOfInteract:
textboxClosing.emit();
isClosed = true;
currentViewScrolled = true
return;
if Input.is_action_just_pressed("interact"):
# This prevents the game trying to advance if the player is still holding
# down interact.
if Input.is_action_just_pressed("interact") && hasLetGoOfInteract:
isSpeedupDown = true;
elif Input.is_action_just_released("interact"):
elif Input.is_action_just_released("interact") && hasLetGoOfInteract:
isSpeedupDown = false;
elif !Input.is_action_pressed("interact"):
elif !Input.is_action_pressed("interact") && hasLetGoOfInteract:
isSpeedupDown = false;
revealTimer += delta;
@@ -62,16 +74,22 @@ func _process(delta: float) -> void:
label.visible_characters += 1;
func setText(text:String) -> void:
isClosed = false;
# Prepare textbox for scrolling
# Resets scroll
revealTimer = 0;
currentViewScrolled = false;
label.visible_characters = 0;
label.startLine = 0;
label.text = ""
await get_tree().process_frame# Absolutely needed to make the text wrap
# I had a frame wait here before.
label.text = text;
label.visible_characters = 0;
# Resets speedup and advancing
hasLetGoOfInteract = !Input.is_action_pressed("interact");
isSpeedupDown = false
isClosed = false;
func setTextAndWait(text:String) -> void:
await setText(text);
self.setText(text);
await self.textboxClosing