Skip to content

Commit

Permalink
Make ToolkitToSpaceConverter more flexible.
Browse files Browse the repository at this point in the history
  • Loading branch information
num0005 committed Jun 25, 2024
1 parent 3193e58 commit bdb9b19
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 127 deletions.
21 changes: 11 additions & 10 deletions Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<local:ProfiletoVisibility x:Key="ProfiletoVisibility" />
<local:ProfiletoVisibilityMulti x:Key="ProfiletoVisibilityMulti" />
<local:ProfiletoIsEnabled x:Key="ProfiletoIsEnabled" />
<local:ForceBooleanConverter x:Key="ForceBooleanConverter" />
<local:ProfiletoContent x:Key="ProfiletoContent" />
<local:LightmapConfigModifier x:Key="LightmapConfigModifier" />
<ObjectDataProvider x:Key="cache_type_enum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
Expand Down Expand Up @@ -71,9 +72,9 @@
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Content="Run Sapien" Click="RunSapien" Padding="4" HorizontalAlignment="Left" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=6, ElementName=toolkit_selection}" ToolTip="Start a new instance of Sapien (the world editor)."/>
<Button Grid.Column="1" Grid.Row="0" Content="Run Game" Click="RunGame" Padding="4" HorizontalAlignment="Center" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=7, ElementName=toolkit_selection}" ToolTip="Start the game (only works if game path is set)."/>
<Button Grid.Column="2" Grid.Row="0" Content="{Binding SelectedIndex, Converter={StaticResource ProfiletoContent}, ConverterParameter=11, ElementName=toolkit_selection}" Click="RunGuerilla" Padding="4" HorizontalAlignment="Right" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=5, ElementName=toolkit_selection}" ToolTip="{Binding SelectedIndex, Converter={StaticResource ProfiletoContent}, ConverterParameter=12, ElementName=toolkit_selection}"/>
<Button Grid.Column="0" Grid.Row="0" Content="Run Sapien" Click="RunSapien" Padding="4" HorizontalAlignment="Left" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=HasSapien, ElementName=toolkit_selection}" ToolTip="Start a new instance of Sapien (the world editor)."/>
<Button Grid.Column="1" Grid.Row="0" Content="Run Game" Click="RunGame" Padding="4" HorizontalAlignment="Center" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=HasStandalone, ElementName=toolkit_selection}" ToolTip="Start the game (only works if game path is set)."/>
<Button Grid.Column="2" Grid.Row="0" Content="{Binding SelectedIndex, Converter={StaticResource ProfiletoContent}, ConverterParameter=11, ElementName=toolkit_selection}" Click="RunGuerilla" Padding="4" HorizontalAlignment="Right" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=HasGuerilla, ElementName=toolkit_selection}" ToolTip="{Binding SelectedIndex, Converter={StaticResource ProfiletoContent}, ConverterParameter=12, ElementName=toolkit_selection}"/>
<Button Grid.Column="0" Grid.Row="2" x:Name="run_cmd" Content="Open CMD in Toolkit folder" Click="run_cmd_Click" Padding="4" HorizontalAlignment="Left" ToolTip="Open the command line in the base folder of the current toolkit."/>
<Button Grid.Column="1" Grid.Row="2" x:Name="open_explorer" Content="Open Toolkit Folder" Padding="4" HorizontalAlignment="Center" Click="open_explorer_Click" ToolTip="Open toolkit base folder in File Explorer."/>
<Grid Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right">
Expand Down Expand Up @@ -164,7 +165,7 @@
<Hyperlink FontStyle="Italic" TextDecorations="{x:Null}" FontSize="10" NavigateUri="lighting">help</Hyperlink>
</TextBlock>
</GroupBox.Header>
<Grid IsEnabled="{Binding IsChecked, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=11, ElementName=CompileOnly}">
<Grid IsEnabled="{Binding IsChecked, Converter={StaticResource ForceBooleanConverter}, ElementName=CompileOnly}">
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
Expand Down Expand Up @@ -281,7 +282,7 @@
<GroupBox.BindingGroup>
<BindingGroup/>
</GroupBox.BindingGroup>
<Grid IsEnabled="{Binding IsChecked, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=11, ElementName=CompileOnly}">
<Grid IsEnabled="{Binding IsChecked, Converter={StaticResource ForceBooleanConverter}, ElementName=CompileOnly}">
<TextBox Name="instance_value" BorderBrush="{StaticResource brushWatermarkBorder}" VerticalAlignment="Center" TextWrapping="Wrap" Background="{DynamicResource brushTextboxBackground}" Foreground="{DynamicResource TextColor}" Text="1" MaxLines="1" MaxLength="4" PreviewKeyDown="spaces_PreviewKeyDown" PreviewTextInput="numbers_only" HorizontalAlignment="Center" MinWidth="48" MinHeight="24" CaretBrush="{DynamicResource TextColor}" ToolTip="How many processes will be used for lightmapping?"/>
</Grid>
</GroupBox>
Expand Down Expand Up @@ -546,9 +547,9 @@
</Grid>
</Grid>
</TabItem>
<TabItem Header="Import Model" Margin="-2,6,0,-6" Height="24" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=9, ElementName=toolkit_selection}">
<TabItem Header="Import Model" Margin="-2,6,0,-6" Height="24" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=h1 + h2|h2codez + h2|mcc + h3 + hr, ElementName=toolkit_selection}">
<Grid Background="{DynamicResource WindowSecondaryColor}">
<Grid IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=9, ElementName=toolkit_selection}">
<Grid IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=h1 + h2|h2codez + h2|mcc + h3 + hr, ElementName=toolkit_selection}">
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
Expand Down Expand Up @@ -736,8 +737,8 @@
</Grid>
</Grid>
</TabItem>
<TabItem Header="Import Sound" Margin="-2,6,0,-10" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=9, ElementName=toolkit_selection}">
<Grid Background="{DynamicResource WindowSecondaryColor}" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=9, ElementName=toolkit_selection}">
<TabItem Header="Import Sound" Margin="-2,6,0,-10" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=h1 + h2|h2codez + h2|mcc + h3 + hr, ElementName=toolkit_selection}">
<Grid Background="{DynamicResource WindowSecondaryColor}" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=h1 + h2|h2codez + h2|mcc + h3 + hr, ElementName=toolkit_selection}">
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
Expand Down Expand Up @@ -950,7 +951,7 @@
</Grid>
</Grid>
</TabItem>
<TabItem Header="Import Sidecar" Margin="-2,14,0,-17" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=12, ElementName=toolkit_selection}">
<TabItem Header="Import Sidecar" Margin="-2,14,0,-17" IsEnabled="{Binding SelectedIndex, Converter={StaticResource ProfiletoIsEnabled}, ConverterParameter=hr + h4, ElementName=toolkit_selection}">
<Grid Background="{DynamicResource WindowSecondaryColor}">
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
Expand Down
217 changes: 100 additions & 117 deletions Launcher/UIHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,24 @@ public enum TogglesUI
{
None = 0,

// game type
H1 = 1 << 0,
H2 = 1 << 2,
H3 = 1 << 3,
HR = 1 << 4,
H4 = 1 << 5,

// what sort of toolkit is this?
MCC = 1 << 6,
H2Codez = 1 << 7,
CommunityBuild = 1 << 8,
LegacyStock = 1 << 9,

// what tools do we have?
HasTool = 1 << 10,
HasSapien = 1 << 11,
HasGuerilla = 1 << 12,
HasStandalone = 1 << 13,

}

Expand Down Expand Up @@ -195,44 +205,9 @@ static public List<string> ParseBindingList(string input)

return elements;
}
}

public class BooleanToSpaceConverter : OneWayValueConverter
{
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
static public bool IsAnyInEnableListValid(IEnumerable<TogglesUI> enable_for)
{
if (value is true)
return new GridLength(8);
else
return new GridLength(0);
}
}

public class ToolkitToSpaceConverter : OneWayValueConverter
{
private GridLength ParseGridConfig(string input)
{
Debug.Assert(input != null);
input = input.Trim();
if (input == "star")
return new GridLength(1, GridUnitType.Star);
else if (input == "auto")
return new GridLength(1, GridUnitType.Auto);
else
{
_ = int.TryParse(input, out int intger_size);

return new GridLength(intger_size);
}
}
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (parameter == null)
return new GridLength(0);

List<string> config = BindingToolkitParser.ParseBindingList(parameter as string);
List<TogglesUI> enable_for = BindingToolkitParser.ParseMultiFlagSet(config[0]);

bool enable;
if (MainWindow.profile_mapping.Count > 0)
{
Expand All @@ -241,7 +216,7 @@ public override object Convert(object value, Type targetType, object parameter,
foreach (TogglesUI toggle in enable_for)
{
bool valid_toggle = true;

if (toggle.HasFlag(TogglesUI.H1) && !MainWindow.halo_ce)
{
valid_toggle = false;
Expand All @@ -267,6 +242,36 @@ public override object Convert(object value, Type targetType, object parameter,
valid_toggle = false;
}

if (toggle.HasFlag(TogglesUI.CommunityBuild) && !MainWindow.halo_community)
{
valid_toggle = false;
}

if (toggle.HasFlag(TogglesUI.LegacyStock) && (MainWindow.halo_mcc || MainWindow.halo_community))
{
valid_toggle = false;
}

if (toggle.HasFlag(TogglesUI.HasTool) && string.IsNullOrEmpty(MainWindow.toolkit_profile.ToolPath))
{
valid_toggle = false;
}

if (toggle.HasFlag(TogglesUI.HasGuerilla) && string.IsNullOrEmpty(MainWindow.toolkit_profile.GuerillaPath))
{
valid_toggle = false;
}

if (toggle.HasFlag(TogglesUI.HasSapien) && string.IsNullOrEmpty(MainWindow.toolkit_profile.SapienPath))
{
valid_toggle = false;
}

if (toggle.HasFlag(TogglesUI.HasStandalone) && string.IsNullOrEmpty(MainWindow.toolkit_profile.GameExePath))
{
valid_toggle = false;
}

if (valid_toggle)
{
enable = true;
Expand All @@ -280,6 +285,59 @@ public override object Convert(object value, Type targetType, object parameter,
enable = true;
}

return enable;
}
}

public class BooleanToSpaceConverter : OneWayValueConverter
{
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is true)
return new GridLength(8);
else
return new GridLength(0);
}
}

public class ForceBooleanConverter : OneWayValueConverter
{
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is true)
return true;
else
return false;
}
}

public class ToolkitToSpaceConverter : OneWayValueConverter
{
private GridLength ParseGridConfig(string input)
{
Debug.Assert(input != null);
input = input.Trim();
if (input == "star")
return new GridLength(1, GridUnitType.Star);
else if (input == "auto")
return new GridLength(1, GridUnitType.Auto);
else
{
_ = int.TryParse(input, out int intger_size);

return new GridLength(intger_size);
}
}
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (parameter == null)
return new GridLength(0);

List<string> config = BindingToolkitParser.ParseBindingList(parameter as string);
List<TogglesUI> enable_for = BindingToolkitParser.ParseMultiFlagSet(config[0]);

bool enable = IsAnyInEnableListValid(enable_for);

if (enable)
{
return ParseGridConfig(config[1]);
Expand Down Expand Up @@ -491,86 +549,11 @@ public class ProfiletoIsEnabled : OneWayValueConverter
{
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var is_enabled = false;
if (ToolkitProfiles.SettingsList.Count > 0)
{
if (parameter is string && Int32.Parse(parameter as string) == 0)
{
if (MainWindow.halo_ce)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 1)
{
if (MainWindow.halo_2)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 2)
{
if (MainWindow.halo_2_standalone_stock)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 3)
{
if (MainWindow.halo_3)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 4)
{
//Tool
if (!string.IsNullOrEmpty(MainWindow.toolkit_profile.ToolPath))
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 5)
{
//Guerilla
if (!string.IsNullOrEmpty(MainWindow.toolkit_profile.GuerillaPath))
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 6)
{
//Sapien
if (!string.IsNullOrEmpty(MainWindow.toolkit_profile.SapienPath))
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 7)
{
//Game
if (!string.IsNullOrEmpty(MainWindow.toolkit_profile.GameExePath))
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 8)
{
if (!MainWindow.halo_ce)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 9)
{
if (!MainWindow.halo_2_standalone_stock && !MainWindow.halo_4)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 10)
{
if (!MainWindow.halo_2_standalone_stock && !MainWindow.halo_3)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 11)
{
bool is_level_import = (bool)value;
if (!is_level_import)
is_enabled = true;
}
else if (parameter is string && Int32.Parse(parameter as string) == 12)
{
if (MainWindow.halo_reach || MainWindow.halo_4)
is_enabled = true;
}
}
else
{
//Either we're in desinger or there are no profiles. Reveal ourselves either way.
is_enabled = true;
}
return is_enabled;
List<TogglesUI> enable_for = BindingToolkitParser.ParseMultiFlagSet(parameter as string);

bool enable = IsAnyInEnableListValid(enable_for);

return enable;
}
}

Expand Down

1 comment on commit bdb9b19

@num0005
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProfiletoIsEnabled:

0 = h1
1 = h2
2 = h2|LegacyStock
3 = h3
4 = HasTool
5 = HasGuerilla
6 = HasSapien
7 = HasStandalone
8 = h2 + h3 + hr + h4
9 = h1 + h2|h2codez + h2|mcc + h3 + hr
10 = h1 + h2|h2codez + h2|mcc + h4 + hr
11 = value cast to bool, use a new binding for this todo
12 = hr + h4

Please sign in to comment.