Doxygen Samurai Engine 0.0.1
Doxygen Samurai Engine Documentation
Loading...
Searching...
No Matches
assetManagerWindow.cpp
Go to the documentation of this file.
2
3#if SAMURAI_WINDOWS
4#define NOMINMAX
5#include <Windows.h>
6#endif
7
8
9namespace samurai
10{
11
16
17 void AssetManagerWindow::update(bool &open, ContainerManager &containerManager, LoadedDll &currentDll,
19 {
20 ImGui::PushID(imguiId);
21
22
23 if (!ImGui::Begin(ICON_NAME, &open))
24 {
25 ImGui::End();
26 ImGui::PopID();
27 return;
28 }
29
30 //todo: for all windows
31 ImGui::SetWindowSize({300,100}, ImGuiCond_FirstUseEver);
32
33 if(std::filesystem::equivalent(currentPath, SAMURAI_RESOURCES_PATH) || searchText[0] != '\0')
34 {
35 ImGui::BeginDisabled(1);
36 }
37 else
38 {
39 ImGui::BeginDisabled(0);
40 }
41
42 if (ImGui::Button(ICON_FK_ARROW_UP))
43 {
44 currentPath = currentPath.parent_path();
45 }
46
47 ImGui::EndDisabled();
48
49 ImGui::SameLine();
50
51 ImGui::InputText("Search file", searchText, sizeof(searchText));
52
53 ImGui::SameLine();
54
55 if (ImGui::Button("Open resources folder"))
56 {
57 #if SAMURAI_WINDOWS
58 ShellExecuteA(NULL, "open", SAMURAI_RESOURCES_PATH, NULL, NULL, SW_RESTORE);
59 #endif
60 }
61
62 std::string longPath = currentPath.string();
63 std::string root = SAMURAI_RESOURCES_PATH;
64 std::string enginePath = "SAMURAI_RESOURCES_PATH/";
65 if (longPath.size() > root.size())
66 {
67 enginePath += (longPath.c_str() + root.size());
68 }
69
70 for (char &c : enginePath)
71 {
72 if (c == '\\')
73 {
74 c = '/';
75 }
76 }
77
78 ImGui::Text(enginePath.c_str());
79
80 ImGui::Separator();
81
82 float contentW = ImGui::GetContentRegionAvail().x;
83 const float size = 160;
84 const float padding = 10;
85
86 ImGui::Columns( std::max(1, (int)(contentW / (size + padding))), 0, false);
87
88 //returns 1 if should break
89 auto displayItem = [&](const std::filesystem::directory_entry &p) -> bool
90 {
91 if (ImGui::BeginChild(p.path().filename().string().c_str(), {size, size + 40}, false,
92 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
93 {
94 //ImGui::
95 ImFontAtlas *atlas = ImGui::GetIO().Fonts;
96
97 ImGui::PushFont(atlas->Fonts[1]);
98
99 if (p.is_directory())
100 {
101
102 if (ImGui::Button(ICON_FK_FOLDER_O, {size ,size}))
103 {
104 currentPath = p;
105
106 //todo deffer
107 ImGui::PopFont();
108 ImGui::EndChild();
109 ImGui::Columns();
110 return 1;
111 }
112 }
113 else
114 {
115 if (ImGui::Button(ICON_FK_FILE_O, {size ,size}))
116 {
117 auto it = currentDll.containerExtensionsSupport.find(p.path().filename().extension().string());
118 if (it != currentDll.containerExtensionsSupport.end())
119 {
120 //todo name
121 containerManager.createContainer(it->second, currentDll, logManager, imguiIDsManager, p.path().string());
122 }
123 }
124 }
125
126 ImGui::PopFont();
127
128 ImGui::Text(p.path().filename().string().c_str());
129
130 if (ImGui::BeginPopupContextWindow())
131 {
132 if (ImGui::Button("reveal in explorer"))
133 {
134
135 #if SAMURAI_WINDOWS
136 if (p.is_directory())
137 {
138 ShellExecuteA(NULL, "open", p.path().string().c_str(), NULL, NULL, SW_RESTORE);
139 }
140 else
141 {
142 auto path = p.path().parent_path().string();
143 ShellExecuteA(NULL, "open", path.c_str(), NULL, NULL, SW_RESTORE);
144 }
145 #endif
146 ImGui::CloseCurrentPopup();
147 }
148
149 if (ImGui::Button("copy file location"))
150 {
151 ImGui::SetClipboardText(p.path().string().c_str());
152 ImGui::CloseCurrentPopup();
153 }
154
155 if (ImGui::Button("copy file location for engine"))
156 {
157 std::string s = "SAMURAI_RESOURCES_PATH \"" + p.path().filename().string() + "\"";
158
159 ImGui::SetClipboardText(s.c_str());
160 ImGui::CloseCurrentPopup();
161 }
162
163 if (!p.is_directory())
164 {
165 if (ImGui::Button("open file"))
166 {
167 #if SAMURAI_WINDOWS
168 ShellExecuteA(NULL, "open", p.path().string().c_str(), NULL, NULL, SW_RESTORE);
169 #endif
170 ImGui::CloseCurrentPopup();
171 }
172 }
173
174
175 {
176 auto it = currentDll.containerExtensionsSupport.find(p.path().filename().extension().string());
177 if (it != currentDll.containerExtensionsSupport.end())
178 {
179 //todo name
180 if (ImGui::Button("Open In engine"))
181 {
182 containerManager.createContainer(it->second, currentDll, logManager, imguiIDsManager, p.path().string());
183 }
184 }
185 }
186
187
188 ImGui::EndPopup();
189 }
190
191
192 }
193
194 ImGui::EndChild();
195
196 return 0;
197 };
198
199 if (searchText[0] == '\0')
200 {
201 for (auto &p : std::filesystem::directory_iterator(currentPath))
202 {
203 if (displayItem(p))
204 {
205 break;
206 }
207
208 ImGui::NextColumn();
209
210 }
211 }
212 else
213 {
214 //search filter
215 for (auto &p : std::filesystem::recursive_directory_iterator(SAMURAI_RESOURCES_PATH))
216 {
217 if (p.is_regular_file())
218 {
219 auto rez = p.path().filename().string();
220
221 if (rez.find(searchText) != std::string::npos)
222 {
223 if (displayItem(p))
224 {
225 break;
226 }
227
228 ImGui::NextColumn();
229 }
230
231 }
232 }
233 }
234
235
236
237 ImGui::Columns(1);
238
239 ImGui::End();
240 ImGui::PopID();
241 }
242
243
244};
245
void init(samurai::samuraiImgui::ImGuiIdsManager &idManager)
static constexpr char * ICON_NAME
void update(bool &open, ContainerManager &containerManager, LoadedDll &currentDll, samurai::LogManager &logManager, samurai::samuraiImgui::ImGuiIdsManager &imguiIDsManager)
std::filesystem::path currentPath
containerId_t createContainer(samurai::ContainerInformation containerInformation, samurai::LoadedDll &loadedDll, samurai::LogManager &logManager, samurai::samuraiImgui::ImGuiIdsManager &imguiIDsManager, std::string &cmd, size_t memoryPos=0)
int getImguiIds(unsigned int count=1)
Definition gui.h:60