102 lines
3.2 KiB
C#
102 lines
3.2 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Media;
|
|
using Project_Periodensystem.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Project_Periodensystem.View
|
|
{
|
|
public partial class LandingPage : UserControl
|
|
{
|
|
private readonly Random random = new();
|
|
private readonly Dictionary<AppTheme, string> themeColors;
|
|
private AppTheme currentTheme;
|
|
private Button? startButton;
|
|
private DateTime lastClickTime = DateTime.MinValue;
|
|
private const int DEBOUNCE_MS = 500;
|
|
|
|
public LandingPage()
|
|
{
|
|
Logger.Log($"=== LandingPage wird initialisiert am {DateTime.Now:dd.MM.yyyy HH:mm:ss} ===");
|
|
InitializeComponent();
|
|
|
|
themeColors = new Dictionary<AppTheme, string>
|
|
{
|
|
{ AppTheme.Dark, "#5C5144" },
|
|
{ AppTheme.Light, "#E8DFD8" },
|
|
{ AppTheme.Classic, "#7B8B6F" }
|
|
};
|
|
|
|
SetRandomTheme();
|
|
startButton = this.Find<Button>("StartButton");
|
|
|
|
if (startButton != null)
|
|
{
|
|
Logger.Log("StartButton gefunden und wird initialisiert");
|
|
startButton.Click += StartButton_Click;
|
|
Logger.Log("Click-Handler wurde registriert");
|
|
}
|
|
else
|
|
{
|
|
Logger.Log("FEHLER: StartButton nicht gefunden!");
|
|
}
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
private void SetRandomTheme()
|
|
{
|
|
var themes = Enum.GetValues<AppTheme>();
|
|
currentTheme = themes[random.Next(themes.Length)];
|
|
this.Background = new SolidColorBrush(Color.Parse(themeColors[currentTheme]));
|
|
Logger.Log($"Theme gewählt: {currentTheme}");
|
|
}
|
|
|
|
private void ThemeButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
var themes = Enum.GetValues<AppTheme>();
|
|
currentTheme = themes[(Array.IndexOf(themes, currentTheme) + 1) % themes.Length];
|
|
|
|
if (this.Parent is ContentControl content && content.Parent is MainWindow mainWindow)
|
|
{
|
|
mainWindow.UpdateTheme(currentTheme);
|
|
}
|
|
}
|
|
|
|
private void StartButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
// Stop event propagation
|
|
e.Handled = true;
|
|
|
|
var now = DateTime.Now;
|
|
// Prüfe ob genug Zeit seit dem letzten Klick vergangen ist
|
|
if ((now - lastClickTime).TotalMilliseconds < DEBOUNCE_MS)
|
|
{
|
|
Logger.Log("Click ignoriert (Debounce)");
|
|
return;
|
|
}
|
|
lastClickTime = now;
|
|
|
|
Logger.Log("StartButton_Click wurde aufgerufen");
|
|
|
|
try
|
|
{
|
|
if (this.Parent is ContentControl content && content.Parent is MainWindow mainWindow)
|
|
{
|
|
mainWindow.ShowPeriodicTable();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Log($"FEHLER im Click-Handler: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|