Skip to content

Commit

Permalink
Fix cursor position for Golden Cookie functionality!
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCanovas committed Sep 5, 2021
1 parent 00aa0ca commit 57bdde4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Cookie Clicker/MainWindow.xaml
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Cookie_Clicker"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="MainWindow_Loaded" ResizeMode="NoResize">
<Grid>
<Grid x:Name="myGrid">
<TextBlock x:Name="tittleTextBox" TextWrapping="Wrap" HorizontalAlignment="Left" Margin="100,20,0,0" FontWeight="Bold" FontSize="30" TextDecorations="{x:Null}" VerticalAlignment="Top" Foreground="#FF006DAC" Text="Auto Clicker for Steam Cookie Clicker"/>
<TextBox x:Name="sleepMillisTextBox" Text="{Binding SleepTimeMillis, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="NumberValidationTextBox" TextWrapping="Wrap" Margin="350,0,0,40" VerticalAlignment="Bottom" HorizontalAlignment="Left" FontSize="16" MinWidth="50" MinHeight="10"/>
<TextBlock x:Name="delayTextBlock" HorizontalAlignment="Left" Margin="50,300,0,0" Text="Initial delay" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="16" FontWeight="Bold"/>
Expand All @@ -31,6 +31,12 @@
<TextBlock x:Name="AuthorName" HorizontalAlignment="Right" Margin="0,0,50,79" Text="Angel Canovas" TextWrapping="Wrap" VerticalAlignment="Bottom" FontSize="16"/>
<TextBlock x:Name="GitlabTittle" HorizontalAlignment="Right" Margin="0,0,180,30" Text="Gitlab:" TextWrapping="Wrap" VerticalAlignment="Bottom" FontSize="20" FontWeight="Bold"/>
<TextBlock HorizontalAlignment="Right" Margin="0,0,50,34" Text="@AngelCanovas" TextWrapping="Wrap" VerticalAlignment="Bottom" FontSize="14"/>
<TextBlock x:Name="versionTextBox" HorizontalAlignment="Right" Margin="0,30,50,0" Text="V 1.2" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="24" FontWeight="Bold"/>
<TextBlock x:Name="versionTextBox" HorizontalAlignment="Right" Margin="0,30,50,0" Text="V 1.3" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="24" FontWeight="Bold"/>
<TextBlock x:Name="xPositionLabel" HorizontalAlignment="Left" Margin="315,102,0,0" Text="(Pixels) Width:" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="14" RenderTransformOrigin="-0.12,0.557"/>
<CheckBox x:Name="fixPositionCheckBox" Content="Fix position for Golden cookie" HorizontalAlignment="Left" Margin="50,100,0,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold" Checked="checkFixPosition" Unchecked="uncheckFixPosition"/>
<TextBox x:Name="xPositionTextBox" Text="{Binding XPosition, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="NumberValidationTextBox" HorizontalAlignment="Left" Margin="410,102,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.502,0.868" MinWidth="50" FontSize="14"/>
<TextBlock x:Name="yPositionLabel" HorizontalAlignment="Left" Margin="500,102,0,0" Text="Heigth:" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="14"/>
<TextBox x:Name="yPositionTextBox" Text="{Binding YPosition, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="NumberValidationTextBox" HorizontalAlignment="Left" Margin="550,102,0,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="14" MinWidth="50"/>
<Button x:Name="clearPositionButton" Content="Reset" HorizontalAlignment="Left" Margin="650,96,0,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold" Padding="10,5,10,5" Click="resetGoldenCookiePosition"/>
</Grid>
</Window>
40 changes: 38 additions & 2 deletions Cookie Clicker/MainWindow.xaml.cs
Expand Up @@ -15,7 +15,12 @@ public partial class MainWindow : Window
{
public int SleepTimeMillis { get; set; }
public int InitialDelay { get; set; }
public bool IsFixPosition { get; set; }
public double XPosition { get; set; }
public double YPosition { get; set; }

bool canAutoClickerStart = false;
bool canSetGoldenCookiePosition = false;
bool toggleAutoClickerState = false;

private IntPtr _windowHandle;
Expand Down Expand Up @@ -64,6 +69,9 @@ public MainWindow()
this.DataContext = this;
SleepTimeMillis = 20;
InitialDelay = 200;
IsFixPosition = false;
XPosition = 300;
YPosition = 400;
}

protected override void OnSourceInitialized(EventArgs e)
Expand Down Expand Up @@ -133,6 +141,7 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
var window = Window.GetWindow(this);
window.KeyDown += HandleKeyPress;
}

private void HandleKeyPress(object sender, KeyEventArgs e)
{
if (isKeyToggleAllowed)
Expand All @@ -148,8 +157,15 @@ private void HandleKeyPress(object sender, KeyEventArgs e)

private void doAClick()
{
Point currentMousePosition = GetMousePosition();
LeftMouseClick((int)currentMousePosition.X, (int)currentMousePosition.Y);
if (IsFixPosition)
{
LeftMouseClick((int) XPosition, (int) YPosition);
}
else
{
Point currentMousePosition = GetMousePosition();
LeftMouseClick((int)currentMousePosition.X, (int)currentMousePosition.Y);
}
}
public static Point GetMousePosition()
{
Expand Down Expand Up @@ -221,5 +237,25 @@ private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
Regex regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}

private void resetGoldenCookiePosition(object sender, RoutedEventArgs e)
{
XPosition = 300 / 1920 * SystemParameters.PrimaryScreenWidth;
YPosition = 400 / 1080 * SystemParameters.PrimaryScreenHeight;
xPositionTextBox.Text = XPosition.ToString();
yPositionTextBox.Text = YPosition.ToString();
IsFixPosition = false;
fixPositionCheckBox.IsChecked = false;
}

private void checkFixPosition(object sender, RoutedEventArgs e)
{
IsFixPosition = true;
}

private void uncheckFixPosition(object sender, RoutedEventArgs e)
{
IsFixPosition = false;
}
}
}

0 comments on commit 57bdde4

Please sign in to comment.