Switch-Toolbox/File_Format_Library/GUI/BFLYT/UserDataEditor.cs
KillzXGaming 4a92d0320a Some fixes.
USD1 fixes and also start to impliment an editor for USD1.
Fix L8 and LA8 displaying.
Fix channel compents. Temporaily uses the swizzle parameter. Todo, do these by shader.
Material saving fixes for bflyt version 8 and higher
2019-09-03 18:58:58 -04:00

176 lines
5.5 KiB
C#

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;
}
List<UserDataEntry> ActiveUserData;
UserDataEntry SelectedEntry;
public void Reset()
{
ActiveUserData = new List<UserDataEntry>();
SelectedEntry = null;
listViewCustom1.Items.Clear();
}
bool IsWiiU = false;
public void LoadUserData(List<UserDataEntry> UserDataList)
{
listViewCustom1.Items.Clear();
ActiveUserData = UserDataList;
foreach (var item in ActiveUserData)
LoadUserData(item);
}
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;
if (IsWiiU)
SelectedEntry = ActiveUserData[listViewCustom1.SelectedIndices[0]];
}
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)
{
UserDataEntry userDataNew = new UserDataEntry();
userDataNew.SetValue(new int[0]);
SelectedEntry = userDataNew;
bool IsEdited = EditData();
if (IsEdited)
{
ActiveUserData.Add(userDataNew);
LoadUserData(userDataNew);
}
}
private bool EditData()
{
if (SelectedEntry != null)
{
UserDataParser parser = new UserDataParser();
parser.UserDataName = SelectedEntry.Name;
parser.Type = SelectedEntry.Type.ToString();
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;
if (parser.Type == "Single")
SelectedEntry.SetValue(parser.GetFloats());
if (parser.Type == "Int32")
SelectedEntry.SetValue(parser.GetInts());
if (parser.Type == "String")
SelectedEntry.SetValue(parser.GetStringASCII());
LoadUserData(ActiveUserData);
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)
ActiveUserData.RemoveAt(index);
}
}
private void listViewCustom1_DoubleClick(object sender, EventArgs e)
{
EditData();
}
}
}