Skip to content

Commit

Permalink
Input actions [debug] support
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Oct 25, 2024
1 parent af1de3a commit 165605c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
2 changes: 1 addition & 1 deletion KinectHandler/KinectHandler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Amethyst.Plugins.Contract">
<Version>0.2.25</Version>
<Version>0.3.32-alpha</Version>
</PackageReference>
<PackageReference Include="System.ComponentModel">
<Version>4.3.0</Version>
Expand Down
82 changes: 79 additions & 3 deletions plugin_Kinect360/Kinect360.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -47,14 +49,58 @@ public class Kinect360 : KinectHandler.KinectHandler, ITrackingDevice
public bool IsFlipSupported => true;
public bool IsAppOrientationSupported => true;
public object SettingsInterfaceRoot => InterfaceRoot;
private static IAmethystHost HostStatic { get; set; }

public ObservableCollection<TrackedJoint> TrackedJoints { get; } =
// Prepend all supported joints to the joints list
new(Enum.GetValues<TrackedJointType>()
.Where(x => x is not TrackedJointType.JointNeck and not TrackedJointType.JointManual and not
TrackedJointType.JointHandTipLeft and not TrackedJointType.JointHandTipRight and not
TrackedJointType.JointThumbLeft and not TrackedJointType.JointThumbRight)
.Select(x => new TrackedJoint { Name = x.ToString(), Role = x }));
.Select(x => new TrackedJoint
{
Name = x.ToString(), Role = x, SupportedInputActions = x switch
{
TrackedJointType.JointHandLeft =>
[
new KeyInputAction<bool>
{
Name = "Left Pause", Description = "Left hand pause gesture",
Guid = "5E4680F9-F232-4EA1-AE12-E96F7F8E0CC1", GetHost = () => HostStatic
},
new KeyInputAction<bool>
{
Name = "Left Point", Description = "Left hand point gesture",
Guid = "8D83B89D-5FBD-4D52-B626-4E90BDD26B08", GetHost = () => HostStatic
},
new KeyInputAction<bool>
{
Name = "Left Press", Description = "Left hand press gesture",
Guid = "E383258F-5918-4F1C-BC66-7325DB1F07E8", GetHost = () => HostStatic
}
],
TrackedJointType.JointHandRight =>
[
new KeyInputAction<bool>
{
Name = "Right Pause", Description = "Right hand pause gesture",
Guid = "B8389FA6-75EF-4509-AEC2-1758AFE41D95", GetHost = () => HostStatic
},
new KeyInputAction<bool>
{
Name = "Right Point", Description = "Right hand point gesture",
Guid = "C58EBCFE-0DF5-40FD-ABC1-06B415FA51BE", GetHost = () => HostStatic
},
new KeyInputAction<bool>
{
Name = "Right Press", Description = "Right hand press gesture",
Guid = "801336BE-5BD5-4881-A390-D57D958592EF", GetHost = () => HostStatic
}
],
_ => []
}
})
);

public string DeviceStatusString => PluginLoaded
? DeviceStatus switch
Expand Down Expand Up @@ -82,6 +128,9 @@ TrackedJointType.JointHandTipLeft and not TrackedJointType.JointHandTipRight and

public void OnLoad()
{
// Backup the plugin host
HostStatic = Host;

TiltNumberBox = new NumberBox
{
SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Inline,
Expand Down Expand Up @@ -109,6 +158,30 @@ public void OnLoad()
VerticalAlignment = VerticalAlignment.Center
};

// TODO TEMPORARY
var actionButtons = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, Margin = new Thickness(5) };
foreach (var action in TrackedJoints.SelectMany(x => x.SupportedInputActions))
{
var button = new Button { Content = action.Name };
actionButtons.Children.Add(button);

button.Click += (_, _) =>
{
try
{
if (action.IsUsed)
//action.Invoke(true);
Host.ReceiveKeyInput(action, true);
}
catch (Exception ex)
{
Host?.Log(ex);
Debugger.Break();
}
};
}
// TODO TEMPORARY

CameraImage = new WriteableBitmap(CameraImageWidth, CameraImageHeight);
InterfaceRoot = new Page
{
Expand All @@ -120,7 +193,10 @@ public void OnLoad()
{
Orientation = Orientation.Horizontal,
Children = { TiltTextBlock, TiltNumberBox }
}
},
// TODO TEMPORARY
actionButtons
// TODO TEMPORARY
}
}
};
Expand Down Expand Up @@ -178,7 +254,7 @@ public void Update()
TrackedJoints[trackedJoints.IndexOf(x)].Position = x.Position.Safe();
TrackedJoints[trackedJoints.IndexOf(x)].Orientation = x.Orientation.Safe();
});

// Update camera feed
if (!IsCameraEnabled) return;
CameraImage.DispatcherQueue.TryEnqueue(async () =>
Expand Down
3 changes: 2 additions & 1 deletion plugin_Kinect360/plugin_Kinect360.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<PublishTrimmed>true</PublishTrimmed>
<Platforms>x64</Platforms>
<UseWinUI>true</UseWinUI>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amethyst.Plugins.Contract" Version="0.2.25" />
<PackageReference Include="Amethyst.Plugins.Contract" Version="0.3.32-alpha" />
<PackageReference Include="RestSharp" Version="108.0.3" />
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" />
<PackageReference Include="System.ComponentModel.Composition.Registration" Version="8.0.0" />
Expand Down

0 comments on commit 165605c

Please sign in to comment.