Skip to content

Commit

Permalink
Adding option to delay craft at start
Browse files Browse the repository at this point in the history
  • Loading branch information
Saad888 committed Feb 8, 2021
1 parent fed7e9b commit dfd7bf3
Show file tree
Hide file tree
Showing 11 changed files with 1,125 additions and 58 deletions.
15 changes: 14 additions & 1 deletion AutoSynthesis/AutoSynthesis.csproj
Expand Up @@ -57,7 +57,7 @@
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
Expand Down Expand Up @@ -120,6 +120,9 @@
<Compile Include="Windows\SaveDialog.xaml.cs">
<DependentUpon>SaveDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\Settings.xaml.cs">
<DependentUpon>Settings.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -152,6 +155,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\Settings.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down Expand Up @@ -230,5 +237,11 @@
<Resource Include="Resources\Images\Buttons\AlwaysOnTopPressedOff.png" />
<Resource Include="Resources\Images\Buttons\AlwaysOnTopPressedOn.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Images\Buttons\settings.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Images\Buttons\settings-hover.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
12 changes: 3 additions & 9 deletions AutoSynthesis/AutoSynthesis.sln
Expand Up @@ -10,9 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
app.manifest = app.manifest
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoSynthesis Updater", "..\AutoSynthesis Updater\AutoSynthesis Updater.csproj", "{6116F2A7-C83A-482A-952A-2086165E558A}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "..\Setup\Setup.vdproj", "{BE9281EC-D3B1-4F12-8339-3D48A71A4228}"
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup1", "..\Setup1\Setup1.vdproj", "{11EC0837-AEB1-4085-9C34-67B1A7F41E77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -24,12 +22,8 @@ Global
{37621B0A-1275-457E-AFB2-C6BC38CDA2A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37621B0A-1275-457E-AFB2-C6BC38CDA2A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37621B0A-1275-457E-AFB2-C6BC38CDA2A1}.Release|Any CPU.Build.0 = Release|Any CPU
{6116F2A7-C83A-482A-952A-2086165E558A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6116F2A7-C83A-482A-952A-2086165E558A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6116F2A7-C83A-482A-952A-2086165E558A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6116F2A7-C83A-482A-952A-2086165E558A}.Release|Any CPU.Build.0 = Release|Any CPU
{BE9281EC-D3B1-4F12-8339-3D48A71A4228}.Debug|Any CPU.ActiveCfg = Debug
{BE9281EC-D3B1-4F12-8339-3D48A71A4228}.Release|Any CPU.ActiveCfg = Release
{11EC0837-AEB1-4085-9C34-67B1A7F41E77}.Debug|Any CPU.ActiveCfg = Debug
{11EC0837-AEB1-4085-9C34-67B1A7F41E77}.Release|Any CPU.ActiveCfg = Release
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 3 additions & 1 deletion AutoSynthesis/Classes/Backend/CraftingEngine.cs
Expand Up @@ -123,7 +123,6 @@ private static void RunCraftingEngine(CancellationToken token)
UICommunicator.UpdateSyrup(NextSyrupUse);
}

Logger.Write("Initiating Crafting");

// If crafts remaining was 0, loop infinitley
// If not, craft until quota is met
Expand All @@ -132,6 +131,9 @@ private static void RunCraftingEngine(CancellationToken token)
// UI MESSAGE: Set timer for overall craft
UICommunicator.UpdateCraftUIInfo(CraftCount, Settings.CraftCount);

// Add requested delay
Break(Settings.StartingDelay);

// Begin Craft Timer:
RunCraftProgressBar();

Expand Down
4 changes: 3 additions & 1 deletion AutoSynthesis/DataTypes/SettingsContainer.cs
Expand Up @@ -14,8 +14,9 @@ class SettingsContainer
public bool CollectableCraft { get; set; }
public int StartingFoodTime { get; set; }
public int StartingSyrupTime { get; set; }
public int StartingDelay { get; set; }

public SettingsContainer(int craftCount, bool collectableCraft, int foodDuration, int startingFoodTime, int startingSyrupTime)
public SettingsContainer(int craftCount, bool collectableCraft, int foodDuration, int startingFoodTime, int startingSyrupTime, int startingDelay)
{
if (craftCount < 0)
{
Expand All @@ -27,6 +28,7 @@ public SettingsContainer(int craftCount, bool collectableCraft, int foodDuration
FoodDuration = foodDuration;
StartingFoodTime = startingFoodTime;
StartingSyrupTime = startingSyrupTime;
StartingDelay = startingDelay;
}
}
}
5 changes: 5 additions & 0 deletions AutoSynthesis/MainWindow.xaml
Expand Up @@ -779,6 +779,11 @@
<ImageBrush ImageSource="Resources/Images/Buttons/AlwaysOnTopOff.png"/>
</Label.Background>
</Label>
<Label x:Name="SettingsButton" Content="" Grid.Column="1" HorizontalAlignment="Left" Margin="204,2,0,0" VerticalAlignment="Top" Width="15" Height="15" Opacity="0.5" MouseEnter="SettingsEnter" MouseLeave="SettingsExit" ToolTip="Settings" MouseUp="OpenSettings">
<Label.Background>
<ImageBrush ImageSource="Resources/Images/Buttons/settings.png"/>
</Label.Background>
</Label>

</Grid>
</Window>
122 changes: 76 additions & 46 deletions AutoSynthesis/MainWindow.xaml.cs
@@ -1,27 +1,18 @@
using System;
using AutoSynthesis.Windows;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WindowsInput.Native;
using System.Threading;
using AutoSynthesis.Windows;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.Deployment.Application;
using System.Reflection;

namespace AutoSynthesis
{
Expand Down Expand Up @@ -84,6 +75,7 @@ private enum SystemStates
public Action<int, int> GetFoodAndSyrupTimings { get; set; }
private System.Windows.Forms.NotifyIcon Notify { get; set; }
private bool NotifyFlagged { get; set; } = true;
private int StartCraftingDelay { get; set; } = 0;
#endregion

#region Brush Colors
Expand All @@ -104,7 +96,7 @@ public MainWindow()
SetErrorAction();
SetupSystemTray();
SetupFoodAndSyrupTimings();
SetAlwaysOnTop();
ReadSettingsFile();

// Set up UICommunicator
UICommunicator.ConnectUI(LBLCraftNumber, LBLUpdate, LBLUpdateFooter, LBLTimerCraft, LBLTimerMacro,
Expand Down Expand Up @@ -355,7 +347,8 @@ private void BTNCraftInitiate(object sender, RoutedEventArgs e)
(bool)CHBCollectableCraft.IsChecked,
FoodTimer,
TimerContainers[TXBFoodTimer].Timer,
TimerContainers[TXBSyrupTimer].Timer
TimerContainers[TXBSyrupTimer].Timer,
StartCraftingDelay * 1000
);
}
catch (InvalidUserParametersException error)
Expand Down Expand Up @@ -1161,38 +1154,10 @@ private void AlwaysOnTopLabelMouseUp(object sender, MouseButtonEventArgs e)
lbl.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
}

private void SetAlwaysOnTop()
{
string path = Assembly.GetExecutingAssembly().CodeBase;
SettingsFileDirectory = System.IO.Path.GetDirectoryName(path).Replace(@"file:\", "") + @"\Settings.txt";
try
{
AlwaysOnTopEnabled = Convert.ToBoolean(File.ReadAllText(SettingsFileDirectory));
}
catch
{
AlwaysOnTopEnabled = false;
}
var resourceUrl = AlwaysOnTopEnabled ? "Resources/Images/Buttons/AlwaysOnTopOn.png" : "Resources/Images/Buttons/AlwaysOnTopOff.png";
AlwaysOnTop_Label.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
}

private void WriteAlwaysOnTop()
{
try
{
File.WriteAllText(SettingsFileDirectory, AlwaysOnTopEnabled.ToString());
}
catch
{

}
}

private void FlipAlwaysOnTop()
{
AlwaysOnTopEnabled = !AlwaysOnTopEnabled;
WriteAlwaysOnTop();
WriteSaveSettings();
}
#endregion

Expand Down Expand Up @@ -1248,6 +1213,71 @@ private void CheckForUpdates()

#endregion

#region Settings
private void SettingsEnter(object sender, MouseEventArgs e)
{
var lbl = (Label)sender;
var resourceUrl = "Resources/Images/Buttons/settings-hover.png";
lbl.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
}

private void SettingsExit(object sender, MouseEventArgs e)
{
var lbl = (Label)sender;
var resourceUrl = "Resources/Images/Buttons/settings.png";
lbl.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
}

private void OpenSettings(object sender, MouseButtonEventArgs e)
{
try
{
var settingsDialogue = new Settings(StartCraftingDelay.ToString());
settingsDialogue.Owner = Application.Current.MainWindow;
if (settingsDialogue.ShowDialog() == true)
StartCraftingDelay = Convert.ToInt32(settingsDialogue.Time);
WriteSaveSettings();
}
catch (Exception error)
{
ErrorMessageHandler(error);
}
}
#endregion

#region Settings Saving
private void WriteSaveSettings()
{
try
{
var text = AlwaysOnTopEnabled.ToString() + "|" + StartCraftingDelay.ToString();
File.WriteAllText(SettingsFileDirectory, text);
}
catch
{

}
}


private void ReadSettingsFile()
{
string path = Assembly.GetExecutingAssembly().CodeBase;
SettingsFileDirectory = Path.GetDirectoryName(path).Replace(@"file:\", "") + @"\Settings.txt";
try
{
var fileResult = File.ReadAllText(SettingsFileDirectory).Split('|');
AlwaysOnTopEnabled = Convert.ToBoolean(fileResult[0]);
StartCraftingDelay = Convert.ToInt32(fileResult[1]);
}
catch
{
AlwaysOnTopEnabled = false;
StartCraftingDelay = 0;
}
var resourceUrl = AlwaysOnTopEnabled ? "Resources/Images/Buttons/AlwaysOnTopOn.png" : "Resources/Images/Buttons/AlwaysOnTopOff.png";
AlwaysOnTop_Label.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
}
#endregion
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions AutoSynthesis/Windows/Settings.xaml
@@ -0,0 +1,75 @@
<Window x:Class="AutoSynthesis.Windows.Settings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AutoSynthesis.Windows"
mc:Ignorable="d"
Title="Settings" SizeToContent="WidthAndHeight" ResizeMode="NoResize" ShowInTaskbar="False" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" Loaded="Window_Loaded" Background="#FF221632" Icon="/AutoSynthesis;component/Resources/Icon/Icon.png" Width="388" Height="102">
<Window.Resources>
<Style x:Key="FocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="Button.Static.Background" Color="#201834"/>
<SolidColorBrush x:Key="Button.Static.Border" Color="#DCEDFF"/>
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#2f2842"/>
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#DCEDFF"/>
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#231e30"/>
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#DCEDFF"/>
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#DCEDFF"/>
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
<Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" OpacityMask="#FFFFF8F8"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsDefaulted" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Margin="10,10,4,12" Height="52">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="Set the delay before starting a craft" HorizontalAlignment="Left" VerticalAlignment="Top" Height="26" Width="358" Margin="0" Foreground="#FFDCEDFF" FontFamily="/AutoSynthesis;component/Resources/Fonts/#Sen" VerticalContentAlignment="Center" Padding="5,0,0,3" FontSize="16"/>
<TextBox x:Name="TXBDelay" HorizontalAlignment="Left" Height="23" Margin="5,0,0,5" TextWrapping="Wrap" VerticalAlignment="Bottom" Width="281" Background="#FFDCEDFF" FontFamily="/AutoSynthesis;component/Resources/Fonts/#Sen" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="14" PreviewTextInput="NumberValidationTextBox"/>
<Button x:Name="BTNConfirm" Content="Save" HorizontalAlignment="Right" Margin="0,0,5,5" VerticalAlignment="Bottom" Width="72" Click="BTNConfirm_Click" Height="23" Style="{DynamicResource ButtonStyle1}" Foreground="#FFDCEDFF" FontFamily="/AutoSynthesis;component/Resources/Fonts/#Sen" FontSize="14"/>

</Grid>
</Window>

0 comments on commit dfd7bf3

Please sign in to comment.