game-manager.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. GameManager::GameManager(View* parent) : Panel(parent, Size{~0, ~0}) {
  2. setCollapsible().setVisible(false);
  3. pathLabel.setFont(Font().setBold()).setForegroundColor({0, 0, 240});
  4. pathLabel.onMouseRelease([&](auto button) {
  5. if(!path || button != Mouse::Button::Left) return;
  6. if(auto location = BrowserDialog()
  7. .setTitle({"Set ", system, " Games Location"})
  8. .setPath(*path)
  9. .setAlignment(programWindow)
  10. .selectFolder()
  11. ) {
  12. *path = location;
  13. pathLabel.setText(*path);
  14. refresh();
  15. }
  16. });
  17. importButton.setText("Import ...").onActivate([&] {
  18. if(auto files = BrowserDialog()
  19. .setTitle({"Import ", system, " Games"})
  20. .setPath(settings.recent)
  21. .setAlignment(programWindow)
  22. .openFiles()
  23. ) {
  24. settings.recent = Location::path(files.first());
  25. gameImporter.import(system, files);
  26. }
  27. });
  28. }
  29. auto GameManager::select(string system) -> void {
  30. path.reset();
  31. for(auto& medium : media) {
  32. if(medium->name() != system) continue;
  33. path = medium->pathname;
  34. }
  35. if(!path) return;
  36. pathLabel.setText(*path);
  37. this->system = system;
  38. refresh();
  39. }
  40. auto GameManager::refresh() -> void {
  41. gameList.reset();
  42. if(!path) return;
  43. for(auto& name : directory::folders(*path)) {
  44. ListViewItem item{&gameList};
  45. item.setIcon(Icon::Emblem::Folder);
  46. item.setText(string{name}.trimRight("/", 1L));
  47. }
  48. programWindow.show(*this);
  49. gameList.resizeColumn();
  50. }