Browse Source

Added AlignableWrapPanel and use it in HelloTherePopup, change pixi file no longer supported text and fixed restart button always showing in Debug

CPKreuz 4 years ago
parent
commit
12076bc321

+ 2 - 2
PixiEditor/Properties/AssemblyInfo.cs

@@ -50,5 +50,5 @@ using System.Windows;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.1.4.0")]
-[assembly: AssemblyFileVersion("0.1.4.0")]
+[assembly: AssemblyVersion("0.2.0.0")]
+[assembly: AssemblyFileVersion("0.2.0.0")]

+ 1 - 1
PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -199,7 +199,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
             catch (OldFileFormatException)
             {
-                NoticeDialog.Show("This pixi file uses the old file format and can't be opened", "Old file format");
+                NoticeDialog.Show("This .pixi file uses the old format, which is no longer supported and can't be opened.", "Old file format");
             }
         }
 

+ 32 - 7
PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -5,8 +5,9 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:dataHolders="clr-namespace:PixiEditor.Models.DataHolders" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
         xmlns:sys="clr-namespace:System;assembly=System.Runtime"
+        xmlns:uc="clr-namespace:PixiEditor.Views.UserControls"
         mc:Ignorable="d"
-        Title="Hello there!" Height="651" Width="651"
+        Title="Hello there!" Height="662" Width="632"
         WindowStyle="None" WindowStartupLocation="CenterScreen">
 
     <Window.Resources>
@@ -20,7 +21,7 @@
 
         <Style TargetType="Button" BasedOn="{StaticResource DarkRoundButton}" x:Key="SocialMediaButton">
             <Setter Property="Width" Value="150"/>
-            <Setter Property="Margin" Value="5,0,5,0"/>
+            <Setter Property="Margin" Value="5,8,5,0"/>
             <Setter Property="FontSize" Value="18"/>
             <Setter Property="Height" Value="28"/>
         </Style>
@@ -62,7 +63,7 @@
                         <Image Source="../../Images/PixiEditorLogo.png" Height="40" VerticalAlignment="Center"/>
                         <TextBlock FontSize="40" FontWeight="SemiBold" VerticalAlignment="Center" Margin="10,0,0,0">PixiEditor</TextBlock>
                     </StackPanel>
-                    <TextBlock HorizontalAlignment="Center" FontSize="20" FontWeight="Medium">v0.2</TextBlock>
+                    <TextBlock HorizontalAlignment="Center" FontSize="20" FontWeight="Medium" Text="{Binding VersionText}"/>
                 </StackPanel>
 
                 <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
@@ -90,7 +91,7 @@
                                     <StackPanel Margin="8,5,8,0" ToolTip="{Binding FilePath}">
                                         <Button Margin="0,10,0,0" HorizontalAlignment="Center"
                                                 Width="100" Height="100"
-                                                Command="{Binding DataContext.OpenRecentCommand, RelativeSource={RelativeSource AncestorType=WrapPanel}}"
+                                                Command="{Binding DataContext.OpenRecentCommand, RelativeSource={RelativeSource AncestorType=uc:AlignableWrapPanel}}"
                                                 CommandParameter="{Binding FilePath}"
                                                 Style="{StaticResource DarkRoundButton}">
                                             <Image Source="{Binding PreviewBitmap}" Margin="20"/>
@@ -110,13 +111,13 @@
                         </ItemsControl.ItemTemplate>
                         <ItemsControl.ItemsPanel>
                             <ItemsPanelTemplate>
-                                <WrapPanel HorizontalAlignment="Center"/>
+                                <uc:AlignableWrapPanel HorizontalAlignment="Center" HorizontalContentAlignment="Center"/>
                             </ItemsPanelTemplate>
                         </ItemsControl.ItemsPanel>
                     </ItemsControl>
                 </StackPanel>
 
-                <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,18">
+                <uc:AlignableWrapPanel Grid.Row="3" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Margin="0,5,0,15">
                     <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://discord.gg/tzkQFDkqQS"
                             Content="Discord">
                         <Button.Style>
@@ -154,7 +155,31 @@
                             </Style>
                         </Button.Style>
                     </Button>
-                </StackPanel>
+                    <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://www.youtube.com/channel/UCT5XvyvX1q5PAIaXfWmpsMQ"
+                            Content="YouTube">
+                        <Button.Style>
+                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
+                                <Style.Triggers>
+                                    <Trigger Property="IsMouseOver" Value="True">
+                                        <Setter Property="Background" Value="#FF0000"/>
+                                    </Trigger>
+                                </Style.Triggers>
+                            </Style>
+                        </Button.Style>
+                    </Button>
+                    <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://opencollective.com/pixieditor"
+                            Content="Sponsor">
+                        <Button.Style>
+                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
+                                <Style.Triggers>
+                                    <Trigger Property="IsMouseOver" Value="True">
+                                        <Setter Property="Background" Value="#DB61A2"/>
+                                    </Trigger>
+                                </Style.Triggers>
+                            </Style>
+                        </Button.Style>
+                    </Button>
+                </uc:AlignableWrapPanel>
             </Grid>
         </ScrollViewer>
     </Grid>

+ 6 - 3
PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
+using System.Reflection;
 using System.Windows;
 using System.Windows.Input;
 using Newtonsoft.Json.Linq;
@@ -34,6 +35,8 @@ namespace PixiEditor.Views.Dialogs
 
         public bool RecentlyOpenedEmpty { get => (bool)GetValue(RecentlyOpenedEmptyProperty); set => SetValue(RecentlyOpenedEmptyProperty, value); }
 
+        public static string VersionText { get => $"v{Assembly.GetExecutingAssembly().GetName().Version.Major}.{Assembly.GetExecutingAssembly().GetName().Version.Minor}"; }
+
         public RelayCommand OpenFileCommand { get; set; }
 
         public RelayCommand OpenNewFileCommand { get; set; }
@@ -62,12 +65,12 @@ namespace PixiEditor.Views.Dialogs
 
             if (RecentlyOpenedEmpty)
             {
-                Height = 450;
-                Width = 522;
+                Height = 500;
+                Width = 520;
             }
             else if (RecentlyOpened.Count < 7)
             {
-                Height = 656;
+                Height = 676;
                 Width = 545;
             }
         }

+ 1 - 1
PixiEditor/Views/MainWindow.xaml

@@ -450,7 +450,7 @@
         <StackPanel Margin="10,0,0,0" VerticalAlignment="Center" Grid.Row="3"
                        Grid.Column="3" Orientation="Horizontal">
             <Button Style="{StaticResource BaseDarkButton}" 
-                    Visibility="{Binding UpdateSubViewModel.UpdateReadyToInstall, Converter={StaticResource BoolToVisibilityConverter}}" FontSize="14" Height="20" 
+                    Visibility="{Binding UpdateSubViewModel.UpdateReadyToInstall, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Hidden}" FontSize="14" Height="20" 
                     Command="{Binding UpdateSubViewModel.RestartApplicationCommand}">Restart</Button>
             <TextBlock VerticalAlignment="Center" Padding="10" HorizontalAlignment="Right"
                        Foreground="White" FontSize="14"  Text="{Binding UpdateSubViewModel.VersionText}" />

+ 123 - 0
PixiEditor/Views/UserControls/AlignableWrapPanel.cs

@@ -0,0 +1,123 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PixiEditor.Views.UserControls
+{
+    public class AlignableWrapPanel : Panel
+    {
+        public HorizontalAlignment HorizontalContentAlignment
+        {
+            get { return (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty); }
+            set { SetValue(HorizontalContentAlignmentProperty, value); }
+        }
+
+        public static readonly DependencyProperty HorizontalContentAlignmentProperty =
+            DependencyProperty.Register("HorizontalContentAlignment", typeof(HorizontalAlignment), typeof(AlignableWrapPanel), new FrameworkPropertyMetadata(HorizontalAlignment.Left, FrameworkPropertyMetadataOptions.AffectsArrange));
+
+        protected override Size MeasureOverride(Size constraint)
+        {
+            Size curLineSize = default;
+            Size panelSize = default;
+
+            UIElementCollection children = InternalChildren;
+
+            for (int i = 0; i < children.Count; i++)
+            {
+                UIElement child = children[i] as UIElement;
+
+                // Flow passes its own constraint to children
+                child.Measure(constraint);
+                Size sz = child.DesiredSize;
+
+                if (curLineSize.Width + sz.Width > constraint.Width)
+                {
+                    panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width);
+                    panelSize.Height += curLineSize.Height;
+                    curLineSize = sz;
+
+                    if (sz.Width > constraint.Width)
+                    {
+                        panelSize.Width = Math.Max(sz.Width, panelSize.Width);
+                        panelSize.Height += sz.Height;
+                        curLineSize = default;
+                    }
+                }
+                else
+                {
+                    curLineSize.Width += sz.Width;
+                    curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
+                }
+            }
+
+
+            panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width);
+            panelSize.Height += curLineSize.Height;
+
+            return panelSize;
+        }
+
+        protected override Size ArrangeOverride(Size arrangeBounds)
+        {
+            int firstInLine = 0;
+            Size curLineSize = default;
+            double accumulatedHeight = 0;
+            UIElementCollection children = this.InternalChildren;
+
+            for (int i = 0; i < children.Count; i++)
+            {
+                Size sz = children[i].DesiredSize;
+
+                if (curLineSize.Width + sz.Width > arrangeBounds.Width)
+                {
+                    ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, i);
+
+                    accumulatedHeight += curLineSize.Height;
+                    curLineSize = sz;
+
+                    if (sz.Width > arrangeBounds.Width)
+                    {
+                        ArrangeLine(accumulatedHeight, sz, arrangeBounds.Width, i, ++i);
+                        accumulatedHeight += sz.Height;
+                        curLineSize = default;
+                    }
+
+                    firstInLine = i;
+                }
+                else
+                {
+                    curLineSize.Width += sz.Width;
+                    curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
+                }
+            }
+
+            if (firstInLine < children.Count)
+            {
+                ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, children.Count);
+            }
+
+            return arrangeBounds;
+        }
+
+        private void ArrangeLine(double y, Size lineSize, double boundsWidth, int start, int end)
+        {
+            double x = 0;
+            if (this.HorizontalContentAlignment == HorizontalAlignment.Center)
+            {
+                x = (boundsWidth - lineSize.Width) / 2;
+            }
+            else if (this.HorizontalContentAlignment == HorizontalAlignment.Right)
+            {
+                x = boundsWidth - lineSize.Width;
+            }
+
+            UIElementCollection children = InternalChildren;
+            for (int i = start; i < end; i++)
+            {
+                UIElement child = children[i];
+                child.Arrange(new Rect(x, y, child.DesiredSize.Width, lineSize.Height));
+                x += child.DesiredSize.Width;
+            }
+        }
+    }
+}