2019-09-04 00:58:58 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Syroot.NintenTools.Bfres;
|
|
|
|
|
|
|
|
|
|
namespace LayoutBXLYT
|
|
|
|
|
{
|
|
|
|
|
public partial class UserDataEditor : UserControl
|
|
|
|
|
{
|
|
|
|
|
public UserDataEditor()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
listViewCustom1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 23:02:25 +02:00
|
|
|
|
BasePane activePane;
|
|
|
|
|
UserData ActiveUserData;
|
2019-09-04 00:58:58 +02:00
|
|
|
|
UserDataEntry SelectedEntry;
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
2019-10-13 23:02:25 +02:00
|
|
|
|
ActiveUserData = new UserData();
|
2019-09-04 00:58:58 +02:00
|
|
|
|
SelectedEntry = null;
|
|
|
|
|
listViewCustom1.Items.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 23:02:25 +02:00
|
|
|
|
public void LoadUserData(BasePane pane, UserData UserData)
|
2019-09-04 00:58:58 +02:00
|
|
|
|
{
|
2019-10-13 23:02:25 +02:00
|
|
|
|
activePane = pane;
|
|
|
|
|
if (UserData != null)
|
|
|
|
|
{
|
|
|
|
|
listViewCustom1.Items.Clear();
|
2019-09-04 00:58:58 +02:00
|
|
|
|
|
2019-10-13 23:02:25 +02:00
|
|
|
|
ActiveUserData = UserData;
|
|
|
|
|
foreach (var item in ActiveUserData.Entries)
|
|
|
|
|
LoadUserData(item);
|
|
|
|
|
}
|
2019-09-04 00:58:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadUserData(UserDataEntry item)
|
|
|
|
|
{
|
|
|
|
|
ListViewItem listItem = new ListViewItem();
|
|
|
|
|
listItem.Text = item.Name;
|
|
|
|
|
listItem.SubItems.Add(item.Type.ToString());
|
|
|
|
|
|
|
|
|
|
string value = "";
|
|
|
|
|
|
|
|
|
|
switch (item.Type)
|
|
|
|
|
{
|
|
|
|
|
case UserDataType.String:
|
|
|
|
|
if (item.GetString() != null)
|
|
|
|
|
{
|
|
|
|
|
value += $" {item.GetString()}";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case UserDataType.Float:
|
|
|
|
|
if (item.GetFloats() != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var val in item.GetFloats())
|
|
|
|
|
value += $" {val}";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case UserDataType.Int:
|
|
|
|
|
if (item.GetInts() != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var val in item.GetInts())
|
|
|
|
|
value += $" {val}";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
listItem.SubItems.Add(value);
|
|
|
|
|
|
|
|
|
|
listViewCustom1.Items.Add(listItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listViewCustom1.SelectedItems.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
btnScrolDown.Enabled = true;
|
|
|
|
|
btnScrollUp.Enabled = true;
|
|
|
|
|
btnEdit.Enabled = true;
|
|
|
|
|
btnRemove.Enabled = true;
|
|
|
|
|
|
2019-10-13 23:02:25 +02:00
|
|
|
|
SelectedEntry = ActiveUserData.Entries[listViewCustom1.SelectedIndices[0]];
|
2019-09-04 00:58:58 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SelectedEntry = null;
|
|
|
|
|
btnScrolDown.Enabled = false;
|
|
|
|
|
btnScrollUp.Enabled = false;
|
|
|
|
|
btnEdit.Enabled = false;
|
|
|
|
|
btnRemove.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnEdit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EditData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-10-13 23:02:25 +02:00
|
|
|
|
if (activePane == null) return;
|
|
|
|
|
|
2019-09-04 00:58:58 +02:00
|
|
|
|
UserDataEntry userDataNew = new UserDataEntry();
|
|
|
|
|
userDataNew.SetValue(new int[0]);
|
|
|
|
|
SelectedEntry = userDataNew;
|
|
|
|
|
bool IsEdited = EditData();
|
|
|
|
|
if (IsEdited)
|
|
|
|
|
{
|
2019-10-13 23:02:25 +02:00
|
|
|
|
ActiveUserData.Entries.Add(userDataNew);
|
2019-09-04 00:58:58 +02:00
|
|
|
|
LoadUserData(userDataNew);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private bool EditData()
|
2019-10-13 23:02:25 +02:00
|
|
|
|
|
2019-09-04 00:58:58 +02:00
|
|
|
|
{
|
|
|
|
|
if (SelectedEntry != null)
|
|
|
|
|
{
|
|
|
|
|
UserDataParser parser = new UserDataParser();
|
|
|
|
|
parser.UserDataName = SelectedEntry.Name;
|
2019-09-04 01:23:04 +02:00
|
|
|
|
parser.Type = SelectedEntry.Type;
|
2019-09-04 00:58:58 +02:00
|
|
|
|
|
|
|
|
|
switch (SelectedEntry.Type)
|
|
|
|
|
{
|
|
|
|
|
case UserDataType.String:
|
|
|
|
|
if (SelectedEntry.GetString() != null)
|
|
|
|
|
parser.LoadValues(SelectedEntry.GetString());
|
|
|
|
|
break;
|
|
|
|
|
case UserDataType.Float:
|
|
|
|
|
if (SelectedEntry.GetString() != null)
|
|
|
|
|
parser.LoadValues(SelectedEntry.GetFloats());
|
|
|
|
|
break;
|
|
|
|
|
case UserDataType.Int:
|
|
|
|
|
if (SelectedEntry.GetInts() != null)
|
|
|
|
|
parser.LoadValues(SelectedEntry.GetInts());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (parser.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
SelectedEntry.Name = parser.UserDataName;
|
|
|
|
|
|
2019-09-04 01:23:04 +02:00
|
|
|
|
if (parser.Type == UserDataType.Float)
|
2019-09-04 00:58:58 +02:00
|
|
|
|
SelectedEntry.SetValue(parser.GetFloats());
|
2019-09-04 01:23:04 +02:00
|
|
|
|
if (parser.Type == UserDataType.Int)
|
2019-09-04 00:58:58 +02:00
|
|
|
|
SelectedEntry.SetValue(parser.GetInts());
|
2019-09-04 01:23:04 +02:00
|
|
|
|
if (parser.Type == UserDataType.String)
|
2019-09-04 00:58:58 +02:00
|
|
|
|
SelectedEntry.SetValue(parser.GetStringASCII());
|
|
|
|
|
|
2019-10-13 23:02:25 +02:00
|
|
|
|
if (ActiveUserData == null)
|
|
|
|
|
ActiveUserData = activePane.CreateUserData();
|
|
|
|
|
|
|
|
|
|
LoadUserData(activePane, ActiveUserData);
|
2019-09-04 00:58:58 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnRemove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listViewCustom1.SelectedIndices.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
int index = listViewCustom1.SelectedIndices[0];
|
|
|
|
|
listViewCustom1.Items.RemoveAt(index);
|
|
|
|
|
|
|
|
|
|
if (ActiveUserData != null)
|
2019-10-13 23:02:25 +02:00
|
|
|
|
ActiveUserData.Entries.RemoveAt(index);
|
2019-09-04 00:58:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void listViewCustom1_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EditData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|