Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Drommedhar committed Oct 6, 2024
1 parent 4d96c32 commit 4658308
Show file tree
Hide file tree
Showing 94 changed files with 3,006 additions and 1,731 deletions.
213 changes: 210 additions & 3 deletions DlssUpdater/App.xaml

Large diffs are not rendered by default.

50 changes: 22 additions & 28 deletions DlssUpdater/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
using DlssUpdater.Services;
using DlssUpdater.Singletons;
using DlssUpdater.Singletons.AntiCheatChecker;
using DlssUpdater.ViewModels.Pages;
using DlssUpdater.ViewModels.Windows;
using DlssUpdater.Views.Pages;
using DlssUpdater.Views.Windows;
using DlssUpdater.Windows.Splashscreen;
using DLSSUpdater.Defines.UI.Pages;
using DLSSUpdater.Singletons;
using DLSSUpdater.ViewModels.Pages;
using DLSSUpdater.ViewModels.Windows;
using DLSSUpdater.Views.Pages;
using DLSSUpdater.Views.Windows;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Wpf.Ui;
using WpfBindingErrors;

namespace DlssUpdater;
Expand All @@ -36,31 +37,18 @@ public partial class App
{
services.AddHostedService<ApplicationHostService>();

// Page resolver service
services.AddSingleton<IPageService, PageService>();

// Theme manipulation
services.AddSingleton<IThemeService, ThemeService>();

// TaskBar manipulation
services.AddSingleton<ITaskBarService, TaskBarService>();


// Service containing navigation, same as INavigationWindow... but without window
services.AddSingleton<INavigationService, NavigationService>();
// Windows
services.AddSingleton<Splashscreen>();
services.AddSingleton<MainWindow>();

// Main window with navigation
// ViewModel
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<MainWindow>();
services.AddSingleton<Splashscreen>();
services.AddSingleton<GamesPage>();
services.AddSingleton<GamesViewModel>();
services.AddSingleton<DLSSPage>();
services.AddSingleton<DLSSViewModel>();
services.AddSingleton<SettingsPage>();
services.AddSingleton<SettingsViewModel>();
services.AddSingleton<ChangelogPage>();
services.AddSingleton<ChangelogViewModel>();
services.AddSingleton<DlssPageViewModel>();
services.AddSingleton<GamePageViewModel>();
services.AddSingleton<GameConfigWindowViewModel>();
services.AddSingleton<SettingsCommonPageViewModel>();
services.AddSingleton<ChangelogPageViewModel>();

services.AddSingleton(NLog.LogManager.GetCurrentClassLogger());

services.AddSingleton<Settings>();
Expand All @@ -70,7 +58,13 @@ public partial class App
services.AddSingleton<VersionUpdater>();
services.AddSingleton<AsyncFileWatcher>();

services.AddSingleton<ISnackbarService, SnackbarService>();
// Pages
services.AddSingleton<LibraryPage>();
services.AddSingleton<DLSSPage>();
services.AddSingleton<SettingsPage>();
services.AddSingleton<ChangelogPage>();
services.AddSingleton<DlssPageControl>();
services.AddSingleton<GamePageControl>();
}).Build();

/// <summary>
Expand Down
31 changes: 31 additions & 0 deletions DlssUpdater/Controls/ChangelogPanel.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<UserControl x:Class="DLSSUpdater.Controls.ChangelogPanel"
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:DLSSUpdater.Controls"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" x:Name="ctrlChangelog" Loaded="ctrlChangelog_Loaded" SizeChanged="ctrlChangelog_SizeChanged">
<Grid>
<GroupBox Margin="5,0,0,-16" Background="#FF1d263c"
adonisExtensions:GroupBoxExtension.HeaderBackground="#FF0e141b">
<GroupBox.Header>
<Grid>
<Label Content="{Binding HeaderText, ElementName=ctrlChangelog}" FontWeight="Bold" FontSize="16" />
<Button
BorderBrush="{x:Null}"
adonisExtensions:CursorSpotlightExtension.BackgroundBrush="#0AFFFFFF"
adonisExtensions:CursorSpotlightExtension.BorderBrush="#0FFFFFFF"
adonisExtensions:CursorSpotlightExtension.RelativeSpotlightSize="10000.0"
adonisExtensions:RippleExtension.BackgroundBrush="#0AFFFFFF"
adonisExtensions:RippleExtension.BorderBrush="#14FFFFFF"
Background="Transparent" Margin="-10,-10,-10,-8" Click="Button_Click" />
</Grid>
</GroupBox.Header>
<StackPanel Name="TextBlockContainer" Orientation="Vertical" Margin="10,-6,10,10" Visibility="{Binding Expanded, ElementName=ctrlChangelog}" IsHitTestVisible="False"/>
</GroupBox>
</Grid>
</UserControl>
157 changes: 157 additions & 0 deletions DlssUpdater/Controls/ChangelogPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using static DlssUpdater.Defines.DlssTypes;

namespace DLSSUpdater.Controls
{
/// <summary>
/// Interaction logic for ChangelogPanel.xaml
/// </summary>
public partial class ChangelogPanel : UserControl
{
public static readonly DependencyProperty HeaderTextProperty =
DependencyProperty.Register("HeaderText", typeof(string), typeof(ChangelogPanel));

public string HeaderText
{
get => (string)GetValue(HeaderTextProperty);
set => SetValue(HeaderTextProperty, value);
}

public static readonly DependencyProperty ContentTextProperty =
DependencyProperty.Register("ContentText", typeof(string), typeof(ChangelogPanel));

public string ContentText
{
get => (string)GetValue(ContentTextProperty);
set => SetValue(ContentTextProperty, value);
}

public static readonly DependencyProperty ExpandedProperty =
DependencyProperty.Register("Expanded", typeof(Visibility), typeof(ChangelogPanel));

private int indentSize = 30; // Indentation size for wrapped lines

public Visibility Expanded
{
get => (Visibility)GetValue(ExpandedProperty);
set => SetValue(ExpandedProperty, value);
}

public ChangelogPanel()
{
InitializeComponent();
}

// Function to split text and create individual TextBlocks for each line
private void UpdateTextBlocks()
{
// Clear existing TextBlocks
TextBlockContainer.Children.Clear();

// Replace tab with 4 spaces for consistency
string text = ContentText.Replace("\t", new string(' ', 4));

// Create a FormattedText to help measure the width of the text
double availableWidth = TextBlockContainer.ActualWidth;

if (availableWidth <= 0) return; // No point in proceeding if the width isn't ready

string[] words = text.Split(' ');
string currentLine = "";
bool isFirstLine = true;

foreach (var word in words)
{
// Add the next word to the line (with a space if not the first word)
string testLine = (currentLine.Length == 0 ? currentLine : currentLine + " ") + word;

// Measure the test line's width
var formattedTestLine = CreateFormattedText(testLine);

// Check if the current line exceeds the available width
if (formattedTestLine.Width > availableWidth)
{
// The current line is too long, so we finalize the current line and move to the next
AddTextBlockToContainer(currentLine, isFirstLine);

// Get indent from last line
var lines = currentLine.Split("\n", StringSplitOptions.RemoveEmptyEntries);
var spaces = lines[^1].TakeWhile(Char.IsWhiteSpace).Count();
// Now check if the line starts with a '-", so we add 2 more spaces
if (lines[^1].Trim().StartsWith("-"))
{
spaces += 3;
}

// Start a new line with indentation for wrapped lines
currentLine = new string(' ', spaces) + word;
isFirstLine = false;
}
else
{
// If the line fits, continue adding to the current line
currentLine = testLine;
}
}

// Add the final line (if any)
if (!string.IsNullOrEmpty(currentLine))
{
AddTextBlockToContainer(currentLine, isFirstLine);
}
}

// Create and measure a FormattedText for line width calculation
private FormattedText CreateFormattedText(string text)
{
return new FormattedText(
text,
System.Globalization.CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface("Segoe UI"), // Use the font you prefer
16, // Font size
Brushes.White,
VisualTreeHelper.GetDpi(this).PixelsPerDip);
}

// Add a new TextBlock to the StackPanel container for each line
private void AddTextBlockToContainer(string text, bool isFirstLine)
{
TextBlock textBlock = new TextBlock
{
Text = text,
FontSize = 16,
FontFamily = new FontFamily("Segoe UI"),
TextWrapping = TextWrapping.NoWrap, // We handle wrapping manually
Margin = new Thickness(0, 0, 0, 0) // Indent wrapped lines
};

TextBlockContainer.Children.Add(textBlock);
}

private void ctrlChangelog_Loaded(object sender, RoutedEventArgs e)
{
UpdateTextBlocks();
}

private void ctrlChangelog_SizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateTextBlocks();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
if (Expanded == Visibility.Visible)
{
Expanded = Visibility.Collapsed;
}
else
{
Expanded = Visibility.Visible;
}
}
}
}
35 changes: 20 additions & 15 deletions DlssUpdater/Controls/DownloadButton.xaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<UserControl x:Class="DlssUpdater.Controls.DownloadButton"
<UserControl x:Class="DLSSUpdater.Controls.DownloadButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
x:Name="downloadButton"
Loaded="downloadButton_Loaded">
<Grid
Width="{Binding ActualWidth,
RelativeSource = {RelativeSource AncestorType = {x:Type UserControl}}}"
Height="{Binding ActualHeight,
RelativeSource ={RelativeSource AncestorType = {x:Type UserControl}}}"
Background="{DynamicResource ApplicationBackgroundBrush}">
<ProgressBar x:Name="prgDownload" Grid.Row="2" VerticalAlignment="Bottom"
Height="{Binding ActualHeight, ElementName=downloadButton}" Foreground="Black" />
<ui:TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding VersionText, ElementName=downloadButton}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}" VerticalAlignment="Center"
<Grid>
<Button x:Name="btnAction" Grid.Column="1" Grid.Row="1" Click="Button_Click"
Foreground="White"
BorderBrush="{x:Null}"
adonisExtensions:CursorSpotlightExtension.BackgroundBrush="#0AFFFFFF"
adonisExtensions:CursorSpotlightExtension.BorderBrush="#0FFFFFFF"
adonisExtensions:CursorSpotlightExtension.RelativeSpotlightSize="0.5"
adonisExtensions:RippleExtension.BackgroundBrush="#0AFFFFFF"
adonisExtensions:RippleExtension.BorderBrush="#14FFFFFF"
Background="#02646464"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding VersionText, ElementName=downloadButton}"
Foreground="White" VerticalAlignment="Center"
HorizontalAlignment="Left" Margin="5,0,0,0" />
<ui:Button x:Name="btnAction" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right"
VerticalAlignment="Center" Icon="{Binding ButtonIcon, ElementName=downloadButton}" Height="50"
Width="50" Margin="0,0,25,0" Click="Button_Click" />
<Label x:Name="lblAction" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,5,0"/>
<ContentControl x:Name="downloadIcon" ContentTemplate="{DynamicResource {x:Static adonisUi:Templates.LoadingBars}}"
Foreground="#14FFFFFF"
Focusable="False" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,5,0"/>
</Grid>
</UserControl>
Loading

0 comments on commit 4658308

Please sign in to comment.