Skip to content

Commit

Permalink
Minor Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
li223 committed Oct 29, 2022
1 parent 91f7904 commit 6af4c1b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 58 deletions.
51 changes: 1 addition & 50 deletions PermitSaveEditor/Data/MainWindowFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,54 +97,5 @@ public void HandleInputVisibility()
HealAll.IsEnabled = !DataManager.AllEnabled(_loadedSave!.NpcHealthDataList.Select(x => !x.IsSick));
}

static bool IsValid(string str, int min, int max)
{
int i;
return int.TryParse(str, out i) && i >= min && i <= max;
}

private void Gold_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 9999);
}

private void Wood_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 9999);
}

private void Stone_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 9999);
}

private void FishingLevel1_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 50);
}

private void FishingLevel2_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 150);
}

private void FishingLevel3_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 300);
}

private void CarpenterLevel_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 2);
}

private void BlacksmithLevel_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 2);
}

private void BadgeLevel_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 2);
}
public bool IsValid(string str, int min, int max) => int.TryParse(str, out int i) && i >= min && i <= max;
}
16 changes: 8 additions & 8 deletions PermitSaveEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
Text="0"
Grid.Column="1"
Style="{StaticResource MainTextBoxTheme}"
PreviewTextInput="Gold_OnPreviewTextInput"/>
PreviewTextInput="Resource_OnPreviewTextInput"/>

</Grid>

<Grid Grid.Column="2">
Expand All @@ -133,7 +133,7 @@
Text="0"
Grid.Column="1"
Style="{StaticResource MainTextBoxTheme}"
PreviewTextInput="CarpenterLevel_OnPreviewTextInput"/>
PreviewTextInput="Level_OnPreviewTextInput"/>
</Grid>
</Grid>

Expand Down Expand Up @@ -177,7 +177,7 @@
Text="0"
Grid.Column="1"
Style="{StaticResource MainTextBoxTheme}"
PreviewTextInput="Wood_OnPreviewTextInput"/>
PreviewTextInput="Resource_OnPreviewTextInput"/>
</Grid>

<Grid Grid.Column="2">
Expand All @@ -196,7 +196,7 @@
Text="0"
Grid.Column="1"
Style="{StaticResource MainTextBoxTheme}"
PreviewTextInput="BlacksmithLevel_OnPreviewTextInput"/>
PreviewTextInput="Level_OnPreviewTextInput"/>
</Grid>
</Grid>

Expand Down Expand Up @@ -244,7 +244,7 @@
Text="0"
Grid.Column="1"
Style="{StaticResource MainTextBoxTheme}"
PreviewTextInput="Stone_OnPreviewTextInput"/>
PreviewTextInput="Resource_OnPreviewTextInput"/>
</Grid>

<Grid Grid.Column="2">
Expand All @@ -257,13 +257,13 @@
HorizontalAlignment="Left"
Margin="4,0,0,0"
Grid.Column="0" />
<TextBox Width="100" VerticalAlignment="Center"
<TextBox Width="100" VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Name="BadgeLevel"
Text="0"
Grid.Column="1"
Style="{StaticResource MainTextBoxTheme}"
PreviewTextInput="BadgeLevel_OnPreviewTextInput"/>
PreviewTextInput="Level_OnPreviewTextInput" Margin="0,0,0,2"/>
</Grid>
</Grid>

Expand Down
21 changes: 21 additions & 0 deletions PermitSaveEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Newtonsoft.Json;
using PermitSaveEditor.Data;
Expand Down Expand Up @@ -158,4 +160,23 @@ private void HealAll_Click(object sender, RoutedEventArgs e)
}

#endregion

#region Input Validation

private void Resource_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
=> e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 9999);

private void Level_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
=> e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 2);

private void FishingLevel1_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
=> e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 50);

private void FishingLevel2_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
=> e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 150);

private void FishingLevel3_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
=> e.Handled = !IsValid(((TextBox)sender).Text + e.Text, 0, 300);

#endregion
}

0 comments on commit 6af4c1b

Please sign in to comment.