- tweak: Compact view

This commit is contained in:
2025-01-17 16:23:50 +03:00
parent 6cb4666d08
commit c549e449fe
3 changed files with 224 additions and 131 deletions

View File

@@ -26,6 +26,7 @@ public partial class ServerListViewModel : ViewModelBase
//Design think
protected override void InitialiseInDesignMode()
{
Console.WriteLine("SOSAL");
ServerInfos.Add(CreateServerView(new ServerHubInfo("ss14://localhost",
new ServerStatus("Nebula", "TestCraft", ["16+", "RU"], "super", 12, 55, 1, false, DateTime.Now, 20), [])));
ServerInfos.Add(CreateServerView(new ServerHubInfo("ss14://localhost",
@@ -37,6 +38,7 @@ public partial class ServerListViewModel : ViewModelBase
//real think
protected override void Initialise()
{
Console.WriteLine("SOSAL!!");
foreach (var info in HubService.ServerList) UnsortedServers.Add(info);
HubService.HubServerChangedEventArgs += HubServerChangedEventArgs;

View File

@@ -1,15 +1,22 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using Nebula.Launcher.Services;
using Nebula.Launcher.ViewModels.Popup;
using Nebula.Launcher.Views;
using Nebula.Shared.Models;
using Nebula.Shared.Services;
using Nebula.Shared.Utils;
namespace Nebula.Launcher.ViewModels;
@@ -28,10 +35,49 @@ public partial class ServerEntryModelView : ViewModelBase
[GenerateProperty] private RunnerService RunnerService { get; } = default!;
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
[GenerateProperty] private ViewHelperService ViewHelperService { get; } = default!;
[GenerateProperty] private RestService RestService { get; } = default!;
[ObservableProperty] private string _description = "...";
[ObservableProperty] private bool _expandInfo = false;
public bool RunVisible => Process == null;
public ServerHubInfo ServerHubInfo { get; set; } = default!;
private ServerInfo? _serverInfo = null;
public async Task<ServerInfo?> GetServerInfo()
{
if (_serverInfo == null)
{
var result =
await RestService.GetAsync<ServerInfo>(ServerHubInfo.Address.ToRobustUrl().InfoUri, CancellationService.Token);
if (result.Value == null) return null;
_serverInfo = result.Value;
}
return _serverInfo;
}
private ServerHubInfo _serverHubInfo = default!;
public ServerHubInfo ServerHubInfo
{
get => _serverHubInfo;
set
{
Tags.Clear();
foreach (var tag in value.StatusData.Tags)
{
Tags.Add(tag);
}
foreach (var tag in value.InferredTags)
{
Tags.Add(tag);
}
_serverHubInfo = value;
OnPropertyChanged(nameof(ServerHubInfo));
}
}
public ObservableCollection<string> Tags { get; } = [];
private Process? Process
{
@@ -45,7 +91,9 @@ public partial class ServerEntryModelView : ViewModelBase
protected override void InitialiseInDesignMode()
{
Description = "Server of meow girls! Nya~ \nNyaMeow\nOOOINK!!";
ServerHubInfo = new ServerHubInfo("ss14://localhost",
new ServerStatus("Ameba", "Locala", ["rp:hrp", "18+"], "Antag", 15, 5, 1, false, DateTime.Now, 100), ["meow:rp"]);
}
protected override void Initialise()
@@ -164,6 +212,18 @@ public partial class ServerEntryModelView : ViewModelBase
Process?.CloseMainWindow();
}
public async void ExpandInfoRequired()
{
ExpandInfo = !ExpandInfo;
if (Avalonia.Controls.Design.IsDesignMode)
{
return;
}
var info = await GetServerInfo();
Description = info != null ? info.Desc : "Server offline";
}
private static string FindDotnetPath()
{
var pathEnv = Environment.GetEnvironmentVariable("PATH");

View File

@@ -1,37 +1,51 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="100"
x:Class="Nebula.Launcher.Views.ServerEntryView"
x:DataType="viewModels:ServerEntryModelView">
<UserControl
d:DesignHeight="300"
d:DesignWidth="800"
mc:Ignorable="d"
x:Class="Nebula.Launcher.Views.ServerEntryView"
x:DataType="viewModels:ServerEntryModelView"
xmlns="https://github.com/avaloniaui"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.DataContext>
<viewModels:ServerEntryModelView />
</Design.DataContext>
<Grid
ColumnDefinitions="*,120"
Margin="0,5,0,5"
RowDefinitions="30,*">
<Border
BorderThickness="2,0,0,0"
CornerRadius="10,0,0,0"
Grid.Column="0"
Grid.Row="0"
Padding="10,0,0,0">
<Label VerticalAlignment="Center">
<TextBlock Text="{Binding ServerHubInfo.StatusData.Name}" />
</Label>
</Border>
<Border
BorderThickness="2,0,2,0"
CornerRadius="0,10,0,0"
Grid.Column="1"
Grid.Row="0"
Padding="5">
<Border CornerRadius="10" Margin="0,5,0,5">
<Grid ColumnDefinitions="30,*,80,120" RowDefinitions="35,*,*">
<Border
BorderThickness="0,0,0,2"
CornerRadius="10"
Grid.Column="1"
Grid.ColumnSpan="2"
Grid.Row="0"
IsVisible="{Binding ExpandInfo}" />
<Button
Command="{Binding ExpandInfoRequired}"
CornerRadius="10,0,0,10"
Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="3"
VerticalAlignment="Stretch">
<Label VerticalAlignment="Center">
^
</Label>
</Button>
<ScrollViewer
Grid.Column="1"
Grid.Row="0"
Margin="5">
<Label VerticalAlignment="Center">
<TextBlock Text="{Binding ServerHubInfo.StatusData.Name}" />
</Label>
</ScrollViewer>
<StackPanel
Grid.Column="2"
Grid.Row="0"
HorizontalAlignment="Center"
Orientation="Horizontal"
VerticalAlignment="Center">
@@ -43,106 +57,123 @@
<TextBlock Text="{Binding ServerHubInfo.StatusData.SoftMaxPlayers}" />
</Label>
</StackPanel>
</Border>
<Border
BorderThickness="2,0,0,0"
CornerRadius="0,0,10,10"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
MinHeight="50">
<Border.Background>
<ImageBrush Stretch="UniformToFill"
asyncImageLoader:ImageBrushLoader.Source="https://t4.ftcdn.net/jpg/00/81/55/69/360_F_81556974_8sF8cKszJaRfBGd5sDt1RXE2QbzDtQqs.jpg" />
</Border.Background>
<Panel
Grid.Column="3"
Grid.Row="0"
Margin="5,0,0,0">
<Button
Command="{Binding RunInstance}"
CornerRadius="10,10,10,10"
HorizontalAlignment="Stretch"
IsVisible="{Binding RunVisible}"
VerticalAlignment="Stretch">
<Label HorizontalAlignment="Center" VerticalAlignment="Center">
Play
</Label>
</Button>
<Grid Grid.ColumnDefinitions="*,*" IsVisible="{Binding !RunVisible}">
<Button
Command="{Binding ReadLog}"
CornerRadius="10,0,0,10"
HorizontalAlignment="Stretch"
Margin="0,0,1,0"
VerticalAlignment="Stretch">
<Label HorizontalAlignment="Center" VerticalAlignment="Center">
Log
</Label>
</Button>
<Button
Command="{Binding StopInstance}"
CornerRadius="10,0,10,0"
Grid.Column="1"
HorizontalAlignment="Stretch"
Margin="1,0,0,0"
VerticalAlignment="Stretch">
<Label HorizontalAlignment="Center" VerticalAlignment="Center">
Stop
</Label>
</Button>
</Grid>
</Panel>
<Border
BorderThickness="0,2,2,0"
CornerRadius="0,0,10,10"
IsVisible="True"
Margin="0,0,0,0"
Opacity="40"
Padding="0">
<UniformGrid Margin="15,5,15,0">
<UniformGrid.Styles>
<Style Selector="Label">
<Setter Property="FontSize" Value="8" />
</Style>
</UniformGrid.Styles>
<Label>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0">RoundStart:</TextBlock>
<TextBlock Text="{Binding ServerHubInfo.StatusData.RoundStartTime}" />
</StackPanel>
</Label>
<Label>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0">Map:</TextBlock>
<TextBlock Text="{Binding ServerHubInfo.StatusData.Map}" />
</StackPanel>
</Label>
<Label>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0">Preset:</TextBlock>
<TextBlock Text="{Binding ServerHubInfo.StatusData.Preset}" />
</StackPanel>
</Label>
<Label>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0">PanicBunker:</TextBlock>
<TextBlock Text="{Binding ServerHubInfo.StatusData.PanicBunker}" />
</StackPanel>
</Label>
<Label>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0">Round Id:</TextBlock>
<TextBlock Text="{Binding ServerHubInfo.StatusData.RoundId}" />
</StackPanel>
</Label>
<Label>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0">Run Level:</TextBlock>
<TextBlock Text="{Binding ServerHubInfo.StatusData.RunLevel}" />
</StackPanel>
</Label>
</UniformGrid>
</Border>
</Border>
<Panel Grid.Column="1" Grid.Row="1">
<Button
Command="{Binding RunInstance}"
CornerRadius="10,0,10,10"
HorizontalAlignment="Stretch"
IsVisible="{Binding RunVisible}"
VerticalAlignment="Stretch">
<Label HorizontalAlignment="Center" VerticalAlignment="Center">
Play
BorderThickness="0,0,0,0"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.Row="1"
IsVisible="{Binding ExpandInfo}"
Margin="5">
<Label FontSize="12">
<TextBlock Text="{Binding Description}" />
</Label>
</Button>
<Grid Grid.ColumnDefinitions="*,*" IsVisible="{Binding !RunVisible}">
<Button
Command="{Binding ReadLog}"
CornerRadius="10,0,0,10"
HorizontalAlignment="Stretch"
Margin="0,0,1,0"
VerticalAlignment="Stretch">
<Label HorizontalAlignment="Center" VerticalAlignment="Center">
Log
</Label>
</Button>
<Button
Command="{Binding StopInstance}"
CornerRadius="0,0,10,0"
Grid.Column="1"
HorizontalAlignment="Stretch"
Margin="1,0,0,0"
VerticalAlignment="Stretch">
<Label HorizontalAlignment="Center" VerticalAlignment="Center">
Stop
</Label>
</Button>
</Grid>
</Panel>
</Grid>
</Border>
<Border
BorderThickness="0,2,0,0"
CornerRadius="10"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.Row="2"
IsVisible="{Binding ExpandInfo}"
Margin="5,15,15,5">
<StackPanel Margin="5" Spacing="4">
<StackPanel Orientation="Horizontal">
<Label FontSize="10" VerticalAlignment="Center">Tags:</Label>
<ItemsControl ItemsSource="{Binding Tags}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type system:String}">
<Border
Background="#121212"
CornerRadius="8"
HorizontalAlignment="Center"
Margin="1,1,1,1"
VerticalAlignment="Center">
<Label FontSize="10" Margin="5,0,5,0">
<TextBlock Text="{Binding}" />
</Label>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
HorizontalAlignment="Left"
Orientation="Horizontal"
VerticalAlignment="Center" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontSize="10" VerticalAlignment="Center">Map:</Label>
<Border
Background="#121212"
CornerRadius="8"
HorizontalAlignment="Center"
Margin="1,1,1,1"
VerticalAlignment="Center">
<Label FontSize="10" Margin="5,0,5,0">
<TextBlock Text="{Binding ServerHubInfo.StatusData.Map}" />
</Label>
</Border>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontSize="10" VerticalAlignment="Center">Preset:</Label>
<Border
Background="#121212"
CornerRadius="8"
HorizontalAlignment="Center"
Margin="1,1,1,1"
VerticalAlignment="Center">
<Label FontSize="10" Margin="5,0,5,0">
<TextBlock Text="{Binding ServerHubInfo.StatusData.Preset}" />
</Label>
</Border>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</Border>
</UserControl>