Added UI Element and other QoL fixes for scripting #329
|
@ -4,6 +4,7 @@
|
|||
//|| SHADE Includes ||
|
||||
//#==============================================================#
|
||||
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||
#include "Editor/SHEditor.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
|
|
@ -33,6 +33,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "SHVSUtilities.h"
|
||||
#include "UI/Events/SHButtonClickEvent.h"
|
||||
#include "UI/SHUIComponent.h"
|
||||
#include "Editor/EditorWindow/MenuBar/SHEditorMenuBar.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -123,6 +124,11 @@ namespace SHADE
|
|||
csScriptsRemoveAllImmediately(entity, callOnDestroy);
|
||||
}
|
||||
|
||||
void SHScriptEngine::RemoveAllScriptsFromAllImmediately(bool callOnDestroy)
|
||||
{
|
||||
csScriptRemoveAllForAllNow(callOnDestroy);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Script Serialisation Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -377,6 +383,13 @@ namespace SHADE
|
|||
return eventData->handle;
|
||||
}
|
||||
|
||||
SHEventHandle SHScriptEngine::onSceneDestroyed(SHEventPtr eventPtr)
|
||||
{
|
||||
auto eventData = reinterpret_cast<const SHEventSpec<SHEditorStateChangeEvent>*>(eventPtr.get());
|
||||
csScriptRemoveAllForAllNow(true);
|
||||
return eventData->handle;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -477,6 +490,12 @@ namespace SHADE
|
|||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"RemoveAllScriptsImmediately"
|
||||
);
|
||||
csScriptRemoveAllForAllNow = dotNet.GetFunctionPtr<CsScriptBoolFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"RemoveAllScriptsFromAllImmediately"
|
||||
);
|
||||
csScriptsSerialiseYaml = dotNet.GetFunctionPtr<CsScriptSerialiseYamlFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
|
@ -549,6 +568,14 @@ namespace SHADE
|
|||
};
|
||||
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 */
|
||||
// Register for collider added event
|
||||
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> addedColliderEventReceiver
|
||||
|
|
|
@ -148,6 +148,13 @@ namespace SHADE
|
|||
/// play mode.
|
||||
/// </param>
|
||||
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 */
|
||||
|
@ -235,6 +242,7 @@ namespace SHADE
|
|||
using CsScriptManipFuncPtr = bool(*)(EntityID, const char*);
|
||||
using CsScriptBasicFuncPtr = void(*)(EntityID);
|
||||
using CsScriptOptionalFuncPtr = void(*)(EntityID, bool);
|
||||
using CsScriptBoolFuncPtr = void(*)(bool);
|
||||
using CsScriptSerialiseYamlFuncPtr = bool(*)(EntityID, void*);
|
||||
using CsScriptDeserialiseYamlFuncPtr = bool(*)(EntityID, const void*);
|
||||
using CsScriptEditorFuncPtr = void(*)(EntityID);
|
||||
|
@ -271,6 +279,7 @@ namespace SHADE
|
|||
CsScriptManipFuncPtr csScriptsAdd = nullptr;
|
||||
CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr;
|
||||
CsScriptOptionalFuncPtr csScriptsRemoveAllImmediately = nullptr;
|
||||
CsScriptBoolFuncPtr csScriptRemoveAllForAllNow = nullptr;
|
||||
CsScriptSerialiseYamlFuncPtr csScriptsSerialiseYaml = nullptr;
|
||||
CsScriptDeserialiseYamlFuncPtr csScriptsDeserialiseYaml = nullptr;
|
||||
// - Events
|
||||
|
@ -295,6 +304,7 @@ namespace SHADE
|
|||
SHEventHandle onUIElementClicked(SHEventPtr eventPtr);
|
||||
SHEventHandle onSceneNodeChildrenAdded(SHEventPtr eventPtr);
|
||||
SHEventHandle onSceneNodeChildrenRemoved(SHEventPtr eventPtr);
|
||||
SHEventHandle onSceneDestroyed(SHEventPtr eventPtr);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
|
|
@ -400,21 +400,21 @@ namespace SHADE
|
|||
return;
|
||||
|
||||
// Clear all
|
||||
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 && Application::IsPlaying || Application::IsPaused)
|
||||
{
|
||||
script->OnDestroy();
|
||||
removeAllScriptsImmediately(entity, callOnDestroy && Application::IsPlaying || Application::IsPaused);
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
script->OnDetached();
|
||||
|
||||
// Remove scripts from awakening if they were not woken up to begin with
|
||||
awakeList.Remove(script);
|
||||
startList.Remove(script);
|
||||
void ScriptStore::RemoveAllScriptsFromAllImmediately(bool callOnDestroy)
|
||||
{
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -798,6 +798,25 @@ namespace SHADE
|
|||
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
|
||||
{
|
||||
/* Select Many */
|
||||
|
|
|
@ -228,6 +228,13 @@ namespace SHADE
|
|||
/// play mode.
|
||||
/// </param>
|
||||
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:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -343,6 +350,7 @@ namespace SHADE
|
|||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
static void removeScript(Script^ script);
|
||||
static void removeAllScriptsImmediately(Entity script, bool callOnDestroy);
|
||||
static void refreshScriptTypeList();
|
||||
static void getGenericMethods();
|
||||
static System::Type^ getScriptType(System::String^ scriptName);
|
||||
|
|
Loading…
Reference in New Issue