Skip to content

Commit

Permalink
Merge pull request #20 from Studio-23-xyz/Timeline-support
Browse files Browse the repository at this point in the history
Timeline support
  • Loading branch information
Warhammer4000 authored Apr 9, 2024
2 parents 8016400 + 1d6630c commit a83e1ea
Show file tree
Hide file tree
Showing 43 changed files with 2,809 additions and 181 deletions.
4 changes: 4 additions & 0 deletions Assets/Packages/com.studio23.ss2.dialoguesystem/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [v0.4.0]
1. Timeline support added
2. Sample timeline scene added

## [v0.3.15]
1. Line Speaker Data added.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using UnityEditor;
using UnityEditor.Localization;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Tables;

# if UNITY_EDITOR
using UnityEditor;
# endif

namespace Studio23.SS2.DialogueSystem.Utility
{
public static class LocalizationExtensions
Expand All @@ -14,9 +18,13 @@ public static void SetEntry(this StringTable table, LocalizedString localizedStr

public static void SaveChanges(this StringTable table)
{
# if UNITY_EDITOR
EditorUtility.SetDirty(table.SharedData);
EditorUtility.SetDirty(table);
# endif
}

# if UNITY_EDITOR
/// <summary>
/// Use this to get localized string value in editor
/// for whatever reason notmal getString doesn't work
Expand All @@ -36,5 +44,6 @@ public static string GetLocalizedStringInEditor(this LocalizedString localizedSt

return entry.Value;
}
# endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,27 @@ public void InitializeDialogueGraph(DialogueGraph newGraph)
/// </summary>
public void StartDialogue(DialogueGraph graph)
{
PlayDialogue(graph);
PlayDialogue(graph).Forget();
}

public void StartDialogue(DialogueGraph graph, DialogueNodeBase startNode)
public void StartDialogue(DialogueNodeBase node)
{
PlayDialogue(graph, startNode);
PlayDialogue(node).Forget();
}

public void StartDialogue()
{
PlayDialogue(_currentGraph);
PlayDialogue(_currentGraph).Forget();
}

public async UniTask PlayDialogue(DialogueGraph graph)
{
PlayDialogue(graph, graph.StartNode);
await PlayDialogue(graph.StartNode);
}

public async UniTask PlayDialogue(DialogueGraph graph, DialogueNodeBase startNode)
public async UniTask PlayDialogue(DialogueNodeBase startNode)
{
_currentGraph = graph;
_currentGraph = startNode.graph as DialogueGraph;
_currentGraph.Initialize();
_currentGraph.HandleDialogueStarted();

Expand All @@ -97,8 +97,6 @@ public async UniTask PlayDialogue(DialogueGraph graph, DialogueNodeBase startNod

_currentGraph.HandleDialogueEnded();
OnDialogueEnded?.Invoke(_currentGraph);

Debug.Log($"{graph} dialogue completed");
}

public void AdvanceDialogue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public bool TryGetDefaultTable(out TableReference defaultTableReference)
return true;
}
}


return false;
}
Expand Down Expand Up @@ -135,7 +134,6 @@ private DialogueStartNode FindStartNode()
}
foreach (var node in nodes)
{
Debug.Log("node " , node);
if (node is DialogueStartNode startNode)
{
_startNode = startNode;
Expand All @@ -144,7 +142,6 @@ private DialogueStartNode FindStartNode()
}

return null;
Debug.LogError($"NO START NODE FOR DIALOGUE GRAPH {this}");
}

}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
# if UNITY_EDITOR
namespace Studio23.SS2.DialogueSystem.Utility.EditorLocaleSetter
{
[InitializeOnLoad]
public static class EditorLocaleSetter
{
static EditorLocaleSetter()
{
if (LocalizationSettings.SelectedLocale == null)
{
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales.FirstOrDefault(l => l.Identifier.ToString().ToLower().Contains("english") );
Debug.Log("SELECTED LOCALE SET TO " + (LocalizationSettings.SelectedLocale == null ? "null": LocalizationSettings.SelectedLocale));
}
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Studio23.SS2.DialogueSystem.Data;
using UnityEngine;

namespace Studio23.SS2.DialogueSystem.View
{
public abstract class DialogueUIBase : MonoBehaviour
{
public abstract void ShowUI();
public abstract void HideUI();
protected abstract void HandleDialogueChoiceEnded(DialogueChoicesNode obj);
protected abstract void HandleDialogueChoiceStarted(DialogueChoicesNode obj);
public abstract void ShowDialogueLineImmediate(DialogueLineNodeBase node);
protected abstract void HandleDialogueLineCompleted(DialogueLineNodeBase dialogueLineNodeBase);
protected abstract void HandleDialogueLineStarted(DialogueLineNodeBase dialogueLineNodeBase);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Localization.Settings;
using UnityEngine.Playables;
using UnityEngine.Serialization;
using UnityEngine.UI;

Expand All @@ -20,105 +22,30 @@ public class DialogueBoxUI : MonoBehaviour
[Header("Configuration")]
[SerializeField] private SubtitleSettings _config;

public event Action OnDialogueAdvanced;

void Start()
public void ShowDialogueLine(DialogueLineNodeBase dialogueLineNodeBase)
{
ApplyConfiguration();
HideUI();
RegisterEvents();
ShowDialogueTextAsync(dialogueLineNodeBase).Forget();
}


private void OnDestroy()
public async UniTask ShowDialogueTextAsync(DialogueLineNodeBase nodeBase)
{
UnRegisterEvents();
DialogueTMP.text = await nodeBase.DialogueLocalizedString.GetLocalizedStringAsync();
}

private void ApplyConfiguration()
public void ShowDialogueLineImmediate(DialogueLineNodeBase nodeBase)
{
DialogueTMP.fontSize = _config.SubtitleFontSize;
DialogueTMP.color = _config.SubtitleColor;
BackgroundImage.gameObject.SetActive(_config.ShowBackground);
BackgroundImage.color = _config.BackGroundColor;
DialogueTMP.text = nodeBase.DialogueLocalizedString.GetLocalizedString();
}


private void RegisterEvents()
{
DialogueSystem.Instance.OnDialogueStarted += ShowUI;
DialogueSystem.Instance.OnDialogueEnded += HideUI;
DialogueSystem.Instance.DialogueLineStarted += handleDialogueLineStarted;

DialogueSystem.Instance.OnDialogueChoiceStarted += HideUI;
DialogueSystem.Instance.OnDialogueChoiceEnded += ShowUI;
}

private void UnRegisterEvents()
{
if (DialogueSystem.Instance != null)
{
DialogueSystem.Instance.OnDialogueStarted -= ShowUI;
DialogueSystem.Instance.OnDialogueEnded -= HideUI;
DialogueSystem.Instance.DialogueLineStarted -= handleDialogueLineStarted;

DialogueSystem.Instance.OnDialogueChoiceStarted -= HideUI;
DialogueSystem.Instance.OnDialogueChoiceEnded -= ShowUI;
}
}


private void handleDialogueLineStarted(DialogueLineNodeBase dialogueLineNodeBase)
{
ShowDialogueTextAsync(dialogueLineNodeBase);
}
private async UniTask ShowDialogueTextAsync(DialogueLineNodeBase nodeBase)
{

// CharacterData characterData = CharacterTable.GetCharacterData(nodeBase.ID);
// string text = await TextLocalizer.LoadTextAndWait(nodeBase.DialogueLocalizedString);
// if (characterData != null)
// {
// if (_config.EnableCharacterColor)
// {
// text = $"<color=#{characterData.DialogueColor.ToHexString()}>{characterData.CharacterName}</color>:{DialogueTMP.text}";
// }
// else
// {
// text = $"{characterData.CharacterName}:{DialogueTMP.text}";
// }
// }

// DialogueTMP.text = text;
await UniTask.Delay(TimeSpan.FromSeconds(5), ignoreTimeScale: false);//TODO Dynamic Wait time according to text length
}

private void HideUI(DialogueChoicesNode obj)
{
HideUI();
}

private void ShowUI(DialogueChoicesNode obj)
{
ShowUI();
}

private void ShowUI(DialogueGraph graph)
{
ShowUI();
}

private void ShowUI()
public void ShowUI()
{
UIRoot.SetActive(true);
BackgroundImage.gameObject.SetActive(true);
}

private void HideUI(DialogueGraph graph)
{
HideUI();
}

private void HideUI()
public void HideUI()
{
UIRoot.SetActive(false);
BackgroundImage.gameObject.SetActive(false);
Expand All @@ -128,6 +55,6 @@ private void HideUI()

public void handleDialogueAdvance()
{
DialogueSystem.Instance.AdvanceDialogue();
OnDialogueAdvanced?.Invoke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@ private void Awake()

private void Start()
{
DialogueSystem.Instance.OnDialogueChoiceStarted += HandleDialogueChoiceStarted;
DialogueSystem.Instance.OnDialogueChoiceStarted += ShowChoices;
DialogueSystem.Instance.OnDialogueChoiceEnded += HandleDialogueChoiceEnded;
}

private void OnDestroy()
{
if (DialogueSystem.Instance != null)
{
DialogueSystem.Instance.OnDialogueChoiceStarted -= HandleDialogueChoiceStarted;
DialogueSystem.Instance.OnDialogueChoiceStarted -= ShowChoices;
DialogueSystem.Instance.OnDialogueChoiceEnded -= HandleDialogueChoiceEnded;
}
}

private void HandleDialogueChoiceEnded(DialogueChoicesNode choicesNode)
{
HideUI();
}

public void HideUI()
{
_buttonContainer.gameObject.SetActive(false);
}

private void HandleDialogueChoiceStarted(DialogueChoicesNode choicesNode)
public void ShowChoices(DialogueChoicesNode choicesNode)
{
SortChoices(choicesNode);
_buttonContainer.gameObject.SetActive(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DialogueStartHelper:MonoBehaviour

public void StartDialogueFromNode()
{
DialogueSystem.Instance.StartDialogue(_graph, StartNode);
DialogueSystem.Instance.StartDialogue(StartNode);
}

public void StartDialogueFromDefaultStartNode()
Expand Down
Loading

0 comments on commit a83e1ea

Please sign in to comment.