122 lines
3.5 KiB
C#
122 lines
3.5 KiB
C#
using System;
|
|
using System.Reactive.Linq;
|
|
using Avalonia.Animation;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Media;
|
|
using Avalonia.ReactiveUI;
|
|
using Avalonia.Styling;
|
|
using ReactiveUI;
|
|
using Valheim_Dashboard.ViewModels;
|
|
using static Valheim_Dashboard.Animationen;
|
|
using Valheim_Dashboard.Views;
|
|
|
|
namespace Valheim_Dashboard.Views
|
|
{
|
|
public partial class ErsterStartView : ReactiveUserControl<ErsterStartViewModel>
|
|
{
|
|
|
|
|
|
|
|
public ErsterStartView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.WhenActivated(disposables =>
|
|
{
|
|
Console.WriteLine("erster start view");
|
|
// Animation starten, wenn ViewModel-Property sich ändert
|
|
this.WhenAnyValue(x => x.ViewModel.StartAnimation)
|
|
.Where(startAnimation => startAnimation)
|
|
.Subscribe(_ => StartAnimation());
|
|
|
|
this.WhenAnyValue(x => x.ViewModel.AnimationTargetPosition)
|
|
.Subscribe(pos =>
|
|
{
|
|
if(HinweisTextBlock != null && WeiterButton != null) {
|
|
double offsetX = pos.X - WeiterButton.Bounds.X - 200;
|
|
double offsetY = pos.Y - WeiterButton.Bounds.Y - 150;
|
|
HinweisTextBlock.RenderTransform = new TranslateTransform(offsetX, offsetY);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
private void StartAnimation()
|
|
{
|
|
|
|
var hinweisTextBlock = this.FindControl<TextBlock>("HinweisTextBlock");
|
|
var weiterButton = this.FindControl<Button>("WeiterButton");
|
|
|
|
|
|
Console.WriteLine($"HinweisTextBlock: {hinweisTextBlock != null}");
|
|
Console.WriteLine($"WeiterButton: {weiterButton != null}");
|
|
|
|
if (hinweisTextBlock != null)
|
|
{
|
|
var animation = new Animation
|
|
{
|
|
Duration = TimeSpan.FromSeconds(2),
|
|
Delay = TimeSpan.FromSeconds(2)
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
animation.Children.Add(new KeyFrame
|
|
{
|
|
|
|
Cue = new Cue(0d),
|
|
Setters =
|
|
{
|
|
new Setter(TextBlock.OpacityProperty, 1.0)
|
|
}
|
|
});
|
|
|
|
animation.Children.Add(new KeyFrame
|
|
{
|
|
Cue = new Cue(1d),
|
|
Setters =
|
|
{
|
|
new Setter(TextBlock.OpacityProperty, 0.2)
|
|
}
|
|
});
|
|
|
|
|
|
// RenderTransform VOR animation.RunAsync setzen!
|
|
hinweisTextBlock.RenderTransform = new ScaleTransform(1, 1);
|
|
|
|
|
|
animation.RunAsync(hinweisTextBlock);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
private void Weiter_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
Console.WriteLine("weiter geklickt");
|
|
Console.WriteLine(this.Parent.Parent.Parent);
|
|
|
|
if (this.Parent.Parent.Parent is MainWindow mainWindow)
|
|
{
|
|
if(mainWindow.DataContext is MainWindowViewModel mainWindowViewModel)
|
|
{
|
|
mainWindowViewModel.SwitchToLizenzView();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |