Update v2 aamp editor
This commit is contained in:
parent
9b5e558543
commit
3ab5e02d5b
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -22,17 +22,6 @@ namespace FirstPlugin.Forms
|
||||
LoadFile(aamp.aampFileV1, treeView1.Nodes[0]);
|
||||
}
|
||||
|
||||
public void LoadImages(TreeView treeView, TreeNode parentNode)
|
||||
{
|
||||
foreach (TreeNode nodes in TreeViewExtensions.Collect(parentNode.Nodes))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
foreach (var image in Images)
|
||||
treeView.ImageList.Images.Add(image);
|
||||
}
|
||||
|
||||
public void LoadFile(AampFile aampFile, TreeNode parentNode)
|
||||
{
|
||||
LoadChildNodes(aampFile.RootNode, parentNode);
|
||||
|
@ -10,13 +10,16 @@ using System.Windows.Forms;
|
||||
using AampV2Library;
|
||||
using Syroot.Maths;
|
||||
using Switch_Toolbox.Library;
|
||||
using Switch_Toolbox.Library.Forms;
|
||||
|
||||
namespace FirstPlugin.Forms
|
||||
{
|
||||
public partial class AampV2Editor : AampEditorBase
|
||||
{
|
||||
public AampV2Editor(AAMP aamp, bool IsSaveDialog) : base (aamp, IsSaveDialog)
|
||||
public AampV2Editor(AAMP aamp, bool IsSaveDialog) : base(aamp, IsSaveDialog)
|
||||
{
|
||||
treeView1.Nodes.Add(aamp.FileName);
|
||||
LoadFile(aamp.aampFileV2, treeView1.Nodes[0]);
|
||||
}
|
||||
|
||||
public void LoadFile(AampFile aampFile, TreeNode parentNode)
|
||||
@ -24,27 +27,150 @@ namespace FirstPlugin.Forms
|
||||
LoadChildNodes(aampFile.RootNode, parentNode);
|
||||
}
|
||||
|
||||
public void LoadImages(TreeView treeView, TreeNode parentNode)
|
||||
public override void TreeView_AfterSelect()
|
||||
{
|
||||
foreach (TreeNode nodes in TreeViewExtensions.Collect(parentNode.Nodes))
|
||||
var node = treeView1.SelectedNode;
|
||||
|
||||
if (node.Tag != null)
|
||||
{
|
||||
if (nodes is EditableEntry)
|
||||
if (node.Tag is ParamObject)
|
||||
{
|
||||
if (((EditableEntry)nodes).entry.ParamType == ParamType.Color4F)
|
||||
{
|
||||
nodes.ImageIndex += treeView.ImageList.Images.Count;
|
||||
nodes.SelectedImageIndex = nodes.ImageIndex;
|
||||
}
|
||||
LoadObjectDataList((ParamObject)node.Tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var image in Images)
|
||||
treeView.ImageList.Images.Add(image);
|
||||
public override void AddParamEntry(TreeNode parentNode)
|
||||
{
|
||||
if (parentNode.Tag != null && parentNode.Tag is ParamObject)
|
||||
{
|
||||
ParamEntry entry = new ParamEntry();
|
||||
entry.ParamType = ParamType.Float;
|
||||
entry.HashString = "NewEntry";
|
||||
entry.Value = 0;
|
||||
|
||||
ListViewItem item = new ListViewItem();
|
||||
SetListItemParamObject(entry, item);
|
||||
|
||||
OpenNewParamEditor(entry, (ParamObject)parentNode.Tag, item);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenameParamEntry(ListViewItem SelectedItem)
|
||||
{
|
||||
if (SelectedItem.Tag != null && SelectedItem.Tag is ParamEntry)
|
||||
{
|
||||
RenameDialog dialog = new RenameDialog();
|
||||
dialog.SetString(SelectedItem.Text);
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string NewString = dialog.textBox1.Text;
|
||||
|
||||
((ParamEntry)SelectedItem.Tag).HashString = NewString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEditorClick(ListViewItem SelectedItem)
|
||||
{
|
||||
if (SelectedItem.Tag != null && SelectedItem.Tag is ParamEntry)
|
||||
{
|
||||
OpenEditor((ParamEntry)SelectedItem.Tag, SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadObjectDataList(ParamObject paramObj)
|
||||
{
|
||||
listViewCustom1.Items.Clear();
|
||||
foreach (var entry in paramObj.paramEntries)
|
||||
{
|
||||
ListViewItem item = new ListViewItem(entry.HashString);
|
||||
SetListItemParamObject(entry, item);
|
||||
listViewCustom1.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetListItemParamObject(ParamEntry entry, ListViewItem item)
|
||||
{
|
||||
item.SubItems.Clear();
|
||||
item.Text = entry.HashString;
|
||||
item.Tag = entry;
|
||||
item.UseItemStyleForSubItems = false;
|
||||
item.SubItems.Add(entry.ParamType.ToString());
|
||||
string ValueText = "";
|
||||
|
||||
System.Drawing.Color color = System.Drawing.Color.Empty;
|
||||
|
||||
switch (entry.ParamType)
|
||||
{
|
||||
case ParamType.Boolean:
|
||||
case ParamType.Float:
|
||||
case ParamType.Int:
|
||||
case ParamType.Uint:
|
||||
ValueText = $"{entry.Value}";
|
||||
break;
|
||||
case ParamType.String64:
|
||||
case ParamType.String32:
|
||||
case ParamType.String256:
|
||||
case ParamType.StringRef:
|
||||
string enocdedString = Encoding.UTF8.GetString((byte[])entry.Value);
|
||||
ValueText = $"{enocdedString}";
|
||||
break;
|
||||
case ParamType.Vector2F:
|
||||
var vec2 = (Vector2F)entry.Value;
|
||||
ValueText = $"{vec2.X} {vec2.Y}";
|
||||
break;
|
||||
case ParamType.Vector3F:
|
||||
var vec3 = (Vector3F)entry.Value;
|
||||
ValueText = $"{vec3.X} {vec3.Y} {vec3.Z}";
|
||||
break;
|
||||
case ParamType.Vector4F:
|
||||
var vec4 = (Vector4F)entry.Value;
|
||||
ValueText = $"{vec4.X} {vec4.Y} {vec4.Z} {vec4.W}";
|
||||
break;
|
||||
case ParamType.Color4F:
|
||||
var col = (Vector4F)entry.Value;
|
||||
ValueText = $"{col.X} {col.Y} {col.Z} {col.W}";
|
||||
|
||||
int ImageIndex = Images.Count;
|
||||
|
||||
color = System.Drawing.Color.FromArgb(
|
||||
EditBox.FloatToIntClamp(col.W),
|
||||
EditBox.FloatToIntClamp(col.X),
|
||||
EditBox.FloatToIntClamp(col.Y),
|
||||
EditBox.FloatToIntClamp(col.Z));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
item.SubItems.Add(ValueText);
|
||||
|
||||
if (color != System.Drawing.Color.Empty)
|
||||
item.SubItems[2].BackColor = color;
|
||||
}
|
||||
|
||||
public override void OnEntryDeletion(object obj, TreeNode objNode)
|
||||
{
|
||||
if (obj is ParamEntry)
|
||||
{
|
||||
var paramObjectParent = (ParamObject)objNode.Tag;
|
||||
|
||||
var entryList = new List<ParamEntry>();
|
||||
for (int i = 0; i < paramObjectParent.paramEntries.Length; i++)
|
||||
entryList.Add(paramObjectParent.paramEntries[i]);
|
||||
|
||||
entryList.Remove((ParamEntry)obj);
|
||||
|
||||
paramObjectParent.paramEntries = entryList.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadChildNodes(ParamList paramList, TreeNode parentNode)
|
||||
{
|
||||
TreeNode newNode = new TreeNode(paramList.HashString);
|
||||
newNode.Tag = paramList;
|
||||
|
||||
parentNode.Nodes.Add(newNode);
|
||||
|
||||
//Add lists and objects if exits
|
||||
@ -59,133 +185,51 @@ namespace FirstPlugin.Forms
|
||||
|
||||
//Add object nodes
|
||||
foreach (var obj in paramList.paramObjects)
|
||||
LoadObjectNodes(obj, newNode.Nodes["obj"]);
|
||||
}
|
||||
|
||||
public void LoadObjectNodes(ParamObject paramObject, TreeNode parentNode)
|
||||
{
|
||||
TreeNode objNode = new TreeNode(paramObject.HashString);
|
||||
parentNode.Nodes.Add(objNode);
|
||||
|
||||
foreach (var entry in paramObject.paramEntries)
|
||||
{
|
||||
EditableEntry entryNode = new EditableEntry($"{entry.HashString}");
|
||||
entryNode.entry = entry;
|
||||
objNode.Nodes.Add(entryNode);
|
||||
|
||||
UpdateEntryNode(entryNode, entry);
|
||||
}
|
||||
SetObjNode(obj, newNode.Nodes["obj"]);
|
||||
}
|
||||
|
||||
List<Bitmap> Images = new List<Bitmap>();
|
||||
|
||||
public void UpdateEntryNode(EditableEntry node, ParamEntry entry)
|
||||
void SetObjNode(ParamObject paramObj, TreeNode parentNode)
|
||||
{
|
||||
node.ImageKey = "empty";
|
||||
node.SelectedImageKey = "empty";
|
||||
string name = paramObj.HashString;
|
||||
|
||||
switch (entry.ParamType)
|
||||
var objNode = new TreeNode(name);
|
||||
objNode.Tag = paramObj;
|
||||
parentNode.Nodes.Add(objNode);
|
||||
}
|
||||
|
||||
private void OpenNewParamEditor(ParamEntry entry, ParamObject paramObject, ListViewItem SelectedItem)
|
||||
{
|
||||
EditBox editor = new EditBox();
|
||||
editor.LoadEntry(entry);
|
||||
editor.ToggleNameEditing(true);
|
||||
|
||||
if (editor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
case ParamType.Boolean:
|
||||
case ParamType.Float:
|
||||
case ParamType.Int:
|
||||
case ParamType.Uint:
|
||||
case ParamType.String64:
|
||||
case ParamType.String32:
|
||||
case ParamType.String256:
|
||||
case ParamType.StringRef:
|
||||
node.Text = $"{entry.HashString} {entry.Value}";
|
||||
break;
|
||||
case ParamType.Vector2F:
|
||||
var vec2 = (Vector2F)entry.Value;
|
||||
node.Text = $"{entry.HashString} {vec2.X} {vec2.Y}";
|
||||
break;
|
||||
case ParamType.Vector3F:
|
||||
var vec3 = (Vector3F)entry.Value;
|
||||
node.Text = $"{entry.HashString} {vec3.X} {vec3.Y} {vec3.Z}";
|
||||
break;
|
||||
case ParamType.Vector4F:
|
||||
var vec4 = (Vector4F)entry.Value;
|
||||
node.Text = $"{entry.HashString} {vec4.X} {vec4.Y} {vec4.Z} {vec4.W}";
|
||||
break;
|
||||
case ParamType.Color4F:
|
||||
var col = (Vector4F)entry.Value;
|
||||
node.Text = $"{entry.HashString} {col.X} {col.Y} {col.Z} {col.W}";
|
||||
editor.SaveEntry();
|
||||
SetListItemParamObject(entry, SelectedItem);
|
||||
listViewCustom1.Items.Add(SelectedItem);
|
||||
|
||||
int ImageIndex = Images.Count;
|
||||
node.ImageIndex = ImageIndex;
|
||||
var entryList = new List<ParamEntry>();
|
||||
for (int i = 0; i < paramObject.paramEntries.Length; i++)
|
||||
entryList.Add(paramObject.paramEntries[i]);
|
||||
|
||||
var color = System.Drawing.Color.FromArgb(
|
||||
Utils.FloatToIntClamp(col.W),
|
||||
Utils.FloatToIntClamp(col.X),
|
||||
Utils.FloatToIntClamp(col.Y),
|
||||
Utils.FloatToIntClamp(col.Z));
|
||||
|
||||
Bitmap bmp = new Bitmap(32, 32);
|
||||
Graphics g = Graphics.FromImage(bmp);
|
||||
g.Clear(color);
|
||||
|
||||
Images.Add(bmp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
entryList.Add(entry);
|
||||
paramObject.paramEntries = entryList.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class EditableEntry : TreeNode
|
||||
private void OpenEditor(ParamEntry entry, ListViewItem SelectedItem)
|
||||
{
|
||||
public ParamEntry entry;
|
||||
public EditableEntry(string name)
|
||||
EditBox editor = new EditBox();
|
||||
editor.LoadEntry(entry);
|
||||
editor.ToggleNameEditing(true);
|
||||
|
||||
if (editor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Text = name;
|
||||
|
||||
ContextMenu = new ContextMenu();
|
||||
ContextMenu.MenuItems.Add(new MenuItem("Edit", OpenEditor));
|
||||
}
|
||||
|
||||
private void OpenEditor(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("Editing v2 AAMP not supported yet. Only v1", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
return;
|
||||
|
||||
EditBox editor = new EditBox();
|
||||
editor.LoadEntry(entry);
|
||||
|
||||
if (editor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
editor.SaveEntry();
|
||||
|
||||
switch (entry.ParamType)
|
||||
{
|
||||
case ParamType.Boolean:
|
||||
case ParamType.Float:
|
||||
case ParamType.Int:
|
||||
case ParamType.Uint:
|
||||
case ParamType.String64:
|
||||
case ParamType.String32:
|
||||
case ParamType.String256:
|
||||
case ParamType.StringRef:
|
||||
Text = $"{entry.HashString} {entry.Value}";
|
||||
break;
|
||||
case ParamType.Vector2F:
|
||||
var vec2 = (Vector2F)entry.Value;
|
||||
Text = $"{entry.HashString} {vec2.X} {vec2.Y}";
|
||||
break;
|
||||
case ParamType.Vector3F:
|
||||
var vec3 = (Vector3F)entry.Value;
|
||||
Text = $"{entry.HashString} {vec3.X} {vec3.Y} {vec3.Z}";
|
||||
break;
|
||||
case ParamType.Vector4F:
|
||||
var vec4 = (Vector4F)entry.Value;
|
||||
Text = $"{entry.HashString} {vec4.X} {vec4.Y} {vec4.Z} {vec4.W}";
|
||||
break;
|
||||
case ParamType.Color4F:
|
||||
var col = (Vector4F)entry.Value;
|
||||
Text = $"{entry.HashString} {col.X} {col.Y} {col.Z} {col.W}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
editor.SaveEntry();
|
||||
SetListItemParamObject(entry, SelectedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user