@@ -25,9 +25,28 @@ public partial class ConfigWindow
2525 private bool NeedsSMDefInvalidation ;
2626
2727 private ICommand textBoxButtonFileCmd ;
28-
2928 private ICommand textBoxButtonFolderCmd ;
3029
30+ private static TextBox SelectedBox ;
31+
32+ private readonly string [ ] CompileMacros =
33+ {
34+ "{editordir} - Directory of the SPCode binary" ,
35+ "{scriptdir} - Directory of the compiling script" ,
36+ "{copydir} - Directory where the .smx should be copied" ,
37+ "{scriptfile} - Full directory and name of the script" ,
38+ "{scriptname} - File name of the script" ,
39+ "{pluginfile} - Full directory and name of the compiled script" ,
40+ "{pluginname} - File name of the compiled script"
41+ } ;
42+
43+ private readonly string [ ] CommandMacros =
44+ {
45+ "{plugins_reload} - Reloads all compiled plugins" ,
46+ "{plugins_load} - Loads all compiled plugins" ,
47+ "{plugins_unload} - Unloads all compiled plugins"
48+ } ;
49+
3150 public ConfigWindow ( )
3251 {
3352 InitializeComponent ( ) ;
@@ -43,7 +62,14 @@ public ConfigWindow()
4362 ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
4463 }
4564
65+ SelectedBox = C_PreBuildCmd ;
66+
4667 ConfigListBox . SelectedIndex = Program . SelectedConfig ;
68+
69+ CompileMacros . ToList ( ) . ForEach ( x => CMD_ItemC . Items . Add ( x ) ) ;
70+ CMD_ItemC . SelectionChanged += CompileMacros_OnClickedItem ;
71+ CommandMacros . ToList ( ) . ForEach ( x => Rcon_MenuC . Items . Add ( x ) ) ;
72+ Rcon_MenuC . SelectionChanged += CommandMacros_OnClickedItem ;
4773 }
4874
4975 public ICommand TextBoxButtonFolderCmd
@@ -130,6 +156,49 @@ private void ConfigListBox_SelectionChanged(object sender, SelectionChangedEvent
130156 LoadConfigToUI ( ConfigListBox . SelectedIndex ) ;
131157 }
132158
159+ private void CompileMacros_OnClickedItem ( object sender , SelectionChangedEventArgs e )
160+ {
161+ if ( CMD_ItemC . SelectedItem is not string content )
162+ {
163+ return ;
164+ }
165+
166+ SelectedBox . AppendText ( content . Substring ( 0 , content . IndexOf ( '}' ) + 1 ) ) ;
167+ var item = new ComboBoxItem ( )
168+ {
169+ Visibility = Visibility . Collapsed ,
170+ Content = "Macros" ,
171+ } ;
172+ CMD_ItemC . Items . Insert ( 0 , item ) ;
173+ CMD_ItemC . SelectedIndex = 0 ;
174+ SelectedBox . Focus ( ) ;
175+ SelectedBox . Select ( SelectedBox . Text . Length , 0 ) ;
176+ }
177+
178+ private void CommandMacros_OnClickedItem ( object sender , SelectionChangedEventArgs e )
179+ {
180+ if ( Rcon_MenuC . SelectedItem is not string content )
181+ {
182+ return ;
183+ }
184+
185+ C_RConCmds . AppendText ( content . Substring ( 0 , content . IndexOf ( '}' ) + 1 ) ) ;
186+ var item = new ComboBoxItem ( )
187+ {
188+ Visibility = Visibility . Collapsed ,
189+ Content = "Macros" ,
190+ } ;
191+ Rcon_MenuC . Items . Insert ( 0 , item ) ;
192+ Rcon_MenuC . SelectedIndex = 0 ;
193+ C_RConCmds . Focus ( ) ;
194+ C_RConCmds . Select ( C_RConCmds . Text . Length , 0 ) ;
195+ }
196+
197+ private void BuildCommandsBoxes_OnFocus ( object sender , RoutedEventArgs e )
198+ {
199+ SelectedBox = sender as TextBox ;
200+ }
201+
133202 private void LoadConfigToUI ( int index )
134203 {
135204 if ( index < 0 || index >= Program . Configs . Length )
@@ -157,7 +226,6 @@ private void LoadConfigToUI(int index)
157226 C_FTPUser . Text = c . FTPUser ;
158227 C_FTPPW . Password = c . FTPPassword ;
159228 C_FTPDir . Text = c . FTPDir ;
160- C_RConEngine . SelectedIndex = c . RConUseSourceEngine ? 0 : 1 ;
161229 C_RConIP . Text = c . RConIP ;
162230 C_RConPort . Text = c . RConPort . ToString ( ) ;
163231 C_RConPW . Password = c . RConPassword ;
@@ -227,7 +295,7 @@ private void AddSMDirButton_Click(object sender, RoutedEventArgs e)
227295 catch ( UnauthorizedAccessException )
228296 {
229297 this . ShowMessageAsync ( "Access error" ,
230- "The directory you just specified could not be accessed properly by SPCode. You might have trouble using the includes from this directory." ,
298+ "The directory you just specified could not be accessed properly by SPCode. You may have trouble using the includes from this directory." ,
231299 MessageDialogStyle . Affirmative , Program . MainWindow . MetroDialogOptions ) ;
232300 }
233301
@@ -415,19 +483,6 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e)
415483 Program . Configs [ ConfigListBox . SelectedIndex ] . FTPDir = C_FTPDir . Text ;
416484 }
417485
418- private void C_RConEngine_Changed ( object sender , RoutedEventArgs e )
419- {
420- if ( ! AllowChange )
421- {
422- return ;
423- }
424-
425- if ( ConfigListBox . SelectedIndex >= 0 )
426- {
427- Program . Configs [ ConfigListBox . SelectedIndex ] . RConUseSourceEngine = C_RConEngine . SelectedIndex == 0 ;
428- }
429- }
430-
431486 private void C_RConIP_TextChanged ( object sender , RoutedEventArgs e )
432487 {
433488 if ( ! AllowChange )
@@ -476,7 +531,6 @@ private void C_RConCmds_TextChanged(object sender, RoutedEventArgs e)
476531
477532 private void MetroWindow_Closing ( object sender , CancelEventArgs e )
478533 {
479- // TODO: find out what is this for
480534 if ( NeedsSMDefInvalidation )
481535 {
482536 foreach ( var config in Program . Configs )
@@ -485,31 +539,23 @@ private void MetroWindow_Closing(object sender, CancelEventArgs e)
485539 }
486540 }
487541
488- // Fill a list with all configs from the ListBox
489-
490542 var configsList = new List < string > ( ) ;
491-
492543 foreach ( ListBoxItem item in ConfigListBox . Items )
493544 {
494545 configsList . Add ( item . Content . ToString ( ) ) ;
495546 }
496547
497- // Check for empty named configs and disallow saving configs
498-
499- foreach ( var cfg in configsList )
548+ // Check for empty named configs
549+ if ( configsList . Any ( x => string . IsNullOrEmpty ( x ) ) )
500550 {
501- if ( cfg == string . Empty )
502- {
503- e . Cancel = true ;
504- this . ShowMessageAsync ( Program . Translations . Get ( "ErrorSavingConfigs" ) ,
505- Program . Translations . Get ( "EmptyConfigNames" ) , MessageDialogStyle . Affirmative ,
506- Program . MainWindow . MetroDialogOptions ) ;
507- return ;
508- }
551+ e . Cancel = true ;
552+ this . ShowMessageAsync ( Program . Translations . Get ( "ErrorSavingConfigs" ) ,
553+ Program . Translations . Get ( "EmptyConfigNames" ) , MessageDialogStyle . Affirmative ,
554+ Program . MainWindow . MetroDialogOptions ) ;
555+ return ;
509556 }
510557
511- // Check for duplicate names in the config list and disallow saving configs
512-
558+ // Check for duplicate names in the config list
513559 if ( configsList . Count != configsList . Distinct ( ) . Count ( ) )
514560 {
515561 e . Cancel = true ;
@@ -559,7 +605,6 @@ private void MetroWindow_Closing(object sender, CancelEventArgs e)
559605 writer . WriteAttributeString ( "FTPUser" , c . FTPUser ) ;
560606 writer . WriteAttributeString ( "FTPPassword" , ManagedAES . Encrypt ( c . FTPPassword ) ) ;
561607 writer . WriteAttributeString ( "FTPDir" , c . FTPDir ) ;
562- writer . WriteAttributeString ( "RConSourceEngine" , c . RConUseSourceEngine ? "1" : "0" ) ;
563608 writer . WriteAttributeString ( "RConIP" , c . RConIP ) ;
564609 writer . WriteAttributeString ( "RConPort" , c . RConPort . ToString ( ) ) ;
565610 writer . WriteAttributeString ( "RConPassword" , ManagedAES . Encrypt ( c . RConPassword ) ) ;
@@ -604,22 +649,11 @@ private void Language_Translate()
604649 FTPPWBlock . Text = Program . Translations . Get ( "FTPPw" ) ;
605650 FTPDirBlock . Text = Program . Translations . Get ( "FTPDir" ) ;
606651 CMD_ItemC . Text = Program . Translations . Get ( "CMDLineCom" ) ;
607- ItemC_EditorDir . Content = "{editordir} - " + Program . Translations . Get ( "ComEditorDir" ) ;
608- ItemC_ScriptDir . Content = "{scriptdir} - " + Program . Translations . Get ( "ComScriptDir" ) ;
609- ItemC_CopyDir . Content = "{copydir} - " + Program . Translations . Get ( "ComCopyDir" ) ;
610- ItemC_ScriptFile . Content = "{scriptfile} - " + Program . Translations . Get ( "ComScriptFile" ) ;
611- ItemC_ScriptName . Content = "{scriptname} - " + Program . Translations . Get ( "ComScriptName" ) ;
612- ItemC_PluginFile . Content = "{pluginfile} - " + Program . Translations . Get ( "ComPluginFile" ) ;
613- ItemC_PluginName . Content = "{pluginname} - " + Program . Translations . Get ( "ComPluginName" ) ;
614- RConEngineBlock . Text = Program . Translations . Get ( "RConEngine" ) ;
615652 RConIPBlock . Text = Program . Translations . Get ( "RConIP" ) ;
616653 RConPortBlock . Text = Program . Translations . Get ( "RconPort" ) ;
617654 RConPWBlock . Text = Program . Translations . Get ( "RconPw" ) ;
618655 RConComBlock . Text = Program . Translations . Get ( "RconCom" ) ;
619656 Rcon_MenuC . Text = Program . Translations . Get ( "RConCMDLineCom" ) ;
620- MenuC_PluginsReload . Content = "{plugins_reload} - " + Program . Translations . Get ( "ComPluginsReload" ) ;
621- MenuC_PluginsLoad . Content = "{plugins_load} - " + Program . Translations . Get ( "ComPluginsLoad" ) ;
622- MenuC_PluginsUnload . Content = "{plugins_unload} - " + Program . Translations . Get ( "ComPluginsUnload" ) ;
623657 }
624658
625659
0 commit comments