mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
New reflection type DynamicItemList
This commit is contained in:
@@ -33,6 +33,7 @@ EditorSelectionPanel::EditorSelectionPanel()
|
||||
REGISTER_TYPE_DRAWER(Vector3, EditorSelectionPanel::DrawFieldTypeVector3);
|
||||
REGISTER_TYPE_DRAWER(std::string, EditorSelectionPanel::DrawFieldTypeString);
|
||||
REGISTER_TYPE_DRAWER(ResourceFile, EditorSelectionPanel::DrawFieldTypeResourceFile);
|
||||
REGISTER_TYPE_DRAWER(DynamicItemList, EditorSelectionPanel::DrawFieldTypeDynamicItemList);
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
|
||||
@@ -783,3 +784,57 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawFieldTypeDynamicItemList(entt::meta_data& field, entt::meta_any& component)
|
||||
{
|
||||
auto propDisplayName = field.prop(HashedName::DisplayName);
|
||||
const char* displayName = *propDisplayName.value().try_cast<const char*>();
|
||||
if (displayName != nullptr)
|
||||
{
|
||||
ImGui::Text(displayName);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
auto fieldVal = field.get(component);
|
||||
auto fieldValPtr = fieldVal.try_cast<DynamicItemList>();
|
||||
if (fieldValPtr == nullptr)
|
||||
{
|
||||
ImGui::Text("ERR");
|
||||
}
|
||||
|
||||
const auto& items = fieldValPtr->items;
|
||||
const int index = fieldValPtr->index;
|
||||
|
||||
// Check first to see if we are within the bounds
|
||||
std::string selectedStr = "";
|
||||
if (index >= 0 || index < items.size())
|
||||
{
|
||||
selectedStr = items[index];
|
||||
}
|
||||
|
||||
std::string controlName = std::string("##") + displayName;
|
||||
if (ImGui::BeginCombo(controlName.c_str(), selectedStr.c_str()))
|
||||
{
|
||||
for (int i = 0; i < items.size(); i++)
|
||||
{
|
||||
bool isSelected = (index == i);
|
||||
std::string name = items[i];
|
||||
|
||||
if (name.empty())
|
||||
{
|
||||
name = "Empty";
|
||||
}
|
||||
|
||||
if (ImGui::Selectable(name.c_str(), isSelected))
|
||||
{
|
||||
field.set(component, i);
|
||||
}
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,4 +99,5 @@ private:
|
||||
void DrawFieldTypeVector3(entt::meta_data& field, entt::meta_any& component);
|
||||
void DrawFieldTypeString(entt::meta_data& field, entt::meta_any& component);
|
||||
void DrawFieldTypeResourceFile(entt::meta_data& field, entt::meta_any& component);
|
||||
void DrawFieldTypeDynamicItemList(entt::meta_data& field, entt::meta_any& component);
|
||||
};
|
||||
@@ -10,7 +10,7 @@ namespace Nuake
|
||||
|
||||
struct ResourceFile
|
||||
{
|
||||
ResourceFile() {}
|
||||
ResourceFile() = default;
|
||||
ResourceFile(const Ref<File>& inFile) : file(inFile) {}
|
||||
|
||||
bool Exist();
|
||||
@@ -18,4 +18,10 @@ namespace Nuake
|
||||
|
||||
Ref<File> file = nullptr;
|
||||
};
|
||||
|
||||
struct DynamicItemList
|
||||
{
|
||||
std::vector<std::string> items;
|
||||
int index = -1;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user