GameObjects on scripts can now be edited in the inspector and are serialized #157
|
@ -195,18 +195,22 @@ namespace SHADE
|
|||
if (SHDragDrop::BeginSource())
|
||||
{
|
||||
std::string moveLabel = "Moving EID: ";
|
||||
static std::vector<EntityID> draggingEntities = editor->selectedEntities;
|
||||
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]));
|
||||
if (i + 1 < static_cast<int>(editor->selectedEntities.size()))
|
||||
draggingEntities.clear();
|
||||
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(", ");
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
else if (SHDragDrop::BeginTarget()) //If Received DragDrop
|
||||
|
|
|
@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// External Dependencies
|
||||
#include <imgui.h>
|
||||
#include "SHEditorWidgets.hpp"
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -287,6 +288,35 @@ namespace SHADE
|
|||
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)
|
||||
{
|
||||
// Clamp input value
|
||||
|
|
|
@ -308,6 +308,14 @@ namespace SHADE
|
|||
/// <returns>True if the value was changed.</returns>
|
||||
static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr);
|
||||
/// <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.
|
||||
/// </summary>
|
||||
/// <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 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);
|
||||
registerUndoAction(object, field, val, oldVal);
|
||||
|
@ -280,12 +280,23 @@ namespace SHADE
|
|||
// Actual Field
|
||||
std::string val = Convert::ToNative(stringVal);
|
||||
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));
|
||||
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
|
||||
{
|
||||
array<System::Type^>^ interfaces = field->FieldType->GetInterfaces();
|
||||
|
|
|
@ -22,6 +22,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Math/Vector2.hxx"
|
||||
#include "Math/Vector3.hxx"
|
||||
#include "Utility/Debug.hxx"
|
||||
#include "Engine/GameObject.hxx"
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* Macro Functions */
|
||||
|
@ -167,6 +168,11 @@ namespace SHADE
|
|||
fieldNode.push_back(vec.y);
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
Debug::LogWarning(Convert::ToNative(System::String::Format
|
||||
|
|
Loading…
Reference in New Issue