Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Random Interval #62

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions AutoClicker/Models/AutoClickerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class AutoClickerSettings

public int MinimumMilliseconds { get; set; }

public bool IsRandomizedIntervalEnabled { get; set; }

public MouseButton SelectedMouseButton { get; set; }

public MouseAction SelectedMouseAction { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions AutoClicker/Utils/SettingsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public static void SetApplicationSettings(AutoClickerSettings settings)
CurrentSettings.AutoClickerSettings.MinimumMinutes = settings.MinimumMinutes;
CurrentSettings.AutoClickerSettings.MinimumHours = settings.MinimumHours;

CurrentSettings.AutoClickerSettings.IsRandomizedIntervalEnabled = settings.IsRandomizedIntervalEnabled;

CurrentSettings.AutoClickerSettings.PickedXValue = settings.PickedXValue;
CurrentSettings.AutoClickerSettings.PickedYValue = settings.PickedYValue;

Expand Down
16 changes: 12 additions & 4 deletions AutoClicker/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,24 @@
</Grid.ColumnDefinitions>

<TextBox Grid.Column="0" Width="45"
Text="{Binding AutoClickerSettings.MaximumHours, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
Text="{Binding AutoClickerSettings.MaximumHours, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding AutoClickerSettings.IsRandomizedIntervalEnabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnn678 Also consider using "IsReadOnly" instead of "IsEnabled"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between the two?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of a TextBox, IsReadOnly allows the user to set focus to and select and copy the text, but not modify it.
A disabled TextBox does not allow any interaction whatsoever.

As a general rule, use IsReadOnly when you have data that you want the user to see and copy, but not modify.
Use a disabled textbox when the data you are displaying is not applicable for the current state of a dialog or window.

Copy link
Author

@bnn678 bnn678 Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning toward rescoping this ticket and removing the textbox disabling since I can't get the binding to update. Then a later PR can disable the textboxes when appropriate.

Gotcha. Yea, this seems like a good idea. I have made this update.

Actually, I made this update and the IsReadOnly property apparently doesn't grey out the textbox (for some reason I thought it would). I think we want to make it very obvious that using the standard interval means that the randomized interval is disregarded so I believe the IsEnabled property is still the better choice. If you are satisfied with this justification, please resolve the conversation as approval.

/>
<TextBlock Grid.Column="1" Margin="5, 0, 5, 5" Text="hours"/>
<TextBox Grid.Column="2" Width="45"
Text="{Binding AutoClickerSettings.MaximumMinutes, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
Text="{Binding AutoClickerSettings.MaximumMinutes, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding AutoClickerSettings.IsRandomizedIntervalEnabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
/>
<TextBlock Grid.Column="3" Margin="5, 0, 5, 5" Text="minutes"/>
<TextBox Grid.Column="4" Width="45"
Text="{Binding AutoClickerSettings.MaximumSeconds, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
Text="{Binding AutoClickerSettings.MaximumSeconds, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding AutoClickerSettings.IsRandomizedIntervalEnabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
/>
<TextBlock Grid.Column="5" Margin="5, 0, 5, 5" Text="seconds"/>
<TextBox Grid.Column="6" Width="45"
Text="{Binding AutoClickerSettings.MaximumMilliseconds, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
Text="{Binding AutoClickerSettings.MaximumMilliseconds, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding AutoClickerSettings.IsRandomizedIntervalEnabled, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
/>
<TextBlock Grid.Column="7" Margin="5, 0, 5, 5" Text="milliseconds"/>
</Grid>
</GroupBox>
Expand Down
3 changes: 3 additions & 0 deletions AutoClicker/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ private int CalculateInterval()
{
var fixedInterval = CalculateFixedInterval();

// Update IsRandomizedIntervalEnabled
AutoClickerSettings.IsRandomizedIntervalEnabled = fixedInterval == 0;
bnn678 marked this conversation as resolved.
Show resolved Hide resolved

// if the fixed click interval is 0, return the randomized click interval
return fixedInterval == 0 ? CalculateRandomizedInterval() : fixedInterval;
}
Expand Down