assetManagerWindow.cpp 5.7 KB

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