- 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>
</Application.Styles>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://LoadingIndicators.Avalonia/LoadingIndicators.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -24,6 +24,7 @@
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<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" />
</ItemGroup>
@@ -40,6 +41,9 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Views\ConfirmDialog.axaml.cs">
<DependentUpon>ConfirmDialog.axaml</DependentUpon>
</Compile>
<Compile Update="Views\ServerDashboard.axaml.cs">
<DependentUpon>ServerDashboard.axaml</DependentUpon>
</Compile>

View File

@@ -22,6 +22,7 @@ using Valheim_Dashboard.Models;
using Valheim_Dashboard.Views;
using static System.Net.WebRequestMethods;
namespace Valheim_Dashboard.ViewModels;
public class ServerDashboardViewModel : ViewModelBase
@@ -50,14 +51,29 @@ public class ServerDashboardViewModel : ViewModelBase
public ObservableCollection<ModInfo> Mods { get; } = new();
private ModInfo _selectedMod;
public ModInfo SelectedMod
private ModInfo? _selectedMod;
public ModInfo? SelectedMod
{
get => _selectedMod;
set
{
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> InstallFromStoreCommand { 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; }
private bool _isLoading;
@@ -124,12 +140,22 @@ public class ServerDashboardViewModel : ViewModelBase
UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod);
InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore);
SaveConfigCommand = ReactiveCommand.Create(SaveConfig);
RemoveModCommand = ReactiveCommand.Create<ModInfo>(RemoveMod);
RemoveModCommand = ReactiveCommand.Create<ModInfo,Task>(RemoveMod);
UpdateModCommand = ReactiveCommand.Create<ModInfo>(UpdateMod);
// DEBUG: harter Testtext – MUSS im Editor erscheinen
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";
// Demo
@@ -431,6 +457,14 @@ public class ServerDashboardViewModel : ViewModelBase
//Mod Liste holen
private bool _isModsLoading;
public bool IsModsLoading
{
get => _isModsLoading;
set => this.RaiseAndSetIfChanged(ref _isModsLoading, value);
}
// Hilfsfunktionen
static string NormalizeKey(string s)
@@ -536,6 +570,7 @@ public class ServerDashboardViewModel : ViewModelBase
// Hauptmethode
public async Task LoadModsFromServer()
{
IsModsLoading = true;
try
{
Mods.Clear();
@@ -585,16 +620,7 @@ public class ServerDashboardViewModel : ViewModelBase
cfgHit = cfgFiles.FirstOrDefault(cf => normCandidates.Any(nc => cf.Normalized.Contains(nc)));
// 3) Fallback: „bester“ Fit über LCS
if (cfgHit == null)
{
cfgHit = cfgFiles
.Select(cf => new {
cf,
score = normCandidates.Max(nc => LongestCommonSubsequenceLen(cf.Normalized, nc))
})
.OrderByDescending(x => x.score)
.FirstOrDefault()?.cf;
}
// cfgHit bleibt null
}
// Version aus DLL ziehen
@@ -629,6 +655,10 @@ public class ServerDashboardViewModel : ViewModelBase
{
Debug.WriteLine($"LoadModsFromFtp Fehler: {ex}");
}
finally
{
IsModsLoading = false;
}
}
@@ -689,9 +719,62 @@ public class ServerDashboardViewModel : ViewModelBase
Debug.WriteLine(SelectedMod.ConfigPath);
FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath);
}
private void RemoveMod(ModInfo mod)
private async Task RemoveMod(ModInfo 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)

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:DataType="vm:ServerDashboardViewModel"
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 -->
<Grid Margin="20" RowDefinitions="Auto,*" RowSpacing="20">
@@ -25,7 +26,7 @@
VerticalAlignment="Center"/>
</Grid>
<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"
Command="{Binding InstallBepInExCommand}"
IsVisible="{Binding ShowInstallButton}"
@@ -51,18 +52,19 @@
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold" Grid.Row="0"/>
<!-- ListBox füllt jetzt automatisch den Rest -->
<StackPanel IsVisible="{Binding !IsModsLoading}">
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel Margin="5">
<Grid ColumnDefinitions="*,Auto" Margin="5" VerticalAlignment="Center">
<!-- 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 Version}" Foreground="Gray"/>
</StackPanel>
<!-- 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 -->
<Button Command="{Binding $parent[UserControl].DataContext.UpdateModCommand}"
CommandParameter="{Binding}"
@@ -70,10 +72,7 @@
BorderThickness="0"
ToolTip.Tip="Update verfügbar"
IsVisible="{Binding HasUpdate}"
HorizontalAlignment="Right"
Content="{LucideIconContent ArrowUp}">
</Button>
Content="{LucideIconContent ArrowUp}" />
<!-- Löschen -->
<Button Command="{Binding $parent[UserControl].DataContext.RemoveModCommand}"
@@ -81,15 +80,25 @@
Background="Transparent"
BorderThickness="0"
ToolTip.Tip="Mod entfernen"
HorizontalAlignment="Right"
Content="{LucideIconContent Trash2}">
</Button>
Content="{LucideIconContent Trash2}" />
</StackPanel>
</DockPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</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">
<Button Content="Mod hochladen" Command="{Binding UploadModCommand}" Height="80" VerticalContentAlignment="Center" HorizontalAlignment="Center" />
@@ -105,6 +114,7 @@
<ae:TextEditor
Document="{Binding ConfigDocument}"
ShowLineNumbers="True"
FontFamily="Cascadia Code, Consolas, Menlo, monospace"
FontSize="16"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"