Started to expose DOM to C# API with support for custom nodes. Currently crash when doing FindNodeByID<T>

This commit is contained in:
antopilo
2024-09-13 00:51:34 -04:00
parent 9e87dca9ce
commit 3b148b76c4
18 changed files with 390 additions and 90 deletions

View File

@@ -242,7 +242,7 @@ namespace Nuake.Net
public bool Playing { get; set; }
public int CurrentAnimation { get; set; }
public void Play(String name)
public void Play(string name)
{
unsafe { PlayIcall(EntityID, name); }
}

View File

@@ -1,8 +1,14 @@
using System;
using Coral.Managed;
using Coral.Managed.Interop;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Nuake.Net
@@ -63,31 +69,95 @@ namespace Nuake.Net
}
}
public class UIWidget
public class Node
{
internal static unsafe delegate*<NativeString, NativeString, NativeString, NativeString, ulong> FindChildByIDICall;
internal static unsafe delegate*<NativeString, NativeString, NativeString, bool> HasNativeInstanceICall;
internal static unsafe delegate*<NativeString, NativeString, NativeInstance<Node>> GetNativeInstanceNodeICall;
public string UUID;
public string CanvasUUID;
public string ID { get; set; } = "";
public List<string> Classes { get; set; } = new();
/// <summary>
/// Traverse the DOM starting from this node to find a child from a unique ID
/// </summary>
/// <typeparam name="T">Type of node</typeparam>
/// <param name="id">Unique id of the node to find</param>
/// <returns></returns>
/// <exception cref="Exception">Node not found</exception>
public T FindChildByID<T>(string id) where T : Node
{
unsafe
{
Engine.Log("Calling FindChildByIDICall with params: " + CanvasUUID + " , " + UUID + " , " + id);
ulong uuid = FindChildByIDICall(CanvasUUID, CanvasUUID, UUID, id);
if (uuid == 0)
{
throw new Exception("Node not found");
}
Node? newNode = null;
//if (HasNativeInstanceICall(CanvasUUID, CanvasUUID, UUID))
//{
// NativeInstance<Node> handle;
// unsafe { handle = GetNativeInstanceNodeICall(CanvasUUID, UUID); }
// newNode = handle.Get();
//}
if(newNode == null)
{
newNode = new Node()
{
UUID = uuid.ToString(),
CanvasUUID = CanvasUUID
};
return newNode as T;
}
return null;
}
}
}
public class TextNode : Node
{
internal static unsafe delegate*<NativeString, NativeString, NativeString, void> SetTextNodeTextICall;
internal static unsafe delegate*<NativeString, NativeString, NativeString> GetTextNodeTextICall;
public string Text
{
get
{
unsafe
{
return GetTextNodeTextICall(this.CanvasUUID, this.UUID).ToString();
}
}
set
{
unsafe
{
SetTextNodeTextICall(this.CanvasUUID, this.UUID, value);
}
}
}
}
public class UIWidget : Node
{
public Style Style { get; set; }
private string HTML;
protected ulong ID { get; set; }
public UIWidget()
{ }
protected UIWidget(ulong id)
{
ID = id;
Style = new Style(id);
HTML = "";
}
public UIWidget() { }
public virtual void OnInit() { }
public virtual void OnTick(float dt) { }
// Events
public virtual void OnClick()
{
}
public virtual void OnClick() { }
}
}