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 `(FInputActionValue, f32 elapsed seconds,
12/// f32 triggered seconds, InputAction)` or a leading part of it: the C++
13/// `EnhancedInputComponent->BindAction(Action, TriggerEvent, this, &AFoo::Function)`.
14///
15/// The actor must have its input component, which a pawn gets when a local
16/// player possesses it: bind from `ReceiveRestarted`, as C++ binds from
17/// `SetupPlayerInputComponent`.
18pub fn bind_action_raw(
19 actor: UObjectHandle,
20 action: UObjectHandle,
21 trigger_event: u8,
22 function: &str,
23) -> RustealResult<()> {
24 check_ffi_ctx(
25 unsafe {
26 ffi_dispatch::input_bind_action(
27 actor,
28 action,
29 trigger_event,
30 function.as_ptr(),
31 function.len() as u32,
32 )
33 },
34 function,
35 )
36}
37
38/// Whether the platform shows touch controls: the C++
39/// `SVirtualJoystick::ShouldDisplayTouchInterface()`, true on mobile, with
40/// `bAlwaysShowTouchInterface` in the input settings, or when faked touch
41/// events (`Use Mouse for Touch`) are set to display them.
42pub fn should_display_touch_interface() -> bool {
43 unsafe { ffi_dispatch::input_should_display_touch_interface() }
44}