Skip to content

Commit

Permalink
User Template nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fronkln committed Nov 29, 2024
1 parent a7123f9 commit a51e5c2
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Projects/CMNEdit/CMNEdit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@
</None>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(ProjectDir)config\*.*&quot; &quot;$(OutDir)\config&quot; /Y /I /E" />
</Target>

</Project>
9 changes: 9 additions & 0 deletions Projects/CMNEdit/NumberBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public enum NumberMode
{
Text,
Byte,
Short,
Ushort,
Int,
UInt,
Float,
Long,
ULong,
}

private NumberMode mode;
Expand Down Expand Up @@ -54,6 +56,13 @@ public static bool Validate(string text, NumberMode mode)
case NumberMode.Long:
long l;
return long.TryParse(text, out l);
case NumberMode.ULong:
ulong ul;
return ulong.TryParse(text, out ul);

case NumberMode.Short:
short s;
return short.TryParse(text, out s);

case NumberMode.Ushort:
ushort us;
Expand Down
34 changes: 34 additions & 0 deletions Projects/CMNEdit/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using HActLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -14,11 +16,43 @@ internal static class Program
[STAThread]
static void Main()
{
string directoryDir = "config";

if(Directory.Exists(directoryDir))
{
string gamesFile = Path.Combine(directoryDir, "games.txt");

if(File.Exists(gamesFile))
{
string[] gameDirs = File.ReadAllLines(gamesFile);

foreach(string str in gameDirs)
{
string gameDir = Path.Combine(directoryDir, "game", str);

if(Directory.Exists(gameDir))
{
string nodesDir = Path.Combine(gameDir, "nodes");

if(Directory.Exists(nodesDir))
{
foreach(string nodeFile in Directory.GetFiles(nodesDir, "*.txt"))
{
UserElementFile file = UserElementFile.Read(nodeFile);
HActLib.Internal.Reflection.RegisterUserNode(file.TargetGame, file.Data);
}
}
}
}
}
}

Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppRegistry.Init();
Application.Run(new Form1());

}
}
}
8 changes: 7 additions & 1 deletion Projects/CMNEdit/TreeView/TreeViewItemNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ string TranslateElement()

if (!isOE)
{
switch(nodeName)
if (node is NodeElementUser)
return (node as NodeElementUser).UserData.NodeName.Replace("_", " ");

switch (nodeName)
{
case "e_auth_element_particle":
DEElementParticle particleElem = node as DEElementParticle;
Expand Down Expand Up @@ -262,6 +265,9 @@ string TranslateElement()
OEElementSE seElem = node as OEElementSE;
return $"Sound Cue {seElem.Cuesheet.ToString("x")} ID {seElem.Sound}";
}

if (node is NodeElementUser)
return (node as NodeElementUser).UserData.NodeName;
}

return nodeName.Replace("e_auth_element_", "").Replace("_", " ").ToTitleCase();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions Projects/CMNEdit/Types/UserElementFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using HActLib;
using System;
using System.Collections.Generic;
using System.IO;

namespace CMNEdit
{
public class UserElementFile
{
public Game TargetGame;
public UserElementData Data = new UserElementData();

public static UserElementFile Read(string path)
{
if (!File.Exists(path))
return null;

string[] buf = File.ReadAllLines(path);

if(buf.Length <= 0)
return null;

string[] split = buf[0].Split(' ');

if (split.Length < 4)
return null;

object gameVal = null;

if (!Enum.TryParse(typeof(Game), split[0], out gameVal))
return null;

UserElementFile file = new UserElementFile();
file.TargetGame = (Game)gameVal;
file.Data.DeveloperName = split[1];
file.Data.NodeName = split[2];
file.Data.ElementID = uint.Parse(split[3]);

if (buf.Length <= 1)
return file;

for (int i = 1; i < buf.Length; i++)
{
if (string.IsNullOrEmpty(buf[i]))
continue;

string[] fieldDat = buf[i].Split(new char[] { ' ' });

if (fieldDat.Length < 2)
continue;

string name = fieldDat[1];
string type = fieldDat[0]; //rest is args

object typeObject = null;

if (!Enum.TryParse(typeof(UserElementFieldType), type, true, out typeObject))
continue;

UserElementField field = new UserElementField();
field.FieldType = (UserElementFieldType)typeObject;
field.Name = name;

if(fieldDat.Length > 2)
for(int k = 2; k < fieldDat.Length; k++)
field.Args.Add(fieldDat[k]);

file.Data.Fields.Add(field);
}

return file;
}
}
}
7 changes: 5 additions & 2 deletions Projects/CMNEdit/Windows/Common/DrawWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static void Draw(NodeElement element)

string elemName = HActLib.Internal.Reflection.GetElementNameByID(element.ElementKind, Form1.curGame);

if (element is NodeElementUser)
NodeElementUserWindow.Draw(Form1.Instance, element);

if (Form1.curVer == GameVersion.Y0_K1)
{
switch (elemName)
Expand Down Expand Up @@ -243,10 +246,10 @@ public static void Draw(NodeElement element)
DEElementBattleSlideWindow.Draw(Form1.Instance, element);
break;
case "e_auth_element_spot_light":
DEElementLightSpotWindow.Draw(Form1.Instance, element);
//DEElementLightSpotWindow.Draw(Form1.Instance, element);
break;
case "e_auth_element_point_light":
DEElementLightPointWindow.Draw(Form1.Instance, element);
//DEElementLightPointWindow.Draw(Form1.Instance, element);
break;
case "e_auth_element_chromatic_aberration":
DEElementChromaticAberrationWindow.Draw(Form1.Instance, element);
Expand Down
101 changes: 101 additions & 0 deletions Projects/CMNEdit/Windows/Common/NodeElementUserWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using CMNEdit.Windows;
using HActLib;
using ParLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CMNEdit
{
internal static class NodeElementUserWindow
{
private static void DrawField(Form1 form, NodeElementUser element, int idx)
{
var field = element.Fields[idx];

string fieldName = field.Name.ToString().ToTitleCase().Replace("_", " ");


switch (field.FieldType)
{
default:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { }, NumberBox.NumberMode.Text, true);
break;
case UserElementFieldType.Byte:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = byte.Parse(val); }, NumberBox.NumberMode.Byte);
break;
case UserElementFieldType.Short:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = short.Parse(val); }, NumberBox.NumberMode.Ushort);
break;
case UserElementFieldType.Int32:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = int.Parse(val); }, NumberBox.NumberMode.Int);
break;
case UserElementFieldType.Int64:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = long.Parse(val); }, NumberBox.NumberMode.Long);
break;
case UserElementFieldType.UShort:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = ushort.Parse(val); }, NumberBox.NumberMode.Ushort);
break;
case UserElementFieldType.UInt32:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = uint.Parse(val); }, NumberBox.NumberMode.UInt);
break;
case UserElementFieldType.UInt64:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = ulong.Parse(val); }, NumberBox.NumberMode.ULong);
break;
case UserElementFieldType.RGB32:
Panel rgb32Panel = null;

rgb32Panel = form.CreatePanel(fieldName, (RGB32)field.Value,
delegate (Color col)
{
field.Value = (RGB32)col;
rgb32Panel.BackColor = col;
});
break;

case UserElementFieldType.RGBA32:
Panel rgba32Panel = null;

rgba32Panel = form.CreatePanel(fieldName, (RGBA32)field.Value,
delegate (Color col)
{
field.Value = (RGBA32)col;
rgba32Panel.BackColor = col;
});
break;

case UserElementFieldType.Float:
form.CreateInput(fieldName, field.Value.ToString(), delegate (string val) { field.Value = Utils.InvariantParse(val); }, NumberBox.NumberMode.Float);
break;

case UserElementFieldType.FAnimationCurve:
form.CreateButton(fieldName, delegate
{
CurveView myNewForm = new CurveView();
myNewForm.Visible = true;
myNewForm.Init((float[])field.Value,
delegate (float[] outCurve)
{
field.Value = outCurve;
});
});
break;

}
}

public static void Draw(Form1 form, Node node)
{
var nodeUser = node as NodeElementUser;

form.CreateHeader(nodeUser.UserData.NodeName.Replace("_", " "));

for(int i = 0; i < nodeUser.Fields.Count; i++)
DrawField(form, nodeUser, i);
}
}
}
4 changes: 4 additions & 0 deletions Projects/CMNEdit/Windows/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2735,6 +2735,8 @@ private void faceExpressionToolStripMenuItem_Click(object sender, EventArgs e)

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
nodesTree.SuspendLayout();

Form1.TranslateNames = checkBox1.Checked;


Expand All @@ -2748,6 +2750,8 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
node.Text = node.HActNode.Name;
}
}

nodesTree.ResumeLayout();
}

private void equipAssetToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
10 changes: 10 additions & 0 deletions Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Reflection
{
public static bool Done = false;
public static Dictionary<Game, Dictionary<uint, Type>> ElementNodes = new Dictionary<Game, Dictionary<uint, Type>>();
public static Dictionary<Game, Dictionary<uint, UserElementData>> UserNodes = new Dictionary<Game, Dictionary<uint, UserElementData>>();
public static Dictionary<Game, List<string>> GamePrefixes = new Dictionary<Game, List<string>>();

public static Type GetElementEnumFromGame(Game game)
Expand Down Expand Up @@ -48,6 +49,14 @@ public static Type GetElementEnumFromGame(Game game)
}
}

public static void RegisterUserNode(Game game, UserElementData dat)
{
if (!Done)
Process();

UserNodes[game][dat.ElementID] = dat;
}

public static string[] GetGamePrefixes(Game game)
{
if (!Done)
Expand Down Expand Up @@ -134,6 +143,7 @@ public static void Process()
for (int i = 0; i < Enum.GetValues(typeof(Game)).Length; i++)
{
ElementNodes.Add((Game)i, new Dictionary<uint, Type>());
UserNodes.Add((Game)i, new Dictionary<uint, UserElementData>());
GamePrefixes.Add((Game)i, new List<string>());
}

Expand Down
Loading

0 comments on commit a51e5c2

Please sign in to comment.