Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
FilePickerModal.h
Go to the documentation of this file.
1/**
2 * @file FilePickerModal.h
3 * @brief Centralized file picker modal for all file selection operations (Phase 40).
4 * @author Olympe Engine
5 * @date 2026-03-20
6 *
7 * Provides a unified, reusable ImGui modal dialog for file selection across all editors.
8 * Supports multiple file types (BehaviorTree .bt.json, SubGraph .ats, etc.) via FilePickerType enum.
9 *
10 * This modal consolidates BehaviorTreeFilePickerModal and SubGraphFilePickerModal into a single
11 * implementation to avoid code duplication and provide consistent UX.
12 */
13
14#pragma once
15
16#include <string>
17#include <vector>
18
19namespace Olympe {
20
21/**
22 * @enum FilePickerType
23 * @brief Supported file types for the centralized file picker modal.
24 */
26{
27 BehaviorTree, ///< .bt.json files in ./Gamedata
28 SubGraph, ///< .ats files in Blueprints
29 Audio, ///< Future: .ogg, .wav files
30 Tileset ///< Future: .tsj tileset files
31};
32
33/**
34 * @class FilePickerModal
35 * @brief Centralized ImGui modal dialog for file selection across all editors.
36 *
37 * Usage:
38 * 1. FilePickerModal modal(FilePickerType::BehaviorTree);
39 * 2. modal.Open(currentPath);
40 * 3. During ImGui loop: modal.Render();
41 * 4. After frame: if (modal.IsConfirmed()) { path = modal.GetSelectedFile(); }
42 *
43 * Features:
44 * - Multi-file-type support via FilePickerType enum
45 * - Path navigation and editing
46 * - File list with scrolling
47 * - Search filter with case-insensitive matching
48 * - Selection confirmation (Select/Cancel buttons)
49 * - Centered modal with size constraints
50 * - Platform-specific file listing (Windows + Unix)
51 */
53public:
54 /**
55 * @brief Constructs a file picker modal for the given file type.
56 * @param fileType Type of files to browse (BehaviorTree, SubGraph, etc.)
57 */
59 ~FilePickerModal() = default;
60
61 // ====================================================================
62 // Modal Lifecycle
63 // ====================================================================
64
65 /**
66 * @brief Opens the modal with optional initial path.
67 * @param currentPath If non-empty, shows this path as starting location
68 *
69 * Initializes all modal state and refreshes the file list.
70 */
71 void Open(const std::string& currentPath = "");
72
73 /**
74 * @brief Closes the modal without confirming changes.
75 *
76 * User cancelled the dialog. IsConfirmed() will return false.
77 */
78 void Close();
79
80 /**
81 * @brief Renders the modal UI. Must be called every frame while open.
82 *
83 * Call this within the main ImGui rendering loop.
84 */
85 void Render();
86
87 // ====================================================================
88 // Query Results
89 // ====================================================================
90
91 /**
92 * @brief Returns true if modal is currently visible.
93 */
94 bool IsOpen() const { return m_isOpen; }
95
96 /**
97 * @brief Returns true if user clicked "Select" button.
98 *
99 * Call this after modal closes to check if user made a selection.
100 * Only use GetSelectedFile() if this returns true.
101 */
102 bool IsConfirmed() const { return m_confirmed; }
103
104 /**
105 * @brief Returns the selected file path (only valid if IsConfirmed() is true).
106 *
107 * Path format depends on file type:
108 * - BehaviorTree: "./Gamedata/MyTree.bt.json"
109 * - SubGraph: "Blueprints/MyBlueprint.ats"
110 */
111 const std::string& GetSelectedFile() const { return m_selectedFile; }
112
113 /**
114 * @brief Returns the file type this modal handles.
115 */
117
118private:
119 // ====================================================================
120 // Configuration & State
121 // ====================================================================
122
123 FilePickerType m_fileType; ///< Type of files to browse
124 bool m_isOpen = false; ///< Is modal currently visible
125 bool m_confirmed = false; ///< Did user click Select
126 std::string m_selectedFile = ""; ///< Full path to selected file
127 std::string m_currentPath = ""; ///< Current directory being browsed
128
129 // ====================================================================
130 // File Listing State
131 // ====================================================================
132
133 std::vector<std::string> m_fileList; ///< Files found in current directory
134 std::vector<std::string> m_folderList; ///< Folders in current directory
135 int m_selectedIndex = -1; ///< Currently highlighted file (-1 = none)
136
137 // ====================================================================
138 // UI State
139 // ====================================================================
140
141 char m_pathBuffer[512] = ""; ///< Path input text buffer
142 char m_searchBuffer[128] = ""; ///< Search filter text buffer
143 int m_selectedFilterIndex = 0; ///< Current filter type (0=default, 1=.bt.json, etc.)
144 std::string m_currentFilter = ""; ///< Current file extension filter
145
146 // ====================================================================
147 // Helper Methods
148 // ====================================================================
149
150 /**
151 * @brief Returns the default directory for this file type.
152 */
153 std::string GetDefaultDirectory() const;
154
155 /**
156 * @brief Returns the file pattern for this file type (e.g., "*.bt.json").
157 */
158 std::string GetFilePattern() const;
159
160 /**
161 * @brief Returns the modal title for this file type (e.g., "Select BehaviorTree File").
162 */
163 std::string GetModalTitle() const;
164
165 /**
166 * @brief Returns the description text for this file type.
167 */
168 std::string GetDescriptionText() const;
169
170 /**
171 * @brief Refreshes file list from current directory.
172 *
173 * Searches for files matching the pattern for this file type.
174 * Logs results to SYSTEM_LOG.
175 */
176 void RefreshFileList();
177
178 /**
179 * @brief Renders the file list UI component with scrolling and selection.
180 */
181 void RenderFileList();
182
183 /**
184 * @brief Renders the action buttons (Select, Cancel).
185 *
186 * Select button is disabled if no file is selected.
187 */
188 void RenderActionButtons();
189
190 /**
191 * @brief Filters and returns files matching the search buffer.
192 * @return Vector of matching filenames (case-insensitive substring matching)
193 */
194 std::vector<std::string> GetFilteredFiles() const;
195
196};
197
198} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Centralized ImGui modal dialog for file selection across all editors.
std::vector< std::string > GetFilteredFiles() const
Filters and returns files matching the search buffer.
char m_searchBuffer[128]
Search filter text buffer.
void RenderActionButtons()
Renders the action buttons (Select, Cancel).
const std::string & GetSelectedFile() const
Returns the selected file path (only valid if IsConfirmed() is true).
std::string m_selectedFile
Full path to selected file.
void Close()
Closes the modal without confirming changes.
std::string m_currentFilter
Current file extension filter.
bool m_isOpen
Is modal currently visible.
int m_selectedIndex
Currently highlighted file (-1 = none)
void RenderFileList()
Renders the file list UI component with scrolling and selection.
std::string GetModalTitle() const
Returns the modal title for this file type (e.g., "Select BehaviorTree File").
bool m_confirmed
Did user click Select.
void Open(const std::string &currentPath="")
Opens the modal with optional initial path.
void Render()
Renders the modal UI.
std::vector< std::string > m_fileList
Files found in current directory.
std::string GetFilePattern() const
Returns the file pattern for this file type (e.g., "*.bt.json").
FilePickerType GetFileType() const
Returns the file type this modal handles.
int m_selectedFilterIndex
Current filter type (0=default, 1=.bt.json, etc.)
bool IsOpen() const
Returns true if modal is currently visible.
std::string GetDefaultDirectory() const
Returns the default directory for this file type.
std::vector< std::string > m_folderList
Folders in current directory.
FilePickerType m_fileType
Type of files to browse.
std::string GetDescriptionText() const
Returns the description text for this file type.
bool IsConfirmed() const
Returns true if user clicked "Select" button.
std::string m_currentPath
Current directory being browsed.
char m_pathBuffer[512]
Path input text buffer.
void RefreshFileList()
Refreshes file list from current directory.
< Provides AssetID and INVALID_ASSET_ID
FilePickerType
Supported file types for the centralized file picker modal.
@ Tileset
Future: .tsj tileset files.
@ Audio
Future: .ogg, .wav files.
@ BehaviorTree
.bt.json files in ./Gamedata
@ SubGraph
Teal — SubGraph call.