Skip to content

Commit

Permalink
fix #62 - fade animation in options list view fixed. (#65)
Browse files Browse the repository at this point in the history
* fix #62 - fade animation in options list view fixed. Effects.Fade now uses a tween . demonstrate fade effects in SQL sample

* test godot 4.3 in CI

* grab focus of the first visible option in OptionsListView.cs, rather than the first option which may be hidden due to being unavailable.
  • Loading branch information
dogboydog authored Sep 13, 2024
1 parent 9d39975 commit 2a82989
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous_build_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
godotVersion: ["4.1.4", "4.2.2"]
godotVersion: ["4.1.4", "4.2.2", "4.3.0"]
targetFramework: ["net6.0", "net7.0"]
name: Build
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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.11] 2024-09-13
* Fix an issue where the OptionsListView did not fade in properly and instead suddenly appeared at the end of the fade time. (Fix #62)
* `Effects.Fade` now uses a Godot Tween.
* Grab focus of the first visible option in OptionsListView.cs, rather than the first option which may be hidden due to being unavailable.

## [0.2.10] 2024-07-11
* Update System.Text.Json to 8.0.4 based on CVE-2024-30105 https://github.com/advisories/GHSA-hh2w-p6rv-4g7w
* Fix references to `RoundedViewStylebox.tres` that were in the wrong case in resource files, which could cause an issue on case-sensitive platforms.
Expand Down
7 changes: 7 additions & 0 deletions Samples/SQLiteVariableStorage/SQLSample.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ variableStorage = NodePath("../SQLVariableStorage")
startNode = "SqlSample"
startAutomatically = true

[node name="LineView" parent="RoundedYarnSpinnerCanvasLayer" index="2"]
useFadeEffect = true
fadeInTime = 1.0

[node name="OptionsListView" parent="RoundedYarnSpinnerCanvasLayer" index="3"]
fadeTime = 2.0

[node name="ColorRect" type="ColorRect" parent="RoundedYarnSpinnerCanvasLayer"]
z_index = -6
z_as_relative = false
Expand Down
26 changes: 16 additions & 10 deletions addons/YarnSpinner-Godot/Runtime/Views/Effects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,25 @@ public static async Task FadeAlpha(Control control, float from, float to, float
color.A = from;
control.Modulate = color;

var timeElapsed = 0d;
var destinationColor = color;
destinationColor.A = to;

while (timeElapsed < fadeTime)
var tween = control.CreateTween();
tween.TweenProperty(control, "modulate", destinationColor, fadeTime);
while (tween.IsRunning())
{
if (stopToken?.WasInterrupted ?? false)
if (!GodotObject.IsInstanceValid(control))
{
// the control was deleted from the scene
return;
}

var fraction = timeElapsed / fadeTime;
timeElapsed += mainTree.Root.GetProcessDeltaTime();
if (stopToken?.WasInterrupted ?? false)
{
tween.Kill();
return;
}

float a = Mathf.Lerp(from, to, (float) fraction);
color.A = a;
control.Modulate = color;
await DefaultActions.Wait(mainTree.Root.GetProcessDeltaTime());
}

Expand All @@ -122,7 +126,7 @@ public static async Task FadeAlpha(Control control, float from, float to, float
stopToken?.Complete();
}

public static async Task Typewriter(RichTextLabel text, float lettersPerSecond,
public static async Task Typewriter(RichTextLabel text, float lettersPerSecond,
Action onCharacterTyped, TaskInterruptToken stopToken = null)
{
await PausableTypewriter(
Expand Down Expand Up @@ -231,7 +235,7 @@ public static async Task PausableTypewriter(RichTextLabel text, float lettersPer
// the requested speed.
var deltaTime = mainTree.Root.GetProcessDeltaTime();
var accumulator = deltaTime;

while (GodotObject.IsInstanceValid(text) && text.VisibleRatio < 1)
{
if (!GodotObject.IsInstanceValid(text))
Expand Down Expand Up @@ -259,6 +263,7 @@ public static async Task PausableTypewriter(RichTextLabel text, float lettersPer
{
return;
}

onPauseEnded?.Invoke();

// need to reset the accumulator
Expand Down Expand Up @@ -289,6 +294,7 @@ public static async Task PausableTypewriter(RichTextLabel text, float lettersPer
{
return;
}

// We either finished displaying everything, or were
// interrupted. Either way, display everything now.
text.VisibleRatio = 1;
Expand Down
8 changes: 5 additions & 3 deletions addons/YarnSpinner-Godot/Runtime/Views/OptionsListView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;

Expand Down Expand Up @@ -76,7 +77,7 @@ private async void RunOptionsInternal(DialogueOption[] dialogueOptions, Action<i
{
// prevent option views from being pressed by the same input that advanced the dialogue
// by waiting a frame
var mainTree = (SceneTree)Engine.GetMainLoop();
var mainTree = (SceneTree) Engine.GetMainLoop();
await mainTree.ToSignal(mainTree, SceneTree.SignalName.ProcessFrame);
viewControl.Visible = false;
// Hide all existing option views
Expand Down Expand Up @@ -152,6 +153,7 @@ private async void RunOptionsInternal(DialogueOption[] dialogueOptions, Action<i
// Note the delegate to call when an option is selected
OnOptionSelected = onOptionSelected;

viewControl.Visible = true;
// Fade it all in
await Effects.FadeAlpha(viewControl, 0, 1, fadeTime);

Expand Down Expand Up @@ -193,8 +195,8 @@ async Task OptionViewWasSelectedInternal(DialogueOption selectedOption)
OnOptionSelected(selectedOption.DialogueOptionID);
}
}

optionViews[0].GrabFocus();
// If the user is hiding unavailable options, select the first visible one.
optionViews.First(view => view.Visible).GrabFocus();
}
catch (Exception e)
{
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.10"
version="0.2.11"
script="YarnSpinnerPlugin.cs"

0 comments on commit 2a82989

Please sign in to comment.