2020-02-06 23:20:42 +00:00
|
|
|
|
using System;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2020-02-06 23:20:42 +00:00
|
|
|
|
using System.Data;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2020-02-06 23:20:42 +00:00
|
|
|
|
using AampLibraryCSharp;
|
|
|
|
|
using Syroot.Maths;
|
2019-07-16 21:35:21 +00:00
|
|
|
|
using Toolbox.Library;
|
2020-02-06 23:20:42 +00:00
|
|
|
|
using Toolbox.Library.Forms;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
|
|
|
|
namespace FirstPlugin.Forms
|
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public partial class AampEditor : AampEditorBase
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public AampEditor(AAMP aamp, bool IsSaveDialog) : base(aamp, IsSaveDialog)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
treeView1.Nodes.Add(aamp.FileName);
|
|
|
|
|
LoadFile(aamp.aampFile, treeView1.Nodes[0]);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public void LoadFile(AampFile aampFile, TreeNode parentNode)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
LoadChildNodes(aampFile.RootNode, parentNode);
|
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public override void TreeView_AfterSelect()
|
|
|
|
|
{
|
|
|
|
|
var node = treeView1.SelectedNode;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (node.Tag != null)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (node.Tag is ParamObject) {
|
|
|
|
|
LoadObjectDataList((ParamObject)node.Tag);
|
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
2019-05-03 19:36:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public override void AddParamEntry(TreeNode parentNode)
|
2019-05-03 19:36:04 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (parentNode.Tag != null && parentNode.Tag is ParamObject)
|
2019-05-03 19:36:04 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
ParamEntry entry = new ParamEntry();
|
|
|
|
|
entry.ParamType = ParamType.Float;
|
|
|
|
|
entry.HashString = "NewEntry";
|
|
|
|
|
entry.Value = 0;
|
|
|
|
|
|
|
|
|
|
ListViewItem item = new ListViewItem();
|
|
|
|
|
SetListItemParamObject(entry, item);
|
2019-05-03 19:36:04 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
OpenNewParamEditor(entry,(ParamObject)parentNode.Tag, item);
|
2019-05-03 19:36:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public override void RenameParamEntry(ListViewItem SelectedItem)
|
2019-05-03 19:36:04 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (SelectedItem.Tag != null && SelectedItem.Tag is ParamEntry)
|
2019-05-03 19:36:04 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
RenameDialog dialog = new RenameDialog();
|
|
|
|
|
dialog.SetString(SelectedItem.Text);
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string NewString = dialog.textBox1.Text;
|
|
|
|
|
|
|
|
|
|
((ParamEntry)SelectedItem.Tag).HashString = NewString;
|
|
|
|
|
}
|
2019-05-03 19:36:04 +00:00
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public override void OnEditorClick(ListViewItem SelectedItem)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (SelectedItem.Tag != null && SelectedItem.Tag is ParamEntry)
|
|
|
|
|
{
|
|
|
|
|
OpenEditor((ParamEntry)SelectedItem.Tag, SelectedItem);
|
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
private void LoadObjectDataList(ParamObject paramObj)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
listViewCustom1.Items.Clear();
|
|
|
|
|
foreach (var entry in paramObj.paramEntries)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
ListViewItem item = new ListViewItem(entry.HashString);
|
|
|
|
|
SetListItemParamObject(entry, item);
|
|
|
|
|
listViewCustom1.Items.Add(item);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
private void SetListItemParamObject(ParamEntry entry, ListViewItem item)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
item.SubItems.Clear();
|
|
|
|
|
item.Text = entry.HashString;
|
|
|
|
|
item.Tag = entry;
|
|
|
|
|
item.UseItemStyleForSubItems = false;
|
|
|
|
|
item.SubItems.Add(entry.ParamType.ToString());
|
|
|
|
|
string ValueText = "";
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
System.Drawing.Color color = System.Drawing.Color.Empty;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
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:
|
|
|
|
|
ValueText = $"{((AampLibraryCSharp.StringEntry)entry.Value).ToString()}";
|
|
|
|
|
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;
|
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
item.SubItems.Add(ValueText);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (color != System.Drawing.Color.Empty)
|
|
|
|
|
item.SubItems[2].BackColor = color;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public override void OnEntryDeletion(object obj, TreeNode objNode)
|
|
|
|
|
{
|
|
|
|
|
if (obj is ParamEntry)
|
|
|
|
|
{
|
|
|
|
|
var paramObjectParent = (ParamObject)objNode.Tag;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
var entryList = new List<ParamEntry>();
|
|
|
|
|
for (int i = 0; i < paramObjectParent.paramEntries.Length; i++)
|
|
|
|
|
entryList.Add(paramObjectParent.paramEntries[i]);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
entryList.Remove((ParamEntry)obj);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
paramObjectParent.paramEntries = entryList.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
public void LoadChildNodes(ParamList paramList, TreeNode parentNode)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
TreeNode newNode = new TreeNode(paramList.HashString);
|
|
|
|
|
newNode.Tag = paramList;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
parentNode.Nodes.Add(newNode);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
//Add lists and objects if exits
|
|
|
|
|
if (paramList.childParams.Length > 0)
|
|
|
|
|
newNode.Nodes.Add("list", "Lists {}");
|
|
|
|
|
if (paramList.paramObjects.Length > 0)
|
|
|
|
|
newNode.Nodes.Add("obj", "Objects {}");
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
//Add child nodes
|
|
|
|
|
foreach (var child in paramList.childParams)
|
|
|
|
|
LoadChildNodes(child, newNode.Nodes["list"]);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
//Add object nodes
|
|
|
|
|
foreach (var obj in paramList.paramObjects)
|
|
|
|
|
SetObjNode(obj, newNode.Nodes["obj"]);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
List<Bitmap> Images = new List<Bitmap>();
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
void SetObjNode(ParamObject paramObj, TreeNode parentNode)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
string name = paramObj.HashString;
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
var objNode = new TreeNode(name);
|
|
|
|
|
objNode.Tag = paramObj;
|
|
|
|
|
parentNode.Nodes.Add(objNode);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
private void OpenNewParamEditor(ParamEntry entry, ParamObject paramObject, ListViewItem SelectedItem)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
EditBox editor = new EditBox();
|
|
|
|
|
editor.LoadEntry(entry);
|
|
|
|
|
editor.ToggleNameEditing(true);
|
|
|
|
|
|
|
|
|
|
if (editor.ShowDialog() == DialogResult.OK)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
editor.SaveEntry();
|
|
|
|
|
SetListItemParamObject(entry, SelectedItem);
|
|
|
|
|
listViewCustom1.Items.Add(SelectedItem);
|
|
|
|
|
|
|
|
|
|
var entryList = new List<ParamEntry>();
|
|
|
|
|
for (int i = 0; i < paramObject.paramEntries.Length; i++)
|
|
|
|
|
entryList.Add(paramObject.paramEntries[i]);
|
|
|
|
|
|
|
|
|
|
entryList.Add(entry);
|
|
|
|
|
paramObject.paramEntries = entryList.ToArray();
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
private void OpenEditor(ParamEntry entry, ListViewItem SelectedItem)
|
2019-04-25 19:21:41 +00:00
|
|
|
|
{
|
2020-02-06 23:20:42 +00:00
|
|
|
|
EditBox editor = new EditBox();
|
|
|
|
|
editor.LoadEntry(entry);
|
|
|
|
|
editor.ToggleNameEditing(true);
|
2019-04-25 19:21:41 +00:00
|
|
|
|
|
2020-02-06 23:20:42 +00:00
|
|
|
|
if (editor.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
editor.SaveEntry();
|
|
|
|
|
SetListItemParamObject(entry, SelectedItem);
|
|
|
|
|
}
|
2019-04-25 19:21:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|