Partial Entity Exposed field implementation

This commit is contained in:
Antoine Pilote
2024-08-13 23:54:51 -04:00
parent 318b646d61
commit 9b9f5d111d
6 changed files with 117 additions and 17 deletions

View File

@@ -208,6 +208,41 @@ void NetScriptPanel::Draw(Nuake::Entity entity)
field.Value = currentValue;
}
if (field.Type == Nuake::NetScriptExposedVarType::Entity)
{
if (!field.Value.has_value())
{
field.Value = field.DefaultValue;
}
int entityId = std::any_cast<int>(field.Value);
auto entity = Nuake::Engine::GetCurrentScene()->GetEntityByID(entityId);
bool invalid = !entity.IsValid();
std::string buttonLabel;
if (invalid)
{
buttonLabel = "Invalid Entity*";
}
else
{
buttonLabel = entity.GetComponent<Nuake::NameComponent>().Name;
}
ImGui::Button(buttonLabel.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY"))
{
Nuake::Entity payload_entity = *(const Nuake::Entity*)payload->Data;
field.Value = payload_entity.GetID();
}
ImGui::EndDragDropTarget();
}
}
ImGui::TableNextColumn();
}
}