mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-02 20:24:26 -07:00
flesh out the data scan UI, tweak selection table
This commit is contained in:
+16
-4
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@@ -65,13 +66,24 @@ public static class Database
|
||||
// skip non-canon difficulties
|
||||
if (diff == Difficulty.None || diff == Difficulty.WorldsEnd) continue;
|
||||
|
||||
if (GetDiffPair(dataPath, data, diff) is var pair && pair != null)
|
||||
var lvl = ((FloatPropertyData)data[Consts.DIFF_LVL_KEY[diff]]).Value;
|
||||
if (lvl == 0) continue; // skip nonexistent level
|
||||
|
||||
// check chart existence
|
||||
var chartFilePath = Path.Combine(dataPath, "MusicData", song.Id, $"{song.Id}_{Consts.DIFF_FILENAME_PREPEND[diff]}.mer");
|
||||
if (!File.Exists(chartFilePath))
|
||||
{
|
||||
song.charts.Add((diff, pair.Value.Item1, pair.Value.Item2));
|
||||
// TODO: add warning message to DataScan
|
||||
Console.WriteLine($"[MISSING CHART] {song.Id} {song.Artist} - {song.Name} / {diff}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: check audio existence; add warning but don't skip
|
||||
|
||||
song.Levels[(int)diff] = lvl;
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => Songs.Add(song));
|
||||
Dispatcher.UIThread.Post(() => Songs.Add(song));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -83,7 +95,6 @@ public static class Database
|
||||
|
||||
private static (Entry, Chart)? GetDiffPair(string dataPath, StructPropertyData song, Difficulty diff)
|
||||
{
|
||||
|
||||
var level = ((FloatPropertyData)song[Consts.DIFF_LVL_KEY[diff]]).Value;
|
||||
if (level == 0)
|
||||
return null;
|
||||
@@ -97,6 +108,7 @@ public static class Database
|
||||
InferClearThresholdFromDifficulty = false
|
||||
});
|
||||
e.ClearThreshold = clearThreshold;
|
||||
e.Difficulty = diff;
|
||||
var c = NotationSerializer.ToChart(chartFilePath, new NotationReadArgs
|
||||
{
|
||||
InferClearThresholdFromDifficulty = false
|
||||
|
||||
@@ -32,11 +32,6 @@ public static class Consts
|
||||
public static readonly IReadOnlyDictionary<uint, string> NUM_SOURCE = _NUM_SOURCE;
|
||||
public static readonly IReadOnlyDictionary<string, uint> SOURCE_NUM = _NUM_SOURCE.ToDictionary(p => p.Value, p => p.Key);
|
||||
|
||||
private static string[] _DIFFICULTIES = {
|
||||
"Normal", "Hard", "Expert", "Inferno"
|
||||
};
|
||||
public static readonly IReadOnlyList<string> DIFFICULTIES = _DIFFICULTIES;
|
||||
|
||||
private static readonly Dictionary<Difficulty, string> _DIFF_LVL_KEY = new()
|
||||
{
|
||||
{Difficulty.Normal, "DifficultyNormalLv"},
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using SaturnData.Notation.Core;
|
||||
|
||||
@@ -21,9 +22,9 @@ public class Song
|
||||
public required float PreviewTime { get; set; }
|
||||
public required float PreviewLen { get; set; }
|
||||
public string SourceName => Consts.NUM_SOURCE[Source];
|
||||
public float?[] Levels { get; set; } = { null, null, null, null };
|
||||
|
||||
|
||||
// TODO: For SaturnData.Entry instances, use this Guid format:
|
||||
// MERCURY_[SONGID]_[DIFF] (each var is int)
|
||||
public List<(Difficulty, Entry, Chart)> charts = new();
|
||||
}
|
||||
+14
-2
@@ -4,6 +4,7 @@ using Avalonia;
|
||||
using System;
|
||||
|
||||
using MercuryConverter.UI;
|
||||
using Avalonia.Logging;
|
||||
|
||||
class Program
|
||||
{
|
||||
@@ -13,7 +14,18 @@ class Program
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
// BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
try
|
||||
{
|
||||
// prepare and run your App here
|
||||
BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// here we can work with the exception, for example add it to our log file
|
||||
Console.WriteLine($"App exception!!\b{e}");
|
||||
}
|
||||
}
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
@@ -21,5 +33,5 @@ class Program
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
.LogToTrace(LogEventLevel.Debug);
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using MercuryConverter.Data;
|
||||
using UAssetAPI;
|
||||
using UAssetAPI.UnrealTypes;
|
||||
|
||||
namespace MercuryConverter.UI.Dialogs;
|
||||
|
||||
public partial class DataOpen : UserControl
|
||||
{
|
||||
public static DataOpen? Instance { get; private set; }
|
||||
public DataOpen()
|
||||
{
|
||||
Instance = this;
|
||||
InitializeComponent();
|
||||
|
||||
if (!Design.IsDesignMode)
|
||||
Run();
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var path = ""; // TODO: set to current data path
|
||||
|
||||
// Content selection
|
||||
while (true)
|
||||
{
|
||||
var selectedPath = await BeginDirSelection();
|
||||
Console.WriteLine($"selectedPath={selectedPath}");
|
||||
if (selectedPath != "" && Directory.Exists(selectedPath))
|
||||
{
|
||||
path = selectedPath;
|
||||
break;
|
||||
}
|
||||
// Display error message
|
||||
|
||||
}
|
||||
|
||||
BeginDataScan(path);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<string> BeginDirSelection()
|
||||
{
|
||||
IReadOnlyList<IStorageFolder>? dirSelection = null;
|
||||
|
||||
await Dispatcher.UIThread.Invoke(async () =>
|
||||
{
|
||||
// Update UI
|
||||
ScanView.IsVisible = false;
|
||||
SelectView.IsVisible = true;
|
||||
|
||||
await Task.Delay(200);
|
||||
|
||||
dirSelection = await TopLevel.GetTopLevel(MainWindow.Instance)!.StorageProvider.OpenFolderPickerAsync
|
||||
(
|
||||
new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "Locate Data Folder",
|
||||
AllowMultiple = false,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (dirSelection!.Count <= 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return dirSelection!.First().TryGetLocalPath()!;
|
||||
}
|
||||
|
||||
private void BeginDataScan(string dataPath)
|
||||
{
|
||||
Console.WriteLine(dataPath);
|
||||
// Update UI
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
SelectView.IsVisible = false;
|
||||
ScanStatus.Text = "scanning...";
|
||||
ScanPath.Text = dataPath;
|
||||
ScanView.IsVisible = true;
|
||||
});
|
||||
|
||||
Database.SetupNew(dataPath);
|
||||
}
|
||||
}
|
||||
@@ -4,33 +4,39 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:MercuryConverter.UI.Dialogs"
|
||||
xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
|
||||
x:Class="MercuryConverter.UI.Dialogs.DataOpen"
|
||||
x:Class="MercuryConverter.UI.Dialogs.DataScanning"
|
||||
>
|
||||
<Panel Margin="12">
|
||||
<StackPanel Name="SelectView" IsVisible="false">
|
||||
<TextBlock FontSize="24" FontWeight="Light" Text="select your data folder..."/>
|
||||
<progRing:ProgressRing Foreground="{DynamicResource SystemBaseMediumColor}"
|
||||
Width="36"
|
||||
Height="36"
|
||||
IsActive="True"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,15,0,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Name="ScanView" IsVisible="true">
|
||||
<TextBlock Name="ScanStatus" FontSize="24" FontWeight="Light" Text="scanning..."/>
|
||||
<TextBlock Name="ScanPath" Text="/there/is/a/path/here or whatever it is askljdhflksahdfliuahleifhu"/>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
|
||||
<StackPanel>
|
||||
<TextBlock Name="ScanStatus" FontSize="24" FontWeight="Light" Text="select your data folder..."/>
|
||||
<TextBlock Name="ScanPath" Text="/there/is/a/path/here" IsVisible="false"/>
|
||||
|
||||
<StackPanel Margin="0 6 0 0" Name="ScanError" IsVisible="False">
|
||||
<TextBlock>
|
||||
<Run FontWeight="DemiBold" Text="ERROR" Foreground="Red"/>
|
||||
<LineBreak/>
|
||||
<Run Name="ErrorText" Text="Data pooped its pants"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Name="ScanInfo">
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<Grid ColumnDefinitions="Auto, *" HorizontalAlignment="Stretch">
|
||||
<progRing:ProgressRing Foreground="{DynamicResource SystemBaseMediumColor}"
|
||||
Name="ProgressAnimation"
|
||||
Grid.Column="0"
|
||||
Width="36"
|
||||
Height="36"
|
||||
IsActive="True"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,15,0,0"/>
|
||||
<StackPanel Margin="0 12 0 0" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Margin="6 0 0 0" Content="Cancel" />
|
||||
<Button Margin="6 0 0 0" Content="Open Data Folder" />
|
||||
<StackPanel Margin="0 12 0 0" Name="ButtonGroup" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right" IsVisible="false">
|
||||
<Button Name="BtnClose" Margin="6 0 0 0" Content="Close" Click="CloseHandler"/>
|
||||
<Button Name="BtnSelectFolder" Margin="6 0 0 0" Content="Open Data Folder" Click="OpenDataHandler"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<!-- <StackPanel Name="SelectErrorView" IsVisible="true">
|
||||
<TextBlock FontSize="24" FontWeight="Light" Text="couldn't fully open data folder"/>
|
||||
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using MercuryConverter.Data;
|
||||
using UAssetAPI;
|
||||
using UAssetAPI.UnrealTypes;
|
||||
|
||||
namespace MercuryConverter.UI.Dialogs;
|
||||
|
||||
public partial class DataScanning : UserControl
|
||||
{
|
||||
public static DataScanning? Instance { get; private set; }
|
||||
public DataScanning()
|
||||
{
|
||||
Instance = this;
|
||||
InitializeComponent();
|
||||
|
||||
ScanPath.Text = "";
|
||||
|
||||
if (!Design.IsDesignMode)
|
||||
RunFlow();
|
||||
}
|
||||
|
||||
public void RunFlow()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var path = ""; // TODO: set to current/saved data path
|
||||
|
||||
// Content selection
|
||||
var selectedPath = await BeginDirSelection();
|
||||
Console.WriteLine($"selectedPath=[{selectedPath}]");
|
||||
|
||||
if (selectedPath == "") // cancelled opening folder
|
||||
{
|
||||
// TODO:
|
||||
// return and go to completed mode if scan already completed
|
||||
// continue if no scan has been completed
|
||||
// break if we already have a path but somehow not scanned
|
||||
UISetError("No data folder provided.");
|
||||
return;
|
||||
}
|
||||
if (!Directory.Exists(selectedPath))
|
||||
{
|
||||
UISetError("Folder does not exist.");
|
||||
return;
|
||||
}
|
||||
if (!(File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uasset")) && File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uexp"))))
|
||||
{
|
||||
UISetError("Missing MusicParameterTable asset files. Without them, we have nothing to work with.");
|
||||
return;
|
||||
}
|
||||
|
||||
path = selectedPath;
|
||||
|
||||
UIScanningMode(path);
|
||||
Database.SetupNew(path);
|
||||
UIScanCompletedMode();
|
||||
});
|
||||
}
|
||||
|
||||
private void UISelectMode()
|
||||
{
|
||||
UISetError();
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScanStatus.Text = "select your data folder...";
|
||||
ScanPath.IsVisible = false;
|
||||
ButtonGroup.IsVisible = false;
|
||||
ProgressAnimation.IsVisible = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void UIScanningMode(string path)
|
||||
{
|
||||
UISetError();
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScanStatus.Text = "scanning...";
|
||||
ScanPath.IsVisible = true;
|
||||
ScanPath.Text = path;
|
||||
ScanInfo.IsVisible = true;
|
||||
ButtonGroup.IsVisible = false;
|
||||
ProgressAnimation.IsVisible = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void UIScanCompletedMode()
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScanStatus.Text = "scan complete";
|
||||
ScanPath.IsVisible = true;
|
||||
ScanInfo.IsVisible = true;
|
||||
ButtonGroup.IsVisible = true;
|
||||
ProgressAnimation.IsVisible = false;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use only when no other processes are running.
|
||||
/// </summary>
|
||||
/// <param name="error"></param>
|
||||
private void UISetError(string? error = null)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (error == null)
|
||||
{
|
||||
ScanError.IsVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ScanError.IsVisible = true;
|
||||
ErrorText.Text = error;
|
||||
ProgressAnimation.IsVisible = false;
|
||||
ButtonGroup.IsVisible = true;
|
||||
ScanStatus.Text = "an error has occurred";
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private async Task<string> BeginDirSelection(string? startDir = null)
|
||||
{
|
||||
IReadOnlyList<IStorageFolder>? dirSelection = null;
|
||||
|
||||
UISelectMode();
|
||||
|
||||
await Dispatcher.UIThread.Invoke(async () =>
|
||||
{
|
||||
await Task.Delay(250);
|
||||
var tl = TopLevel.GetTopLevel(MainWindow.Instance)!;
|
||||
dirSelection = await tl.StorageProvider.OpenFolderPickerAsync
|
||||
(
|
||||
new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "Locate Data Folder",
|
||||
AllowMultiple = false,
|
||||
SuggestedStartLocation = startDir == null ? null : await tl.StorageProvider.TryGetFolderFromPathAsync(startDir),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (dirSelection!.Count <= 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return dirSelection!.First().TryGetLocalPath()!;
|
||||
}
|
||||
|
||||
private void CloseHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
MainWindow.Instance!.Dialog.IsOpen = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void OpenDataHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
RunFlow();
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@ public partial class Welcome : Window
|
||||
|
||||
private void ClickHandler(object sender, RoutedEventArgs args)
|
||||
{
|
||||
MainWindow.Instance!.Dialog.DialogContent = new DataOpen().Content;
|
||||
MainWindow.Instance!.Dialog.DialogContent = new DataScanning().Content;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -30,8 +30,8 @@
|
||||
<DockPanel>
|
||||
|
||||
<Menu Name="MenuBar" DockPanel.Dock="Top">
|
||||
<MenuItem Header="File">
|
||||
<MenuItem Header="Open Data Folder..." />
|
||||
<MenuItem Header="_File">
|
||||
<MenuItem Name="DataFolderBtn" Header="_Open Data Folder..." Command="{Binding OpenDataHandler}" />
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Instance = this;
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
|
||||
// Force dark mode in designer
|
||||
if (Design.IsDesignMode)
|
||||
@@ -39,4 +40,10 @@ public partial class MainWindow : Window
|
||||
Dialog.DialogContent = new Welcome().Content;
|
||||
Dialog.IsOpen = true;
|
||||
}
|
||||
|
||||
public void OpenDataHandler()
|
||||
{
|
||||
Dialog.IsOpen = true;
|
||||
Dialog.DialogContent = new DataScanning().Content;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,6 @@
|
||||
<!-- Song Listing Table -->
|
||||
<DockPanel>
|
||||
<DockPanel Margin="0 4 0 8" DockPanel.Dock="Top">
|
||||
<!-- <ComboBox DockPanel.Dock="Right" Width="160" PlaceholderText="Source filter" Name="SourceFilter"/> -->
|
||||
<TextBox Watermark="Search for title, artist, designer..."/>
|
||||
</DockPanel>
|
||||
<UserControl Background="{DynamicResource DataGridContentBackground}">
|
||||
@@ -48,7 +47,7 @@
|
||||
<DataGridTextColumn Header="ID" Width="90" Binding="{Binding Id}"/>
|
||||
<DataGridTextColumn Header="Title" Width="*" Binding="{Binding Name}"/>
|
||||
<DataGridTextColumn Header="Artist" Width="*" Binding="{Binding Artist}"/>
|
||||
<DataGridTextColumn Header="Source" Width="150" Binding="{Binding SourceName}"/>
|
||||
<DataGridTextColumn Header="Source" Width="150" Binding="{Binding SourceName}" SortMemberPath="Source"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</UserControl>
|
||||
|
||||
Reference in New Issue
Block a user