diff --git a/SHADE_CSharp/src/Events/CallbackAction.cs b/SHADE_CSharp/src/Events/CallbackAction.cs index ec34ca5c..968302ed 100644 --- a/SHADE_CSharp/src/Events/CallbackAction.cs +++ b/SHADE_CSharp/src/Events/CallbackAction.cs @@ -57,6 +57,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -130,6 +134,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -204,6 +212,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -279,6 +291,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -355,6 +371,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -432,6 +452,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -510,6 +534,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -589,6 +617,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -669,6 +701,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// @@ -750,6 +786,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// diff --git a/SHADE_CSharp/src/Events/CallbackAction.tt b/SHADE_CSharp/src/Events/CallbackAction.tt index 0b1efb83..fffd4251 100644 --- a/SHADE_CSharp/src/Events/CallbackAction.tt +++ b/SHADE_CSharp/src/Events/CallbackAction.tt @@ -74,6 +74,10 @@ namespace SHADE #region Constructors ------------------------------------------------------------ /// + /// Constructs an empty Callback action. + /// + public CallbackAction() {} + /// /// Constructs a CallbackAction that represents a call to the specified method on the /// specified target. /// diff --git a/SHADE_CSharp/src/Events/CallbackEvent.cs b/SHADE_CSharp/src/Events/CallbackEvent.cs index 7b30a8ec..ec464ba9 100644 --- a/SHADE_CSharp/src/Events/CallbackEvent.cs +++ b/SHADE_CSharp/src/Events/CallbackEvent.cs @@ -22,6 +22,10 @@ namespace SHADE /// public interface ICallbackEvent { + /// + /// Registers an empty ICallbackAction. + /// + void RegisterAction(); /// /// Registers an ICallbackAction with the event such that it will be called in /// future @@ -59,6 +63,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -140,6 +149,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -221,6 +235,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -302,6 +321,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -383,6 +407,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -464,6 +493,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -545,6 +579,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -626,6 +665,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -707,6 +751,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action @@ -788,6 +837,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action diff --git a/SHADE_CSharp/src/Events/CallbackEvent.tt b/SHADE_CSharp/src/Events/CallbackEvent.tt index 74fadd08..6a545601 100644 --- a/SHADE_CSharp/src/Events/CallbackEvent.tt +++ b/SHADE_CSharp/src/Events/CallbackEvent.tt @@ -38,6 +38,10 @@ namespace SHADE /// public interface ICallbackEvent { + /// + /// Registers an empty ICallbackAction. + /// + void RegisterAction(); /// /// Registers an ICallbackAction with the event such that it will be called in /// future @@ -76,6 +80,11 @@ namespace SHADE #region Usage Functions --------------------------------------------------------- /// + public void RegisterAction() + { + actions.Add(new CallbackAction<<# for (int t = 1; t < i + 1; ++t) { #>T<#=t#><# if (t != i) { #>, <# } #><# } #>>()); + } + /// public void RegisterAction(ICallbackAction action) { // Check if valid action diff --git a/SHADE_Engine/src/Editor/SHEditorUI.cpp b/SHADE_Engine/src/Editor/SHEditorUI.cpp index 7107778d..0137b951 100644 --- a/SHADE_Engine/src/Editor/SHEditorUI.cpp +++ b/SHADE_Engine/src/Editor/SHEditorUI.cpp @@ -54,7 +54,7 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ bool SHEditorUI::CollapsingHeader(const std::string& title) { - return ImGui::CollapsingHeader(title.c_str()); + return ImGui::CollapsingHeader(title.c_str(), ImGuiTreeNodeFlags_DefaultOpen); } void SHEditorUI::SameLine() diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index fea59353..195d8ee3 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -255,6 +255,10 @@ namespace SHADE ..\\bin\\Debug\\SHADE_Managed.dll\n\ ..\\bin\\Release\\SHADE_Managed.dll\n\ \n\ + \n\ + ..\\bin\\Debug\\SHADE_CSharp.dll\n\ + ..\\bin\\Release\\SHADE_CSharp.dll\n\ + \n\ \n\ "; diff --git a/SHADE_Managed/src/Editor/Editor.cxx b/SHADE_Managed/src/Editor/Editor.cxx index c2b34d44..018a9591 100644 --- a/SHADE_Managed/src/Editor/Editor.cxx +++ b/SHADE_Managed/src/Editor/Editor.cxx @@ -286,17 +286,59 @@ namespace SHADE registerUndoAction(object, field, Convert::ToCLI(val), Convert::ToCLI(oldVal)); } } - else if (field->FieldType->BaseType == ICallbackEvent::typeid) - { - // Needs to present - // - name and param list - // Needs to present for each callbackaction - // - object, methodinfo OR action - // - Ways to add or remove items - } else { - return; + array^ interfaces = field->FieldType->GetInterfaces(); + if (interfaces->Length > 0 && interfaces[0] == ICallbackEvent::typeid) + { + array^ typeArgs = field->FieldType->GenericTypeArguments; + System::String^ title = field->Name + " : CallbackEvent<"; + for (int i = 0; i < typeArgs->Length; ++i) + { + title += typeArgs[i]->Name; + if (i < typeArgs->Length - 1) + title += ", "; + } + title += ">"; + if (SHEditorUI::CollapsingHeader(Convert::ToNative(title))) + { + ICallbackEvent^ callbackEvent = safe_cast(field->GetValue(object)); + if (callbackEvent == nullptr) + { + // Construct one since it was not constructed before + callbackEvent = safe_cast(System::Activator::CreateInstance(field->FieldType)); + } + for each (ICallbackAction ^ action in callbackEvent->Actions) + { + if (action->IsRuntimeAction) + continue; + + if (action->TargetObject == nullptr) + SHEditorUI::Text("Target Object"); + else + SHEditorUI::Text(Convert::ToNative(action->TargetObject->GetType()->Name)); + SHEditorUI::SameLine(); + + if (action->TargetMethodName == nullptr) + SHEditorUI::Text("Target Method Name"); + else + SHEditorUI::Text(Convert::ToNative(action->TargetMethodName)); + } + if (SHEditorUI::Button("Add Action")) + { + callbackEvent->RegisterAction(); + } + } + // Needs to present + // - name and param list + // Needs to present for each callbackaction + // - object, methodinfo OR action + // - Ways to add or remove items + } + else + { + return; + } } // Check if the field has a specific attribute diff --git a/TempScriptsFolder/RaccoonSpin.cs b/TempScriptsFolder/RaccoonSpin.cs index d6ee1c9f..6bbd1462 100644 --- a/TempScriptsFolder/RaccoonSpin.cs +++ b/TempScriptsFolder/RaccoonSpin.cs @@ -7,6 +7,10 @@ public class RaccoonSpin : Script [Tooltip("Speed of the rotation in radians per second.")] private double RotateSpeed = 1.0; private double rotation = 0.0; + [SerializeField] + private CallbackEvent testEvent; + [SerializeField] + private CallbackEvent testEvent3 = new CallbackEvent(); private Transform Transform; public RaccoonSpin(GameObject gameObj) : base(gameObj) { }