mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-03 18:24:38 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 381c815528 | |||
| 6d81ec700d | |||
| 705f2049fd | |||
| 9583117eea | |||
| dc1f43d385 | |||
| cb9c8cbb08 | |||
| a87c1ebc4c | |||
| 1aac7faae1 | |||
| 121481af00 | |||
| 92ed2c39f0 | |||
| e1800a20b9 | |||
| 5004a2889a |
@@ -0,0 +1,155 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.VisualTree;
|
||||
using StarterNG.Controls;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
/// <summary>Windows under gamescope, which gives them no title bar, no close button and no maximizing.</summary>
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class GamescopeWindowsTests
|
||||
{
|
||||
static GamescopeWindowsTests()
|
||||
{
|
||||
HeadlessDrawing.Ensure();
|
||||
DialogKeyboard.Install();
|
||||
GamescopeWindows.Install(false, () => "Zamknij");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("gamescope", null, true)]
|
||||
[InlineData("Gamescope", null, true)]
|
||||
[InlineData("KDE", "gamescope-0", true)]
|
||||
[InlineData(null, "gamescope-0", true)]
|
||||
[InlineData("KDE", null, false)]
|
||||
[InlineData("KDE", "", false)]
|
||||
[InlineData(null, null, false)]
|
||||
public void Gamescope_is_told_by_its_session_or_by_its_display(string? desktop, string? display, bool expected)
|
||||
{
|
||||
var variables = new Dictionary<string, string?>
|
||||
{
|
||||
["XDG_CURRENT_DESKTOP"] = desktop,
|
||||
["GAMESCOPE_WAYLAND_DISPLAY"] = display,
|
||||
// Big Picture on a desktop, whose window manager still draws the bars.
|
||||
["SteamGamepadUI"] = "1"
|
||||
};
|
||||
|
||||
Assert.Equal(expected, GamescopeWindows.IsGamescope(name => variables.GetValueOrDefault(name)));
|
||||
}
|
||||
|
||||
private static (Window Owner, Window Window) Open(Control content, bool gamescope, bool escapeCloses = true)
|
||||
{
|
||||
GamescopeWindows.Active = gamescope;
|
||||
var owner = new Window();
|
||||
owner.Show();
|
||||
var window = new Window { Title = "Taśmy", Width = 300, Height = 200, Content = content };
|
||||
DialogKeyboard.SetEscapeCloses(window, escapeCloses);
|
||||
window.Show(owner);
|
||||
// Headless a window says it opened before it is given its owner; it says so again once it has one.
|
||||
Assert.Same(owner, window.Owner);
|
||||
window.RaiseEvent(new RoutedEventArgs(Window.WindowOpenedEvent));
|
||||
Controls.Settle();
|
||||
return (owner, window);
|
||||
}
|
||||
|
||||
private static Button? CloseButton(Window window) =>
|
||||
window.GetVisualDescendants().OfType<Button>().FirstOrDefault(b => Equals(b.Content, "Zamknij"));
|
||||
|
||||
[Fact]
|
||||
public void Under_gamescope_a_window_over_another_gets_its_title_and_a_close_button()
|
||||
{
|
||||
var content = new TextBlock { Text = "zawartość" };
|
||||
var (owner, window) = Open(content, gamescope: true);
|
||||
try
|
||||
{
|
||||
bool closed = false;
|
||||
window.Closed += (_, _) => closed = true;
|
||||
|
||||
Assert.Contains(window.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Taśmy");
|
||||
Assert.Same(content, window.GetVisualDescendants().OfType<TextBlock>().First(t => t.Text == "zawartość"));
|
||||
var close = CloseButton(window);
|
||||
Assert.NotNull(close);
|
||||
|
||||
close.RaiseEvent(Controls.Click());
|
||||
Assert.True(closed);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GamescopeWindows.Active = false;
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Under_gamescope_esc_closes_even_a_window_that_stays_open_beside_the_starter()
|
||||
{
|
||||
var (owner, window) = Open(new TextBox(), gamescope: true, escapeCloses: false);
|
||||
try
|
||||
{
|
||||
bool closed = false;
|
||||
window.Closed += (_, _) => closed = true;
|
||||
|
||||
Assert.True(Controls.Press(window, Key.Escape));
|
||||
Assert.True(closed);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GamescopeWindows.Active = false;
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_window_shows_what_it_had_first_and_the_bar_after_it_in_tab_order()
|
||||
{
|
||||
var first = new Button { Content = "Pierwszy" };
|
||||
var (owner, window) = Open(new StackPanel { Children = { first } }, gamescope: true);
|
||||
try
|
||||
{
|
||||
var grid = Assert.IsType<Grid>(window.Content);
|
||||
Assert.IsType<StackPanel>(grid.Children[0]);
|
||||
Assert.True(first.IsFocused);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GamescopeWindows.Active = false;
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_window_that_says_twice_it_opened_gets_one_bar()
|
||||
{
|
||||
var (owner, window) = Open(new TextBlock { Text = "zawartość" }, gamescope: true);
|
||||
try
|
||||
{
|
||||
window.RaiseEvent(new RoutedEventArgs(Window.WindowOpenedEvent));
|
||||
Controls.Settle();
|
||||
|
||||
Assert.Single(window.GetVisualDescendants().OfType<Button>(), b => Equals(b.Content, "Zamknij"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
GamescopeWindows.Active = false;
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Elsewhere_a_window_keeps_what_it_shows_and_esc_keeps_its_choice()
|
||||
{
|
||||
var content = new TextBox();
|
||||
var (owner, window) = Open(content, gamescope: false, escapeCloses: false);
|
||||
try
|
||||
{
|
||||
Assert.Same(content, window.Content);
|
||||
Assert.Null(CloseButton(window));
|
||||
Assert.False(Controls.Press(window, Key.Escape));
|
||||
}
|
||||
finally
|
||||
{
|
||||
owner.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,83 @@ public class GraphicsCardsTests
|
||||
Assert.Equal(new[] { "AMD Radeon RX 6700 XT", "AMD Radeon 780M" }, cards.Select(card => card.Name));
|
||||
}
|
||||
|
||||
private static GraphicsCards WindowsReader(IReadOnlyList<DxgiAdapter>? dxgi, params GraphicsCard[] registry) =>
|
||||
new(new InMemoryFileSystem(), new FakeEnvironment().AsWindows(), new LinuxGpus(new InMemoryFileSystem(), new FakeEnvironment()),
|
||||
() => Array.Empty<string>(), () => dxgi, () => registry);
|
||||
|
||||
private static DxgiAdapter Adapter(string name, uint vendor, long memory, uint flags = 0) =>
|
||||
new(name, vendor, (ulong)memory, flags);
|
||||
|
||||
[Fact]
|
||||
public void Windows_takes_the_cards_dxgi_lists_and_the_discrete_one_first()
|
||||
{
|
||||
var reader = WindowsReader(
|
||||
new[] { Adapter("AMD Radeon(TM) Graphics", 0x1002, GiB / 2), Adapter("NVIDIA GeForce RTX 3060", 0x10DE, 12 * GiB) },
|
||||
new GraphicsCard("AMD Radeon(TM) Graphics", GiB / 2));
|
||||
|
||||
var cards = reader.List();
|
||||
|
||||
Assert.Equal(new[] { "NVIDIA GeForce RTX 3060", "AMD Radeon(TM) Graphics" }, cards.Select(card => card.Name));
|
||||
Assert.Equal(12, cards[0].MemoryGb);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Software_adapters_are_no_cards()
|
||||
{
|
||||
var cards = DxgiAdapters.Cards(new[]
|
||||
{
|
||||
Adapter("Microsoft Basic Render Driver", 0x1414, 0, flags: 2),
|
||||
Adapter("Microsoft Remote Display Adapter", 0x1414, 0),
|
||||
Adapter("Some software rasterizer", 0x1234, 0, flags: 2),
|
||||
Adapter("NVIDIA GeForce RTX 5060 Laptop GPU", 0x10DE, 8546942976)
|
||||
});
|
||||
|
||||
Assert.Equal("NVIDIA GeForce RTX 5060 Laptop GPU", Assert.Single(cards).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_card_dxgi_lists_twice_is_shown_once()
|
||||
{
|
||||
var cards = DxgiAdapters.Cards(new[]
|
||||
{
|
||||
Adapter("AMD Radeon 780M Graphics", 0x1002, GiB / 2),
|
||||
Adapter("AMD Radeon 780M Graphics ", 0x1002, GiB / 2)
|
||||
});
|
||||
|
||||
Assert.Equal("AMD Radeon 780M Graphics", Assert.Single(cards).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_registry_answers_when_dxgi_cannot_be_asked()
|
||||
{
|
||||
var card = Assert.Single(WindowsReader(null, new GraphicsCard("NVIDIA GeForce RTX 3060", 12 * GiB)).List());
|
||||
|
||||
Assert.Equal("NVIDIA GeForce RTX 3060", card.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_registry_answers_when_dxgi_lists_only_software()
|
||||
{
|
||||
var reader = WindowsReader(new[] { Adapter("Microsoft Basic Render Driver", 0x1414, 0, flags: 2) },
|
||||
new GraphicsCard("AMD Radeon(TM) Graphics", GiB / 2));
|
||||
|
||||
Assert.Equal("AMD Radeon(TM) Graphics", Assert.Single(reader.List()).Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dxgi_answers_on_this_machine()
|
||||
{
|
||||
if (!OperatingSystem.IsWindows())
|
||||
return;
|
||||
|
||||
// Every Windows lists at least the Basic Render Driver, so an answer means the calls work.
|
||||
var adapters = DxgiAdapters.Read();
|
||||
|
||||
Assert.NotNull(adapters);
|
||||
Assert.NotEmpty(adapters);
|
||||
Assert.All(adapters, adapter => Assert.False(string.IsNullOrWhiteSpace(adapter.Description)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void There_are_no_cards_on_a_mac()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using Avalonia.Controls;
|
||||
using StarterNG.Controls;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
[Collection(AvaloniaControls.Name)]
|
||||
public class PrecipitationItemTests
|
||||
{
|
||||
// Shown in whatever language the tests run in: the key alone, or English once a test built the application.
|
||||
private static void ShowsText(string key, PrecipitationItem item)
|
||||
{
|
||||
Assert.Equal(key, item.Key);
|
||||
Assert.Equal(AppLanguage.Text(key), item.Content);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Light_precipitation_is_light_rain_until_told_it_snows()
|
||||
{
|
||||
var item = new PrecipitationItem();
|
||||
|
||||
ShowsText("OvercastRainLight", item);
|
||||
|
||||
item.Snow = true;
|
||||
|
||||
ShowsText("OvercastSnowLight", item);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Heavy_precipitation_is_rain_or_snow()
|
||||
{
|
||||
var item = new PrecipitationItem { Heavy = true };
|
||||
|
||||
ShowsText("OvercastRain", item);
|
||||
|
||||
item.Snow = true;
|
||||
|
||||
ShowsText("OvercastSnow", item);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_option_keeps_its_name_in_a_dropdown_and_out_of_it()
|
||||
{
|
||||
var item = new PrecipitationItem { Heavy = true, Snow = true };
|
||||
var combo = new ComboBox { Items = { item } };
|
||||
|
||||
ShowsText("OvercastSnow", item);
|
||||
|
||||
combo.Items.Remove(item);
|
||||
item.Snow = false;
|
||||
|
||||
ShowsText("OvercastRain", item);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void In_a_window_the_option_looks_like_any_other_and_still_follows_the_temperature()
|
||||
{
|
||||
var item = new PrecipitationItem { Heavy = true };
|
||||
var combo = new ComboBox { Items = { new ComboBoxItem { Content = "Bezchmurnie" }, item } };
|
||||
var window = Controls.Show(combo, themed: true);
|
||||
|
||||
combo.IsDropDownOpen = true;
|
||||
window.UpdateLayout();
|
||||
|
||||
Assert.NotNull(item.Template);
|
||||
item.Snow = true;
|
||||
ShowsText("OvercastSnow", item);
|
||||
|
||||
window.Close();
|
||||
item.Snow = false;
|
||||
ShowsText("OvercastRain", item);
|
||||
}
|
||||
}
|
||||
@@ -78,10 +78,36 @@ public class SceneryWeatherTests
|
||||
{
|
||||
var weather = new SceneryWeather { Overcast = 0.42, OvercastRandom = true };
|
||||
|
||||
Assert.Equal(-1.5, weather.EffectiveOvercast(new StubRandom()));
|
||||
Assert.Equal(0, weather.EffectiveOvercast(new StubRandom()));
|
||||
Assert.Equal(0.42, new SceneryWeather { Overcast = 0.42 }.EffectiveOvercast(new StubRandom()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_random_overcast_preset_is_one_the_simulator_would_draw_again()
|
||||
{
|
||||
var weather = new SceneryWeather { OvercastRandom = true };
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
Assert.InRange(weather.EffectiveOvercast(new StubRandom(i)), 0, 2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_negative_overcast_in_the_scenery_is_read_as_random()
|
||||
{
|
||||
var weather = TestScenery.Parser(new DateTime(2026, 1, 1))
|
||||
.Parse("scenery/x.scn", "atmo 0 0 0 50 900 0 0 0 -1.5 endatmo").Weather;
|
||||
|
||||
Assert.True(weather.OvercastRandom);
|
||||
Assert.False(weather.Changed);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(2, false)]
|
||||
[InlineData(1, true)]
|
||||
[InlineData(-10, true)]
|
||||
public void Precipitation_is_snow_at_or_below_one_degree(double temperature, bool snow) =>
|
||||
Assert.Equal(snow, SceneryWeather.Snows(temperature));
|
||||
|
||||
private static string Rewritten(string scn) =>
|
||||
SceneryWeatherWriter.Rewrite(scn, new SceneryWeather(), new StubRandom());
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SoftwareRenderTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_the_switch_the_graphics_card_draws()
|
||||
public void Without_the_switch_it_is_not_asked_for()
|
||||
{
|
||||
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
|
||||
Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
|
||||
@@ -25,21 +25,25 @@ public class SoftwareRenderTests
|
||||
{
|
||||
var options = SoftwareRender.Win32Options;
|
||||
|
||||
// No WinUI composition, DirectComposition or swap chain of the graphics card's.
|
||||
Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode);
|
||||
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void X11_draws_on_the_processor()
|
||||
public void X11_draws_on_the_processor_when_asked()
|
||||
{
|
||||
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Both_platforms_options_go_to_the_same_builder()
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void The_options_go_to_the_same_builder_with_or_without_the_switch(bool asked)
|
||||
{
|
||||
var builder = AppBuilder.Configure<Avalonia.Application>();
|
||||
string[] args = asked ? new[] { SoftwareRender.Switch } : Array.Empty<string>();
|
||||
|
||||
Assert.Same(builder, SoftwareRender.ApplyTo(builder));
|
||||
Assert.Same(builder, SoftwareRender.ApplyTo(builder, args));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,20 @@ public class TrainsetDisplayTests
|
||||
Assert.True(TrainsetDisplay.StartableIn(decor, Mode(advanced: true)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_standard_mode_changes_the_crew_but_not_in_the_simulators_own_consists()
|
||||
{
|
||||
var standard = Mode(advanced: false);
|
||||
var decor = new Trainset("trainset a tor 0 0 //$decor\nnode -1 0 v1 dynamic d s m 0 headdriver 3 0 enddynamic\nendtrainset");
|
||||
|
||||
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(), standard));
|
||||
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(driver: "nobody"), standard));
|
||||
Assert.True(TrainsetDisplay.CrewEditableIn(null, standard));
|
||||
Assert.False(TrainsetDisplay.CrewEditableIn(Consist(description: "-ai"), standard));
|
||||
Assert.False(TrainsetDisplay.CrewEditableIn(decor, standard));
|
||||
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(description: "-ai"), Mode(advanced: true)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_filters_work_in_the_advanced_mode()
|
||||
{
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using Avalonia;
|
||||
using StarterNG.Infrastructure;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class WindowSurfacesTests
|
||||
{
|
||||
[Fact]
|
||||
public void Windows_draws_into_a_directcomposition_surface_and_never_through_winui_composition()
|
||||
{
|
||||
var options = WindowSurfaces.Win32Options;
|
||||
|
||||
Assert.Equal(Win32CompositionMode.DirectComposition, options.CompositionMode.First());
|
||||
Assert.DoesNotContain(Win32CompositionMode.WinUIComposition, options.CompositionMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_window_surface_is_only_the_fallback()
|
||||
{
|
||||
// There ANGLE presents through a swap chain, and the Steam overlay draws over it.
|
||||
Assert.Equal(Win32CompositionMode.RedirectionSurface, WindowSurfaces.Win32Options.CompositionMode.Last());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_swap_chain_of_its_own_is_asked_for()
|
||||
{
|
||||
Assert.DoesNotContain(Win32CompositionMode.LowLatencyDxgiSwapChain, WindowSurfaces.Win32Options.CompositionMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_graphics_card_still_draws()
|
||||
{
|
||||
Assert.Equal(new Win32PlatformOptions().RenderingMode, WindowSurfaces.Win32Options.RenderingMode);
|
||||
Assert.Contains(Win32RenderingMode.AngleEgl, WindowSurfaces.Win32Options.RenderingMode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void The_options_go_to_the_same_builder_with_or_without_the_processor(bool softwareRender)
|
||||
{
|
||||
var builder = AppBuilder.Configure<Avalonia.Application>();
|
||||
|
||||
Assert.Same(builder, WindowSurfaces.ApplyTo(builder, softwareRender));
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ public partial class App : Avalonia.Application
|
||||
// Before any control exists: the names are given as controls are filled in.
|
||||
ScreenReaderNames.Install();
|
||||
DialogKeyboard.Install();
|
||||
GamescopeWindows.Install(GamescopeWindows.IsGamescope(AppServices.Current.Environment.GetVariable),
|
||||
() => Loc["Close"]);
|
||||
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ public static class DialogKeyboard
|
||||
// button or a window of its own that handles the key keep it.
|
||||
private static void OnEscape(Window window, KeyEventArgs e)
|
||||
{
|
||||
if (e.Handled || e.Key != Key.Escape || e.KeyModifiers != KeyModifiers.None || !GetEscapeCloses(window))
|
||||
// Under gamescope a window has no other way out than Esc and the bar it is given there.
|
||||
if (e.Handled || e.Key != Key.Escape || e.KeyModifiers != KeyModifiers.None ||
|
||||
!(GetEscapeCloses(window) || GamescopeWindows.Active))
|
||||
return;
|
||||
|
||||
window.Close();
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace StarterNG.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// The starter's windows under gamescope, SteamOS's game mode (or gamescope started by
|
||||
/// hand): it shows one window at a time over the whole screen and is no window manager.
|
||||
/// No window gets a title bar or a close button from it, and a request to maximize is
|
||||
/// not answered, so gamescope stretches a window of its first size over the screen.
|
||||
/// Here each window over another gets a bar with its title and a close button, Esc closes
|
||||
/// it whatever it says otherwise, and every window takes the size of the screen itself.
|
||||
/// </summary>
|
||||
public static class GamescopeWindows
|
||||
{
|
||||
private static readonly AttachedProperty<bool> FittedProperty =
|
||||
AvaloniaProperty.RegisterAttached<Window, bool>("GamescopeFitted", typeof(GamescopeWindows));
|
||||
|
||||
private static readonly IBrush BarLine = new SolidColorBrush(Color.FromArgb(0x40, 0x80, 0x80, 0x80));
|
||||
|
||||
private static Func<string> _closeLabel = () => "Close";
|
||||
private static bool _installed;
|
||||
|
||||
/// <summary>
|
||||
/// XDG_CURRENT_DESKTOP is gamescope in SteamOS's game mode and in the sessions made
|
||||
/// after it; GAMESCOPE_WAYLAND_DISPLAY is set by any gamescope for what it starts,
|
||||
/// one started by hand on a desktop too. Steam's Big Picture on a desktop is neither:
|
||||
/// its window manager still draws the bars.
|
||||
/// </summary>
|
||||
public static bool IsGamescope(Func<string, string?> variable) =>
|
||||
string.Equals(variable("XDG_CURRENT_DESKTOP"), "gamescope", StringComparison.OrdinalIgnoreCase)
|
||||
|| !string.IsNullOrEmpty(variable("GAMESCOPE_WAYLAND_DISPLAY"));
|
||||
|
||||
/// <summary>Whether the starter runs under gamescope; set once by <see cref="Install"/>.</summary>
|
||||
public static bool Active { get; set; }
|
||||
|
||||
public static void Install(bool active, Func<string> closeLabel)
|
||||
{
|
||||
Active = active;
|
||||
_closeLabel = closeLabel;
|
||||
if (_installed)
|
||||
return;
|
||||
|
||||
_installed = true;
|
||||
Window.WindowOpenedEvent.AddClassHandler<Window>((window, _) => OnOpened(window));
|
||||
}
|
||||
|
||||
private static void OnOpened(Window window)
|
||||
{
|
||||
// The main window has a bar of its own and fills the screen from its constructor;
|
||||
// the splash goes by itself. A window may say twice that it opened.
|
||||
if (!Active || window.Owner is null || window.GetValue(FittedProperty))
|
||||
return;
|
||||
|
||||
window.SetValue(FittedProperty, true);
|
||||
AddTitleBar(window);
|
||||
FillScreen(window);
|
||||
}
|
||||
|
||||
/// <summary>The window's title and a close button above what it shows, after it in Tab order.</summary>
|
||||
public static void AddTitleBar(Window window)
|
||||
{
|
||||
if (window.Content is not Control content)
|
||||
return;
|
||||
|
||||
// Over the whole screen a window sized to what it shows keeps it in the middle.
|
||||
if (window.SizeToContent != SizeToContent.Manual)
|
||||
{
|
||||
content.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
content.VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
|
||||
var title = new TextBlock
|
||||
{
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Margin = new Thickness(12, 0),
|
||||
FontWeight = FontWeight.SemiBold,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis
|
||||
};
|
||||
title[!TextBlock.TextProperty] = window[!Window.TitleProperty];
|
||||
|
||||
var close = new Button
|
||||
{
|
||||
Content = _closeLabel(),
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Margin = new Thickness(8, 4)
|
||||
};
|
||||
close.Classes.Add("Flat");
|
||||
close.Click += (_, _) => window.Close();
|
||||
|
||||
var bar = new DockPanel
|
||||
{
|
||||
Background = Brushes.Transparent,
|
||||
Children = { close, title }
|
||||
};
|
||||
DockPanel.SetDock(close, Dock.Right);
|
||||
|
||||
var line = new Border
|
||||
{
|
||||
BorderBrush = BarLine,
|
||||
BorderThickness = new Thickness(0, 0, 0, 1),
|
||||
Child = bar
|
||||
};
|
||||
|
||||
window.Content = null;
|
||||
Grid.SetRow(content, 1);
|
||||
Grid.SetRow(line, 0);
|
||||
// What the window shows first, so Tab and the first focus reach it before the bar.
|
||||
window.Content = new Grid
|
||||
{
|
||||
RowDefinitions = new RowDefinitions("Auto,*"),
|
||||
Children = { content, line }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The size and place of the screen's working area, which gamescope then shows as it is.</summary>
|
||||
public static void FillScreen(Window window)
|
||||
{
|
||||
var screen = window.Screens.ScreenFromWindow(window)
|
||||
?? window.Screens.ScreenFromPoint(window.Position)
|
||||
?? window.Screens.Primary;
|
||||
if (screen is null)
|
||||
return;
|
||||
|
||||
var area = screen.WorkingArea;
|
||||
double width = area.Width / screen.Scaling;
|
||||
double height = area.Height / screen.Scaling;
|
||||
window.SizeToContent = SizeToContent.Manual;
|
||||
window.MinWidth = Math.Min(window.MinWidth, width);
|
||||
window.MinHeight = Math.Min(window.MinHeight, height);
|
||||
window.MaxWidth = Math.Max(window.MaxWidth, width);
|
||||
window.MaxHeight = Math.Max(window.MaxHeight, height);
|
||||
window.Position = area.Position;
|
||||
window.Width = width;
|
||||
window.Height = height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.LogicalTree;
|
||||
|
||||
namespace StarterNG.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// An overcast option above 1, where the simulator rains or, at 1 °C and below, snows:
|
||||
/// named for what falls, light or not, in the starter's language.
|
||||
/// </summary>
|
||||
public class PrecipitationItem : ComboBoxItem
|
||||
{
|
||||
public static readonly StyledProperty<bool> HeavyProperty =
|
||||
AvaloniaProperty.Register<PrecipitationItem, bool>(nameof(Heavy));
|
||||
|
||||
public static readonly StyledProperty<bool> SnowProperty =
|
||||
AvaloniaProperty.Register<PrecipitationItem, bool>(nameof(Snow));
|
||||
|
||||
public PrecipitationItem() => UpdateText();
|
||||
|
||||
/// <summary>Rain or snow rather than light rain or light snow.</summary>
|
||||
public bool Heavy
|
||||
{
|
||||
get => GetValue(HeavyProperty);
|
||||
set => SetValue(HeavyProperty, value);
|
||||
}
|
||||
|
||||
public bool Snow
|
||||
{
|
||||
get => GetValue(SnowProperty);
|
||||
set => SetValue(SnowProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(ComboBoxItem);
|
||||
|
||||
/// <summary>The key of the text the option is named by.</summary>
|
||||
public string Key => (Snow ? "OvercastSnow" : "OvercastRain") + (Heavy ? "" : "Light");
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
if (change.Property == HeavyProperty || change.Property == SnowProperty)
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
AppLanguage.Changed += UpdateText;
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
AppLanguage.Changed -= UpdateText;
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
}
|
||||
|
||||
private void UpdateText() => Content = AppLanguage.Text(Key);
|
||||
}
|
||||
@@ -8,7 +8,14 @@ public sealed class SceneryWeather
|
||||
public const int FogMin = 10;
|
||||
public const int FogMax = 10000;
|
||||
|
||||
private static readonly double[] OvercastPresets = { -1.5, 0, 0.3, 0.7, 1, 1.1, 1.5 };
|
||||
/// <summary>
|
||||
/// What the simulator makes of each: up to 0.1 clear, 0.5 scattered, 0.9 broken,
|
||||
/// 1 overcast; above 1 it rains or snows, the denser from 1.35 on.
|
||||
/// </summary>
|
||||
private static readonly double[] OvercastPresets = { 0, 0.3, 0.7, 1, 1.1, 1.5 };
|
||||
|
||||
/// <summary>The simulator rains above 1 °C and snows at that or below.</summary>
|
||||
public static bool Snows(double temperature) => temperature <= 1;
|
||||
|
||||
private string _authoredTime = "10:30";
|
||||
private string _authoredTimeOverride = "10:30";
|
||||
|
||||
@@ -52,6 +52,14 @@ public static class TrainsetDisplay
|
||||
public static bool StartableIn(Trainset trainset, SimulatorSettings settings) =>
|
||||
settings.AdvancedSettings || (!IsAi(trainset) && !trainset.Decor);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the crew of the consist being edited may be changed: in the standard mode
|
||||
/// only in one the player may start in - the simulator's own consists and the
|
||||
/// decorations keep the crew the scenario gave them.
|
||||
/// </summary>
|
||||
public static bool CrewEditableIn(Trainset? trainset, SimulatorSettings settings) =>
|
||||
trainset is null || StartableIn(trainset, settings);
|
||||
|
||||
/// <summary>The consist's row in those lists: what it is made of, or the track of one with nothing on it.</summary>
|
||||
public static string ListLabel(Trainset trainset) =>
|
||||
CompositionText(trainset) ?? string.Format(App.Loc["EmptyTrainset"], trainset.Track ?? "");
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>An adapter as DXGI describes it (DXGI_ADAPTER_DESC1).</summary>
|
||||
/// <param name="DedicatedVideoMemory">The card's own memory; for a card in a processor, the share the firmware sets aside.</param>
|
||||
public sealed record DxgiAdapter(string Description, uint VendorId, ulong DedicatedVideoMemory, uint Flags);
|
||||
|
||||
/// <summary>
|
||||
/// The graphics cards of a Windows machine as DXGI lists them: the adapters Windows
|
||||
/// draws with, whose drivers the simulator's OpenGL runs on too. The registry's list of
|
||||
/// video devices is what each driver chose to write there, and some leave their card out of it.
|
||||
/// </summary>
|
||||
public static unsafe class DxgiAdapters
|
||||
{
|
||||
private const uint MicrosoftVendor = 0x1414;
|
||||
private const uint SoftwareFlag = 2; // DXGI_ADAPTER_FLAG_SOFTWARE
|
||||
private const int NotFound = unchecked((int)0x887A0002); // DXGI_ERROR_NOT_FOUND
|
||||
private const int MostAdapters = 64;
|
||||
|
||||
private static readonly Guid FactoryInterface = new("770aae78-f26f-4dba-a829-253c83d1b387"); // IDXGIFactory1
|
||||
|
||||
/// <summary>The cards among the adapters: not the Microsoft Basic Render Driver or any other software one.</summary>
|
||||
public static IReadOnlyList<GraphicsCard> Cards(IEnumerable<DxgiAdapter> adapters) =>
|
||||
adapters
|
||||
.Where(adapter => (adapter.Flags & SoftwareFlag) == 0 && adapter.VendorId != MicrosoftVendor)
|
||||
.Select(adapter => new GraphicsCard(adapter.Description.Trim(), (long)adapter.DedicatedVideoMemory))
|
||||
.Where(card => card.Name.Length > 0)
|
||||
// Two of the same card tell no more than one, as in the registry's list.
|
||||
.DistinctBy(card => card.Name)
|
||||
.ToList();
|
||||
|
||||
/// <summary>Every adapter DXGI lists, software ones too; null when DXGI could not be asked.</summary>
|
||||
[SupportedOSPlatform("windows")]
|
||||
public static IReadOnlyList<DxgiAdapter>? Read()
|
||||
{
|
||||
IntPtr factory;
|
||||
try
|
||||
{
|
||||
Guid iid = FactoryInterface;
|
||||
if (CreateDXGIFactory1(&iid, &factory) < 0 || factory == IntPtr.Zero)
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// IDXGIFactory1::EnumAdapters1, after IUnknown's 3, IDXGIObject's 4 and IDXGIFactory's 5.
|
||||
var enumAdapters1 = (delegate* unmanaged[Stdcall]<IntPtr, uint, IntPtr*, int>)Method(factory, 12);
|
||||
var adapters = new List<DxgiAdapter>();
|
||||
for (uint i = 0; i < MostAdapters; i++)
|
||||
{
|
||||
IntPtr adapter;
|
||||
int result = enumAdapters1(factory, i, &adapter);
|
||||
if (result == NotFound)
|
||||
break;
|
||||
if (result < 0 || adapter == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
// IDXGIAdapter1::GetDesc1, after IUnknown's 3, IDXGIObject's 4 and IDXGIAdapter's 3.
|
||||
var getDesc1 = (delegate* unmanaged[Stdcall]<IntPtr, AdapterDesc1*, int>)Method(adapter, 10);
|
||||
AdapterDesc1 desc;
|
||||
if (getDesc1(adapter, &desc) >= 0)
|
||||
adapters.Add(new DxgiAdapter(new string(desc.Description), desc.VendorId,
|
||||
desc.DedicatedVideoMemory, desc.Flags));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Release(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
return adapters;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Release(factory);
|
||||
}
|
||||
}
|
||||
|
||||
private static void* Method(IntPtr instance, int slot) => (*(void***)instance)[slot];
|
||||
|
||||
private static void Release(IntPtr instance) =>
|
||||
((delegate* unmanaged[Stdcall]<IntPtr, uint>)Method(instance, 2))(instance);
|
||||
|
||||
[DllImport("dxgi.dll", ExactSpelling = true)]
|
||||
private static extern int CreateDXGIFactory1(Guid* riid, IntPtr* factory);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private struct AdapterDesc1
|
||||
{
|
||||
public fixed char Description[128];
|
||||
public uint VendorId;
|
||||
public uint DeviceId;
|
||||
public uint SubSysId;
|
||||
public uint Revision;
|
||||
public nuint DedicatedVideoMemory;
|
||||
public nuint DedicatedSystemMemory;
|
||||
public nuint SharedSystemMemory;
|
||||
public uint AdapterLuidLow;
|
||||
public int AdapterLuidHigh;
|
||||
public uint Flags;
|
||||
}
|
||||
}
|
||||
@@ -30,14 +30,20 @@ public sealed class GraphicsCards
|
||||
private readonly IEnvironment _environment;
|
||||
private readonly LinuxGpus _gpus;
|
||||
private readonly Func<IReadOnlyList<string>> _nvidiaSmi;
|
||||
private readonly Func<IReadOnlyList<DxgiAdapter>?> _dxgi;
|
||||
private readonly Func<IReadOnlyList<GraphicsCard>> _registry;
|
||||
|
||||
public GraphicsCards(IFileSystem files, IEnvironment environment, LinuxGpus gpus,
|
||||
Func<IReadOnlyList<string>>? nvidiaSmi = null)
|
||||
Func<IReadOnlyList<string>>? nvidiaSmi = null,
|
||||
Func<IReadOnlyList<DxgiAdapter>?>? dxgi = null,
|
||||
Func<IReadOnlyList<GraphicsCard>>? registry = null)
|
||||
{
|
||||
_files = files;
|
||||
_environment = environment;
|
||||
_gpus = gpus;
|
||||
_nvidiaSmi = nvidiaSmi ?? AskNvidiaSmi;
|
||||
_dxgi = dxgi ?? AskDxgi;
|
||||
_registry = registry ?? ReadRegistry;
|
||||
}
|
||||
|
||||
/// <summary>Takes a while on Linux, where the PCI list is read: not for the UI thread.</summary>
|
||||
@@ -46,15 +52,34 @@ public sealed class GraphicsCards
|
||||
IEnumerable<GraphicsCard> cards = Array.Empty<GraphicsCard>();
|
||||
if (_environment.IsLinux)
|
||||
cards = FromLinux();
|
||||
else if (_environment.IsWindows && OperatingSystem.IsWindows())
|
||||
cards = FromRegistry();
|
||||
else if (_environment.IsWindows)
|
||||
cards = FromWindows();
|
||||
|
||||
// A program goes to the discrete card, on Windows by its own request.
|
||||
return cards.OrderBy(card => card.SharedMemory).ThenByDescending(card => card.MemoryBytes).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DXGI's list, the adapters the simulator's OpenGL runs on. The registry's list of
|
||||
/// video devices only when DXGI cannot be asked or lists no card: there each driver
|
||||
/// writes what it chooses, and some leave their card out (an RTX 3060 beside a Ryzen's
|
||||
/// Radeon was missing from it).
|
||||
/// </summary>
|
||||
private IReadOnlyList<GraphicsCard> FromWindows()
|
||||
{
|
||||
var adapters = _dxgi();
|
||||
var cards = adapters is null ? Array.Empty<GraphicsCard>() : DxgiAdapters.Cards(adapters);
|
||||
return cards.Count > 0 ? cards : _registry();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<DxgiAdapter>? AskDxgi() =>
|
||||
OperatingSystem.IsWindows() ? DxgiAdapters.Read() : null;
|
||||
|
||||
private static IReadOnlyList<GraphicsCard> ReadRegistry() =>
|
||||
OperatingSystem.IsWindows() ? FromRegistry() : Array.Empty<GraphicsCard>();
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
private static IEnumerable<GraphicsCard> FromRegistry()
|
||||
private static IReadOnlyList<GraphicsCard> FromRegistry()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -286,7 +286,11 @@ public sealed class SceneryParser
|
||||
|
||||
if (numbers.Count >= 6 &&
|
||||
double.TryParse(numbers[^1], NumberStyles.Float, CultureInfo.InvariantCulture, out double overcast))
|
||||
weather.Overcast = overcast;
|
||||
{
|
||||
// The simulator draws a negative overcast anew each run, from 0 up to its size.
|
||||
weather.OvercastRandom = overcast < 0;
|
||||
weather.Overcast = Math.Max(overcast, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static string? MatchAllDirectives(string content, string letter)
|
||||
|
||||
@@ -6,8 +6,15 @@ using Avalonia;
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Drawn by the processor instead of the graphics card, for a machine on which the
|
||||
/// window comes up empty. Each platform reads only its own options, so both are given.
|
||||
/// On Windows the processor draws the starter's windows, and each frame is copied into its window
|
||||
/// by GDI. Every way of the graphics card's failed on some machine: Avalonia's WinUI composition
|
||||
/// visual left windows black on Windows 11 25H2, the Steam overlay drew its frame counter over a
|
||||
/// window's own swap chain, and with DirectComposition the starter vanished a few seconds after its
|
||||
/// window came up on a Windows 10 machine with a GTX 1650, without a word in its log. A frame copied
|
||||
/// by GDI has no swap chain for an overlay to hook, and lists, text and pictures are no work for the
|
||||
/// processor.
|
||||
/// On X11 the graphics card draws, unless <see cref="Switch"/> asks the processor, for a machine on
|
||||
/// which the window comes up empty. Each platform reads only its own options.
|
||||
/// </summary>
|
||||
public static class SoftwareRender
|
||||
{
|
||||
@@ -27,6 +34,9 @@ public static class SoftwareRender
|
||||
RenderingMode = new[] { X11RenderingMode.Software }
|
||||
};
|
||||
|
||||
public static AppBuilder ApplyTo(AppBuilder builder) =>
|
||||
builder.With(Win32Options).With(X11Options);
|
||||
public static AppBuilder ApplyTo(AppBuilder builder, IEnumerable<string> args)
|
||||
{
|
||||
builder.With(Win32Options);
|
||||
return AskedIn(args) ? builder.With(X11Options) : builder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using Avalonia;
|
||||
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// On Windows the graphics card draws each window of the starter into a DirectComposition
|
||||
/// surface, not into Avalonia's default WinUI composition visual. On Windows 11 25H2 that
|
||||
/// visual was left empty on many starts: the main window, or a dialog opened later,
|
||||
/// stayed black while the others drew, and came back only now and then.
|
||||
/// The window's own redirection surface is only the fallback: there ANGLE draws through a
|
||||
/// swap chain of the window, and the Steam overlay, which Steam puts into the starter as
|
||||
/// the game it launches, hooks that swap chain's Present and draws its frame counter and
|
||||
/// notifications over the starter. A composition surface is drawn without a Present.
|
||||
/// </summary>
|
||||
public static class WindowSurfaces
|
||||
{
|
||||
public static Win32PlatformOptions Win32Options => new()
|
||||
{
|
||||
CompositionMode = new[]
|
||||
{
|
||||
Win32CompositionMode.DirectComposition,
|
||||
Win32CompositionMode.RedirectionSurface
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The options a platform reads are the last given, so the processor, when asked
|
||||
/// for, draws with <see cref="SoftwareRender"/>'s own and these are left out.
|
||||
/// </summary>
|
||||
public static AppBuilder ApplyTo(AppBuilder builder, bool softwareRender) =>
|
||||
softwareRender ? SoftwareRender.ApplyTo(builder) : builder.With(Win32Options);
|
||||
}
|
||||
@@ -57,6 +57,9 @@ public partial class MainWindow : Window
|
||||
ExtendClientAreaTitleBarHeightHint = TitleBarHeight;
|
||||
|
||||
FitToScreen();
|
||||
// Gamescope does not maximize a window: it would stretch the first size over the screen.
|
||||
if (GamescopeWindows.Active)
|
||||
GamescopeWindows.FillScreen(this);
|
||||
// Ahead of the layout a new size starts: changed during it, the bar keeps the old width.
|
||||
Resized += (_, e) => FitTopBar(e.ClientSize.Width);
|
||||
Opened += (_, _) => FitTopBar(ClientSize.Width);
|
||||
@@ -432,7 +435,7 @@ public partial class MainWindow : Window
|
||||
private bool wantsMaximized()
|
||||
{
|
||||
// make sure the window fills the whole screen on gamescope sessions
|
||||
if (Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP") == "gamescope")
|
||||
if (GamescopeWindows.Active)
|
||||
return true;
|
||||
|
||||
// catch being launched via Steam Big Picture mode as well
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace StarterNG;
|
||||
static class Program
|
||||
{
|
||||
|
||||
private static bool _softwareRender;
|
||||
// What --software-render is looked for in; none for the designer, which calls BuildAvaloniaApp itself.
|
||||
private static string[] _args = Array.Empty<string>();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
@@ -19,7 +20,7 @@ static class Program
|
||||
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
||||
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
||||
|
||||
_softwareRender = SoftwareRender.AskedIn(args);
|
||||
_args = args;
|
||||
|
||||
// Composition root first: everything below, including the crash handlers,
|
||||
// resolves its collaborators from this graph.
|
||||
@@ -73,14 +74,14 @@ static class Program
|
||||
};
|
||||
}
|
||||
|
||||
// Without the switch the graphics card draws, into the window surfaces.
|
||||
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
|
||||
WindowSurfaces.ApplyTo(builder, _softwareRender);
|
||||
// On Windows the processor draws; on X11 the graphics card, unless --software-render.
|
||||
private static AppBuilder WithSoftwareRender(this AppBuilder builder) =>
|
||||
SoftwareRender.ApplyTo(builder, _args);
|
||||
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.WithSoftwareRenderIfAsked()
|
||||
.WithSoftwareRender()
|
||||
.WithInterFont()
|
||||
.WithDiagnosticsLogging()
|
||||
.AfterSetup(_ => LogUiExceptions());
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<!-- DXGI is asked through function pointers, which NativeAOT compiles without reflection. -->
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationIcon>Assets\starter.ico</ApplicationIcon>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
|
||||
@@ -69,7 +69,7 @@ public partial class Depot : UserControl
|
||||
if (Design.IsDesignMode)
|
||||
return;
|
||||
|
||||
// The standard mode lists other consists and leaves the crew alone.
|
||||
// The standard mode lists other consists and leaves the crew of the simulator's own alone.
|
||||
Settings.AdvancedModeChanged += () =>
|
||||
{
|
||||
PopulateSceneryConsists();
|
||||
|
||||
@@ -49,6 +49,9 @@ public sealed class VehicleCards
|
||||
|
||||
public Dynamic? PressedCar { get; set; }
|
||||
|
||||
private bool CrewEditable =>
|
||||
TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
|
||||
|
||||
public VehicleCards(Panel consistStack, VehicleCatalog db, Consist consist,
|
||||
Cargo cargo, MiniTextures minis, Cursor hand,
|
||||
Action redraw, Action refreshDetails, Action<Dynamic> selectInBrowser,
|
||||
@@ -117,8 +120,8 @@ public sealed class VehicleCards
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
Margin = new Thickness(0, 1, 0, 2)
|
||||
};
|
||||
// Who sits in the cab - the player, the simulator, a passenger or nobody - is for the advanced mode.
|
||||
if (AppServices.Current.Settings.AdvancedSettings)
|
||||
// Who sits in the cab; in the standard mode not in the simulator's own consists.
|
||||
if (CrewEditable)
|
||||
controls.Children.Add(DriverButton(item));
|
||||
controls.Children.Add(FlipButton(item));
|
||||
|
||||
@@ -695,7 +698,7 @@ public sealed class VehicleCards
|
||||
else if (_consist.CanJoin(item, index))
|
||||
menu.AddItem(App.Loc["TipJoin"], () => _consist.Join(item));
|
||||
|
||||
if (AppServices.Current.Settings.AdvancedSettings)
|
||||
if (CrewEditable)
|
||||
{
|
||||
var crew = new MenuItem { Header = App.Loc["CrewLabel"] };
|
||||
foreach (var (type, key) in CrewChoices.All)
|
||||
|
||||
@@ -280,8 +280,8 @@ public sealed class VehicleDetails
|
||||
};
|
||||
driver.MinWidth = 0;
|
||||
driver.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
// Shown but not changed in the standard mode: who drives is for the advanced one.
|
||||
driver.IsEnabled = AppServices.Current.Settings.AdvancedSettings;
|
||||
// Shown but not changed in the standard mode in the simulator's own consists.
|
||||
driver.IsEnabled = TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
|
||||
|
||||
var rows = new StackPanel();
|
||||
rows.Children.Add(Row(App.Loc["CrewLabel"], driver));
|
||||
|
||||
@@ -189,13 +189,12 @@
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectionChanged="Weather_OnSelectionChanged">
|
||||
<ComboBoxItem Tag="random" Content="{Binding [OvercastRandom], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="-1.5" Content="{Binding [OvercastClear], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="0" Content="{Binding [OvercastFair], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="0" Content="{Binding [OvercastClear], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="0.3" Content="{Binding [OvercastLight], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="0.7" Content="{Binding [OvercastModerate], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="1" Content="{Binding [OvercastHeavy], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="1.1" Content="{Binding [OvercastCloudy], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="1.5" Content="{Binding [OvercastStorm], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ComboBoxItem Tag="1" Content="{Binding [OvercastCloudy], Source={x:Static starterNg:App.Loc}}" />
|
||||
<ctl:PrecipitationItem Tag="1.1" Name="weatherPrecipitationLight" />
|
||||
<ctl:PrecipitationItem Tag="1.5" Name="weatherPrecipitation" Heavy="True" />
|
||||
</ComboBox>
|
||||
|
||||
<Border Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="5"
|
||||
|
||||
@@ -831,6 +831,7 @@ public partial class Scenarios : UserControl
|
||||
weatherTemp.ValueText = weatherTempLabel.Text;
|
||||
weatherFog.ValueText = weatherFogLabel.Text;
|
||||
weatherDayDate.Text = string.Format(LanguageCulture, App.Loc["DayOfYear"], SelectedDayOfYear());
|
||||
weatherPrecipitationLight.Snow = weatherPrecipitation.Snow = SceneryWeather.Snows(weatherTemp.Value);
|
||||
|
||||
weatherRestore.IsEnabled = _currentScenery?.Weather.Changed ?? false;
|
||||
}
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
<String key="SeasonWinter">Zima</String>
|
||||
<String key="OvercastRandom">Náhodné</String>
|
||||
<String key="OvercastClear">Jasno</String>
|
||||
<String key="OvercastFair">Skoro jasno</String>
|
||||
<String key="OvercastLight">Slabá oblačnost</String>
|
||||
<String key="OvercastModerate">Mírná oblačnost</String>
|
||||
<String key="OvercastHeavy">Silná oblačnost</String>
|
||||
<String key="OvercastCloudy">Zataženo</String>
|
||||
<String key="OvercastStorm">Bouřka</String>
|
||||
<String key="OvercastRainLight">Slabý déšť</String>
|
||||
<String key="OvercastRain">Déšť</String>
|
||||
<String key="OvercastSnowLight">Slabé sněžení</String>
|
||||
<String key="OvercastSnow">Sněžení</String>
|
||||
<String key="WeatherDateTime">Datum a čas</String>
|
||||
<String key="WeatherConditions">Povětrnostní podmínky</String>
|
||||
<String key="Consist">Souprava</String>
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
<String key="SeasonWinter">Winter</String>
|
||||
<String key="OvercastRandom">Random</String>
|
||||
<String key="OvercastClear">Clear</String>
|
||||
<String key="OvercastFair">Fair</String>
|
||||
<String key="OvercastLight">Light clouds</String>
|
||||
<String key="OvercastModerate">Moderate clouds</String>
|
||||
<String key="OvercastHeavy">Heavy clouds</String>
|
||||
<String key="OvercastCloudy">Cloudy</String>
|
||||
<String key="OvercastStorm">Storm</String>
|
||||
<String key="OvercastRainLight">Light rain</String>
|
||||
<String key="OvercastRain">Rain</String>
|
||||
<String key="OvercastSnowLight">Light snow</String>
|
||||
<String key="OvercastSnow">Snow</String>
|
||||
<String key="WeatherDateTime">Date and time</String>
|
||||
<String key="WeatherConditions">Conditions</String>
|
||||
<String key="Consist">Consist</String>
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
<String key="SeasonWinter">Tél</String>
|
||||
<String key="OvercastRandom">Véletlenszerű</String>
|
||||
<String key="OvercastClear">Derült</String>
|
||||
<String key="OvercastFair">Gyengén felhős</String>
|
||||
<String key="OvercastLight">Kevés felhő</String>
|
||||
<String key="OvercastModerate">Közepes felhőzet</String>
|
||||
<String key="OvercastHeavy">Erős felhőzet</String>
|
||||
<String key="OvercastCloudy">Borult</String>
|
||||
<String key="OvercastStorm">Vihar</String>
|
||||
<String key="OvercastRainLight">Gyenge eső</String>
|
||||
<String key="OvercastRain">Eső</String>
|
||||
<String key="OvercastSnowLight">Gyenge havazás</String>
|
||||
<String key="OvercastSnow">Havazás</String>
|
||||
<String key="WeatherDateTime">Dátum és idő</String>
|
||||
<String key="WeatherConditions">Időjárási viszonyok</String>
|
||||
<String key="Consist">Szerelvény</String>
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
<String key="SeasonWinter">Zima</String>
|
||||
<String key="OvercastRandom">Losowe</String>
|
||||
<String key="OvercastClear">Bezchmurnie</String>
|
||||
<String key="OvercastFair">Pogodnie</String>
|
||||
<String key="OvercastLight">Lekkie zachmurzenie</String>
|
||||
<String key="OvercastModerate">Umiarkowane zachmurzenie</String>
|
||||
<String key="OvercastHeavy">Duże zachmurzenie</String>
|
||||
<String key="OvercastCloudy">Pochmurno</String>
|
||||
<String key="OvercastStorm">Burza</String>
|
||||
<String key="OvercastRainLight">Lekki deszcz</String>
|
||||
<String key="OvercastRain">Deszcz</String>
|
||||
<String key="OvercastSnowLight">Lekki śnieg</String>
|
||||
<String key="OvercastSnow">Śnieg</String>
|
||||
<String key="WeatherDateTime">Data i godzina</String>
|
||||
<String key="WeatherConditions">Warunki atmosferyczne</String>
|
||||
<String key="Consist">Zestawienie</String>
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
<String key="SeasonWinter">Зима</String>
|
||||
<String key="OvercastRandom">Случайно</String>
|
||||
<String key="OvercastClear">Ясно</String>
|
||||
<String key="OvercastFair">Малооблачно</String>
|
||||
<String key="OvercastLight">Лёгкая облачность</String>
|
||||
<String key="OvercastModerate">Умеренная облачность</String>
|
||||
<String key="OvercastHeavy">Сильная облачность</String>
|
||||
<String key="OvercastCloudy">Пасмурно</String>
|
||||
<String key="OvercastStorm">Гроза</String>
|
||||
<String key="OvercastRainLight">Небольшой дождь</String>
|
||||
<String key="OvercastRain">Дождь</String>
|
||||
<String key="OvercastSnowLight">Небольшой снег</String>
|
||||
<String key="OvercastSnow">Снег</String>
|
||||
<String key="WeatherDateTime">Дата и время</String>
|
||||
<String key="WeatherConditions">Погодные условия</String>
|
||||
<String key="Consist">Состав</String>
|
||||
|
||||
@@ -48,12 +48,13 @@
|
||||
<String key="SeasonWinter">冬</String>
|
||||
<String key="OvercastRandom">随机</String>
|
||||
<String key="OvercastClear">晴</String>
|
||||
<String key="OvercastFair">晴好</String>
|
||||
<String key="OvercastLight">少云</String>
|
||||
<String key="OvercastModerate">多云</String>
|
||||
<String key="OvercastHeavy">阴</String>
|
||||
<String key="OvercastCloudy">阴天</String>
|
||||
<String key="OvercastStorm">雷暴</String>
|
||||
<String key="OvercastRainLight">小雨</String>
|
||||
<String key="OvercastRain">雨</String>
|
||||
<String key="OvercastSnowLight">小雪</String>
|
||||
<String key="OvercastSnow">雪</String>
|
||||
<String key="WeatherDateTime">日期和时间</String>
|
||||
<String key="WeatherConditions">天气状况</String>
|
||||
<String key="Consist">编组</String>
|
||||
|
||||
Reference in New Issue
Block a user