From 998728fa98d8042702790d4fd8ca502c9fe168be Mon Sep 17 00:00:00 2001 From: SunnieShine Date: Wed, 6 Mar 2024 10:55:04 +0800 Subject: [PATCH] Fix little bug, close #557. --- .../StrategyingResources.Designer.cs | 2 +- .../Resources/StrategyingResources.resx | 2 +- .../Resources/StrategyingResources.zh-cn.resx | 2 +- .../Constraints/EliminationCountConstraint.cs | 12 ++++++-- .../Pages/GeneratedPuzzleConstraintPage.xaml | 2 +- .../GeneratedPuzzleConstraintPage.xaml.cs | 29 +++++++++++++++++-- src/docxml/Sudoku.Strategying.xml | 7 ++++- 7 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/Sudoku.Strategying/Resources/StrategyingResources.Designer.cs b/src/Sudoku.Strategying/Resources/StrategyingResources.Designer.cs index fe6f4f5d2..a4a30564b 100644 --- a/src/Sudoku.Strategying/Resources/StrategyingResources.Designer.cs +++ b/src/Sudoku.Strategying/Resources/StrategyingResources.Designer.cs @@ -124,7 +124,7 @@ internal static string DifficultyLevelConstraint { } /// - /// Looks up a localized string similar to Elimination count rule: a step must contain {0} {1} elimination{2}. + /// Looks up a localized string similar to Elimination count rule: a {3} step must contain {0} {1} elimination{2}. /// internal static string EliminationCountConstraint { get { diff --git a/src/Sudoku.Strategying/Resources/StrategyingResources.resx b/src/Sudoku.Strategying/Resources/StrategyingResources.resx index 88297d4f4..ca1e626ef 100644 --- a/src/Sudoku.Strategying/Resources/StrategyingResources.resx +++ b/src/Sudoku.Strategying/Resources/StrategyingResources.resx @@ -184,6 +184,6 @@ Single prefer rule: {0} is preferred as primary technique, Hidden Single in rows or columns {1}included - Elimination count rule: a step must contain {0} {1} elimination{2} + Elimination count rule: a {3} step must contain {0} {1} elimination{2} \ No newline at end of file diff --git a/src/Sudoku.Strategying/Resources/StrategyingResources.zh-cn.resx b/src/Sudoku.Strategying/Resources/StrategyingResources.zh-cn.resx index 8cf602424..2e2d23441 100644 --- a/src/Sudoku.Strategying/Resources/StrategyingResources.zh-cn.resx +++ b/src/Sudoku.Strategying/Resources/StrategyingResources.zh-cn.resx @@ -181,6 +181,6 @@ 出数技巧偏好:希望以{0}技巧作为主技巧解题,行列排除{1}在计算之中 - 删数数量:一个步骤需要有 {0} {1} 个删数结论{2} + 删数数量:一个{3}步骤需要有 {0} {1} 个删数结论{2} \ No newline at end of file diff --git a/src/Sudoku.Strategying/Strategying/Constraints/EliminationCountConstraint.cs b/src/Sudoku.Strategying/Strategying/Constraints/EliminationCountConstraint.cs index 9a0956393..8e2ab2449 100644 --- a/src/Sudoku.Strategying/Strategying/Constraints/EliminationCountConstraint.cs +++ b/src/Sudoku.Strategying/Strategying/Constraints/EliminationCountConstraint.cs @@ -15,6 +15,13 @@ public sealed partial class EliminationCountConstraint : Constraint, IComparison [StringMember] public int LimitCount { get; set; } + /// + /// Indicates the technique used. + /// + [HashCodeMember] + [StringMember] + public Technique Technique { get; set; } + /// [HashCodeMember] [StringMember] @@ -33,7 +40,7 @@ public override bool Check(ConstraintCheckingContext context) var @operator = Operator.GetOperator(); foreach (var step in context.AnalyzerResult) { - if (@operator(LimitCount, step.Conclusions.Length)) + if (step.Code == Technique && @operator(LimitCount, step.Conclusions.Length)) { return true; } @@ -52,6 +59,7 @@ public override string ToString(CultureInfo? culture = null) ResourceDictionary.Get("EliminationCountConstraint", culture), Operator.GetOperatorString(), LimitCount, - LimitCount != 1 ? string.Empty : ResourceDictionary.Get("NounPluralSuffix", culture) + LimitCount != 1 ? string.Empty : ResourceDictionary.Get("NounPluralSuffix", culture), + Technique.GetName(culture) ); } diff --git a/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml b/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml index 6a8db285f..b8325c0ec 100644 --- a/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml +++ b/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml @@ -48,7 +48,7 @@ - + diff --git a/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml.cs b/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml.cs index 3db919820..224c105ba 100644 --- a/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml.cs +++ b/src/SudokuStudio/Views/Pages/GeneratedPuzzleConstraintPage.xaml.cs @@ -706,9 +706,9 @@ from technique in techniques select technique.GetName(App.CurrentCulture) }; } - private SettingsCard? Create_EliminationCount(EliminationCountConstraint constraint) + private SettingsExpander? Create_EliminationCount(EliminationCountConstraint constraint) { - if (constraint is not { LimitCount: var limitCount, Operator: var @operator }) + if (constraint is not { LimitCount: var limitCount, Operator: var @operator, Technique: var technique }) { return null; } @@ -723,15 +723,38 @@ from technique in techniques select technique.GetName(App.CurrentCulture) // var limitCountControl = LimitCountControl(limitCount, constraint); + // + // chosen techniques displayer + // + var displayerControl = new TextBlock + { + MaxWidth = 400, + TextWrapping = TextWrapping.WrapWholeWords, + VerticalAlignment = VerticalAlignment.Center, + Text = $"{technique.GetName(App.CurrentCulture)}{ResourceDictionary.Get("_Token_Comma2", App.CurrentCulture)}" + }; + + // + // technique view + // + var techniqueControl = new TechniqueView { SelectionMode = TechniqueViewSelectionMode.Single, SelectedTechniques = [technique] }; + techniqueControl.CurrentSelectedTechniqueChanged += (_, e) => + { + var technique = e.Technique; + constraint.Technique = technique; + displayerControl.Text = $"{technique.GetName(App.CurrentCulture)}{ResourceDictionary.Get("_Token_Comma2", App.CurrentCulture)}"; + }; + return new() { Header = ResourceDictionary.Get("GeneratedPuzzleConstraintPage_EliminationCount", App.CurrentCulture), Margin = DefaultMargin, + Items = { techniqueControl }, Content = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 3, - Children = { operatorControl, limitCountControl } + Children = { displayerControl, operatorControl, limitCountControl } }, Tag = constraint }; diff --git a/src/docxml/Sudoku.Strategying.xml b/src/docxml/Sudoku.Strategying.xml index 5f4815afc..9ae1d5d96 100644 --- a/src/docxml/Sudoku.Strategying.xml +++ b/src/docxml/Sudoku.Strategying.xml @@ -87,7 +87,7 @@ - Looks up a localized string similar to Elimination count rule: a step must contain {0} {1} elimination{2}. + Looks up a localized string similar to Elimination count rule: a {3} step must contain {0} {1} elimination{2}. @@ -496,6 +496,11 @@ + + + Indicates the technique used. + +