1- using System ;
1+ using AutoSynthesis . Windows ;
2+ using Newtonsoft . Json ;
3+ using System ;
24using System . Collections . Generic ;
5+ using System . Diagnostics ;
6+ using System . IO ;
37using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
68using System . Net ;
7- using System . IO ;
9+ using System . Reflection ;
810using System . Windows ;
9- using System . Diagnostics ;
1011using System . Windows . Controls ;
11- using System . Windows . Data ;
12- using System . Windows . Documents ;
1312using System . Windows . Input ;
1413using System . Windows . Media ;
1514using System . Windows . Media . Imaging ;
1615using 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
2617namespace 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}
0 commit comments