diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-28 11:37:03 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-28 11:37:03 -0500 |
| commit | 41b5dafb1a3bf80db48abeb235ce00ec8e1c566f (patch) | |
| tree | 43060def473ca22710af744178e678dff936d213 /editor | |
| parent | 3187a32f7f0253ded7a41c4c21612253e525a8fe (diff) | |
first pass - add Asset Picker to editor
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 102 |
1 files changed, 89 insertions, 13 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index e66f14c..3a8e068 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -59,6 +59,7 @@ InputActionSetHandle debugControlsHandle = InputActionSetHandle_MAX; bool shouldSetupEditor = true; bool shouldDisableEditor = false; bool shouldRebuildProjectDir = true; +bool shouldRebuildAssetList = true; struct EntityTypeInstanceCreateInfo { EntityHandle entityTypeEntityHandle; @@ -438,6 +439,58 @@ void RecordImGui_GLM(const char *label, glm::mat4 &mat) { } } +struct assetLabel { + AssetKey key = {'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'}; + AssetHandle handle{}; +}; +DynArray<assetLabel> assetEntries{0, nullptr}; +int assetLabelCmp(const void *a, const void *b) { + const auto &tA = *static_cast<const assetLabel *>(a); + const auto &tB = *static_cast<const assetLabel *>(b); + return strcmp(tA.key, tB.key); +} +void buildAssetLableList() { + +} +struct AssetPickerSearchStruct { + int64_t selectedItem = -1; + char source[8]; + char safeKey[AssetKeyLength + 1]; +}; +void RecordImGui_AssetPicker(AssetPickerSearchStruct &apss) { + if (shouldRebuildAssetList == true) { + if (assetEntries.Count() == 0) { + uint64_t bCount = AM_GetBucketCount(); + for (uint64_t b = 0; b < bCount; ++b) { + uint64_t iCount = 0; + Asset *assets = AM_GetAssets(b, iCount); + for (long i = 0; i < iCount; ++i) { + const Asset &a = assets[i]; + assetLabel &al = assetEntries.Push(); + memcpy(al.key, a.key, AssetKeyLength); + al.handle = a.handle; + } + } + } + std::qsort(assetEntries.GetPtr(), assetEntries.Count(), sizeof(assetLabel), assetLabelCmp); + } + if (ImGui::BeginPopup(apss.source)) { + ImGui::SeparatorText("Asset"); + const int64_t iCount = assetEntries.Count(); + for (int64_t i = 0; i < iCount; ++i) { + const assetLabel &al = assetEntries[i]; + char buf[AssetKeyLength + 1]; + snprintf(buf, AssetKeyLength + 1, "%s", al.key); + if (ImGui::Selectable(buf, apss.selectedItem == i)) { + snprintf(apss.safeKey, AssetKeyLength + 1, "%s", buf); + apss.selectedItem = i; + ImGui::CloseCurrentPopup(); + } + } + ImGui::EndPopup(); + } +} + void RecordImGuiEditorWrapper() { ImGui::DockSpaceOverViewport(nullptr, ImGuiDockNodeFlags_PassthruCentralNode); ImGui::BeginMainMenuBar(); @@ -721,12 +774,28 @@ bool RecordImGui_CallbackSelectModal(long &selectedIndex) { void RecordImGuiModalCreateEntityType() { if (ImGui::BeginPopupModal("CreateEntityType", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - static char modelKey[AssetKeyLength + 1]; - static char textureKey[AssetKeyLength + 1]; static char entityTypeCode[32]; - - ImGui::InputText("Model Key", modelKey, AssetKeyLength); - ImGui::InputText("Texture Key", textureKey, AssetKeyLength); + static AssetPickerSearchStruct apssModel{ + .source = {"cet_mdl"}, + .safeKey = {""}, + }; + static AssetPickerSearchStruct apssTexture{ + .source = {"cet_txr"}, + .safeKey = {""}, + }; + + if (ImGui::Button("Model Key")) { + ImGui::OpenPopup(apssModel.source); + } + ImGui::SameLine(); + ImGui::Text("%s", apssModel.safeKey); + RecordImGui_AssetPicker(apssModel); + if (ImGui::Button("Texture Key")) { + ImGui::OpenPopup(apssTexture.source); + } + ImGui::SameLine(); + ImGui::Text("%s", apssTexture.safeKey); + RecordImGui_AssetPicker(apssTexture); ImGui::InputText("Entity Type Code", entityTypeCode, 31); ImGui::InputScalar("Starting Instance Count", ImGuiDataType_U32, &entityTypeToCreate.startingInstanceCount); ImGui::InputScalar("GLTF Import Index - Vertex", ImGuiDataType_S16, &entityTypeToCreate.Importer_GLTF.AccessorIndexVertex); @@ -741,25 +810,32 @@ void RecordImGuiModalCreateEntityType() { if (ImGui::Button("Create")) { // TODO some type of validation - modelKey[0] = '\0'; - textureKey[0] = '\0'; - entityTypeCode[0] = '\0'; - modelKey[AssetKeyLength] = '\0'; - textureKey[AssetKeyLength] = '\0'; - entityTypeCode[31] = '\0'; - strncpy(entityTypeToCreate.modelAssetKey, modelKey, AssetKeyLength); - strncpy(entityTypeToCreate.textureAssetKey, textureKey, AssetKeyLength); + strncpy(entityTypeToCreate.modelAssetKey, apssModel.safeKey, AssetKeyLength); + strncpy(entityTypeToCreate.textureAssetKey, apssTexture.safeKey, AssetKeyLength); char *sEntityTypeCode = Pke_New<char>(strlen(entityTypeCode) + 1); strncpy(sEntityTypeCode, entityTypeCode, 31); entityTypeToCreate.entityTypeCode = sEntityTypeCode; shouldCreateEntityType = true; + + apssModel.safeKey[0] = '\0'; + apssTexture.safeKey[0] = '\0'; + entityTypeCode[0] = '\0'; + apssModel.safeKey[AssetKeyLength] = '\0'; + apssTexture.safeKey[AssetKeyLength] = '\0'; + entityTypeCode[31] = '\0'; ImGui::CloseCurrentPopup(); } ImGui::SameLine(); if (ImGui::Button("Cancel")) { + apssModel.safeKey[0] = '\0'; + apssTexture.safeKey[0] = '\0'; + entityTypeCode[0] = '\0'; + apssModel.safeKey[AssetKeyLength] = '\0'; + apssTexture.safeKey[AssetKeyLength] = '\0'; + entityTypeCode[31] = '\0'; ImGui::CloseCurrentPopup(); } |
