From cb3aa67e1f6916fac973b679a963872330507c7c Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Tue, 1 Aug 2023 19:04:51 -0700 Subject: [PATCH 1/3] Add utils.showFloatingGamepadTextInput() --- client.d.ts | 7 +++++++ src/api/utils.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/client.d.ts b/client.d.ts index 006629a..ca90578 100644 --- a/client.d.ts +++ b/client.d.ts @@ -185,6 +185,13 @@ export namespace utils { export function getAppId(): number export function getServerRealTime(): number export function isSteamRunningOnSteamDeck(): boolean + export const enum FloatingGamepadTextInputMode { + SingleLine = 0, + MultipleLines = 1, + Email = 2, + Numeric = 3 + } + export function showFloatingGamepadTextInput(keyboardMode: FloatingGamepadTextInputMode, x: number, y: number, width: number, height: number): boolean } export namespace workshop { export interface UgcResult { diff --git a/src/api/utils.rs b/src/api/utils.rs index 01346d6..ce56812 100644 --- a/src/api/utils.rs +++ b/src/api/utils.rs @@ -2,6 +2,9 @@ use napi_derive::napi; #[napi] pub mod utils { + use napi::bindgen_prelude::{FromNapiValue, ToNapiValue}; + use steamworks::FloatingGamepadTextInputMode as kFloatingGamepadTextInputMode; + #[napi] pub fn get_app_id() -> u32 { let client = crate::client::get_client(); @@ -19,4 +22,41 @@ pub mod utils { let client = crate::client::get_client(); client.utils().is_steam_running_on_steam_deck() } + + #[napi] + pub enum FloatingGamepadTextInputMode { + SingleLine, + MultipleLines, + Email, + Numeric, + } + + #[napi] + pub fn show_floating_gamepad_text_input( + keyboard_mode: FloatingGamepadTextInputMode, + x: i32, + y: i32, + width: i32, + height: i32, + ) -> bool { + let client = crate::client::get_client(); + let dismissed_cb = || {}; + client.utils().show_floating_gamepad_text_input( + match keyboard_mode { + FloatingGamepadTextInputMode::SingleLine => { + kFloatingGamepadTextInputMode::SingleLine + } + FloatingGamepadTextInputMode::MultipleLines => { + kFloatingGamepadTextInputMode::MultipleLines + } + FloatingGamepadTextInputMode::Email => kFloatingGamepadTextInputMode::Email, + FloatingGamepadTextInputMode::Numeric => kFloatingGamepadTextInputMode::Numeric, + }, + x, + y, + width, + height, + dismissed_cb, + ) + } } From c4195e49f18d433c090a2b8576d3df999785acc5 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Wed, 30 Aug 2023 19:32:48 -0700 Subject: [PATCH 2/3] Add utils.showGamepadTextInput() --- client.d.ts | 9 +++++++++ src/api/utils.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/client.d.ts b/client.d.ts index ca90578..f2327c1 100644 --- a/client.d.ts +++ b/client.d.ts @@ -185,6 +185,15 @@ export namespace utils { export function getAppId(): number export function getServerRealTime(): number export function isSteamRunningOnSteamDeck(): boolean + export const enum GamepadTextInputMode { + Normal = 0, + Password = 1 + } + export const enum GamepadTextInputLineMode { + SingleLine = 0, + MultipleLines = 1 + } + export function showGamepadTextInput(inputMode: GamepadTextInputMode, inputLineMode: GamepadTextInputLineMode, description: string, maxCharacters: number, existingText?: string | undefined | null): boolean export const enum FloatingGamepadTextInputMode { SingleLine = 0, MultipleLines = 1, diff --git a/src/api/utils.rs b/src/api/utils.rs index ce56812..cc74361 100644 --- a/src/api/utils.rs +++ b/src/api/utils.rs @@ -4,6 +4,8 @@ use napi_derive::napi; pub mod utils { use napi::bindgen_prelude::{FromNapiValue, ToNapiValue}; use steamworks::FloatingGamepadTextInputMode as kFloatingGamepadTextInputMode; + use steamworks::GamepadTextInputLineMode as kGamepadTextInputLineMode; + use steamworks::GamepadTextInputMode as kGamepadTextInputMode; #[napi] pub fn get_app_id() -> u32 { @@ -23,6 +25,44 @@ pub mod utils { client.utils().is_steam_running_on_steam_deck() } + #[napi] + pub enum GamepadTextInputMode { + Normal, + Password, + } + + #[napi] + pub enum GamepadTextInputLineMode { + SingleLine, + MultipleLines, + } + + #[napi] + pub fn show_gamepad_text_input( + input_mode: GamepadTextInputMode, + input_line_mode: GamepadTextInputLineMode, + description: String, + max_characters: u32, + existing_text: Option, + ) -> bool { + let client = crate::client::get_client(); + let dismissed_cb = |_| {}; + client.utils().show_gamepad_text_input( + match input_mode { + GamepadTextInputMode::Normal => kGamepadTextInputMode::Normal, + GamepadTextInputMode::Password => kGamepadTextInputMode::Password, + }, + match input_line_mode { + GamepadTextInputLineMode::SingleLine => kGamepadTextInputLineMode::SingleLine, + GamepadTextInputLineMode::MultipleLines => kGamepadTextInputLineMode::MultipleLines, + }, + &description, + max_characters, + existing_text.as_deref(), + dismissed_cb, + ) + } + #[napi] pub enum FloatingGamepadTextInputMode { SingleLine, From 4c047c76e6a59cb9a1fb578ee43148aec06511b5 Mon Sep 17 00:00:00 2001 From: ceifa Date: Mon, 17 Jun 2024 21:33:28 -0300 Subject: [PATCH 3/3] promisify gamepad functions --- client.d.ts | 6 ++++-- src/api/utils.rs | 54 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/client.d.ts b/client.d.ts index f2327c1..8c78acb 100644 --- a/client.d.ts +++ b/client.d.ts @@ -193,14 +193,16 @@ export namespace utils { SingleLine = 0, MultipleLines = 1 } - export function showGamepadTextInput(inputMode: GamepadTextInputMode, inputLineMode: GamepadTextInputLineMode, description: string, maxCharacters: number, existingText?: string | undefined | null): boolean + /** @returns the entered text, or null if cancelled or could not show the input */ + export function showGamepadTextInput(inputMode: GamepadTextInputMode, inputLineMode: GamepadTextInputLineMode, description: string, maxCharacters: number, existingText?: string | undefined | null): Promise export const enum FloatingGamepadTextInputMode { SingleLine = 0, MultipleLines = 1, Email = 2, Numeric = 3 } - export function showFloatingGamepadTextInput(keyboardMode: FloatingGamepadTextInputMode, x: number, y: number, width: number, height: number): boolean + /** @returns true if the floating keyboard was shown, otherwise, false */ + export function showFloatingGamepadTextInput(keyboardMode: FloatingGamepadTextInputMode, x: number, y: number, width: number, height: number): Promise } export namespace workshop { export interface UgcResult { diff --git a/src/api/utils.rs b/src/api/utils.rs index cc74361..1745353 100644 --- a/src/api/utils.rs +++ b/src/api/utils.rs @@ -6,6 +6,7 @@ pub mod utils { use steamworks::FloatingGamepadTextInputMode as kFloatingGamepadTextInputMode; use steamworks::GamepadTextInputLineMode as kGamepadTextInputLineMode; use steamworks::GamepadTextInputMode as kGamepadTextInputMode; + use tokio::sync::oneshot; #[napi] pub fn get_app_id() -> u32 { @@ -37,17 +38,21 @@ pub mod utils { MultipleLines, } + /// @returns the entered text, or null if cancelled or could not show the input #[napi] - pub fn show_gamepad_text_input( + pub async fn show_gamepad_text_input( input_mode: GamepadTextInputMode, input_line_mode: GamepadTextInputLineMode, description: String, max_characters: u32, existing_text: Option, - ) -> bool { + ) -> Option { let client = crate::client::get_client(); - let dismissed_cb = |_| {}; - client.utils().show_gamepad_text_input( + + let (tx, rx) = oneshot::channel(); + let mut tx = Some(tx); + + let opened = client.utils().show_gamepad_text_input( match input_mode { GamepadTextInputMode::Normal => kGamepadTextInputMode::Normal, GamepadTextInputMode::Password => kGamepadTextInputMode::Password, @@ -59,8 +64,21 @@ pub mod utils { &description, max_characters, existing_text.as_deref(), - dismissed_cb, - ) + move |dismissed_data| { + if let Some(tx) = tx.take() { + let text = client + .utils() + .get_entered_gamepad_text_input(&dismissed_data); + tx.send(text).unwrap(); + } + }, + ); + + if opened { + rx.await.unwrap() + } else { + None + } } #[napi] @@ -71,8 +89,9 @@ pub mod utils { Numeric, } + /// @returns true if the floating keyboard was shown, otherwise, false #[napi] - pub fn show_floating_gamepad_text_input( + pub async fn show_floating_gamepad_text_input( keyboard_mode: FloatingGamepadTextInputMode, x: i32, y: i32, @@ -80,8 +99,11 @@ pub mod utils { height: i32, ) -> bool { let client = crate::client::get_client(); - let dismissed_cb = || {}; - client.utils().show_floating_gamepad_text_input( + + let (tx, rx) = oneshot::channel(); + let mut tx = Some(tx); + + let opened = client.utils().show_floating_gamepad_text_input( match keyboard_mode { FloatingGamepadTextInputMode::SingleLine => { kFloatingGamepadTextInputMode::SingleLine @@ -96,7 +118,17 @@ pub mod utils { y, width, height, - dismissed_cb, - ) + move || { + if let Some(tx) = tx.take() { + tx.send(true).unwrap(); + } + }, + ); + + if opened { + rx.await.unwrap() + } else { + false + } } }