2019-04-22 04:00:38 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
2019-09-13 03:26:11 +02:00
|
|
|
|
using System.Drawing.Text;
|
2019-04-22 04:00:38 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2019-07-16 23:35:21 +02:00
|
|
|
|
using Toolbox.Library.Forms;
|
|
|
|
|
using Toolbox.Library;
|
2019-09-13 03:26:11 +02:00
|
|
|
|
using Toolbox.Library.IO;
|
2019-04-22 04:00:38 +02:00
|
|
|
|
|
|
|
|
|
namespace FirstPlugin.Forms
|
|
|
|
|
{
|
2019-06-14 00:40:29 +02:00
|
|
|
|
public partial class MSBTEditor : UserControl, IFIleEditor
|
2019-04-22 04:00:38 +02:00
|
|
|
|
{
|
2019-04-22 23:52:21 +02:00
|
|
|
|
public bool ShowPreviewText = true;
|
2019-08-11 02:52:58 +02:00
|
|
|
|
public bool ShowLabels = true;
|
2019-04-22 23:52:21 +02:00
|
|
|
|
|
2019-04-22 04:00:38 +02:00
|
|
|
|
public List<IFileFormat> GetFileFormats()
|
|
|
|
|
{
|
|
|
|
|
return new List<IFileFormat>() { activeMessageFile };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MSBTEditor()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
listViewCustom1.HeaderStyle = ColumnHeaderStyle.None;
|
2019-04-22 23:52:21 +02:00
|
|
|
|
listViewCustom1.FullRowSelect = true;
|
|
|
|
|
listViewCustom1.CanResizeList = false;
|
2019-04-30 21:25:42 +02:00
|
|
|
|
|
|
|
|
|
hexEditor1.EnableMenuBar = false;
|
2019-09-21 03:37:55 +02:00
|
|
|
|
|
|
|
|
|
Reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Reload()
|
|
|
|
|
{
|
|
|
|
|
string[] fontSizes = { "8", "9", "10", "11", "12", "14", "16", "18",
|
|
|
|
|
"20", "22", "24", "26", "28", "30", "36", "48", "72" };
|
|
|
|
|
|
|
|
|
|
FontFamily[] fontFamilies = new InstalledFontCollection().Families;
|
|
|
|
|
fontFamiltyCB.Items.Clear();
|
|
|
|
|
fontFamiltyCB.Items.AddRange(fontFamilies.Select(o => o.Name).ToArray());
|
|
|
|
|
fontFamiltyCB.SelectedText = Runtime.MessageEditor.FontFamily.Name;
|
|
|
|
|
|
|
|
|
|
fontSizeCB.Items.Clear();
|
|
|
|
|
fontSizeCB.Items.AddRange(fontSizes);
|
|
|
|
|
fontSizeCB.SelectedText = Runtime.MessageEditor.FontSize.ToString();
|
2019-04-22 04:00:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSBT activeMessageFile;
|
|
|
|
|
|
|
|
|
|
public void LoadMSBT(MSBT msbt)
|
|
|
|
|
{
|
2019-08-17 00:09:40 +02:00
|
|
|
|
listViewCustom1.BeginUpdate();
|
2019-08-11 01:20:39 +02:00
|
|
|
|
listViewCustom1.Items.Clear();
|
|
|
|
|
|
2019-04-22 04:00:38 +02:00
|
|
|
|
activeMessageFile = msbt;
|
2019-04-22 23:52:21 +02:00
|
|
|
|
|
|
|
|
|
if (msbt.header.Text2 != null)
|
|
|
|
|
{
|
2019-08-26 03:11:10 +02:00
|
|
|
|
if (ShowLabels && msbt.HasLabels)
|
2019-04-22 23:52:21 +02:00
|
|
|
|
{
|
2019-08-11 16:16:32 +02:00
|
|
|
|
foreach (var lbl in msbt.header.Label1.Labels)
|
2019-08-11 02:52:58 +02:00
|
|
|
|
{
|
2019-08-11 16:16:32 +02:00
|
|
|
|
ListViewItem item = new ListViewItem();
|
|
|
|
|
item.Text = lbl.Name;
|
|
|
|
|
item.Tag = msbt.header.Text2.TextData[(int)lbl.Index];
|
|
|
|
|
listViewCustom1.Items.Add(item);
|
2019-08-11 02:52:58 +02:00
|
|
|
|
}
|
|
|
|
|
listViewCustom1.Sorting = SortOrder.Ascending;
|
|
|
|
|
listViewCustom1.Sort();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var text in msbt.header.Text2.TextData)
|
|
|
|
|
{
|
2019-08-11 16:16:32 +02:00
|
|
|
|
ListViewItem item = new ListViewItem();
|
2019-08-11 02:52:58 +02:00
|
|
|
|
string listText = text.GetTextLabel(ShowPreviewText, msbt.header.StringEncoding);
|
2019-04-22 23:52:21 +02:00
|
|
|
|
|
2019-08-11 02:52:58 +02:00
|
|
|
|
if (listText.Length > 25)
|
|
|
|
|
listText = $"{listText.Substring(0, 25)}......";
|
2019-04-22 23:52:21 +02:00
|
|
|
|
|
2019-08-11 16:16:32 +02:00
|
|
|
|
item.Text = listText;
|
|
|
|
|
item.Tag = text;
|
|
|
|
|
listViewCustom1.Items.Add(item);
|
2019-08-11 02:52:58 +02:00
|
|
|
|
}
|
2019-04-22 23:52:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-17 00:09:40 +02:00
|
|
|
|
|
|
|
|
|
listViewCustom1.EndUpdate();
|
2019-04-22 23:52:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (activeMessageFile == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (listViewCustom1.SelectedItems.Count > 0)
|
|
|
|
|
{
|
2019-08-11 16:16:32 +02:00
|
|
|
|
var item = listViewCustom1.SelectedItems[0];
|
|
|
|
|
if (item.Tag is MSBT.StringEntry)
|
2019-04-22 23:52:21 +02:00
|
|
|
|
{
|
2019-08-11 16:16:32 +02:00
|
|
|
|
var msbtString = (MSBT.StringEntry)item.Tag;
|
|
|
|
|
|
|
|
|
|
editTextTB.Text = msbtString.GetText(activeMessageFile.header.StringEncoding);
|
|
|
|
|
originalTextTB.Text = msbtString.GetText(activeMessageFile.header.StringEncoding);
|
|
|
|
|
hexEditor1.LoadData(msbtString.Data);
|
2019-04-22 23:52:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-22 04:00:38 +02:00
|
|
|
|
}
|
2019-09-13 03:26:11 +02:00
|
|
|
|
|
|
|
|
|
private void UpdateFont(Font font)
|
|
|
|
|
{
|
|
|
|
|
editTextTB.Font = font;
|
|
|
|
|
originalTextTB.Font = font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadFontToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
|
|
ofd.Filter = "Supported Formats|*.bfttf; *.ttf;*.otf|" +
|
|
|
|
|
"Binary Cafe True Type Font |*.bfttf|" +
|
|
|
|
|
"True Type Font |*.ttf|" +
|
|
|
|
|
"Open Type Font |*.otf|" +
|
|
|
|
|
"All files(*.*)|*.*";
|
|
|
|
|
|
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (Utils.GetExtension(ofd.FileName) == ".bfttf")
|
|
|
|
|
{
|
|
|
|
|
BFTTF bfttf = (BFTTF)STFileLoader.OpenFileFormat(ofd.FileName);
|
|
|
|
|
var font = bfttf.ToFont(editTextTB.Font.Size);
|
|
|
|
|
UpdateFont(font);
|
|
|
|
|
bfttf.Unload();
|
|
|
|
|
}
|
|
|
|
|
else if (Utils.GetExtension(ofd.FileName) == ".ttf" ||
|
|
|
|
|
Utils.GetExtension(ofd.FileName) == ".otf")
|
|
|
|
|
{
|
|
|
|
|
PrivateFontCollection privateFonts = new PrivateFontCollection();
|
|
|
|
|
privateFonts.AddFontFile(ofd.FileName);
|
|
|
|
|
var font = privateFonts.Families[0];
|
|
|
|
|
UpdateFont(new Font(privateFonts.Families[0], editTextTB.Font.Size));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-21 03:37:55 +02:00
|
|
|
|
|
|
|
|
|
private void fontFamiltyCB_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ReloadFont();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fontSizeCB_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ReloadFont();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReloadFont()
|
|
|
|
|
{
|
|
|
|
|
float fontSize = 12;
|
|
|
|
|
float.TryParse(fontSizeCB.Text, out fontSize);
|
|
|
|
|
originalTextTB.Font = new Font(fontFamiltyCB.Text, fontSize);
|
|
|
|
|
editTextTB.Font = new Font(fontFamiltyCB.Text, fontSize);
|
|
|
|
|
|
|
|
|
|
// Runtime.MessageEditor.FontFamily = fontFamiltyCB.SelectedText;
|
|
|
|
|
// Runtime.MessageEditor.FontSize = fontSize;
|
|
|
|
|
}
|
2019-04-22 04:00:38 +02:00
|
|
|
|
}
|
|
|
|
|
}
|