Added UI Element and other QoL fixes for scripting #329
|
@ -4,6 +4,7 @@
|
||||||
//|| SHADE Includes ||
|
//|| SHADE Includes ||
|
||||||
//#==============================================================#
|
//#==============================================================#
|
||||||
#include "Editor/EditorWindow/SHEditorWindow.h"
|
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||||
|
#include "Editor/SHEditor.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "SHVSUtilities.h"
|
#include "SHVSUtilities.h"
|
||||||
#include "UI/Events/SHButtonClickEvent.h"
|
#include "UI/Events/SHButtonClickEvent.h"
|
||||||
#include "UI/SHUIComponent.h"
|
#include "UI/SHUIComponent.h"
|
||||||
|
#include "Editor/EditorWindow/MenuBar/SHEditorMenuBar.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -123,6 +124,11 @@ namespace SHADE
|
||||||
csScriptsRemoveAllImmediately(entity, callOnDestroy);
|
csScriptsRemoveAllImmediately(entity, callOnDestroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHScriptEngine::RemoveAllScriptsFromAllImmediately(bool callOnDestroy)
|
||||||
|
{
|
||||||
|
csScriptRemoveAllForAllNow(callOnDestroy);
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Script Serialisation Functions */
|
/* Script Serialisation Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -377,6 +383,13 @@ namespace SHADE
|
||||||
return eventData->handle;
|
return eventData->handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHEventHandle SHScriptEngine::onSceneDestroyed(SHEventPtr eventPtr)
|
||||||
|
{
|
||||||
|
auto eventData = reinterpret_cast<const SHEventSpec<SHEditorStateChangeEvent>*>(eventPtr.get());
|
||||||
|
csScriptRemoveAllForAllNow(true);
|
||||||
|
return eventData->handle;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -477,6 +490,12 @@ namespace SHADE
|
||||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||||
"RemoveAllScriptsImmediately"
|
"RemoveAllScriptsImmediately"
|
||||||
);
|
);
|
||||||
|
csScriptRemoveAllForAllNow = dotNet.GetFunctionPtr<CsScriptBoolFuncPtr>
|
||||||
|
(
|
||||||
|
DEFAULT_CSHARP_LIB_NAME,
|
||||||
|
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||||
|
"RemoveAllScriptsFromAllImmediately"
|
||||||
|
);
|
||||||
csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
|
csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
|
||||||
(
|
(
|
||||||
DEFAULT_CSHARP_LIB_NAME,
|
DEFAULT_CSHARP_LIB_NAME,
|
||||||
|
@ -549,6 +568,14 @@ namespace SHADE
|
||||||
};
|
};
|
||||||
SHEventManager::SubscribeTo(SH_ENTITY_DESTROYED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(destroyedEventReceiver));
|
SHEventManager::SubscribeTo(SH_ENTITY_DESTROYED_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(destroyedEventReceiver));
|
||||||
|
|
||||||
|
/* Editor */
|
||||||
|
// Register for editor state change event
|
||||||
|
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> destroyedSceneEventReceiver
|
||||||
|
{
|
||||||
|
std::make_shared<SHEventReceiverSpec<SHScriptEngine>>(this, &SHScriptEngine::onSceneDestroyed)
|
||||||
|
};
|
||||||
|
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(destroyedSceneEventReceiver));
|
||||||
|
|
||||||
/* Colliders */
|
/* Colliders */
|
||||||
// Register for collider added event
|
// Register for collider added event
|
||||||
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addedColliderEventReceiver
|
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addedColliderEventReceiver
|
||||||
|
|
|
@ -148,6 +148,13 @@ namespace SHADE
|
||||||
/// play mode.
|
/// play mode.
|
||||||
/// </param>
|
/// </param>
|
||||||
void RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy);
|
void RemoveAllScriptsImmediately(EntityID entity, bool callOnDestroy);
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all Scripts attached to all entities immediately. The
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callOnDestroy">
|
||||||
|
/// Whether or not to call OnDestroy on the scripts.
|
||||||
|
/// </param>
|
||||||
|
void RemoveAllScriptsFromAllImmediately(bool callOnDestroy);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Script Serialisation Functions */
|
/* Script Serialisation Functions */
|
||||||
|
@ -235,6 +242,7 @@ namespace SHADE
|
||||||
using CsScriptManipFuncPtr = bool(*)(EntityID, const char*);
|
using CsScriptManipFuncPtr = bool(*)(EntityID, const char*);
|
||||||
using CsScriptBasicFuncPtr = void(*)(EntityID);
|
using CsScriptBasicFuncPtr = void(*)(EntityID);
|
||||||
using CsScriptOptionalFuncPtr = void(*)(EntityID, bool);
|
using CsScriptOptionalFuncPtr = void(*)(EntityID, bool);
|
||||||
|
using CsScriptBoolFuncPtr = void(*)(bool);
|
||||||
using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*);
|
using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*);
|
||||||
using CsScriptDeserialiseYamlFuncPtr = bool(*)(EntityID, const void*);
|
using CsScriptDeserialiseYamlFuncPtr = bool(*)(EntityID, const void*);
|
||||||
using CsScriptEditorFuncPtr = void(*)(EntityID);
|
using CsScriptEditorFuncPtr = void(*)(EntityID);
|
||||||
|
@ -271,6 +279,7 @@ namespace SHADE
|
||||||
CsScriptManipFuncPtr csScriptsAdd = nullptr;
|
CsScriptManipFuncPtr csScriptsAdd = nullptr;
|
||||||
CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr;
|
CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr;
|
||||||
CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr;
|
CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr;
|
||||||
|
CsScriptBoolFuncPtr csScriptRemoveAllForAllNow = nullptr;
|
||||||
CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr;
|
CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr;
|
||||||
CsScriptDeserialiseYamlFuncPtr csScriptsDeserialiseYaml = nullptr;
|
CsScriptDeserialiseYamlFuncPtr csScriptsDeserialiseYaml = nullptr;
|
||||||
// - Events
|
// - Events
|
||||||
|
@ -295,6 +304,7 @@ namespace SHADE
|
||||||
SHEventHandle onUIElementClicked(SHEventPtr eventPtr);
|
SHEventHandle onUIElementClicked(SHEventPtr eventPtr);
|
||||||
SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr);
|
SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr);
|
||||||
SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr);
|
SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr);
|
||||||
|
SHEventHandle onSceneDestroyed(SHEventPtr eventPtr);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
|
@ -400,21 +400,21 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Clear all
|
// Clear all
|
||||||
System::Collections::Generic::List<Script^>^ scriptList = scripts[entity];
|
removeAllScriptsImmediately(entity, callOnDestroy && Application::IsPlaying || Application::IsPaused);
|
||||||
for each (Script ^ script in scriptList)
|
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||||
{
|
|
||||||
// Call OnDestroy only if indicated and also if the game has run
|
|
||||||
if (callOnDestroy && Application::IsPlaying || Application::IsPaused)
|
|
||||||
{
|
|
||||||
script->OnDestroy();
|
|
||||||
}
|
}
|
||||||
script->OnDetached();
|
|
||||||
|
|
||||||
// Remove scripts from awakening if they were not woken up to begin with
|
void ScriptStore::RemoveAllScriptsFromAllImmediately(bool callOnDestroy)
|
||||||
awakeList.Remove(script);
|
{
|
||||||
startList.Remove(script);
|
SAFE_NATIVE_CALL_BEGIN
|
||||||
|
// Clear all
|
||||||
|
for each (System::Collections::Generic::KeyValuePair<Entity, ScriptList^>^ pair in scripts)
|
||||||
|
{
|
||||||
|
removeAllScriptsImmediately(pair->Key, callOnDestroy);
|
||||||
}
|
}
|
||||||
scriptList->Clear();
|
awakeList.Clear();
|
||||||
|
startList.Clear();
|
||||||
|
disposalQueue.Clear();
|
||||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,6 +798,25 @@ namespace SHADE
|
||||||
script->OnDetached();
|
script->OnDetached();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptStore::removeAllScriptsImmediately(Entity entity, bool callOnDestroy)
|
||||||
|
{
|
||||||
|
System::Collections::Generic::List<Script^>^ scriptList = scripts[entity];
|
||||||
|
for each (Script ^ script in scriptList)
|
||||||
|
{
|
||||||
|
// Call OnDestroy only if indicated and also if the game has run
|
||||||
|
if (callOnDestroy)
|
||||||
|
{
|
||||||
|
script->OnDestroy();
|
||||||
|
}
|
||||||
|
script->OnDetached();
|
||||||
|
|
||||||
|
// Remove scripts from awakening if they were not woken up to begin with
|
||||||
|
awakeList.Remove(script);
|
||||||
|
startList.Remove(script);
|
||||||
|
}
|
||||||
|
scriptList->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/* Select Many */
|
/* Select Many */
|
||||||
|
|
|
@ -228,6 +228,13 @@ namespace SHADE
|
||||||
/// play mode.
|
/// play mode.
|
||||||
/// </param>
|
/// </param>
|
||||||
static void RemoveAllScriptsImmediately(Entity entity, bool callOnDestroy);
|
static void RemoveAllScriptsImmediately(Entity entity, bool callOnDestroy);
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all Scripts attached to all entities immediately. The
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callOnDestroy">
|
||||||
|
/// Whether or not to call OnDestroy on the scripts.
|
||||||
|
/// </param>
|
||||||
|
static void RemoveAllScriptsFromAllImmediately(bool callOnDestroy);
|
||||||
|
|
||||||
internal:
|
internal:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -343,6 +350,7 @@ namespace SHADE
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
static void removeScript(Script^ script);
|
static void removeScript(Script^ script);
|
||||||
|
static void removeAllScriptsImmediately(Entity script, bool callOnDestroy);
|
||||||
static void refreshScriptTypeList();
|
static void refreshScriptTypeList();
|
||||||
static void getGenericMethods();
|
static void getGenericMethods();
|
||||||
static System::Type^ getScriptType(System::String^ scriptName);
|
static System::Type^ getScriptType(System::String^ scriptName);
|
||||||
|
|
Loading…
Reference in New Issue