diff --git a/Engine/Source/Editor/UILayers/AssetBrowser.cpp b/Engine/Source/Editor/UILayers/AssetBrowser.cpp index 898b8c95..0c17ca7e 100644 --- a/Engine/Source/Editor/UILayers/AssetBrowser.cpp +++ b/Engine/Source/Editor/UILayers/AssetBrowser.cpp @@ -348,7 +348,7 @@ void AssetBrowser::UpdateAssetFolderTree() //m_pImportFileBrowser->SetTypeFilters({ ".dds", "*.exr", "*.hdr", "*.ktx", ".tga" }); m_pImportFileBrowser->Open(); - CD_INFO("Import asset type: {}", GetIOAssetTypeName(m_importOptions.AssetType)); + CD_INFO("Import asset type: {}", nameof::nameof_enum(m_importOptions.AssetType)); } else if (ImGui::Selectable("Shader")) @@ -358,7 +358,7 @@ void AssetBrowser::UpdateAssetFolderTree() //m_pImportFileBrowser->SetTypeFilters({ ".sc" }); // ".hlsl" m_pImportFileBrowser->Open(); - CD_INFO("Import asset type: {}", GetIOAssetTypeName(m_importOptions.AssetType)); + CD_INFO("Import asset type: {}", nameof::nameof_enum(m_importOptions.AssetType)); } else if (ImGui::Selectable("Model")) { @@ -367,7 +367,7 @@ void AssetBrowser::UpdateAssetFolderTree() //m_pImportFileBrowser->SetTypeFilters({ ".fbx", ".gltf" }); // ".obj", ".dae", ".ogex" m_pImportFileBrowser->Open(); - CD_INFO("Import asset type: {}", GetIOAssetTypeName(m_importOptions.AssetType)); + CD_INFO("Import asset type: {}", nameof::nameof_enum(m_importOptions.AssetType)); } #ifdef ENABLE_DDGI @@ -402,7 +402,7 @@ void AssetBrowser::UpdateAssetFolderTree() m_pExportFileBrowser->SetTitle("ExportAssets - SceneDatabase"); m_pExportFileBrowser->Open(); - CD_INFO("Export asset type: {}", GetIOAssetTypeName(m_exportOptions.AssetType)); + CD_INFO("Export asset type: {}", nameof::nameof_enum(m_exportOptions.AssetType)); } ImGui::EndPopup(); @@ -875,7 +875,7 @@ void AssetBrowser::ProcessSceneDatabase(cd::SceneDatabase* pSceneDatabase, bool pSceneDatabase->GetTextures().clear(); for (auto& material : pSceneDatabase->GetMaterials()) { - for (int textureTypeIndex = 0; textureTypeIndex < static_cast(cd::MaterialTextureType::Count); ++textureTypeIndex) + for (int textureTypeIndex = 0; textureTypeIndex < nameof::enum_count(); ++textureTypeIndex) { material.RemoveTexture(static_cast(textureTypeIndex)); } diff --git a/Engine/Source/Editor/UILayers/AssetBrowser.h b/Engine/Source/Editor/UILayers/AssetBrowser.h index ad18a10c..3fb19549 100644 --- a/Engine/Source/Editor/UILayers/AssetBrowser.h +++ b/Engine/Source/Editor/UILayers/AssetBrowser.h @@ -39,30 +39,8 @@ enum class IOAssetType Terrain, Light, Unknown, - - Count, -}; - -constexpr const char *IOAssetTypeName[] = -{ - "CubeMap", - "DDGIModel", - "Model", - "Shader", - "SceneDatabase", - "Terrain", - "Light", - "Unknown", }; -static_assert(static_cast(IOAssetType::Count) == sizeof(IOAssetTypeName) / sizeof(char*), - "IO asset type and names mismatch."); - -CD_FORCEINLINE const char* GetIOAssetTypeName(IOAssetType type) -{ - return IOAssetTypeName[static_cast(type)]; -} - struct AssetImportOptions { IOAssetType AssetType = IOAssetType::Unknown; diff --git a/Engine/Source/Editor/UILayers/Inspector.cpp b/Engine/Source/Editor/UILayers/Inspector.cpp index 5602c2be..821f9a3b 100644 --- a/Engine/Source/Editor/UILayers/Inspector.cpp +++ b/Engine/Source/Editor/UILayers/Inspector.cpp @@ -187,7 +187,7 @@ void UpdateComponentWidget(engine::SceneWorld* pScene { // TODO : generic cull mode. ImGuiUtils::ImGuiBoolProperty("TwoSided", pMaterialComponent->GetTwoSided()); - ImGuiUtils::ImGuiStringProperty("BlendMode", nameof::nameof_enum(pMaterialComponent->GetBlendMode()).data()); + ImGuiUtils::ImGuiEnumProperty("BlendMode", pMaterialComponent->GetBlendMode()); } ImGui::Separator(); @@ -200,7 +200,7 @@ void UpdateComponentWidget(engine::SceneWorld* pScene } // Textures - for (int textureTypeValue = 0; textureTypeValue < static_cast(cd::MaterialTextureType::Count); ++textureTypeValue) + for (int textureTypeValue = 0; textureTypeValue < nameof::enum_count(); ++textureTypeValue) { auto textureType = static_cast(textureTypeValue); bool allowNoTextures = textureType == cd::MaterialTextureType::BaseColor || @@ -386,7 +386,7 @@ void UpdateComponentWidget(engine::SceneWorld* pSceneWor if (isOpen) { cd::LightType lightType = pLightComponent->GetType(); - std::string lightTypeName = cd::GetLightTypeName(lightType); + std::string lightTypeName(nameof::nameof_enum(lightType)); ImGuiUtils::ImGuiStringProperty("Type", lightTypeName); ImGuiUtils::ColorPickerProperty("Color", pLightComponent->GetColor()); @@ -559,25 +559,11 @@ void UpdateComponentWidget(engine::SceneWorld* pSceneWorld if (!skyTypes.empty()) { - static const char* crtItem = nameof::nameof_enum(engine::SkyType::SkyBox).data(); - if (ImGui::BeginCombo("##combo", crtItem)) + auto currentSkyType = pSkyComponent->GetSkyType(); + if (ImGuiUtils::ImGuiEnumProperty("SkyType", currentSkyType)) { - for (size_t index = 0; index < skyTypes.size(); ++index) - { - bool isSelected = (crtItem == skyTypes[index]); - if (ImGui::Selectable(skyTypes[index], isSelected)) - { - crtItem = skyTypes[index]; - pSkyComponent->SetSkyType(static_cast(index)); - } - if (isSelected) - { - ImGui::SetItemDefaultFocus(); - } - } - ImGui::EndCombo(); + pSkyComponent->SetSkyType(currentSkyType); } - } if (pSkyComponent->GetAtmophericScatteringEnable()) diff --git a/Engine/Source/Editor/UILayers/MainMenu.cpp b/Engine/Source/Editor/UILayers/MainMenu.cpp index 700530b7..6a241d1a 100644 --- a/Engine/Source/Editor/UILayers/MainMenu.cpp +++ b/Engine/Source/Editor/UILayers/MainMenu.cpp @@ -84,11 +84,9 @@ void MainMenu::EditMenu() if (ImGui::BeginMenu(CD_TEXT("TEXT_STYLE"))) { - // It is not convenient in C++ to loop enum except define an extra array to wrap them. - // C++ 20/23 ranges may look better but still needs std::iota inside its implementation. - for (engine::ThemeColor theme = engine::ThemeColor::Black; theme < engine::ThemeColor::Count; - theme = static_cast(static_cast(theme) + 1)) + for (uint32_t index = 0U; index < nameof::enum_count(); ++index) { + engine::ThemeColor theme = static_cast(index); engine::ImGuiContextInstance* pImGuiContextInstance = GetImGuiContextInstance(); if (ImGui::MenuItem(nameof::nameof_enum(theme).data(), "", pImGuiContextInstance->GetImGuiThemeColor() == theme)) { @@ -101,9 +99,9 @@ void MainMenu::EditMenu() if (ImGui::BeginMenu(CD_TEXT("TEXT_LANGUAGE"))) { - for (engine::Language language = engine::Language::ChineseSimplied; language < engine::Language::Count; - language = static_cast(static_cast(language) + 1)) + for (uint32_t index = 0U; index < nameof::enum_count(); ++index) { + engine::Language language = static_cast(index); engine::ImGuiContextInstance* pImGuiContextInstance = GetImGuiContextInstance(); if (ImGui::MenuItem(nameof::nameof_enum(language).data(), "", pImGuiContextInstance->GetImGuiLanguage() == language)) { diff --git a/Engine/Source/Runtime/ECWorld/SceneWorld.cpp b/Engine/Source/Runtime/ECWorld/SceneWorld.cpp index 080c99cc..6d69e27f 100644 --- a/Engine/Source/Runtime/ECWorld/SceneWorld.cpp +++ b/Engine/Source/Runtime/ECWorld/SceneWorld.cpp @@ -251,7 +251,7 @@ void SceneWorld::AddMaterialToSceneDatabase(engine::Entity entity) pMaterialData->SetFloatProperty(cd::MaterialPropertyGroup::Roughness, cd::MaterialProperty::Factor, pMaterialComponent->GetRoughnessFactor()); pMaterialData->SetBoolProperty(cd::MaterialPropertyGroup::General, cd::MaterialProperty::TwoSided, pMaterialComponent->GetTwoSided()); - for (int textureTypeValue = 0; textureTypeValue (cd::MaterialTextureType::Count); ++textureTypeValue) + for (int textureTypeValue = 0; textureTypeValue < nameof::enum_count(); ++textureTypeValue) { if (MaterialComponent::TextureInfo* textureInfo = pMaterialComponent->GetTextureInfo(static_cast(textureTypeValue))) { diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index 48734b9c..d929a147 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -7,6 +7,7 @@ #include "Math/UnitSystem.hpp" #include + namespace ImGuiUtils { @@ -15,6 +16,44 @@ static bool ImGuiBoolProperty(const char* pName, bool& value) return ImGui::Checkbox(pName, &value); } +template +static bool ImGuiEnumProperty(const char* pName, EnumType& value) +{ + bool dirty = false; + + ImGui::Columns(2); + ImGui::TextUnformatted(pName); + ImGui::NextColumn(); + ImGui::PushItemWidth(-1); + + if (ImGui::BeginCombo("##combo", nameof::nameof_enum(value).data())) + { + auto enumCount = nameof::enum_count(); + for (uint32_t enumIndex = 0U; enumIndex < enumCount; ++enumIndex) + { + EnumType enumValue = static_cast(enumIndex); + bool isSelected = enumValue == value; + if (ImGui::Selectable(nameof::nameof_enum(enumValue).data(), isSelected)) + { + value = enumValue; + dirty = true; + } + + if (isSelected) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + + ImGui::PopItemWidth(); + ImGui::NextColumn(); + ImGui::Columns(1); + + return dirty; +} + static bool ImGuiStringProperty(const char* pName, const char* pValue) { ImGui::Columns(2); diff --git a/Engine/Source/Runtime/ImGui/Language.h b/Engine/Source/Runtime/ImGui/Language.h index a4977564..751f67ab 100644 --- a/Engine/Source/Runtime/ImGui/Language.h +++ b/Engine/Source/Runtime/ImGui/Language.h @@ -13,8 +13,7 @@ enum class Language Japanese, Korean, Thai, - Vitnam, - Count, + Vitnam }; } \ No newline at end of file diff --git a/Engine/Source/Runtime/ImGui/ThemeColor.h b/Engine/Source/Runtime/ImGui/ThemeColor.h index d3c42242..1b798c36 100644 --- a/Engine/Source/Runtime/ImGui/ThemeColor.h +++ b/Engine/Source/Runtime/ImGui/ThemeColor.h @@ -9,8 +9,7 @@ enum class ThemeColor Classic, Dark, Grey, - Light, - Count + Light }; } \ No newline at end of file diff --git a/Engine/Source/ThirdParty/AssetPipeline b/Engine/Source/ThirdParty/AssetPipeline index a136b098..c5ad7de0 160000 --- a/Engine/Source/ThirdParty/AssetPipeline +++ b/Engine/Source/ThirdParty/AssetPipeline @@ -1 +1 @@ -Subproject commit a136b09867907e5adf72fa3d72602f05a60bf4eb +Subproject commit c5ad7de0bde5229052423badc9f2d40cfd79472c