mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-10-30 11:40:28 +01:00
Draw a stand-in for a missing thumbnail, pass the language code to eu07.ini
The file was getting "pl" or "en" whatever the user picked, so a simulator with its own language file started in English.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
|
||||
@@ -25,6 +29,75 @@ public sealed class MiniTextures
|
||||
return image;
|
||||
}
|
||||
|
||||
/// <summary>Body of the drawn stand-in; the black wagon of the old starter.</summary>
|
||||
private static readonly IBrush MissingBody = new SolidColorBrush(Color.Parse("#0B0C0D"));
|
||||
|
||||
private static readonly IBrush MissingEdge = new SolidColorBrush(Color.Parse("#3A424A"));
|
||||
|
||||
private static readonly IBrush MissingMark = new SolidColorBrush(Color.Parse("#E6E8EA"));
|
||||
|
||||
/// <summary>Real minis are about 80x30, and the stand-in keeps that shape.</summary>
|
||||
private const double MiniAspect = 80.0 / 30.0;
|
||||
|
||||
/// <summary>
|
||||
/// The stand-in for a vehicle with no thumbnail: a dark wagon marked with
|
||||
/// question marks, the way the old starter drew textures/mini/other.bmp.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Reached only when the installation has no other.bmp either - a vehicle
|
||||
/// naming a thumbnail we do not have already falls back to that file. Drawn
|
||||
/// rather than loaded so the consist keeps its length whatever is missing;
|
||||
/// a vehicle that is simply absent from the strip reads as a shorter train.
|
||||
/// </remarks>
|
||||
public static Control MissingVisual(string? label, int height)
|
||||
{
|
||||
double width = height * MiniAspect;
|
||||
double bodyTop = height * 0.23;
|
||||
double bodyHeight = height * 0.47;
|
||||
double wheelRadius = height * 0.13;
|
||||
|
||||
var canvas = new Canvas { Width = width, Height = height };
|
||||
|
||||
var body = new Border
|
||||
{
|
||||
Width = width - 4,
|
||||
Height = bodyHeight,
|
||||
Background = MissingBody,
|
||||
BorderBrush = MissingEdge,
|
||||
BorderThickness = new Thickness(1),
|
||||
Child = new TextBlock
|
||||
{
|
||||
Text = "? ?",
|
||||
FontSize = Math.Max(9, height * 0.34),
|
||||
FontWeight = FontWeight.SemiBold,
|
||||
Foreground = MissingMark,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
}
|
||||
};
|
||||
Canvas.SetLeft(body, 2);
|
||||
Canvas.SetTop(body, bodyTop);
|
||||
canvas.Children.Add(body);
|
||||
|
||||
foreach (double centre in new[] { width * 0.22, width * 0.78 })
|
||||
{
|
||||
var wheel = new Ellipse
|
||||
{
|
||||
Width = wheelRadius * 2,
|
||||
Height = wheelRadius * 2,
|
||||
Fill = MissingBody
|
||||
};
|
||||
Canvas.SetLeft(wheel, centre - wheelRadius);
|
||||
Canvas.SetTop(wheel, bodyTop + bodyHeight - wheelRadius);
|
||||
canvas.Children.Add(wheel);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(label))
|
||||
ToolTip.SetTip(canvas, label);
|
||||
|
||||
return canvas;
|
||||
}
|
||||
|
||||
public Bitmap? Get(string? name, int height, bool strict = false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
|
||||
@@ -92,18 +92,9 @@ public sealed class VehicleCards
|
||||
}
|
||||
else
|
||||
{
|
||||
minis.Children.Add(MemberFrame(new Border
|
||||
{
|
||||
Height = VehicleCardStyle.ThumbHeight, Width = 90, Background = VehicleCardStyle.Placeholder,
|
||||
CornerRadius = new CornerRadius(4),
|
||||
Child = new TextBlock
|
||||
{
|
||||
Text = car.SkinFile, FontSize = 10, TextWrapping = TextWrapping.Wrap,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center
|
||||
}
|
||||
}, item, car, CardCaption(item, car, index)));
|
||||
minis.Children.Add(MemberFrame(
|
||||
MiniTextures.MissingVisual(car.SkinFile, VehicleCardStyle.ThumbHeight),
|
||||
item, car, CardCaption(item, car, index)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -427,26 +427,6 @@ public partial class Scenarios : UserControl
|
||||
private static readonly Avalonia.Media.IBrush SelectedVehicleBrush =
|
||||
new Avalonia.Media.SolidColorBrush(Avalonia.Media.Color.Parse("#41C400"));
|
||||
|
||||
private static readonly Avalonia.Media.IBrush MissingMiniBrush =
|
||||
new Avalonia.Media.SolidColorBrush(Avalonia.Media.Color.Parse("#22808080"));
|
||||
|
||||
private static Control MissingMiniBox(string? label, int height) => new Border
|
||||
{
|
||||
Height = height,
|
||||
Width = height * 2,
|
||||
Background = MissingMiniBrush,
|
||||
CornerRadius = new Avalonia.CornerRadius(4),
|
||||
Child = new TextBlock
|
||||
{
|
||||
Text = label,
|
||||
FontSize = 10,
|
||||
TextWrapping = Avalonia.Media.TextWrapping.Wrap,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = Avalonia.Media.TextAlignment.Center
|
||||
}
|
||||
};
|
||||
|
||||
private readonly Dictionary<string, Bitmap?> _miniCache = new();
|
||||
|
||||
private Bitmap? LoadMini(string? name, int height)
|
||||
@@ -834,7 +814,7 @@ public partial class Scenarios : UserControl
|
||||
Stretch = Avalonia.Media.Stretch.Uniform,
|
||||
Margin = new Thickness(0)
|
||||
})
|
||||
: MissingMiniBox(train.SkinFile, thumbH);
|
||||
: MiniTextures.MissingVisual(train.SkinFile, thumbH);
|
||||
|
||||
bool selected = !string.IsNullOrEmpty(train.Name) &&
|
||||
string.Equals(train.Name, AppServices.Current.State.StartingVehicleName,
|
||||
@@ -1025,14 +1005,11 @@ public partial class Scenarios : UserControl
|
||||
for (int i = _dragBlockStart; i < _dragBlockStart + _dragBlockLength; i++)
|
||||
{
|
||||
var source = consistStack.Children[i];
|
||||
// The ghost mirrors what the slot shows, stand-in wagons included, so
|
||||
// dragging a vehicle with no thumbnail still carries something visible.
|
||||
Control copy = source is Border { Child: Image image }
|
||||
? new Image { Source = image.Source, Height = image.Height, Stretch = image.Stretch }
|
||||
: new Border
|
||||
{
|
||||
Width = source.Bounds.Width,
|
||||
Height = source.Bounds.Height,
|
||||
Background = MissingMiniBrush
|
||||
};
|
||||
: MiniTextures.MissingVisual(null, (int)source.Bounds.Height);
|
||||
panel.Children.Add(copy);
|
||||
}
|
||||
|
||||
|
||||
@@ -277,8 +277,9 @@ public partial class Settings : UserControl, ISettingsCapture
|
||||
public void CaptureInto(SimulatorSettings s)
|
||||
{
|
||||
|
||||
s.Language = (ChangeLanguageCb.SelectedItem as ComboBoxItem)?.Content?.ToString()
|
||||
?? App.Loc.CurrentLanguage;
|
||||
var language = ChangeLanguageCb.SelectedItem as ComboBoxItem;
|
||||
s.Language = language?.Content?.ToString() ?? App.Loc.CurrentLanguage;
|
||||
s.LanguageCode = language?.Tag as string ?? App.Loc.CurrentLangCode;
|
||||
s.Fullscreen = IsChecked(FullscreenCb);
|
||||
s.PauseWhenInactive = IsChecked(PauseInactiveCb);
|
||||
s.PauseOnStart = IsChecked(PauseStartCb);
|
||||
|
||||
Reference in New Issue
Block a user