Initial commit
This commit is contained in:
284
Valheim Dashboard/TutorialManager.cs
Normal file
284
Valheim Dashboard/TutorialManager.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Media;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Valheim_Dashboard
|
||||
{
|
||||
public class TutorialManager
|
||||
{
|
||||
private readonly Window _mainWindow;
|
||||
|
||||
public TutorialManager(Window mainWindow)
|
||||
{
|
||||
_mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow));
|
||||
}
|
||||
|
||||
|
||||
public void HighlightControl(Control target, bool highlight)
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
if (highlight)
|
||||
{
|
||||
if (target is Button button)
|
||||
{
|
||||
button.BorderBrush = Brushes.Gold;
|
||||
button.BorderThickness = new Thickness(2);
|
||||
}
|
||||
|
||||
// Weitere visuelle Anpassungen hier
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target is Button button)
|
||||
{
|
||||
button.BorderBrush = Brushes.Transparent;
|
||||
button.BorderThickness = new Thickness(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Highlight ein Element mit einem animierten Rahmen
|
||||
public void HighlightElement(Control element, Brush borderBrush, double thickness = 3)
|
||||
{
|
||||
|
||||
if (element is Button button)
|
||||
{
|
||||
button.BorderBrush = borderBrush;
|
||||
button.BorderThickness = new Thickness(thickness);
|
||||
}
|
||||
|
||||
if (element is TextBox textBox)
|
||||
{
|
||||
textBox.BorderBrush = borderBrush;
|
||||
textBox.BorderThickness = new Thickness(thickness);
|
||||
}
|
||||
|
||||
if (element is Expander expander)
|
||||
{
|
||||
|
||||
|
||||
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var overlayLayer = _mainWindow.FindControl<Canvas>("OverlayLayer");
|
||||
if (overlayLayer == null)
|
||||
{
|
||||
Console.WriteLine("Overlay-Layer (Canvas) nicht gefunden.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Ziel-Element Position berechnen
|
||||
var targetPosition = expander.TranslatePoint(new Point(0, 0), overlayLayer);
|
||||
if (targetPosition.HasValue)
|
||||
{
|
||||
var highlightBorder = new Border
|
||||
{
|
||||
BorderBrush = borderBrush,
|
||||
BorderThickness = new Thickness(thickness),
|
||||
Background = Brushes.Transparent,
|
||||
Width = expander.Bounds.Width + thickness * 2,
|
||||
Height = expander.Bounds.Height + thickness * 2
|
||||
};
|
||||
|
||||
overlayLayer.Children.Add(highlightBorder);
|
||||
Canvas.SetLeft(highlightBorder, targetPosition.Value.X - thickness);
|
||||
Canvas.SetTop(highlightBorder, targetPosition.Value.Y - thickness);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Konnte die Position der Zielkontrolle nicht berechnen.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SmoothScrollToControl(ScrollViewer scrollViewer, Control target, int duration = 300)
|
||||
{
|
||||
|
||||
var targetPosition = target.TranslatePoint(new Point(0, 0), scrollViewer);
|
||||
|
||||
double startOffset = scrollViewer.Offset.Y;
|
||||
double delta = targetPosition.Value.Y - startOffset;
|
||||
|
||||
int frames = duration / 16; // 16ms pro Frame
|
||||
for (int i = 0; i <= frames; i++)
|
||||
{
|
||||
double progress = (double)i / frames;
|
||||
double easedProgress = EasingFunction(progress); // Optional: Easing-Funktion
|
||||
scrollViewer.Offset = new Vector(scrollViewer.Offset.X, startOffset + (delta * easedProgress));
|
||||
await Task.Delay(16);
|
||||
}
|
||||
}
|
||||
|
||||
private double EasingFunction(double t)
|
||||
{
|
||||
return t * t * (3 - 2 * t); // Standard Smoothing (EaseInOut)
|
||||
}
|
||||
|
||||
|
||||
// Öffnen eines Expanders
|
||||
public void OpenExpander(Expander expander)
|
||||
{
|
||||
if (expander != null)
|
||||
{
|
||||
expander.IsExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseExpander(Expander expander)
|
||||
{
|
||||
if (expander != null)
|
||||
{
|
||||
expander.IsExpanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Schreibe Text in ein Textfeld (z. B. TextBox)
|
||||
public void WriteText(TextBox textBox, string text)
|
||||
{
|
||||
if (textBox != null)
|
||||
{
|
||||
textBox.Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
// Simuliere einen Button-Klick
|
||||
public void ClickButton(Button button)
|
||||
{
|
||||
if (button != null)
|
||||
{
|
||||
button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); // Simuliere Klick
|
||||
}
|
||||
}
|
||||
|
||||
public enum SpeechBubblePosition
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Zeige eine Sprechblase mit einem Weiter-Button
|
||||
public void ShowSpeechBubble(Control target, SpeechBubblePosition position, string text, Action onNext = null)
|
||||
{
|
||||
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var overlayLayer = _mainWindow.FindControl<Canvas>("OverlayLayer");
|
||||
if (overlayLayer == null)
|
||||
{
|
||||
Console.WriteLine("Overlay-Layer (Canvas) nicht gefunden.");
|
||||
return;
|
||||
}
|
||||
|
||||
var speechBubble = new Border
|
||||
{
|
||||
Background = Brushes.DarkGray,
|
||||
BorderBrush = Brushes.Black,
|
||||
BorderThickness = new Thickness(2),
|
||||
CornerRadius = new CornerRadius(8),
|
||||
Width = 250,
|
||||
Padding = new Thickness(10),
|
||||
Child = new StackPanel
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new TextBlock
|
||||
{
|
||||
Text = text,
|
||||
Foreground = Brushes.White,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Margin = new Thickness(0, 0, 0, 10)
|
||||
},
|
||||
new Button
|
||||
{
|
||||
IsHitTestVisible = true,
|
||||
Content = "Weiter",
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
Command = ReactiveUI.ReactiveCommand.Create(() =>
|
||||
{
|
||||
overlayLayer.Children.Clear();
|
||||
onNext?.Invoke();
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Positionierung relativ zum Ziel
|
||||
|
||||
var targetPosition = target.TranslatePoint(new Point(0, 0), overlayLayer);
|
||||
if (targetPosition.HasValue)
|
||||
{
|
||||
overlayLayer.Children.Add(speechBubble);
|
||||
|
||||
// Bildschirm- oder Overlay-Größen abrufen
|
||||
var overlayBounds = overlayLayer.Bounds;
|
||||
|
||||
double finalX = targetPosition.Value.X;
|
||||
double finalY = targetPosition.Value.Y;
|
||||
|
||||
// Manuelle Layout-Berechnung
|
||||
speechBubble.Measure(Size.Infinity); // Grenze für unendliche Größe setzen
|
||||
speechBubble.Arrange(new Rect(0, 0, speechBubble.DesiredSize.Width, speechBubble.DesiredSize.Height));
|
||||
|
||||
// Nach Layout-Berechnung gewünschte Maße abrufen
|
||||
double speechBubbleWidth = speechBubble.Bounds.Width > 0 ? speechBubble.Bounds.Width : speechBubble.DesiredSize.Width;
|
||||
double speechBubbleHeight = speechBubble.Bounds.Height > 0 ? speechBubble.Bounds.Height : speechBubble.DesiredSize.Height;
|
||||
|
||||
|
||||
// Position basierend auf dem Parameter "position" berechnen
|
||||
switch (position)
|
||||
{
|
||||
case SpeechBubblePosition.Top:
|
||||
finalX = targetPosition.Value.X + (target.Bounds.Width / 2) - (speechBubbleWidth / 2);
|
||||
finalY = targetPosition.Value.Y - speechBubbleHeight - 10;
|
||||
break;
|
||||
|
||||
case SpeechBubblePosition.Bottom:
|
||||
finalX = targetPosition.Value.X + (target.Bounds.Width / 2) - (speechBubbleWidth / 2);
|
||||
finalY = targetPosition.Value.Y + target.Bounds.Height + 10;
|
||||
break;
|
||||
|
||||
case SpeechBubblePosition.Left:
|
||||
finalX = targetPosition.Value.X - speechBubbleWidth - 10;
|
||||
finalY = targetPosition.Value.Y;
|
||||
break;
|
||||
|
||||
case SpeechBubblePosition.Right:
|
||||
finalX = targetPosition.Value.X + target.Bounds.Width + 10;
|
||||
finalY = targetPosition.Value.Y;
|
||||
break;
|
||||
}
|
||||
|
||||
// Dynamisch prüfen, ob das Popup im Sichtbereich ist
|
||||
if (finalX < 0) finalX = 0; // Zu weit links
|
||||
if (finalX + speechBubble.Width > overlayBounds.Width) finalX = overlayBounds.Width - speechBubble.Width; // Zu weit rechts
|
||||
if (finalY < 0) finalY = 0; // Zu weit oben
|
||||
if (finalY + speechBubble.Height > overlayBounds.Height) finalY = overlayBounds.Height - speechBubble.Height; // Zu weit unten
|
||||
|
||||
// Position setzen
|
||||
Canvas.SetLeft(speechBubble, finalX);
|
||||
Canvas.SetTop(speechBubble, finalY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Konnte die Position der Zielkontrolle nicht berechnen.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user