Skip to content

Commit

Permalink
set LineView's MouseFilter to 'ignore' to avoid interfering with clic…
Browse files Browse the repository at this point in the history
…ks. fix an issue where 'use fade effect' would cause the ConvertBBCodeToHTML feature to stop working while the text was fading out. set the LineView to Visible=False when marking its alpha as 0. (#61)
  • Loading branch information
dogboydog authored Jun 30, 2024
1 parent d0c95d7 commit cb03496
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.2.9] 2024-06-30

* Set LineView's MouseFilter to 'ignore' to avoid interfering with clicks.
* Fix an issue where 'use fade effect' would cause the ConvertBBCodeToHTML feature to stop working while the text was fading out.
* Set the LineView to Visible=False when marking its alpha as 0.

## [0.2.8] 2024-05-24
* Fix Yarn commands not supporting methods with optional arguments (by @spirifoxy)
* Update Visual Novel sample to make use of this fix
Expand Down
55 changes: 29 additions & 26 deletions addons/YarnSpinner-Godot/Runtime/Views/LineView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ private void SetViewAlpha(float alpha)
var color = viewControl.Modulate;
color.A = alpha;
viewControl.Modulate = color;
viewControl.Visible = alpha != 0f;
}

/// <inheritdoc/>
Expand All @@ -292,9 +293,6 @@ public void DismissLine(Action onDismissalComplete)

private async void DismissLineInternal(Action onDismissalComplete)
{
// disabling interaction temporarily while dismissing the line
// we don't want people to interrupt a dismissal
var interactable = viewControl.Visible;
SetCanvasInteractable(false);

// If we're using a fade effect, run it, and wait for it to finish.
Expand All @@ -305,7 +303,6 @@ private async void DismissLineInternal(Action onDismissalComplete)
}

SetViewAlpha(0f);
SetCanvasInteractable(interactable);
if (onDismissalComplete != null)
{
onDismissalComplete();
Expand Down Expand Up @@ -342,6 +339,7 @@ public void InterruptLine(LocalizedLine dialogueLine, Action onInterruptLineFini
characterNameText.Text = dialogueLine.CharacterName;
lineText.Text = dialogueLine.TextWithoutCharacterName.Text;
}
ConvertHTMLToBBCodeIfConfigured();


// Show the entire line's text immediately.
Expand Down Expand Up @@ -369,20 +367,19 @@ public void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
errorMessage = failedTask.Exception.ToString();
}
GD.PushError($"Error while running {nameof(RunLineInternal)}: {errorMessage}");
},
TaskContinuationOptions.OnlyOnFaulted);
},
TaskContinuationOptions.OnlyOnFaulted);
}

private async Task RunLineInternal(LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
async Task PresentLine()
{
lineText.Visible = true;
viewControl.Visible = true;
var color = viewControl.Modulate;
color.A = 1f;
viewControl.Modulate = color;
SetCanvasInteractable(true);
SetViewAlpha(1f);

// Hide the continue button until presentation is complete (if
// we have one).
Expand Down Expand Up @@ -437,17 +434,7 @@ async Task PresentLine()
lineText.Text = text.Text;
}

if (ConvertHTMLToBBCode)
{
const string htmlTagPattern = @"<(.*?)>";
if (characterNameText != null)
{
characterNameText.Text = Regex.Replace(characterNameText.Text, htmlTagPattern, "[$1]");
}

lineText.Text = Regex.Replace(lineText.Text, htmlTagPattern, "[$1]");
}

ConvertHTMLToBBCodeIfConfigured();
if (useTypewriterEffect)
{
// If we're using the typewriter effect, hide all of the
Expand Down Expand Up @@ -481,9 +468,7 @@ async Task PresentLine()
{
var pauses = LineView.GetPauseDurationsInsideLine(text);
// setting the canvas all back to its defaults because if we didn't also fade we don't have anything visible
color = viewControl.Modulate;
color.A = 1f;
viewControl.Modulate = color;
SetViewAlpha(1f);
SetCanvasInteractable(true);
await Effects.PausableTypewriter(
lineText,
Expand All @@ -501,7 +486,7 @@ await Effects.PausableTypewriter(

// Run any presentations as a single async Task. If this is stopped,
// which UserRequestedViewAdvancement can do, then we will stop all
// of the animations at once.
// the animations at once.
await PresentLine();

if (!IsInstanceValid(this))
Expand Down Expand Up @@ -551,6 +536,25 @@ await Effects.PausableTypewriter(
onDialogueLineFinished();
}

/// <summary>
/// If <see cref="ConvertHTMLToBBCode"/> is true, replace any HTML tags in the line text and
/// character name text with BBCode tags.
/// </summary>
private void ConvertHTMLToBBCodeIfConfigured()
{
if (ConvertHTMLToBBCode)
{
const string htmlTagPattern = @"<(.*?)>";
if (characterNameText != null)
{
characterNameText.Text = Regex.Replace(characterNameText.Text, htmlTagPattern, "[$1]");
}

lineText.Text = Regex.Replace(lineText.Text, htmlTagPattern, "[$1]");
}

}

private void SetCanvasInteractable(bool b)
{
if (!IsInstanceValid(viewControl))
Expand All @@ -560,7 +564,6 @@ private void SetCanvasInteractable(bool b)

viewControl.MouseFilter = b ? Control.MouseFilterEnum.Pass : Control.MouseFilterEnum.Ignore;
viewControl.SetProcessInput(b);
viewControl.Visible = b;
}

/// <inheritdoc/>
Expand Down
1 change: 1 addition & 0 deletions addons/YarnSpinner-Godot/Scenes/DefaultDialogueSystem.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("3")
viewControlPath = NodePath("ViewControl")
useFadeEffect = false
Expand Down
2 changes: 1 addition & 1 deletion addons/YarnSpinner-Godot/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="YarnSpinner-Godot"
description="Yarn language based dialogue system plugin for Godot"
author="dogboydog"
version="0.2.8"
version="0.2.9"
script="YarnSpinnerPlugin.cs"

0 comments on commit cb03496

Please sign in to comment.