Selaa lähdekoodia

Finished filtering

flabbet 3 vuotta sitten
vanhempi
commit
7ad2bca366

+ 16 - 0
PixiEditor/Models/Enums/ColorsNumberMode.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PixiEditor.Models.Enums
+{
+    public enum ColorsNumberMode
+    {
+        Any,
+        Max,
+        Min,
+        Exact
+    }
+}

+ 9 - 2
PixiEditor/Models/ExternalServices/LospecPaletteFetcher.cs

@@ -1,5 +1,6 @@
 using Newtonsoft.Json;
 using Newtonsoft.Json;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Enums;
 using System;
 using System;
 using System.Linq;
 using System.Linq;
 using System.Net;
 using System.Net;
@@ -11,19 +12,25 @@ namespace PixiEditor.Models.ExternalServices
     public static class LospecPaletteFetcher
     public static class LospecPaletteFetcher
     {
     {
         public const string LospecApiUrl = "https://lospec.com/palette-list";
         public const string LospecApiUrl = "https://lospec.com/palette-list";
-        public static async Task<PaletteList> FetchPage(int page, string sortingType = "default", string[] tags = null)
+        public static async Task<PaletteList> FetchPage(int page, string sortingType = "default", string[] tags = null, 
+            ColorsNumberMode colorsNumberMode = ColorsNumberMode.Any, int colorNumber = 8)
         {
         {
             try
             try
             {
             {
                 using (HttpClient client = new HttpClient())
                 using (HttpClient client = new HttpClient())
                 {
                 {
-                    string url = @$"{LospecApiUrl}/load?colorNumberFilterType=any&page={page}&sortingType={sortingType}&tag=";
+                    string url = @$"{LospecApiUrl}/load?colorNumberFilterType={colorsNumberMode.ToString().ToLower()}&page={page}&sortingType={sortingType}&tag=";
                     
                     
                     if(tags != null && tags.Length > 0)
                     if(tags != null && tags.Length > 0)
                     {
                     {
                         url += $"{string.Join(',', tags)}";
                         url += $"{string.Join(',', tags)}";
                     }
                     }
 
 
+                    if(colorsNumberMode != ColorsNumberMode.Any)
+                    {
+                        url += $"&colorNumber={colorNumber}";
+                    }
+
                     HttpResponseMessage response = await client.GetAsync(url);
                     HttpResponseMessage response = await client.GetAsync(url);
                     if (response.StatusCode == HttpStatusCode.OK)
                     if (response.StatusCode == HttpStatusCode.OK)
                     {
                     {

+ 10 - 1
PixiEditor/Views/Dialogs/LospecPalettesBrowser.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls.Lospec" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls.Lospec" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              mc:Ignorable="d" 
              mc:Ignorable="d" 
-             xmlns:gif="http://wpfanimatedgif.codeplex.com" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls"
+             xmlns:gif="http://wpfanimatedgif.codeplex.com" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls" xmlns:views="clr-namespace:PixiEditor.Views"
         Title="Palettes Browser" WindowStartupLocation="CenterScreen" MinWidth="200" Height="600" Width="800" WindowStyle="None"
         Title="Palettes Browser" WindowStartupLocation="CenterScreen" MinWidth="200" Height="600" Width="800" WindowStyle="None"
              Name="lospecPalettesBrowser">
              Name="lospecPalettesBrowser">
     <Window.Resources>
     <Window.Resources>
@@ -46,6 +46,15 @@
                 <Label Margin="10 0 0 0" Content="Tags:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center" FontSize="16"/>
                 <Label Margin="10 0 0 0" Content="Tags:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center" FontSize="16"/>
                 <usercontrols:InputBox OnSubmit="TagsInput_OnSubmit" FontSize="16" VerticalAlignment="Center" 
                 <usercontrols:InputBox OnSubmit="TagsInput_OnSubmit" FontSize="16" VerticalAlignment="Center" 
                                        Style="{StaticResource DarkTextBoxStyle}" Width="250" />
                                        Style="{StaticResource DarkTextBoxStyle}" Width="250" />
+                <Label Margin="10 0 0 0" Content="Colors:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center" FontSize="16"/>
+                <ComboBox Name="colorsComboBox" FontSize="16" VerticalAlignment="Center" SelectionChanged="ColorsComboBox_SelectionChanged">
+                    <ComboBoxItem IsSelected="True">Any</ComboBoxItem>
+                    <ComboBoxItem>Max</ComboBoxItem>
+                    <ComboBoxItem>Min</ComboBoxItem>
+                    <ComboBoxItem>Exact</ComboBoxItem>
+                </ComboBox>
+                <views:NumberInput Width="50" FontSize="16" VerticalAlignment="Center" Margin="10 0 0 0" 
+                                   Value="{Binding ElementName=lospecPalettesBrowser, Path=ColorsNumber, Mode=TwoWay}"/>
             </StackPanel>
             </StackPanel>
         </StackPanel>
         </StackPanel>
         <Grid Grid.Row="2" Margin="10">
         <Grid Grid.Row="2" Margin="10">

+ 33 - 4
PixiEditor/Views/Dialogs/LospecPalettesBrowser.xaml.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Enums;
 using PixiEditor.Models.Events;
 using PixiEditor.Models.Events;
 using PixiEditor.Models.ExternalServices;
 using PixiEditor.Models.ExternalServices;
 using System;
 using System;
@@ -58,11 +59,27 @@ namespace PixiEditor.Views.Dialogs
         public static readonly DependencyProperty IsFetchingProperty =
         public static readonly DependencyProperty IsFetchingProperty =
             DependencyProperty.Register("IsFetching", typeof(bool), typeof(LospecPalettesBrowser), new PropertyMetadata(false));
             DependencyProperty.Register("IsFetching", typeof(bool), typeof(LospecPalettesBrowser), new PropertyMetadata(false));
 
 
+        public int ColorsNumber
+        {
+            get { return (int)GetValue(ColorsNumberProperty); }
+            set { SetValue(ColorsNumberProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ColorsNumber.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ColorsNumberProperty =
+            DependencyProperty.Register("ColorsNumber", typeof(int), typeof(LospecPalettesBrowser), 
+                new PropertyMetadata(8, ColorsNumberChanged));
+
         public string SortingType { get; set; } = "Default";
         public string SortingType { get; set; } = "Default";
+        public ColorsNumberMode ColorsNumberMode { get; set; } = ColorsNumberMode.Any;
         public string[] Tags { get; set; } = Array.Empty<string>();
         public string[] Tags { get; set; } = Array.Empty<string>();
 
 
         private char[] _separators = new char[] { ' ', ',' };
         private char[] _separators = new char[] { ' ', ',' };
 
 
+        public LospecPalettesBrowser()
+        {
+            InitializeComponent();
+        }
 
 
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
         {
@@ -74,18 +91,19 @@ namespace PixiEditor.Views.Dialogs
             SystemCommands.CloseWindow(this);
             SystemCommands.CloseWindow(this);
         }
         }
 
 
-
-        public LospecPalettesBrowser()
+        private static async void ColorsNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
         {
-            InitializeComponent();
+            LospecPalettesBrowser browser = (LospecPalettesBrowser)d;
+            await browser.UpdatePaletteList(true);
         }
         }
 
 
+
         public async Task UpdatePaletteList(bool refetch = false)
         public async Task UpdatePaletteList(bool refetch = false)
         {
         {
             IsFetching = true;
             IsFetching = true;
             if (PaletteList == null || refetch)
             if (PaletteList == null || refetch)
             {
             {
-                PaletteList = await LospecPaletteFetcher.FetchPage(0, SortingType.ToLower(), Tags);
+                PaletteList = await LospecPaletteFetcher.FetchPage(0, SortingType.ToLower(), Tags, ColorsNumberMode, ColorsNumber);
                 OnListFetched.Invoke(PaletteList);
                 OnListFetched.Invoke(PaletteList);
             }
             }
 
 
@@ -130,6 +148,17 @@ namespace PixiEditor.Views.Dialogs
             scrollViewer.ScrollToHome();
             scrollViewer.ScrollToHome();
         }
         }
 
 
+
+        private async void ColorsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            if (e.AddedItems != null && e.AddedItems.Count > 0 && e.AddedItems[0] is ComboBoxItem item && item.Content is string value)
+            {
+                ColorsNumberMode = Enum.Parse<ColorsNumberMode>(value);
+                await UpdatePaletteList(true);
+                scrollViewer.ScrollToHome();
+            }
+        }
+
         private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
         private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
         {
         {
             ((Grid)sender).Focus();
             ((Grid)sender).Focus();