Skip to content

Commit

Permalink
Select multi, some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Nov 13, 2024
1 parent 357eb84 commit 42f363a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
27 changes: 14 additions & 13 deletions Alpha/Gui/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,24 @@ public static void DrawHorizontalSplitter(ref float width) {
}
}

public static AlphaGameData? DrawGameDataPicker(GameDataService gameData, AlphaGameData current) {
AlphaGameData? ret = null;

const string contextMenuId = "##gameDataPickerContextMenu";

public static void DrawFakeHamburger(Action draw) {
const string contextMenuId = "##fakeHamburger";
if (ImGui.Button("#")) ImGui.OpenPopup(contextMenuId);

if (ImGui.BeginPopup(contextMenuId)) {
var options = gameData.GameDatas.Values.ToList();
var names = options.Select(x => x.GameInstallationInfo.GameVersion ?? x.GamePath).ToArray();
var currentIdx = options.IndexOf(current);
if (ImGui.Combo("##gameDataPicker", ref currentIdx, names, names.Length)) {
ret = options[currentIdx];
}

draw();
ImGui.EndPopup();
}
}

public static AlphaGameData? DrawGameDataPicker(GameDataService gameData, AlphaGameData current) {
AlphaGameData? ret = null;

var options = gameData.GameDatas.Values.ToList();
var names = options.Select(x => x.GameInstallationInfo.GameVersion ?? x.GamePath).ToArray();
var currentIdx = options.IndexOf(current);
if (ImGui.Combo("##gameDataPicker", ref currentIdx, names, names.Length)) {
ret = options[currentIdx];
}

return ret;
}
Expand Down
16 changes: 10 additions & 6 deletions Alpha/Gui/Windows/ExcelWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ protected override void Draw() {
private void DrawSidebar() {
var temp = ImGui.GetCursorPosY();

if (Components.DrawGameDataPicker(this.gameDataService, this.GameData!) is { } newGameData) {
this.logger.LogDebug("Game data changed to {NewGameData}", newGameData.GamePath);
this.GameData = newGameData;
this.excel.SetGameData(newGameData);
this.GameDataChanged();
}
Components.DrawFakeHamburger(() => {
if (Components.DrawGameDataPicker(this.gameDataService, this.GameData!) is { } newGameData) {
this.logger.LogDebug("Game data changed to {NewGameData}", newGameData.GamePath);
this.GameData = newGameData;
this.excel.SetGameData(newGameData);
this.GameDataChanged();
}
});

ImGui.SameLine();

Expand Down Expand Up @@ -442,6 +444,7 @@ private void DrawSheet(float width) {
}

for (var i = 0; i < colCount; i++) {
ImGui.PushID(i);
var colId = colMappings[i];
var colName = sheetDefinition?.GetNameForColumn(colId) ?? colId.ToString();

Expand All @@ -459,6 +462,7 @@ private void DrawSheet(float width) {
ImGui.TextUnformatted(offsetStr);
ImGui.EndTooltip();
}
ImGui.PopID();
}

var actualRowCount = this.filteredRows?.Count ?? (int) rowCount;
Expand Down
45 changes: 39 additions & 6 deletions Alpha/Gui/Windows/FilesystemWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class FilesystemWindow : Window, IDisposable {
private string filter = string.Empty;
private readonly List<string> filteredDirectories = [];
private readonly List<string> visibleRootCategories = [..PathService.RootCategories.Keys];
private readonly List<PathService.File> selectedFiles = new();
private float sidebarWidth = 300f;

private readonly GameDataService gameDataService;
Expand Down Expand Up @@ -77,11 +78,32 @@ private void DrawSidebar() {
return;
}

if (Components.DrawGameDataPicker(this.gameDataService, this.GameData!) is { } newGameData) {
this.GameData = newGameData;
this.pathService.SetGameData(this.GameData);
this.GameDataChanged();
}
Components.DrawFakeHamburger(() => {
if (Components.DrawGameDataPicker(this.gameDataService, this.GameData!) is { } newGameData) {
this.GameData = newGameData;
this.pathService.SetGameData(this.GameData);
this.GameDataChanged();
}

var hasSelectedFiles = this.selectedFiles.Count > 0;
if (!hasSelectedFiles) ImGui.BeginDisabled();
if (ImGui.Button("Export selected files")) {
var dir = NFD.PickFolder(string.Empty);
if (!string.IsNullOrWhiteSpace(dir)) {
foreach (var file in this.selectedFiles) {
var resource = this.pathService.GetFile<FileResource>(this.GameData!, file);
if (resource is null) continue;

var path = Path.Combine(dir, this.GetPath(file));
var dirPath = Path.GetDirectoryName(path)!;
if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);

System.IO.File.WriteAllBytes(path, resource.Data);
}
}
}
if (!hasSelectedFiles) ImGui.EndDisabled();
});

ImGui.SameLine();

Expand Down Expand Up @@ -191,7 +213,18 @@ private void DrawFolder(string path, PathService.Folder folder) {
foreach (var (file, filename) in files) {
if (filterExists && !this.GetPath(file).Contains(this.filter, StringComparison.OrdinalIgnoreCase)) continue;

if (ImGui.Selectable(filename)) this.Open(file);
var selected = this.SelectedFile?.Item2 == file || this.selectedFiles.Contains(file);
if (ImGui.Selectable(filename, selected)) {
if (Util.IsKeyDown(ImGuiKey.LeftCtrl)) {
if (this.selectedFiles.Contains(file)) {
this.selectedFiles.Remove(file);
} else {
this.selectedFiles.Add(file);
}
} else {
this.Open(file);
}
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions Alpha/Services/PathService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ public void SetGameData(AlphaGameData gameData) {
Task.Run(() => {
try {
lock (this.processLock) {
this.Clear();
logger.LogInformation("Processing path lists");

var stopwatch = Stopwatch.StartNew();
this.Clear();

this.LoadPathLists();
logger.LogInformation("Loaded path lists: {Time}", stopwatch.Elapsed);

this.LoadGameFiles(gameData);
logger.LogInformation("Sorting folders: {Time}", stopwatch.Elapsed);

logger.LogInformation("Finished processing path lists in {Time}", stopwatch.Elapsed);
}
} catch (Exception e) {
Expand All @@ -69,7 +73,7 @@ public void Dispose() {

private void LoadPathLists() {
foreach (var path in pathList.LoadPathLists()) {
var file = this.ParseResLogger(path);
var file = this.ParseResLogger(path.ToLower());
var folder = this.GetFolder(file.FolderName!, true)!;
folder.Files[file.FileHash] = file;

Expand Down Expand Up @@ -193,7 +197,7 @@ uint FolderHash
}

public record File(Dat? Dat, ulong Hash, string? FolderName = null, string? FileName = null) {
public string? Path = FolderName != null && FileName != null ? FolderName + FileName : null;
public string? Path => FolderName != null && FileName != null ? (FolderName + "/" + FileName) : null;
public uint FolderHash = (uint) (Hash >> 32);
public uint FileHash = (uint) Hash;

Expand Down

0 comments on commit 42f363a

Please sign in to comment.