Browse Source

some initial working

flabbet 3 years ago
parent
commit
1101103f96

+ 13 - 0
PixiEditor/Models/DataHolders/LospecPalette/LospecUser.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PixiEditor.Models.DataHolders.LospecPalette
+{
+    public class LospecUser
+    {
+        public string Name { get; set; }
+    }
+}

+ 13 - 0
PixiEditor/Models/DataHolders/LospecPalette/Palette.cs

@@ -0,0 +1,13 @@
+using PixiEditor.Models.DataHolders.LospecPalette;
+using SkiaSharp;
+using System.Collections.Generic;
+
+namespace PixiEditor.Models.DataHolders
+{
+    public class Palette
+    {
+        public string Title { get; set; }
+        public LospecUser User { get; set; }
+        public ObservableCollection<string> Colors { get; set; }
+    }
+}

+ 9 - 0
PixiEditor/Models/DataHolders/LospecPalette/PaletteList.cs

@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+
+namespace PixiEditor.Models.DataHolders
+{
+    public class PaletteList
+    {
+        public List<Palette> Palettes { get; set; }
+    }
+}

+ 28 - 0
PixiEditor/Models/ExternalServices/LospecPaletteFetcher.cs

@@ -0,0 +1,28 @@
+using Newtonsoft.Json;
+using PixiEditor.Models.DataHolders;
+using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+namespace PixiEditor.Models.ExternalServices
+{
+    public static class LospecPaletteFetcher
+    {
+        public const string LospecApiUrl = "https://lospec.com/palette-list";
+        public static async Task<PaletteList> FetchPage(int page)
+        {
+            using (HttpClient client = new HttpClient())
+            {
+                string url = @$"{LospecApiUrl}/load?colorNumberFilterType=any&page={page}&tag=&sortingType=default";
+                HttpResponseMessage response = await client.GetAsync(url);
+                if (response.StatusCode == HttpStatusCode.OK)
+                {
+                    string content = await response.Content.ReadAsStringAsync();
+                    return JsonConvert.DeserializeObject<PaletteList>(content);
+                }
+            }
+
+            return null;
+        }
+    }
+}

+ 7 - 2
PixiEditor/Views/MainWindow.xaml

@@ -13,7 +13,7 @@
         xmlns:cmd="http://www.galasoft.ch/mvvmlight" 
         xmlns:avalondock="https://github.com/Dirkster99/AvalonDock"
         xmlns:colorpicker="clr-namespace:ColorPicker;assembly=ColorPicker" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls" xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours" 
-        xmlns:avalonDockTheme="clr-namespace:PixiEditor.Styles.AvalonDock" xmlns:layerUserControls="clr-namespace:PixiEditor.Views.UserControls.Layers" xmlns:sys="clr-namespace:System;assembly=System.Runtime" d:DataContext="{d:DesignInstance Type=vm:ViewModelMain}"
+        xmlns:avalonDockTheme="clr-namespace:PixiEditor.Styles.AvalonDock" xmlns:layerUserControls="clr-namespace:PixiEditor.Views.UserControls.Layers" xmlns:sys="clr-namespace:System;assembly=System.Runtime" xmlns:lospec="clr-namespace:PixiEditor.Views.UserControls.Lospec" d:DataContext="{d:DesignInstance Type=vm:ViewModelMain}"
         mc:Ignorable="d" WindowStyle="None" Initialized="MainWindow_Initialized"
         Title="PixiEditor" Name="mainWindow" Height="1000" Width="1600" Background="{StaticResource MainColor}"
         WindowStartupLocation="CenterScreen" WindowState="Maximized">
@@ -343,7 +343,7 @@
                                     <avalondock:LayoutAnchorable ContentId="palette" Title="Palette" CanHide="False"
                                                                  CanClose="False" CanAutoHide="False"
                                                                  CanDockAsTabbedDocument="False" CanFloat="True">
-                                        <usercontrols:Palette Colors="{Binding BitmapManager.ActiveDocument.Palette}"
+                                        <usercontrols:PaletteViewer Colors="{Binding BitmapManager.ActiveDocument.Palette}"
                                                               SelectColorCommand="{Binding ColorsSubViewModel.SelectColorCommand}"/>
                                     </avalondock:LayoutAnchorable>
                                     <avalondock:LayoutAnchorable ContentId="swatches" Title="Swatches" CanHide="False"
@@ -353,6 +353,11 @@
                                             SelectSwatchCommand="{Binding ColorsSubViewModel.SelectColorCommand}"
                                             Swatches="{Binding BitmapManager.ActiveDocument.Swatches}"/>
                                     </avalondock:LayoutAnchorable>
+                                    <avalondock:LayoutAnchorable ContentId="paletteBrowser" Title="Palette Browser" CanHide="False"
+                                                                 CanClose="False" CanAutoHide="False"
+                                                                 CanDockAsTabbedDocument="False" CanFloat="True">
+                                        <lospec:LospecPalettesBrowser/>
+                                    </avalondock:LayoutAnchorable>
 
                                 </LayoutAnchorablePane>
                                 <LayoutAnchorablePane>

+ 0 - 28
PixiEditor/Views/UserControls/Lospec/LospecPaletteBrowser.xaml.cs

@@ -1,28 +0,0 @@
-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.Lospec
-{
-    /// <summary>
-    /// Interaction logic for LospecPaletteBrowser.xaml
-    /// </summary>
-    public partial class LospecPaletteBrowser : UserControl
-    {
-        public LospecPaletteBrowser()
-        {
-            InitializeComponent();
-        }
-    }
-}

+ 6 - 5
PixiEditor/Views/UserControls/Lospec/LospecPaletteItem.xaml

@@ -8,18 +8,18 @@
              d:DesignHeight="100" d:DesignWidth="250" Name="paletteItem">
     <Grid>
         <Grid.ColumnDefinitions>
-            <ColumnDefinition Width="4*"/>
-            <ColumnDefinition/>
+            <ColumnDefinition Width="84*"/>
+            <ColumnDefinition Width="41*"/>
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
             <RowDefinition Height="35"/>
             <RowDefinition Height="65"/>
         </Grid.RowDefinitions>
         <StackPanel Orientation="Vertical" Grid.RowSpan="2" Grid.ColumnSpan="2">
-            <TextBlock Text="Palette Name" Foreground="White"/>
-            <TextBlock Text="Palette Creator" Foreground="White"/>
+            <TextBlock Text="{Binding Palette.Title, ElementName=paletteItem}" Foreground="White"/>
+            <TextBlock Text="{Binding Palette.User.Name, ElementName=paletteItem}" Foreground="White"/>
         </StackPanel>
-        <ItemsControl Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ElementName=paletteItem, Path=Colors}">
+        <ItemsControl Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ElementName=paletteItem, Path=Palette.Colors}">
             <ItemsControl.ItemsPanel>
                 <ItemsPanelTemplate>
                     <WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
@@ -31,5 +31,6 @@
                 </DataTemplate>
             </ItemsControl.ItemTemplate>
         </ItemsControl>
+        <Button Grid.Row="1" Grid.Column="1"  Content="Import" Style="{StaticResource AccentDarkRoundButton}"/>
     </Grid>
 </UserControl>

+ 8 - 7
PixiEditor/Views/UserControls/Lospec/LospecPaletteItem.xaml.cs

@@ -1,4 +1,5 @@
-using SkiaSharp;
+using PixiEditor.Models.DataHolders;
+using SkiaSharp;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -22,15 +23,15 @@ namespace PixiEditor.Views.UserControls.Lospec
     /// </summary>
     public partial class LospecPaletteItem : UserControl
     {
-        public ObservableCollection<SKColor> Colors
+        public Palette Palette
         {
-            get { return (ObservableCollection<SKColor>)GetValue(ColorsProperty); }
-            set { SetValue(ColorsProperty, value); }
+            get { return (Palette)GetValue(PaletteProperty); }
+            set { SetValue(PaletteProperty, value); }
         }
 
-        // Using a DependencyProperty as the backing store for Colors.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty ColorsProperty =
-            DependencyProperty.Register("Colors", typeof(ObservableCollection<SKColor>), typeof(LospecPaletteItem));
+        // Using a DependencyProperty as the backing store for Palette.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty PaletteProperty =
+            DependencyProperty.Register("Palette", typeof(Palette), typeof(LospecPaletteItem), new PropertyMetadata(null));
 
 
         public LospecPaletteItem()

+ 10 - 4
PixiEditor/Views/UserControls/Lospec/LospecPaletteBrowser.xaml → PixiEditor/Views/UserControls/Lospec/LospecPalettesBrowser.xaml

@@ -1,12 +1,18 @@
-<UserControl x:Class="PixiEditor.Views.UserControls.Lospec.LospecPaletteBrowser"
+<UserControl x:Class="PixiEditor.Views.UserControls.Lospec.LospecPalettesBrowser"
              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:local="clr-namespace:PixiEditor.Views.UserControls.Lospec"
              mc:Ignorable="d" 
-             d:DesignHeight="400" d:DesignWidth="250">
+             d:DesignHeight="400" d:DesignWidth="250" GotFocus="UserControl_GotFocus" Name="lospecPalettesBrowser">
     <Grid>
-            
+        <ItemsControl ItemsSource="{Binding ElementName=lospecPalettesBrowser, Path=PaletteList.Palettes}">
+            <ItemsControl.ItemTemplate>
+                <DataTemplate>
+                    <local:LospecPaletteItem Palette="{Binding}"/>
+                </DataTemplate>
+            </ItemsControl.ItemTemplate>
+        </ItemsControl>   
     </Grid>
 </UserControl>

+ 47 - 0
PixiEditor/Views/UserControls/Lospec/LospecPalettesBrowser.xaml.cs

@@ -0,0 +1,47 @@
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.ExternalServices;
+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.Lospec
+{
+    /// <summary>
+    /// Interaction logic for LospecPalettesBrowser.xaml
+    /// </summary>
+    public partial class LospecPalettesBrowser : UserControl
+    {
+        public PaletteList PaletteList
+        {
+            get { return (PaletteList)GetValue(PaletteListProperty); }
+            set { SetValue(PaletteListProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for PaletteList.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty PaletteListProperty =
+            DependencyProperty.Register("PaletteList", typeof(PaletteList), typeof(LospecPalettesBrowser));
+
+
+        public LospecPalettesBrowser()
+        {
+            InitializeComponent();
+        }
+
+        private async void UserControl_GotFocus(object sender, RoutedEventArgs e)
+        {
+            if(PaletteList == null)
+                PaletteList = await LospecPaletteFetcher.FetchPage(0);
+        }
+    }
+}

+ 2 - 2
PixiEditor/Views/UserControls/Palette.xaml → PixiEditor/Views/UserControls/PaletteViewer.xaml

@@ -1,4 +1,4 @@
-<UserControl x:Class="PixiEditor.Views.UserControls.Palette"
+<UserControl x:Class="PixiEditor.Views.UserControls.PaletteViewer"
              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" 
@@ -66,7 +66,7 @@
                             <b:Interaction.Triggers>
                                 <b:EventTrigger EventName="MouseUp">
                                     <b:InvokeCommandAction
-                                    Command="{Binding SelectColorCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Palette}}}"
+                                    Command="{Binding SelectColorCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PaletteViewer}}}"
                                     CommandParameter="{Binding}" />
                                 </b:EventTrigger>
                             </b:Interaction.Triggers>

+ 4 - 4
PixiEditor/Views/UserControls/Palette.xaml.cs → PixiEditor/Views/UserControls/PaletteViewer.xaml.cs

@@ -12,12 +12,12 @@ namespace PixiEditor.Views.UserControls
     /// <summary>
     /// Interaction logic for Palette.xaml
     /// </summary>
-    public partial class Palette : UserControl
+    public partial class PaletteViewer : UserControl
     {
         public const string PaletteColorDaoFormat = "PixiEditor.PaletteColor";
 
         public static readonly DependencyProperty ColorsProperty = DependencyProperty.Register(
-            "Colors", typeof(ObservableCollection<SKColor>), typeof(Palette));
+            "Colors", typeof(ObservableCollection<SKColor>), typeof(PaletteViewer));
 
         public ObservableCollection<SKColor> Colors
         {
@@ -33,9 +33,9 @@ namespace PixiEditor.Views.UserControls
 
         // Using a DependencyProperty as the backing store for SelectColorCommand.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty SelectColorCommandProperty =
-            DependencyProperty.Register("SelectColorCommand", typeof(ICommand), typeof(Palette));
+            DependencyProperty.Register("SelectColorCommand", typeof(ICommand), typeof(PaletteViewer));
 
-        public Palette()
+        public PaletteViewer()
         {
             InitializeComponent();
         }

+ 14 - 0
PixiEditorTests/ModelsTests/LospecPaletteFetcher/LospecPaletteFetcherTests.cs

@@ -0,0 +1,14 @@
+using Xunit;
+
+namespace PixiEditorTests.ModelsTests.LospecPaletteFetcher
+{
+    public class LospecPaletteFetcherTests
+    {
+        [Fact]
+        public async void TestThatLospecPaletteFetcherFetchesData()
+        {
+            var result = await PixiEditor.Models.ExternalServices.LospecPaletteFetcher.FetchPage(0);
+            Assert.NotEmpty(result.Palettes);
+        }
+    }
+}