1
0
mirror of synced 2024-12-11 23:36:01 +01:00
Switch-Toolbox/File_Format_Library/GUI/Message/MSBTEditor.cs

99 lines
3.0 KiB
C#
Raw Normal View History

2019-04-22 04:00:38 +02:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Toolbox.Library.Forms;
using Toolbox.Library;
2019-04-22 04:00:38 +02:00
namespace FirstPlugin.Forms
{
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;
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;
hexEditor1.EnableMenuBar = false;
2019-04-22 04:00:38 +02:00
}
MSBT activeMessageFile;
public void LoadMSBT(MSBT msbt)
{
listViewCustom1.BeginUpdate();
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)
{
if (ShowLabels)
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 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);
}
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();
string listText = text.GetTextLabel(ShowPreviewText, msbt.header.StringEncoding);
2019-04-22 23:52:21 +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-04-22 23:52:21 +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
}
}
}