@@ -25,9 +25,28 @@ public partial class ConfigWindow
25
25
private bool NeedsSMDefInvalidation ;
26
26
27
27
private ICommand textBoxButtonFileCmd ;
28
-
29
28
private ICommand textBoxButtonFolderCmd ;
30
29
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
+
31
50
public ConfigWindow ( )
32
51
{
33
52
InitializeComponent ( ) ;
@@ -43,7 +62,14 @@ public ConfigWindow()
43
62
ConfigListBox . Items . Add ( new ListBoxItem { Content = config . Name } ) ;
44
63
}
45
64
65
+ SelectedBox = C_PreBuildCmd ;
66
+
46
67
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 ;
47
73
}
48
74
49
75
public ICommand TextBoxButtonFolderCmd
@@ -130,6 +156,49 @@ private void ConfigListBox_SelectionChanged(object sender, SelectionChangedEvent
130
156
LoadConfigToUI ( ConfigListBox . SelectedIndex ) ;
131
157
}
132
158
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
+
133
202
private void LoadConfigToUI ( int index )
134
203
{
135
204
if ( index < 0 || index >= Program . Configs . Length )
@@ -157,7 +226,6 @@ private void LoadConfigToUI(int index)
157
226
C_FTPUser . Text = c . FTPUser ;
158
227
C_FTPPW . Password = c . FTPPassword ;
159
228
C_FTPDir . Text = c . FTPDir ;
160
- C_RConEngine . SelectedIndex = c . RConUseSourceEngine ? 0 : 1 ;
161
229
C_RConIP . Text = c . RConIP ;
162
230
C_RConPort . Text = c . RConPort . ToString ( ) ;
163
231
C_RConPW . Password = c . RConPassword ;
@@ -227,7 +295,7 @@ private void AddSMDirButton_Click(object sender, RoutedEventArgs e)
227
295
catch ( UnauthorizedAccessException )
228
296
{
229
297
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." ,
231
299
MessageDialogStyle . Affirmative , Program . MainWindow . MetroDialogOptions ) ;
232
300
}
233
301
@@ -415,19 +483,6 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e)
415
483
Program . Configs [ ConfigListBox . SelectedIndex ] . FTPDir = C_FTPDir . Text ;
416
484
}
417
485
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
-
431
486
private void C_RConIP_TextChanged ( object sender , RoutedEventArgs e )
432
487
{
433
488
if ( ! AllowChange )
@@ -476,7 +531,6 @@ private void C_RConCmds_TextChanged(object sender, RoutedEventArgs e)
476
531
477
532
private void MetroWindow_Closing ( object sender , CancelEventArgs e )
478
533
{
479
- // TODO: find out what is this for
480
534
if ( NeedsSMDefInvalidation )
481
535
{
482
536
foreach ( var config in Program . Configs )
@@ -485,31 +539,23 @@ private void MetroWindow_Closing(object sender, CancelEventArgs e)
485
539
}
486
540
}
487
541
488
- // Fill a list with all configs from the ListBox
489
-
490
542
var configsList = new List < string > ( ) ;
491
-
492
543
foreach ( ListBoxItem item in ConfigListBox . Items )
493
544
{
494
545
configsList . Add ( item . Content . ToString ( ) ) ;
495
546
}
496
547
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 ) ) )
500
550
{
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 ;
509
556
}
510
557
511
- // Check for duplicate names in the config list and disallow saving configs
512
-
558
+ // Check for duplicate names in the config list
513
559
if ( configsList . Count != configsList . Distinct ( ) . Count ( ) )
514
560
{
515
561
e . Cancel = true ;
@@ -559,7 +605,6 @@ private void MetroWindow_Closing(object sender, CancelEventArgs e)
559
605
writer . WriteAttributeString ( "FTPUser" , c . FTPUser ) ;
560
606
writer . WriteAttributeString ( "FTPPassword" , ManagedAES . Encrypt ( c . FTPPassword ) ) ;
561
607
writer . WriteAttributeString ( "FTPDir" , c . FTPDir ) ;
562
- writer . WriteAttributeString ( "RConSourceEngine" , c . RConUseSourceEngine ? "1" : "0" ) ;
563
608
writer . WriteAttributeString ( "RConIP" , c . RConIP ) ;
564
609
writer . WriteAttributeString ( "RConPort" , c . RConPort . ToString ( ) ) ;
565
610
writer . WriteAttributeString ( "RConPassword" , ManagedAES . Encrypt ( c . RConPassword ) ) ;
@@ -604,22 +649,11 @@ private void Language_Translate()
604
649
FTPPWBlock . Text = Program . Translations . Get ( "FTPPw" ) ;
605
650
FTPDirBlock . Text = Program . Translations . Get ( "FTPDir" ) ;
606
651
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" ) ;
615
652
RConIPBlock . Text = Program . Translations . Get ( "RConIP" ) ;
616
653
RConPortBlock . Text = Program . Translations . Get ( "RconPort" ) ;
617
654
RConPWBlock . Text = Program . Translations . Get ( "RconPw" ) ;
618
655
RConComBlock . Text = Program . Translations . Get ( "RconCom" ) ;
619
656
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" ) ;
623
657
}
624
658
625
659
0 commit comments