126 lines
4.8 KiB
C#
126 lines
4.8 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Media.Imaging;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
|
|
namespace AquaCare.View
|
|
{
|
|
// Fenster zur Anzeige von Schritt-für-Schritt-Tutorials mit Bildern
|
|
public partial class TutorialsWindow : Window
|
|
{
|
|
// Liste der Bildpfade für das aktuelle Tutorial
|
|
private List<string> _images;
|
|
// TextBlock zur Anzeige des aktuellen Bildindexes
|
|
private TextBlock? _imageIndexTextBlock;
|
|
// TextBlock für den Starttext
|
|
private TextBlock? _initialText;
|
|
// Index des aktuell angezeigten Bildes
|
|
private int _currentImageIndex;
|
|
|
|
// Dictionary mit der Anzahl der Bilder pro Tutorial-Ordner
|
|
private readonly Dictionary<string, int> _imageCountPerFolder = new()
|
|
{
|
|
{"Fische füttern", 3},
|
|
{"Wasser wechseln", 7},
|
|
{"Filter reinigen", 8}
|
|
};
|
|
|
|
// Konstruktor: Initialisiert das Fenster und sucht die UI-Elemente
|
|
public TutorialsWindow()
|
|
{
|
|
InitializeComponent(); // Initialisiert die UI-Komponenten
|
|
_images = new List<string>();
|
|
|
|
// Sucht die Textblöcke anhand ihres Namens in der XAML
|
|
_imageIndexTextBlock = this.Find<TextBlock>("imageIndexTextBlock")
|
|
?? throw new InvalidOperationException("imageIndexTextBlock not found");
|
|
_initialText = this.Find<TextBlock>("initialText")
|
|
?? throw new InvalidOperationException("initialText not found");
|
|
}
|
|
|
|
// Lädt die Bilder für das gewählte Tutorial
|
|
private void LoadTutorialImages(string folderName)
|
|
{
|
|
if (_initialText == null || tutorialImage == null) return;
|
|
if (!_imageCountPerFolder.ContainsKey(folderName)) return;
|
|
|
|
int imageCount = _imageCountPerFolder[folderName];
|
|
_images = new List<string>();
|
|
|
|
// Füge dynamisch die richtige Anzahl Bilder hinzu
|
|
for (int i = 1; i <= imageCount; i++)
|
|
{
|
|
_images.Add($"Ressourcen/BilderTutorials/{folderName}/{i}.jpg");
|
|
}
|
|
|
|
_currentImageIndex = 0;
|
|
_initialText.IsVisible = false;
|
|
tutorialImage.IsVisible = true;
|
|
UpdateTutorialContent();
|
|
}
|
|
|
|
// Aktualisiert das angezeigte Bild und den Index-Text
|
|
private void UpdateTutorialContent()
|
|
{
|
|
try
|
|
{
|
|
if (_imageIndexTextBlock == null || _initialText == null || tutorialImage == null) return;
|
|
|
|
if (_images.Count > 0 && _currentImageIndex >= 0 && _currentImageIndex < _images.Count)
|
|
{
|
|
string fullPath = $"avares://AquaCare.View/{_images[_currentImageIndex]}";
|
|
System.Diagnostics.Debug.WriteLine($"Lade Bild: {fullPath}"); // Debug-Ausgabe
|
|
|
|
var uri = new Uri(fullPath);
|
|
var asset = Avalonia.Platform.AssetLoader.Open(uri);
|
|
tutorialImage.Source = new Bitmap(asset);
|
|
|
|
_imageIndexTextBlock.Text = $"Bild {_currentImageIndex + 1} von {_images.Count}";
|
|
_initialText.IsVisible = false;
|
|
tutorialImage.IsVisible = true;
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"Fehler beim Laden des Bildes: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
// Navigiert zum nächsten oder vorherigen Bild
|
|
private void NavigateImages(bool forward)
|
|
{
|
|
if (forward)
|
|
{
|
|
_currentImageIndex = _currentImageIndex < _images.Count - 1 ? _currentImageIndex + 1 : 0;
|
|
}
|
|
else
|
|
{
|
|
_currentImageIndex = _currentImageIndex > 0 ? _currentImageIndex - 1 : _images.Count - 1;
|
|
}
|
|
UpdateTutorialContent();
|
|
}
|
|
|
|
// Event Handler für die Tutorial-Auswahl
|
|
private void FischeFütternClick(object? sender, RoutedEventArgs e)
|
|
=> LoadTutorialImages("Fische füttern");
|
|
|
|
private void WasserWechselnClick(object? sender, RoutedEventArgs e)
|
|
=> LoadTutorialImages("Wasser wechseln");
|
|
|
|
private void FilterReinigenClick(object? sender, RoutedEventArgs e)
|
|
=> LoadTutorialImages("Filter reinigen");
|
|
|
|
// Event Handler für die Navigation durch die Bilder
|
|
private void NextImageClick(object? sender, RoutedEventArgs e)
|
|
=> NavigateImages(true);
|
|
|
|
private void PreviousImageClick(object? sender, RoutedEventArgs e)
|
|
=> NavigateImages(false);
|
|
|
|
// Event Handler zum Schließen des Fensters
|
|
private void CloseClick(object? sender, RoutedEventArgs e)
|
|
=> Close();
|
|
}
|
|
}
|