fix scrollbars and whatever broke after rebase

This commit is contained in:
vddCore 2024-03-29 07:55:55 +01:00
parent 6a41444fac
commit 054555afcb
10 changed files with 315 additions and 352 deletions

View file

@ -5,4 +5,6 @@ namespace Saradomin.Infrastructure
public record MainViewLoadedMessage : Message;
public record NotificationBoxStateChangedMessage(bool WasOpened) : Message;
public record SettingsModifiedMessage(string SettingName) : Message;
public record ClientClosedMessage : Message;
public record ClientLaunchRequestedMessage : Message;
}

View file

@ -1,8 +0,0 @@
using Glitonea.Mvvm.Messaging;
namespace Saradomin.Infrastructure.Messaging;
public class ClientClosedMessage : Message
{
}

View file

@ -1,8 +0,0 @@
using Glitonea.Mvvm.Messaging;
namespace Saradomin.Infrastructure.Messaging;
public class ClientLaunchRequestedMessage : Message
{
}

View file

@ -1,34 +1,35 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style Selector="ListBox.PluginList &gt; ListBoxItem">
<Style Selector="ListBox.PluginList > ListBoxItem">
<Setter Property="Background" Value="{StaticResource DarkMediumBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource LightForegroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList > ListBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource DarkMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:selected /template/ ContentPresenter">
<Style Selector="ListBox.PluginList > ListBoxItem:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource DarkMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:pointerover /template/ ContentPresenter">
<Style Selector="ListBox.PluginList > ListBoxItem:pressed /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource DarkMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:pressed /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource DarkMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:nth-child(2n) /template/ ContentPresenter">
<Style Selector="ListBox.PluginList > ListBoxItem:nth-child(2n) /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource SemiLightMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:nth-child(2n):selected /template/ ContentPresenter">
<Style Selector="ListBox.PluginList > ListBoxItem:nth-child(2n):selected /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource SemiLightMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:nth-child(2n):pressed /template/ ContentPresenter">
<Style Selector="ListBox.PluginList > ListBoxItem:nth-child(2n):pressed /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource SemiLightMediumBackgroundBrush}" />
</Style>
<Style Selector="ListBox.PluginList &gt; ListBoxItem:nth-child(2n):pointerover /template/ ContentPresenter">
<Style Selector="ListBox.PluginList > ListBoxItem:nth-child(2n):pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{StaticResource SemiLightMediumBackgroundBrush}" />
</Style>
</Styles>

View file

@ -9,6 +9,10 @@
<Setter Property="Padding" Value="1" />
<Setter Property="ClipValueToMinMax" Value="True" />
</Style>
<Style Selector="NumericUpDown.NormalNumericUpDown /template/ TextBox#PART_TextBox /template/ ScrollViewer#PART_ScrollViewer /template/ ScrollBar">
<Setter Property="Visibility" Value="Hidden" />
</Style>
<!-- https://github.com/AvaloniaUI/Avalonia/issues/2098
https://github.com/AvaloniaUI/Avalonia/issues/1635 -->

View file

@ -1,51 +1,25 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style Selector="ScrollBar:vertical">
<Setter Property="Width" Value="10" />
<Setter Property="Template">
<ControlTemplate>
<Border Background="{StaticResource MediumBackgroundBrush}"
ClipToBounds="True">
<Grid RowDefinitions="Auto,*,Auto"
Background="{StaticResource DarkBackgroundBrush}">
<Track Grid.Row="1"
Grid.Column="1"
Minimum="{TemplateBinding Minimum}"
Maximum="{TemplateBinding Maximum}"
Value="{TemplateBinding Value, Mode=TwoWay}"
ViewportSize="{TemplateBinding ViewportSize}"
Orientation="{TemplateBinding Orientation}"
IsDirectionReversed="True">
<Thumb Name="thumb"
Width="4"
Margin="0,10,0,10" />
</Track>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="ScrollViewer.MainViewScrollViewer /template/ ScrollBar:vertical">
<Setter Property="Width" Value="10" />
<Setter Property="Template">
<ControlTemplate>
<Border Background="{StaticResource MediumBackgroundBrush}"
ClipToBounds="True"
CornerRadius="0,6,0,0">
CornerRadius="0,4,0,0">
<Grid RowDefinitions="Auto,*,Auto"
Background="{StaticResource DarkBackgroundBrush}">
<Track Grid.Row="1"
Grid.Column="1"
Minimum="{TemplateBinding Minimum}"
Maximum="{TemplateBinding Maximum}"
Value="{TemplateBinding Value, Mode=TwoWay}"
ViewportSize="{TemplateBinding ViewportSize}"
Orientation="{TemplateBinding Orientation}"
DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
IsDirectionReversed="True">
<Thumb Name="thumb"
Width="4"
Margin="0,10,0,10" />
<Track.Thumb>
<Thumb Name="thumb" Width="4" ClipToBounds="True" />
</Track.Thumb>
</Track>
</Grid>
</Border>
@ -56,6 +30,11 @@
<Style Selector="Thumb#thumb">
<Setter Property="Background" Value="{StaticResource DarkMediumBackgroundBrush}" />
</Style>
<Style Selector="Thumb#thumb /template/ Border">
<Setter Property="Margin" Value="0,6" />
</Style>
<Style Selector="Thumb#thumb:pointerover">
<Setter Property="Background" Value="{StaticResource MouseOverBrush}" />

View file

@ -6,101 +6,95 @@
xmlns:mvvm="clr-namespace:Glitonea.Mvvm;assembly=Glitonea"
xmlns:vm="clr-namespace:Saradomin.ViewModel.Controls"
DataContext="{mvvm:DataContextSource vm:PluginManagerViewModel}">
<Grid RowDefinitions="*,Auto">
<Border Grid.Row="1"
Height="2"
Margin="1,2"
BorderBrush="{StaticResource DarkMediumBorderBrush}"
BorderThickness="0,1,0,0" />
<Border Grid.Row="0">
<Grid RowDefinitions="Auto,*">
<Border Grid.Row="0"
Height="350"
Margin="0,2,0,0"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1,1,0,1"
ClipToBounds="True">
<Grid>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#BBFFFFFF"
IsVisible="{Binding !!!PluginList.Count}"
Text="Fetching plugin metadata..."
ZIndex="9999"
Width="425" />
<ListBox Classes="PluginList"
ItemsSource="{Binding PluginList}"
SelectionMode="Single"
ClipToBounds="True"
IsVisible="{Binding PluginList.Count}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type model:PluginInfo}">
<Grid ColumnDefinitions="250,50,100" RowDefinitions="*" >
<TextBlock Grid.Column="1"
Margin="2,5,2,0"
<Border>
<Grid RowDefinitions="Auto,*">
<Border Grid.Row="0"
Height="350"
Margin="0,2,0,0"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1,1,0,1"
ClipToBounds="True">
<Grid>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#BBFFFFFF"
IsVisible="{Binding !!!PluginList.Count}"
Text="Fetching plugin metadata..."
ZIndex="9999"
Width="425" />
<ListBox Classes="PluginList"
ItemsSource="{Binding PluginList}"
SelectionMode="Single"
ClipToBounds="True"
IsVisible="{Binding PluginList.Count}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type model:PluginInfo}">
<Grid ColumnDefinitions="250,50,100" RowDefinitions="*" >
<TextBlock Grid.Column="1"
Margin="2,5,2,0"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Foreground="#BBFFFFFF"
FontSize="11"
Text="{Binding Version}" />
<Button Grid.Row="0"
Grid.Column="2"
Margin="-125,0,2,2"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1"
Classes="OutsideNavigator"
Command="{Binding $parent[local:PluginManagerView].DataContext.UpdateLocalPlugin}"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Foreground="#BBFFFFFF"
FontSize="11"
Text="{Binding Version}" />
<Button Grid.Row="0" Grid.Column="2"
Margin="-125,0,2,2"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1"
Classes="OutsideNavigator"
Command="{Binding $parent[local:PluginManagerView].DataContext.UpdateLocalPlugin}"
VerticalAlignment="Top"
Content="Update"
IsVisible="{Binding CanUpdate}"
IsEnabled="{Binding !$parent[local:PluginManagerView].DataContext.IsTransactionInProgress}" />
<Button Grid.Row="0" Grid.Column="2"
Margin="0,0,2,2"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1"
Classes="OutsideNavigator"
Command="{Binding $parent[local:PluginManagerView].DataContext.InstallRemotePlugin}"
CommandParameter="{Binding}"
VerticalAlignment="Top"
Content="Install"
IsVisible="{Binding !Installed}"
IsEnabled="{Binding !$parent[local:PluginManagerView].DataContext.IsTransactionInProgress}" />
<Button Grid.Row="0" Grid.Column="2"
Margin="0,0,2,2"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1"
Classes="OutsideNavigator"
Command="{Binding $parent[local:PluginManagerView].DataContext.UninstallLocalPlugin}"
CommandParameter="{Binding}"
VerticalAlignment="Top"
Content="Uninstall"
IsVisible="{Binding Installed}"
IsEnabled="{Binding !$parent[local:PluginManagerView].DataContext.IsTransactionInProgress}" />
<Expander Grid.Column="0" Grid.Row="0" Header="{Binding Name}">
<StackPanel>
<TextBlock
Margin="2,0,0,0"
VerticalAlignment="Center"
Foreground="#BBFFFFFF"
FontSize="11"
FontStyle="Oblique"
Text="{Binding Author}" />
Content="Update"
IsVisible="{Binding CanUpdate}"
IsEnabled="{Binding !$parent[local:PluginManagerView].DataContext.IsTransactionInProgress}" />
<Button Grid.Row="0"
Grid.Column="2"
Margin="0,0,2,2"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1"
Classes="OutsideNavigator"
Command="{Binding $parent[local:PluginManagerView].DataContext.InstallRemotePlugin}"
CommandParameter="{Binding}"
VerticalAlignment="Top"
Content="Install"
IsVisible="{Binding !Installed}"
IsEnabled="{Binding !$parent[local:PluginManagerView].DataContext.IsTransactionInProgress}" />
<Button Grid.Row="0"
Grid.Column="2"
Margin="0,0,2,2"
BorderBrush="{StaticResource DarkBorderBrush}"
BorderThickness="1"
Classes="OutsideNavigator"
Command="{Binding $parent[local:PluginManagerView].DataContext.UninstallLocalPlugin}"
CommandParameter="{Binding}"
VerticalAlignment="Top"
Content="Uninstall"
IsVisible="{Binding Installed}"
IsEnabled="{Binding !$parent[local:PluginManagerView].DataContext.IsTransactionInProgress}" />
<Expander Grid.Column="0" Grid.Row="0" Header="{Binding Name}">
<StackPanel>
<TextBlock Margin="2,0,0,0"
VerticalAlignment="Center"
Foreground="#BBFFFFFF"
FontSize="11"
FontStyle="Oblique"
Text="{Binding Author}" />
<TextBlock
Margin="2,5,0,4"
VerticalAlignment="Bottom"
Foreground="#BBFFFFFF"
TextWrapping="Wrap"
FontSize="11"
Text="{Binding Description}" />
</StackPanel>
</Expander>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
</Grid>
</Border>
</Grid>
<TextBlock Margin="2,5,0,4"
VerticalAlignment="Bottom"
Foreground="#BBFFFFFF"
TextWrapping="Wrap"
FontSize="11"
Text="{Binding Description}" />
</StackPanel>
</Expander>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
</Grid>
</Border>
</UserControl>

View file

@ -2,8 +2,6 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Saradomin.View.Controls"
xmlns:converters="clr-namespace:Glitonea.Mvvm.Converters;assembly=Glitonea"
xmlns:glitonea="clr-namespace:Glitonea;assembly=Glitonea"
xmlns:mvvm="clr-namespace:Glitonea.Mvvm;assembly=Glitonea"
xmlns:vm="clr-namespace:Saradomin.ViewModel.Controls"
DataContext="{mvvm:DataContextSource vm:SettingsViewModel}">
@ -180,14 +178,14 @@
<HeaderedContentControl Grid.Row="1"
Margin="0,4,0,4"
Padding="3,0,7,0"
Padding="3,0,0,0"
BorderThickness="0"
Classes="GroupBox"
Header="plugin management">
<DockPanel>
<controls:PluginManagerView Margin="-2,2" Name="PmView"/>
<Button
Margin="-141,-17,0,2"
<Button Margin="-141,-17,0,2"
Width="140"
Height="17"
BorderBrush="{StaticResource DarkBorderBrush}"

View file

@ -112,7 +112,7 @@
HorizontalContentAlignment="Center"
CornerRadius="0,0,0,0"
Header="settings">
<Border Margin="4,0,4,0"
<Border Margin="4,4,4,0"
Background="{StaticResource MediumBackgroundBrush}"
BorderBrush="{StaticResource SemiLightMediumBorderBrush}"
BorderThickness="1,1,1,0"
@ -120,7 +120,8 @@
<ScrollViewer Classes="MainViewScrollViewer"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Visible">
<controls:SettingsView VerticalAlignment="Stretch" />
<controls:SettingsView VerticalAlignment="Stretch"
MaxHeight="500"/>
</ScrollViewer>
</Border>
</TabItem>
@ -129,7 +130,7 @@
HorizontalContentAlignment="Center"
CornerRadius="0,0,8,0"
Header="singleplayer">
<Border Margin="4,0,4,0"
<Border Margin="4,4,4,0"
Background="{StaticResource MediumBackgroundBrush}"
BorderBrush="{StaticResource SemiLightMediumBorderBrush}"
BorderThickness="1,1,1,0"

View file

@ -15,226 +15,226 @@ using Avalonia.Media;
using Avalonia.Threading;
using Glitonea.Mvvm;
using Glitonea.Mvvm.Messaging;
using Saradomin.Infrastructure.Messaging;
using Saradomin.Infrastructure;
using Saradomin.Infrastructure.Services;
using Saradomin.Model.Settings.Launcher;
using Saradomin.Utilities;
using Saradomin.View.Windows;
using static Saradomin.Utilities.SingleplayerManagement;
namespace Saradomin.ViewModel.Controls;
public class SingleplayerViewModel : ViewModelBase
namespace Saradomin.ViewModel.Controls
{
private readonly ISingleplayerUpdateService _singleplayerUpdateService;
private readonly ISettingsService _settingsService;
private readonly IJavaUpdateService _javaUpdateService;
public string SingleplayerDownloadText { get; private set; } =
Directory.Exists(CrossPlatform.GetSingleplayerHome()) ? "Update Singleplayer" : "Download Singleplayer";
public bool CanLaunch { get; private set; } = File.Exists(CrossPlatform.LocateSingleplayerExecutable());
public TextBox SingleplayerLogsTextBox { get; }
public bool ShowLogPanel { get; private set; }
public LauncherSettings Launcher => _settingsService.Launcher;
private string _oldServerAddress, _oldManagementAddress;
private Process _serverProcess;
public SingleplayerViewModel(ISettingsService settingsService,
IJavaUpdateService javaUpdateService,
ISingleplayerUpdateService iSingleplayerUpdateService)
public class SingleplayerViewModel : ViewModelBase
{
_settingsService = settingsService;
_javaUpdateService = javaUpdateService;
_singleplayerUpdateService = iSingleplayerUpdateService;
_singleplayerUpdateService.SingleplayerDownloadProgressChanged += OnSingleplayerDownloadProgressChanged;
private readonly ISingleplayerUpdateService _singleplayerUpdateService;
private readonly ISettingsService _settingsService;
private readonly IJavaUpdateService _javaUpdateService;
SingleplayerLogsTextBox = new TextBox
public string SingleplayerDownloadText { get; private set; } =
Directory.Exists(CrossPlatform.GetSingleplayerHome()) ? "Update Singleplayer" : "Download Singleplayer";
public bool CanLaunch { get; private set; } = File.Exists(CrossPlatform.LocateSingleplayerExecutable());
public TextBox SingleplayerLogsTextBox { get; }
public bool ShowLogPanel { get; private set; }
public LauncherSettings Launcher => _settingsService.Launcher;
private string _oldServerAddress, _oldManagementAddress;
private Process _serverProcess;
public SingleplayerViewModel(ISettingsService settingsService,
IJavaUpdateService javaUpdateService,
ISingleplayerUpdateService iSingleplayerUpdateService)
{
Foreground = new SolidColorBrush(Colors.Black),
FontSize = 12,
Margin = new Thickness(8, 0, 0, 0),
IsReadOnly = true,
BorderThickness = new Thickness(0),
Background = Brushes.Transparent,
AcceptsReturn = true,
TextWrapping = TextWrapping.Wrap,
};
_settingsService = settingsService;
_javaUpdateService = javaUpdateService;
_singleplayerUpdateService = iSingleplayerUpdateService;
_singleplayerUpdateService.SingleplayerDownloadProgressChanged += OnSingleplayerDownloadProgressChanged;
SingleplayerLogsTextBox = new TextBox
{
Foreground = new SolidColorBrush(Colors.Black),
FontSize = 12,
Margin = new Thickness(8, 0, 0, 0),
IsReadOnly = true,
BorderThickness = new Thickness(0),
Background = Brushes.Transparent,
AcceptsReturn = true,
TextWrapping = TextWrapping.Wrap,
};
Message.Subscribe<ClientClosedMessage>(this, OnClientClosed);
}
Message.Subscribe<ClientClosedMessage>(this, OnClientClosed);
}
private void OnClientClosed(ClientClosedMessage _)
{
if (_serverProcess == null) return;
_serverProcess.Kill();
_serverProcess = null;
CanLaunch = true;
_settingsService.Client.GameServerAddress = _oldServerAddress;
_settingsService.Client.ManagementServerAddress = _oldManagementAddress;
}
private void OnSingleplayerDownloadProgressChanged(object sender, Tuple<float, bool> e)
{
float progress = e.Item1;
bool finished = e.Item2;
if (finished)
private void OnClientClosed(ClientClosedMessage _)
{
SingleplayerDownloadText = "Update Singleplayer";
ApplyLatestBackup(PrintLog);
PrintLog($"Singleplayer Download complete");
PrintLog($"");
if (_serverProcess == null) return;
_serverProcess.Kill();
_serverProcess = null;
CanLaunch = true;
return;
_settingsService.Client.GameServerAddress = _oldServerAddress;
_settingsService.Client.ManagementServerAddress = _oldManagementAddress;
}
if (progress >= 1f)
private void OnSingleplayerDownloadProgressChanged(object sender, Tuple<float, bool> e)
{
SingleplayerDownloadText = "Extracting...";
return;
float progress = e.Item1;
bool finished = e.Item2;
if (finished)
{
SingleplayerDownloadText = "Update Singleplayer";
ApplyLatestBackup(PrintLog);
PrintLog($"Singleplayer Download complete");
PrintLog($"");
CanLaunch = true;
return;
}
if (progress >= 1f)
{
SingleplayerDownloadText = "Extracting...";
return;
}
SingleplayerDownloadText = $"Downloading... {progress * 100:F2}%";
}
SingleplayerDownloadText = $"Downloading... {progress * 100:F2}%";
}
public void DownloadSingleplayer()
{
if (File.Exists(CrossPlatform.LocateSingleplayerExecutable()) && !CanLaunch) return; // While the button could be disabled, this looks nicer visually (since we update the download progress in the button text)
CanLaunch = false;
MakeBackup();
PrintLog($"Starting singleplayer download...");
_singleplayerUpdateService.DownloadSingleplayer();
}
public void DownloadSingleplayer()
{
if (File.Exists(CrossPlatform.LocateSingleplayerExecutable()) && !CanLaunch) return; // While the button could be disabled, this looks nicer visually (since we update the download progress in the button text)
CanLaunch = false;
MakeBackup();
PrintLog($"Starting singleplayer download...");
_singleplayerUpdateService.DownloadSingleplayer();
}
private void MakeBackup()
{
PrintLog("Starting backup of player saves and economy files..");
SingleplayerManagement.MakeBackup(PrintLog);
PrintLog($"Done backing up player saves and economy files");
PrintLog($"");
}
private void MakeBackup()
{
PrintLog("Starting backup of player saves and economy files..");
SingleplayerManagement.MakeBackup(PrintLog);
PrintLog($"Done backing up player saves and economy files");
PrintLog($"");
}
public void OpenBackupFolder()
{
if (!Directory.Exists(CrossPlatform.GetSingleplayerBackupsHome()))
Directory.CreateDirectory(CrossPlatform.GetSingleplayerBackupsHome());
CrossPlatform.OpenFolder(CrossPlatform.GetSingleplayerBackupsHome());
}
public void OpenBackupFolder()
{
if (!Directory.Exists(CrossPlatform.GetSingleplayerBackupsHome()))
Directory.CreateDirectory(CrossPlatform.GetSingleplayerBackupsHome());
CrossPlatform.OpenFolder(CrossPlatform.GetSingleplayerBackupsHome());
}
[Pure]
public static bool IsServerTerminationLog(string log)
{
return Regex.IsMatch(log, @"^\[\d{2}:\d{2}:\d{2}\]: \[SystemTermination\] Server successfully terminated!\s*$");
}
[Pure]
public static bool IsServerTerminationLog(string log)
{
return Regex.IsMatch(log, @"^\[\d{2}:\d{2}:\d{2}\]: \[SystemTermination\] Server successfully terminated!\s*$");
}
private void PrintLog(string message)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) message = Regex.Replace(message, @"\e\[[0-9;]*m", string.Empty);
private void PrintLog(string message)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) message = Regex.Replace(message, @"\e\[[0-9;]*m", string.Empty);
ShowLogPanel = true;
Dispatcher.UIThread.Post(() => { SingleplayerLogsTextBox.Text += message + Environment.NewLine; },
DispatcherPriority.Background);
ShowLogPanel = true;
Dispatcher.UIThread.Post(() => { SingleplayerLogsTextBox.Text += message + Environment.NewLine; },
DispatcherPriority.Background);
if (IsServerTerminationLog(message)) CanLaunch = true;
}
public async void LaunchSingleplayer()
{
string javaVersionOutput = CrossPlatform.RunCommandAndGetOutput(
$"\"{Launcher.JavaExecutableLocation}\" -version"
);
if (!javaVersionOutput.Contains("11"))
{
PrintLog("You don't have Java 11 set! Saradomin will grab it's own copy..");
await _javaUpdateService.DownloadAndSetJava11(_settingsService);
}
CanLaunch = false;
PrintLog("Starting Singleplayer.. The Singleplayer client will launch when 2009scape is ready. Sit tight!");
_oldServerAddress = _settingsService.Client.GameServerAddress;
_oldManagementAddress = _settingsService.Client.ManagementServerAddress;
_settingsService.Client.GameServerAddress = _settingsService.Client.ManagementServerAddress = "localhost";
new Task(() => LaunchServerAndClient(Launcher.JavaExecutableLocation, PrintLog)).Start();
}
private void LaunchServerAndClient (string javaExecutableLocation, Action<string> log)
{
var serverJar = CrossPlatform.GetSingleplayerHome() + @"/game/server.jar";
if (IsPortInUse(43595))
{
log("Port 43595 is in use. Cannot start the server again.");
return;
if (IsServerTerminationLog(message)) CanLaunch = true;
}
_serverProcess = CrossPlatform.StartJavaProcess(javaExecutableLocation, serverJar, "2G", log, null);
while (!IsPortInUse(43595)) Thread.Sleep(1000);
Message.Broadcast<ClientLaunchRequestedMessage>();
}
public async void LaunchSingleplayer()
{
string javaVersionOutput = CrossPlatform.RunCommandAndGetOutput(
$"\"{Launcher.JavaExecutableLocation}\" -version"
);
if (!javaVersionOutput.Contains("11"))
{
PrintLog("You don't have Java 11 set! Saradomin will grab it's own copy..");
await _javaUpdateService.DownloadAndSetJava11(_settingsService);
}
CanLaunch = false;
PrintLog("Starting Singleplayer.. The Singleplayer client will launch when 2009scape is ready. Sit tight!");
_oldServerAddress = _settingsService.Client.GameServerAddress;
_oldManagementAddress = _settingsService.Client.ManagementServerAddress;
_settingsService.Client.GameServerAddress = _settingsService.Client.ManagementServerAddress = "localhost";
new Task(() => LaunchServerAndClient(Launcher.JavaExecutableLocation, PrintLog)).Start();
}
private void LaunchServerAndClient (string javaExecutableLocation, Action<string> log)
{
var serverJar = CrossPlatform.GetSingleplayerHome() + @"/game/server.jar";
if (IsPortInUse(43595))
{
log("Port 43595 is in use. Cannot start the server again.");
return;
}
_serverProcess = CrossPlatform.StartJavaProcess(javaExecutableLocation, serverJar, "2G", log, null);
while (!IsPortInUse(43595)) Thread.Sleep(1000);
Message.Broadcast<ClientLaunchRequestedMessage>();
}
private static bool IsPortInUse(int port)
{
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpListeners();
return tcpConnInfoArray.Any(endpoint => endpoint.Port == port);
}
private void LaunchFaq()
{
CrossPlatform.LaunchURL("https://2009scape.org/site/game_guide/singleplayer.html");
}
private void LaunchForums()
{
CrossPlatform.LaunchURL("https://forum.2009scape.org/viewforum.php?f=8-support");
}
public bool Cheats
{
get => ParseConf<bool>("noauth_default_admin");
set => WriteConf("noauth_default_admin", value);
}
public bool FakePlayers
{
get => ParseConf<bool>("enable_bots", true);
set => WriteConf("enable_bots", value);
}
public bool GEAutoBuySell
{
get => ParseConf<bool>("i_want_to_cheat");
set => WriteConf("i_want_to_cheat", value);
}
public bool Debug
{
get => ParseConf<bool>("debug");
set => WriteConf("debug", value);
}
public async void ResetToDefaults()
{
using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(5);
MakeBackup();
PrintLog("Grabbing the default config from the latest singleplayer codebase..");
try
private static bool IsPortInUse(int port)
{
string defaultConf = await httpClient.GetStringAsync("https://gitlab.com/2009scape/singleplayer/windows/-/raw/master/game/worldprops/default.conf");
await File.WriteAllTextAsync(CrossPlatform.GetSingleplayerHome() + "/game/worldprops/default.conf",
defaultConf);
}
catch (Exception ex)
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpListeners();
return tcpConnInfoArray.Any(endpoint => endpoint.Port == port);
}
private void LaunchFaq()
{
PrintLog($"Couldn't reset game properties");
PrintLog(ex.Message);
return;
CrossPlatform.LaunchURL("https://2009scape.org/site/game_guide/singleplayer.html");
}
private void LaunchForums()
{
CrossPlatform.LaunchURL("https://forum.2009scape.org/viewforum.php?f=8-support");
}
public bool Cheats
{
get => ParseConf<bool>("noauth_default_admin");
set => WriteConf("noauth_default_admin", value);
}
public bool FakePlayers
{
get => ParseConf<bool>("enable_bots", true);
set => WriteConf("enable_bots", value);
}
public bool GEAutoBuySell
{
get => ParseConf<bool>("i_want_to_cheat");
set => WriteConf("i_want_to_cheat", value);
}
public bool Debug
{
get => ParseConf<bool>("debug");
set => WriteConf("debug", value);
}
public async void ResetToDefaults()
{
using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(5);
MakeBackup();
PrintLog("Grabbing the default config from the latest singleplayer codebase..");
try
{
string defaultConf = await httpClient.GetStringAsync("https://gitlab.com/2009scape/singleplayer/windows/-/raw/master/game/worldprops/default.conf");
await File.WriteAllTextAsync(CrossPlatform.GetSingleplayerHome() + "/game/worldprops/default.conf",
defaultConf);
}
catch (Exception ex)
{
PrintLog($"Couldn't reset game properties");
PrintLog(ex.Message);
return;
}
Cheats = GEAutoBuySell = Debug = false; // Force update UI
FakePlayers = true;
PrintLog("Saved new config.");
PrintLog("");
}
Cheats = GEAutoBuySell = Debug = false; // Force update UI
FakePlayers = true;
PrintLog("Saved new config.");
PrintLog("");
}
}