Skip to content

Commit

Permalink
Implement ShowFloatingGamepadTextInput API and FloatingGamepadTextInp…
Browse files Browse the repository at this point in the history
…utDismissed event. (#329)

Fixes #327
  • Loading branch information
hokein committed Jul 27, 2024
1 parent e47452b commit 5b22e2f
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 10 deletions.
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'src/api/steam_api_registry.h',
'src/api/steam_api_settings.cc',
'src/api/steam_api_stats.cc',
'src/api/steam_api_utils.cc',
'src/api/steam_api_workshop.cc',
'src/greenworks_api.cc',
'src/greenworks_async_workers.cc',
Expand Down
8 changes: 7 additions & 1 deletion docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,10 @@ Returns:

Posted after the user executes a steam url with command line or query parameters such as `steam://run/<appid>//?param1=value1;param2=value2;param3=value3;` while the game is already running. The new params can be queried with [GetLaunchCommandLine](https://partner.steamgames.com/doc/api/ISteamApps#GetLaunchCommandLine) and [GetLaunchQueryParam](https://partner.steamgames.com/doc/api/ISteamApps#GetLaunchQueryParam).

[Steam docs](https://partner.steamgames.com/doc/api/ISteamApps#NewUrlLaunchParameters_t)
[Steam docs](https://partner.steamgames.com/doc/api/ISteamApps#NewUrlLaunchParameters_t)

### Event: 'floating-gamepad-text-input-dismissed'

Emitted when the floating keyboard invoked from ShowFloatingGamepadTextInput has been closed.

[Steam docs](https://partner.steamgames.com/doc/api/ISteamUtils#FloatingGamepadTextInputDismissed_t)
21 changes: 21 additions & 0 deletions docs/utils.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
## Methods

### greenworks.FloatingGamepadTextInputMode

Represents Steam SDK `EFloatingGamepadTextInputMode`.

* `SingleLine`
* `MultipleLines`
* `Email`
* `Numeric`

### greenworks.showFloatingGamepadTextInput(keyboardMode, x, y, width, height)

* `keyboardMode` greenworks.FloatingGamepadTextInputMode
* `x` Integer
* `y` Integer
* `width` Integer
* `height` Integer

Opens a floating keyboard over the game content and sends OS keyboard keys directly to the game.

Returns `true` if the floating keyboard was shown, otherwise `false`.

### greenworks.Utils.move(source_dir, target_dir, [success_callback], [error_callback])

* `source_dir` String
Expand Down
55 changes: 55 additions & 0 deletions src/api/steam_api_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2024 Greenheart Games Pty. Ltd. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "nan.h"
#include "v8.h"

#include "steam/steam_api.h"

#include "steam_api_registry.h"

namespace greenworks {
namespace api {
namespace {

void InitFloatingGamepadTextInputMode(v8::Local<v8::Object> exports) {
v8::Local<v8::Object> mode = Nan::New<v8::Object>();
SET_TYPE(mode, "SingleLine", k_EFloatingGamepadTextInputModeModeSingleLine);
SET_TYPE(mode, "MultipleLines", k_EFloatingGamepadTextInputModeModeMultipleLines);
SET_TYPE(mode, "Email",
k_EFloatingGamepadTextInputModeModeEmail);
SET_TYPE(mode, "Numeric", k_EFloatingGamepadTextInputModeModeNumeric);
Nan::Persistent<v8::Object> constructor;
constructor.Reset(mode);
Nan::Set(exports,
Nan::New("FloatingGamepadTextInputMode").ToLocalChecked(),
mode);
}

NAN_METHOD(ShowFloatingGamepadTextInput) {
Nan::HandleScope scope;
if (info.Length() < 5 || !info[0]->IsInt32() || !info[1]->IsInt32() ||
!info[2]->IsInt32() || !info[3]->IsInt32() || !info[4]->IsString()) {
THROW_BAD_ARGS("Bad arguments");
}

EFloatingGamepadTextInputMode input_mode =
static_cast<EFloatingGamepadTextInputMode>(
Nan::To<int32>(info[0]).FromJust());
info.GetReturnValue().Set(SteamUtils()->ShowFloatingGamepadTextInput(
input_mode, Nan::To<int32>(info[1]).FromJust(),
Nan::To<int32>(info[2]).FromJust(), Nan::To<int32>(info[3]).FromJust(),
Nan::To<int32>(info[4]).FromJust()));
}

void RegisterAPIs(v8::Local<v8::Object> target) {
InitFloatingGamepadTextInputMode(target);
SET_FUNCTION("showFloatingGamepadTextInput", ShowFloatingGamepadTextInput);
}

SteamAPIRegistry::Add X(RegisterAPIs);

} // namespace
} // namespace api
} // namespace greenworks
21 changes: 15 additions & 6 deletions src/steam_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>

#include "nan.h"
#include "steam/isteamutils.h"

namespace greenworks {

Expand Down Expand Up @@ -41,19 +42,20 @@ SteamClient::SteamClient()
steam_persona_state_change_(this, &SteamClient::OnPeronaStateChange),
avatar_image_loaded_(this, &SteamClient::OnAvatarImageLoaded),
game_connected_friend_chat_msg_(
this,
&SteamClient::OnGameConnectedFriendChatMessage),
this, &SteamClient::OnGameConnectedFriendChatMessage),
dlc_installed_(this, &SteamClient::OnDLCInstalled),
MicroTxnAuthorizationResponse_(
this,
&SteamClient::OnMicroTxnAuthorizationResponse),
this, &SteamClient::OnMicroTxnAuthorizationResponse),
OnLobbyCreated_(this, &SteamClient::OnLobbyCreated),
OnLobbyDataUpdate_(this, &SteamClient::OnLobbyDataUpdate),
OnLobbyEnter_(this, &SteamClient::OnLobbyEnter),
OnLobbyInvite_(this, &SteamClient::OnLobbyInvite),
OnGameLobbyJoinRequested_(this, &SteamClient::OnGameLobbyJoinRequested),
OnGameRichPresenceJoinRequested_(this, &SteamClient::OnGameRichPresenceJoinRequested),
OnNewUrlLaunchParameters_(this, &SteamClient::OnNewUrlLaunchParameters) {}
OnGameRichPresenceJoinRequested_(
this, &SteamClient::OnGameRichPresenceJoinRequested),
OnNewUrlLaunchParameters_(this, &SteamClient::OnNewUrlLaunchParameters),
OnFloatingGamepadTextInputDismissed_(
this, &SteamClient::OnFloatingGamepadTextInputDismissed) {}

SteamClient::~SteamClient() {
for (size_t i = 0; i < observer_list_.size(); ++i) {
Expand Down Expand Up @@ -204,6 +206,13 @@ void SteamClient::OnNewUrlLaunchParameters(NewUrlLaunchParameters_t *callback) {
}
}

void SteamClient::OnFloatingGamepadTextInputDismissed(
FloatingGamepadTextInputDismissed_t *callback) {
for (size_t i = 0; i < observer_list_.size(); ++i) {
observer_list_[i]->OnFloatingGamepadTextInputDismissed();
}
}

void SteamClient::StartSteamLoop() {
if (g_steam_timer)
return;
Expand Down
14 changes: 11 additions & 3 deletions src/steam_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SteamClient {
virtual void OnGameLobbyJoinRequested(uint64 SteamIdLobby, uint64 SteamIdUser) = 0;
virtual void OnGameRichPresenceJoinRequested(uint64 steamIDFriend, std::string rgchConnect) = 0;
virtual void OnNewUrlLaunchParameters() = 0;
virtual void OnFloatingGamepadTextInputDismissed() = 0;
virtual ~Observer() {}
};

Expand Down Expand Up @@ -90,9 +91,16 @@ class SteamClient {
STEAM_CALLBACK(SteamClient, OnLobbyDataUpdate, LobbyDataUpdate_t, OnLobbyDataUpdate_);
STEAM_CALLBACK(SteamClient, OnLobbyEnter, LobbyEnter_t, OnLobbyEnter_);
STEAM_CALLBACK(SteamClient, OnLobbyInvite, LobbyInvite_t, OnLobbyInvite_);
STEAM_CALLBACK(SteamClient, OnGameLobbyJoinRequested, GameLobbyJoinRequested_t, OnGameLobbyJoinRequested_);
STEAM_CALLBACK(SteamClient, OnGameRichPresenceJoinRequested, GameRichPresenceJoinRequested_t, OnGameRichPresenceJoinRequested_);
STEAM_CALLBACK(SteamClient, OnNewUrlLaunchParameters, NewUrlLaunchParameters_t, OnNewUrlLaunchParameters_);
STEAM_CALLBACK(SteamClient, OnGameLobbyJoinRequested,
GameLobbyJoinRequested_t, OnGameLobbyJoinRequested_);
STEAM_CALLBACK(SteamClient, OnGameRichPresenceJoinRequested,
GameRichPresenceJoinRequested_t,
OnGameRichPresenceJoinRequested_);
STEAM_CALLBACK(SteamClient, OnNewUrlLaunchParameters,
NewUrlLaunchParameters_t, OnNewUrlLaunchParameters_);
STEAM_CALLBACK(SteamClient, OnFloatingGamepadTextInputDismissed,
FloatingGamepadTextInputDismissed_t,
OnFloatingGamepadTextInputDismissed_);
};

} // namespace greenworks
Expand Down
9 changes: 9 additions & 0 deletions src/steam_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,13 @@ void SteamEvent::OnNewUrlLaunchParameters() {
Nan::New(persistent_steam_events_), "on", 1, argv);
}

void SteamEvent::OnFloatingGamepadTextInputDismissed() {
Nan::HandleScope scope;
v8::Local<v8::Value> argv[] = {
Nan::New("floating-gamepad-text-input-dismissed").ToLocalChecked()};
Nan::AsyncResource ar(
"greenworks:SteamEvent.OnFloatingGamepadTextInputDismissed");
ar.runInAsyncScope(Nan::New(persistent_steam_events_), "on", 1, argv);
}

} // namespace greenworks
1 change: 1 addition & 0 deletions src/steam_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SteamEvent : public greenworks::SteamClient::Observer {
void OnGameRichPresenceJoinRequested(uint64 steamIDFriend,
std::string rgchConnect) override;
void OnNewUrlLaunchParameters() override;
void OnFloatingGamepadTextInputDismissed() override;

private:
const Nan::Persistent<v8::Object>& persistent_steam_events_;
Expand Down

0 comments on commit 5b22e2f

Please sign in to comment.