Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced InputText for the script component with a Combo (dropdown) #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions Hazelnut/src/Panels/SceneHierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,20 @@ namespace Hazel {

DrawComponent<ScriptComponent>("Script", entity, [entity, scene = m_Context](auto& component) mutable
{
bool scriptClassExists = ScriptEngine::EntityClassExists(component.ClassName);

static char buffer[64];
strcpy_s(buffer, sizeof(buffer), component.ClassName.c_str());
if (ImGui::BeginCombo("Class", component.ClassName.c_str()))
{
for (const auto& [className, scriptClass] : ScriptEngine::GetEntityClasses())
{
bool isSelected = className == component.ClassName;
if (ImGui::Selectable(className.c_str(), isSelected))
component.ClassName = className;

if (!scriptClassExists)
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.9f, 0.2f, 0.3f, 1.0f));
if (isSelected)
ImGui::SetItemDefaultFocus();
}

if (ImGui::InputText("Class", buffer, sizeof(buffer)))
component.ClassName = buffer;
ImGui::EndCombo();
}

// Fields
bool sceneRunning = scene->IsRunning();
Expand All @@ -358,47 +362,41 @@ namespace Hazel {
}
else
{
if (scriptClassExists)
{
Ref<ScriptClass> entityClass = ScriptEngine::GetEntityClass(component.ClassName);
const auto& fields = entityClass->GetFields();
Ref<ScriptClass> entityClass = ScriptEngine::GetEntityClass(component.ClassName);
const auto& fields = entityClass->GetFields();

auto& entityFields = ScriptEngine::GetScriptFieldMap(entity);
for (const auto& [name, field] : fields)
auto& entityFields = ScriptEngine::GetScriptFieldMap(entity);
for (const auto& [name, field] : fields)
{
// Field has been set in editor
if (entityFields.find(name) != entityFields.end())
{
// Field has been set in editor
if (entityFields.find(name) != entityFields.end())
{
ScriptFieldInstance& scriptField = entityFields.at(name);
ScriptFieldInstance& scriptField = entityFields.at(name);

// Display control to set it maybe
if (field.Type == ScriptFieldType::Float)
{
float data = scriptField.GetValue<float>();
if (ImGui::DragFloat(name.c_str(), &data))
scriptField.SetValue(data);
}
// Display control to set it maybe
if (field.Type == ScriptFieldType::Float)
{
float data = scriptField.GetValue<float>();
if (ImGui::DragFloat(name.c_str(), &data))
scriptField.SetValue(data);
}
else
}
else
{
// Display control to set it maybe
if (field.Type == ScriptFieldType::Float)
{
// Display control to set it maybe
if (field.Type == ScriptFieldType::Float)
float data = 0.0f;
if (ImGui::DragFloat(name.c_str(), &data))
{
float data = 0.0f;
if (ImGui::DragFloat(name.c_str(), &data))
{
ScriptFieldInstance& fieldInstance = entityFields[name];
fieldInstance.Field = field;
fieldInstance.SetValue(data);
}
ScriptFieldInstance& fieldInstance = entityFields[name];
fieldInstance.Field = field;
fieldInstance.SetValue(data);
}
}
}
}
}

if (!scriptClassExists)
ImGui::PopStyleColor();
}
});

DrawComponent<SpriteRendererComponent>("Sprite Renderer", entity, [](auto& component)
Expand Down