Skip to content

Commit

Permalink
Update Playbook ui pages
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoxy committed Sep 19, 2023
1 parent 1d329ca commit 91afe90
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 38 deletions.
118 changes: 118 additions & 0 deletions Dive/Dive.UI/Common/UIElements/DashedBorder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Dive.UI.Common.UIElements
{
public class DashedBorder : Border
{
private static DoubleCollection? emptyDoubleCollection;
private static DoubleCollection EmptyDoubleCollection()
{
if (emptyDoubleCollection == null)
{
DoubleCollection doubleCollection = new DoubleCollection();
doubleCollection.Freeze();
emptyDoubleCollection = doubleCollection;
}
return emptyDoubleCollection;
}

public static readonly DependencyProperty UseDashedBorderProperty =
DependencyProperty.Register(nameof(UseDashedBorder),
typeof(bool),
typeof(DashedBorder),
new FrameworkPropertyMetadata(false, OnUseDashedBorderChanged));

public static readonly DependencyProperty DashedBorderBrushProperty =
DependencyProperty.Register(nameof(DashedBorderBrush),
typeof(Brush),
typeof(DashedBorder),
new FrameworkPropertyMetadata(null));

public static readonly DependencyProperty StrokeDashArrayProperty =
DependencyProperty.Register(nameof(StrokeDashArray),
typeof(DoubleCollection),
typeof(DashedBorder),
new FrameworkPropertyMetadata(EmptyDoubleCollection()));

private static void OnUseDashedBorderChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
{
DashedBorder dashedBorder = (DashedBorder)target;
dashedBorder.UseDashedBorderChanged();
}

private Rectangle GetBoundRectangle()
{
Rectangle rectangle = new Rectangle();

rectangle.SetBinding(Rectangle.StrokeThicknessProperty, new Binding() { Source = this, Path = new PropertyPath("BorderThickness.Left") });
rectangle.SetBinding(Rectangle.RadiusXProperty, new Binding() { Source = this, Path = new PropertyPath("CornerRadius.TopLeft") });
rectangle.SetBinding(Rectangle.RadiusYProperty, new Binding() { Source = this, Path = new PropertyPath("CornerRadius.TopLeft") });
rectangle.SetBinding(Rectangle.WidthProperty, new Binding() { Source = this, Path = new PropertyPath(ActualWidthProperty) });
rectangle.SetBinding(Rectangle.HeightProperty, new Binding() { Source = this, Path = new PropertyPath(ActualHeightProperty) });

return rectangle;
}

private Rectangle GetBackgroundRectangle()
{
Rectangle rectangle = GetBoundRectangle();
rectangle.SetBinding(Rectangle.StrokeProperty, new Binding() { Source = this, Path = new PropertyPath(BackgroundProperty) });
return rectangle;
}

private Rectangle GetDashedRectangle()
{
Rectangle rectangle = GetBoundRectangle();
rectangle.SetBinding(Rectangle.StrokeDashArrayProperty, new Binding() { Source = this, Path = new PropertyPath(StrokeDashArrayProperty) });
rectangle.SetBinding(Rectangle.StrokeProperty, new Binding() { Source = this, Path = new PropertyPath(DashedBorderBrushProperty) });
Panel.SetZIndex(rectangle, 2);
return rectangle;
}

private VisualBrush CreateDashedBorderBrush()
{
VisualBrush dashedBorderBrush = new VisualBrush();
Grid grid = new Grid();
Rectangle backgroundRectangle = GetBackgroundRectangle();
Rectangle dashedRectangle = GetDashedRectangle();
grid.Children.Add(backgroundRectangle);
grid.Children.Add(dashedRectangle);
dashedBorderBrush.Visual = grid;
return dashedBorderBrush;
}

private void UseDashedBorderChanged()
{
if (UseDashedBorder)
{
BorderBrush = CreateDashedBorderBrush();
}
else
{
ClearValue(BorderBrushProperty);
}
}

public bool UseDashedBorder
{
get { return (bool)GetValue(UseDashedBorderProperty); }
set { SetValue(UseDashedBorderProperty, value); }
}

public Brush DashedBorderBrush
{
get { return (Brush)GetValue(DashedBorderBrushProperty); }
set { SetValue(DashedBorderBrushProperty, value); }
}

public DoubleCollection StrokeDashArray
{
get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); }
set { SetValue(StrokeDashArrayProperty, value); }
}
}
}
2 changes: 1 addition & 1 deletion Dive/Dive.UI/Dive.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AssemblyName>Dive</AssemblyName>
<Company>Exploitox</Company>
<Authors>valnoxy</Authors>
<Version>1.0.0.435</Version>
<Version>1.0.0.441</Version>
<Copyright>Copyright © 2018 - 2023 Exploitox. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/valnoxy/dive</PackageProjectUrl>
<RepositoryUrl>https://github.com/valnoxy/dive</RepositoryUrl>
Expand Down
5 changes: 3 additions & 2 deletions Dive/Dive.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
WindowCornerPreference="Round"
ResizeMode="NoResize"
ContentRendered="MainWindow_OnLoaded">
<Grid>
<Grid AllowDrop="True" Drop="UIElement_OnDrop" DragEnter="UIElement_OnDragEnter">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Expand All @@ -30,7 +30,8 @@
x:Name="RootNavigation"
Grid.Column="0"
Margin="6,0,6,0"
Loaded="RootNavigation_OnLoaded"/>
Loaded="RootNavigation_OnLoaded"
AllowDrop="True"/>
</Grid>

<ui:TitleBar
Expand Down
12 changes: 11 additions & 1 deletion Dive/Dive.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public MainWindow()
_displayDebugConsole = true;
#else
DebugString.Visibility = Visibility.Visible;
DebugString.Text = "Beta build [B6 Public]";
DebugString.Text = "Public Beta Build 6";
#endif
// Get version
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
Expand Down Expand Up @@ -144,5 +144,15 @@ private void MainWindow_OnLoaded(object? sender, EventArgs eventArgs)
{
RootNavigation.Navigate("dashboard"); // Workaround
}

private void UIElement_OnDrop(object sender, DragEventArgs e)
{
Common.Debug.WriteLine("Drop");
}

private void UIElement_OnDragEnter(object sender, DragEventArgs e)
{
Common.Debug.WriteLine("DragEnter");
}
}
}
4 changes: 2 additions & 2 deletions Dive/Dive.UI/Pages/TweaksContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<!-- step content -->
<!--<ContentPresenter Grid.Row="1" Content="{Binding StepViewModel}"/>-->
<ContentControl x:Name="FrameWindow"/>
<ContentControl x:Name="FrameWindow" AllowDrop="True"/>

<!-- buttons -->
<Grid Grid.Row="2">
Expand All @@ -27,7 +27,7 @@
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>

<Button Content="Cancel"
<Button Grid.Column="0" Content="Cancel"
x:Name="CancelBtn"
IsCancel="True"
Width="80"
Expand Down
28 changes: 15 additions & 13 deletions Dive/Dive.UI/Pages/TweaksContent.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using Dive.UI.Pages.ApplyPages;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Dive.UI.Common;
using Dive.UI.Pages.TweaksPages;
using Dive.UI.Pages.TweaksPages.PlayBook;

namespace Dive.UI.Pages
{
Expand All @@ -15,7 +14,8 @@ public partial class TweaksContent : UserControl
{
public static TweaksContent? ContentWindow;

TweaksDashboard TD = new TweaksDashboard();
readonly TweaksDashboard _td = new();
readonly PlayBookLoad _pb = new();
//DeploymentSettingsStep deploymentSettingsStep = new DeploymentSettingsStep();

public TweaksContent()
Expand All @@ -24,7 +24,7 @@ public TweaksContent()

NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
FrameWindow.Content = TD;
FrameWindow.Content = _td;
ContentWindow = this;
}

Expand All @@ -35,8 +35,10 @@ private void Button_Click(object sender, RoutedEventArgs e)
case TweakMode.AutoInit:
switch (FrameWindow.Content)
{
case AutoInitSettings:
FrameWindow.Content = TD;
case PlayBookLoad:
//_pb.DragEnter += UserControlDragEnter;
//_pb.Drop += _pb_Drop;
FrameWindow.Content = _pb;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
break;
Expand All @@ -48,7 +50,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
switch (FrameWindow.Content)
{
case MigrateSettings:
FrameWindow.Content = TD;
FrameWindow.Content = _td;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
break;
Expand All @@ -61,7 +63,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
switch (FrameWindow.Content)
{
case MigrateSettings:
FrameWindow.Content = TD;
FrameWindow.Content = _td;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
break;
Expand All @@ -81,8 +83,8 @@ private void Back_Click(object sender, RoutedEventArgs e)
case TweakMode.AutoInit:
switch (FrameWindow.Content)
{
case AutoInitSettings:
FrameWindow.Content = TD;
case PlayBookLoad:
FrameWindow.Content = _td;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
break;
Expand All @@ -94,7 +96,7 @@ private void Back_Click(object sender, RoutedEventArgs e)
switch (FrameWindow.Content)
{
case MigrateSettings:
FrameWindow.Content = TD;
FrameWindow.Content = _td;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
break;
Expand All @@ -107,7 +109,7 @@ private void Back_Click(object sender, RoutedEventArgs e)
switch (FrameWindow.Content)
{
case MigrateSettings:
FrameWindow.Content = TD;
FrameWindow.Content = _td;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = false;
break;
Expand All @@ -123,7 +125,7 @@ private void Back_Click(object sender, RoutedEventArgs e)

private void CancelBtn_Click(object sender, RoutedEventArgs e)
{
FrameWindow.Content = TD;
FrameWindow.Content = _td;
NextBtn.IsEnabled = false;
NextBtn.Visibility = Visibility.Visible;
}
Expand Down
31 changes: 31 additions & 0 deletions Dive/Dive.UI/Pages/TweaksPages/PlayBook/PlayBookLoad.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<UserControl x:Class="Dive.UI.Pages.TweaksPages.PlayBook.PlayBookLoad"
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:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:Dive.UI.Pages.TweaksPages.PlayBook"
xmlns:uiElements="clr-namespace:Dive.UI.Common.UIElements"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="0,-20,0,0" AllowDrop="True"
Drop="UIElement_OnDrop"
DragEnter="UIElement_DragEnter">
<Grid.RowDefinitions>
<RowDefinition Height="420"/>
</Grid.RowDefinitions>

<uiElements:DashedBorder UseDashedBorder="True"
DashedBorderBrush="White"
StrokeDashArray="2 1"
Background="Transparent"
BorderThickness="2"
CornerRadius="10"
Margin="20">
<Label HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Drag .dpbx file or click here to load playbook"
FontSize="20"/>
</uiElements:DashedBorder>
</Grid>
</UserControl>
48 changes: 48 additions & 0 deletions Dive/Dive.UI/Pages/TweaksPages/PlayBook/PlayBookLoad.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Windows;
using Dive.UI.Common;

namespace Dive.UI.Pages.TweaksPages.PlayBook
{
/// <summary>
/// Interaktionslogik für PlayBookLoad.xaml
/// </summary>
public partial class PlayBookLoad
{
public event DragEventHandler DragEnter;
public event DragEventHandler Drop;

public PlayBookLoad()
{
InitializeComponent();

if (TweaksContent.ContentWindow == null) return;
TweaksContent.ContentWindow.NextBtn.IsEnabled = false;
TweaksContent.ContentWindow.BackBtn.IsEnabled = true;
}

private void UIElement_OnDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
Debug.WriteLine(file);
}
}
}

private void UIElement_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effects = DragDropEffects.Copy;
}
else
{
e.Effects = DragDropEffects.None;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<UserControl x:Class="Dive.UI.Pages.TweaksPages.AutoInitSettings"
<UserControl x:Class="Dive.UI.Pages.TweaksPages.PlayBook.PlayBookSettings"
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:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:Dive.UI.Pages.TweaksPages"
xmlns:local="clr-namespace:Dive.UI.Pages.TweaksPages.PlayBook"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="0,-20,0,0">
Expand Down
Loading

0 comments on commit 91afe90

Please sign in to comment.