Преглед на файлове

Added buy pack in palette browser and donate icon on Steam

Krzysztof Krysiński преди 2 години
родител
ревизия
c2cf012dbd

+ 1 - 0
src/PixiEditor.Extensions/Common/UserPreferences/PreferencesConstants.cs

@@ -7,4 +7,5 @@ public static class PreferencesConstants
 
     public const string MaxOpenedRecently = "MaxOpenedRecently";
     public const int MaxOpenedRecentlyDefault = 8;
+    public const string HideBuySupporterPackText = "HideBuySupporterPackText";
 }

+ 1 - 1
src/PixiEditor.Extensions/PixiEditor.Extensions.csproj

@@ -6,7 +6,7 @@
         <Nullable>enable</Nullable>
       <UseWPF>true</UseWPF>
       <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
-      <Version>0.0.7</Version>
+      <Version>0.0.3</Version>
       <Title>PixiEditor Extensions</Title>
       <Authors>PixiEditor Organization</Authors>
       <Copyright>PixiEditor Organization</Copyright>

+ 17 - 2
src/PixiEditor.Platform.MSStore/MSAdditionalContentProvider.cs

@@ -2,8 +2,23 @@
 
 public sealed class MSAdditionalContentProvider : IAdditionalContentProvider
 {
-    public bool IsContentAvailable(AdditionalContentProduct product)
+    public bool IsContentInstalled(AdditionalContentProduct product)
     {
-        return true;
+        if(!PlatformHasContent(product)) return false;
+
+        return product switch
+        {
+            AdditionalContentProduct.SupporterPack => false,
+            _ => false
+        };
+    }
+
+    public bool PlatformHasContent(AdditionalContentProduct product)
+    {
+        return product switch
+        {
+            AdditionalContentProduct.SupporterPack => false,
+            _ => false
+        };
     }
 }

+ 11 - 1
src/PixiEditor.Platform.Standalone/StandaloneAdditionalContentProvider.cs

@@ -2,7 +2,17 @@
 
 public sealed class StandaloneAdditionalContentProvider : IAdditionalContentProvider
 {
-    public bool IsContentAvailable(AdditionalContentProduct product)
+    public bool IsContentInstalled(AdditionalContentProduct product)
+    {
+        if(!PlatformHasContent(product)) return false;
+#if DEBUG
+        return true;
+#else
+        return false;
+#endif
+    }
+
+    public bool PlatformHasContent(AdditionalContentProduct product)
     {
 #if DEBUG
         return true;

+ 7 - 2
src/PixiEditor.Platform.Steam/SteamAdditionalContentProvider.cs

@@ -9,11 +9,16 @@ public sealed class SteamAdditionalContentProvider : IAdditionalContentProvider
         { AdditionalContentProduct.SupporterPack, new AppId_t(2435860) }
     };
 
-    public bool IsContentAvailable(AdditionalContentProduct product)
+    public bool IsContentInstalled(AdditionalContentProduct product)
     {
-        if(!productIds.ContainsKey(product)) return false;
+        if(!PlatformHasContent(product)) return false;
 
         AppId_t appId = productIds[product];
         return SteamApps.BIsDlcInstalled(appId);
     }
+
+    public bool PlatformHasContent(AdditionalContentProduct product)
+    {
+        return productIds.ContainsKey(product);
+    }
 }

+ 2 - 1
src/PixiEditor.Platform/IAdditionalContentProvider.cs

@@ -7,5 +7,6 @@ public enum AdditionalContentProduct
 
 public interface IAdditionalContentProvider
 {
-    public bool IsContentAvailable(AdditionalContentProduct product);
+    public bool IsContentInstalled(AdditionalContentProduct product);
+    public bool PlatformHasContent(AdditionalContentProduct product);
 }

+ 4 - 0
src/PixiEditor/Data/Localization/Languages/en.json

@@ -569,4 +569,8 @@
   "ERROR_NO_CLASS_ENTRY": "Extension class entry is missing on path '{0}'.",
   "ERROR_NO_ENTRY_ASSEMBLY": "Extension entry assembly is missing on path '{0}'.",
   "ERROR_MISSING_ADDITIONAL_CONTENT": "Your current setup doesn't allow loading this extension. Perhaps you don't own it or don't have it installed. You can purchase it here '{0}'.",
+
+  "BUY_NOW": "Buy Now",
+  "BUY_SUPPORTER_PACK": "Buy Supporter Pack",
+  "PALETTE_BROWSER_BUY_TEXT": "Buy Supporter Pack and get 21 beautiful palettes!"
 }

+ 4 - 4
src/PixiEditor/Models/AppExtensions/ExtensionLoader.cs

@@ -68,15 +68,15 @@ internal class ExtensionLoader
         }
         catch (JsonException)
         {
-            MessageBox.Show(new LocalizedString("ERROR_INVALID_PACKAGE", packageJsonPath), "ERROR");
+            //MessageBox.Show(new LocalizedString("ERROR_INVALID_PACKAGE", packageJsonPath), "ERROR");
         }
         catch (ExtensionException ex)
         {
-            MessageBox.Show(ex.DisplayMessage, "ERROR");
+            //MessageBox.Show(ex.DisplayMessage, "ERROR");
         }
         catch (Exception ex)
         {
-            MessageBox.Show(new LocalizedString("ERROR_LOADING_PACKAGE", packageJsonPath), "ERROR");
+            //MessageBox.Show(new LocalizedString("ERROR_LOADING_PACKAGE", packageJsonPath), "ERROR");
         }
     }
 
@@ -131,7 +131,7 @@ internal class ExtensionLoader
 
         if (product == null) return true;
 
-        return IPlatform.Current.AdditionalContentProvider?.IsContentAvailable(product.Value) ?? false;
+        return IPlatform.Current.AdditionalContentProvider?.IsContentInstalled(product.Value) ?? false;
     }
 
     private bool IsOfficialAssemblyLegit(string metadataUniqueName, Assembly assembly)

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/AdditionalContent/AdditionalContentViewModel.cs

@@ -11,5 +11,5 @@ internal class AdditionalContentViewModel : ViewModelBase
         AdditionalContentProvider = additionalContentProvider;
     }
 
-    public bool IsSupporterPackAvailable => AdditionalContentProvider != null && AdditionalContentProvider.IsContentAvailable(AdditionalContentProduct.SupporterPack);
+    public bool IsSupporterPackAvailable => AdditionalContentProvider != null && AdditionalContentProvider.IsContentInstalled(AdditionalContentProduct.SupporterPack);
 }

+ 10 - 2
src/PixiEditor/Views/Dialogs/AboutPopup.xaml

@@ -131,9 +131,17 @@
                     <Button Command="{cmds:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}" CommandParameter="https://www.youtube.com/channel/UCT5XvyvX1q5PAIaXfWmpsMQ" 
                             Style="{StaticResource SocialMediaButton}" Tag="#FF0000" ui:Translator.TooltipKey="YOUTUBE"
                             Content="/Images/SocialMedia/YouTubeIcon.png"/>
-                    <Button Command="{cmds:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}" CommandParameter="https://opencollective.com/pixieditor"
+                    <Button Command="{cmds:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}"
+                            Visibility="{Binding DisplayDonationButton,
+                            Converter={BoolToVisibilityConverter}}"
+                            CommandParameter="https://opencollective.com/pixieditor"
                             Style="{StaticResource SocialMediaButton}" Tag="#d4af37" ui:Translator.TooltipKey="DONATE"
-                            Visibility="{Binding DisplayDonationButton, Converter={BoolToVisibilityConverter}}"
+                            Content="/Images/SocialMedia/DonateIcon.png"/>
+                    <Button Command="{cmds:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}"
+                            Visibility="{Binding DisplayDonationButton,
+                            Converter={InverseBoolToVisibilityConverter}}"
+                            CommandParameter="https://store.steampowered.com/app/2435860/PixiEditor__Supporter_Pack/"
+                            Style="{StaticResource SocialMediaButton}" Tag="#d4af37" ui:Translator.TooltipKey="BUY_SUPPORTER_PACK"
                             Content="/Images/SocialMedia/DonateIcon.png"/>
                 </userControls:AlignableWrapPanel>
         </StackPanel>

+ 6 - 0
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -263,6 +263,12 @@
                             CommandParameter="https://opencollective.com/pixieditor"
                             Style="{StaticResource SocialMediaButton}" Tag="#d4af37" ui:Translator.TooltipKey="DONATE"
                             Content="/Images/SocialMedia/DonateIcon.png"/>
+                    <Button Command="{cmds:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}"
+                            Visibility="{Binding ShowDonateButton,
+                            Converter={InverseBoolToVisibilityConverter}}"
+                            CommandParameter="https://store.steampowered.com/app/2435860/PixiEditor__Supporter_Pack/"
+                            Style="{StaticResource SocialMediaButton}" Tag="#d4af37" ui:Translator.TooltipKey="BUY_SUPPORTER_PACK"
+                            Content="/Images/SocialMedia/DonateIcon.png"/>
                 </uc:AlignableWrapPanel>
             </Grid>
         </ScrollViewer>

+ 20 - 2
src/PixiEditor/Views/Dialogs/PalettesBrowser.xaml

@@ -15,6 +15,8 @@
     xmlns:helpers="clr-namespace:PixiEditor.Helpers"
     xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
     xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+    xmlns:commands="clr-namespace:PixiEditor.Models.Commands.Attributes.Commands"
+    xmlns:xaml="clr-namespace:PixiEditor.Models.Commands.XAML"
     x:Class="PixiEditor.Views.Dialogs.PalettesBrowser"
     mc:Ignorable="d"
     WindowStartupLocation="CenterScreen" 
@@ -139,8 +141,23 @@
                 <Image Width="128" Height="128" Source="/Images/Search.png"/>
             </StackPanel>
             <ScrollViewer x:Name="scrollViewer" Margin="5" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" ScrollChanged="ScrollViewer_ScrollChanged">
-                <ItemsControl x:Name="itemsControl" ItemsSource="{Binding SortedResults, ElementName=palettesBrowser}"
-                          Visibility="{Binding PaletteList.FetchedCorrectly, Converter={StaticResource BoolToVisibilityConverter}, ElementName=palettesBrowser}">
+                <StackPanel Orientation="Vertical">
+                    <Border Visibility="{Binding ElementName=palettesBrowser, Path=ShowBuyText, Converter={converters:BoolToVisibilityConverter}}"
+                            Margin="0 0 0 5" Padding="5" Background="{StaticResource MainColor}" CornerRadius="5">
+                        <DockPanel>
+                            <TextBlock FontSize="14" VerticalAlignment="Center" DockPanel.Dock="Left" ui:Translator.Key="PALETTE_BROWSER_BUY_TEXT" Foreground="White"/>
+                            <Button Cursor="Hand" Margin="5 0" DockPanel.Dock="Right" HorizontalAlignment="Right" Content="&#x2715;"
+                                    Click="HideBuyText_OnClick"
+                                    Style="{StaticResource ImageButtonStyle}" VerticalAlignment="Center"
+                                    Padding="0" Background="Transparent" Foreground="White" BorderThickness="0" FontSize="18"/>
+                            <Button DockPanel.Dock="Right" Margin="10 0" HorizontalAlignment="Left" ui:Translator.Key="BUY_NOW"
+                                    Background="{StaticResource AccentRed}"
+                                    Command="{xaml:Command PixiEditor.Links.OpenHyperlink, UseProvided=True}" CommandParameter="https://store.steampowered.com/app/2435860/PixiEditor__Supporter_Pack/"
+                                    Style="{StaticResource DarkRoundButton}"/>
+                        </DockPanel>
+                    </Border>
+                    <ItemsControl x:Name="itemsControl" ItemsSource="{Binding SortedResults, ElementName=palettesBrowser}"
+                                  Visibility="{Binding PaletteList.FetchedCorrectly, Converter={StaticResource BoolToVisibilityConverter}, ElementName=palettesBrowser}">
                     <ItemsControl.ItemTemplate>
                         <DataTemplate>
                             <local:PaletteItem Palette="{Binding}"
@@ -151,6 +168,7 @@
                         </DataTemplate>
                     </ItemsControl.ItemTemplate>
                 </ItemsControl>
+                </StackPanel>
             </ScrollViewer>
             <Image gif:ImageBehavior.AnimatedSource="/Images/Processing.gif" HorizontalAlignment="Center" VerticalAlignment="Center"
                    Visibility="{Binding IsFetching, Converter={StaticResource BoolToVisibilityConverter}, ElementName=palettesBrowser}"

+ 44 - 2
src/PixiEditor/Views/Dialogs/PalettesBrowser.xaml.cs

@@ -23,6 +23,7 @@ using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.Localization;
+using PixiEditor.Platform;
 using PixiEditor.Views.UserControls;
 using PixiEditor.Views.UserControls.Palettes;
 using PaletteColor = PixiEditor.Extensions.Palettes.PaletteColor;
@@ -147,6 +148,16 @@ internal partial class PalettesBrowser : Window, IPopupWindow
     }
     public RelayCommand<Palette> ToggleFavouriteCommand { get; set; }
 
+    public static readonly DependencyProperty ShowBuyTextProperty = DependencyProperty.Register(
+        nameof(ShowBuyText), typeof(bool), typeof(PalettesBrowser),
+        new PropertyMetadata(!IPreferences.Current.GetPreference(PreferencesConstants.HideBuySupporterPackText, false)));
+
+    public bool ShowBuyText
+    {
+        get { return (bool)GetValue(ShowBuyTextProperty); }
+        set { SetValue(ShowBuyTextProperty, value); }
+    }
+
     public int SortingIndex { get; set; } = 0;
     public ColorsNumberMode ColorsNumberMode { get; set; } = ColorsNumberMode.Any;
 
@@ -180,6 +191,19 @@ internal partial class PalettesBrowser : Window, IPopupWindow
         InitializeComponent();
         Title = new LocalizedString("PALETTE_BROWSER");
         Instance = this;
+        if (IPlatform.Current?.AdditionalContentProvider != null)
+        {
+            ShowBuyText =
+                IPlatform.Current.AdditionalContentProvider.PlatformHasContent(AdditionalContentProduct.SupporterPack) &&
+                !IPlatform.Current.AdditionalContentProvider.IsContentInstalled(AdditionalContentProduct
+                    .SupporterPack) &&
+                !IPreferences.Current.GetPreference(PreferencesConstants.HideBuySupporterPackText, false);
+        }
+        else
+        {
+            ShowBuyText = false;
+        }
+
         DeletePaletteCommand = new RelayCommand<Palette>(DeletePalette, CanDeletePalette);
         ToggleFavouriteCommand = new RelayCommand<Palette>(ToggleFavourite, CanToggleFavourite);
         AddFromPaletteCommand = new RelayCommand(AddFromCurrentPalette, CanAddFromPalette);
@@ -391,7 +415,7 @@ internal partial class PalettesBrowser : Window, IPopupWindow
         }
         else
         {
-            PaletteList.Palettes?.AddRange(src.Palettes);
+            AddToPaletteList(src.Palettes);
         }
 
         Sort();
@@ -399,6 +423,18 @@ internal partial class PalettesBrowser : Window, IPopupWindow
         IsFetching = false;
     }
 
+    private void AddToPaletteList(WpfObservableRangeCollection<Palette> srcPalettes)
+    {
+        if (srcPalettes == null)
+            return;
+
+        foreach (var pal in srcPalettes)
+        {
+            if(PaletteEquals(pal, PaletteList.Palettes)) continue;
+            PaletteList.Palettes.Add(pal);
+        }
+    }
+
     private async Task<PaletteList> FetchPaletteList(FilteringSettings filtering)
     {
         int startIndex = PaletteList != null ? PaletteList.Palettes.Count : 0;
@@ -438,7 +474,7 @@ internal partial class PalettesBrowser : Window, IPopupWindow
                 return;
             }
 
-            PaletteList.Palettes.AddRange(newPalettes.Palettes.Where(x => !PaletteEquals(x, PaletteList.Palettes)));
+            AddToPaletteList(newPalettes.Palettes);
             Sort();
             IsFetching = false;
 
@@ -641,4 +677,10 @@ internal partial class PalettesBrowser : Window, IPopupWindow
 
         IPreferences.Current.RemoveCallback(PreferencesConstants.FavouritePalettes, OnFavouritePalettesChanged);
     }
+
+    private void HideBuyText_OnClick(object sender, RoutedEventArgs e)
+    {
+        IPreferences.Current.UpdatePreference(PreferencesConstants.HideBuySupporterPackText, true);
+        ShowBuyText = false;
+    }
 }