Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/Controls/Default.controls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; Current control configuration
; Current control configuration
; =============================
; This file was automatically generated. Please modify only if you know what you're doing.
; Last updated 2026.01.16
Expand Down Expand Up @@ -79,6 +79,7 @@ CAMERA_ZOOM_OUT, keyboard, Keypad0, 0
CAMERA_POI_PREVIOUS, keyboard, Keypad1, 0
CAMERA_POI_NEXT, keyboard, Keypad7, 0
CAMERA_RESET, keyboard, Keypad5, 0
CAMERA_GRAB_TOGGLE, mouse, 2, 0
CAMERA_RESTRICTION, keyboard, R, 2
TIMETABLE_TOGGLE, keyboard, T, 2
TIMETABLE_UP, keyboard, Up, 2
Expand Down
31 changes: 31 additions & 0 deletions assets/Languages/en-US.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,30 @@
<trans-unit id="assignment_joystick_axis_positive">
<source>positive direction</source>
</trans-unit>
<trans-unit id="selection_mouse">
<source>Mouse:</source>
</trans-unit>
<trans-unit id="selection_mouse_button">
<source>Button:</source>
</trans-unit>
<trans-unit id="assignment_mouse">
<source>Mouse</source>
</trans-unit>
<trans-unit id="assignment_mouse_left">
<source>Left Click</source>
</trans-unit>
<trans-unit id="assignment_mouse_middle">
<source>Middle Click</source>
</trans-unit>
<trans-unit id="assignment_mouse_right">
<source>Right Click</source>
</trans-unit>
<trans-unit id="assignment_mouse_scrollup">
<source>Scroll Up</source>
</trans-unit>
<trans-unit id="assignment_mouse_scrolldown">
<source>Scroll Down</source>
</trans-unit>
<trans-unit id="assignment_joystick_axis_invalid">
<source>invalid direction</source>
</trans-unit>
Expand Down Expand Up @@ -1222,6 +1246,9 @@
<trans-unit id="camera_transition_duration">
<source>Transition duration (sec):</source>
</trans-unit>
<trans-unit id="camera_zoom_scroll_speed">
<source>Zoom Scroll Speed:</source>
</trans-unit>
<trans-unit id="misc_simulation">
<source>Detail of simulation</source>
</trans-unit>
Expand Down Expand Up @@ -1315,6 +1342,7 @@
<trans-unit id="other_timetable_mode_prefercustom">
<source>Prefer custom timetable</source>
</trans-unit>

<trans-unit id="package_choose">
<source>Choose...</source>
</trans-unit>
Expand Down Expand Up @@ -2238,6 +2266,9 @@
<trans-unit id="camera_reset">
<source>Resets the camera view to default values</source>
</trans-unit>
<trans-unit id="camera_grab_toggle">
<source>Toggles camera grab (Mouse look)</source>
</trans-unit>
<trans-unit id="camera_restriction">
<source>Activates or deactivates interior view camera restriction</source>
</trans-unit>
Expand Down
57 changes: 57 additions & 0 deletions assets/Languages/id-ID.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,38 @@
<source>positive direction</source>
<target>arah positif</target>
</trans-unit>
<trans-unit id="selection_mouse">
<source>Mouse:</source>
<target>Mouse:</target>
</trans-unit>
<trans-unit id="selection_mouse_button">
<source>Button:</source>
<target>Tombol:</target>
</trans-unit>
<trans-unit id="assignment_mouse">
<source>Mouse</source>
<target>Mouse</target>
</trans-unit>
<trans-unit id="assignment_mouse_left">
<source>Left Click</source>
<target>Klik Kiri</target>
</trans-unit>
<trans-unit id="assignment_mouse_middle">
<source>Middle Click</source>
<target>Klik Tengah</target>
</trans-unit>
<trans-unit id="assignment_mouse_right">
<source>Right Click</source>
<target>Klik Kanan</target>
</trans-unit>
<trans-unit id="assignment_mouse_scrollup">
<source>Scroll Up</source>
<target>Scroll Atas</target>
</trans-unit>
<trans-unit id="assignment_mouse_scrolldown">
<source>Scroll Down</source>
<target>Scroll Bawah</target>
</trans-unit>
<trans-unit id="assignment_joystick_axis_invalid">
<source>invalid direction</source>
<target>arah tidak valid</target>
Expand Down Expand Up @@ -1489,6 +1521,26 @@
<source>Miscellaneous</source>
<target>Lainnya</target>
</trans-unit>
<trans-unit id="camera">
<source>Camera options</source>
<target>Pengaturan kamera</target>
</trans-unit>
<trans-unit id="camera_interior_transition">
<source>Smooth interior transition</source>
<target>Transisi interior halus</target>
</trans-unit>
<trans-unit id="camera_exterior_transition">
<source>Smooth exterior transition</source>
<target>Transisi eksterior halus</target>
</trans-unit>
<trans-unit id="camera_transition_duration">
<source>Transition duration (sec):</source>
<target>Durasi transisi (detik):</target>
</trans-unit>
<trans-unit id="camera_zoom_scroll_speed">
<source>Zoom Scroll Speed:</source>
<target>Kecepatan Scroll Zoom:</target>
</trans-unit>
<trans-unit id="misc_simulation">
<source>Detail of simulation</source>
<target>Detail simulasi</target>
Expand Down Expand Up @@ -1611,6 +1663,7 @@
<source>Prefer custom timetable</source>
<target>Buat sendiri</target>
</trans-unit>

<trans-unit id="package_choose">
<source>Choose...</source>
<target>Pilih....</target>
Expand Down Expand Up @@ -2808,6 +2861,10 @@
<source>Resets the camera view to default values</source>
<target>Reset kamera</target>
</trans-unit>
<trans-unit id="camera_grab_toggle">
<source>Toggles camera grab (Mouse look)</source>
<target>Aktifkan/nonaktifkan kontrol kamera dengan mouse</target>
</trans-unit>
<trans-unit id="camera_restriction">
<source>Activates or deactivates interior view camera restriction</source>
<target>Aktifkan / matikan batasan kamera</target>
Expand Down
15 changes: 14 additions & 1 deletion source/OpenBVE/Game/Menu/Menu.Controls.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LibRender2.Primitives;
using LibRender2.Primitives;
using OpenBveApi.Colors;
using OpenBveApi.Hosts;
using OpenBveApi.Interface;
Expand Down Expand Up @@ -71,6 +71,19 @@ private static string GetControlDescription(int idx)
case ControlMethod.Invalid:
str = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "menu", "joystick_notavailable" });
break;
case ControlMethod.Mouse:
str = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "controls", "assignment_mouse" }) + " [";
switch (loadedControl.Element)
{
case MouseElement.Left: str += Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "controls", "assignment_mouse_left" }); break;
case MouseElement.Middle: str += Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "controls", "assignment_mouse_middle" }); break;
case MouseElement.Right: str += Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "controls", "assignment_mouse_right" }); break;
case MouseElement.ScrollUp: str += Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "controls", "assignment_mouse_scrollup" }); break;
case MouseElement.ScrollDown: str += Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "controls", "assignment_mouse_scrolldown" }); break;
default: str += loadedControl.Element; break;
}
str += "]";
break;
}

return str;
Expand Down
3 changes: 2 additions & 1 deletion source/OpenBVE/Game/Menu/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,15 @@ public bool IsCustomizingControl()
//
// SET CONTROL CUSTOM DATA
//
internal void SetControlKbdCustomData(Key key, KeyboardModifier keybMod)
internal void SetControlKbdCustomData(Key key, KeyboardModifier keybMod, int modifierOrder)
{
//Check that we are customising a key, and that our key is NOT the menu back key
if (isCustomisingControl && key != MenuBackKey && CustomControlIdx < Interface.CurrentControls.Length)
{
Interface.CurrentControls[CustomControlIdx].Method = ControlMethod.Keyboard;
Interface.CurrentControls[CustomControlIdx].Key = key;
Interface.CurrentControls[CustomControlIdx].Modifier = keybMod;
Interface.CurrentControls[CustomControlIdx].ModifierOrder = modifierOrder;
Interface.SaveControls(null, Interface.CurrentControls);
}
PopMenu();
Expand Down
2 changes: 1 addition & 1 deletion source/OpenBVE/System/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ protected override void OnRenderFrame(FrameEventArgs e)

MainLoop.UpdateControlRepeats(RealTimeElapsed);
MainLoop.ProcessKeyboard();
MainLoop.UpdateMouse(RealTimeElapsed);
MainLoop.ProcessControls(TimeElapsed);
MainLoop.UpdateMouse(RealTimeElapsed);
if (Program.Joysticks.AttachedJoysticks.TryGetTypedValue(AbstractRailDriver.Guid, out AbstractRailDriver railDriver))
{
if (Interface.CurrentOptions.RailDriverMPH)
Expand Down
37 changes: 35 additions & 2 deletions source/OpenBVE/System/Input/Controls.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -191,7 +191,21 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)
Controls[Length].Key = (OpenBveApi.Input.Key)CurrentKey;
Controls[Length].Direction = 0;
Controls[Length].Modifier = (KeyboardModifier) Modifiers;
if (Terms.Length >= 5 && int.TryParse(Terms[4], NumberStyles.Integer, Culture, out int Option))
if (Terms.Length >= 6)
{
// Format including the required modifier press order: key, modifiers, order, option
int Order;
if (!int.TryParse(Terms[4], NumberStyles.Integer, Culture, out Order) || Order < 0)
{
Order = 0;
}
Controls[Length].ModifierOrder = Order;
if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Option))
{
Controls[Length].Option = Option;
}
}
else if (Terms.Length >= 5 && int.TryParse(Terms[4], NumberStyles.Integer, Culture, out int Option))
{
Controls[Length].Option = Option;
}
Expand Down Expand Up @@ -332,6 +346,25 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls)

}
}
else if (Method == ControlMethod.Mouse & Terms.Length >= 3)
{
if (int.TryParse(Terms[2], out int CurrentButton))
{
Controls[Length].Method = Method;
Controls[Length].Element = CurrentButton;
Controls[Length].Modifier = KeyboardModifier.None;
Controls[Length].Option = 0;
if (Terms.Length >= 4 && int.TryParse(Terms[3], NumberStyles.Integer, Culture, out int Option))
{
Controls[Length].Option = Option;
}
if (Terms.Length >= 5 && int.TryParse(Terms[4], NumberStyles.Integer, Culture, out int Modifiers))
{
Controls[Length].Modifier = (KeyboardModifier) Modifiers;
}
Valid = true;
}
}

if (!Valid)
{
Expand Down
41 changes: 38 additions & 3 deletions source/OpenBVE/System/Input/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ internal static partial class MainLoop
/// <summary>Called when a KeyDown event is generated</summary>
internal static void KeyDownEvent(object sender, KeyboardKeyEventArgs e)
{
switch (e.Key)
{
case Key.ShiftLeft:
case Key.ShiftRight:
PushHeldModifier(KeyboardModifier.Shift);
break;
case Key.ControlLeft:
case Key.ControlRight:
PushHeldModifier(KeyboardModifier.Ctrl);
break;
case Key.AltLeft:
case Key.AltRight:
PushHeldModifier(KeyboardModifier.Alt);
break;
}
if (Interface.CurrentOptions.KioskMode && Program.Renderer.CurrentInterface != InterfaceType.GLMainMenu)
{
//If in kiosk mode, reset the timer and disable AI on keypress
Expand All @@ -34,9 +49,11 @@ internal static void KeyDownEvent(object sender, KeyboardKeyEventArgs e)
if (e.Shift) CurrentKeyboardModifier |= KeyboardModifier.Shift;
if (e.Control) CurrentKeyboardModifier |= KeyboardModifier.Ctrl;
if (e.Alt) CurrentKeyboardModifier |= KeyboardModifier.Alt;
HeldKeyboardModifiers |= CurrentKeyboardModifier;
int capturedModifierOrder = ModifierOrder.GetRank(HeldModifierSequence, HeldModifierSequenceCount, CurrentKeyboardModifier);
if (Program.Renderer.CurrentInterface >= InterfaceType.Menu && Game.Menu.IsCustomizingControl())
{
Game.Menu.SetControlKbdCustomData((OpenBveApi.Input.Key)e.Key, CurrentKeyboardModifier);
Game.Menu.SetControlKbdCustomData((OpenBveApi.Input.Key)e.Key, CurrentKeyboardModifier, capturedModifierOrder);
return;
}
//Traverse the controls array
Expand All @@ -47,7 +64,7 @@ internal static void KeyDownEvent(object sender, KeyboardKeyEventArgs e)
//Compare the current and previous keyboard states
//Only process if they are different
if (!Enum.IsDefined(typeof(OpenBveApi.Input.Key), Interface.CurrentControls[i].Key)) continue;
if ((OpenBveApi.Input.Key)e.Key == Interface.CurrentControls[i].Key && Interface.CurrentControls[i].Modifier == CurrentKeyboardModifier)
if ((OpenBveApi.Input.Key)e.Key == Interface.CurrentControls[i].Key && Interface.CurrentControls[i].Modifier == CurrentKeyboardModifier && (Interface.CurrentControls[i].ModifierOrder == 0 || Interface.CurrentControls[i].ModifierOrder == capturedModifierOrder))
{

Interface.CurrentControls[i].AnalogState = 1.0;
Expand Down Expand Up @@ -103,8 +120,26 @@ internal static void KeyUpEvent(object sender, KeyboardKeyEventArgs e)
{
TrainManager.PlayerTrain.Plugin.RawKeyUp((OpenBveApi.Input.Key)e.Key);
}
//We don't need to check for modifiers on key up
//Track held modifiers so mouse bindings requiring them can be matched
BlockKeyRepeat = true;
switch (e.Key)
{
case Key.ShiftLeft:
case Key.ShiftRight:
HeldKeyboardModifiers &= ~KeyboardModifier.Shift;
RemoveHeldModifier(KeyboardModifier.Shift);
break;
case Key.ControlLeft:
case Key.ControlRight:
HeldKeyboardModifiers &= ~KeyboardModifier.Ctrl;
RemoveHeldModifier(KeyboardModifier.Ctrl);
break;
case Key.AltLeft:
case Key.AltRight:
HeldKeyboardModifiers &= ~KeyboardModifier.Alt;
RemoveHeldModifier(KeyboardModifier.Alt);
break;
}
//Traverse the controls array
for (int i = 0; i < Interface.CurrentControls.Length; i++)
{
Expand Down
Loading