|
@@ -34,6 +34,8 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
{
|
|
|
public MainWindowViewModel()
|
|
|
{
|
|
|
+ _serverPanels = new();
|
|
|
+
|
|
|
Task.Run(async () =>
|
|
|
{
|
|
|
try
|
|
@@ -164,19 +166,9 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
_connection.Reconnecting += reconnecting;
|
|
|
_connection.Reconnected += reconnected;
|
|
|
-
|
|
|
- if (Avalonia.Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop && desktop.MainWindow is not null)
|
|
|
- {
|
|
|
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
|
- Dispatcher.UIThread.InvokeAsync(() =>
|
|
|
- {
|
|
|
- var stackpanel = desktop.MainWindow.GetControl<StackPanel>("ServersStackPanel");
|
|
|
- foreach (var server in serverNames)
|
|
|
- stackpanel.Children.Add(CreateServerPanel(server));
|
|
|
- });
|
|
|
-#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
+ foreach (var server in serverNames)
|
|
|
+ ServerPanels.Add(CreateServerPanel(server));
|
|
|
|
|
|
await _connection.StartAsync();
|
|
|
|
|
@@ -273,25 +265,24 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
DownloadedVersion _startedVersion;
|
|
|
|
|
|
ObservableCollection<DownloadedVersion> _downloadedVersions;
|
|
|
+ ObservableCollection<ServerPanelModel> _serverPanels;
|
|
|
|
|
|
- public ObservableCollection<DownloadedVersion> DownloadedVersions {
|
|
|
- get => _downloadedVersions;
|
|
|
- set
|
|
|
- {
|
|
|
- this.RaiseAndSetIfChanged(ref _downloadedVersions, value);
|
|
|
- }
|
|
|
+ public ObservableCollection<DownloadedVersion> DownloadedVersions
|
|
|
+ {
|
|
|
+ get => _downloadedVersions;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _downloadedVersions, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ObservableCollection<ServerPanelModel> ServerPanels
|
|
|
+ {
|
|
|
+ get => _serverPanels;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _serverPanels, value);
|
|
|
}
|
|
|
|
|
|
public DownloadedVersion DownloadedVersion
|
|
|
{
|
|
|
get => _downloadedVersion;
|
|
|
- set
|
|
|
- {
|
|
|
- this.RaiseAndSetIfChanged(ref _downloadedVersion, value);
|
|
|
- //Settings.lastChosenVersion = value.version;
|
|
|
- //logger.Debug("Version choosen: {0}",value.version);
|
|
|
- //logger.Debug("Version json: {0}", value.path);
|
|
|
- }
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _downloadedVersion, value);
|
|
|
}
|
|
|
|
|
|
public int DownloadedIndex
|
|
@@ -836,46 +827,16 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Panel CreateServerPanel(string name)
|
|
|
+ private ServerPanelModel CreateServerPanel(string name)
|
|
|
{
|
|
|
- ServerPanelModel serverPanelModel = new(name, "Wait for update...", "No players.",string.Empty);
|
|
|
-
|
|
|
- Panel panel = new Panel()
|
|
|
- {
|
|
|
- VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top,
|
|
|
- HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch,
|
|
|
- Height = 75,
|
|
|
- Width = 150,
|
|
|
- Margin = Avalonia.Thickness.Parse("0 0 10 10")
|
|
|
- };
|
|
|
-
|
|
|
- panel.Children.Add(new Border()
|
|
|
- {
|
|
|
- Background = Brushes.Black,
|
|
|
- Opacity = 0.2,
|
|
|
- CornerRadius = Avalonia.CornerRadius.Parse("15")
|
|
|
- });
|
|
|
-
|
|
|
- var tip = new ToolTip()
|
|
|
- {
|
|
|
- Content = new TextBlock() {TextWrapping = TextWrapping.Wrap, [!TextBlock.TextProperty] = new Binding { Source = serverPanelModel,Path = nameof(serverPanelModel.Tip) } }
|
|
|
- };
|
|
|
-
|
|
|
- ToolTip.SetTip(panel, tip);
|
|
|
-
|
|
|
- StackPanel textPanel = new() { VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center };
|
|
|
-
|
|
|
- textPanel.Children.Add(new TextBlock() { VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center, [!TextBlock.TextProperty] = new Binding { Source = serverPanelModel, Path = nameof(serverPanelModel.Status) } });
|
|
|
- textPanel.Children.Add(new TextBlock() { FontSize = 20, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center, [!TextBlock.TextProperty] = new Binding { Source = serverPanelModel, Path = nameof(serverPanelModel.Players) } });
|
|
|
-
|
|
|
- panel.Children.Add(textPanel);
|
|
|
+ ServerPanelModel serverPanelModel = new(name, "Wait for update...", "No players.","-/-");
|
|
|
|
|
|
System.Timers.Timer timeoutTimer = new System.Timers.Timer(30000);
|
|
|
|
|
|
timeoutTimer.Elapsed += (object? source, ElapsedEventArgs e) =>
|
|
|
{
|
|
|
serverPanelModel.Status = $"{serverPanelModel.Name}: Offline";
|
|
|
- serverPanelModel.Players = string.Empty;
|
|
|
+ serverPanelModel.Players = "-/-";
|
|
|
};
|
|
|
timeoutTimer.Start();
|
|
|
|
|
@@ -901,7 +862,7 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
timeoutTimer.Start();
|
|
|
});
|
|
|
|
|
|
- return panel;
|
|
|
+ return serverPanelModel;
|
|
|
}
|
|
|
|
|
|
public void OnClosing(object sender, CancelEventArgs args)
|