Skip to content

Commit

Permalink
importing and exporting dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonym271 committed Apr 30, 2021
1 parent 5dd7cd3 commit 14856a8
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 61 deletions.
6 changes: 6 additions & 0 deletions 7sCarletSceneEditor/7sCarletSceneEditor.csproj
Expand Up @@ -36,8 +36,13 @@
<Reference Include="Be.Windows.Forms.HexBox, Version=1.6.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Be.Windows.Forms.HexBox.1.6.1\lib\net40\Be.Windows.Forms.HexBox.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -56,6 +61,7 @@
<Compile Include="InstructionTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="JsonObjects.cs" />
<Compile Include="MainWindow.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
20 changes: 2 additions & 18 deletions 7sCarletSceneEditor/InstructionDataSource.cs
Expand Up @@ -51,35 +51,19 @@ public Instruction Instruction
_instruction.ContentChanged -= OnInstructionChanged;
value.ContentChanged += OnInstructionChanged;
_instruction = value;
OnInstructionChanged(value, EventArgs.Empty);
OnInstructionChanged(value);
}
}

public event Action<string> TextChanged;
public event Action<byte[]> DataChanged;

private void OnInstructionChanged(object sender, EventArgs args)
private void OnInstructionChanged(Instruction sender)
{
if (_instruction is ITextRepresentable tr)
TextChanged?.Invoke(tr.Text);
if (_instruction is IBinaryRepresentable br)
DataChanged?.Invoke(br.Data);
}

/*
public void SetText(string text)
{
if (_instruction is ITextRepresentable tr)
tr.Text = text;
else throw new ArgumentException("Current instruction does not support text data!");
}
public void SetData(byte[] data)
{
if (_instruction is IBinaryRepresentable br)
br.Data = data;
else throw new ArgumentException("Current instruction does not support binary data!");
}
*/
}
}
42 changes: 33 additions & 9 deletions 7sCarletSceneEditor/Instructions.cs
@@ -1,7 +1,5 @@


using System;
using System.Text;
using System;
using System.IO;

namespace _7sCarletSceneEditor
{
Expand All @@ -21,13 +19,15 @@ public abstract class Instruction
public virtual string Name => this.GetType().Name;
public virtual string ContentType => "None";

public event EventHandler ContentChanged;
protected void OnContentChanged(EventArgs args) => ContentChanged?.Invoke(this, args);
public event Action<Instruction> ContentChanged;
protected void OnContentChanged() => ContentChanged?.Invoke(this);

public Instruction(short opcode)
{
this.Opcode = opcode;
}

public abstract void Write(BinaryWriter file);
}

public class BinaryInstruction : Instruction, IBinaryRepresentable
Expand All @@ -39,7 +39,7 @@ public byte[] Data
set
{
_data = value;
OnContentChanged(EventArgs.Empty);
OnContentChanged();
}
}
public override string ContentType => "Binary";
Expand All @@ -49,6 +49,13 @@ public byte[] Data
{
_data = data;
}

public override void Write(BinaryWriter file)
{
file.Write((short)(_data.Length + 4));
file.Write(Opcode);
file.Write(_data);
}
}

public class TextInstruction : Instruction, ITextRepresentable, IBinaryRepresentable
Expand All @@ -60,7 +67,7 @@ public string Text
set
{
_text = value;
OnContentChanged(EventArgs.Empty);
OnContentChanged();
}
}
// public override string DisplayName => base.DisplayName + " (Text)";
Expand All @@ -71,7 +78,7 @@ public byte[] Data
set
{
Text = Utility.DefaultEncoding.GetString(value);
OnContentChanged(EventArgs.Empty);
OnContentChanged();
}
}

Expand All @@ -80,6 +87,14 @@ public byte[] Data
{
_text = text;
}

public override void Write(BinaryWriter file)
{
byte[] data = Data;
file.Write((short)(data.Length + 4));
file.Write(Opcode);
file.Write(data);
}
}

public class DialogTextInstruction : TextInstruction
Expand All @@ -91,5 +106,14 @@ public class DialogTextInstruction : TextInstruction
{
ID = id;
}

public override void Write(BinaryWriter file)
{
byte[] data = Data;
file.Write((short)(data.Length + 8));
file.Write(Opcode);
file.Write(ID);
file.Write(data);
}
}
}
24 changes: 24 additions & 0 deletions 7sCarletSceneEditor/JsonObjects.cs
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace _7sCarletSceneEditor
{
internal class JsonDialogInstruction
{
public int id { get; set; } = -1;
public string[] lines { get; set; } = Array.Empty<string>();

public JsonDialogInstruction() { }
public JsonDialogInstruction(DialogTextInstruction inst)
{
id = inst.ID;
lines = inst.Text.Trim('\0').Split(new string[] { "@@" }, StringSplitOptions.None);
}

public string GetText() => string.Join("@@", lines);
}
}
55 changes: 41 additions & 14 deletions 7sCarletSceneEditor/MainWindow.Designer.cs

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

0 comments on commit 14856a8

Please sign in to comment.