Skip to content

Commit 2a82989

Browse files
authored
fix #62 - fade animation in options list view fixed. (#65)
* 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.
1 parent 9d39975 commit 2a82989

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

.github/workflows/continuous_build_check.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
godotVersion: ["4.1.4", "4.2.2"]
26+
godotVersion: ["4.1.4", "4.2.2", "4.3.0"]
2727
targetFramework: ["net6.0", "net7.0"]
2828
name: Build
2929
runs-on: ubuntu-latest

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

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

7+
## [0.2.11] 2024-09-13
8+
* Fix an issue where the OptionsListView did not fade in properly and instead suddenly appeared at the end of the fade time. (Fix #62)
9+
* `Effects.Fade` now uses a Godot Tween.
10+
* Grab focus of the first visible option in OptionsListView.cs, rather than the first option which may be hidden due to being unavailable.
11+
712
## [0.2.10] 2024-07-11
813
* Update System.Text.Json to 8.0.4 based on CVE-2024-30105 https://github.com/advisories/GHSA-hh2w-p6rv-4g7w
914
* Fix references to `RoundedViewStylebox.tres` that were in the wrong case in resource files, which could cause an issue on case-sensitive platforms.

Samples/SQLiteVariableStorage/SQLSample.tscn

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ variableStorage = NodePath("../SQLVariableStorage")
1515
startNode = "SqlSample"
1616
startAutomatically = true
1717

18+
[node name="LineView" parent="RoundedYarnSpinnerCanvasLayer" index="2"]
19+
useFadeEffect = true
20+
fadeInTime = 1.0
21+
22+
[node name="OptionsListView" parent="RoundedYarnSpinnerCanvasLayer" index="3"]
23+
fadeTime = 2.0
24+
1825
[node name="ColorRect" type="ColorRect" parent="RoundedYarnSpinnerCanvasLayer"]
1926
z_index = -6
2027
z_as_relative = false

addons/YarnSpinner-Godot/Runtime/Views/Effects.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,25 @@ public static async Task FadeAlpha(Control control, float from, float to, float
9494
color.A = from;
9595
control.Modulate = color;
9696

97-
var timeElapsed = 0d;
97+
var destinationColor = color;
98+
destinationColor.A = to;
9899

99-
while (timeElapsed < fadeTime)
100+
var tween = control.CreateTween();
101+
tween.TweenProperty(control, "modulate", destinationColor, fadeTime);
102+
while (tween.IsRunning())
100103
{
101-
if (stopToken?.WasInterrupted ?? false)
104+
if (!GodotObject.IsInstanceValid(control))
102105
{
106+
// the control was deleted from the scene
103107
return;
104108
}
105109

106-
var fraction = timeElapsed / fadeTime;
107-
timeElapsed += mainTree.Root.GetProcessDeltaTime();
110+
if (stopToken?.WasInterrupted ?? false)
111+
{
112+
tween.Kill();
113+
return;
114+
}
108115

109-
float a = Mathf.Lerp(from, to, (float) fraction);
110-
color.A = a;
111-
control.Modulate = color;
112116
await DefaultActions.Wait(mainTree.Root.GetProcessDeltaTime());
113117
}
114118

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

125-
public static async Task Typewriter(RichTextLabel text, float lettersPerSecond,
129+
public static async Task Typewriter(RichTextLabel text, float lettersPerSecond,
126130
Action onCharacterTyped, TaskInterruptToken stopToken = null)
127131
{
128132
await PausableTypewriter(
@@ -231,7 +235,7 @@ public static async Task PausableTypewriter(RichTextLabel text, float lettersPer
231235
// the requested speed.
232236
var deltaTime = mainTree.Root.GetProcessDeltaTime();
233237
var accumulator = deltaTime;
234-
238+
235239
while (GodotObject.IsInstanceValid(text) && text.VisibleRatio < 1)
236240
{
237241
if (!GodotObject.IsInstanceValid(text))
@@ -259,6 +263,7 @@ public static async Task PausableTypewriter(RichTextLabel text, float lettersPer
259263
{
260264
return;
261265
}
266+
262267
onPauseEnded?.Invoke();
263268

264269
// need to reset the accumulator
@@ -289,6 +294,7 @@ public static async Task PausableTypewriter(RichTextLabel text, float lettersPer
289294
{
290295
return;
291296
}
297+
292298
// We either finished displaying everything, or were
293299
// interrupted. Either way, display everything now.
294300
text.VisibleRatio = 1;

addons/YarnSpinner-Godot/Runtime/Views/OptionsListView.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nullable disable
22
using System;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Threading.Tasks;
56
using Godot;
67

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

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

@@ -193,8 +195,8 @@ async Task OptionViewWasSelectedInternal(DialogueOption selectedOption)
193195
OnOptionSelected(selectedOption.DialogueOptionID);
194196
}
195197
}
196-
197-
optionViews[0].GrabFocus();
198+
// If the user is hiding unavailable options, select the first visible one.
199+
optionViews.First(view => view.Visible).GrabFocus();
198200
}
199201
catch (Exception e)
200202
{

addons/YarnSpinner-Godot/plugin.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="YarnSpinner-Godot"
44
description="Yarn language based dialogue system plugin for Godot"
55
author="dogboydog"
6-
version="0.2.10"
6+
version="0.2.11"
77
script="YarnSpinnerPlugin.cs"

0 commit comments

Comments
 (0)