Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 96/dialog subtitles #166

Merged
merged 19 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Assets/UnZENity-Core/Scripts/Adapter/ISubtitlesAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using GUZ.Core.Data;
using UnityEngine;
using ZenKit.Daedalus;

namespace GUZ.Core.Adapter
{
public interface ISubtitlesAdapter
{
public void ShowSubtitles(GameObject npcGo);
public void HideSubtitles();
public void HideSubtitlesImmediate();
public void FillSubtitles(string npcName, string text);
}
}
11 changes: 11 additions & 0 deletions Assets/UnZENity-Core/Scripts/Adapter/ISubtitlesAdapter.cs.meta

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

1 change: 1 addition & 0 deletions Assets/UnZENity-Core/Scripts/GameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class GameContext

public static IInteractionAdapter InteractionAdapter;
public static IDialogAdapter DialogAdapter;
public static ISubtitlesAdapter SubtitlesAdapter;
public static IGameVersionAdapter GameVersionAdapter;

public enum Controls
Expand Down
2 changes: 2 additions & 0 deletions Assets/UnZENity-Core/Scripts/Globals/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static class Dialogs
public static List<InfoInstance> Instances = new();
public static bool IsInDialog;

public static CutsceneLibrary CutsceneLibrary;

public static int GestureCount;

public static class CurrentDialog
Expand Down
7 changes: 7 additions & 0 deletions Assets/UnZENity-Core/Scripts/Manager/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static void StartDialog(GameObject npcGo, NpcProperties properties, bool
{
GameData.Dialogs.IsInDialog = true;

// WIP: locking movement
GameContext.InteractionAdapter.LockPlayerInPlace();

// We are already inside a sub-dialog
if (GameData.Dialogs.CurrentDialog.Options.Any())
{
Expand Down Expand Up @@ -227,7 +230,11 @@ public static void StopDialog()
GameData.Dialogs.CurrentDialog.Options.Clear();
GameData.Dialogs.IsInDialog = false;

// WIP: unlocking movement
GameContext.InteractionAdapter.UnlockPlayer();

GameContext.DialogAdapter.HideDialog();
GameContext.SubtitlesAdapter.HideSubtitles();
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions Assets/UnZENity-Core/Scripts/Manager/GUZBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static void BootGothicUnZeNity(GameConfiguration config, string gothicDir
LoadGothicVm(gothicDir);
SetLanguage();
LoadDialogs();
LoadSubtitles();
LoadVideos();
LoadSfxVm(gothicDir);
LoadPfxVm(gothicDir);
Expand Down Expand Up @@ -116,6 +117,11 @@ private static void LoadDialogs()
infoInstances.ForEach(i => GameData.Dialogs.Instances.Add(i));
}

private static void LoadSubtitles()
{
GameData.Dialogs.CutsceneLibrary = new($"{GameGlobals.Settings.Gothic1Path}\\_work\\DATA\\scripts\\Content\\CUTSCENE\\Ou.csl");
BoroBongo marked this conversation as resolved.
Show resolved Hide resolved
BoroBongo marked this conversation as resolved.
Show resolved Hide resolved
}

private static void LoadVideos()
{
GameGlobals.Video.Init();
Expand Down
5 changes: 5 additions & 0 deletions Assets/UnZENity-Core/Scripts/Manager/NpcHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ public static bool ExtWldDetectNpcEx(NpcInstance npcInstance, int specificNpcInd
.OrderBy(i => Vector3.Distance(i.Properties.transform.position, npcPos)) // get nearest
.FirstOrDefault();

// without this Dialog box stops and breaks the entire NPC logic
if(foundNpc == null){
return false;
}

// We need to set it, as there are calls where we immediately need _other_. e.g.:
// if (Wld_DetectNpc(self, ...) && (Npc_GetDistToNpc(self, other)<HAI_DIST_SMALLTALK)
if (foundNpc.Instance != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using GUZ.Core.Globals;
using GUZ.Core.Manager;
using UnityEngine;
using ZenKit;
using ZenKit.Daedalus;
using Random = UnityEngine.Random;

namespace GUZ.Core.Npc.Actions.AnimationActions
Expand All @@ -31,8 +33,11 @@ public override void Start()
// If NPC talked before, we stop it immediately (As some audio samples are shorter than the actual animation)
AnimationCreator.StopAnimation(NpcGo);


NpcHelper.GetHeroGameObject().GetComponent<AudioSource>().PlayOneShot(audioClip);
// FIXME - Show subtitles somewhere next to Hero (== ourself/main camera)
// FIXME - Show subtitles somewhere next to Hero (== ourself/main camera) PrintDialog()
PrintDialog();

}
// NPC
else
Expand All @@ -45,8 +50,22 @@ public override void Start()

Props.NpcSound.PlayOneShot(audioClip);

// FIXME - Show subtitles above NPC
PrintDialog();
}
}

private void PrintDialog()
{
// FIXME - Show subtitles somewhere next to Hero (== ourself/main camera)
var currentMessage = GameData.Dialogs.CutsceneLibrary.Blocks.Find(x => x.Name == OutputName).Message;
NpcInstance globalHero = (NpcInstance)GameData.GothicVm.GlobalHero;
if(_isHeroSpeaking){
GameContext.SubtitlesAdapter.FillSubtitles(globalHero.GetName(NpcNameSlot.Slot0), currentMessage.Text);
}
else{
GameContext.SubtitlesAdapter.FillSubtitles(Props.NpcInstance.GetName(ZenKit.Daedalus.NpcNameSlot.Slot0), currentMessage.Text);
}
GameContext.SubtitlesAdapter.ShowSubtitles(Props.Go);
}

/// <summary>
Expand Down Expand Up @@ -95,6 +114,7 @@ public override bool IsFinished()
AnimationCreator.StopHeadMorphAnimation(Props, HeadMorph.HeadMorphType.Viseme);
}

GameContext.SubtitlesAdapter.HideSubtitles();
return true;
}

Expand Down
1 change: 1 addition & 0 deletions Assets/UnZENity-Flat/Scripts/FlatContextBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected override void RegisterControlModule(GameContext.Controls controls)

GameContext.InteractionAdapter = new FlatInteractionAdapter();
GameContext.DialogAdapter = null; // TBD
GameContext.SubtitlesAdapter = null; // TBD
}

protected override void RegisterGameVersionModule(GameVersion version)
Expand Down
Loading
Loading