Skip to content

Commit

Permalink
added speaker & voice file information
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonym271 committed May 29, 2021
1 parent 173f0e1 commit 36cccd3
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 33 deletions.
42 changes: 36 additions & 6 deletions 7sCarletSceneEditor/Instructions.cs
Expand Up @@ -70,7 +70,7 @@ public string Text
OnContentChanged();
}
}
// public override string DisplayName => base.DisplayName + " (Text)";

public override string ContentType => "Text";
public byte[] Data
{
Expand All @@ -91,17 +91,19 @@ public byte[] Data
public override void Write(BinaryWriter file)
{
byte[] data = Data;
file.Write((short)(data.Length + 4));
file.Write((short)(data.Length + 5));
file.Write(Opcode);
file.Write(data);
file.Write((byte)0); // some of them require null termination
}
}

public class DialogTextInstruction : TextInstruction
public class TextInstructionWithID : TextInstruction
{
public int ID { get; set; }
public override string Name => "DialogText";
public DialogTextInstruction(short opcode, int id, string text) :
public override string Name => "TextInstructionWithID";

public TextInstructionWithID(short opcode, int id, string text) :
base(opcode, text)
{
ID = id;
Expand All @@ -110,10 +112,38 @@ public class DialogTextInstruction : TextInstruction
public override void Write(BinaryWriter file)
{
byte[] data = Data;
file.Write((short)(data.Length + 8));
file.Write((short)(data.Length + 9));
file.Write(Opcode);
file.Write(ID);
file.Write(data);
file.Write((byte)0); // some of them require null termination
}
}

public class DialogTextInstruction : TextInstructionWithID
{
public override string Name => "DialogText";

public DialogTextInstruction(short opcode, int id, string text) :
base(opcode, id, text)
{}
}

public class SpeakerNameInstruction : TextInstructionWithID
{
public override string Name => "SpeakerName";

public SpeakerNameInstruction(short opcode, int id, string text) :
base(opcode, id, text)
{ }
}

public class VoiceFileInstruction : TextInstructionWithID
{
public override string Name => "VoiceFile";

public VoiceFileInstruction(short opcode, int id, string text) :
base(opcode, id, text)
{ }
}
}
6 changes: 5 additions & 1 deletion 7sCarletSceneEditor/JsonObjects.cs
Expand Up @@ -10,13 +10,17 @@ namespace _7sCarletSceneEditor
internal class JsonDialogInstruction
{
public int id { get; set; } = -1;
public string speaker { get; set; } = null;
public string voiceFile { get; set; } = null;
public string[] lines { get; set; } = Array.Empty<string>();

public JsonDialogInstruction() { }
public JsonDialogInstruction(DialogTextInstruction inst)
public JsonDialogInstruction(DialogTextInstruction inst, string speaker = null, string voice = null)
{
id = inst.ID;
lines = inst.Text.Trim('\0').Split(new string[] { "@@" }, StringSplitOptions.None);
this.speaker = string.IsNullOrEmpty(speaker) ? null : speaker;
voiceFile = string.IsNullOrEmpty(voice) ? null : voice;
}

public string GetText() => string.Join("@@", lines);
Expand Down
66 changes: 45 additions & 21 deletions 7sCarletSceneEditor/MainWindow.Designer.cs

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

35 changes: 31 additions & 4 deletions 7sCarletSceneEditor/MainWindow.cs
Expand Up @@ -85,12 +85,24 @@ private void ExportDialogs(string filename)
if (CurrentScenario == null)
throw new ArgumentNullException("No scenario is loaded!");
List<JsonDialogInstruction> objects = new List<JsonDialogInstruction>();
string lastSpeaker = null;
string voiceFile = null;
foreach (var inst in CurrentScenario)
{
if (inst is DialogTextInstruction d)
objects.Add(new JsonDialogInstruction(d));
{
objects.Add(new JsonDialogInstruction(d, lastSpeaker, voiceFile));
voiceFile = null; // reset because each text is only associated to 1 voice file
}
else if (inst is VoiceFileInstruction v)
voiceFile = v.Text;
else if (inst is SpeakerNameInstruction s)
lastSpeaker = s.Text;
}
File.WriteAllText(filename, JsonConvert.SerializeObject(objects.ToArray(), Newtonsoft.Json.Formatting.Indented));
File.WriteAllText(filename, JsonConvert.SerializeObject(
objects.ToArray(),
Newtonsoft.Json.Formatting.Indented,
new Newtonsoft.Json.JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }));
}

private void ImportDialogs(string filename)
Expand Down Expand Up @@ -238,18 +250,33 @@ private void listView_SelectedIndexChanged(object sender, EventArgs e)
if ( _skipSelectionChanged || listView.SelectedIndices.Count == 0)
return;

if (listView.Items[listView.SelectedIndices[0]] is InstructionListViewItem item)
int index = listView.SelectedIndices[0];
if (listView.Items[index] is InstructionListViewItem item)
{
CurrentInstruction = item.Instruction;
DataSource.Instruction = item.Instruction;
tabView.Enabled = false;
try
{
tabView.TabPages.Clear();
if (item.Instruction is TextInstruction inst)
StringBuilder status = new StringBuilder();
status.Append($"0x{item.Instruction.Opcode:X4} | {item.Instruction.Name}");

if (item.Instruction is ITextRepresentable instT)
tabView.TabPages.Add(tabViewString);
if (item.Instruction is IBinaryRepresentable instB)
tabView.TabPages.Add(tabViewHex);
if (item.Instruction is DialogTextInstruction instD)
{
var str = CurrentScenario.GetSpeaker(index);
if (!string.IsNullOrEmpty(str))
status.Append(" | Speaker: ").Append(str);
str = CurrentScenario.GetVoiceFile(index);
if (!string.IsNullOrEmpty(str))
status.Append(" | Voice File: ").Append(str);
}

statusLabel.Text = status.ToString();
}
catch (Exception exc)
{
Expand Down
3 changes: 3 additions & 0 deletions 7sCarletSceneEditor/MainWindow.resx
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>126, 17</value>
</metadata>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Expand Down
38 changes: 37 additions & 1 deletion 7sCarletSceneEditor/Scenario.cs
Expand Up @@ -47,7 +47,19 @@ public static Scenario Load(string filename)
inst = new DialogTextInstruction(
opcode,
BitConverter.ToInt32(data, 0),
Utility.DefaultEncoding.GetString(data, 4, data.Length - 4));
Utility.GetStringWithoutZeros(data, 4, data.Length - 4));
break;
case 0x0018:
inst = new SpeakerNameInstruction(
opcode,
BitConverter.ToInt32(data, 0),
Utility.GetStringWithoutZeros(data, 4, data.Length - 4));
break;
case 0x0024:
inst = new VoiceFileInstruction(
opcode,
BitConverter.ToInt32(data, 0),
Utility.GetStringWithoutZeros(data, 4, data.Length - 4));
break;
default:
inst = new BinaryInstruction(opcode, data);
Expand Down Expand Up @@ -79,5 +91,29 @@ IEnumerator IEnumerable.GetEnumerator()
{
return Instructions.GetEnumerator();
}

public string GetSpeaker(int dialogInstructionIndex)
{
for (int i = dialogInstructionIndex - 1; i > 0; i--)
{
var inst = Instructions[i];
if (inst is SpeakerNameInstruction speaker)
return speaker.Text;
}
return null;
}

public string GetVoiceFile(int dialogInstructionIndex)
{
for (int i = dialogInstructionIndex - 1; i > 0; i--)
{
var inst = Instructions[i];
if (inst is VoiceFileInstruction voice)
return voice.Text;
else if (inst is DialogTextInstruction dialog)
return null; // only one text per voice file
}
return null;
}
}
}

0 comments on commit 36cccd3

Please sign in to comment.