mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-02 20:24:26 -07:00
refactors and more UI
This commit is contained in:
@@ -0,0 +1,102 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace MercuryConverter.Data;
|
||||||
|
|
||||||
|
public static class Database
|
||||||
|
{
|
||||||
|
public static void Setup(string dataDirPath)
|
||||||
|
{
|
||||||
|
// Check that path exists
|
||||||
|
if (!Directory.Exists(dataDirPath))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Folder {dataDirPath} doesn't exist!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get metadata.json
|
||||||
|
var jPath = Path.Combine(dataDirPath, "metadata.json");
|
||||||
|
string jStr;
|
||||||
|
JsonElement mdObj;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jStr = File.ReadAllText(jPath);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Couldn't read {jPath}: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mdObj = JsonDocument.Parse(jStr).RootElement.GetProperty("Exports")[0].GetProperty("Table").GetProperty("Data");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Couldn't parse JSON object: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Clear existing structures
|
||||||
|
|
||||||
|
// Parse metadata.json
|
||||||
|
foreach (var mdSong in mdObj.EnumerateArray())
|
||||||
|
{
|
||||||
|
var id = "";
|
||||||
|
var title = "";
|
||||||
|
var rubi = "";
|
||||||
|
var artist = "";
|
||||||
|
var genre = -1;
|
||||||
|
var copyright = "";
|
||||||
|
var bpm = "";
|
||||||
|
var version = -1;
|
||||||
|
var previewTime = -1;
|
||||||
|
var previewLength = -1;
|
||||||
|
var jacketPath = "";
|
||||||
|
|
||||||
|
var level = new string?[] { null, null, null, null };
|
||||||
|
var levelBGA = new string?[] { null, null, null, null};
|
||||||
|
var levelAudio = new string?[] { null, null, null, null };
|
||||||
|
var levelDesigner = new string?[] { null, null, null, null };
|
||||||
|
var levelClearRequirements = new string?[] { null, null, null, null };
|
||||||
|
|
||||||
|
foreach (var prop in mdSong.GetProperty("Value").EnumerateArray())
|
||||||
|
{
|
||||||
|
var value = prop.GetProperty("Value");
|
||||||
|
// Console.WriteLine($"{prop.GetProperty("Name")}={prop.GetProperty("Value")}");
|
||||||
|
switch (prop.GetProperty("Name").GetString()!)
|
||||||
|
{
|
||||||
|
case "AssetDirectory":
|
||||||
|
id = value.GetString()!;
|
||||||
|
break;
|
||||||
|
case "ScoreGenre":
|
||||||
|
genre = value.GetInt16();
|
||||||
|
break;
|
||||||
|
case "MusicMessage":
|
||||||
|
title = value.GetString();
|
||||||
|
break;
|
||||||
|
case "ArtistMessage":
|
||||||
|
artist = value.GetString();
|
||||||
|
break;
|
||||||
|
case "Rubi":
|
||||||
|
rubi = value.GetString();
|
||||||
|
break;
|
||||||
|
case "Bpm":
|
||||||
|
bpm = value.GetString();
|
||||||
|
break;
|
||||||
|
case "CopyrightMessage":
|
||||||
|
var c = value.GetString();
|
||||||
|
if (!new string?[] { "", "-", null }.Contains(c))
|
||||||
|
{
|
||||||
|
copyright = c;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"[{id}] {artist} - {title}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
namespace MercuryConverter;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
public static class Database
|
|
||||||
{
|
|
||||||
public static readonly ObservableCollection<Data.Song> Songs = new();
|
|
||||||
}
|
|
||||||
@@ -19,9 +19,11 @@
|
|||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.10" />
|
||||||
|
<PackageReference Include="DialogHost.Avalonia" Version="0.9.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AvaloniaResource Include="Assets\**"/>
|
<AvaloniaResource Include="Assets\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+4
-2
@@ -11,8 +11,10 @@ class Program
|
|||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||||
// yet and stuff might break.
|
// yet and stuff might break.
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
public static void Main(string[] args)
|
||||||
.StartWithClassicDesktopLifetime(args);
|
{
|
||||||
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||||
|
}
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
|
|||||||
+5
-1
@@ -1,6 +1,7 @@
|
|||||||
<Application xmlns="https://github.com/avaloniaui"
|
<Application xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="MercuryConverter.UI.App"
|
x:Class="MercuryConverter.UI.App"
|
||||||
|
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
|
||||||
RequestedThemeVariant="Default"> <!-- Dark Default Light -->
|
RequestedThemeVariant="Default"> <!-- Dark Default Light -->
|
||||||
|
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
@@ -15,6 +16,8 @@
|
|||||||
</FluentTheme>
|
</FluentTheme>
|
||||||
|
|
||||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
|
||||||
|
<dialogHostAvalonia:DialogHostStyles/>
|
||||||
|
<StyleInclude Source="avares://AvaloniaProgressRing/Styles/ProgressRing.xaml"/>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
|
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
@@ -28,7 +31,8 @@
|
|||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
<ResourceDictionary x:Key="Dark">
|
<ResourceDictionary x:Key="Dark">
|
||||||
<SolidColorBrush x:Key="ExpanderHeaderBackgroundPointerOver">#20000000</SolidColorBrush>
|
<SolidColorBrush x:Key="ExpanderHeaderBackgroundPointerOver">#20000000</SolidColorBrush>
|
||||||
<SolidColorBrush x:Key="DataGridContentBackground">#20000000</SolidColorBrush>
|
<SolidColorBrush x:Key="DataGridContentBackground">#ff000000</SolidColorBrush>
|
||||||
|
<SolidColorBrush x:Key="DialogHostOverlayBackgroundMixinBrush">#222244</SolidColorBrush>
|
||||||
<Bitmap x:Key="BannerBitmap">/Assets/imgs/banner_dark.png</Bitmap>
|
<Bitmap x:Key="BannerBitmap">/Assets/imgs/banner_dark.png</Bitmap>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</ResourceDictionary.ThemeDictionaries>
|
</ResourceDictionary.ThemeDictionaries>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
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"
|
||||||
|
>
|
||||||
|
<StackPanel Margin="12">
|
||||||
|
<TextBlock Text="Select your data folder..."/>
|
||||||
|
<progRing:ProgressRing Foreground="{DynamicResource SystemBaseMediumColor}"
|
||||||
|
Width="36"
|
||||||
|
Height="36"
|
||||||
|
IsActive="True"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Margin="0,15,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
namespace MercuryConverter.UI.Dialogs;
|
||||||
|
|
||||||
|
public partial class DataOpen : Window
|
||||||
|
{
|
||||||
|
public DataOpen()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BeginDirSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BeginDirSelection()
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Invoke(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(200);
|
||||||
|
var dirSelection = await GetTopLevel(this)!.StorageProvider.OpenFolderPickerAsync
|
||||||
|
(
|
||||||
|
new FolderPickerOpenOptions
|
||||||
|
{
|
||||||
|
Title = "Open Data Folder",
|
||||||
|
AllowMultiple = false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (dirSelection.Count <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var d = dirSelection!.First().TryGetLocalPath()!;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:MercuryConverter.UI.Dialogs"
|
||||||
|
x:Class="MercuryConverter.UI.Dialogs.Welcome"
|
||||||
|
>
|
||||||
|
<StackPanel Margin="12">
|
||||||
|
<TextBlock FontSize="36" HorizontalAlignment="Center">
|
||||||
|
Welcome to <Bold>MercuryConverter</Bold>!
|
||||||
|
</TextBlock>
|
||||||
|
<TextBlock HorizontalAlignment="Center">
|
||||||
|
<InlineUIContainer BaselineAlignment="Bottom">
|
||||||
|
<!-- TODO: move HOWTO to this repo -->
|
||||||
|
<HyperlinkButton Content="Setup your data folder" Padding="0" NavigateUri="https://github.com/muskit/WacK-Repackager/blob/main/HOWTO.md" />
|
||||||
|
</InlineUIContainer>
|
||||||
|
before proceeding.
|
||||||
|
</TextBlock>
|
||||||
|
<Button Content="Open Data Folder" Click="ClickHandler" HorizontalAlignment="Center" Margin="0 8 0 0" />
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using DialogHostAvalonia;
|
||||||
|
|
||||||
|
namespace MercuryConverter.UI.Dialogs;
|
||||||
|
|
||||||
|
public partial class Welcome : Window
|
||||||
|
{
|
||||||
|
public Welcome()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClickHandler(object sender, RoutedEventArgs args)
|
||||||
|
{
|
||||||
|
MainWindow.Instance!.Dialog.DialogContent = new DataOpen().Content;
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
-26
@@ -2,41 +2,48 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
|
||||||
xmlns:local="clr-namespace:MercuryConverter.UI"
|
xmlns:local="clr-namespace:MercuryConverter.UI"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
|
||||||
|
|
||||||
x:Class="MercuryConverter.UI.MainWindow"
|
x:Class="MercuryConverter.UI.MainWindow"
|
||||||
|
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
Title="MercuryConverter"
|
Title="MercuryConverter"
|
||||||
Width="1024" Height="800"
|
Width="1024" Height="800"
|
||||||
MinWidth="800" MinHeight="600"
|
MinWidth="800" MinHeight="600"
|
||||||
ExtendClientAreaToDecorationsHint="True"
|
ExtendClientAreaToDecorationsHint="True"
|
||||||
>
|
>
|
||||||
<!-- Components -->
|
<dialogHost:DialogHost CloseOnClickAway="False" Name="Dialog">
|
||||||
<Panel>
|
<dialogHost:DialogHost.DialogContent>
|
||||||
<!-- Banner -->
|
<Button Content="Test"/>
|
||||||
<StackPanel>
|
</dialogHost:DialogHost.DialogContent>
|
||||||
<UserControl Background="{DynamicResource SystemAltHighColor}" Height="86"/>
|
|
||||||
</StackPanel>
|
|
||||||
<StackPanel HorizontalAlignment="Right">
|
|
||||||
<Image Height="86" Source="{DynamicResource BannerBitmap}"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
<DockPanel>
|
<!-- Components -->
|
||||||
|
<Panel>
|
||||||
|
<!-- Banner -->
|
||||||
|
<StackPanel>
|
||||||
|
<UserControl Background="{DynamicResource SystemAltHighColor}" Height="86"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel HorizontalAlignment="Right">
|
||||||
|
<Image Height="86" Source="{DynamicResource BannerBitmap}"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<Menu Name="MenuBar" DockPanel.Dock="Top">
|
<DockPanel>
|
||||||
<MenuItem Header="File">
|
|
||||||
<MenuItem Header="Open Data Folder..." />
|
|
||||||
</MenuItem>
|
|
||||||
</Menu>
|
|
||||||
|
|
||||||
<TabControl>
|
<Menu Name="MenuBar" DockPanel.Dock="Top">
|
||||||
<TabItem Header="selection">
|
<MenuItem Header="File">
|
||||||
<UserControl Name="SelectionControl"/>
|
<MenuItem Header="Open Data Folder..." />
|
||||||
</TabItem>
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
|
||||||
<TabItem Header="export">
|
<TabControl>
|
||||||
</TabItem>
|
<TabItem Header="selection">
|
||||||
</TabControl>
|
<UserControl Name="SelectionControl"/>
|
||||||
</DockPanel>
|
</TabItem>
|
||||||
</Panel>
|
|
||||||
|
<TabItem Header="export">
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
|
</DockPanel>
|
||||||
|
</Panel>
|
||||||
|
</dialogHost:DialogHost>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
+21
-2
@@ -1,14 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using MercuryConverter.UI.Dialogs;
|
||||||
|
using MercuryConverter.UI.Views;
|
||||||
|
|
||||||
namespace MercuryConverter.UI;
|
namespace MercuryConverter.UI;
|
||||||
|
|
||||||
using MercuryConverter.UI.Views;
|
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
public static MainWindow? Instance { get; private set; }
|
||||||
|
private bool initialShown = false;
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
Instance = this;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
// Force dark mode in designer
|
// Force dark mode in designer
|
||||||
@@ -19,5 +26,17 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
// Setup tab views
|
// Setup tab views
|
||||||
SelectionControl.Content = new Selection();
|
SelectionControl.Content = new Selection();
|
||||||
|
|
||||||
|
// Show dialog on startup
|
||||||
|
Activated += OnActivated;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnActivated(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (initialShown) return;
|
||||||
|
initialShown = true;
|
||||||
|
|
||||||
|
Dialog.DialogContent = new Welcome().Content;
|
||||||
|
Dialog.IsOpen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user