Skip to content

Commit

Permalink
Add voiced line subtitle editing (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jun 2, 2023
1 parent a17b8a6 commit 71f57fd
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/PlaceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public SKBitmap GetNewPlaceGraphic(SKTypeface msGothicHaruhi)
string spaceAdjustedText = PlaceName.Replace(" ", " ");
SKBitmap newPlaceBitmap = new(PlaceGraphic.Width, PlaceGraphic.Height);
SKCanvas canvas = new(newPlaceBitmap);
SKColor bgColor = new SKColor(0, 249, 0);
SKColor bgColor = new(0, 249, 0);
canvas.DrawRegion(new(new SKRectI(0, 0, newPlaceBitmap.Width, newPlaceBitmap.Height)), new SKPaint { Color = bgColor });
TextBlock placeText = new()
{
Expand Down
13 changes: 13 additions & 0 deletions src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -68,6 +69,8 @@ public class Project
public ScenarioStruct Scenario { get; set; }
[JsonIgnore]
public MessageInfoFile MessInfo { get; set; }
[JsonIgnore]
public VoiceMapFile VoiceMap { get; set; }

public Project()
{
Expand Down Expand Up @@ -270,6 +273,11 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
tracker.Finished++;
}

if (VoiceMapIsV06OrHigher())
{
VoiceMap = Evt.Files.First(v => v.Name == "VOICEMAPS").CastTo<VoiceMapFile>();
}

string[] bgmFiles = Directory.GetFiles(Path.Combine(IterativeDirectory, "rom", "data", "bgm")).OrderBy(s => s).ToArray();
tracker.Focus("BGM Tracks", bgmFiles.Length);
for (int i = 0; i < bgmFiles.Length; i++)
Expand Down Expand Up @@ -379,6 +387,11 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
return new(LoadProjectState.SUCCESS);
}

public bool VoiceMapIsV06OrHigher()
{
return Evt.Files.Any(f => f.Name == "VOICEMAPS") && Encoding.ASCII.GetString(Evt.Files.First(f => f.Name == "VOICEMAPS").Data.Skip(0x08).Take(4).ToArray()) == "SUBS";
}

public void MigrateProject(string newRom, ILogger log, IProgressTracker tracker)
{
log.Log($"Attempting to migrate base ROM to {newRom}");
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/SerialLoops.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.3" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="2.8.2.3" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.27.5" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.27.14" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="NitroPacker.Core" Version="2.1.0" />
<PackageReference Include="NLayer" Version="1.14.0" />
Expand Down
98 changes: 98 additions & 0 deletions src/SerialLoops/Editors/VoicedLineEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using Eto.Forms;
using HaruhiChokuretsuLib.Archive.Event;
using HaruhiChokuretsuLib.Util;
using NAudio.Wave;
using SerialLoops.Controls;
using SerialLoops.Dialogs;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using SerialLoops.Lib.Util;
using SerialLoops.Utility;
using System;
using System.IO;
using System.Linq;

namespace SerialLoops.Editors
{
Expand Down Expand Up @@ -64,6 +68,99 @@ public override Container GetEditorPanel()
Content = GetEditorPanel();
};

StackLayout subtitleLayout = new();
if (_project.VoiceMap is not null)
{
TextBox subtitleBox = new()
{
Width = 400,
};
RadioButtonList screenSelectionList = new()
{
Orientation = Orientation.Horizontal,
Items =
{
VoiceMapFile.VoiceMapStruct.Screen.TOP.ToString(),
VoiceMapFile.VoiceMapStruct.Screen.BOTTOM.ToString(),
},
SelectedKey = VoiceMapFile.VoiceMapStruct.Screen.BOTTOM.ToString(),
};
RadioButtonList yPosSelectionList = new()
{
Orientation = Orientation.Horizontal,
Items =
{
VoiceMapFile.VoiceMapStruct.YPosition.TOP.ToString(),
VoiceMapFile.VoiceMapStruct.YPosition.BELOW_TOP.ToString(),
VoiceMapFile.VoiceMapStruct.YPosition.ABOVE_BOTTOM.ToString(),
VoiceMapFile.VoiceMapStruct.YPosition.BOTTOM.ToString(),
},
SelectedKey = VoiceMapFile.VoiceMapStruct.YPosition.ABOVE_BOTTOM.ToString(),
};
var voiceMapStruct = _project.VoiceMap.VoiceMapStructs.FirstOrDefault(v => v.VoiceFileName == Path.GetFileNameWithoutExtension(_vce.VoiceFile));
if (voiceMapStruct is not null)
{
if (_project.LangCode != "ja")
{
subtitleBox.Text = voiceMapStruct.Subtitle.GetSubstitutedString(_project);
}
else
{
subtitleBox.Text = voiceMapStruct.Subtitle;
}

screenSelectionList.SelectedKey = voiceMapStruct.TargetScreen.ToString();
yPosSelectionList.SelectedKey = voiceMapStruct.YPos.ToString();
}

subtitleBox.TextChanged += (sender, args) =>
{
string subtitle = _project.LangCode != "ja" ? subtitleBox.Text.GetOriginalString(_project) : subtitleBox.Text;
var voiceMapStruct = _project.VoiceMap.VoiceMapStructs.FirstOrDefault(v => v.VoiceFileName == Path.GetFileNameWithoutExtension(_vce.VoiceFile));
if (voiceMapStruct is null)
{
_project.VoiceMap.VoiceMapStructs.Add(new()
{
VoiceFileName = Path.GetFileNameWithoutExtension(_vce.VoiceFile),
FontSize = 100,
TargetScreen = Enum.Parse<VoiceMapFile.VoiceMapStruct.Screen>(screenSelectionList.SelectedKey),
Timer = 350,
});
_project.VoiceMap.VoiceMapStructs[_project.VoiceMap.VoiceMapStructs.Count - 1].SetSubtitle(subtitle, _project.FontReplacement);
_project.VoiceMap.VoiceMapStructs[_project.VoiceMap.VoiceMapStructs.Count - 1].YPos = Enum.Parse<VoiceMapFile.VoiceMapStruct.YPosition>(yPosSelectionList.SelectedKey);
}
else
{
voiceMapStruct.SetSubtitle(subtitle, _project.FontReplacement);
}
UpdateTabTitle(false, subtitleBox);
};

screenSelectionList.SelectedKeyChanged += (sender, args) =>
{
var voiceMapStruct = _project.VoiceMap.VoiceMapStructs.FirstOrDefault(v => v.VoiceFileName == Path.GetFileNameWithoutExtension(_vce.VoiceFile));
if (voiceMapStruct is not null)
{
voiceMapStruct.TargetScreen = Enum.Parse<VoiceMapFile.VoiceMapStruct.Screen>(screenSelectionList.SelectedKey);
UpdateTabTitle(false);
}
};

yPosSelectionList.SelectedKeyChanged += (sender, args) =>
{
var voiceMapStruct = _project.VoiceMap.VoiceMapStructs.FirstOrDefault(v => v.VoiceFileName == Path.GetFileNameWithoutExtension(_vce.VoiceFile));
if (voiceMapStruct is not null)
{
voiceMapStruct.YPos = Enum.Parse<VoiceMapFile.VoiceMapStruct.YPosition>(yPosSelectionList.SelectedKey);
UpdateTabTitle(false);
}
};

subtitleLayout.Items.Add(ControlGenerator.GetControlWithLabel("Subtitle", subtitleBox));
subtitleLayout.Items.Add(ControlGenerator.GetControlWithLabel("Target Screen", screenSelectionList));
subtitleLayout.Items.Add(ControlGenerator.GetControlWithLabel("Y Position", yPosSelectionList));
}

return new TableLayout(
new TableRow(ControlGenerator.GetPlayerStackLayout(VcePlayer, _vce.Name, _vce.AdxType.ToString())),
new TableRow(new StackLayout
Expand All @@ -77,6 +174,7 @@ public override Container GetEditorPanel()
restoreButton,
}
}),
new TableRow(subtitleLayout),
new TableRow()
);
}
Expand Down
12 changes: 12 additions & 0 deletions src/SerialLoops/MainForm.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ private void SaveProject_Executed(object sender, EventArgs e)
IEnumerable<ItemDescription> unsavedItems = OpenProject.Items.Where(i => i.UnsavedChanges);
bool savedExtra = false;
bool changedNameplates = false;
bool changedSubs = false;
SKCanvas nameplateCanvas = new(OpenProject.NameplateBitmap);
SKCanvas speakerCanvas = new(OpenProject.SpeakerBitmap);

Expand Down Expand Up @@ -461,6 +462,13 @@ private void SaveProject_Executed(object sender, EventArgs e)
evt.CollectGarbage();
IO.WriteStringFile(Path.Combine("assets", "events", $"{evt.Index:X3}.s"), evt.GetSource(new()), OpenProject, Log);
break;
case ItemDescription.ItemType.Voice:
VoicedLineItem vce = (VoicedLineItem)item;
if (OpenProject.VoiceMap is not null)
{
changedSubs = true;
}
break;

default:
Log.LogWarning($"Saving for {item.Type}s not yet implemented.");
Expand All @@ -475,6 +483,10 @@ private void SaveProject_Executed(object sender, EventArgs e)
OpenProject.NameplateBitmap.Encode(nameplateStream, SKEncodedImageFormat.Png, 1);
IO.WriteBinaryFile(Path.Combine("assets", "graphics", "B87.png"), nameplateStream.ToArray(), OpenProject, Log);
}
if (changedSubs)
{
IO.WriteStringFile(Path.Combine("assets", "events", $"{OpenProject.VoiceMap.Index:X3}.s"), OpenProject.VoiceMap.GetSource(), OpenProject, Log);
}
foreach (Editor editor in EditorTabs.Tabs.Pages.Cast<Editor>())
{
editor.UpdateTabTitle(true);
Expand Down

0 comments on commit 71f57fd

Please sign in to comment.