File: game-manager.cpp

package info (click to toggle)
ares 147%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 35,260 kB
  • sloc: cpp: 334,263; ansic: 98,696; sh: 131; makefile: 67
file content (58 lines) | stat: -rw-r--r-- 1,888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
GameManager::GameManager(View* parent) : Panel(parent, Size{~0, ~0}) {
  setCollapsible().setVisible(false);
  pathLabel.setFont(Font().setBold()).setForegroundColor({0, 0, 240});
  pathLabel.onMouseRelease([&](auto button) {
    if(!path || button != Mouse::Button::Left) return;
    if(auto location = BrowserDialog()
    .setTitle({"Set ", system, " Games Location"})
    .setPath(path)
    .setAlignment(programWindow)
    .selectFolder()
    ) {
      path = location;
      auto userPath = Path::user();
      auto pathLabelTemp = string{path}.replace(userPath, "~/");
      pathLabel.setText(pathLabelTemp);
      refresh();
    }
  });
  importButton.setText("Import ...").onActivate([&] {
    auto pak = mia::Medium::create(system);
    auto extensions = pak->extensions();
    for(auto& extension : extensions) extension.prepend("*.");
    auto files = BrowserDialog()
    .setTitle({"Import ", system, " Games"})
    .setPath(settings.recent)
    .setFilters({{system, "|", nall::merge(extensions, ":"), ":*.zip:", nall::merge(extensions, ":").upcase(), ":*.ZIP"}, "All|*"})
    .setAlignment(programWindow)
    .openFiles();
    if(!files.empty()) {
      settings.recent = Location::path(files.front());
      gameImporter.import(system, files);
    }
  });
}

auto GameManager::select(string system) -> void {
  auto userPath = Path::user();
  path = {userPath, "Emulation/", system, "/"};
  auto pathLabelTemp = string{path}.replace(userPath, "~/");
  pathLabel.setText(pathLabelTemp);
  this->system = system;
  refresh();
}

auto GameManager::refresh() -> void {
  gameList.reset();
  if(!path) return;

  for(auto& name : directory::folders(path)) {
    ListViewItem item{&gameList};
    item.setIcon(Icon::Emblem::Folder);
    item.setText(string{name}.trimRight("/", 1L));
  }

  programWindow.show(*this);
  Application::processEvents();
  gameList.resizeColumn();
}