Skip to content

Commit

Permalink
Demo Viewer Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
netquick committed Jul 17, 2024
1 parent 171642d commit 5427262
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 70 deletions.
11 changes: 10 additions & 1 deletion DeFRaG_Helper/CustomStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@
<!-- Define the ControlTemplate -->
<!-- Add other setters as needed to match your theme -->
</Style>
<Style x:Key="DarkListViewStyle2" TargetType="ListView">
<Setter Property="Background" Value="#222222"/>
<Setter Property="Foreground" Value="#D3D3D3"/>
<Setter Property="BorderBrush" Value="#222222"/>
<Setter Property="BorderThickness" Value="1"/>

<!-- Define the ControlTemplate -->
<!-- Add other setters as needed to match your theme -->
</Style>

<!-- ListViewItem Style with Hover Effect -->
<!-- ListViewItem Style with Hover Effect -->
<Style TargetType="ListViewItem">
<Setter Property="Foreground" Value="White"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
Expand Down
9 changes: 9 additions & 0 deletions DeFRaG_Helper/ToDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Images from 3 folders
- Demo: Collection for miniview
- Settings: Include Image setting
- Search
- Language
- Edit maps
- Config editor
- Records
- Versioning
52 changes: 52 additions & 0 deletions DeFRaG_Helper/UserControls/DemoCard.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<UserControl x:Class="DeFRaG_Helper.UserControls.DemoCard"
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:DeFRaG_Helper.UserControls"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="1000"
MouseEnter="UserControl_MouseEnter"
MouseLeave="UserControl_MouseLeave"
MouseDoubleClick="DemoCard_MouseDoubleClick">
<UserControl.Resources>
<!-- Hover Style for Border -->
<Style x:Key="HoverBorderStyle" TargetType="Border">
<Setter Property="Background" Value="#2c2c2c"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!-- Change to desired hover background color -->
<Setter Property="Background" Value="#3e3e3e"/>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Border CornerRadius="10" Background="#2c2c2c" Margin="10, 5, 10, 5" Style="{StaticResource HoverBorderStyle}" x:Name="MainBorder">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Name: " FontFamily="Segoe UI" FontSize="16" Foreground="White" VerticalAlignment="Bottom" Margin="10, 5, 0, 0"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding PlayerName}" FontSize="16" Foreground="White" VerticalAlignment="Bottom" Margin="10, 5, 0, 0"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Mapname: " FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 0"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Mapname}" FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 0"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Physics: " FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 5"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Physics}" FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 5"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="Country: " FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 5, 0, 0"/>
<TextBlock Grid.Row="0" Grid.Column="3" Text="{Binding PlayerCountry}" FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 5, 0, 0"/>
<TextBlock Grid.Row="1" Grid.Column="2" Text="Type: " FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 0"/>
<TextBlock Grid.Row="1" Grid.Column="3" Text="{Binding Type}" FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 0"/>
<TextBlock Grid.Row="2" Grid.Column="2" Text="Time: " FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 5"/>
<TextBlock Grid.Row="2" Grid.Column="3" Text="{Binding Time}" FontSize="12" Foreground="White" VerticalAlignment="Bottom" Margin="10, 0, 0, 5"/>
</Grid>
</Border>
</UserControl>
103 changes: 103 additions & 0 deletions DeFRaG_Helper/UserControls/DemoCard.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using DeFRaG_Helper.ViewModels;
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 DeFRaG_Helper.UserControls
{
/// <summary>
/// Interaction logic for DemoCard.xaml
/// </summary>
public partial class DemoCard : UserControl
{
public DemoCard()
{
InitializeComponent();
}



private async void DemoCard_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
// Check if the actual item (not empty space) in the ListView was double-clicked
var item = ((FrameworkElement)e.OriginalSource).DataContext as DemoItem;
if (item != null)
{
//we need the mapname of the actual demo
var mapName = item.Mapname;
//now we have to check if the map is installed. We check "IsInstalled" property of the map
var viewModel = MapViewModel.GetInstanceAsync().Result;
MessageHelper.Log($"Checking for Mapname: {mapName}");
var map = viewModel.Maps.FirstOrDefault(m => m.Mapname == (mapName + ".bsp"));
if (map != null)
{
if (map.IsInstalled == 0)
{
await MapInstaller.InstallMap(map);
MessageHelper.Log($"Map {map.Mapname} installed.");
}
//Prepare the progress handler to update the UI
var progressHandler = new Progress<double>(value =>
{
App.Current.Dispatcher.Invoke(() => MainWindow.Instance.UpdateProgressBar(value));
});
//Prepare the link for the demo. It's contructed from http://95.31.6.66/~/api/get_file_list?uri=/demos/{mapName[0]}/{mapName}/" and the name of the demo
var demoLink = $"http://95.31.6.66/demos/{mapName[0]}/{mapName}/{item.Name}";

//check if there is a demo folder. If not, create it
if (!System.IO.Directory.Exists(AppConfig.GameDirectoryPath + "\\defrag\\demos"))
{
System.IO.Directory.CreateDirectory(AppConfig.GameDirectoryPath + "\\defrag\\demos");
}
//check if there is a demo folder for the map. If not, create it
if (!System.IO.Directory.Exists(AppConfig.GameDirectoryPath + $"\\defrag\\demos\\{mapName}"))
{
System.IO.Directory.CreateDirectory(AppConfig.GameDirectoryPath + $"\\defrag\\demos\\{mapName}");
}

//Download the demo to the demo folder
await Downloader.DownloadFileAsync(demoLink, AppConfig.GameDirectoryPath + $"\\defrag\\demos\\{mapName}\\{item.Name}", progressHandler);




//System.Diagnostics.Process.Start(AppConfig.GameDirectoryPath + "\\oDFe.x64.exe", $"+demo {mapName}//{System.IO.Path.GetFilenameWithoutExtension(item.Name)}") ;
System.Diagnostics.Process.Start(AppConfig.GameDirectoryPath + "\\oDFe.x64.exe", $"+demo {mapName}/{System.IO.Path.GetFileNameWithoutExtension(item.Name)}");


}




// Implement your double-click logic here
// For example, navigate to a detail page or display a dialog
///MessageBox.Show($"Double-clicked on item: {item.Name}");


}
}
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
// Change to a slightly lighter or darker background color on hover
MainBorder.Background = new SolidColorBrush(Color.FromRgb(62, 62, 62)); // Example color
}

private void UserControl_MouseLeave(object sender, MouseEventArgs e)
{
// Revert to the original background color
MainBorder.Background = new SolidColorBrush(Color.FromRgb(45, 45, 45)); // Example color
}
}
}
18 changes: 15 additions & 3 deletions DeFRaG_Helper/UserControls/HighLightCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DeFRaG_Helper.UserControls"
xmlns:converters="clr-namespace:DeFRaG_Helper.Converters"

MouseEnter="UserControl_MouseEnter"
MouseLeave="UserControl_MouseLeave"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="200">
<UserControl.Resources>
Expand All @@ -14,7 +15,18 @@
<converters:IntToBoolConverter x:Key="IntToBoolConverter"/>

</UserControl.Resources>
<Border Margin="10" CornerRadius="10" Background="#2d2d2d" MouseLeftButtonDown="Border_MouseLeftButtonDown">
<Border Margin="10" CornerRadius="10" Background="#2d2d2d" MouseLeftButtonDown="Border_MouseLeftButtonDown">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="#2d2d2d"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!-- Change to a slightly lighter or darker background color on hover -->
<Setter Property="Background" Value="#FFFFFF"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
Expand All @@ -25,7 +37,7 @@
<TextBlock Text="{Binding Name}" FontSize="20" Foreground="White" Margin="20,10,20,0" Height="96" VerticalAlignment="Top" TextWrapping="Wrap" MaxWidth="160" HorizontalAlignment="Center"/>
</Grid>
<!-- Adjusted inner Border with straight upper corners and rounded bottom corners -->
<Border Grid.Row="1" Height="60" Background="#2a2a2a" CornerRadius="0,0,10,10">
<Border Grid.Row="1" Height="60" Background="#2a2a2a" CornerRadius="0,0,10,10" x:Name="MainBorder">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down
13 changes: 13 additions & 0 deletions DeFRaG_Helper/UserControls/HighLightCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,18 @@ private async void FavoriteCheckBox_Unchecked(object sender, RoutedEventArgs e)
await mapViewModel.UpdateFavoriteStateAsync(map);
}
}

private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
// Change to a slightly lighter or darker background color on hover
MainBorder.Background = new SolidColorBrush(Color.FromRgb(62, 62, 62)); // Example color
}

private void UserControl_MouseLeave(object sender, MouseEventArgs e)
{
// Revert to the original background color
MainBorder.Background = new SolidColorBrush(Color.FromRgb(45, 45, 45)); // Example color
}

}
}
17 changes: 15 additions & 2 deletions DeFRaG_Helper/UserControls/HighLightServerCard.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
<UserControl x:Class="DeFRaG_Helper.HighLightServerCard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:DeFRaG_Helper"
mc:Ignorable="d"
MouseEnter="UserControl_MouseEnter"
MouseLeave="UserControl_MouseLeave"
d:DesignHeight="200" d:DesignWidth="200">

<Border Margin="10" CornerRadius="10" Background="#2d2d2d" MouseLeftButtonDown="Border_MouseLeftButtonDown">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="#2d2d2d"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!-- Change to a slightly lighter or darker background color on hover -->
<Setter Property="Background" Value="#3e3e3e"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
Expand All @@ -27,7 +40,7 @@

</Grid>
<!-- Adjusted inner Border with straight upper corners and rounded bottom corners -->
<Border Grid.Row="1" Height="60" Background="#2a2a2a" CornerRadius="0,0,10,10">
<Border x:Name="MainBorder" Grid.Row="1" Height="60" Background="#2a2a2a" CornerRadius="0,0,10,10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down
11 changes: 11 additions & 0 deletions DeFRaG_Helper/UserControls/HighLightServerCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,16 @@ private void ConnectToServer()
Debug.WriteLine($"Connecting to server at ");
// Implement the actual connection logic here
}
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
{
// Change to a slightly lighter or darker background color on hover
MainBorder.Background = new SolidColorBrush(Color.FromRgb(62, 62, 62)); // Example color
}

private void UserControl_MouseLeave(object sender, MouseEventArgs e)
{
// Revert to the original background color
MainBorder.Background = new SolidColorBrush(Color.FromRgb(45, 45, 45)); // Example color
}
}
}
25 changes: 25 additions & 0 deletions DeFRaG_Helper/UserControls/MiniView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<UserControl x:Class="DeFRaG_Helper.UserControls.MiniView"
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:DeFRaG_Helper.UserControls"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="120">
<Border CornerRadius="10" Background="#222222">
<Grid>
<Image Margin="5,5,5,45" Source="{Binding ImagePath}"/>
<Border Margin="0,75,0,0" Background="#2c2c2c" CornerRadius="0,0,10,10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Name}" FontSize="12" Foreground="White" HorizontalAlignment="Center" />
<TextBlock Grid.Row="1" Text="{Binding Mapname}" FontSize="10" Foreground="White" HorizontalAlignment="Center"/>
</Grid>

</Border>
</Grid>
</Border>
</UserControl>
28 changes: 28 additions & 0 deletions DeFRaG_Helper/UserControls/MiniView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 DeFRaG_Helper.UserControls
{
/// <summary>
/// Interaction logic for MiniView.xaml
/// </summary>
public partial class MiniView : UserControl
{
public MiniView()
{
InitializeComponent();
}
}
}
Loading

0 comments on commit 5427262

Please sign in to comment.