Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit be36c06

Browse files
committed
improve macro inserting in configs (closes #114)
1 parent 60aa6cb commit be36c06

File tree

5 files changed

+88
-79
lines changed

5 files changed

+88
-79
lines changed

Interop/ConfigControl.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public static Config[] Load()
138138
FTPUser = _FTPUser,
139139
FTPPassword = _FTPPW,
140140
FTPDir = _FTPDir,
141-
RConUseSourceEngine = _RConEngineTypeSource,
142141
RConIP = _RConIP,
143142
RConPort = _RConPort,
144143
RConPassword = _RConPassword,

UI/Windows/ConfigWindow.xaml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
Style="{StaticResource SearchMetroTextBox}"
6262
controls:TextBoxHelper.ButtonCommand="{Binding TextBoxButtonFileCmd, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
6363
<TextBox Name="C_ServerArgs" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,186,5,0" TextChanged="C_ServerArgs_TextChanged" />
64-
<TextBox Name="C_PreBuildCmd" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="5,246,5,0" Height="80" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextChanged="C_PreBuildCmd_TextChanged" />
65-
<TextBox Name="C_PostBuildCmd" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="5,351,5,0" Height="80" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextChanged="C_PostBuildCmd_TextChanged" />
64+
<TextBox Name="C_PreBuildCmd" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="5,246,5,0" Height="80" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextChanged="C_PreBuildCmd_TextChanged" GotFocus="BuildCommandsBoxes_OnFocus" />
65+
<TextBox Name="C_PostBuildCmd" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="5,351,5,0" Height="80" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextChanged="C_PostBuildCmd_TextChanged" GotFocus="BuildCommandsBoxes_OnFocus" />
6666
<Slider Name="C_OptimizationLevel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="195,436,0,0" Width="75" Minimum="0" Maximum="2" TickFrequency="2" IsSnapToTickEnabled="True" TickPlacement="BottomRight" AutoToolTipPlacement="TopLeft" ValueChanged="C_OptimizationLevel_ValueChanged" />
6767
<Slider Name="C_VerboseLevel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="195,466,0,0" Width="75" Minimum="0" Maximum="2" TickFrequency="1" IsSnapToTickEnabled="True" TickPlacement="BottomRight" AutoToolTipPlacement="TopLeft" ValueChanged="C_VerboseLevel_ValueChanged" />
6868
<TextBlock Name="FTPHostBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,501,0,0" Text="FTP Host:" IsHitTestVisible="False" />
@@ -73,32 +73,20 @@
7373
<TextBox Name="C_FTPUser" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,526,5,0" TextChanged="C_FTPUser_TextChanged" />
7474
<PasswordBox Name="C_FTPPW" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,556,5,0" PasswordChanged="C_FTPPW_TextChanged" />
7575
<TextBox Name="C_FTPDir" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,586,5,0" TextChanged="C_FTPDir_TextChanged" />
76-
<ComboBox Name="CMD_ItemC" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,216,5,0" Text="Commandline variables" Width="200" SelectedIndex="0">
77-
<ComboBoxItem Name="ItemC_EditorDir" Content="{}{editordir} - Directory of the SPEdit binary" />
78-
<ComboBoxItem Name="ItemC_ScriptDir" Content="{}{scriptdir} - Directory of the Compiling script" />
79-
<ComboBoxItem Name="ItemC_CopyDir" Content="{}{copydir} - Directory where the smx should be copied" />
80-
<ComboBoxItem Name="ItemC_ScriptFile" Content="{}{scriptfile} - Full Directory and Name of the script" />
81-
<ComboBoxItem Name="ItemC_ScriptName" Content="{}{scriptname} - File Name of the script" />
82-
<ComboBoxItem Name="ItemC_PluginFile" Content="{}{pluginfile} - Full Directory and Name of the compiled script" />
83-
<ComboBoxItem Name="ItemC_PluginName" Content="{}{pluginname} - File Name of the compiled script" />
76+
<ComboBox Name="CMD_ItemC" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,216,5,0" Width="200" SelectedIndex="0">
77+
<ComboBoxItem Visibility="Collapsed">Macros</ComboBoxItem>
8478
</ComboBox>
85-
<TextBlock Name="RConEngineBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,636,0,0" Text="RCon Server Engine:" IsHitTestVisible="False" />
8679
<TextBlock Name="RConIPBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,666,0,0" Text="RCon Server IP:" IsHitTestVisible="False" />
8780
<TextBlock Name="RConPortBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,696,0,0" Text="RCon Server Port:" IsHitTestVisible="False" />
8881
<TextBlock Name="RConPWBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,726,0,0" Text="RCon Password:" IsHitTestVisible="False" />
8982
<TextBlock Name="RConComBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,756,0,0" Text="RCon Commands:" IsHitTestVisible="False" />
90-
<ComboBox Name="C_RConEngine" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,631,5,0" SelectionChanged="C_RConEngine_Changed">
91-
<ComboBoxItem Content="Source Engine" IsSelected="True" />
92-
<ComboBoxItem Content="Gold Source Engine" />
93-
</ComboBox>
9483
<TextBox Name="C_RConIP" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,661,5,0" TextChanged="C_RConIP_TextChanged" />
9584
<TextBox Name="C_RConPort" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,691,5,0" TextChanged="C_RConPort_TextChanged" />
9685
<PasswordBox Name="C_RConPW" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="195,721,5,0" PasswordChanged="C_RConPW_TextChanged" />
97-
<ComboBox Name="Rcon_MenuC" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,751,5,0" Text="Rcon commandline variables" Width="200" SelectedIndex="0">
98-
<ComboBoxItem Name="MenuC_PluginsReload" Content="{}{plugins_reload} - Reloads all compiled plugins" />
99-
<ComboBoxItem Name="MenuC_PluginsLoad" Content="{}{plugins_load} - Loads all compiled plugins" />
100-
<ComboBoxItem Name="MenuC_PluginsUnload" Content="{}{plugins_unload} - Unloads all compiled plugins" />
86+
<ComboBox Name="Rcon_MenuC" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,751,5,0" Width="200" SelectedIndex="0">
87+
<ComboBoxItem Visibility="Collapsed">Macros</ComboBoxItem>
10188
</ComboBox>
89+
10290
<TextBox Name="C_RConCmds" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="5,781,5,0" Height="80" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextChanged="C_RConCmds_TextChanged" />
10391
<Rectangle Fill="#FFCCCCCC" HorizontalAlignment="Left" Height="93" Margin="195,30,0,0" Stroke="#FFCCCCCC" VerticalAlignment="Top" Width="668"/>
10492
<ListBox x:Name="C_SMDir" Height="91" Margin="196,31,6,0" VerticalAlignment="Top" SelectionMode="Extended"/>

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

UI/Windows/OptionsWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<ComboBox Name="AccentColor" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="425,5,0,0" Width="200" SelectionChanged="AccentColor_Changed" />
5252
<Label Name="LanguageLabel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="333,37,0,0" Content="Language:" />
5353
<ComboBox Name="LanguageBox" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="425,37,0,0" Width="200" SelectionChanged="LanguageBox_Changed" />
54-
<Label Name="ActionOnCloseLabel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="333,72,0,0" Content="On close:" />
55-
<ComboBox Name="ActionOnCloseBox" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="425,72,0,0" Width="200" SelectionChanged="ActionOnCloseBox_Changed" />
54+
<Label Name="ActionOnCloseLabel" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="333,69,0,0" Content="On close:" />
55+
<ComboBox Name="ActionOnCloseBox" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="425,69,0,0" Width="200" SelectionChanged="ActionOnCloseBox_Changed" />
5656
</Grid>
5757
</ScrollViewer>
5858
</controls:MetroTabItem>

Utils/Models/Config.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
54
using SourcepawnCondenser.SourcemodDefinition;
6-
using SPCode.Interop;
75

86
namespace SPCode.Utils
97
{
@@ -12,30 +10,20 @@ public class Config
1210
public bool AutoCopy;
1311
public bool AutoUpload;
1412
public bool AutoRCON;
15-
1613
public string CopyDirectory = string.Empty;
17-
1814
public bool DeleteAfterCopy;
1915
public string FTPDir = string.Empty;
20-
2116
public string FTPHost = "ftp://localhost/";
22-
23-
// securestring? No! Because it's saved in plaintext and if you want to keep it a secret, you shouldn't automatically upload it anyways...
2417
public string FTPPassword = string.Empty;
25-
2618
public string FTPUser = string.Empty;
2719
public string Name = string.Empty;
28-
2920
public int OptimizeLevel = 2;
30-
3121
public string PostCmd = string.Empty;
3222
public string PreCmd = string.Empty;
3323
public string RConCommands = string.Empty;
3424
public string RConIP = "127.0.0.1";
3525
public string RConPassword = string.Empty;
3626
public ushort RConPort = 27015;
37-
38-
public bool RConUseSourceEngine = true;
3927
public string ServerArgs = string.Empty;
4028
public string ServerFile = string.Empty;
4129

0 commit comments

Comments
 (0)