Skip to main content

rusteal_core/
input.rs

1// Enhanced Input bindings (raw handle versions) and the touch interface check.
2// The typed wrapper lives in the generated bindings' manual/input_ext.rs.
3
4use rusteal_ffi::UObjectHandle;
5
6use crate::error::{check_ffi_ctx, RustealResult};
7use crate::ffi_dispatch;
8
9/// Bind `trigger_event` (an `ETriggerEvent` value) of `action` on `actor`'s
10/// Enhanced Input component to `actor`'s UFUNCTION `function` (its UE name),
11/// which takes no parameters or one `FInputActionValue`: the C++
12/// `EnhancedInputComponent->BindAction(Action, TriggerEvent, this, &AFoo::Function)`.
13///
14/// The actor must have its input component, which a pawn gets when a local
15/// player possesses it: bind from `ReceiveRestarted`, as C++ binds from
16/// `SetupPlayerInputComponent`.
17pub fn bind_action_raw(
18    actor: UObjectHandle,
19    action: UObjectHandle,
20    trigger_event: u8,
21    function: &str,
22) -> RustealResult<()> {
23    check_ffi_ctx(
24        unsafe {
25            ffi_dispatch::input_bind_action(
26                actor,
27                action,
28                trigger_event,
29                function.as_ptr(),
30                function.len() as u32,
31            )
32        },
33        function,
34    )
35}
36
37/// Whether the platform shows touch controls: the C++
38/// `SVirtualJoystick::ShouldDisplayTouchInterface()`, true on mobile, with
39/// `bAlwaysShowTouchInterface` in the input settings, or when faked touch
40/// events (`Use Mouse for Touch`) are set to display them.
41pub fn should_display_touch_interface() -> bool {
42    unsafe { ffi_dispatch::input_should_display_touch_interface() }
43}