Merge pull request #157 from SHADE-DP/SP3-6-c-scripting
GameObjects on scripts can now be edited in the inspector and are serialized Also credit to @srishamharan for fix to SHHierarchyPanel's drag and drop
This commit is contained in:
commit
ff74c090d5
|
@ -195,18 +195,22 @@ namespace SHADE
|
||||||
if (SHDragDrop::BeginSource())
|
if (SHDragDrop::BeginSource())
|
||||||
{
|
{
|
||||||
std::string moveLabel = "Moving EID: ";
|
std::string moveLabel = "Moving EID: ";
|
||||||
|
static std::vector<EntityID> draggingEntities = editor->selectedEntities;
|
||||||
if (!isSelected)
|
if (!isSelected)
|
||||||
editor->selectedEntities.push_back(eid);
|
|
||||||
for (int i = 0; i < static_cast<int>(editor->selectedEntities.size()); ++i)
|
|
||||||
{
|
{
|
||||||
moveLabel.append(std::to_string(editor->selectedEntities[i]));
|
draggingEntities.clear();
|
||||||
if (i + 1 < static_cast<int>(editor->selectedEntities.size()))
|
draggingEntities.push_back(eid);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < static_cast<int>(draggingEntities.size()); ++i)
|
||||||
|
{
|
||||||
|
moveLabel.append(std::to_string(draggingEntities[i]));
|
||||||
|
if (i + 1 < static_cast<int>(draggingEntities.size()))
|
||||||
{
|
{
|
||||||
moveLabel.append(", ");
|
moveLabel.append(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::Text(moveLabel.c_str());
|
ImGui::Text(moveLabel.c_str());
|
||||||
SHDragDrop::SetPayload<std::vector<EntityID>>(SHDragDrop::DRAG_EID, &editor->selectedEntities);
|
SHDragDrop::SetPayload<std::vector<EntityID>>(SHDragDrop::DRAG_EID, &draggingEntities);
|
||||||
SHDragDrop::EndSource();
|
SHDragDrop::EndSource();
|
||||||
}
|
}
|
||||||
else if (SHDragDrop::BeginTarget()) //If Received DragDrop
|
else if (SHDragDrop::BeginTarget()) //If Received DragDrop
|
||||||
|
|
|
@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "SHEditorWidgets.hpp"
|
#include "SHEditorWidgets.hpp"
|
||||||
|
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -287,6 +288,35 @@ namespace SHADE
|
||||||
return CHANGED;
|
return CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SHEditorUI::InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered)
|
||||||
|
{
|
||||||
|
ImGui::Text(label.c_str());
|
||||||
|
if (isHovered)
|
||||||
|
*isHovered = ImGui::IsItemHovered();
|
||||||
|
ImGui::SameLine();
|
||||||
|
SHEntity* entity = SHEntityManager::GetEntityByID(value);
|
||||||
|
std::ostringstream oss;
|
||||||
|
if (entity)
|
||||||
|
{
|
||||||
|
oss << value << ": " << entity->name;
|
||||||
|
}
|
||||||
|
std::string entityName = oss.str();
|
||||||
|
bool changed = ImGui::InputText("##", &entityName, ImGuiInputTextFlags_ReadOnly);
|
||||||
|
if (SHDragDrop::BeginTarget())
|
||||||
|
{
|
||||||
|
if (const std::vector<EntityID>* payload = SHDragDrop::AcceptPayload<std::vector<EntityID>>(SHDragDrop::DRAG_EID))
|
||||||
|
{
|
||||||
|
if (!payload->empty())
|
||||||
|
{
|
||||||
|
value = payload->at(0);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
SHDragDrop::EndTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered)
|
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered)
|
||||||
{
|
{
|
||||||
// Clamp input value
|
// Clamp input value
|
||||||
|
|
|
@ -308,6 +308,14 @@ namespace SHADE
|
||||||
/// <returns>True if the value was changed.</returns>
|
/// <returns>True if the value was changed.</returns>
|
||||||
static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr);
|
static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Creates a drag field widget for int input.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
|
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||||
|
/// <returns>True if the value was changed.</returns>
|
||||||
|
static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr);
|
||||||
|
/// <summary>
|
||||||
/// Creates a combo box for enumeration input.
|
/// Creates a combo box for enumeration input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="Enum">The type of enum to input.</typeparam>
|
/// <typeparam name="Enum">The type of enum to input.</typeparam>
|
||||||
|
|
|
@ -260,7 +260,7 @@ namespace SHADE
|
||||||
|
|
||||||
int val = safe_cast<int>(field->GetValue(object));
|
int val = safe_cast<int>(field->GetValue(object));
|
||||||
int oldVal = val;
|
int oldVal = val;
|
||||||
if (SHEditorUI::InputEnumCombo(Convert::ToNative(field->Name), val, nativeEnumNames))
|
if (SHEditorUI::InputEnumCombo(Convert::ToNative(field->Name), val, nativeEnumNames, &isHovered))
|
||||||
{
|
{
|
||||||
field->SetValue(object, val);
|
field->SetValue(object, val);
|
||||||
registerUndoAction(object, field, val, oldVal);
|
registerUndoAction(object, field, val, oldVal);
|
||||||
|
@ -280,12 +280,23 @@ namespace SHADE
|
||||||
// Actual Field
|
// Actual Field
|
||||||
std::string val = Convert::ToNative(stringVal);
|
std::string val = Convert::ToNative(stringVal);
|
||||||
std::string oldVal = val;
|
std::string oldVal = val;
|
||||||
if (SHEditorUI::InputTextField(Convert::ToNative(field->Name), val))
|
if (SHEditorUI::InputTextField(Convert::ToNative(field->Name), val, &isHovered))
|
||||||
{
|
{
|
||||||
field->SetValue(object, Convert::ToCLI(val));
|
field->SetValue(object, Convert::ToCLI(val));
|
||||||
registerUndoAction(object, field, Convert::ToCLI(val), Convert::ToCLI(oldVal));
|
registerUndoAction(object, field, Convert::ToCLI(val), Convert::ToCLI(oldVal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (field->FieldType == GameObject::typeid)
|
||||||
|
{
|
||||||
|
GameObject gameObj = safe_cast<GameObject>(field->GetValue(object));
|
||||||
|
uint32_t entityId = gameObj.GetEntity();
|
||||||
|
if (SHEditorUI::InputGameObjectField(Convert::ToNative(field->Name), entityId, &isHovered))
|
||||||
|
{
|
||||||
|
GameObject newVal = GameObject(entityId);
|
||||||
|
field->SetValue(object, newVal);
|
||||||
|
registerUndoAction(object, field, newVal, gameObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
array<System::Type^>^ interfaces = field->FieldType->GetInterfaces();
|
array<System::Type^>^ interfaces = field->FieldType->GetInterfaces();
|
||||||
|
|
|
@ -22,6 +22,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Math/Vector2.hxx"
|
#include "Math/Vector2.hxx"
|
||||||
#include "Math/Vector3.hxx"
|
#include "Math/Vector3.hxx"
|
||||||
#include "Utility/Debug.hxx"
|
#include "Utility/Debug.hxx"
|
||||||
|
#include "Engine/GameObject.hxx"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------*/
|
||||||
/* Macro Functions */
|
/* Macro Functions */
|
||||||
|
@ -167,6 +168,11 @@ namespace SHADE
|
||||||
fieldNode.push_back(vec.y);
|
fieldNode.push_back(vec.y);
|
||||||
fieldNode.push_back(vec.z);
|
fieldNode.push_back(vec.z);
|
||||||
}
|
}
|
||||||
|
else if (fieldInfo->FieldType == GameObject::typeid)
|
||||||
|
{
|
||||||
|
GameObject gameObj = safe_cast<GameObject>(fieldInfo->GetValue(object));
|
||||||
|
fieldNode = gameObj.GetEntity();
|
||||||
|
}
|
||||||
else // Not any of the supported types
|
else // Not any of the supported types
|
||||||
{
|
{
|
||||||
Debug::LogWarning(Convert::ToNative(System::String::Format
|
Debug::LogWarning(Convert::ToNative(System::String::Format
|
||||||
|
@ -242,6 +248,10 @@ namespace SHADE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (fieldInfo->FieldType == GameObject::typeid)
|
||||||
|
{
|
||||||
|
fieldInfo->SetValue(object, GameObject(node.as<uint32_t>()));
|
||||||
|
}
|
||||||
else // Not any of the supported types
|
else // Not any of the supported types
|
||||||
{
|
{
|
||||||
Debug::LogWarning(Convert::ToNative(System::String::Format
|
Debug::LogWarning(Convert::ToNative(System::String::Format
|
||||||
|
|
Loading…
Reference in New Issue