Skip to content

Commit

Permalink
Updated Avalonia to 11.0.10 and Godot to 4.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJul committed May 3, 2024
1 parent b2e9eb8 commit 45c6b10
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 37 deletions.
6 changes: 3 additions & 3 deletions samples/GameMenu/GameMenu.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.1.3">
<Project Sdk="Godot.NET.Sdk/4.2.2">

<PropertyGroup>
<AssemblyTitle>Estragonia GameMenu Sample</AssemblyTitle>
Expand All @@ -22,8 +22,8 @@

<ItemGroup>
<PackageReference Include="JLeb.Estragonia" Version="1.*" Condition="$(SolutionName) != 'JLeb.Estragonia'" />
<PackageReference Include="Avalonia.Themes.Simple" Version="[11.0.5]" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="[11.0.2]" />
<PackageReference Include="Avalonia.Themes.Simple" Version="[11.0.10]" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="[11.0.10.9]" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.1.3">
<Project Sdk="Godot.NET.Sdk/4.2.2">

<PropertyGroup>
<AssemblyTitle>Estragonia HelloWorld Sample</AssemblyTitle>
Expand All @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="JLeb.Estragonia" Version="1.*" Condition="$(SolutionName) != 'JLeb.Estragonia'" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="[11.0.5]" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="[11.0.10]" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/HelloWorld/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ mesh = SubResource("BoxMesh_qchun")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
root_node = NodePath("../Cube")
autoplay = "cube_rotation"
libraries = {
"": SubResource("AnimationLibrary_jucv5")
}
autoplay = "cube_rotation"

[node name="UserInterface" type="Control" parent="."]
layout_mode = 3
Expand Down
2 changes: 1 addition & 1 deletion samples/HelloWorld/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="HelloWorld"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.1", "C#", "Forward Plus")
config/features=PackedStringArray("4.2", "C#", "Forward Plus")
config/icon="res://icon.svg"

[autoload]
Expand Down
1 change: 0 additions & 1 deletion src/JLeb.Estragonia/AvaloniaControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Godot.NativeInterop;
using JLeb.Estragonia.Input;
using AvControl = Avalonia.Controls.Control;
using AvDispatcher = Avalonia.Threading.Dispatcher;
using GdControl = Godot.Control;
using GdInput = Godot.Input;
using GdKey = Godot.Key;
Expand Down
137 changes: 133 additions & 4 deletions src/JLeb.Estragonia/ConversionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Avalonia;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Input;
using Godot;
using Godot.Collections;
using AvColor = Avalonia.Media.Color;
using AvKey = Avalonia.Input.Key;
using GdCursorShape = Godot.Control.CursorShape;
Expand Down Expand Up @@ -140,6 +140,132 @@ public static class ConversionExtensions {
[GdKey.Bar] = AvKey.Oem102
};

private static readonly Dictionary<GdKey, PhysicalKey> s_physicalKeyMap = new() {
[GdKey.Backspace] = PhysicalKey.Backspace,
[GdKey.Tab] = PhysicalKey.Tab, // Godot maps Tab and CrSel to the same key
[GdKey.Clear] = PhysicalKey.NumPadClear, // Godot maps both Clear and OEM Clear to the same key
[GdKey.Enter] = PhysicalKey.Enter,
[GdKey.Shift] = PhysicalKey.ShiftLeft, // Godot maps Left Shift and Right Shift keys to the same key
[GdKey.Ctrl] = PhysicalKey.ControlLeft, // Godot maps Left Ctrl and Right Ctrl keys to the same key
[GdKey.Alt] = PhysicalKey.AltLeft, // Godot maps Left Alt and Right Alt keys to the same key
[GdKey.Pause] = PhysicalKey.Pause,
[GdKey.Capslock] = PhysicalKey.CapsLock,
[GdKey.Escape] = PhysicalKey.Escape, // Godot maps Escape and Attn keys to the same key
[GdKey.Space] = PhysicalKey.Space,
[GdKey.Pageup] = PhysicalKey.PageUp,
[GdKey.Pagedown] = PhysicalKey.PageDown,
[GdKey.End] = PhysicalKey.End,
[GdKey.Home] = PhysicalKey.Home,
[GdKey.Left] = PhysicalKey.ArrowLeft,
[GdKey.Up] = PhysicalKey.ArrowUp,
[GdKey.Right] = PhysicalKey.ArrowRight,
[GdKey.Down] = PhysicalKey.ArrowDown,
[GdKey.Print] = PhysicalKey.PrintScreen, // Godot maps Print and Snapshot keys to the same key
[GdKey.Insert] = PhysicalKey.Insert,
[GdKey.Delete] = PhysicalKey.Delete,
[GdKey.Help] = PhysicalKey.Help,
[GdKey.A] = PhysicalKey.A,
[GdKey.B] = PhysicalKey.B,
[GdKey.C] = PhysicalKey.C,
[GdKey.D] = PhysicalKey.D,
[GdKey.E] = PhysicalKey.E,
[GdKey.F] = PhysicalKey.F,
[GdKey.G] = PhysicalKey.G,
[GdKey.H] = PhysicalKey.H,
[GdKey.I] = PhysicalKey.I,
[GdKey.J] = PhysicalKey.J,
[GdKey.K] = PhysicalKey.K,
[GdKey.L] = PhysicalKey.L,
[GdKey.M] = PhysicalKey.M,
[GdKey.N] = PhysicalKey.N,
[GdKey.O] = PhysicalKey.O,
[GdKey.P] = PhysicalKey.P,
[GdKey.Q] = PhysicalKey.Q,
[GdKey.R] = PhysicalKey.R,
[GdKey.S] = PhysicalKey.S,
[GdKey.T] = PhysicalKey.T,
[GdKey.U] = PhysicalKey.U,
[GdKey.V] = PhysicalKey.V,
[GdKey.W] = PhysicalKey.W,
[GdKey.X] = PhysicalKey.X,
[GdKey.Y] = PhysicalKey.Y,
[GdKey.Z] = PhysicalKey.Z,
[GdKey.Meta] = PhysicalKey.MetaLeft, // Godot maps Left Win and Right Win keys to the same key
[GdKey.Menu] = PhysicalKey.ContextMenu, // Godot maps Left Menu and Right Menu keys to the same key
[GdKey.Standby] = PhysicalKey.Sleep,
[GdKey.Kp0] = PhysicalKey.NumPad0,
[GdKey.Kp1] = PhysicalKey.NumPad1,
[GdKey.Kp2] = PhysicalKey.NumPad2,
[GdKey.Kp3] = PhysicalKey.NumPad3,
[GdKey.Kp4] = PhysicalKey.NumPad4,
[GdKey.Kp5] = PhysicalKey.NumPad5,
[GdKey.Kp6] = PhysicalKey.NumPad6,
[GdKey.Kp7] = PhysicalKey.NumPad7,
[GdKey.Kp8] = PhysicalKey.NumPad8,
[GdKey.Kp9] = PhysicalKey.NumPad9,
[GdKey.KpMultiply] = PhysicalKey.NumPadMultiply,
[GdKey.KpAdd] = PhysicalKey.NumPadAdd,
[GdKey.KpSubtract] = PhysicalKey.NumPadSubtract,
[GdKey.KpPeriod] = PhysicalKey.NumPadDecimal, // Godot maps Separator and Decimal keys to the same key
[GdKey.KpDivide] = PhysicalKey.NumPadDivide,
[GdKey.F1] = PhysicalKey.F1,
[GdKey.F2] = PhysicalKey.F2,
[GdKey.F3] = PhysicalKey.F3,
[GdKey.F4] = PhysicalKey.F4,
[GdKey.F5] = PhysicalKey.F5,
[GdKey.F6] = PhysicalKey.F6,
[GdKey.F7] = PhysicalKey.F7,
[GdKey.F8] = PhysicalKey.F8,
[GdKey.F9] = PhysicalKey.F9,
[GdKey.F10] = PhysicalKey.F10,
[GdKey.F11] = PhysicalKey.F11,
[GdKey.F12] = PhysicalKey.F12,
[GdKey.F13] = PhysicalKey.F13,
[GdKey.F14] = PhysicalKey.F14,
[GdKey.F15] = PhysicalKey.F15,
[GdKey.F16] = PhysicalKey.F16,
[GdKey.F17] = PhysicalKey.F17,
[GdKey.F18] = PhysicalKey.F18,
[GdKey.F19] = PhysicalKey.F19,
[GdKey.F20] = PhysicalKey.F20,
[GdKey.F21] = PhysicalKey.F21,
[GdKey.F22] = PhysicalKey.F22,
[GdKey.F23] = PhysicalKey.F23,
[GdKey.F24] = PhysicalKey.F24,
[GdKey.Numlock] = PhysicalKey.NumLock,
[GdKey.Scrolllock] = PhysicalKey.ScrollLock,
[GdKey.Back] = PhysicalKey.BrowserBack,
[GdKey.Forward] = PhysicalKey.BrowserForward,
[GdKey.Refresh] = PhysicalKey.BrowserRefresh,
[GdKey.Stop] = PhysicalKey.BrowserStop,
[GdKey.Search] = PhysicalKey.BrowserSearch,
[GdKey.Favorites] = PhysicalKey.BrowserFavorites,
[GdKey.Homepage] = PhysicalKey.Home,
[GdKey.Volumemute] = PhysicalKey.AudioVolumeMute,
[GdKey.Volumedown] = PhysicalKey.AudioVolumeDown,
[GdKey.Volumeup] = PhysicalKey.AudioVolumeUp,
[GdKey.Medianext] = PhysicalKey.MediaTrackNext,
[GdKey.Mediaprevious] = PhysicalKey.MediaTrackPrevious,
[GdKey.Mediastop] = PhysicalKey.MediaStop,
[GdKey.Mediaplay] = PhysicalKey.MediaPlayPause, // Godot maps bot Media Play/Pause and Play keys to the same key
[GdKey.Launchmail] = PhysicalKey.LaunchMail,
[GdKey.Launchmedia] = PhysicalKey.MediaSelect,
[GdKey.Launch0] = PhysicalKey.LaunchApp1,
[GdKey.Launch1] = PhysicalKey.LaunchApp2,
[GdKey.Semicolon] = PhysicalKey.Semicolon,
[GdKey.Equal] = PhysicalKey.Equal,
[GdKey.Comma] = PhysicalKey.Comma,
[GdKey.Minus] = PhysicalKey.Minus,
[GdKey.Period] = PhysicalKey.Period,
[GdKey.Slash] = PhysicalKey.Slash,
[GdKey.Quoteleft] = PhysicalKey.Backquote,
[GdKey.Bracketleft] = PhysicalKey.BracketLeft,
[GdKey.Backslash] = PhysicalKey.Backslash,
[GdKey.Bracketright] = PhysicalKey.BracketRight,
[GdKey.Apostrophe] = PhysicalKey.Quote,
[GdKey.Bar] = PhysicalKey.IntlBackslash
};

private static readonly Dictionary<StandardCursorType, GdCursorShape> s_cursorMap = new() {
[StandardCursorType.Arrow] = GdCursorShape.Arrow,
[StandardCursorType.Ibeam] = GdCursorShape.Ibeam,
Expand Down Expand Up @@ -167,7 +293,10 @@ public static class ConversionExtensions {
};

public static AvKey ToAvaloniaKey(this GdKey source)
=> s_keyMap.TryGetValue(source, out var result) ? result : AvKey.None;
=> s_keyMap.GetValueOrDefault(source, AvKey.None);

public static PhysicalKey ToAvaloniaPhysicalKey(this GdKey source)
=> s_physicalKeyMap.GetValueOrDefault(source, PhysicalKey.None);

public static Size ToAvaloniaSize(this Vector2 source)
=> new(source.X, source.Y);
Expand All @@ -179,6 +308,6 @@ public static AvColor ToAvaloniaColor(this GdColor source)
=> new((byte) source.A8, (byte) source.R8, (byte) source.G8, (byte) source.B8);

public static GdCursorShape ToGodotCursorShape(this StandardCursorType source)
=> s_cursorMap.TryGetValue(source, out var result) ? result : GdCursorShape.Arrow;
=> s_cursorMap.GetValueOrDefault(source, GdCursorShape.Arrow);

}
10 changes: 5 additions & 5 deletions src/JLeb.Estragonia/GodotTopLevelImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Avalonia.Rendering.Composition;
using Godot;
using JLeb.Estragonia.Input;
using AvDispatcher = Avalonia.Threading.Dispatcher;
using AvKey = Avalonia.Input.Key;
using GdCursorShape = Godot.Control.CursorShape;
using GdMouseButton = Godot.MouseButton;
Expand Down Expand Up @@ -260,16 +259,18 @@ public bool OnKey(InputEventKey inputEvent, ulong timestamp) {

var keyCode = inputEvent.Keycode;
var pressed = inputEvent.Pressed;

var key = keyCode.ToAvaloniaKey();

if (key != AvKey.None) {
var args = new RawKeyEventArgs(
GodotDevices.Keyboard,
timestamp,
_inputRoot,
pressed ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp,
key,
inputEvent.GetRawInputModifiers()
inputEvent.GetRawInputModifiers(),
inputEvent.PhysicalKeycode.ToAvaloniaPhysicalKey(),
OS.GetKeycodeString(inputEvent.KeyLabel)
);

input(args);
Expand Down Expand Up @@ -300,8 +301,7 @@ public bool OnJoypadButton(InputEventJoypadButton inputEvent, ulong timestamp) {
timestamp,
_inputRoot,
inputEvent.IsPressed() ? RawJoypadButtonEventType.ButtonDown : RawJoypadButtonEventType.ButtonUp,
inputEvent.ButtonIndex,
inputEvent.Pressure
inputEvent.ButtonIndex
);

input(args);
Expand Down
9 changes: 1 addition & 8 deletions src/JLeb.Estragonia/Input/JoypadButtonEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ public class JoypadButtonEventArgs : RoutedEventArgs {
/// <summary>Gets the button that was pressed or released.</summary>
public JoyButton Button { get; }

/// <summary>
/// Gets the pressure the user puts on the button with their finger, if the controller supports it.
/// Ranges from 0 to 1.
/// </summary>
public float Pressure { get; }

public JoypadButtonEventArgs(RoutedEvent? routedEvent, object? source, IJoypadDevice device, JoyButton button, float pressure)
public JoypadButtonEventArgs(RoutedEvent? routedEvent, object? source, IJoypadDevice device, JoyButton button)
: base(routedEvent, source) {
Device = device;
Button = button;
Pressure = pressure;
}

}
2 changes: 1 addition & 1 deletion src/JLeb.Estragonia/Input/JoypadDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void ProcessButtonEvent(RawJoypadButtonEventArgs rawArgs) {
return;

var element = rawArgs.Root.FocusManager?.GetFocusedElement() ?? rawArgs.Root;
var args = new JoypadButtonEventArgs(routedEvent, element, this, rawArgs.Button, rawArgs.Pressure);
var args = new JoypadButtonEventArgs(routedEvent, element, this, rawArgs.Button);
element.RaiseEvent(args);
rawArgs.Handled = args.Handled;
}
Expand Down
10 changes: 1 addition & 9 deletions src/JLeb.Estragonia/Input/RawJoypadButtonEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ public class RawJoypadButtonEventArgs : RawInputEventArgs {
/// <summary>Gets the button that was pressed or released.</summary>
public JoyButton Button { get; }

/// <summary>
/// Gets the pressure the user puts on the button with their finger, if the controller supports it.
/// Ranges from 0 to 1.
/// </summary>
public float Pressure { get; }

public RawJoypadButtonEventArgs(
IJoypadDevice device,
ulong timestamp,
IInputRoot root,
RawJoypadButtonEventType type,
JoyButton button,
float pressure
JoyButton button
) : base(device, timestamp, root) {
Button = button;
Pressure = pressure;
Type = type;
}

Expand Down
4 changes: 2 additions & 2 deletions src/JLeb.Estragonia/JLeb.Estragonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GodotSharp" Version="4.1.3" />
<PackageReference Include="Avalonia.Skia" Version="[11.0.5]" />
<PackageReference Include="GodotSharp" Version="4.2.2" />
<PackageReference Include="Avalonia.Skia" Version="[11.0.10]" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>

Expand Down

0 comments on commit 45c6b10

Please sign in to comment.