Skip to content

Commit

Permalink
Added Required Zones Expanded window
Browse files Browse the repository at this point in the history
  • Loading branch information
kruumy committed Mar 12, 2023
1 parent ddf2ff2 commit 4aed362
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 9 deletions.
10 changes: 5 additions & 5 deletions EasyZoneBuilder.Core/DependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public async Task<Dictionary<string, Dictionary<string, AssetType>>> GetAssetsAs
public Dictionary<string, RequiredZonesEntryInfo> GetRequiredZones( ModCSV csv )
{
// Took a lot of inspiration from https://github.com/XLabsProject/iw4-zone-asset-finder/blob/main/iw4-zone-asset-finder/Commands/BuildRequirements.cs
List<KeyValuePair<string, List<string>>> assets_zones = new List<KeyValuePair<string, List<string>>>();
List<KeyValuePair<KeyValuePair<string, AssetType>, List<string>>> assets_zones = new List<KeyValuePair<KeyValuePair<string, AssetType>, List<string>>>();
foreach ( KeyValuePair<string, AssetType> asset in csv )
{
string dependency_graph_assetQuery = $"{asset.Value}:{asset.Key}";
if ( this.TryGetValue(dependency_graph_assetQuery, out List<string> queryResult) )
{
assets_zones.Add(new KeyValuePair<string, List<string>>(asset.Key, queryResult));
assets_zones.Add(new KeyValuePair<KeyValuePair<string, AssetType>, List<string>>(new KeyValuePair<string, AssetType>(asset.Key, asset.Value), queryResult));
}
else
{
Expand All @@ -102,7 +102,7 @@ public Dictionary<string, RequiredZonesEntryInfo> GetRequiredZones( ModCSV csv )
while ( assets_zones.Count > 0 )
{
Dictionary<string, RequiredZonesEntryInfo> zoneScore = new Dictionary<string, RequiredZonesEntryInfo>();
foreach ( KeyValuePair<string, List<string>> asset_zones in assets_zones )
foreach ( KeyValuePair<KeyValuePair<string, AssetType>, List<string>> asset_zones in assets_zones )
{
foreach ( string zone in asset_zones.Value )
{
Expand All @@ -114,7 +114,7 @@ public Dictionary<string, RequiredZonesEntryInfo> GetRequiredZones( ModCSV csv )
{
zoneScore[ zone ].score = 0;
}
zoneScore[ zone ].assets.Add(asset_zones.Key);
zoneScore[ zone ].assets.Add(asset_zones.Key.Key, asset_zones.Key.Value);
zoneScore[ zone ].score++;
}
}
Expand All @@ -129,7 +129,7 @@ public Dictionary<string, RequiredZonesEntryInfo> GetRequiredZones( ModCSV csv )
public class RequiredZonesEntryInfo
{
public int score;
public List<string> assets = new List<string>();
public Dictionary<string, AssetType> assets = new Dictionary<string, AssetType>();
}
public IEnumerable<string> GetZones()
{
Expand Down
10 changes: 10 additions & 0 deletions EasyZoneBuilder.GUI/EasyZoneBuilder.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<Compile Include="NewZone.xaml.cs">
<DependentUpon>NewZone.xaml</DependentUpon>
</Compile>
<Compile Include="RequiredZonesExpanded.xaml.cs">
<DependentUpon>RequiredZonesExpanded.xaml</DependentUpon>
</Compile>
<Compile Include="Zone.xaml.cs">
<DependentUpon>Zone.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -124,6 +127,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="RequiredZonesExpanded.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Zone.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -189,5 +196,8 @@
<ItemGroup>
<Resource Include="Resources\settings.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\open_window.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
16 changes: 15 additions & 1 deletion EasyZoneBuilder.GUI/Mod.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="130"></ColumnDefinition>
<ColumnDefinition Width="35"></ColumnDefinition>
<ColumnDefinition Width="35"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button
x:Name="FindRequiredZonesBtn"
Expand All @@ -98,9 +99,22 @@
VerticalContentAlignment="Center">
</TextBox>
<Button
x:Name="DependencyGraphSettingsBtn"
x:Name="RequiredZonesExpandedBtn"
Grid.Column="2"
Margin="5"
Click="RequiredZonesExpanded_Click">
<StackPanel>
<Image>
<Image.Source>
<BitmapImage UriSource="Resources/open_window.ico" />
</Image.Source>
</Image>
</StackPanel>
</Button>
<Button
x:Name="DependencyGraphSettingsBtn"
Grid.Column="3"
Margin="5"
Click="DependencyGraphSettingsBtn_Click">
<StackPanel>
<Image>
Expand Down
12 changes: 9 additions & 3 deletions EasyZoneBuilder.GUI/Mod.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async void writeFastFileBtn_Click( object sender, RoutedEventArgs e )
}
}

private void DeleteContextMenuItem_Click( object sender, RoutedEventArgs e )
public void DeleteContextMenuItem_Click( object sender, RoutedEventArgs e )
{
if ( selectedMod.SelectedItem is Core.Mod sMod && CsvGrid.SelectedItems.Count > 0 )
{
Expand Down Expand Up @@ -102,15 +102,15 @@ private async void readFastFileContextMenu_Click( object sender, RoutedEventArgs
}
}

private async void FindRequiredZonesBtn_Click( object sender, RoutedEventArgs e )
private void FindRequiredZonesBtn_Click( object sender, RoutedEventArgs e )
{
if ( selectedMod.SelectedItem is Core.Mod sMod )
{
FindRequiredZonesBtn.IsEnabled = false;
object oldContent = FindRequiredZonesBtn.Content;
FindRequiredZonesBtn.Content = "Finding...";
detectedZonesBox.Text = string.Empty;
await DependencyGraph.DefaultInstance.Pull();
//await DependencyGraph.DefaultInstance.Pull();
foreach ( string zone in DependencyGraph.DefaultInstance.GetRequiredZones(sMod.CSV).Keys )
{
detectedZonesBox.Text += zone + ", ";
Expand All @@ -129,5 +129,11 @@ private void DependencyGraphSettingsBtn_Click( object sender, RoutedEventArgs e
DependencyGraphSettings window = new DependencyGraphSettings();
window.ShowDialog();
}

private void RequiredZonesExpanded_Click( object sender, RoutedEventArgs e )
{
RequiredZonesExpanded window = new RequiredZonesExpanded();
window.Show();
}
}
}
61 changes: 61 additions & 0 deletions EasyZoneBuilder.GUI/RequiredZonesExpanded.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Window x:Class="EasyZoneBuilder.GUI.RequiredZonesExpanded"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EasyZoneBuilder.GUI"
mc:Ignorable="d"
Style="{DynamicResource CustomWindowStyle}"
Title="Required Zones" Height="300" Width="450" ResizeMode="CanResizeWithGrip" Icon="/Resources/main.ico" WindowStartupLocation="CenterOwner">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid x:Name="AssetGrid"
Grid.Row="0"
AutoGenerateColumns="False"
SelectionMode="Extended"
Margin="5">
<DataGrid.Columns>
<DataGridTextColumn Header="AssetType"
Binding="{Binding Key.Value}"
Width="75"
IsReadOnly="True" />
<DataGridTextColumn Header="Name"
Binding="{Binding Key.Key}"
Width="*"
IsReadOnly="True" />
<DataGridTextColumn Header="Zone"
Binding="{Binding Value}"
Width="125"
IsReadOnly="True" />


</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete"
x:Name="DeleteContextMenuItem"
Click="DeleteContextMenuItem_Click">
<MenuItem.Icon>
<Image>
<Image.Source>
<BitmapImage UriSource="Resources/trash.ico" />
</Image.Source>
</Image>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>
<Button
x:Name="FindRequiredZonesBtn"
Grid.Row="1"
Margin="5"
Content="Find Required Zones"
Click="FindRequiredZonesBtn_Click">

</Button>
</Grid>
</Window>
69 changes: 69 additions & 0 deletions EasyZoneBuilder.GUI/RequiredZonesExpanded.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using EasyZoneBuilder.Core;
using System.Collections.Generic;
using System.Windows;

namespace EasyZoneBuilder.GUI
{
/// <summary>
/// Interaction logic for RequiredZonesExpanded.xaml
/// </summary>
public partial class RequiredZonesExpanded : Window
{
public RequiredZonesExpanded()
{
InitializeComponent();
}

private async void FindRequiredZonesBtn_Click( object sender, RoutedEventArgs e )
{
if ( Mod.Instance.selectedMod.SelectedItem is Core.Mod sMod )
{
FindRequiredZonesBtn.IsEnabled = false;
object oldContent = FindRequiredZonesBtn.Content;
FindRequiredZonesBtn.Content = "Finding...";
await DependencyGraph.DefaultInstance.Pull();
RefreshAssetGrid();
FindRequiredZonesBtn.Content = oldContent;
FindRequiredZonesBtn.IsEnabled = true;
}
}

private void RefreshAssetGrid()
{
if ( Mod.Instance.selectedMod.SelectedItem is Core.Mod sMod )
{
Dictionary<string, DependencyGraph.RequiredZonesEntryInfo> reqZones = DependencyGraph.DefaultInstance.GetRequiredZones(sMod.CSV);
AssetGrid.ItemsSource = ConvertToNewDictionary(reqZones);
}
}

private Dictionary<KeyValuePair<string, AssetType>, string> ConvertToNewDictionary( Dictionary<string, DependencyGraph.RequiredZonesEntryInfo> originalDict )
{
Dictionary<KeyValuePair<string, AssetType>, string> newDict = new Dictionary<KeyValuePair<string, AssetType>, string>();

foreach ( KeyValuePair<string, DependencyGraph.RequiredZonesEntryInfo> kvp in originalDict )
{
foreach ( KeyValuePair<string, AssetType> asset in kvp.Value.assets )
{
newDict.Add(asset, kvp.Key);
}
}
return newDict;
}


private void DeleteContextMenuItem_Click( object sender, RoutedEventArgs e )
{
if ( Mod.Instance.selectedMod.SelectedItem is Core.Mod sMod && AssetGrid.SelectedItems.Count > 0 )
{
foreach ( object item in AssetGrid.SelectedItems )
{
sMod.CSV.Remove(((KeyValuePair<KeyValuePair<string, AssetType>, string>)item).Key.Key);
}
sMod.CSV.Push();
Mod.Instance.ReadModCsvBtn_Click(sender, e);
RefreshAssetGrid();
}
}
}
}
Binary file added EasyZoneBuilder.GUI/Resources/open_window.ico
Binary file not shown.

0 comments on commit 4aed362

Please sign in to comment.