Skip to content

Commit dfd7bf3

Browse files
committed
Adding option to delay craft at start
1 parent fed7e9b commit dfd7bf3

File tree

11 files changed

+1125
-58
lines changed

11 files changed

+1125
-58
lines changed

AutoSynthesis/AutoSynthesis.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<TargetZone>LocalIntranet</TargetZone>
5858
</PropertyGroup>
5959
<PropertyGroup>
60-
<GenerateManifests>true</GenerateManifests>
60+
<GenerateManifests>false</GenerateManifests>
6161
</PropertyGroup>
6262
<PropertyGroup>
6363
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
@@ -120,6 +120,9 @@
120120
<Compile Include="Windows\SaveDialog.xaml.cs">
121121
<DependentUpon>SaveDialog.xaml</DependentUpon>
122122
</Compile>
123+
<Compile Include="Windows\Settings.xaml.cs">
124+
<DependentUpon>Settings.xaml</DependentUpon>
125+
</Compile>
123126
<Page Include="MainWindow.xaml">
124127
<Generator>MSBuild:Compile</Generator>
125128
<SubType>Designer</SubType>
@@ -152,6 +155,10 @@
152155
<SubType>Designer</SubType>
153156
<Generator>MSBuild:Compile</Generator>
154157
</Page>
158+
<Page Include="Windows\Settings.xaml">
159+
<SubType>Designer</SubType>
160+
<Generator>MSBuild:Compile</Generator>
161+
</Page>
155162
</ItemGroup>
156163
<ItemGroup>
157164
<Compile Include="Properties\AssemblyInfo.cs">
@@ -230,5 +237,11 @@
230237
<Resource Include="Resources\Images\Buttons\AlwaysOnTopPressedOff.png" />
231238
<Resource Include="Resources\Images\Buttons\AlwaysOnTopPressedOn.png" />
232239
</ItemGroup>
240+
<ItemGroup>
241+
<Resource Include="Resources\Images\Buttons\settings.png" />
242+
</ItemGroup>
243+
<ItemGroup>
244+
<Resource Include="Resources\Images\Buttons\settings-hover.png" />
245+
</ItemGroup>
233246
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
234247
</Project>

AutoSynthesis/AutoSynthesis.sln

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1010
app.manifest = app.manifest
1111
EndProjectSection
1212
EndProject
13-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoSynthesis Updater", "..\AutoSynthesis Updater\AutoSynthesis Updater.csproj", "{6116F2A7-C83A-482A-952A-2086165E558A}"
14-
EndProject
15-
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "..\Setup\Setup.vdproj", "{BE9281EC-D3B1-4F12-8339-3D48A71A4228}"
13+
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup1", "..\Setup1\Setup1.vdproj", "{11EC0837-AEB1-4085-9C34-67B1A7F41E77}"
1614
EndProject
1715
Global
1816
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -24,12 +22,8 @@ Global
2422
{37621B0A-1275-457E-AFB2-C6BC38CDA2A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
2523
{37621B0A-1275-457E-AFB2-C6BC38CDA2A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
2624
{37621B0A-1275-457E-AFB2-C6BC38CDA2A1}.Release|Any CPU.Build.0 = Release|Any CPU
27-
{6116F2A7-C83A-482A-952A-2086165E558A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28-
{6116F2A7-C83A-482A-952A-2086165E558A}.Debug|Any CPU.Build.0 = Debug|Any CPU
29-
{6116F2A7-C83A-482A-952A-2086165E558A}.Release|Any CPU.ActiveCfg = Release|Any CPU
30-
{6116F2A7-C83A-482A-952A-2086165E558A}.Release|Any CPU.Build.0 = Release|Any CPU
31-
{BE9281EC-D3B1-4F12-8339-3D48A71A4228}.Debug|Any CPU.ActiveCfg = Debug
32-
{BE9281EC-D3B1-4F12-8339-3D48A71A4228}.Release|Any CPU.ActiveCfg = Release
25+
{11EC0837-AEB1-4085-9C34-67B1A7F41E77}.Debug|Any CPU.ActiveCfg = Debug
26+
{11EC0837-AEB1-4085-9C34-67B1A7F41E77}.Release|Any CPU.ActiveCfg = Release
3327
EndGlobalSection
3428
GlobalSection(SolutionProperties) = preSolution
3529
HideSolutionNode = FALSE

AutoSynthesis/Classes/Backend/CraftingEngine.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ private static void RunCraftingEngine(CancellationToken token)
123123
UICommunicator.UpdateSyrup(NextSyrupUse);
124124
}
125125

126-
Logger.Write("Initiating Crafting");
127126

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

134+
// Add requested delay
135+
Break(Settings.StartingDelay);
136+
135137
// Begin Craft Timer:
136138
RunCraftProgressBar();
137139

AutoSynthesis/DataTypes/SettingsContainer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class SettingsContainer
1414
public bool CollectableCraft { get; set; }
1515
public int StartingFoodTime { get; set; }
1616
public int StartingSyrupTime { get; set; }
17+
public int StartingDelay { get; set; }
1718

18-
public SettingsContainer(int craftCount, bool collectableCraft, int foodDuration, int startingFoodTime, int startingSyrupTime)
19+
public SettingsContainer(int craftCount, bool collectableCraft, int foodDuration, int startingFoodTime, int startingSyrupTime, int startingDelay)
1920
{
2021
if (craftCount < 0)
2122
{
@@ -27,6 +28,7 @@ public SettingsContainer(int craftCount, bool collectableCraft, int foodDuration
2728
FoodDuration = foodDuration;
2829
StartingFoodTime = startingFoodTime;
2930
StartingSyrupTime = startingSyrupTime;
31+
StartingDelay = startingDelay;
3032
}
3133
}
3234
}

AutoSynthesis/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,11 @@
779779
<ImageBrush ImageSource="Resources/Images/Buttons/AlwaysOnTopOff.png"/>
780780
</Label.Background>
781781
</Label>
782+
<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">
783+
<Label.Background>
784+
<ImageBrush ImageSource="Resources/Images/Buttons/settings.png"/>
785+
</Label.Background>
786+
</Label>
782787

783788
</Grid>
784789
</Window>

AutoSynthesis/MainWindow.xaml.cs

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
using System;
1+
using AutoSynthesis.Windows;
2+
using Newtonsoft.Json;
3+
using System;
24
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.IO;
37
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
68
using System.Net;
7-
using System.IO;
9+
using System.Reflection;
810
using System.Windows;
9-
using System.Diagnostics;
1011
using System.Windows.Controls;
11-
using System.Windows.Data;
12-
using System.Windows.Documents;
1312
using System.Windows.Input;
1413
using System.Windows.Media;
1514
using System.Windows.Media.Imaging;
1615
using System.Windows.Navigation;
17-
using System.Windows.Shapes;
18-
using WindowsInput.Native;
19-
using System.Threading;
20-
using AutoSynthesis.Windows;
21-
using System.Runtime.InteropServices;
22-
using Newtonsoft.Json;
23-
using System.Deployment.Application;
24-
using System.Reflection;
2516

2617
namespace AutoSynthesis
2718
{
@@ -84,6 +75,7 @@ private enum SystemStates
8475
public Action<int, int> GetFoodAndSyrupTimings { get; set; }
8576
private System.Windows.Forms.NotifyIcon Notify { get; set; }
8677
private bool NotifyFlagged { get; set; } = true;
78+
private int StartCraftingDelay { get; set; } = 0;
8779
#endregion
8880

8981
#region Brush Colors
@@ -104,7 +96,7 @@ public MainWindow()
10496
SetErrorAction();
10597
SetupSystemTray();
10698
SetupFoodAndSyrupTimings();
107-
SetAlwaysOnTop();
99+
ReadSettingsFile();
108100

109101
// Set up UICommunicator
110102
UICommunicator.ConnectUI(LBLCraftNumber, LBLUpdate, LBLUpdateFooter, LBLTimerCraft, LBLTimerMacro,
@@ -355,7 +347,8 @@ private void BTNCraftInitiate(object sender, RoutedEventArgs e)
355347
(bool)CHBCollectableCraft.IsChecked,
356348
FoodTimer,
357349
TimerContainers[TXBFoodTimer].Timer,
358-
TimerContainers[TXBSyrupTimer].Timer
350+
TimerContainers[TXBSyrupTimer].Timer,
351+
StartCraftingDelay * 1000
359352
);
360353
}
361354
catch (InvalidUserParametersException error)
@@ -1161,38 +1154,10 @@ private void AlwaysOnTopLabelMouseUp(object sender, MouseButtonEventArgs e)
11611154
lbl.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
11621155
}
11631156

1164-
private void SetAlwaysOnTop()
1165-
{
1166-
string path = Assembly.GetExecutingAssembly().CodeBase;
1167-
SettingsFileDirectory = System.IO.Path.GetDirectoryName(path).Replace(@"file:\", "") + @"\Settings.txt";
1168-
try
1169-
{
1170-
AlwaysOnTopEnabled = Convert.ToBoolean(File.ReadAllText(SettingsFileDirectory));
1171-
}
1172-
catch
1173-
{
1174-
AlwaysOnTopEnabled = false;
1175-
}
1176-
var resourceUrl = AlwaysOnTopEnabled ? "Resources/Images/Buttons/AlwaysOnTopOn.png" : "Resources/Images/Buttons/AlwaysOnTopOff.png";
1177-
AlwaysOnTop_Label.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
1178-
}
1179-
1180-
private void WriteAlwaysOnTop()
1181-
{
1182-
try
1183-
{
1184-
File.WriteAllText(SettingsFileDirectory, AlwaysOnTopEnabled.ToString());
1185-
}
1186-
catch
1187-
{
1188-
1189-
}
1190-
}
1191-
11921157
private void FlipAlwaysOnTop()
11931158
{
11941159
AlwaysOnTopEnabled = !AlwaysOnTopEnabled;
1195-
WriteAlwaysOnTop();
1160+
WriteSaveSettings();
11961161
}
11971162
#endregion
11981163

@@ -1248,6 +1213,71 @@ private void CheckForUpdates()
12481213

12491214
#endregion
12501215

1216+
#region Settings
1217+
private void SettingsEnter(object sender, MouseEventArgs e)
1218+
{
1219+
var lbl = (Label)sender;
1220+
var resourceUrl = "Resources/Images/Buttons/settings-hover.png";
1221+
lbl.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
1222+
}
1223+
1224+
private void SettingsExit(object sender, MouseEventArgs e)
1225+
{
1226+
var lbl = (Label)sender;
1227+
var resourceUrl = "Resources/Images/Buttons/settings.png";
1228+
lbl.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
1229+
}
1230+
1231+
private void OpenSettings(object sender, MouseButtonEventArgs e)
1232+
{
1233+
try
1234+
{
1235+
var settingsDialogue = new Settings(StartCraftingDelay.ToString());
1236+
settingsDialogue.Owner = Application.Current.MainWindow;
1237+
if (settingsDialogue.ShowDialog() == true)
1238+
StartCraftingDelay = Convert.ToInt32(settingsDialogue.Time);
1239+
WriteSaveSettings();
1240+
}
1241+
catch (Exception error)
1242+
{
1243+
ErrorMessageHandler(error);
1244+
}
1245+
}
1246+
#endregion
1247+
1248+
#region Settings Saving
1249+
private void WriteSaveSettings()
1250+
{
1251+
try
1252+
{
1253+
var text = AlwaysOnTopEnabled.ToString() + "|" + StartCraftingDelay.ToString();
1254+
File.WriteAllText(SettingsFileDirectory, text);
1255+
}
1256+
catch
1257+
{
1258+
1259+
}
1260+
}
1261+
12511262

1263+
private void ReadSettingsFile()
1264+
{
1265+
string path = Assembly.GetExecutingAssembly().CodeBase;
1266+
SettingsFileDirectory = Path.GetDirectoryName(path).Replace(@"file:\", "") + @"\Settings.txt";
1267+
try
1268+
{
1269+
var fileResult = File.ReadAllText(SettingsFileDirectory).Split('|');
1270+
AlwaysOnTopEnabled = Convert.ToBoolean(fileResult[0]);
1271+
StartCraftingDelay = Convert.ToInt32(fileResult[1]);
1272+
}
1273+
catch
1274+
{
1275+
AlwaysOnTopEnabled = false;
1276+
StartCraftingDelay = 0;
1277+
}
1278+
var resourceUrl = AlwaysOnTopEnabled ? "Resources/Images/Buttons/AlwaysOnTopOn.png" : "Resources/Images/Buttons/AlwaysOnTopOff.png";
1279+
AlwaysOnTop_Label.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), resourceUrl)));
1280+
}
1281+
#endregion
12521282
}
12531283
}
113 KB
Loading
112 KB
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<Window x:Class="AutoSynthesis.Windows.Settings"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:AutoSynthesis.Windows"
7+
mc:Ignorable="d"
8+
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">
9+
<Window.Resources>
10+
<Style x:Key="FocusVisual">
11+
<Setter Property="Control.Template">
12+
<Setter.Value>
13+
<ControlTemplate>
14+
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
15+
</ControlTemplate>
16+
</Setter.Value>
17+
</Setter>
18+
</Style>
19+
<SolidColorBrush x:Key="Button.Static.Background" Color="#201834"/>
20+
<SolidColorBrush x:Key="Button.Static.Border" Color="#DCEDFF"/>
21+
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#2f2842"/>
22+
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#DCEDFF"/>
23+
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#231e30"/>
24+
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#DCEDFF"/>
25+
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
26+
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#DCEDFF"/>
27+
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
28+
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
29+
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
30+
<Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
31+
<Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
32+
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
33+
<Setter Property="BorderThickness" Value="1"/>
34+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
35+
<Setter Property="VerticalContentAlignment" Value="Center"/>
36+
<Setter Property="Padding" Value="1"/>
37+
<Setter Property="Template">
38+
<Setter.Value>
39+
<ControlTemplate TargetType="{x:Type Button}">
40+
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
41+
<ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" OpacityMask="#FFFFF8F8"/>
42+
</Border>
43+
<ControlTemplate.Triggers>
44+
<Trigger Property="IsDefaulted" Value="true">
45+
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
46+
</Trigger>
47+
<Trigger Property="IsMouseOver" Value="true">
48+
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
49+
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
50+
</Trigger>
51+
<Trigger Property="IsPressed" Value="true">
52+
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
53+
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
54+
</Trigger>
55+
<Trigger Property="IsEnabled" Value="false">
56+
<Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
57+
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
58+
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
59+
</Trigger>
60+
</ControlTemplate.Triggers>
61+
</ControlTemplate>
62+
</Setter.Value>
63+
</Setter>
64+
</Style>
65+
</Window.Resources>
66+
<Grid Margin="10,10,4,12" Height="52">
67+
<Grid.ColumnDefinitions>
68+
<ColumnDefinition/>
69+
</Grid.ColumnDefinitions>
70+
<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"/>
71+
<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"/>
72+
<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"/>
73+
74+
</Grid>
75+
</Window>

0 commit comments

Comments
 (0)