Improved CallbackEvent inspector

This commit is contained in:
Kah Wei 2022-10-25 16:55:50 +08:00
parent 73a85e4aab
commit 3bdc48260f
1 changed files with 31 additions and 15 deletions

View File

@ -197,7 +197,7 @@ namespace SHADE
void Editor::renderScriptInInspector(Entity entity, Script^ script, int index) void Editor::renderScriptInInspector(Entity entity, Script^ script, int index)
{ {
// Constants // Constants
const std::string LABEL = Convert::ToNative(script->GetType()->Name); const std::string LABEL = Convert::ToNative(script->GetType()->Name);
// Header // Header
SHEditorUI::PushID(index); SHEditorUI::PushID(index);
@ -302,6 +302,10 @@ namespace SHADE
title += ">"; title += ">";
if (SHEditorUI::CollapsingHeader(Convert::ToNative(title))) if (SHEditorUI::CollapsingHeader(Convert::ToNative(title)))
{ {
// Constants
const std::string LABEL = Convert::ToNative(field->Name);
SHEditorUI::PushID(LABEL);
ICallbackEvent^ callbackEvent = safe_cast<ICallbackEvent^>(field->GetValue(object)); ICallbackEvent^ callbackEvent = safe_cast<ICallbackEvent^>(field->GetValue(object));
if (callbackEvent == nullptr) if (callbackEvent == nullptr)
{ {
@ -313,27 +317,39 @@ namespace SHADE
if (action->IsRuntimeAction) if (action->IsRuntimeAction)
continue; continue;
if (action->TargetObject == nullptr) // Attempt to get the object if any
SHEditorUI::Text("Target Object"); int entityId = static_cast<int>(-1);
else if (action->TargetObject)
SHEditorUI::Text(Convert::ToNative(action->TargetObject->GetType()->Name)); {
Script^ script = safe_cast<Script^>(action->TargetObject);
if (script)
{
entityId = static_cast<int>(script->Owner.GetEntity());
}
}
SHEditorUI::InputInt("", entityId);
SHEditorUI::SameLine(); SHEditorUI::SameLine();
System::String^ methodName = "";
if (action->TargetMethodName == nullptr) if (action->TargetMethodName != nullptr)
SHEditorUI::Text("Target Method Name"); {
else methodName = action->TargetMethodName;
SHEditorUI::Text(Convert::ToNative(action->TargetMethodName)); }
std::string methodNameNative = Convert::ToNative(methodName);
SHEditorUI::InputTextField("", methodNameNative);
SHEditorUI::SameLine();
if (SHEditorUI::Button("-"))
{
callbackEvent->DeregisterAction(action);
break;
}
} }
if (SHEditorUI::Button("Add Action")) if (SHEditorUI::Button("Add Action"))
{ {
callbackEvent->RegisterAction(); callbackEvent->RegisterAction();
} }
SHEditorUI::PopID();
} }
// Needs to present
// - name and param list
// Needs to present for each callbackaction
// - object, methodinfo OR action
// - Ways to add or remove items
} }
else else
{ {