Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BehaviorTreeFilePickerModal.h
Go to the documentation of this file.
1/**
2 * @file BehaviorTreeFilePickerModal.h
3 * @brief ImGui modal for selecting BehaviorTree files (Phase C).
4 * @author Olympe Engine
5 * @date 2026-03-15
6 *
7 * Provides a file browser dialog for users to select .bt.json behavior tree files
8 * to link with AIBehavior_data components in EntityPrefab editor.
9 * Pattern adapted from SubGraphFilePickerModal.
10 */
11
12#pragma once
13
14#include <string>
15#include <vector>
16
17namespace Olympe {
18
19/**
20 * @class BehaviorTreeFilePickerModal
21 * @brief ImGui modal dialog for selecting BehaviorTree .bt.json files.
22 *
23 * Usage:
24 * 1. Call Open() to initialize and show modal
25 * 2. Call Render() each frame (returns true if still open)
26 * 3. Check IsConfirmed() after close to see if user applied changes
27 * 4. Call GetSelectedFile() to get the chosen file path
28 * 5. Call Close() to dismiss modal
29 */
31public:
34
35 // ====================================================================
36 // Modal Lifecycle
37 // ====================================================================
38
39 /**
40 * @brief Opens the modal with optional initial path.
41 * @param currentPath If non-empty, shows this path as selected initially
42 */
43 void Open(const std::string& currentPath = "");
44
45 /**
46 * @brief Closes the modal without confirming changes.
47 */
48 void Close();
49
50 /**
51 * @brief Renders the modal UI. Call every frame while modal is open.
52 */
53 void Render();
54
55 // ====================================================================
56 // Query Results
57 // ====================================================================
58
59 /**
60 * @brief Returns true if modal is currently visible.
61 */
62 bool IsOpen() const { return m_isOpen; }
63
64 /**
65 * @brief Returns true if user clicked "Select" button.
66 * Call this after modal closes to check if changes should be applied.
67 */
68 bool IsConfirmed() const { return m_confirmed; }
69
70 /**
71 * @brief Returns the selected file path (only valid if IsConfirmed() is true).
72 */
73 const std::string& GetSelectedFile() const { return m_selectedFile; }
74
75private:
76 // ====================================================================
77 // Modal State
78 // ====================================================================
79
80 bool m_isOpen = false; ///< Is modal currently displayed
81 bool m_confirmed = false; ///< Did user click Select button
82 std::string m_selectedFile = ""; ///< The file path user selected
83 std::string m_currentPath = ""; ///< Current browse directory
84
85 // ====================================================================
86 // File Listing State
87 // ====================================================================
88
89 std::vector<std::string> m_behaviorTreeFiles; ///< .bt.json files in current directory
90 int m_selectedIndex = -1; ///< Currently highlighted file (-1 = none)
91
92 // ====================================================================
93 // UI State
94 // ====================================================================
95
96 char m_pathBuffer[512] = ""; ///< Directory path input buffer
97 char m_searchBuffer[128] = ""; ///< Search filter text
98
99 // ====================================================================
100 // Helper Methods
101 // ====================================================================
102
103 /**
104 * @brief Scans current directory for .bt.json behavior tree files.
105 * Populates m_behaviorTreeFiles with file names.
106 */
107 void RefreshFileList();
108
109 /**
110 * @brief Renders the file list with scrolling support.
111 */
112 void RenderFileList();
113
114 /**
115 * @brief Renders action buttons (Select, Cancel).
116 */
117 void RenderActionButtons();
118
119 /**
120 * @brief Filters file list by search term.
121 * @return Filtered file list
122 */
123 std::vector<std::string> GetFilteredFiles() const;
124};
125
126} // namespace Olympe
ImGui modal dialog for selecting BehaviorTree .bt.json files.
std::string m_selectedFile
The file path user selected.
char m_pathBuffer[512]
Directory path input buffer.
std::vector< std::string > m_behaviorTreeFiles
.bt.json files in current directory
void RenderActionButtons()
Renders action buttons (Select, Cancel).
int m_selectedIndex
Currently highlighted file (-1 = none)
std::vector< std::string > GetFilteredFiles() const
Filters file list by search term.
const std::string & GetSelectedFile() const
Returns the selected file path (only valid if IsConfirmed() is true).
void RenderFileList()
Renders the file list with scrolling support.
bool IsOpen() const
Returns true if modal is currently visible.
bool IsConfirmed() const
Returns true if user clicked "Select" button.
void Close()
Closes the modal without confirming changes.
bool m_isOpen
Is modal currently displayed.
void RefreshFileList()
Scans current directory for .bt.json behavior tree files.
bool m_confirmed
Did user click Select button.
std::string m_currentPath
Current browse directory.
void Open(const std::string &currentPath="")
Opens the modal with optional initial path.
< Provides AssetID and INVALID_ASSET_ID