- Editor gefixt :) Sauberes Syntax hervorheben nun Fehler war, avalonia etc zu updaten! regelmäßig updates machen also xD

- UI Überarbeitet im ServerDashboard, bepinex status wird jetzt kleiner wenn nix weiter angezeigt wird und modliste größer. Löschen und update buttons eingefügt in modsliste

TODO: Update und Delete function Mods, Ladeanimation für Modupload und so :P
- Lschen und Update buttons in liste sollen ganz rechts immer sein!
This commit is contained in:
tbS
2025-08-28 23:13:34 +02:00
parent cf6bd3765f
commit 32cbe40921
8 changed files with 215 additions and 122 deletions

View File

@@ -16,8 +16,12 @@
<DataTemplate DataType="viewModels:FtpViewModel">
<views:FtpView/>
</DataTemplate>
<DataTemplate DataType="viewModels:ServerDashboardViewModel">
<views:ServerDashboardView/>
</DataTemplate>
</Application.DataTemplates>
<Application.Styles>
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<FluentTheme/>
<StyleInclude Source="Styles.axaml"/>
<Style>
@@ -34,6 +38,7 @@
<!-- hellgrau -->
<SolidColorBrush x:Key="Cfg.NumberBrush" Color="#CE9178"/>
<!-- amber/zahl -->
<SolidColorBrush x:Key="Cfg.BoolBrush" Color="#4EC9B0"/>
<SolidColorBrush x:Key="Cfg.BgBrush" Color="#1E1E1E"/>
<SolidColorBrush x:Key="Cfg.FgBrush" Color="#D4D4D4"/>
</Style.Resources>

View File

@@ -20,78 +20,93 @@ public partial class App : Application
AvaloniaXamlLoader.Load(this);
}
static HighlightingBrush HB(string key)
{
var obj = Application.Current!.FindResource(key);
if (obj is ISolidColorBrush scb) return new SimpleHighlightingBrush(scb.Color);
return new SimpleHighlightingBrush(Colors.LightGray);
}
private void RegisterCfgHighlighting()
{
static HighlightingBrush HB(string key)
{
var obj = Application.Current!.FindResource(key);
if (obj is ISolidColorBrush scb)
return new SimpleHighlightingBrush(scb.Color); // <-- Color, nicht IBrush
throw new InvalidOperationException($"Resource '{key}' must be a SolidColorBrush.");
}
var section = new HighlightingColor { Foreground = HB("Cfg.SectionBrush"), FontWeight = FontWeight.Bold };
var comment = new HighlightingColor { Foreground = HB("Cfg.CommentBrush"), FontStyle = FontStyle.Italic };
var key = new HighlightingColor { Foreground = HB("Cfg.KeyBrush") };
var keyCol = new HighlightingColor { Foreground = HB("Cfg.KeyBrush") };
var equal = new HighlightingColor { Foreground = HB("Cfg.EqualBrush") };
var value = new HighlightingColor { Foreground = HB("Cfg.ValueBrush") };
var number = new HighlightingColor { Foreground = HB("Cfg.NumberBrush") };
var rules = new HighlightingRuleSet();
// 1) Kommentare: ^\s*#.*
// 0) Volle Kommentarzeilen
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"^\s*#.*", RegexOptions.Compiled | RegexOptions.Multiline),
Regex = new Regex(@"^[ \t]*[;#].*$", RegexOptions.Multiline),
Color = comment
});
// 2) Sektionen: [Name]
// 1) Sektionen: [Section]
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"^\s*\[[^\]\r\n]+\]\s*$", RegexOptions.Compiled | RegexOptions.Multiline),
Regex = new Regex(@"^\s*\[[^\]\r\n]+\]\s*$", RegexOptions.Multiline),
Color = section
});
// 3a) Schl<68>ssel (von Zeilenbeginn bis vor "=")
rules.Spans.Add(new HighlightingSpan
{
StartExpression = new Regex(@"^\s*", RegexOptions.Compiled | RegexOptions.Multiline),
EndExpression = new Regex(@"=", RegexOptions.Compiled),
SpanColor = key
});
// 3b) Gleichheitszeichen
// 2) Key (nur der Text vor '=' auf derselben Zeile)
// - ignoriert f<>hrende Spaces (Lookbehind)
// - endet direkt vor '=' (Lookahead)
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"=", RegexOptions.Compiled),
Regex = new Regex(@"(?<=^[ \t]*)[^=\r\n\[\];#][^=\r\n]*?(?=\s*=)", RegexOptions.Multiline),
Color = keyCol
});
// 3) '=' rot
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"=", RegexOptions.None),
Color = equal
});
// 3c) Werte (von "=" bis Zeilenende; Kommentar nicht einschlie<69>en)
rules.Spans.Add(new HighlightingSpan
{
StartExpression = new Regex(@"=(?!.*#)", RegexOptions.Compiled), // bis Zeilenende ohne #
EndExpression = new Regex(@"$", RegexOptions.Compiled | RegexOptions.Multiline),
SpanColor = value
});
// 3d) Zahlen im Wert hervorheben
// 4a) Zahlen im Value
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"\b-?\d+(\.\d+)?\b", RegexOptions.Compiled),
Regex = new Regex(@"(?<==\s*)(-?\d+(\.\d+)?)", RegexOptions.Multiline),
Color = number
});
var def = new CustomHighlightingDefinition("CfgDark", rules);
HighlightingManager.Instance.RegisterHighlighting("CfgDark", new[] { ".cfg", ".cfg.txt", ".properties" }, def);
// 4b) Bool-Werte im Value
var boolVal = new HighlightingColor { Foreground = HB("Cfg.BoolBrush") };
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"(?<==\s*)(On|Off|True|False)\b", RegexOptions.IgnoreCase | RegexOptions.Multiline),
Color = boolVal
});
IBrush? TryRes(string key) => (IBrush?)Current?.FindResource(key);
// 4c) Allgemeine Werte (kein Zahl, kein Bool)
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"(?<==\s*)(?!On\b|Off\b|True\b|False\b)([A-Za-z_][^\r\n#;]*)",
RegexOptions.IgnoreCase | RegexOptions.Multiline),
Color = value
});
// 6) Inline-Kommentare rechts vom Wert
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"[ \t][;#].*$", RegexOptions.Multiline),
Color = comment
});
var def = new InlineHighlightingDefinition("CfgDark", rules);
HighlightingManager.Instance.RegisterHighlighting("CfgDark", new[] { ".cfg", ".properties" }, def);
}
// kleine Helper-Definition
sealed class CustomHighlightingDefinition : IHighlightingDefinition
sealed class InlineHighlightingDefinition : IHighlightingDefinition
{
public CustomHighlightingDefinition(string name, HighlightingRuleSet rules) { Name = name; MainRuleSet = rules; }
public InlineHighlightingDefinition(string name, HighlightingRuleSet rules)
{ Name = name; MainRuleSet = rules; }
public string Name { get; }
public HighlightingRuleSet MainRuleSet { get; }
public IEnumerable<HighlightingColor> NamedHighlightingColors => Array.Empty<HighlightingColor>();
@@ -99,7 +114,6 @@ public partial class App : Application
public HighlightingRuleSet? GetNamedRuleSet(string name) => null;
public HighlightingColor? GetNamedColor(string name) => null;
}
public override void OnFrameworkInitializationCompleted()
{

View File

@@ -11,5 +11,12 @@ public class ModInfo
public string Name { get; set; }
public string Version { get; set; }
public string ConfigPath { get; set; }
// falls z. B. Versionscheck über Thunderstore/FTP
public string? LatestVersion { get; set; }
public bool HasUpdate =>
!string.IsNullOrEmpty(LatestVersion) &&
LatestVersion != Version;
}

View File

@@ -13,17 +13,18 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia" Version="11.3.4" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.3.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.4" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.4" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.3">
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.4">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.4" />
<PackageReference Include="Lucide.Avalonia" Version="0.1.41" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,4 +1,6 @@
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media;
using AvaloniaEdit.Document;
using ReactiveUI;
using System;
@@ -105,7 +107,8 @@ public class ServerDashboardViewModel : ViewModelBase
public ReactiveCommand<Unit, Unit> UploadModCommand { get; }
public ReactiveCommand<Unit, Unit> InstallFromStoreCommand { get; }
public ReactiveCommand<Unit, Unit> SaveConfigCommand { get; }
public ReactiveCommand<Unit, Unit> RemoveModCommand { get; }
public ReactiveCommand<ModInfo, Unit> RemoveModCommand { get; }
public ReactiveCommand<ModInfo, Unit> UpdateModCommand { get; }
private bool _isLoading;
public bool IsLoading
@@ -118,15 +121,16 @@ public class ServerDashboardViewModel : ViewModelBase
{
InstallBepInExCommand = ReactiveCommand.Create(InstallBepInEx);
UpdateBepInExCommand = ReactiveCommand.Create(UpdateBepInEx);
UploadModCommand = ReactiveCommand.Create(UploadMod);
UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod);
InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore);
SaveConfigCommand = ReactiveCommand.Create(SaveConfig);
RemoveModCommand = ReactiveCommand.Create(RemoveMod);
RemoveModCommand = ReactiveCommand.Create<ModInfo>(RemoveMod);
UpdateModCommand = ReactiveCommand.Create<ModInfo>(UpdateMod);
// DEBUG: harter Testtext – MUSS im Editor erscheinen
ConfigDocument.Text = "[Berries]\n# test\nRaspberryCost = 5";
ConfigDocument.Text = "Bitte Mod Auswählen";
//SelectedMod.Name = "Bitte Mod Auswählen";
// Demo
//BepInExStatus = "Nicht installiert";
@@ -162,6 +166,7 @@ public class ServerDashboardViewModel : ViewModelBase
{
BepInExStatus = "Nicht installiert";
ShowInstallButton = true;
BepInExStatusBrush = Brushes.Red;
return;
}
@@ -196,10 +201,12 @@ public class ServerDashboardViewModel : ViewModelBase
if (info != null)
{
BepInExStatus = $"Installiert (V{info.FileVersion})";
BepInExStatusBrush = Brushes.Green;
}
else
{
BepInExStatus = "Installiert (Version unbekannt)";
BepInExStatusBrush = Brushes.Green;
}
ShowInstallButton = false;
@@ -242,6 +249,14 @@ public class ServerDashboardViewModel : ViewModelBase
set => this.RaiseAndSetIfChanged(ref _isProgress, value);
}
private IBrush _bepInExStatusBrush = Brushes.Red; // default
public IBrush BepInExStatusBrush
{
get => _bepInExStatusBrush;
set => this.RaiseAndSetIfChanged(ref _bepInExStatusBrush, value);
}
public async Task InstallBepInEx()
{
Debug.WriteLine("Install start");
@@ -624,32 +639,63 @@ public class ServerDashboardViewModel : ViewModelBase
{
var dialog = new OpenFileDialog
{
AllowMultiple = false
AllowMultiple = false,
Filters =
{
new FileDialogFilter { Name = "Mod Files", Extensions = { "dll" } },
new FileDialogFilter { Name = "All Files", Extensions = { "*" } }
}
};
dialog.Filters.Add(new FileDialogFilter { Name = "Config Files", Extensions = { "cfg" } });
dialog.Filters.Add(new FileDialogFilter { Name = "All Files", Extensions = { "*" } });
var result = await dialog.ShowAsync(parent);
return result?.FirstOrDefault(); // Gibt den ausgewählten Pfad zurück oder null
return result?.FirstOrDefault();
}
public async Task UploadMod()
{
// 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 path = await OpenFileAsync(parent);
if (string.IsNullOrEmpty(path))
return;
var fileName = Path.GetFileName(path);
var remotePath = FtpViewModel._currentPath.TrimEnd('/') + "/BepInEx/plugins/" + fileName;
try
{
await FtpViewModel._ftpClient.UploadFileAsync(path, remotePath);
Debug.WriteLine($"Upload erfolgreich: {remotePath}");
await LoadModsFromServer();
}
catch (Exception ex)
{
Debug.WriteLine($"Fehler beim Upload: {ex.Message}");
}
}
private async void UploadMod() {
if (_mainWindow == null)
return; // Window muss gesetzt sein
var path = await OpenFileAsync(_mainWindow);
FtpViewModel._ftpClient.UploadFileAsync("", "");
}
private void InstallFromStore() { /* TODO */ }
private void SaveConfig() {
Debug.WriteLine(SelectedMod.ConfigPath);
FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath);
}
private void RemoveMod()
private void RemoveMod(ModInfo mod)
{
if (SelectedMod != null)
Mods.Remove(SelectedMod);
Mods.Remove(mod);
}
private void UpdateMod(ModInfo mod)
{
Debug.WriteLine($"Update {mod.Name} von {mod.Version} → {mod.LatestVersion}");
}
}

View File

@@ -10,21 +10,9 @@ public partial class MainWindow : Window
{
InitializeComponent();
// Loggen, sobald das Fenster ge<67>ffnet wurde (Layout fertig)
this.Opened += (_, __) =>
{
Debug.WriteLine($"Window size after open: {Bounds.Width} x {Bounds.Height}");
};
var locator = new ViewModelLocator();
var mainVm = new MainWindowViewModel(locator);
DataContext = mainVm;
// MainWindow ins ServerDashboardViewModel setzen
if (locator.ServerDashboardViewModel is ServerDashboardViewModel dashboardVm)
{
dashboardVm.SetMainWindow(this); // <-- hier 'this' ist MainWindow
}
DataContext = mainVm;
this.DataContext = mainVm;
}

View File

@@ -7,77 +7,114 @@
mc:Ignorable="d" d:DesignWidth="1424" d:DesignHeight="714"
x:Class="Valheim_Dashboard.Views.ServerDashboardView"
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">
<Grid ColumnDefinitions="2*,3*">
<!-- Linke Spalte -->
<StackPanel Margin="20" Spacing="20">
<Grid Margin="20" RowDefinitions="Auto,*" RowSpacing="20">
<!-- BepInEx Status -->
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="12" Padding="20">
<StackPanel Spacing="10" Height="120">
<TextBlock Text="BepInEx Status" FontSize="28" FontWeight="Bold"/>
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="12" Padding="20"
Grid.Row="0">
<StackPanel Spacing="10">
<Grid>
<TextBlock Text="BepInEx Status" FontSize="28" FontWeight="Bold"/>
<Ellipse Width="20" Height="20" Fill="{Binding BepInExStatusBrush}" Stroke="Black" StrokeThickness="1"
VerticalAlignment="Center"/>
</Grid>
<TextBlock Text="{Binding BepInExStatus}" FontSize="20"/>
<ProgressBar IsVisible="{Binding IsLoading}" />
<Button Content="Installieren"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Command="{Binding InstallBepInExCommand}"
IsVisible="{Binding ShowInstallButton}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Height="80"/>
<Button Content="Update"
Command="{Binding UpdateBepInExCommand}"
IsVisible="{Binding ShowUpdateButton}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Height="80"/>
<ProgressBar Minimum="0" Maximum="100" Value="{Binding ProgressValue}" IsVisible="{Binding IsProgress}" Height="20"/>
<ProgressBar Minimum="0" Maximum="100" Value="{Binding ProgressValue}"
IsVisible="{Binding IsProgress}" Height="20"/>
<TextBlock Text="{Binding ProgressText}" Margin="0,5,0,0" IsVisible="{Binding IsProgress}"/>
</StackPanel>
</Border>
<!-- Mods Liste -->
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="12" Padding="20">
<StackPanel Height="450">
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold"/>
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}" Height="330">
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="12" Padding="20"
Grid.Row="1">
<Grid RowDefinitions="Auto,*,Auto" RowSpacing="10">
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold" Grid.Row="0"/>
<!-- ListBox füllt jetzt automatisch den Rest -->
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,5,0"/>
<TextBlock Text="{Binding Version}" Foreground="Gray"/>
</StackPanel>
<DockPanel Margin="5">
<!-- Links: Name + Version -->
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
<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">
<!-- Update nur wenn HasUpdate true -->
<Button Command="{Binding $parent[UserControl].DataContext.UpdateModCommand}"
CommandParameter="{Binding}"
Background="Transparent"
BorderThickness="0"
ToolTip.Tip="Update verfügbar"
IsVisible="{Binding HasUpdate}"
HorizontalAlignment="Right"
Content="{LucideIconContent ArrowUp}">
</Button>
<!-- Löschen -->
<Button Command="{Binding $parent[UserControl].DataContext.RemoveModCommand}"
CommandParameter="{Binding}"
Background="Transparent"
BorderThickness="0"
ToolTip.Tip="Mod entfernen"
HorizontalAlignment="Right"
Content="{LucideIconContent Trash2}">
</Button>
</StackPanel>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Margin="0,20,0,0">
<Button Content="Mod hochladen" Command="{Binding UploadModCommand}" Height="80" HorizontalAlignment="Left"/>
<Button Content="Aus Store installieren" Command="{Binding InstallFromStoreCommand}" Height="80" HorizontalAlignment="Right"/>
<Grid Grid.Row="2">
<Button Content="Mod hochladen" Command="{Binding UploadModCommand}" Height="80" VerticalContentAlignment="Center" HorizontalAlignment="Center" />
<Button Content="Aus Store installieren" Command="{Binding InstallFromStoreCommand}" Height="80" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
</Grid>
</StackPanel>
</Grid>
</Border>
</StackPanel>
</Grid>
<!-- Rechte Spalte (Config Editor) -->
<StackPanel Grid.Column="1" Margin="20" Spacing="20">
<TextBlock Text="{Binding SelectedMod.Name}" FontSize="28" FontWeight="Bold"/>
<ae:TextEditor
Document="{Binding ConfigDocument}"
x:Name="MyEditorName"
IsVisible="True"
BorderBrush="Black"
BorderThickness="20"
ShowLineNumbers="True"
Background="Red"
Foreground="Yellow"
FontFamily="Cascadia Code, Consolas, Menlo, monospace"
FontSize="20"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" Height="520" />
<ae:TextEditor
Document="{Binding ConfigDocument}"
ShowLineNumbers="True"
FontSize="16"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
SyntaxHighlighting="CfgDark"
Background="{DynamicResource Cfg.BgBrush}"
Foreground="{DynamicResource Cfg.FgBrush}"
Height="520"
/>
<Grid>
<Button Content="Speichern" Command="{Binding SaveConfigCommand}" Height="80" HorizontalAlignment="Left"/>
<Button Content="Mod entfernen" Command="{Binding RemoveModCommand}" Height="80" Background="Red" HorizontalAlignment="Right"/>
<Button Content="Speichern" Command="{Binding SaveConfigCommand}" Height="80" HorizontalAlignment="Right" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
</Grid>
</StackPanel>

View File

@@ -10,11 +10,6 @@ public partial class ServerDashboardView : UserControl
{
public ServerDashboardView()
{
InitializeComponent();
this.AttachedToVisualTree += (_, __) =>
{
var te = this.FindControl<AvaloniaEdit.TextEditor>("MyEditorName");
Debug.WriteLine("TE Document text = " + te?.Document?.Text?.Length);
};
InitializeComponent();
}
}