Merge pull request #3760 from MaaAssistantArknights/feat/realtime_binding_combat_parameters

feat: 实时更新战斗设置
This commit is contained in:
uye
2023-02-20 00:37:57 +08:00
committed by GitHub
3 changed files with 41 additions and 28 deletions

View File

@@ -1468,6 +1468,11 @@ namespace MaaWpfGui
get => _stage1;
set
{
if (_stage1 == value)
{
return;
}
if (CustomStageCode)
{
value = ToUpperAndCheckStage(value);
@@ -1555,16 +1560,16 @@ namespace MaaWpfGui
{
get
{
if (!IsStageOpen(_remainingSanityStage))
{
return string.Empty;
}
return _remainingSanityStage;
}
set
{
if (_remainingSanityStage == value)
{
return;
}
if (CustomStageCode)
{
value = ToUpperAndCheckStage(value);
@@ -1832,17 +1837,15 @@ namespace MaaWpfGui
get => _medicineNumber;
set
{
if (string.IsNullOrEmpty(value))
if (_medicineNumber == value)
{
value = "0";
}
if (value == "0")
{
UseStone = false;
return;
}
SetAndNotify(ref _medicineNumber, value);
// If the amount of medicine is 0, the stone is not used.
UseStone = UseStone;
SetFightParams();
ViewStatusStorage.Set("MainFunction.UseMedicine.Quantity", MedicineNumber);
}
@@ -1858,7 +1861,8 @@ namespace MaaWpfGui
get => _useStone;
set
{
if (MedicineNumber == "0")
// If the amount of medicine is 0, the stone is not used.
if (!int.TryParse(MedicineNumber, out int result) || result == 0)
{
value = false;
}
@@ -1883,9 +1887,9 @@ namespace MaaWpfGui
get => _stoneNumber;
set
{
if (string.IsNullOrEmpty(value))
if (_stoneNumber == value)
{
value = "0";
return;
}
SetAndNotify(ref _stoneNumber, value);
@@ -1919,9 +1923,9 @@ namespace MaaWpfGui
get => _maxTimes;
set
{
if (string.IsNullOrEmpty(value))
if (MaxTimes == value)
{
value = "0";
return;
}
SetAndNotify(ref _maxTimes, value);
@@ -2065,11 +2069,6 @@ namespace MaaWpfGui
get => _dropsQuantity;
set
{
if (string.IsNullOrEmpty(value))
{
value = "0";
}
SetAndNotify(ref _dropsQuantity, value);
SetFightParams();
ViewStatusStorage.Set("MainFunction.Drops.Quantity", DropsQuantity);

View File

@@ -57,8 +57,9 @@
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"
LostFocus="FightSettingsTextBoxLostFocus"
PreviewTextInput="TextBox_RestrictInputInt"
Text="{Binding MedicineNumber}" />
Text="{Binding MedicineNumber, UpdateSourceTrigger=PropertyChanged}" />
<TextBox
Width="60"
Height="30"
@@ -67,8 +68,9 @@
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"
LostFocus="FightSettingsTextBoxLostFocus"
PreviewTextInput="TextBox_RestrictInputInt"
Text="{Binding StoneNumber}" />
Text="{Binding StoneNumber, UpdateSourceTrigger=PropertyChanged}" />
<TextBox
Width="60"
Height="30"
@@ -77,8 +79,9 @@
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"
LostFocus="FightSettingsTextBoxLostFocus"
PreviewTextInput="TextBox_RestrictInputInt"
Text="{Binding MaxTimes}" />
Text="{Binding MaxTimes, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
<Grid Grid.Row="1">
@@ -125,8 +128,9 @@
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"
LostFocus="FightSettingsTextBoxLostFocus"
PreviewTextInput="TextBox_RestrictInputInt"
Text="{Binding DropsQuantity}"
Text="{Binding DropsQuantity, UpdateSourceTrigger=PropertyChanged}"
Visibility="{c:Binding IsSpecifiedDrops}" />
</StackPanel>
</Grid>
@@ -195,7 +199,7 @@
Padding="6,0,0,0"
VerticalContentAlignment="Center"
IsHitTestVisible="{c:Binding !FightTaskRunning}"
Text="{Binding Stage1}"
Text="{Binding Stage1, UpdateSourceTrigger=PropertyChanged}"
ToolTip="{DynamicResource CustomStageCodeTip}"
Visibility="{c:Binding CustomStageCode}" />
<ComboBox
@@ -238,7 +242,7 @@
Padding="6,0,0,0"
VerticalContentAlignment="Center"
IsHitTestVisible="{c:Binding !FightTaskRunning}"
Text="{Binding RemainingSanityStage}"
Text="{Binding RemainingSanityStage, UpdateSourceTrigger=PropertyChanged}"
ToolTip="{DynamicResource UseRemainingSanityStageTip}"
Visibility="{c:Binding UseRemainingSanityStage and CustomStageCode}" />
</StackPanel>

View File

@@ -12,6 +12,7 @@
// </copyright>
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -36,5 +37,14 @@ namespace MaaWpfGui
Regex regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
private void FightSettingsTextBoxLostFocus(object sender, RoutedEventArgs e)
{
TextBox textBox = sender as TextBox;
if (string.IsNullOrEmpty(textBox.Text))
{
textBox.Text = "0";
}
}
}
}