mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-01 20:34:57 +01:00
A consist added to the warehouse gets a name there. The crew type stays through loading a consist. The vehicle base window replaces the texture base. The depot follows consists changed on the scenarios page, also with the warehouse tab left open.
97 lines
3.8 KiB
C#
97 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Avalonia.Input;
|
|
|
|
namespace StarterNG.Infrastructure;
|
|
|
|
public enum ShortcutScope
|
|
{
|
|
Global,
|
|
|
|
Depot,
|
|
|
|
Consist
|
|
}
|
|
|
|
public sealed record Shortcut(
|
|
string Id,
|
|
string Display,
|
|
string LabelKey,
|
|
ShortcutScope Scope,
|
|
Key Key = Key.None,
|
|
KeyModifiers Modifiers = KeyModifiers.None)
|
|
{
|
|
public bool IsDispatched => Key != Key.None;
|
|
|
|
public bool Matches(Key key, KeyModifiers modifiers) =>
|
|
IsDispatched && Key == key && Modifiers == modifiers;
|
|
}
|
|
|
|
public static class Shortcuts
|
|
{
|
|
public const string Start = "start";
|
|
public const string PageScenarios = "page.scenarios";
|
|
public const string PageDepot = "page.depot";
|
|
public const string PageSettings = "page.settings";
|
|
public const string ShowHelp = "help";
|
|
public const string AddVehicle = "vehicle.add";
|
|
public const string RemoveVehicle = "vehicle.remove";
|
|
public const string ClearConsist = "consist.clear";
|
|
public const string SetNumber = "vehicle.number";
|
|
public const string FocusSearch = "search";
|
|
public const string Undo = "consist.undo";
|
|
public const string Redo = "consist.redo";
|
|
public const string SaveToScenery = "consist.savescenery";
|
|
|
|
public static readonly IReadOnlyList<Shortcut> All = new[]
|
|
{
|
|
new Shortcut(Start, "Ctrl+Enter", "Start", ShortcutScope.Global,
|
|
Key.Enter, KeyModifiers.Control),
|
|
new Shortcut(PageScenarios, "Ctrl+1", "NavScenarios", ShortcutScope.Global,
|
|
Key.D1, KeyModifiers.Control),
|
|
new Shortcut(PageDepot, "Ctrl+2", "NavDepot", ShortcutScope.Global,
|
|
Key.D2, KeyModifiers.Control),
|
|
new Shortcut(PageSettings, "Ctrl+3", "NavSettings", ShortcutScope.Global,
|
|
Key.D3, KeyModifiers.Control),
|
|
new Shortcut(ShowHelp, "F1", "ShortcutShowHelp", ShortcutScope.Global,
|
|
Key.F1),
|
|
|
|
new Shortcut(FocusSearch, "Ctrl+F", "ShortcutFocusSearch", ShortcutScope.Depot,
|
|
Key.F, KeyModifiers.Control),
|
|
new Shortcut(AddVehicle, "Insert", "ShortcutAddVehicle", ShortcutScope.Depot,
|
|
Key.Insert),
|
|
new Shortcut(RemoveVehicle, "Delete", "RemoveVehicle", ShortcutScope.Depot,
|
|
Key.Delete),
|
|
new Shortcut(ClearConsist, "Ctrl+Delete", "ConsistRemoveAll", ShortcutScope.Depot,
|
|
Key.Delete, KeyModifiers.Control),
|
|
new Shortcut(SetNumber, "Ctrl+N", "ShortcutSetNumber", ShortcutScope.Depot,
|
|
Key.N, KeyModifiers.Control),
|
|
new Shortcut(Undo, "Ctrl+Z", "ShortcutUndo", ShortcutScope.Depot,
|
|
Key.Z, KeyModifiers.Control),
|
|
new Shortcut(Redo, "Ctrl+Y", "ShortcutRedo", ShortcutScope.Depot,
|
|
Key.Y, KeyModifiers.Control),
|
|
new Shortcut(SaveToScenery, "Ctrl+S", "SaveToScenery", ShortcutScope.Depot,
|
|
Key.S, KeyModifiers.Control),
|
|
|
|
new Shortcut("consist.prevnext", "← →", "ShortcutPrevNext", ShortcutScope.Consist),
|
|
new Shortcut("consist.firstlast", "Home / End", "ShortcutFirstLast", ShortcutScope.Consist),
|
|
new Shortcut("consist.member", "↑ ↓", "ShortcutMember", ShortcutScope.Consist),
|
|
new Shortcut("consist.move", "Ctrl+← Ctrl+→", "ShortcutMoveVehicle", ShortcutScope.Consist),
|
|
new Shortcut("consist.flip", "Space", "TipFlip", ShortcutScope.Consist),
|
|
new Shortcut("consist.menu", "Enter", "ShortcutCardMenu", ShortcutScope.Consist)
|
|
};
|
|
|
|
public static string? Match(Key key, KeyModifiers modifiers) =>
|
|
All.FirstOrDefault(s => s.Matches(key, modifiers))?.Id;
|
|
|
|
public static IEnumerable<Shortcut> InScope(ShortcutScope scope) =>
|
|
All.Where(s => s.Scope == scope);
|
|
|
|
public static string ScopeLabel(ShortcutScope scope) => scope switch
|
|
{
|
|
ShortcutScope.Depot => App.Loc["NavDepot"],
|
|
ShortcutScope.Consist => App.Loc["Consist"],
|
|
_ => App.Loc["ShortcutsGlobal"]
|
|
};
|
|
}
|