Skip to content

Commit 0f2d96a

Browse files
authored
feat: speech bubble styles (#32)
1 parent d3d6a35 commit 0f2d96a

20 files changed

+8191
-771
lines changed

Assets/DevTools/CSV/CsvConverter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ BaseEntry previous
272272
);
273273
*/
274274
entry.Content = cells.Text();
275+
entry.Style = cells.Style() switch {
276+
"speech" => DialogueEntry.BubbleStyle.Speech,
277+
"thought" => DialogueEntry.BubbleStyle.Thought,
278+
"action" => DialogueEntry.BubbleStyle.Action,
279+
_ => throw new Exception($"Unknown style: {cells.Style()}."),
280+
};
275281

276282
if (cells.Actions() != "") {
277283
_events.Clear();
@@ -603,6 +609,7 @@ private static bool IsEmpty(this List<string> list) =>
603609
string.IsNullOrEmpty(list[0]) || list[0].StartsWith('#');
604610

605611
private static string Key(this List<string> list) => list[0];
612+
private static string Style(this List<string> list) => list[1];
606613
private static string Type(this List<string> list) => list[2];
607614
private static string Speaker(this List<string> list) => list[3];
608615
private static bool Once(this List<string> list) => list[4] == "TRUE";

Assets/Environment/Materials/BoxSDFUI.mat

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Environment/Shaders/BoxSDF.shader

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Shader "GUI/BoxSDF"
77
_Radius ("Radius", Float) = 0.3
88
_StrokeWidth ("Stroke Width", Float) = 0.1
99
_Smoothness ("Smoothness", Float) = 0.01
10+
_Dash ("Dash", Float) = 0
1011
_Test ("Test", Vector) = (0, 0, 0, 0)
1112

1213
[HideInInspector] _StencilComp ("Stencil Comparison", Float) = 8
@@ -85,6 +86,7 @@ Shader "GUI/BoxSDF"
8586
float _Radius;
8687
float _StrokeWidth;
8788
float _Smoothness;
89+
float _Dash;
8890
float4 _ClipRect;
8991
float4 _Test;
9092

@@ -130,6 +132,15 @@ Shader "GUI/BoxSDF"
130132
float2 ddyClipPos = ddy(position);
131133
float smoothness = _Smoothness * (abs(ddxClipPos) + abs(ddyClipPos));
132134

135+
float dash = input.params2.w * _Dash * _StrokeWidth;
136+
float2 absolutePosition = uv * size / dash;
137+
138+
float stripe = saturate(fmod((absolutePosition.x + absolutePosition.y), 1.0)) * 6;
139+
float stripeAlpha = dash > 0
140+
? smoothstep(1, 1 + smoothness, stripe)
141+
* smoothstep(5 + smoothness, 5, stripe)
142+
: 1.0;
143+
133144
color.a *=
134145
smoothstep(
135146
paddingEdge,
@@ -140,7 +151,8 @@ Shader "GUI/BoxSDF"
140151
strokeEdge - smoothness,
141152
strokeEdge,
142153
distance
143-
);
154+
)
155+
* stripeAlpha;
144156

145157
float paint = tex2D(_PaintTex, (uv * size + input.params2.xy) * _Test.z).b;
146158
// color.rgb += lerp(input.params2.z, input.params2.w, paint);

Assets/Player/ManagerStates/DialogueState.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Aarthificial.Typewriter.References;
55
using Input;
66
using Interactions;
7+
using System.Collections.Generic;
78
using Typewriter;
89
using UnityEngine;
910
using UnityEngine.Assertions;
@@ -27,7 +28,7 @@ private enum SubState {
2728
[Inject] [SerializeField] private OverlayChannel _overlay;
2829
[SerializeField] private Volume _volume;
2930
[SerializeField] private float _interactionCooldown = 0.5f;
30-
private CommandOption[] _options = new CommandOption[16];
31+
private List<DialogueEntry> _options = new();
3132
private BaseEntry[] _rules = new BaseEntry[16];
3233

3334
private SubState _subState = SubState.Choice;
@@ -144,7 +145,8 @@ private void ProcessEntry(BaseEntry entry) {
144145
_players.TryGetPlayer(speaker, out var player);
145146
Assert.IsNotNull(player, $"Missing speaker: {speaker}");
146147

147-
_overlay.Dialogue.Wheel.SetOptions(_options, 0);
148+
_options.Clear();
149+
_overlay.Dialogue.Wheel.SetOptions(_options);
148150
_overlay.Dialogue.Wheel.Button.SetAction(
149151
DialogueButton.ActionType.Skip
150152
);
@@ -155,24 +157,20 @@ private void ProcessEntry(BaseEntry entry) {
155157
(EntryReference)choice,
156158
_rules
157159
);
158-
var count = 0;
160+
_options.Clear();
159161
for (var i = 0; i < ruleCount; i++) {
160162
var rule = _rules[i];
161-
if (rule is not DialogueEntry response) {
162-
continue;
163+
if (rule is DialogueEntry response) {
164+
_options.Add(response);
163165
}
164-
_options[count++] = new CommandOption {
165-
Text = response.Content,
166-
IsRT = response.Speaker == _players.RT.Fact,
167-
};
168166
}
169167

170-
if (count == 0) {
168+
if (_options.Count == 0) {
171169
_currentEntry = null;
172170
return;
173171
}
174172

175-
_overlay.Dialogue.Wheel.SetOptions(_options, count);
173+
_overlay.Dialogue.Wheel.SetOptions(_options);
176174
_overlay.Dialogue.Wheel.Button.SetAction(
177175
choice.IsCancellable
178176
? DialogueButton.ActionType.Cancel

0 commit comments

Comments
 (0)