- add: Autoscroller think

This commit is contained in:
2025-01-19 12:55:39 +03:00
parent 2e3e50e7af
commit 46d17b98b2
3 changed files with 86 additions and 23 deletions

View File

@@ -93,7 +93,7 @@ public partial class ServerEntryModelView : ViewModelBase
{
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"]);
new ServerStatus("Ameba", "Locala meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow ", ["rp:hrp", "18+"], "Antag", 15, 5, 1, false, DateTime.Now, 100), ["meow:rp"]);
}
protected override void Initialise()

View File

@@ -6,18 +6,21 @@
x:DataType="viewModels:ServerEntryModelView"
xmlns="https://github.com/avaloniaui"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
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"
xmlns:converters="clr-namespace:Nebula.Launcher.Converters">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.DataContext>
<viewModels:ServerEntryModelView />
</Design.DataContext>
<Border CornerRadius="10" Margin="0,5,0,5">
<Grid ColumnDefinitions="30,*,80,90" RowDefinitions="35,*,*">
<Border
BorderThickness="0,0,0,0"
CornerRadius="10"
Margin="0,5,0,5">
<Grid ColumnDefinitions="30,*,80,50" RowDefinitions="35,*,*">
<Border
BorderThickness="0,0,0,2"
CornerRadius="10"
@@ -25,6 +28,7 @@
Grid.ColumnSpan="2"
Grid.Row="0"
IsVisible="{Binding ExpandInfo}" />
<Button
Command="{Binding ExpandInfoRequired}"
CornerRadius="10,0,0,10"
@@ -32,12 +36,15 @@
Grid.Row="0"
Grid.RowSpan="3"
VerticalAlignment="Stretch">
<Label VerticalAlignment="Bottom" Margin="5,0,5,2">i</Label>
<Label Margin="5,0,5,0" VerticalAlignment="Bottom">i</Label>
</Button>
<ScrollViewer
Grid.Column="1"
Grid.Row="0"
Margin="5">
HorizontalScrollBarVisibility="Hidden"
Margin="10,0,0,0"
VerticalScrollBarVisibility="Disabled"
x:Name="AutoScrollViewer">
<Label VerticalAlignment="Center">
<TextBlock Text="{Binding ServerHubInfo.StatusData.Name}" />
</Label>
@@ -57,6 +64,7 @@
</Label>
</StackPanel>
<Panel
Grid.Column="3"
Grid.Row="0"
@@ -67,26 +75,15 @@
HorizontalAlignment="Stretch"
IsVisible="{Binding RunVisible}"
VerticalAlignment="Stretch">
<Svg Path="/Assets/svg/play.svg"/>
<Svg Margin="4" Path="/Assets/svg/play.svg" />
</Button>
<Grid ColumnDefinitions="*,*"
IsVisible="{Binding !RunVisible}">
<Grid ColumnDefinitions="*" IsVisible="{Binding !RunVisible}">
<Button
Command="{Binding ReadLog}"
CornerRadius="10,0,0,10"
CornerRadius="10"
HorizontalAlignment="Stretch"
Margin="0,0,2,0"
VerticalAlignment="Stretch">
<Svg Path="/Assets/svg/newspaper.svg"/>
</Button>
<Button
Command="{Binding StopInstance}"
CornerRadius="0,10,10,0"
Grid.Column="1"
HorizontalAlignment="Stretch"
Margin="2,0,0,0"
VerticalAlignment="Stretch">
<Svg Path="/Assets/svg/stop.svg"/>
<Svg Margin="4" Path="/Assets/svg/newspaper.svg" />
</Button>
</Grid>
</Panel>
@@ -99,7 +96,7 @@
IsVisible="{Binding ExpandInfo}"
Margin="5">
<Label FontSize="12">
<TextBlock Text="{Binding Description}" />
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</Label>
</Border>
<Border
@@ -168,6 +165,22 @@
</StackPanel>
</StackPanel>
</Border>
<StackPanel
Grid.Column="3"
Grid.Row="1"
IsVisible="{Binding ExpandInfo}"
Margin="5,5,0,0"
Spacing="5">
<Button
Command="{Binding StopInstance}"
CornerRadius="10"
Height="35"
HorizontalAlignment="Stretch"
IsVisible="{Binding !RunVisible}"
VerticalAlignment="Stretch">
<Svg Margin="4" Path="/Assets/svg/stop.svg" />
</Button>
</StackPanel>
</Grid>
</Border>
</UserControl>

View File

@@ -1,19 +1,69 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using Nebula.Launcher.ViewModels;
namespace Nebula.Launcher.Views;
public partial class ServerEntryView : UserControl
{
private DispatcherTimer _scrollTimer;
private bool _scrollingDown = true;
public ServerEntryView()
{
InitializeComponent();
StartAutoScrolling();
}
public ServerEntryView(ServerEntryModelView modelView) : this()
{
DataContext = modelView;
}
private void StartAutoScrolling()
{
_scrollTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(50) // Adjust the interval for scroll speed
};
_scrollTimer.Tick += AutoScroll;
_scrollTimer.Start();
}
private void AutoScroll(object? sender, EventArgs e)
{
// Get the current offset and extent
var currentOffset = AutoScrollViewer.Offset.X;
var maxOffset = AutoScrollViewer.Extent.Width - AutoScrollViewer.Viewport.Width;
if (_scrollingDown)
{
// Scroll down
if (currentOffset < maxOffset)
{
AutoScrollViewer.Offset = new Avalonia.Vector(currentOffset + 2, AutoScrollViewer.Offset.Y); // Adjust speed
}
else
{
// Reverse direction when reaching the bottom
_scrollingDown = false;
}
}
else
{
// Scroll up
if (currentOffset > 0)
{
AutoScrollViewer.Offset = new Avalonia.Vector(currentOffset - 2, AutoScrollViewer.Offset.Y); // Adjust speed
}
else
{
// Reverse direction when reaching the top
_scrollingDown = true;
}
}
}
}