Skip to content

Commit

Permalink
Add converters, models, and update project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MopigamesYT committed Jan 27, 2025
1 parent d420e17 commit 54b8968
Show file tree
Hide file tree
Showing 19 changed files with 1,017 additions and 57 deletions.
46 changes: 45 additions & 1 deletion App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,52 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Libertix"
xmlns:converters="clr-namespace:Libertix.Converters"
StartupUri="MainWindow.xaml">
<Application.Resources>

<Style x:Key="ModernButton" TargetType="Button">
<Setter Property="Background" Value="#2a273f"/>
<Setter Property="Foreground" Value="#E0DEF4"/>
<Setter Property="Padding" Value="20,10"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
CornerRadius="8"
BorderThickness="0"
Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#EA9A97"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#eb6f92"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- Color Resources -->
<SolidColorBrush x:Key="PrimaryBackground" Color="#232136"/>
<SolidColorBrush x:Key="SecondaryBackground" Color="#2a273f"/>
<SolidColorBrush x:Key="AccentColor" Color="#3e8fb0"/>
<SolidColorBrush x:Key="TextPrimary" Color="#e0def4"/>
<SolidColorBrush x:Key="TextSecondary" Color="#908caa"/>
<SolidColorBrush x:Key="ErrorColor" Color="#eb6f92"/>

<!-- Converters -->
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<converters:InverseBoolConverter x:Key="InverseBoolConverter"/>
<converters:ScaleConverter x:Key="ScaleConverter"/>
<converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>
<converters:VisibilityToBoolConverter x:Key="VisibilityToBoolConverter"/>

</Application.Resources>
</Application>
27 changes: 27 additions & 0 deletions Commands/RelayCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Windows.Input;

namespace Libertix.Commands
{
public class RelayCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Func<object, bool> _canExecute;

public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute;
}

public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}

public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true;

public void Execute(object parameter) => _execute(parameter);
}
}
152 changes: 152 additions & 0 deletions Controls/ErrorPanel.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<UserControl x:Class="Libertix.Controls.ErrorPanel"
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:converters="clr-namespace:Libertix.Converters"
mc:Ignorable="d">

<UserControl.Resources>
<Style x:Key="CustomScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Rectangle Fill="#908caa"
RadiusX="4"
RadiusY="4"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="CustomScrollBar" TargetType="{x:Type ScrollBar}">
<Setter Property="Width" Value="8"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid>
<Rectangle Fill="#363252"
RadiusX="4"
RadiusY="4"/>
<Track x:Name="PART_Track"
IsDirectionReversed="True">
<Track.Thumb>
<Thumb Style="{StaticResource CustomScrollBarThumb}"/>
</Track.Thumb>
</Track>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="CustomScrollViewer" TargetType="{x:Type ScrollViewer}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ScrollContentPresenter/>
<ScrollBar x:Name="PART_VerticalScrollBar"
Grid.Column="1"
Value="{TemplateBinding VerticalOffset}"
Maximum="{TemplateBinding ScrollableHeight}"
ViewportSize="{TemplateBinding ViewportHeight}"
Style="{StaticResource CustomScrollBar}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Border Background="#2a273f"
BorderBrush="#eb6f92"
BorderThickness="1"
CornerRadius="8"
MaxWidth="{Binding MaxWidth, RelativeSource={RelativeSource AncestorType=UserControl}}"
MaxHeight="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Window}, Converter={StaticResource ScaleConverter}, ConverterParameter=0.8}"
MinWidth="300">

<ScrollViewer Style="{StaticResource CustomScrollViewer}"
VerticalScrollBarVisibility="Auto"
Margin="40,30">
<StackPanel>
<TextBlock Text="{Binding Title, RelativeSource={RelativeSource AncestorType=UserControl}}"
Foreground="#eb6f92"
FontSize="32"
FontWeight="Light"
TextAlignment="Center"
TextWrapping="Wrap"
Margin="0,0,0,20"/>

<TextBlock Text="{Binding Message, RelativeSource={RelativeSource AncestorType=UserControl}}"
Foreground="#e0def4"
FontSize="16"
TextAlignment="Center"
TextWrapping="Wrap"/>

<Expander Margin="0,20,0,0"
BorderThickness="0"
IsExpanded="True">
<Expander.Header>
<TextBlock Text="System Requirements"
Foreground="#908caa"
FontSize="16"
FontWeight="SemiBold"/>
</Expander.Header>
<Expander.Style>
<Style TargetType="Expander">
<Style.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter Property="Header">
<Setter.Value>
<TextBlock Text="System Requirements"
Foreground="#908caa"
FontSize="16"
FontWeight="SemiBold"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Expander.Style>
<Border Background="#363252"
CornerRadius="4"
Padding="20"
Margin="0,10,0,0">
<StackPanel>
<!-- System Requirements -->
<TextBlock Text="{Binding Details, RelativeSource={RelativeSource AncestorType=UserControl}}"
Foreground="#e0def4"
FontFamily="Consolas"
FontSize="14"
TextWrapping="Wrap"/>

<!-- Additional Space Needed -->
<TextBlock Text="{Binding AdditionalDetails, RelativeSource={RelativeSource AncestorType=UserControl}}"
Foreground="#eb6f92"
FontSize="14"
FontWeight="SemiBold"
Margin="0,10,0,0"
TextWrapping="Wrap"
Visibility="{Binding AdditionalDetails, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={StaticResource StringToVisibilityConverter}}"/>
</StackPanel>
</Border>
</Expander>

<Button Content="{Binding ActionButtonText, RelativeSource={RelativeSource AncestorType=UserControl}}"
Style="{StaticResource ModernButton}"
Width="250"
Height="50"
Margin="0,30,0,0"
Command="{Binding ActionCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
Visibility="{Binding ActionButtonText, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={StaticResource StringToVisibilityConverter}}"/>
</StackPanel>
</ScrollViewer>
</Border>
</UserControl>
76 changes: 76 additions & 0 deletions Controls/ErrorPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;

namespace Libertix.Controls
{
public partial class ErrorPanel : UserControl
{
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(ErrorPanel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register("Message", typeof(string), typeof(ErrorPanel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty DetailsProperty =
DependencyProperty.Register("Details", typeof(string), typeof(ErrorPanel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty AdditionalDetailsProperty =
DependencyProperty.Register("AdditionalDetails", typeof(string), typeof(ErrorPanel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty ActionButtonTextProperty =
DependencyProperty.Register("ActionButtonText", typeof(string), typeof(ErrorPanel), new PropertyMetadata(string.Empty));

public static readonly DependencyProperty ActionCommandProperty =
DependencyProperty.Register("ActionCommand", typeof(ICommand), typeof(ErrorPanel), new PropertyMetadata(null));

public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}

public string Message
{
get => (string)GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}

public string Details
{
get => (string)GetValue(DetailsProperty);
set => SetValue(DetailsProperty, value);
}

public string AdditionalDetails
{
get => (string)GetValue(AdditionalDetailsProperty);
set => SetValue(AdditionalDetailsProperty, value);
}

public string ActionButtonText
{
get => (string)GetValue(ActionButtonTextProperty);
set => SetValue(ActionButtonTextProperty, value);
}

public ICommand ActionCommand
{
get => (ICommand)GetValue(ActionCommandProperty);
set => SetValue(ActionCommandProperty, value);
}

public ErrorPanel()
{
InitializeComponent();
}

private void Expander_Expanded(object sender, RoutedEventArgs e)
{
if (sender is Expander expander)
{
expander.BringIntoView();
}
}
}
}
19 changes: 19 additions & 0 deletions Converters/BoolToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Windows;
using System.Windows.Data;

namespace Libertix.Converters
{
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value is bool boolValue && boolValue ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value is Visibility visibility && visibility == Visibility.Visible;
}
}
}
18 changes: 18 additions & 0 deletions Converters/InverseBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Windows.Data;

namespace Libertix.Converters
{
public class InverseBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value is bool boolValue ? !boolValue : true;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value is bool boolValue ? !boolValue : true;
}
}
}
26 changes: 26 additions & 0 deletions Converters/ResponsiveFontConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace Libertix.Pages
{
public class ResponsiveFontConverter : IMultiValueConverter
{
public double SmallScreenSize { get; set; }
public double DefaultSize { get; set; }

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] is double width)
{
return width < 800 ? SmallScreenSize : DefaultSize;
}
return DefaultSize;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 54b8968

Please sign in to comment.