-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44d2eb6
commit 9f10301
Showing
9 changed files
with
194 additions
and
15 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
Montage.Weiss.Tools.GUI/ViewModels/Dialogs/ImportDeckViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Avalonia.Controls; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using Lamar; | ||
using Montage.Weiss.Tools.CLI; | ||
using Montage.Weiss.Tools.Entities; | ||
using Montage.Weiss.Tools.GUI.Utilities; | ||
using Serilog; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Montage.Weiss.Tools.GUI.ViewModels.Dialogs; | ||
public partial class ImportDeckViewModel : ViewModelBase | ||
{ | ||
private static readonly ILogger Log = Serilog.Log.ForContext<ImportDeckViewModel>(); | ||
|
||
[ObservableProperty] | ||
private bool _isVisible; | ||
|
||
[ObservableProperty] | ||
private Func<MainWindowViewModel?> _parent; | ||
|
||
[ObservableProperty] | ||
private string deckUrl; | ||
|
||
public ImportDeckViewModel() | ||
{ | ||
Parent = () => null; | ||
IsVisible = Design.IsDesignMode; | ||
DeckUrl = string.Empty; | ||
} | ||
|
||
internal async Task ImportDeck() | ||
{ | ||
if (Parent() is not MainWindowViewModel parentModel) | ||
return; | ||
if (parentModel.Container is not IContainer container) | ||
return; | ||
|
||
var progressReporter = new ProgressReporter(Log, message => parentModel.Status = message); | ||
|
||
var command = new ExportVerb { Source = DeckUrl, NonInteractive = true, NoWarning = true }; | ||
var deck = await command.Parse(container, progressReporter); | ||
|
||
parentModel.DeckName = deck.Name; | ||
parentModel.DeckRemarks = deck.Remarks; | ||
|
||
var cacheList = deck.Ratios.Keys.Where(c => c.GetCachedImagePath() is null && c.EnglishSetType != EnglishSetType.Custom) | ||
.DistinctBy(c => c.ReleaseID) | ||
.Select(c => new CacheVerb { Language = (c.Language == CardLanguage.English ? "en" : "jp"), ReleaseIDorFullSerialID = c.ReleaseID }) | ||
.ToList(); | ||
|
||
foreach (var cacheCommand in cacheList) | ||
await cacheCommand.Run(container, progressReporter); | ||
|
||
parentModel.DeckRatioList.Clear(); | ||
|
||
foreach (var ratio in deck.Ratios) | ||
parentModel.DeckRatioList.Add(new CardRatioViewModel(ratio.Key, ratio.Value)); | ||
|
||
parentModel.SortDeck(); | ||
parentModel.UpdateDeckStats(); | ||
|
||
IsVisible = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<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" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="100" | ||
xmlns:vm="clr-namespace:Montage.Weiss.Tools.GUI.ViewModels.Dialogs;assembly=wsm-gui" | ||
x:Class="Montage.Weiss.Tools.GUI.Views.ImportDeckDialog" | ||
x:DataType="vm:ImportDeckViewModel" | ||
> | ||
<Design.DataContext> | ||
<!-- This only sets the DataContext for the previewer in an IDE, | ||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --> | ||
<vm:ImportDeckViewModel /> | ||
</Design.DataContext> | ||
|
||
<Design.DesignStyle> | ||
<Styles> | ||
<StyleInclude Source="avares://wsm-gui/Styles/Dark.axaml" /> | ||
</Styles> | ||
</Design.DesignStyle> | ||
|
||
<Border Grid.ColumnSpan="3" | ||
Name="DialogToastBox" | ||
Classes="DialogBox" | ||
VerticalAlignment="Center" | ||
HorizontalAlignment="Center" | ||
IsVisible="{Binding IsVisible}" | ||
> | ||
|
||
<StackPanel> | ||
<TextBlock Text="Importing Deck from URL..." Margin="5,5,5,10" /> | ||
<TextBox Watermark="Deck URL..." | ||
Text="{Binding DeckUrl}" | ||
MinWidth="400" | ||
/> | ||
<UniformGrid HorizontalAlignment="Stretch" | ||
Columns="2" | ||
Rows="1" | ||
> | ||
<Button MinWidth="200" | ||
HorizontalAlignment="Stretch" | ||
HorizontalContentAlignment="Center" | ||
VerticalContentAlignment="Center" | ||
Click="CancelButton_Click" | ||
Grid.Column="1" | ||
> | ||
Cancel | ||
</Button> | ||
|
||
<Button MinWidth="200" | ||
HorizontalAlignment="Stretch" | ||
HorizontalContentAlignment="Center" | ||
VerticalContentAlignment="Center" | ||
Click="ParseButton_Click" | ||
Grid.Column="2" | ||
> | ||
Parse | ||
</Button> | ||
</UniformGrid> | ||
</StackPanel> | ||
</Border> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Montage.Weiss.Tools.GUI.ViewModels.Dialogs; | ||
using System.Threading.Tasks; | ||
|
||
namespace Montage.Weiss.Tools.GUI.Views; | ||
|
||
public partial class ImportDeckDialog : UserControl | ||
{ | ||
public ImportDeckDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void CancelButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) | ||
{ | ||
if (DataContext is not ImportDeckViewModel vm) | ||
return; | ||
vm.IsVisible = false; | ||
} | ||
|
||
private void ParseButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) | ||
{ | ||
if (DataContext is not ImportDeckViewModel vm) | ||
return; | ||
Task.Run(async () => await vm.ImportDeck()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters