Browse Source

Did what flabbet said and added a preview

CPKreuz 4 years ago
parent
commit
550b024d11

+ 28 - 0
PixiEditor/Helpers/Converters/BoolToDiscordBrush.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Data;
+using System.Windows.Media;
+
+namespace PixiEditor.Helpers.Converters
+{
+    class BoolToDiscordBrush : IValueConverter
+    {
+        private static SolidColorBrush IsPlayingBrush = new SolidColorBrush(Color.FromRgb(114, 137, 218));
+        private static SolidColorBrush IsntPlayingBrush = new SolidColorBrush(Color.FromRgb(32, 34, 37));
+
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            return (bool)value ? IsPlayingBrush : IsntPlayingBrush;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 24 - 0
PixiEditor/Helpers/Converters/BoolToVisibiltyConverter.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    public class BoolToVisibiltyConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            return (bool)value ? Visibility.Visible : Visibility.Collapsed;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 26 - 0
PixiEditor/Helpers/Converters/EmptyStringToVisibiltyConverter.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    class EmptyStringToVisibiltyConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            string s = (string)value;
+
+            return !string.IsNullOrEmpty(s) ? Visibility.Visible : Visibility.Collapsed;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

BIN
PixiEditor/Images/PixiBotLogo.png


+ 2 - 0
PixiEditor/PixiEditor.csproj

@@ -32,6 +32,7 @@
     <None Remove="Images\Eye.png" />
     <None Remove="Images\Eye.png" />
     <None Remove="Images\MoveImage.png" />
     <None Remove="Images\MoveImage.png" />
     <None Remove="Images\MoveViewportImage.png" />
     <None Remove="Images\MoveViewportImage.png" />
+    <None Remove="Images\PixiBotLogo.png" />
     <None Remove="Images\PixiEditorLogo.png" />
     <None Remove="Images\PixiEditorLogo.png" />
     <None Remove="Images\SelectImage.png" />
     <None Remove="Images\SelectImage.png" />
     <None Remove="Images\ZoomImage.png" />
     <None Remove="Images\ZoomImage.png" />
@@ -72,6 +73,7 @@
     <Resource Include="Images\MoveViewportImage.png" />
     <Resource Include="Images\MoveViewportImage.png" />
     <Resource Include="Images\PenImage.png" />
     <Resource Include="Images\PenImage.png" />
     <Resource Include="Images\ColorPickerImage.png" />
     <Resource Include="Images\ColorPickerImage.png" />
+    <Resource Include="Images\PixiBotLogo.png" />
     <Resource Include="Images\PixiEditorLogo.png" />
     <Resource Include="Images\PixiEditorLogo.png" />
     <Resource Include="Images\RectangleImage.png" />
     <Resource Include="Images\RectangleImage.png" />
     <Resource Include="Images\SelectImage.png" />
     <Resource Include="Images\SelectImage.png" />

+ 84 - 23
PixiEditor/ViewModels/SubViewModels/Main/DiscordViewModel.cs

@@ -34,6 +34,51 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
             }
         }
         }
 
 
+        private bool showDocumentName = PreferencesSettings.GetPreference(nameof(ShowDocumentName), true);
+
+        public bool ShowDocumentName
+        {
+            get => showDocumentName;
+            set
+            {
+                if (showDocumentName != value)
+                {
+                    showDocumentName = value;
+                    UpdatePresence(currentDocument);
+                }
+            }
+        }
+
+        private bool showDocumentSize = PreferencesSettings.GetPreference(nameof(ShowDocumentSize), true);
+
+        public bool ShowDocumentSize
+        {
+            get => showDocumentSize;
+            set
+            {
+                if (showDocumentSize != value)
+                {
+                    showDocumentSize = value;
+                    UpdatePresence(currentDocument);
+                }
+            }
+        }
+
+        private bool showLayerCount = PreferencesSettings.GetPreference(nameof(ShowLayerCount), true);
+
+        public bool ShowLayerCount
+        {
+            get => showLayerCount;
+            set
+            {
+                if (showLayerCount != value)
+                {
+                    showLayerCount = value;
+                    UpdatePresence(currentDocument);
+                }
+            }
+        }
+
         public DiscordViewModel(ViewModelMain owner, string clientId)
         public DiscordViewModel(ViewModelMain owner, string clientId)
             : base(owner)
             : base(owner)
         {
         {
@@ -42,6 +87,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
 
             Enabled = PreferencesSettings.GetPreference<bool>("EnableRichPresence");
             Enabled = PreferencesSettings.GetPreference<bool>("EnableRichPresence");
             PreferencesSettings.AddCallback("EnableRichPresence", x => Enabled = (bool)x);
             PreferencesSettings.AddCallback("EnableRichPresence", x => Enabled = (bool)x);
+            PreferencesSettings.AddCallback(nameof(ShowDocumentName), x => ShowDocumentName = (bool)x);
+            PreferencesSettings.AddCallback(nameof(ShowDocumentSize), x => ShowDocumentSize = (bool)x);
+            PreferencesSettings.AddCallback(nameof(ShowLayerCount), x => ShowLayerCount = (bool)x);
         }
         }
 
 
         public void Start()
         public void Start()
@@ -65,37 +113,29 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
                 return;
                 return;
             }
             }
 
 
-            RichPresence richPresence = new RichPresence
-            {
-                Assets = new Assets
-                {
-                    LargeImageKey = "editorlogo",
-                    LargeImageText = "You discovered PixiEditor's logo",
-                    SmallImageKey = "github",
-                    SmallImageText = "Download PixiEditor on GitHub (please)!"
-                }
-            };
+            RichPresence richPresence = NewDefaultRP();
 
 
-            if (document == null)
-            {
-                richPresence.WithTimestamps(new Timestamps(DateTime.UtcNow));
-                richPresence.Details = "Staring at absolutely";
-                richPresence.State = "nothing";
-            }
-            else
+            if (document != null)
             {
             {
                 richPresence.WithTimestamps(new Timestamps(document.OpenedUTC));
                 richPresence.WithTimestamps(new Timestamps(document.OpenedUTC));
-                richPresence.Details = $"Editing {document.Name}";
 
 
-                string state = $"{document.Width}x{document.Height}, ";
+                richPresence.Details = ShowDocumentName ? $"Editing {document.Name}" : "Editing something (incognito)";
 
 
-                if (document.Layers.Count == 1)
+                string state = string.Empty;
+
+                if (ShowDocumentSize)
                 {
                 {
-                    state += "1 Layer";
+                    state = $"{document.Width}x{document.Height}";
                 }
                 }
-                else
+
+                if (ShowDocumentSize && ShowLayerCount)
+                {
+                    state += ", ";
+                }
+
+                if (ShowLayerCount)
                 {
                 {
-                    state += $"{document.Layers.Count} Layers";
+                    state += document.Layers.Count == 1 ? "1 Layer" : $"{document.Layers.Count} Layers";
                 }
                 }
 
 
                 richPresence.State = state;
                 richPresence.State = state;
@@ -104,6 +144,27 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             client.SetPresence(richPresence);
             client.SetPresence(richPresence);
         }
         }
 
 
+        private static RichPresence NewDefaultRP()
+        {
+            return new RichPresence
+            {
+                Details = "Staring at absolutely",
+                State = "nothing",
+
+                Assets = new Assets
+                {
+                    LargeImageKey = "editorlogo",
+                    LargeImageText = "You discovered PixiEditor's logo",
+                    SmallImageKey = "github",
+                    SmallImageText = "Download PixiEditor on GitHub (github.com/PixiEditor/PixiEditor)!"
+                },
+                Timestamps = new Timestamps()
+                {
+                    Start = DateTime.UtcNow
+                }
+            };
+        }
+
         private void DocumentChanged(object sender, Models.Events.DocumentChangedEventArgs e)
         private void DocumentChanged(object sender, Models.Events.DocumentChangedEventArgs e)
         {
         {
             if (currentDocument != null)
             if (currentDocument != null)

+ 29 - 0
PixiEditor/ViewModels/SubViewModels/UserPreferences/SettingsGroup.cs

@@ -0,0 +1,29 @@
+using System.ComponentModel;
+using PixiEditor.Helpers;
+using PixiEditor.Models.UserPreferences;
+
+namespace PixiEditor.ViewModels.SubViewModels.UserPreferences
+{
+    public class SettingsGroup : NotifyableObject
+    {
+        protected static T GetPreference<T>(string name)
+        {
+            return PreferencesSettings.GetPreference<T>(name);
+        }
+
+#nullable enable
+
+        protected static T? GetPreference<T>(string name, T? fallbackValue)
+        {
+            return PreferencesSettings.GetPreference(name, fallbackValue);
+        }
+
+#nullable disable
+
+        protected void RaiseAndUpdatePreference<T>(string name, T value)
+        {
+            RaisePropertyChanged(name);
+            PreferencesSettings.UpdatePreference(name, value);
+        }
+    }
+}

+ 84 - 7
PixiEditor/ViewModels/SubViewModels/UserPreferences/SettingsViewModel.cs

@@ -58,18 +58,95 @@ namespace PixiEditor.ViewModels.SubViewModels.UserPreferences
             }
             }
         }
         }
 
 
-        private bool enableRichPresence = PreferencesSettings.GetPreference<bool>(nameof(EnableRichPresence));
-
-        public bool EnableRichPresence
+        public class DiscordSettings : SettingsGroup
         {
         {
-            get => enableRichPresence;
-            set
+            private bool enableRichPresence = GetPreference(nameof(EnableRichPresence), true);
+
+            public bool EnableRichPresence
+            {
+                get => enableRichPresence;
+                set
+                {
+                    enableRichPresence = value;
+                    RaiseAndUpdatePreference(nameof(EnableRichPresence), value);
+                }
+            }
+
+            private bool showDocumentName = GetPreference(nameof(ShowDocumentName), true);
+
+            public bool ShowDocumentName
+            {
+                get => showDocumentName;
+                set
+                {
+                    showDocumentName = value;
+                    RaiseAndUpdatePreference(nameof(ShowDocumentName), value);
+                    RaisePropertyChanged(nameof(DetailPreview));
+                }
+            }
+
+            private bool showDocumentSize = GetPreference(nameof(ShowDocumentSize), true);
+
+            public bool ShowDocumentSize
+            {
+                get => showDocumentSize;
+                set
+                {
+                    showDocumentSize = value;
+                    RaiseAndUpdatePreference(nameof(ShowDocumentSize), value);
+                    RaisePropertyChanged(nameof(StatePreview));
+                }
+            }
+
+            private bool showLayerCount = GetPreference(nameof(ShowLayerCount), true);
+
+            public bool ShowLayerCount
             {
             {
-                enableRichPresence = value;
-                RaiseAndUpdatePreference(nameof(EnableRichPresence), value);
+                get => showLayerCount;
+                set
+                {
+                    showLayerCount = value;
+                    RaiseAndUpdatePreference(nameof(ShowLayerCount), value);
+                    RaisePropertyChanged(nameof(StatePreview));
+                }
+            }
+
+            public string DetailPreview
+            {
+                get
+                {
+                    return ShowDocumentName ? $"Editing coolPixelArt.pixi" : "Editing something (incognito)";
+                }
+            }
+
+            public string StatePreview
+            {
+                get
+                {
+                    string state = string.Empty;
+
+                    if (ShowDocumentSize)
+                    {
+                        state = "16x16";
+                    }
+
+                    if (ShowDocumentSize && ShowLayerCount)
+                    {
+                        state += ", ";
+                    }
+
+                    if (ShowLayerCount)
+                    {
+                        state += "2 Layers";
+                    }
+
+                    return state;
+                }
             }
             }
         }
         }
 
 
+        public DiscordSettings Discord { get; set; } = new DiscordSettings();
+
         public void RaiseAndUpdatePreference<T>(string name, T value)
         public void RaiseAndUpdatePreference<T>(string name, T value)
         {
         {
             RaisePropertyChanged(name);
             RaisePropertyChanged(name);

+ 9 - 3
PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -3,10 +3,12 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        xmlns:local="clr-namespace:PixiEditor.Views.Dialogs" xmlns:viewmodels="clr-namespace:PixiEditor.ViewModels" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters" xmlns:views="clr-namespace:PixiEditor.Views" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours"
+        xmlns:local="clr-namespace:PixiEditor.Views.Dialogs" xmlns:viewmodels="clr-namespace:PixiEditor.ViewModels" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters" xmlns:views="clr-namespace:PixiEditor.Views" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls"
         mc:Ignorable="d"
         mc:Ignorable="d"
         Title="Settings" Name="window" 
         Title="Settings" Name="window" 
-        Height="450" Width="800" WindowStyle="None" DataContext="{DynamicResource SettingsWindowViewModel}"
+        Height="600" Width="800"
+        MinHeight="350" MinWidth="600"
+        WindowStyle="None" DataContext="{DynamicResource SettingsWindowViewModel}"
         BorderBrush="Black" BorderThickness="1">
         BorderBrush="Black" BorderThickness="1">
     <Window.Resources>
     <Window.Resources>
         <viewmodels:SettingsWindowViewModel x:Key="SettingsWindowViewModel"/>
         <viewmodels:SettingsWindowViewModel x:Key="SettingsWindowViewModel"/>
@@ -81,7 +83,11 @@
                 <StackPanel Orientation="Vertical">
                 <StackPanel Orientation="Vertical">
                     <Label Style="{StaticResource Header1}" Content="Rich Presence"/>
                     <Label Style="{StaticResource Header1}" Content="Rich Presence"/>
                     <StackPanel Orientation="Vertical" Margin="50 0 50 0">
                     <StackPanel Orientation="Vertical" Margin="50 0 50 0">
-                        <CheckBox IsChecked="{Binding SettingsSubViewModel.EnableRichPresence}" Content="Enable"/>
+                        <CheckBox Margin="5" IsChecked="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" Content="Enabled"/>
+                        <CheckBox Margin="5" IsEnabled="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" IsChecked="{Binding SettingsSubViewModel.Discord.ShowDocumentName}" Content="Show Document Name"/>
+                        <CheckBox Margin="5" IsEnabled="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" IsChecked="{Binding SettingsSubViewModel.Discord.ShowDocumentSize}" Content="Show Document Size"/>
+                        <CheckBox Margin="5" IsEnabled="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" IsChecked="{Binding SettingsSubViewModel.Discord.ShowLayerCount}" Content="Show Layer Count"/>
+                        <usercontrols:DiscordRPPreview Margin="5" State="{Binding SettingsSubViewModel.Discord.StatePreview}" Detail="{Binding SettingsSubViewModel.Discord.DetailPreview}" Width="280" IsPlaying="{Binding SettingsSubViewModel.Discord.EnableRichPresence}"/>
                     </StackPanel>
                     </StackPanel>
                 </StackPanel>
                 </StackPanel>
             </Grid>
             </Grid>

+ 64 - 0
PixiEditor/Views/UserControls/DiscordRPPreview.xaml

@@ -0,0 +1,64 @@
+<UserControl x:Class="PixiEditor.Views.UserControls.DiscordRPPreview"
+             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:PixiEditor.Views.UserControls" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+             mc:Ignorable="d" 
+             d:DesignHeight="280" d:DesignWidth="300"
+             x:Name="uc">
+    <UserControl.Resources>
+        <converters:EmptyStringToVisibiltyConverter x:Key="EmptyStringToVisibilty"/>
+        <converters:BoolToVisibiltyConverter x:Key="BoolToVisibilty"/>
+        <converters:BoolToDiscordBrush x:Key="BoolToDiscordColor"/>
+    </UserControl.Resources>
+    <Grid>
+        <Grid.OpacityMask>
+            <VisualBrush Visual="{Binding ElementName=OutsideBorder}"/>
+        </Grid.OpacityMask>
+        <Border CornerRadius="5" Background="{Binding ElementName=uc, Path=IsPlaying, Converter={StaticResource BoolToDiscordColor}}" x:Name="OutsideBorder"/>
+        <Grid x:Name="background">
+            <Grid.RowDefinitions>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="Auto"/>
+                </Grid.RowDefinitions>
+
+                <Grid VerticalAlignment="Center">
+                    <StackPanel>
+                        <Grid  Width="80" Height="80" Margin="20">
+                            <Image Source="{Binding ElementName=uc, Path=UserSource}"/>
+                        <Border Height="30" Width="30" Background="#FF43B581" CornerRadius="90" BorderThickness="5" BorderBrush="{Binding ElementName=uc, Path=IsPlaying, Converter={StaticResource BoolToDiscordColor}}">
+                                <Border.RenderTransform>
+                                    <TransformGroup>
+                                        <TranslateTransform X="27" Y="27"></TranslateTransform>
+                                    </TransformGroup>
+                                </Border.RenderTransform>
+                            </Border>
+                        </Grid>
+
+                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,15">
+                            <TextBlock Foreground="White" FontSize="16" FontWeight="SemiBold">PixiBot</TextBlock>
+                            <TextBlock Foreground="White" FontSize="16">#8523</TextBlock>
+                            <Border CornerRadius="3" BorderThickness="1" Background="White" Margin="5,0,0,0" VerticalAlignment="Center">
+                                <TextBlock Foreground="#FF7289DA" FontSize="12" Margin="4,2,4,2" FontWeight="Medium">BOT</TextBlock>
+                            </Border>
+                        </StackPanel>
+                    </StackPanel>
+                </Grid>
+                <Grid Grid.Row="1" Background="#0D000000" Visibility="{Binding ElementName=uc, Path=IsPlaying, Converter={StaticResource BoolToVisibilty}}">
+                    <StackPanel Orientation="Vertical" Margin="15">
+                        <TextBlock FontWeight="Bold" FontSize="12" Foreground="White" Margin="0,0,0,10">PLAYING A "GAME"</TextBlock>
+                        <StackPanel Orientation="Horizontal">
+                            <Image Source="../../Images/PixiEditorLogo.png" Height="70"/>
+                            <StackPanel Margin="15,0,0,0" VerticalAlignment="Center">
+                                <TextBlock Foreground="White" FontSize="12" FontWeight="SemiBold">PixiEditor</TextBlock>
+                            <TextBlock Foreground="White" FontSize="12" Text="{Binding ElementName=uc, Path=Detail}" Visibility="{Binding ElementName=uc, Path=Detail, Converter={StaticResource EmptyStringToVisibilty}}"/>
+                            <TextBlock Foreground="White" FontSize="12" Text="{Binding ElementName=uc, Path=State}" Visibility="{Binding ElementName=uc, Path=State, Converter={StaticResource EmptyStringToVisibilty}}"/>
+                            <TextBlock Foreground="White" FontSize="12">00:00 elapsed</TextBlock>
+                            </StackPanel>
+                        </StackPanel>
+                    </StackPanel>
+                </Grid>
+            </Grid>
+        </Grid>
+</UserControl>

+ 67 - 0
PixiEditor/Views/UserControls/DiscordRPPreview.xaml.cs

@@ -0,0 +1,67 @@
+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 PixiEditor.Views.UserControls
+{
+    /// <summary>
+    /// Interaction logic for DiscordRPPreview.xaml
+    /// </summary>
+    public partial class DiscordRPPreview : UserControl
+    {
+        public static readonly DependencyProperty StateProperty =
+               DependencyProperty.Register(nameof(State), typeof(string), typeof(DiscordRPPreview), new PropertyMetadata("nothing"));
+
+        public string State
+        {
+            get => (string)GetValue(StateProperty);
+            set => SetValue(StateProperty, value);
+        }
+
+        public static readonly DependencyProperty DetailProperty =
+                DependencyProperty.Register(nameof(Detail), typeof(string), typeof(DiscordRPPreview), new PropertyMetadata("Staring at absolutely"));
+
+        public string Detail
+        {
+            get => (string)GetValue(DetailProperty);
+            set => SetValue(DetailProperty, value);
+        }
+
+        public static readonly DependencyProperty UserSourceProperty =
+                DependencyProperty.Register(nameof(UserSource), typeof(string), typeof(DiscordRPPreview), new PropertyMetadata("../../Images/pixiBotLogo.png"));
+
+        public string UserSource
+        {
+            get => (string)GetValue(UserSourceProperty);
+            set => SetValue(UserSourceProperty, value);
+        }
+
+        public static readonly DependencyProperty IsPlayingProperty =
+                DependencyProperty.Register(nameof(IsPlaying), typeof(bool), typeof(DiscordRPPreview), new PropertyMetadata(true));
+
+        public bool IsPlaying
+        {
+            get => (bool)GetValue(IsPlayingProperty);
+            set
+            {
+                SetValue(IsPlayingProperty, value);
+            }
+        }
+
+        public DiscordRPPreview()
+        {
+            InitializeComponent();
+        }
+    }
+}