Skip to content

Commit

Permalink
Mods are now fully implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
TrinityDevelopers committed Apr 27, 2020
1 parent ff362b6 commit b29799f
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 8 deletions.
92 changes: 92 additions & 0 deletions ZenovaLauncher/Dialogs/EditProfileDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,98 @@
</ComboBox.ItemTemplate>
</ComboBox>
</ui:SimpleStackPanel>
<Expander
x:Name="ModOptionsExpander"
ExpandDirection="Down"
IsExpanded="False"
VerticalAlignment="Top"
Padding="2">
<Expander.Header>
<TextBlock FontSize="15" FontWeight="SemiBold" Typography.Capitals="AllSmallCaps" VerticalAlignment="Center" Text="Mod Options" />
</Expander.Header>
<ui:SimpleStackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="30" Margin="0,15,0,0">
<ui:SimpleStackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="2">
<TextBlock Margin="2,-8,0,0" FontSize="15" FontWeight="SemiBold" Typography.Capitals="AllSmallCaps" Text="Available Mods" />
<Border Background="{DynamicResource LauncherControlTransientBackgroundBrush}" CornerRadius="2" Padding="0,2,0,2">
<ListBox
x:Name="AvailableModsBox"
Background="Transparent"
Height="100"
ItemContainerStyle="{DynamicResource ProfileListBoxItemStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Separator x:Name="Separator" Margin="12,0,12,0" VerticalAlignment="Top" Background="{DynamicResource AppBarSeparatorLowForeground}" />
<Grid Margin="12,3,12,3">
<TextBlock FontSize="14" FontWeight="DemiBold" Text="{Binding Name}" />
<Button x:Name="AddButton" HorizontalAlignment="Right" Padding="2" Visibility="Hidden" Click="AddModClick">
<Button.Content>
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="5">
<TextBlock FontSize="12" Text="Add"/>
<ui:FontIcon Glyph="&#xECC8;" FontSize="12" />
</ui:SimpleStackPanel>
</Button.Content>
</Button>
</Grid>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsMouseOver}" Value="True">
<Setter TargetName="AddButton" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}" Value="True">
<Setter TargetName="AddButton" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
<Setter Property="Visibility" TargetName="Separator" Value="Collapsed"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
</ui:SimpleStackPanel>
<ui:SimpleStackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="2">
<TextBlock Margin="2,-8,0,0" FontSize="15" FontWeight="SemiBold" Typography.Capitals="AllSmallCaps" Text="Loaded Mods" />
<Border Background="{DynamicResource LauncherControlTransientBackgroundBrush}" CornerRadius="2" Padding="0,2,0,2">
<ListBox
x:Name="LoadedModsBox"
Background="Transparent"
Height="100"
ItemContainerStyle="{DynamicResource ProfileListBoxItemStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Separator x:Name="Separator" Margin="12,0,12,0" VerticalAlignment="Top" Background="{DynamicResource AppBarSeparatorLowForeground}" />
<Grid Margin="12,3,12,3">
<TextBlock FontSize="14" FontWeight="DemiBold" Text="{Binding Name}" />
<Button x:Name="RemoveButton" HorizontalAlignment="Right" Padding="2" Visibility="Hidden" Click="RemoveModClick">
<Button.Content>
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="5">
<TextBlock FontSize="12" Text="Remove"/>
<ui:FontIcon Glyph="&#xECC9;" FontSize="12" />
</ui:SimpleStackPanel>
</Button.Content>
</Button>
</Grid>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsMouseOver}" Value="True">
<Setter TargetName="RemoveButton" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}" Value="True">
<Setter TargetName="RemoveButton" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
<Setter Property="Visibility" TargetName="Separator" Value="Collapsed"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</Expander>
</ui:SimpleStackPanel>
</Grid>
</ui:ContentDialog>
63 changes: 61 additions & 2 deletions ZenovaLauncher/Dialogs/EditProfileDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using ModernWpf.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace ZenovaLauncher
{
Expand All @@ -11,6 +14,9 @@ namespace ZenovaLauncher
/// </summary>
public partial class EditProfileDialog : ContentDialog
{
public Profile EditedProfile { get; set; }
public ObservableCollection<Mod> LoadedMods { get; set; }

public EditProfileDialog(Profile profile)
{
InitializeComponent();
Expand All @@ -31,14 +37,67 @@ public EditProfileDialog(Profile profile)
VersionBox.Items.Filter = o => predicates.Any(predicate => predicate(o));
VersionBox.SelectedItem = profile.Version;
VersionBox.IsEnabled = profile.Editable;
AvailableModsBox.ItemsSource = ModManager.instance.ToList();
LoadedMods = profile.ModsList != null ? new ObservableCollection<Mod>(profile.ModsList) : new ObservableCollection<Mod>();
LoadedModsBox.ItemsSource = LoadedMods;
FilterModsList();
ModOptionsExpander.IsEnabled = profile.Editable;
}

public void RefreshMods()
{
AvailableModsBox.Items.Refresh();
LoadedModsBox.Items.Refresh();
}

private void VersionChanged(object sender, SelectionChangedEventArgs e)
{
RemoveUnsupportedMods();
FilterModsList();
RefreshMods();
}

private void AddModClick(object sender, RoutedEventArgs e)
{
LoadedMods.Add((sender as FrameworkElement).DataContext as Mod);
FilterModsList();
RefreshMods();
}

private void RemoveModClick(object sender, RoutedEventArgs e)
{
LoadedMods.Remove((sender as FrameworkElement).DataContext as Mod);
FilterModsList();
RefreshMods();
}

protected void RemoveUnsupportedMods()
{
if (LoadedMods != null)
{
foreach (Mod m in LoadedMods.Where(m => !m.SupportsVersion(VersionBox.SelectedItem as MinecraftVersion)).ToList())
LoadedMods.Remove(m);
}
}

protected void FilterModsList()
{
if (AvailableModsBox != null && LoadedMods != null)
{
List<Predicate<object>> predicates = new List<Predicate<object>>
{
m => (m as Mod).SupportsVersion(VersionBox.SelectedItem as MinecraftVersion),
m => !LoadedMods.Contains(m as Mod)
};
AvailableModsBox.Items.Filter = o => predicates.All(predicate => predicate(o));
}
}

private void SaveProfile(object sender, ContentDialogButtonClickEventArgs e)
{
EditedProfile.Name = ProfileNameBox.Text;
EditedProfile.Version = VersionBox.SelectedItem as MinecraftVersion;
EditedProfile.ModsList = LoadedMods.Count > 0 ? LoadedMods : null;
}

public Profile EditedProfile { get; set; }
}
}
30 changes: 30 additions & 0 deletions ZenovaLauncher/Dialogs/ModDetailsDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<ui:ContentDialog x:Class="ZenovaLauncher.ModDetailsDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZenovaLauncher"
xmlns:ui="http://schemas.modernwpf.com/2019"
mc:Ignorable="d"
Style="{StaticResource LauncherContentDialog}"
HorizontalContentAlignment="Center"
Title="Mod Details"
SecondaryButtonText="Exit"
CloseButtonText="Close">

<Grid>
<ui:SimpleStackPanel VerticalAlignment="Stretch" HorizontalAlignment="Center" Spacing="10" Margin="10" Width="400">
<ui:SimpleStackPanel>
<TextBlock FontWeight="Bold" FontSize="16" Text="{Binding SelectedMod.Name}" />
<TextBlock FontSize="12">
v<Run Text="{Binding SelectedMod.ModVersion, Mode=OneWay}" />
</TextBlock>
<TextBlock FontSize="12">
By <Run Text="{Binding SelectedMod.Author}" />
</TextBlock>
</ui:SimpleStackPanel>
<Separator Background="{DynamicResource AppBarSeparatorLowForeground}" />
<TextBlock x:Name="ModDescription" TextWrapping="Wrap"/>
</ui:SimpleStackPanel>
</Grid>
</ui:ContentDialog>
34 changes: 34 additions & 0 deletions ZenovaLauncher/Dialogs/ModDetailsDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ModernWpf.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ZenovaLauncher
{
/// <summary>
/// Interaction logic for ModDetailsDialog.xaml
/// </summary>
public partial class ModDetailsDialog : ContentDialog
{
public Mod SelectedMod { get; set; }

public ModDetailsDialog(Mod selectedMod)
{
InitializeComponent();
DataContext = this;
SelectedMod = selectedMod;
SelectedMod.SetDescriptionTextBlock(ModDescription);
}
}
}
25 changes: 25 additions & 0 deletions ZenovaLauncher/Mods/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using Newtonsoft.Json;
using System;
using System.IO;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;

namespace ZenovaLauncher
{
public class Mod
{
public string NameId { get; set; }
public string Name { get; set; }
public string Author { get; set; } = "unknown";
public string Description { get; set; }
public string DescriptionFile { get; set; } = null;
public Version Version { get; set; }
public string MinVersion
{
Expand All @@ -27,12 +33,31 @@ public string MaxVersion
public MinecraftVersion MaxMCVersion { get; set; }
[JsonIgnore]
public Version LatestSupported => MaxMCVersion.Version;
[JsonIgnore]
public string ModVersion => Version.ToString();

public bool SupportsVersion(MinecraftVersion version)
{
return version.Version >= MinMCVersion.Version && version.Version <= MaxMCVersion.Version;
}

public void SetDescriptionTextBlock(TextBlock textBlock)
{
if (!string.IsNullOrEmpty(DescriptionFile))
{
string descriptionFilePath = Path.Combine(ModManager.instance.ModsDirectory, ModDirectory, DescriptionFile);
if (File.Exists(descriptionFilePath))
{
textBlock.Inlines.Clear();
textBlock.Inlines.Add(XamlReader.Parse(File.ReadAllText(descriptionFilePath)) as Inline);
}
}
else
{
textBlock.Text = Description;
}
}

public enum ModSortType
{
ByLatestSupported,
Expand Down
10 changes: 8 additions & 2 deletions ZenovaLauncher/Pages/ModsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ private void SortChanged(object sender, SelectionChangedEventArgs e)

private void ModSelected(object sender, MouseButtonEventArgs e)
{

ModDetails((sender as FrameworkElement).DataContext as Mod);
}

private void ModDetailsClick(object sender, RoutedEventArgs e)
{

ModDetails((sender as FrameworkElement).DataContext as Mod);
}

private void DeleteModClick(object sender, RoutedEventArgs e)
Expand All @@ -74,5 +74,11 @@ protected void SortModList(Mod.ModSortType sortType)
ModsListBox.Items.SortDescriptions.Add(sd);
}
}

protected async void ModDetails(Mod mod)
{
ModDetailsDialog modDetails = new ModDetailsDialog(mod);
await modDetails.ShowAsync();
}
}
}
8 changes: 4 additions & 4 deletions ZenovaLauncher/SetupZenovaLauncher.iss
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChang
Root: HKA; Subkey: "{code:GetSubKey}"; \
ValueType: string; ValueName: "ZENOVA_DATA"; ValueData: "{code:GetDataDir}"; \
Flags: uninsdeletevalue
Root: HKCR; Subkey: ".zmp"; ValueData: "{#MyAppName}"; \
Root: HKA; Subkey: "Software\Classes\.zmp"; ValueData: "{#MyAppName}"; \
Flags: uninsdeletevalue; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}"; ValueData: "{#MyAppName}"; \
Root: HKA; Subkey: "Software\Classes\{#MyAppName}"; ValueData: "{#MyAppName}"; \
Flags: uninsdeletekey; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\DefaultIcon"; \
Root: HKA; Subkey: "Software\Classes\{#MyAppName}\DefaultIcon"; \
ValueData: "{app}\{#MyAppExeName},0"; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\shell\open\command"; \
Root: HKA; Subkey: "Software\Classes\{#MyAppName}\shell\open\command"; \
ValueData: """{app}\{#MyAppExeName}"" ""%1"""; ValueType: string; ValueName: ""

[Code]
Expand Down
7 changes: 7 additions & 0 deletions ZenovaLauncher/ZenovaLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<Compile Include="Controls\LauncherSideMenu.cs" />
<Compile Include="Controls\LauncherSideMenuArgs.cs" />
<Compile Include="Controls\LauncherTabControl.cs" />
<Compile Include="Dialogs\ModDetailsDialog.xaml.cs">
<DependentUpon>ModDetailsDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Mods\Mod.cs" />
<Compile Include="Mods\ModManager.cs" />
<Compile Include="Profiles\AccountManager.cs" />
Expand Down Expand Up @@ -115,6 +118,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\ModDetailsDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\HelpPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down

0 comments on commit b29799f

Please sign in to comment.