Skip to content

Commit

Permalink
Fixes #502.
Browse files Browse the repository at this point in the history
KyouyamaKazusa0805 committed Nov 14, 2023
1 parent 6ee3986 commit b0400ad
Showing 3 changed files with 456 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -30,7 +30,9 @@
<AppBarElementContainer>
<ComboBox x:Name="PuzzleLibraryChoser" DisplayMemberPath="DisplayName" SelectionChanged="PuzzleLibraryChoser_SelectionChanged" />
</AppBarElementContainer>
<AppBarButton Icon="NewWindow" Label="{m:R Key=AnalyzePage_FetchPuzzleFromLibrary}" Click="FetchInPuzzleLibraryButton_Click" />
<AppBarButton
x:Name="FetchInPuzzleLibraryButton" Icon="NewWindow" Label="{m:R Key=AnalyzePage_FetchPuzzleFromLibrary}"
Click="FetchInPuzzleLibraryButton_Click" />
<AppBarSeparator />
<AppBarButton
Icon="NewWindow" Label="{m:R Key=AnalyzePage_GeneratingPuzzlesAndSaveThem}"
37 changes: 28 additions & 9 deletions src/SudokuStudio/Views/Pages/Operation/GeneratingOperation.xaml.cs
Original file line number Diff line number Diff line change
@@ -106,18 +106,33 @@ private void SetMemoryOptions(AnalyzePage basePage)

if (basePage._puzzleLibraries is { } libs)
{
PuzzleLibraryChoser.ItemsSource = libs;
var fileId = ((App)Application.Current).Preference.UIPreferences.FetchingPuzzleLibrary;
var foundElementCorrespondingIndex = -1;
for (var i = 0; i < libs.Count; i++)
switch (libs.Count)
{
if (libs[i] is { FileId: var fileIdToCheck } && fileIdToCheck == fileId)
case 0:
{
foundElementCorrespondingIndex = i;
PuzzleLibraryChoser.Visibility = Visibility.Collapsed;
FetchInPuzzleLibraryButton.Visibility = Visibility.Collapsed;
break;
}
default:
{
PuzzleLibraryChoser.Visibility = Visibility.Visible;
FetchInPuzzleLibraryButton.Visibility = Visibility.Visible;
PuzzleLibraryChoser.ItemsSource = libs;
var fileId = ((App)Application.Current).Preference.UIPreferences.FetchingPuzzleLibrary;
var foundElementCorrespondingIndex = -1;
for (var i = 0; i < libs.Count; i++)
{
if (libs[i] is { FileId: var fileIdToCheck } && fileIdToCheck == fileId)
{
foundElementCorrespondingIndex = i;
break;
}
}
PuzzleLibraryChoser.SelectedIndex = foundElementCorrespondingIndex == -1 ? 0 : foundElementCorrespondingIndex;
break;
}
}
PuzzleLibraryChoser.SelectedIndex = foundElementCorrespondingIndex == -1 ? 0 : foundElementCorrespondingIndex;
}
}

@@ -305,9 +320,13 @@ private async void NewPuzzleButton_ClickAsync(object sender, RoutedEventArgs e)
private void FetchInPuzzleLibraryButton_Click(object sender, RoutedEventArgs e)
{
var source = (PuzzleLibraryBindableSource)PuzzleLibraryChoser.SelectedValue;
var i = Random.Shared.Next(0, source.Puzzles.Length);
if (source.Puzzles.Length == 0)
{
// No puzzles in this library.
return;
}

BasePage.SudokuPane.Puzzle = source.Puzzles[i];
BasePage.SudokuPane.Puzzle = source.Puzzles[Random.Shared.Next(0, source.Puzzles.Length)];
BasePage.ClearAnalyzeTabsData();
}

Loading

0 comments on commit b0400ad

Please sign in to comment.