Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
SaveFilePickerModal.h
Go to the documentation of this file.
1/**
2 * @file SaveFilePickerModal.h
3 * @brief Centralized Save As modal for all file save operations (Phase 40 Enhancement).
4 * @author Olympe Engine
5 * @date 2026-03-21
6 *
7 * Provides a unified ImGui modal dialog for file saving across all editors.
8 * Automatically handles file extensions based on file type.
9 */
10
11#pragma once
12
13#include <string>
14#include <vector>
15
16namespace Olympe {
17
18/**
19 * @enum SaveFileType
20 * @brief Supported file types for the centralized save modal.
21 */
22enum class SaveFileType
23{
24 BehaviorTree, ///< .bt.json files
25 Blueprint, ///< .ats files (SubGraph/VisualScript)
26 EntityPrefab, ///< .pref.json files (Entity Prefab)
27 Audio ///< .ogg files (audio assets)
28};
29
30/**
31 * @class SaveFilePickerModal
32 * @brief Centralized ImGui modal dialog for file saving across all editors.
33 *
34 * Usage:
35 * 1. SaveFilePickerModal modal(SaveFileType::BehaviorTree);
36 * 2. modal.Open(defaultDirectory, suggestedFilename);
37 * 3. During ImGui loop: modal.Render();
38 * 4. After frame: if (modal.IsConfirmed()) { path = modal.GetSelectedFile(); }
39 *
40 * Features:
41 * - Auto-extension handling based on SaveFileType
42 * - Path navigation
43 * - Filename input with optional extension preview
44 * - Overwrite confirmation if file exists
45 * - Folder navigation with ".." for parent directory
46 * - Platform-specific implementation (Windows + Unix)
47 */
49public:
50 /**
51 * @brief Constructs a save file picker modal for the given file type.
52 * @param fileType Type of file to save (BehaviorTree, Blueprint, etc.)
53 */
56
57 // ====================================================================
58 // Modal Lifecycle
59 // ====================================================================
60
61 /**
62 * @brief Opens the modal with initial directory and filename.
63 * @param directory Starting directory path
64 * @param suggestedFilename Suggested filename (without extension)
65 *
66 * Extension will be automatically appended based on file type.
67 */
68 void Open(const std::string& directory, const std::string& suggestedFilename = "");
69
70 /**
71 * @brief Closes the modal without confirming changes.
72 */
73 void Close();
74
75 /**
76 * @brief Renders the modal UI. Must be called every frame while open.
77 */
78 void Render();
79
80 // ====================================================================
81 // Query Results
82 // ====================================================================
83
84 /**
85 * @brief Returns true if modal is currently visible.
86 */
87 bool IsOpen() const { return m_isOpen; }
88
89 /**
90 * @brief Returns true if user clicked "Save" button.
91 */
92 bool IsConfirmed() const { return m_confirmed; }
93
94 /**
95 * @brief Returns the selected file path with extension (only valid if IsConfirmed() is true).
96 *
97 * Example: "Gamedata/MyTree.bt.json"
98 */
99 const std::string& GetSelectedFile() const { return m_selectedFile; }
100
101 /**
102 * @brief Returns the file type this modal handles.
103 */
105
106private:
107 // ====================================================================
108 // Configuration & State
109 // ====================================================================
110
111 SaveFileType m_fileType; ///< Type of file to save
112 bool m_isOpen = false; ///< Is modal currently visible
113 bool m_confirmed = false; ///< Did user click Save
114 std::string m_selectedFile = ""; ///< Full path with extension
115 std::string m_currentPath = ""; ///< Current directory
116
117 // ====================================================================
118 // File Listing State
119 // ====================================================================
120
121 std::vector<std::string> m_fileList; ///< Files in current directory
122 std::vector<std::string> m_folderList; ///< Folders in current directory
123
124 // ====================================================================
125 // UI State
126 // ====================================================================
127
128 char m_pathBuffer[512] = ""; ///< Path input text buffer
129 char m_filenameBuffer[256] = ""; ///< Filename input (without extension)
130 bool m_showOverwriteConfirm = false; ///< Show overwrite confirmation dialog
131
132 // ====================================================================
133 // Helper Methods
134 // ====================================================================
135
136 /**
137 * @brief Returns the default directory for this file type.
138 */
139 std::string GetDefaultDirectory() const;
140
141 /**
142 * @brief Returns the file extension for this file type (e.g., ".bt.json").
143 */
144 std::string GetFileExtension() const;
145
146 /**
147 * @brief Returns a description of this file type for the modal title.
148 */
149 std::string GetModalTitle() const;
150
151 /**
152 * @brief Returns user-friendly description text.
153 */
154 std::string GetDescriptionText() const;
155
156 /**
157 * @brief Refreshes the file and folder lists for the current directory.
158 */
159 void RefreshFileList();
160
161 /**
162 * @brief Renders the file list in the modal.
163 */
164 void RenderFileList();
165
166 /**
167 * @brief Renders folder navigation.
168 */
169 void RenderFolderList();
170
171 /**
172 * @brief Renders filename input and extension display.
173 */
174 void RenderFilenameInput();
175
176 /**
177 * @brief Renders action buttons (Save/Cancel).
178 */
179 void RenderActionButtons();
180
181 /**
182 * @brief Checks if a file exists at the given path.
183 */
184 bool FileExists(const std::string& path) const;
185
186 /**
187 * @brief Renders the overwrite confirmation dialog.
188 */
190};
191
192} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Centralized ImGui modal dialog for file saving across all editors.
void Close()
Closes the modal without confirming changes.
void RenderActionButtons()
Renders action buttons (Save/Cancel).
void RenderFolderList()
Renders folder navigation.
std::string GetModalTitle() const
Returns a description of this file type for the modal title.
std::string GetDefaultDirectory() const
Returns the default directory for this file type.
SaveFileType GetFileType() const
Returns the file type this modal handles.
const std::string & GetSelectedFile() const
Returns the selected file path with extension (only valid if IsConfirmed() is true).
std::vector< std::string > m_fileList
Files in current directory.
bool m_showOverwriteConfirm
Show overwrite confirmation dialog.
std::string GetDescriptionText() const
Returns user-friendly description text.
bool IsOpen() const
Returns true if modal is currently visible.
std::string m_currentPath
Current directory.
void RefreshFileList()
Refreshes the file and folder lists for the current directory.
void Open(const std::string &directory, const std::string &suggestedFilename="")
Opens the modal with initial directory and filename.
std::vector< std::string > m_folderList
Folders in current directory.
void RenderOverwriteConfirmation()
Renders the overwrite confirmation dialog.
char m_pathBuffer[512]
Path input text buffer.
SaveFileType m_fileType
Type of file to save.
void RenderFileList()
Renders the file list in the modal.
char m_filenameBuffer[256]
Filename input (without extension)
std::string m_selectedFile
Full path with extension.
bool m_confirmed
Did user click Save.
bool IsConfirmed() const
Returns true if user clicked "Save" button.
void Render()
Renders the modal UI.
void RenderFilenameInput()
Renders filename input and extension display.
std::string GetFileExtension() const
Returns the file extension for this file type (e.g., ".bt.json").
bool m_isOpen
Is modal currently visible.
bool FileExists(const std::string &path) const
Checks if a file exists at the given path.
< Provides AssetID and INVALID_ASSET_ID
@ Audio
Future: .ogg, .wav files.
@ BehaviorTree
.bt.json files in ./Gamedata
SaveFileType
Supported file types for the centralized save modal.
@ Blueprint
.ats files (SubGraph/VisualScript)