Skip to content

Commit 1626920

Browse files
authored
feat: new dialogue UI with scrollable history (#27)
1 parent e08f13d commit 1626920

25 files changed

+1531
-666
lines changed

Assets/Environment/Materials/BoxSDFUI.mat

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

Assets/Environment/Prefabs/Doc.prefab

Lines changed: 22 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Interactions/Conversation.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Aarthificial.Typewriter;
2+
using Cinemachine;
23
using Items;
34
using Player;
45
using UnityEngine;
@@ -31,8 +32,30 @@ InteractionWaypoint waypoint
3132

3233
private PlayerLookup<Interaction> _interactions;
3334

35+
[SerializeField] private CinemachineVirtualCamera _cameraTemplate;
36+
[SerializeField] private float _orthoSize = 4;
3437
[SerializeField] private InteractionArea _area;
35-
[Inject] [SerializeField] private OverlayChannel _overlay;
38+
39+
private CinemachineVirtualCamera _camera;
40+
41+
protected override void Awake() {
42+
base.Awake();
43+
_camera = Instantiate(_cameraTemplate);
44+
var cameraTarget = new GameObject("Camera Target").transform;
45+
cameraTarget.SetParent(transform);
46+
var position = Vector3.zero;
47+
foreach (var waypoint in Waypoints) {
48+
position += waypoint.Position;
49+
}
50+
position /= Waypoints.Length;
51+
position.y += 1;
52+
cameraTarget.position = position;
53+
54+
_camera.Follow = cameraTarget;
55+
_camera.Priority = 100;
56+
_camera.m_Lens.OrthographicSize = _orthoSize;
57+
_camera.gameObject.SetActive(false);
58+
}
3659

3760
private void Update() {
3861
UpdateInteraction(PlayerType.LT);
@@ -131,6 +154,16 @@ public void OnFocusExit(PlayerController player) {
131154
: default;
132155
}
133156

157+
public override void OnDialogueEnter() {
158+
base.OnDialogueEnter();
159+
_camera.gameObject.SetActive(true);
160+
}
161+
162+
public override void OnDialogueExit() {
163+
base.OnDialogueExit();
164+
_camera.gameObject.SetActive(false);
165+
}
166+
134167
public Vector3 GetPosition(PlayerController player) {
135168
return _interactions[player.Type].Waypoint.Position;
136169
}
@@ -160,10 +193,6 @@ private void UpdateState() {
160193
}
161194
}
162195

163-
private void HandleButtonClicked() {
164-
Event.Invoke(Context);
165-
}
166-
167196
private InteractionWaypoint FindClosestWaypoint(
168197
Vector3 position,
169198
InteractionWaypoint omit = null

Assets/Interactions/Interactable.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class Interactable : MonoBehaviour {
2424
public Blackboard Blackboard = new();
2525
[SerializeField] protected InteractionContext Context;
2626

27-
private void Awake() {
27+
protected virtual void Awake() {
2828
Context.Interaction = Blackboard;
29-
Context.Setup();
29+
Context.Setup(this);
3030
Blackboard.Set(InteractionContext.PickUp, 1);
3131
Blackboard.Set(InteractionContext.IsLTPresent, 0);
3232
Blackboard.Set(InteractionContext.IsRTPresent, 0);
@@ -49,6 +49,10 @@ public void OnHoverExit() {
4949
OnStateChanged();
5050
}
5151

52+
public virtual void OnDialogueEnter() { }
53+
54+
public virtual void OnDialogueExit() { }
55+
5256
protected void OnStateChanged() {
5357
StateChanged?.Invoke();
5458
}

Assets/Interactions/InteractionContext.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ public class InteractionContext : ITypewriterContext {
1717
public static int PickUp = -2028872245;
1818

1919
public static int ContextScope = -1768494618;
20-
public static int InteractionScope = -1936302086;
20+
public static int InteractionScope = -1936302086;
2121
public Blackboard Context;
2222
[NonSerialized] public Blackboard Interaction;
23+
public Interactable Interactable;
2324

2425
public bool TryGetBlackboard(int scope, out IBlackboard blackboard) {
2526
if (scope == InteractionScope) {
@@ -36,7 +37,8 @@ public bool TryGetBlackboard(int scope, out IBlackboard blackboard) {
3637
return false;
3738
}
3839

39-
public void Setup() {
40+
public void Setup(Interactable interactable) {
41+
Interactable = interactable;
4042
Context.Set(CurrentSpeaker, 0);
4143
Context.Set(LT, LT);
4244
Context.Set(RT, RT);

Assets/Interactions/InteractionGizmo.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Player;
2-
using System;
32
using UnityEngine;
43
using Utils;
54
using Utils.Tweening;
@@ -18,11 +17,11 @@ private static readonly int
1817
[Inject] [SerializeField] private PlayerChannel _players;
1918
[Inject] [SerializeField] private OverlayChannel _overlay;
2019
[SerializeField] private Conversation _conversation;
21-
[SerializeField] private float _angle;
2220

2321
private MeshRenderer _renderer;
2422
private MaterialPropertyBlock _block;
25-
private Dynamics _dynamics;
23+
private Dynamics _fastDynamics;
24+
private Dynamics _slowDynamics;
2625

2726
private void Awake() {
2827
_renderer = GetComponent<MeshRenderer>();
@@ -47,6 +46,7 @@ private void OnDisable() {
4746
private void Render() {
4847
if (_players.Manager.DialogueState.IsActive) {
4948
_opacity = 0.32f;
49+
_opacity = 0;
5050
_expansion = 1;
5151
_playerPresence = 0;
5252
return;
@@ -63,11 +63,18 @@ private void Render() {
6363
: _conversation.IsHovered
6464
? 0.54f
6565
: 0.32f;
66+
6667
_playerType = _conversation.PlayerType switch {
6768
PlayerType.LT => 0,
6869
PlayerType.RT => 1,
6970
_ => 0.5f,
7071
};
72+
if (_playerPresence == 0) {
73+
_slowDynamics.ForceSet(_playerType);
74+
} else {
75+
_slowDynamics.Set(_playerType);
76+
}
77+
7178
_playerPresence = _conversation.IsFocused ? 1 : 0;
7279
}
7380

@@ -76,10 +83,13 @@ private void Update() {
7683
_block ??= new MaterialPropertyBlock();
7784
#endif
7885

79-
_dynamics.Set(
80-
new Vector4(_expansion, _opacity, _playerType, _playerPresence)
86+
_fastDynamics.Set(_expansion, _opacity, _playerPresence);
87+
var fastValue = _fastDynamics.Update(SpringConfig.Snappy);
88+
var slowValue = _slowDynamics.Update(SpringConfig.Slow);
89+
_block.SetVector(
90+
_stateID,
91+
new Vector4(fastValue.x, fastValue.y, slowValue.x, fastValue.z)
8192
);
82-
_block.SetVector(_stateID, _dynamics.Update(SpringConfig.Snappy));
8393

8494
if (_players.IsReady) {
8595
var ltPosition =

Assets/Player/ConversationProfile.asset

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

0 commit comments

Comments
 (0)