Skip to content

Commit 90a1086

Browse files
committed
Settings tab: make background focusable (so can click focus away from textbox), New project: lock project name if creating new project from context menu (since it takes folder name), fix project creation inside current folder (instead of creating new project there), rename init method to: "executeMethod UnityLauncherProTools.InitializeProject.Init", Settings: save custom init script values and toggle
1 parent 3bce557 commit 90a1086

File tree

8 files changed

+88
-12
lines changed

8 files changed

+88
-12
lines changed

UnityLauncherPro/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
</ArrayOfString>
114114
</value>
115115
</setting>
116+
<setting name="customInitFile" serializeAs="String">
117+
<value>InitializeProject.cs</value>
118+
</setting>
119+
<setting name="useInitScript" serializeAs="String">
120+
<value>False</value>
121+
</setting>
116122
</UnityLauncherPro.Properties.Settings>
117123
</userSettings>
118124
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:System="clr-namespace:System;assembly=mscorlib"
88
xmlns:converters="clr-namespace:UnityLauncherPro.Converters" x:Class="UnityLauncherPro.MainWindow"
99
mc:Ignorable="d"
10-
Title="UnityLauncherPro" Height="650" Width="880" WindowStartupLocation="CenterScreen" Background="{DynamicResource ThemeDarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" Icon="Images/icon.ico" SourceInitialized="Window_SourceInitialized">
10+
Title="UnityLauncherPro" Height="650" Width="880" WindowStartupLocation="CenterScreen" Background="{DynamicResource ThemeDarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" Closing="Window_Closing" SizeChanged="Window_SizeChanged" Icon="Images/icon.ico" SourceInitialized="Window_SourceInitialized" MouseDown="Window_MouseDown">
1111
<Window.Resources>
1212

1313
<converters:LastModifiedConverter x:Key="lastModifiedConverter"/>
@@ -1036,7 +1036,7 @@
10361036

10371037
<!-- Tab: Settings -->
10381038
<TabItem Header="Settings" Style="{DynamicResource TabItemStyle1}" Padding="0,0,0,0" Margin="-1,1,1,-1" BorderBrush="{x:Null}" Background="Black">
1039-
<Grid>
1039+
<Grid x:Name="gridSettingsBg" Focusable="True">
10401040
<Grid.RowDefinitions>
10411041
<!-- top labels-->
10421042
<RowDefinition Height="28" />
@@ -1141,9 +1141,9 @@
11411141
</StackPanel>
11421142

11431143
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
1144-
<CheckBox x:Name="chkUseInitScript" Content="Use Init script for new projects" ToolTip="..." HorizontalAlignment="Left"/>
1144+
<CheckBox x:Name="chkUseInitScript" Content="Use Init script for new projects" ToolTip="..." HorizontalAlignment="Left" Checked="chkUseInitScript_Checked" Unchecked="chkUseInitScript_Checked"/>
11451145
<!--<Label Content="Init script for new projects" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" />-->
1146-
<TextBox x:Name="txtCustomInitFile" BorderBrush="Transparent" MinWidth="128" ToolTip="Default is InitProject.cs" Padding="0,3,0,0" Margin="5,0,0,0" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" Text="InitProject.cs" PreviewKeyDown="TxtCustomThemeFile_PreviewKeyDown" />
1146+
<TextBox x:Name="txtCustomInitFile" BorderBrush="Transparent" MinWidth="128" ToolTip="Default is InitProject.cs" Padding="0,3,0,0" Margin="5,0,0,0" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" Text="InitializeProject.cs" PreviewKeyDown="txtCustomInitFile_PreviewKeyDown" LostFocus="txtCustomInitFile_LostFocus" />
11471147
<Button Style="{StaticResource CustomButton}" ToolTip="Explore Scripts folder" x:Name="btnExploreScriptsFolder" Content="..." Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="btnExploreScriptsFolder_Click" Margin="5,0,0,0"/>
11481148
</StackPanel>
11491149

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ void LoadSettings()
440440
txtShortcutBatchFileFolder.Text = Properties.Settings.Default.shortcutBatchFileFolder;
441441
}
442442

443+
chkUseInitScript.IsChecked = Properties.Settings.Default.useInitScript;
444+
txtCustomInitFile.Text = Properties.Settings.Default.customInitFile;
445+
443446
} // LoadSettings()
444447

445448

@@ -1600,9 +1603,12 @@ void CreateNewEmptyProject(string targetFolder = null)
16001603
string rootFolder = txtRootFolderForNewProjects.Text;
16011604

16021605
// if have targetfolder, then use that instead of quick folder
1603-
if (targetFolder != null && Directory.Exists(targetFolder))
1606+
if (targetFolder != null)
16041607
{
1605-
rootFolder = targetFolder;
1608+
if (Directory.Exists(targetFolder))
1609+
{
1610+
rootFolder = Directory.GetParent(targetFolder).FullName;
1611+
}
16061612
}
16071613
else
16081614
{
@@ -1619,7 +1625,6 @@ void CreateNewEmptyProject(string targetFolder = null)
16191625
// for new projects created from explorer, always ask for name
16201626
if (chkAskNameForQuickProject.IsChecked == true || targetFolder != null)
16211627
{
1622-
// ask name
16231628
string newVersion = null;
16241629

16251630
// if in maintab
@@ -1638,7 +1643,8 @@ void CreateNewEmptyProject(string targetFolder = null)
16381643
return;
16391644
}
16401645

1641-
NewProject modalWindow = new NewProject(newVersion, Tools.GetSuggestedProjectName(newVersion, rootFolder), rootFolder);
1646+
var suggestedName = targetFolder != null ? Path.GetFileName(targetFolder) : Tools.GetSuggestedProjectName(newVersion, rootFolder);
1647+
NewProject modalWindow = new NewProject(newVersion, suggestedName, rootFolder, targetFolder != null);
16421648
modalWindow.ShowInTaskbar = this == null;
16431649
modalWindow.WindowStartupLocation = this == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
16441650
modalWindow.Topmost = this == null;
@@ -2759,6 +2765,38 @@ private void btnExploreScriptsFolder_Click(object sender, RoutedEventArgs e)
27592765
Tools.LaunchExplorer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts"));
27602766
}
27612767

2768+
private void txtCustomInitFile_PreviewKeyDown(object sender, KeyEventArgs e)
2769+
{
2770+
switch (e.Key)
2771+
{
2772+
case Key.Return: // pressed enter in theme file text box
2773+
Properties.Settings.Default.customInitFile = txtCustomInitFile.Text;
2774+
Properties.Settings.Default.Save();
2775+
break;
2776+
}
2777+
}
2778+
2779+
private void txtCustomInitFile_LostFocus(object sender, RoutedEventArgs e)
2780+
{
2781+
var s = (TextBox)sender;
2782+
Properties.Settings.Default.customInitFile = s.Text;
2783+
Properties.Settings.Default.Save();
2784+
}
2785+
2786+
private void chkUseInitScript_Checked(object sender, RoutedEventArgs e)
2787+
{
2788+
if (this.IsActive == false) return; // dont run code on window init
2789+
2790+
var isChecked = (bool)((CheckBox)sender).IsChecked;
2791+
Properties.Settings.Default.useInitScript = isChecked;
2792+
Properties.Settings.Default.Save();
2793+
}
2794+
2795+
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
2796+
{
2797+
gridSettingsBg.Focus();
2798+
}
2799+
27622800
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
27632801
//{
27642802
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

UnityLauncherPro/NewProject.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
<ComboBox Grid.Column="2" x:Name="cmbNewProjectTemplate" DisplayMemberPath="Key" SelectedIndex="0" Margin="6,0,0,0" TabIndex="2" DropDownOpened="CmbNewProjectTemplate_DropDownOpened" />
205205
</Grid>
206206

207-
<Label x:Name="lblNewProjectFolder" Content="(folder)" Foreground="{DynamicResource ThemeButtonBackground}" Margin="0" FontSize="10" Padding="5,0,5,3" />
207+
<Label x:Name="lblNewProjectFolder" Content="(folder)" Foreground="{DynamicResource ThemeButtonForegroundDisabled}" Margin="0" FontSize="10" Padding="5,0,5,3" />
208208
<Grid HorizontalAlignment="Stretch" Margin="0,8,0,0">
209209
<Grid.ColumnDefinitions>
210210
<ColumnDefinition Width="*"/>

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class NewProject : Window
1919
int previousSelectedTemplateIndex = -1;
2020
int previousSelectedModuleIndex = -1;
2121

22-
public NewProject(string unityVersion, string suggestedName, string targetFolder)
22+
public NewProject(string unityVersion, string suggestedName, string targetFolder, bool nameIsLocked = false)
2323
{
2424
isInitializing = true;
2525
InitializeComponent();
@@ -28,6 +28,8 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
2828
newVersion = unityVersion;
2929
newName = suggestedName;
3030

31+
txtNewProjectName.IsEnabled = !nameIsLocked;
32+
3133
txtNewProjectName.Text = newName;
3234
lblNewProjectFolder.Content = targetFolder;
3335

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,11 @@
113113
&lt;string&gt;C:\Program Files\&lt;/string&gt;
114114
&lt;/ArrayOfString&gt;</Value>
115115
</Setting>
116+
<Setting Name="customInitFile" Type="System.String" Scope="User">
117+
<Value Profile="(Default)">InitializeProject.cs</Value>
118+
</Setting>
119+
<Setting Name="useInitScript" Type="System.Boolean" Scope="User">
120+
<Value Profile="(Default)">False</Value>
121+
</Setting>
116122
</Settings>
117123
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, b
255255

256256
if (useInitScript == true)
257257
{
258-
unitycommandlineparameters += " -executeMethod UnityLauncherProTools.InitProject.Init";
258+
unitycommandlineparameters += " -executeMethod UnityLauncherProTools.InitializeProject.Init";
259259
}
260260

261261
Console.WriteLine("Start process: " + cmd + " " + unitycommandlineparameters);
@@ -1111,7 +1111,7 @@ public static Project FastCreateProject(string version, string baseFolder, strin
11111111

11121112
var proc = LaunchProject(proj, null, useInitScript);
11131113
ProcessHandler.Add(proj, proc);
1114-
1114+
11151115
return proj;
11161116
} // FastCreateProject
11171117

0 commit comments

Comments
 (0)