CPKreuz před 1 rokem
rodič
revize
5745e93595

binární
src/PixiEditor.AvaloniaUI/Data/BetaExampleFiles/Pond.pixi


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

@@ -671,5 +671,8 @@
   "NOISE_TYPE": "Noise Type",
   "OCTAVES": "Octaves",
   "ACTIVE_FRAME": "Active Frame",
-  "NORMALIZED_TIME": "Normalized Time"
+  "NORMALIZED_TIME": "Normalized Time",
+  
+  "BETA_EXAMPLE_FILES": "Beta Example Files",
+  "POND_EXAMPLE": "Pond"
 }

+ 29 - 0
src/PixiEditor.AvaloniaUI/Views/Windows/BetaExampleFile.cs

@@ -0,0 +1,29 @@
+using Avalonia.Platform;
+using PixiEditor.AvaloniaUI.Models.IO;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.Extensions.Common.Localization;
+using PixiEditor.Parser;
+
+namespace PixiEditor.AvaloniaUI.Views.Windows;
+
+public class BetaExampleFile
+{
+    private readonly string resourcePath;
+    
+    public Surface PreviewImage { get; }
+    
+    public LocalizedString DisplayName { get; }
+    
+    public BetaExampleFile(string name, LocalizedString displayName)
+    {
+        resourcePath = Path.Combine(Paths.DataResourceUri, "BetaExampleFiles", name);
+        DisplayName = displayName;
+        
+        var stream = GetStream();
+        var bytes = PixiParser.ReadPreview(stream);
+
+        PreviewImage = Surface.Load(bytes);
+    }
+    
+    public Stream GetStream() => AssetLoader.Open(new Uri(resourcePath));
+}

+ 42 - 0
src/PixiEditor.AvaloniaUI/Views/Windows/HelloTherePopup.axaml

@@ -16,6 +16,7 @@
                          xmlns:visuals="clr-namespace:PixiEditor.AvaloniaUI.Views.Visuals"
                          xmlns:skiaSharp="clr-namespace:SkiaSharp;assembly=SkiaSharp"
                          xmlns:ui1="clr-namespace:PixiEditor.AvaloniaUI.Helpers.UI"
+                         xmlns:windows="clr-namespace:PixiEditor.AvaloniaUI.Views.Windows"
                          mc:Ignorable="d"
                          Title="Hello there!" Height="662" Width="982" MinHeight="500" MinWidth="500"
                          Loaded="HelloTherePopup_OnLoaded">
@@ -254,6 +255,47 @@
                                 </ItemsPanelTemplate>
                             </ItemsControl.ItemsPanel>
                         </ItemsControl>
+                        
+                        <TextBlock FontSize="23" FontWeight="SemiBold" HorizontalAlignment="Center"
+                                   ui:Translator.Key="BETA_EXAMPLE_FILES" />
+                        
+                        <ItemsControl ItemsSource="{Binding BetaExampleFiles}">
+                            <ItemsControl.ItemTemplate>
+                                <DataTemplate DataType="{x:Type windows:BetaExampleFile}">
+                                    <Grid>
+                                        <StackPanel Margin="8,5,8,0">
+                                            <Button Margin="0,10,0,0" HorizontalAlignment="Center"
+                                                    Width="100" Height="100"
+                                                    Padding="0"
+                                                    Command="{Binding OpenBetaExampleCommand, RelativeSource={RelativeSource AncestorType=windows:HelloTherePopup}}"
+                                                    CommandParameter="{Binding}"
+                                                    x:Name="fileButton">
+                                                <Grid Width="100" Height="100">
+                                                    <visuals:SurfaceControl
+                                                        Surface="{Binding PreviewImage}"
+                                                        Margin="10"
+                                                        Stretch="Uniform"
+                                                        x:Name="image">
+                                                        <ui:RenderOptionsBindable.BitmapInterpolationMode>
+                                                            <MultiBinding
+                                                                Converter="{converters:WidthToBitmapScalingModeConverter}">
+                                                                <Binding Path="PreviewImage.Size.X" />
+                                                                <Binding ElementName="image" Path="Width" />
+                                                            </MultiBinding>
+                                                        </ui:RenderOptionsBindable.BitmapInterpolationMode>
+                                                    </visuals:SurfaceControl>
+                                                </Grid>
+                                            </Button>
+
+                                            <TextBlock ui:Translator.LocalizedString="{Binding DisplayName}"
+                                                       Width="110" TextAlignment="Center"
+                                                       TextTrimming="CharacterEllipsis"
+                                                       FontSize="18" Margin="10,10,10,2" HorizontalAlignment="Center" />
+                                        </StackPanel>
+                                    </Grid>
+                                </DataTemplate>
+                            </ItemsControl.ItemTemplate>
+                        </ItemsControl>
                     </StackPanel>
 
                     <panels:AlignableWrapPanel Grid.Row="3" HorizontalContentAlignment="Center"

+ 24 - 0
src/PixiEditor.AvaloniaUI/Views/Windows/HelloTherePopup.axaml.cs

@@ -7,11 +7,13 @@ using Avalonia.Interactivity;
 using CommunityToolkit.Mvvm.Input;
 using PixiEditor.AvaloniaUI.Helpers;
 using PixiEditor.AvaloniaUI.Helpers.Extensions;
+using PixiEditor.AvaloniaUI.Models.IO;
 using PixiEditor.AvaloniaUI.Models.Services.NewsFeed;
 using PixiEditor.AvaloniaUI.Models.Structures;
 using PixiEditor.AvaloniaUI.Models.UserData;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 using PixiEditor.AvaloniaUI.Views.Dialogs;
+using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.CommonApi.UserPreferences.Settings.PixiEditor;
 using PixiEditor.OperatingSystem;
 
@@ -23,6 +25,8 @@ namespace PixiEditor.AvaloniaUI.Views.Windows;
 internal partial class HelloTherePopup : PixiEditorPopup
 {
     public RecentlyOpenedCollection RecentlyOpened { get => FileViewModel.RecentlyOpened; }
+    
+    public List<BetaExampleFile> BetaExampleFiles { get; }
 
     public static readonly StyledProperty<FileViewModel> FileViewModelProperty =
         AvaloniaProperty.Register<HelloTherePopup, FileViewModel>(nameof(FileViewModel));
@@ -75,6 +79,8 @@ internal partial class HelloTherePopup : PixiEditorPopup
     public AsyncRelayCommand OpenNewFileCommand { get; set; }
 
     public RelayCommand<string> OpenRecentCommand { get; set; }
+    
+    public AsyncRelayCommand<BetaExampleFile> OpenBetaExampleCommand { get; set; }
 
     public RelayCommand<string> OpenInExplorerCommand { get; set; }
 
@@ -101,11 +107,19 @@ internal partial class HelloTherePopup : PixiEditorPopup
         OpenFileCommand = new AsyncRelayCommand(OpenFile);
         OpenNewFileCommand = new AsyncRelayCommand(OpenNewFile);
         OpenRecentCommand = new RelayCommand<string>(OpenRecent);
+        OpenBetaExampleCommand = new AsyncRelayCommand<BetaExampleFile>(OpenBetaExample);
         OpenInExplorerCommand = new RelayCommand<string>(OpenInExplorer, CanOpenInExplorer);
 
         RecentlyOpenedEmpty = RecentlyOpened.Count == 0;
         RecentlyOpened.CollectionChanged += RecentlyOpened_CollectionChanged;
 
+        // Beta examples
+        (string file, LocalizedString name)[] files = [
+            ("Pond.pixi", "POND_EXAMPLE")
+        ];
+
+        BetaExampleFiles = new List<BetaExampleFile>(files.Select(x => new BetaExampleFile(x.file, x.name)));
+        
         _newsDisabled = PixiEditorSettings.StartupWindow.DisableNewsPanel.Value;
 
         NewsProvider = new NewsProvider();
@@ -141,6 +155,16 @@ internal partial class HelloTherePopup : PixiEditorPopup
         }
     }
 
+    private async Task OpenBetaExample(BetaExampleFile? arg)
+    {
+        await using var stream = arg.GetStream();
+        
+        var bytes = new byte[stream.Length];
+        await stream.ReadExactlyAsync(bytes);
+
+        FileViewModel.OpenRecoveredDotPixi(null, bytes);
+    }
+
     private static void NewsPanelCollapsedChangedCallback(AvaloniaPropertyChangedEventArgs<bool> e)
     {
         HelloTherePopup helloTherePopup = (HelloTherePopup)e.Sender;