Skip to content

Commit

Permalink
Merge pull request #59 from Milkitic/develop
Browse files Browse the repository at this point in the history
develop2master
  • Loading branch information
Milkitic authored Nov 14, 2020
2 parents 02e30c8 + e78118d commit 4547fb5
Show file tree
Hide file tree
Showing 37 changed files with 837 additions and 74 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[submodule "Libraries/OSharp.Storyboard"]
path = Libraries/OSharp.Storyboard
url = https://github.com/Milkitic/OSharp.Storyboard
branch = master
[submodule "Libraries/OSharp.Common"]
path = Libraries/OSharp.Common
url = https://github.com/Milkitic/OSharp.Common
branch = master
[submodule "Libraries/OSharp.Beatmap"]
path = Libraries/OSharp.Beatmap
url = https://github.com/Milkitic/OSharp.Beatmap
url = https://github.com/Milkitic/OSharp.Beatmap
branch = master
2 changes: 1 addition & 1 deletion Libraries/OSharp.Beatmap
2 changes: 1 addition & 1 deletion Libraries/OSharp.Storyboard
4 changes: 4 additions & 0 deletions OsuPlayer.Common/Configuration/LyricSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ public class LyricSection
public LyricProvideType ProvideType { get; set; } = LyricProvideType.Original;
public bool StrictMode { get; set; } = true;
public bool EnableCache { get; set; } = true;
public string FontFamily { get; set; }
public double Hue { get; set; }
public double Saturation { get; set; }
public double Lightness { get; set; }
}
}
2 changes: 1 addition & 1 deletion OsuPlayer.Media.Audio/ObservablePlayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ await OsuFile.ReadFromFileAsync(path, options => options.ExcludeSection("Editor"
if (trueBeatmap == null)
{
trueBeatmap = beatmap;
trueBeatmap.FolderName = path;
trueBeatmap.FolderName = path; // I forgot why I did this but there should be some reasons.
}

PlayList.AddOrSwitchTo(trueBeatmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ public override async Task DisposeAsync()
}

Logger.Debug($"Disposing: Canceled {nameof(_cts)}.");
await Task.WhenAll(_backoffTask).ConfigureAwait(false);
if (_backoffTask != null)
await _backoffTask.ConfigureAwait(false);
Logger.Debug($"Disposing: Stopped task {nameof(_backoffTask)}.");
_cts?.Dispose();
Logger.Debug($"Disposing: Disposed {nameof(_cts)}.");
Expand Down
2 changes: 1 addition & 1 deletion OsuPlayer.Media.Audio/Playlist/PlayList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private async Task<PlayControlResult> SwitchByControl(bool isNext, bool isManual
var playControlResult = new PlayControlResult(PlayControlResult.PlayControlStatus.Stop,
PlayControlResult.PointerControlStatus.Keep);
if (AutoSwitched != null)
await AutoSwitched.Invoke(playControlResult, CurrentInfo.Beatmap, true).ConfigureAwait(false);
await AutoSwitched.Invoke(playControlResult, CurrentInfo.Beatmap, false).ConfigureAwait(false);
return playControlResult;
}

Expand Down
42 changes: 42 additions & 0 deletions OsuPlayer.Wpf/Converters/LocalizedFontFamilyConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;

namespace Milky.OsuPlayer.Converters
{
public class LocalizedFontFamilyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is FontFamily fontFamily)
{
var languageSpecificStringDictionary = fontFamily.FamilyNames;
if (languageSpecificStringDictionary.TryGetValue(
XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.Name), out var fontName))
{
return fontName;
}
else if (languageSpecificStringDictionary.Count > 1)
{
var name = languageSpecificStringDictionary.FirstOrDefault(k =>
k.Key != XmlLanguage.GetLanguage("en-us")).Value;
return name;
}
else
{
return languageSpecificStringDictionary.FirstOrDefault().Value;
}
}

throw new ArgumentNullException(nameof(fontFamily));
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
14 changes: 14 additions & 0 deletions OsuPlayer.Wpf/Converters/MainWindowConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,18 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
throw new NotImplementedException();
}
}

public class BoolFalseToVisibleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var show = (bool)value;
return !show ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion OsuPlayer.Wpf/Converters/PlayingConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class BoolIsFavToSvgConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is bool b)) return value;
if (!(value is bool b)) return Application.Current.FindResource("HeartDisabledTempl");
return b ? Application.Current.FindResource("HeartEnabledTempl") : Application.Current.FindResource("HeartDisabledTempl");
}

Expand Down
21 changes: 21 additions & 0 deletions OsuPlayer.Wpf/Converters/RoundedNumberConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace Milky.OsuPlayer.Converters
{
public class RoundedNumberConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var d = System.Convert.ToDouble(value);
return Math.Round(d, 3);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var d = System.Convert.ToDouble(value);
return d;
}
}
}
2 changes: 1 addition & 1 deletion OsuPlayer.Wpf/EntryStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static void InitLocalDb()
var appDbOperator = new AppDbOperator();
var defCol = appDbOperator.GetCollections();
var locked = defCol.Where(k => k.LockedBool);
if (!locked.Any()) appDbOperator.AddCollection("最喜爱的", true);
if (!locked.Any()) appDbOperator.AddCollection("Favorite", true);
}
}
}
8 changes: 8 additions & 0 deletions OsuPlayer.Wpf/OsuPlayer.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\LocalizedFontFamilyConverter.cs" />
<Compile Include="Converters\RoundedNumberConverter.cs" />
<Compile Include="Utils\CompoundUtil.cs" />
<Compile Include="Utils\FontFamilyComparer.cs" />
<Compile Include="Utils\SafeDbOperator.cs" />
<Compile Include="UiComponents\TextBlockComponent\OutlinedTextBlock.cs" />
<Compile Include="UserControls\AddCollectionControl.xaml.cs">
Expand Down Expand Up @@ -612,6 +616,10 @@
<Resource Include="Resources\Fonts\SourceSansPro-Black.ttf" />
<Resource Include="Resources\asio.png" />
<Resource Include="Resources\osu_texture_black.png" />
<None Include="lang\en-US.xaml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
11 changes: 6 additions & 5 deletions OsuPlayer.Wpf/Pages/CollectionPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
x:Class="Milky.OsuPlayer.Pages.CollectionPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:buttonComponent="clr-namespace:Milky.OsuPlayer.UiComponents.ButtonComponent"
xmlns:converters="clr-namespace:Milky.OsuPlayer.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:osuPlayer="clr-namespace:Milky.OsuPlayer"
xmlns:panelComponent="clr-namespace:Milky.OsuPlayer.UiComponents.PanelComponent"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:viewModels="clr-namespace:Milky.OsuPlayer.ViewModels"
xmlns:converters="clr-namespace:Milky.OsuPlayer.Converters"
xmlns:buttonComponent="clr-namespace:Milky.OsuPlayer.UiComponents.ButtonComponent"
xmlns:textBoxComponent="clr-namespace:Milky.OsuPlayer.UiComponents.TextBoxComponent"
xmlns:panelComponent="clr-namespace:Milky.OsuPlayer.UiComponents.PanelComponent"
xmlns:viewModels="clr-namespace:Milky.OsuPlayer.ViewModels"
Title="CollectionPage"
d:DesignHeight="450"
d:DesignWidth="800"
Expand Down Expand Up @@ -203,7 +203,8 @@
MouseDownBackground="#ef3d40"
MouseDownForeground="#e8e8e8"
MouseOverBackground="#ff6d70"
MouseOverForeground="White" />
MouseOverForeground="White"
Visibility="{Binding CollectionInfo.LockedBool, Converter={StaticResource BoolFalseToVisibleConverter}}" />
</WrapPanel>
<StackPanel
Margin="5"
Expand Down
26 changes: 10 additions & 16 deletions OsuPlayer.Wpf/Pages/CollectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -58,19 +57,14 @@ public CollectionPage(string colId) : this()
UpdateView(colId);
}

public void UpdateView(string colId)
public async Task UpdateView(string colId)
{
Task.Run(() =>
{
Thread.Sleep(100);
Execute.OnUiThread(() =>
{
var collectionInfo = _safeDbOperator.GetCollectionById(colId);
if (collectionInfo == null) return;
ViewModel.CollectionInfo = collectionInfo;
UpdateList();
});
});
await Task.Delay(1);

var collectionInfo = _safeDbOperator.GetCollectionById(colId);
if (collectionInfo == null) return;
ViewModel.CollectionInfo = collectionInfo;
UpdateList();
}

public void UpdateList()
Expand Down Expand Up @@ -158,9 +152,9 @@ private async void ItemDelete_Click(object sender, RoutedEventArgs e)

private void BtnDelCol_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show(_mainWindow, "确认删除收藏夹?", _mainWindow.Title, MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
var result = MessageBox.Show(_mainWindow, I18NUtil.GetString("ui-ensureRemoveCollection"), _mainWindow.Title, MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation);
if (result == MessageBoxResult.OK)
{
if (!_safeDbOperator.TryRemoveCollection(ViewModel.CollectionInfo)) return;
_mainWindow.SwitchRecent.IsChecked = true;
Expand Down
6 changes: 3 additions & 3 deletions OsuPlayer.Wpf/Pages/RecentPlayPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private void RecentListItem_MouseDoubleClick(object sender, RoutedEventArgs e)

private void BtnDelAll_Click(object sender, RoutedEventArgs e)
{
var result = MessageBox.Show(_mainWindow, "真的要删除全部吗?", _mainWindow.Title, MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
var result = MessageBox.Show(_mainWindow, I18NUtil.GetString("ui-ensureRemoveAll"), _mainWindow.Title, MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation);
if (result == MessageBoxResult.OK)
{
if (SafeDbOperator.TryClearRecent())
UpdateList();
Expand Down
19 changes: 13 additions & 6 deletions OsuPlayer.Wpf/Pages/Settings/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ private async void CheckUpdate_Click(object sender, RoutedEventArgs e)
{
//todo: action
CheckUpdate.IsEnabled = false;
var hasNew = await Service.Get<UpdateInst>().CheckUpdateAsync();
CheckUpdate.IsEnabled = true;
if (hasNew == null)
bool? hasNew;
try
{
hasNew = await Service.Get<UpdateInst>().CheckUpdateAsync();
}
catch (Exception ex)
{
MessageBox.Show(_configWindow, "检查更新时出错。", _configWindow.Title, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(_configWindow, I18NUtil.GetString("ui-sets-content-errorWhileCheckingUpdate") + Environment.NewLine +
(ex.InnerException?.Message ?? ex.Message),
_configWindow.Title, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

CheckUpdate.IsEnabled = true;

AppSettings.Default.LastUpdateCheck = DateTime.Now;
GetLastUpdate();
AppSettings.SaveDefault();
Expand All @@ -75,8 +82,8 @@ private async void CheckUpdate_Click(object sender, RoutedEventArgs e)
}
else
{
MessageBox.Show(_configWindow, "已是最新版本。", _configWindow.Title, MessageBoxButton.OK,
MessageBoxImage.Information);
MessageBox.Show(_configWindow, I18NUtil.GetString("ui-sets-content-alreadyNewest"), _configWindow.Title,
MessageBoxButton.OK, MessageBoxImage.Information);
}
}

Expand Down
19 changes: 15 additions & 4 deletions OsuPlayer.Wpf/Pages/Settings/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
x:Class="Milky.OsuPlayer.Pages.Settings.GeneralPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:buttonComponent="clr-namespace:Milky.OsuPlayer.UiComponents.ButtonComponent"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:loaderComponent="clr-namespace:Milky.OsuPlayer.UiComponents.LoaderComponent"
xmlns:local="clr-namespace:Milky.OsuPlayer.Pages.Settings"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:scanning="clr-namespace:Milky.OsuPlayer.Common.Scanning;assembly=OsuPlayer.Common"
xmlns:textBoxComponent="clr-namespace:Milky.OsuPlayer.UiComponents.TextBoxComponent"
xmlns:buttonComponent="clr-namespace:Milky.OsuPlayer.UiComponents.ButtonComponent"
xmlns:loaderComponent="clr-namespace:Milky.OsuPlayer.UiComponents.LoaderComponent"
Title="GeneralPage"
d:DesignHeight="450"
d:DesignWidth="800"
FontFamily="{StaticResource SspRegular}"
Loaded="Page_Loaded"
mc:Ignorable="d">
<Page.DataContext>
<d:Page.DataContext>
<scanning:FileScannerViewModel />
</Page.DataContext>
</d:Page.DataContext>
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Margin="10">
Expand Down Expand Up @@ -102,6 +102,17 @@
IconMargin="0"
IconTemplate="{StaticResource FolderTempl}"
Style="{StaticResource SettingsButton}" />
<buttonComponent:CommonButton
x:Name="btnStartScan"
Height="25"
Margin="6,0,0,0"
Padding="5,0"
VerticalAlignment="Center"
Background="#E3E3E3"
Click="ScanNow_Click"
Content="{DynamicResource ui-btn-scanManually}"
Style="{StaticResource SettingsButton}"
Visibility="{Binding IsScanning, Converter={StaticResource BoolFalseToVisibleConverter}}" />
<loaderComponent:Loader
Width="25"
Height="25"
Expand Down
7 changes: 7 additions & 0 deletions OsuPlayer.Wpf/Pages/Settings/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public GeneralPage()
_configWindow = WindowEx.GetCurrentFirst<ConfigWindow>();
InitializeComponent();
ScannerViewModel = Service.Get<OsuFileScanner>().ViewModel;
DataContext = ScannerViewModel;
}

private void RunOnStartup_CheckChanged(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -168,5 +169,11 @@ private async void SyncNow_Click(object sender, RoutedEventArgs e)
_configWindow.Title, MessageBoxButton.OK, MessageBoxImage.Error);
}
}

private async void ScanNow_Click(object sender, RoutedEventArgs e)
{
await Service.Get<OsuFileScanner>().CancelTaskAsync();
await Service.Get<OsuFileScanner>().NewScanAndAddAsync(AppSettings.Default.General.CustomSongsPath);
}
}
}
3 changes: 3 additions & 0 deletions OsuPlayer.Wpf/Styles/ConverterDictionary.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
<converters:NullToHiddenConverter x:Key="NullToHiddenConverter" />
<converters:NullToCollapsedConverter x:Key="NullToCollapsedConverter" />
<converters:BoolTrueToVisibleConverter x:Key="BoolTrueToVisibleConverter" />
<converters:BoolFalseToVisibleConverter x:Key="BoolFalseToVisibleConverter" />
<converters:NullToFullOpacityConverter x:Key="NullToFullOpacityConverter" />
<converters:NullToBoolFalseConverter x:Key="NullToBoolFalseConverter" />
<converters:PlayModeConverter x:Key="PlayModeConverter" />
<converters:BoolIsFavToSvgConverter x:Key="BoolIsFavToSvgConverter" />
<converters:DeviceInfoToStringConverter x:Key="DeviceInfoToStringConverter" />
<converters:Multi_EqualityToVisibilityConverter x:Key="Multi_EqualityToVisibilityConverter" />
<converters:Multi_ListViewSelectAndScrollConverter x:Key="Multi_ListViewSelectAndScrollConverter" />
<converters:LocalizedFontFamilyConverter x:Key="LocalizedFontFamilyConverter" />
<converters:RoundedNumberConverter x:Key="RoundedNumberConverter" />
</ResourceDictionary>
Loading

0 comments on commit 4547fb5

Please sign in to comment.