mirror of
https://gitlab.com/2009scape/Saradomin-Launcher.git
synced 2026-08-01 14:19:14 -06:00
Add connection settings, fix crash on missing path during settings load.
This commit is contained in:
parent
e72bd51ae3
commit
67a3530b11
9 changed files with 244 additions and 24 deletions
|
|
@ -19,6 +19,7 @@
|
|||
<StyleInclude Source="avares://Saradomin/Resources/Styles/Hyperlink.axaml" />
|
||||
<StyleInclude Source="avares://Saradomin/Resources/Styles/ToolTip.axaml" />
|
||||
<StyleInclude Source="avares://Saradomin/Resources/Styles/AntiAliasingRadioButton.axaml" />
|
||||
<StyleInclude Source="avares://Saradomin/Resources/Styles/RadioButton.axaml" />
|
||||
|
||||
<StyleInclude Source="avares://Glitonea/Glitonea.axaml" />
|
||||
</Application.Styles>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,14 @@ namespace Saradomin.Model.Settings.Client
|
|||
{
|
||||
public const string FileName = "config.json";
|
||||
|
||||
public const string LiveServerAddress = "play.2009scape.org";
|
||||
public const string TestServerAddress = "test.2009scape.org";
|
||||
|
||||
[JsonPropertyName("ip_management")]
|
||||
public string IpManagement { get; set; } = "play.2009scape.org";
|
||||
public string IpManagement { get; set; } = LiveServerAddress;
|
||||
|
||||
[JsonPropertyName("ip_address")]
|
||||
public string ServerAddress { get; set; } = "play.2009scape.org";
|
||||
public string ServerAddress { get; set; } = LiveServerAddress;
|
||||
|
||||
[JsonPropertyName("world")]
|
||||
public ushort World { get; set; } = 1;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
Content="{TemplateBinding Content}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
TextBlock.Foreground="{TemplateBinding Foreground}" />
|
||||
TextBlock.Foreground="{TemplateBinding Foreground}"
|
||||
TextBlock.FontSize="13" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
|
@ -46,7 +47,8 @@
|
|||
Content="{TemplateBinding Content}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
TextBlock.Foreground="{TemplateBinding Foreground}" />
|
||||
TextBlock.Foreground="{TemplateBinding Foreground}"
|
||||
TextBlock.FontSize="13" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
|
|
|||
70
Saradomin/Resources/Styles/RadioButton.axaml
Normal file
70
Saradomin/Resources/Styles/RadioButton.axaml
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<Styles xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Style Selector="RadioButton.NormalRadioButton">
|
||||
<Setter Property="Foreground" Value="#3E3529" />
|
||||
<Setter Property="Background" Value="#998468" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Grid ColumnDefinitions="Auto,Auto"
|
||||
Background="{TemplateBinding Background}">
|
||||
<Canvas Grid.Column="0"
|
||||
Width="24"
|
||||
Height="24">
|
||||
<Path Fill="{TemplateBinding Foreground}"
|
||||
Data="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" />
|
||||
</Canvas>
|
||||
|
||||
<ContentPresenter Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Content="{TemplateBinding Content}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
TextBlock.FontSize="13"
|
||||
TextBlock.Foreground="{TemplateBinding Foreground}" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style Selector="RadioButton.NormalRadioButton:checked">
|
||||
<Setter Property="Foreground" Value="#3E3529" />
|
||||
<Setter Property="Background" Value="#998468" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Grid ColumnDefinitions="Auto,Auto"
|
||||
Background="{TemplateBinding Background}">
|
||||
<Canvas Grid.Column="0"
|
||||
Width="24"
|
||||
Height="24">
|
||||
<Path Fill="{TemplateBinding Foreground}"
|
||||
Data="M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,7A5,5 0 0,0 7,12A5,5 0 0,0 12,17A5,5 0 0,0 17,12A5,5 0 0,0 12,7Z" />
|
||||
</Canvas>
|
||||
|
||||
<ContentPresenter Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
Content="{TemplateBinding Content}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
TextBlock.FontSize="13"
|
||||
TextBlock.Foreground="{TemplateBinding Foreground}" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style Selector="RadioButton.NormalRadioButton:pointerover">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="RadioButton.NormalRadioButton:checked:pointerover">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="RadioButton.NormalRadioButton:pressed">
|
||||
<Setter Property="Foreground" Value="#F2C954" />
|
||||
</Style>
|
||||
</Styles>
|
||||
|
|
@ -4,9 +4,13 @@
|
|||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove=".gitignore" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<TargetPlatform>x64</TargetPlatform>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="0.10.14" />
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ namespace Saradomin.Services
|
|||
|
||||
private void TryReadConfigurationData()
|
||||
{
|
||||
if (!Directory.Exists(CrossPlatform.Locate2009scapeHome()))
|
||||
Directory.CreateDirectory(CrossPlatform.Locate2009scapeHome());
|
||||
|
||||
if (File.Exists(LauncherSettingsPath))
|
||||
{
|
||||
using (var stream = File.OpenRead(LauncherSettingsPath))
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@
|
|||
<TextBlock Grid.Row="0"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="#3E3529"
|
||||
Text="Anti-aliasing quality"
|
||||
Margin="0,0,0,2"/>
|
||||
Text="Anti-aliasing quality"
|
||||
Margin="0,0,0,2" />
|
||||
|
||||
<controls:AntiAliasingSelector Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,4"
|
||||
AntiAliasingLevel="{Binding Client.Customization.AntiAliasingSampleCount, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
|
|
@ -264,17 +264,120 @@
|
|||
|
||||
<HeaderedContentControl Classes="GroupBox"
|
||||
Header="launcher settings"
|
||||
DockPanel.Dock="Left"
|
||||
HorizontalAlignment="Stretch">
|
||||
DockPanel.Dock="Top">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<CheckBox Content="Place 'X' button on the left"
|
||||
IsChecked="{Binding Launcher.PlaceCloseButtonOnLeft, Mode=TwoWay}" />
|
||||
|
||||
<CheckBox Content="Close the launcher after executing the client"
|
||||
IsChecked="{Binding Launcher.ExitAfterLaunchingClient, Mode=TwoWay}"/>
|
||||
|
||||
<CheckBox Content="Check for updates before launching the client"
|
||||
IsChecked="{Binding Launcher.CheckForClientUpdatesOnLaunch, Mode=TwoWay}"/>
|
||||
<CheckBox Content="Close the launcher after executing the client"
|
||||
IsChecked="{Binding Launcher.ExitAfterLaunchingClient, Mode=TwoWay}" />
|
||||
|
||||
<CheckBox Margin="0,0,0,4"
|
||||
Content="Check for updates before launching the client"
|
||||
IsChecked="{Binding Launcher.CheckForClientUpdatesOnLaunch, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
</HeaderedContentControl>
|
||||
|
||||
<HeaderedContentControl Classes="GroupBox"
|
||||
Header="connection settings"
|
||||
DockPanel.Dock="Left"
|
||||
HorizontalAlignment="Stretch">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto">
|
||||
<TextBlock Grid.Row="0"
|
||||
Margin="2,0,0,2"
|
||||
Text="Server profile"
|
||||
Foreground="#3E3529" />
|
||||
|
||||
<Grid Grid.Row="1"
|
||||
ColumnDefinitions="*,*,*">
|
||||
<RadioButton Grid.Column="0"
|
||||
Classes="NormalRadioButton"
|
||||
Content="Live"
|
||||
Command="{Binding UpdateServerProfile}"
|
||||
CommandParameter="live"
|
||||
IsChecked="{Binding IsLiveServerSelected}" />
|
||||
|
||||
<RadioButton Grid.Column="1"
|
||||
Classes="NormalRadioButton"
|
||||
Content="Testing"
|
||||
Command="{Binding UpdateServerProfile}"
|
||||
CommandParameter="testing"
|
||||
IsChecked="{Binding IsTestingServerSelected}" />
|
||||
|
||||
<RadioButton Grid.Column="2"
|
||||
Name="CustomServerProfileRadioButton"
|
||||
Classes="NormalRadioButton"
|
||||
Content="User-defined" />
|
||||
</Grid>
|
||||
|
||||
<TextBox Grid.Row="2"
|
||||
Margin="0,2,0,0"
|
||||
Classes="NormalTextBox"
|
||||
HorizontalAlignment="Stretch"
|
||||
Text="{Binding ServerAddress, Mode=TwoWay}"
|
||||
Watermark="Enter a server address..."
|
||||
IsFocused="{Binding IsServerAddressBeingEdited, Mode=OneWayToSource}"
|
||||
IsEnabled="{Binding #CustomServerProfileRadioButton.IsChecked}"
|
||||
IsReadOnly="{Binding !#CustomServerProfileRadioButton.IsChecked}" />
|
||||
|
||||
<Grid Grid.Row="3"
|
||||
Grid.ColumnDefinitions="*,*,*"
|
||||
Grid.RowDefinitions="Auto,Auto,Auto"
|
||||
Margin="0,4,0,0">
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="2,0,0,2"
|
||||
Text="Base port"
|
||||
Foreground="#3E3529" />
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="2,0,0,2"
|
||||
Text="World list port"
|
||||
Foreground="#3E3529" />
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Margin="2,0,0,2"
|
||||
Text="Cache server port"
|
||||
Foreground="#3E3529" />
|
||||
|
||||
<NumericUpDown Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Classes="NormalNumericUpDown"
|
||||
Margin="0,0,4,0"
|
||||
Width="NaN"
|
||||
Value="{Binding Client.GameServerPort}"
|
||||
Minimum="0"
|
||||
Maximum="65535" />
|
||||
|
||||
<NumericUpDown Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,4,0"
|
||||
Width="NaN"
|
||||
Classes="NormalNumericUpDown"
|
||||
Value="{Binding Client.WorldListServerPort}"
|
||||
Minimum="0"
|
||||
Maximum="65535" />
|
||||
|
||||
<NumericUpDown Grid.Row="1"
|
||||
Grid.Column="2"
|
||||
Width="NaN"
|
||||
Classes="NormalNumericUpDown"
|
||||
Value="{Binding Client.CacheServerPort}"
|
||||
Minimum="0"
|
||||
Maximum="65535" />
|
||||
|
||||
<Button Grid.Row="2"
|
||||
Grid.ColumnSpan="3"
|
||||
Classes="Hyperlink"
|
||||
Margin="0,4,0,0"
|
||||
Content="reset"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{Binding ResetServerConfiguration}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</HeaderedContentControl>
|
||||
</DockPanel>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using Avalonia.Collections;
|
||||
using Glitonea.Extensions;
|
||||
using Glitonea.Mvvm;
|
||||
using Glitonea.Utilities;
|
||||
using JetBrains.Annotations;
|
||||
using Saradomin.Messaging;
|
||||
using Saradomin.Model.Settings.Client;
|
||||
using Saradomin.Model.Settings.Launcher;
|
||||
|
|
@ -34,6 +32,23 @@ namespace Saradomin.ViewModel.Controls
|
|||
OnPropertyChanged(nameof(LoginMusicTheme));
|
||||
}
|
||||
}
|
||||
|
||||
public string ServerAddress
|
||||
{
|
||||
get => Client.ServerAddress;
|
||||
set
|
||||
{
|
||||
Client.ServerAddress = value;
|
||||
Client.IpManagement = value;
|
||||
|
||||
OnPropertyChanged(nameof(ServerAddress));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsServerAddressBeingEdited { get; set; }
|
||||
|
||||
public bool IsLiveServerSelected => !IsServerAddressBeingEdited && ServerAddress == ClientSettings.LiveServerAddress;
|
||||
public bool IsTestingServerSelected => !IsServerAddressBeingEdited && ServerAddress == ClientSettings.TestServerAddress;
|
||||
|
||||
public ObservableCollection<string> MusicTitles { get; private set; }
|
||||
|
||||
|
|
@ -86,5 +101,24 @@ namespace Saradomin.ViewModel.Controls
|
|||
{
|
||||
Client.Customization.RightClickMenu.SetDefaults();
|
||||
}
|
||||
|
||||
private void ResetServerConfiguration()
|
||||
{
|
||||
Client.GameServerPort = 43594;
|
||||
Client.CacheServerPort = 43595;
|
||||
Client.WorldListServerPort = 5555;
|
||||
|
||||
ServerAddress = ClientSettings.LiveServerAddress;
|
||||
}
|
||||
|
||||
private void UpdateServerProfile(string param)
|
||||
{
|
||||
ServerAddress = param switch
|
||||
{
|
||||
"live" => ClientSettings.LiveServerAddress,
|
||||
"testing" => ClientSettings.TestServerAddress,
|
||||
_ => throw new NotSupportedException($"{param} is not a supported parameter.")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,8 @@ namespace Saradomin.ViewModel.Windows
|
|||
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
var response = await httpClient.GetAsync("https://2009scape.org/services/m=news/archives/latest.html");
|
||||
var response =
|
||||
await httpClient.GetAsync("https://2009scape.org/services/m=news/archives/latest.html");
|
||||
var doc = new HtmlDocument();
|
||||
doc.Load(await response.Content.ReadAsStreamAsync());
|
||||
var node = doc.DocumentNode.SelectSingleNode("//div[@class='msgcontents']");
|
||||
|
|
@ -88,7 +89,6 @@ namespace Saradomin.ViewModel.Windows
|
|||
CanLaunch = true;
|
||||
LaunchText = $"Failed to update 2009scape: {e.Message}";
|
||||
return;
|
||||
// todo messagebox
|
||||
}
|
||||
|
||||
LaunchText = "Play! (already running)";
|
||||
|
|
@ -140,7 +140,7 @@ namespace Saradomin.ViewModel.Windows
|
|||
|
||||
if (!File.Exists(clientPath))
|
||||
{
|
||||
LaunchText = "Cannot launch. Missing client file.";
|
||||
LaunchText = "Cannot launch. Missing client executable. Click me again to re-try.";
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ namespace Saradomin.ViewModel.Windows
|
|||
|
||||
private void OnClientDownloadProgressUpdated(object sender, float e)
|
||||
{
|
||||
LaunchText = $"Updating... (Downloading client: {e * 100}%)";
|
||||
LaunchText = $"Updating... (Downloading client: {e * 100:F2}%)";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue