- Layout Verschiebung behoben bei Configeditor

- Config zuordnung überarbeitet -> keine vorhanden zeigt im editor dann hinweis an: Keine Config gefunden. Server bereits neu gestartet ?
- Config Speichern behoben
- Ladeanimationen hinzugefügt
- Mod löschen funktion eingefügt -> Popup zur bestätigung ob gelöscht werden soll
This commit is contained in:
tbS
2025-08-29 18:43:41 +02:00
parent 32cbe40921
commit aaf6e02862
6 changed files with 198 additions and 33 deletions

View File

@@ -44,4 +44,11 @@
</Style.Resources> </Style.Resources>
</Style> </Style>
</Application.Styles> </Application.Styles>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://LoadingIndicators.Avalonia/LoadingIndicators.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application> </Application>

View File

@@ -24,6 +24,7 @@
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets> <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.4" /> <PackageReference Include="Avalonia.ReactiveUI" Version="11.3.4" />
<PackageReference Include="LoadingIndicators.Avalonia" Version="11.0.11.1" />
<PackageReference Include="Lucide.Avalonia" Version="0.1.41" /> <PackageReference Include="Lucide.Avalonia" Version="0.1.41" />
</ItemGroup> </ItemGroup>
@@ -40,6 +41,9 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Update="Views\ConfirmDialog.axaml.cs">
<DependentUpon>ConfirmDialog.axaml</DependentUpon>
</Compile>
<Compile Update="Views\ServerDashboard.axaml.cs"> <Compile Update="Views\ServerDashboard.axaml.cs">
<DependentUpon>ServerDashboard.axaml</DependentUpon> <DependentUpon>ServerDashboard.axaml</DependentUpon>
</Compile> </Compile>

View File

@@ -22,6 +22,7 @@ using Valheim_Dashboard.Models;
using Valheim_Dashboard.Views; using Valheim_Dashboard.Views;
using static System.Net.WebRequestMethods; using static System.Net.WebRequestMethods;
namespace Valheim_Dashboard.ViewModels; namespace Valheim_Dashboard.ViewModels;
public class ServerDashboardViewModel : ViewModelBase public class ServerDashboardViewModel : ViewModelBase
@@ -50,14 +51,29 @@ public class ServerDashboardViewModel : ViewModelBase
public ObservableCollection<ModInfo> Mods { get; } = new(); public ObservableCollection<ModInfo> Mods { get; } = new();
private ModInfo _selectedMod;
public ModInfo SelectedMod private ModInfo? _selectedMod;
public ModInfo? SelectedMod
{ {
get => _selectedMod; get => _selectedMod;
set set
{ {
this.RaiseAndSetIfChanged(ref _selectedMod, value); this.RaiseAndSetIfChanged(ref _selectedMod, value);
_ = LoadSelectedModConfigFromFtp(); // async fire-and-forget
if (value == null)
{
SelectedModConfig = string.Empty;
}
else if (string.IsNullOrEmpty(value.ConfigPath))
{
// Keine Config zugeordnet → Hinweistext
SelectedModConfig = "Keine Config gefunden, Server bereits neugestartet?";
}
else
{
// Config laden
_ = LoadSelectedModConfigFromFtp(); ;
}
} }
} }
@@ -107,7 +123,7 @@ public class ServerDashboardViewModel : ViewModelBase
public ReactiveCommand<Unit, Unit> UploadModCommand { get; } public ReactiveCommand<Unit, Unit> UploadModCommand { get; }
public ReactiveCommand<Unit, Unit> InstallFromStoreCommand { get; } public ReactiveCommand<Unit, Unit> InstallFromStoreCommand { get; }
public ReactiveCommand<Unit, Unit> SaveConfigCommand { get; } public ReactiveCommand<Unit, Unit> SaveConfigCommand { get; }
public ReactiveCommand<ModInfo, Unit> RemoveModCommand { get; } public ReactiveCommand<ModInfo, Task> RemoveModCommand { get; }
public ReactiveCommand<ModInfo, Unit> UpdateModCommand { get; } public ReactiveCommand<ModInfo, Unit> UpdateModCommand { get; }
private bool _isLoading; private bool _isLoading;
@@ -124,12 +140,22 @@ public class ServerDashboardViewModel : ViewModelBase
UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod); UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod);
InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore); InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore);
SaveConfigCommand = ReactiveCommand.Create(SaveConfig); SaveConfigCommand = ReactiveCommand.Create(SaveConfig);
RemoveModCommand = ReactiveCommand.Create<ModInfo>(RemoveMod); RemoveModCommand = ReactiveCommand.Create<ModInfo,Task>(RemoveMod);
UpdateModCommand = ReactiveCommand.Create<ModInfo>(UpdateMod); UpdateModCommand = ReactiveCommand.Create<ModInfo>(UpdateMod);
// DEBUG: harter Testtext – MUSS im Editor erscheinen // DEBUG: harter Testtext – MUSS im Editor erscheinen
ConfigDocument.Text = "Bitte Mod Auswählen"; ConfigDocument.Text = "Bitte Mod Auswählen";
// SelectedModConfig Sync mit ConfigDocument text (:
ConfigDocument = new TextDocument();
ConfigDocument.TextChanged += (s, e) =>
{
if (SelectedModConfig != ConfigDocument.Text)
SelectedModConfig = ConfigDocument.Text;
};
//SelectedMod.Name = "Bitte Mod Auswählen"; //SelectedMod.Name = "Bitte Mod Auswählen";
// Demo // Demo
@@ -431,6 +457,14 @@ public class ServerDashboardViewModel : ViewModelBase
//Mod Liste holen //Mod Liste holen
private bool _isModsLoading;
public bool IsModsLoading
{
get => _isModsLoading;
set => this.RaiseAndSetIfChanged(ref _isModsLoading, value);
}
// Hilfsfunktionen // Hilfsfunktionen
static string NormalizeKey(string s) static string NormalizeKey(string s)
@@ -536,6 +570,7 @@ public class ServerDashboardViewModel : ViewModelBase
// Hauptmethode // Hauptmethode
public async Task LoadModsFromServer() public async Task LoadModsFromServer()
{ {
IsModsLoading = true;
try try
{ {
Mods.Clear(); Mods.Clear();
@@ -585,16 +620,7 @@ public class ServerDashboardViewModel : ViewModelBase
cfgHit = cfgFiles.FirstOrDefault(cf => normCandidates.Any(nc => cf.Normalized.Contains(nc))); cfgHit = cfgFiles.FirstOrDefault(cf => normCandidates.Any(nc => cf.Normalized.Contains(nc)));
// 3) Fallback: „bester“ Fit über LCS // 3) Fallback: „bester“ Fit über LCS
if (cfgHit == null) // cfgHit bleibt null
{
cfgHit = cfgFiles
.Select(cf => new {
cf,
score = normCandidates.Max(nc => LongestCommonSubsequenceLen(cf.Normalized, nc))
})
.OrderByDescending(x => x.score)
.FirstOrDefault()?.cf;
}
} }
// Version aus DLL ziehen // Version aus DLL ziehen
@@ -629,6 +655,10 @@ public class ServerDashboardViewModel : ViewModelBase
{ {
Debug.WriteLine($"LoadModsFromFtp Fehler: {ex}"); Debug.WriteLine($"LoadModsFromFtp Fehler: {ex}");
} }
finally
{
IsModsLoading = false;
}
} }
@@ -689,9 +719,62 @@ public class ServerDashboardViewModel : ViewModelBase
Debug.WriteLine(SelectedMod.ConfigPath); Debug.WriteLine(SelectedMod.ConfigPath);
FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath); FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath);
} }
private void RemoveMod(ModInfo mod) private async Task RemoveMod(ModInfo mod)
{ {
Mods.Remove(mod); // Finde das aktive Fenster über das Visual Tree
var topLevel = TopLevel.GetTopLevel(App.Current!.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime d
? d.MainWindow
: null);
if (topLevel is not Window parent)
{
Debug.WriteLine("Kein gültiges Window gefunden.");
return;
}
var dialog = new ConfirmDialog();
dialog.SetMessage($"Möchtest du den Mod \"{mod.Name}\" wirklich löschen?");
bool confirmed = await dialog.ShowDialogAsync(parent);
if (confirmed)
{
Mods.Remove(mod);
if (ServerSettingsView.method == "ftp")
{
var remotePath = CombineFtp(FtpViewModel._currentPath, "BepInEx/plugins", mod.Name + ".dll");
try
{
await FtpViewModel._ftpClient.DeleteFileAsync(remotePath);
Debug.WriteLine($"Mod {mod.Name} gelöscht.");
}
catch (Exception ex)
{
Debug.WriteLine($"Fehler beim Löschen der Mod {mod.Name}: {ex.Message}");
}
try
{
await FtpViewModel._ftpClient.DeleteFileAsync(mod.ConfigPath);
Debug.WriteLine($"Mod Config {mod.Name} gelöscht.");
}
catch (Exception ex)
{
Debug.WriteLine($"Fehler beim Löschen der Mod Config {mod.Name}: {ex.Message}");
}
}
else
{
Debug.WriteLine("Plugin funktion fehlt noch");
}
}
} }
private void UpdateMod(ModInfo mod) private void UpdateMod(ModInfo mod)

View File

@@ -0,0 +1,31 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Valheim_Dashboard.Views.ConfirmDialog"
Width="400" Height="200"
CanResize="False"
WindowStartupLocation="CenterOwner"
Background="{DynamicResource Cfg.BgBrush}">
<StackPanel Margin="20" Spacing="20" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="MessageText"
FontSize="20"
Foreground="{DynamicResource Cfg.FgBrush}"
TextWrapping="Wrap"
TextAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="20">
<Button x:Name="YesButton"
Content="Ja"
Width="100"
Height="40"
Background="Green"
Foreground="White"/>
<Button x:Name="NoButton"
Content="Nein"
Width="100"
Height="40"
Background="Red"
Foreground="White"/>
</StackPanel>
</StackPanel>
</Window>

View File

@@ -0,0 +1,30 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using System.Threading.Tasks;
namespace Valheim_Dashboard.Views
{
public partial class ConfirmDialog : Window
{
private TaskCompletionSource<bool> _tcs = new();
public ConfirmDialog()
{
InitializeComponent();
YesButton.Click += (_, __) => { _tcs.TrySetResult(true); Close(); };
NoButton.Click += (_, __) => { _tcs.TrySetResult(false); Close(); };
}
public void SetMessage(string message)
{
MessageText.Text = message;
}
public Task<bool> ShowDialogAsync(Window parent)
{
base.ShowDialog(parent); // Fenster modal <20>ffnen
return _tcs.Task;
}
}
}

View File

@@ -8,10 +8,11 @@
x:Class="Valheim_Dashboard.Views.ServerDashboardView" x:Class="Valheim_Dashboard.Views.ServerDashboardView"
x:DataType="vm:ServerDashboardViewModel" x:DataType="vm:ServerDashboardViewModel"
xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:icons="clr-namespace:Lucide.Avalonia;assembly=Lucide.Avalonia"> xmlns:icons="clr-namespace:Lucide.Avalonia;assembly=Lucide.Avalonia"
xmlns:li="using:LoadingIndicators.Avalonia">
<Grid ColumnDefinitions="2*,3*"> <Grid ColumnDefinitions="570,*">
<!-- Linke Spalte --> <!-- Linke Spalte -->
<Grid Margin="20" RowDefinitions="Auto,*" RowSpacing="20"> <Grid Margin="20" RowDefinitions="Auto,*" RowSpacing="20">
@@ -25,7 +26,7 @@
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
</Grid> </Grid>
<TextBlock Text="{Binding BepInExStatus}" FontSize="20"/> <TextBlock Text="{Binding BepInExStatus}" FontSize="20"/>
<ProgressBar IsVisible="{Binding IsLoading}" /> <li:LoadingIndicator IsActive="{Binding IsLoading}" IsVisible="{Binding IsLoading}" Mode="Arcs" SpeedRatio="0.8" Height="100" Width="100" />
<Button Content="Installieren" <Button Content="Installieren"
Command="{Binding InstallBepInExCommand}" Command="{Binding InstallBepInExCommand}"
IsVisible="{Binding ShowInstallButton}" IsVisible="{Binding ShowInstallButton}"
@@ -51,18 +52,19 @@
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold" Grid.Row="0"/> <TextBlock Text="Mods" FontSize="28" FontWeight="Bold" Grid.Row="0"/>
<!-- ListBox füllt jetzt automatisch den Rest --> <!-- ListBox füllt jetzt automatisch den Rest -->
<StackPanel IsVisible="{Binding !IsModsLoading}">
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}"> <ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<DockPanel Margin="5"> <Grid ColumnDefinitions="*,Auto" Margin="5" VerticalAlignment="Center">
<!-- Links: Name + Version --> <!-- Links: Name + Version -->
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left"> <StackPanel Orientation="Horizontal" Grid.Column="0">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,10,0"/> <TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,10,0"/>
<TextBlock Text="{Binding Version}" Foreground="Gray"/> <TextBlock Text="{Binding Version}" Foreground="Gray"/>
</StackPanel> </StackPanel>
<!-- Rechts: Icon-Buttons --> <!-- Rechts: Icon-Buttons -->
<StackPanel Orientation="Horizontal" Spacing="8" DockPanel.Dock="Right"> <StackPanel Orientation="Horizontal" Spacing="8" Grid.Column="1" HorizontalAlignment="Right">
<!-- Update nur wenn HasUpdate true --> <!-- Update nur wenn HasUpdate true -->
<Button Command="{Binding $parent[UserControl].DataContext.UpdateModCommand}" <Button Command="{Binding $parent[UserControl].DataContext.UpdateModCommand}"
CommandParameter="{Binding}" CommandParameter="{Binding}"
@@ -70,10 +72,7 @@
BorderThickness="0" BorderThickness="0"
ToolTip.Tip="Update verfügbar" ToolTip.Tip="Update verfügbar"
IsVisible="{Binding HasUpdate}" IsVisible="{Binding HasUpdate}"
HorizontalAlignment="Right" Content="{LucideIconContent ArrowUp}" />
Content="{LucideIconContent ArrowUp}">
</Button>
<!-- Löschen --> <!-- Löschen -->
<Button Command="{Binding $parent[UserControl].DataContext.RemoveModCommand}" <Button Command="{Binding $parent[UserControl].DataContext.RemoveModCommand}"
@@ -81,15 +80,25 @@
Background="Transparent" Background="Transparent"
BorderThickness="0" BorderThickness="0"
ToolTip.Tip="Mod entfernen" ToolTip.Tip="Mod entfernen"
HorizontalAlignment="Right" Content="{LucideIconContent Trash2}" />
Content="{LucideIconContent Trash2}">
</Button>
</StackPanel> </StackPanel>
</DockPanel> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
</StackPanel>
<!-- Spinner -->
<StackPanel IsVisible="{Binding IsModsLoading}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Spacing="10">
<li:LoadingIndicator IsActive="True" Mode="Arcs" SpeedRatio="0.8" Height="100" Width="100" />
<TextBlock Text="Mods werden geladen..."
Foreground="Gray"
FontSize="16"
HorizontalAlignment="Center"/>
</StackPanel>
<Grid Grid.Row="2"> <Grid Grid.Row="2">
<Button Content="Mod hochladen" Command="{Binding UploadModCommand}" Height="80" VerticalContentAlignment="Center" HorizontalAlignment="Center" /> <Button Content="Mod hochladen" Command="{Binding UploadModCommand}" Height="80" VerticalContentAlignment="Center" HorizontalAlignment="Center" />
@@ -105,8 +114,9 @@
<ae:TextEditor <ae:TextEditor
Document="{Binding ConfigDocument}" Document="{Binding ConfigDocument}"
ShowLineNumbers="True" ShowLineNumbers="True"
FontFamily="Cascadia Code, Consolas, Menlo, monospace"
FontSize="16" FontSize="16"
HorizontalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
SyntaxHighlighting="CfgDark" SyntaxHighlighting="CfgDark"
Background="{DynamicResource Cfg.BgBrush}" Background="{DynamicResource Cfg.BgBrush}"