From 5e6b190223a2d144fc643894633f6f8d1c052a99 Mon Sep 17 00:00:00 2001 From: myT <> Date: Sat, 28 Dec 2024 19:11:47 +0100 Subject: [PATCH] added file dialog pk3 filtering and kb navigation --- code/client/cl_imgui.cpp | 47 +++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/code/client/cl_imgui.cpp b/code/client/cl_imgui.cpp index 6e68cbd..bad892e 100644 --- a/code/client/cl_imgui.cpp +++ b/code/client/cl_imgui.cpp @@ -180,24 +180,37 @@ static bool DoFileDialog(FileDialog& dialog) bool success = false; if(ImGui::BeginPopupModal(dialog.dialogName, NULL, ImGuiWindowFlags_AlwaysAutoResize)) { + static bool showFilesInPaks = false; + if(!dialog.folderMode) + { + ImGui::Checkbox("Show files in PK3s", &showFilesInPaks); + } + if(BeginTable(dialog.folderMode ? "Folders" : "Files", 1)) { for(int i = 0; i < dialog.fileCount; i++) { + const char* const filePath = dialog.filePaths[i]; if(dialog.folderMode && - (Q_stricmp(dialog.filePaths[i], ".") == 0 || - Q_stricmp(dialog.filePaths[i], "..") == 0)) + (Q_stricmp(filePath, ".") == 0 || Q_stricmp(filePath, "..") == 0)) + { + continue; + } + + if(!dialog.folderMode && + !showFilesInPaks && + FS_FileIsInPAK(va("%s/%s", dialog.folder, filePath), NULL, NULL)) { continue; } ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - if(ImGui::Selectable(dialog.filePaths[i], i == dialog.selectedFileIndex, + if(ImGui::Selectable(filePath, i == dialog.selectedFileIndex, ImGuiSelectableFlags_DontClosePopups)) { dialog.selectedFileIndex = i; - Q_strncpyz(dialog.fileName, dialog.filePaths[i], sizeof(dialog.fileName)); + Q_strncpyz(dialog.fileName, filePath, sizeof(dialog.fileName)); } } ImGui::EndTable(); @@ -205,12 +218,26 @@ static bool DoFileDialog(FileDialog& dialog) if(dialog.saveMode) { + if(ImGui::IsWindowAppearing()) + { + ImGui::SetKeyboardFocusHere(); + } if(ImGui::InputText(dialog.folderMode ? "Folder path" : "File path", dialog.fileName, sizeof(dialog.fileName))) { dialog.selectedFileIndex = -1; } - if(ImGui::Button("Save") && + bool save = false; + if(ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) + { + save = true; + } + if(ImGui::Button("Save")) + { + save = true; + } + + if(save && dialog.fileName[0] != '\0' && dialog.fileName[0] != '.') { @@ -246,8 +273,18 @@ static bool DoFileDialog(FileDialog& dialog) } } + bool cancel = false; ImGui::SameLine(); if(ImGui::Button("Cancel")) + { + cancel = true; + } + if(ImGui::IsKeyPressed(ImGuiKey_Escape, false)) + { + cancel = true; + } + + if(cancel) { FS_FreeFileList(dialog.filePaths); dialog.filePaths = NULL;