f648cb1fd8
* Update the FileIOAlias naming to make the cache, project root and engine root paths more clear The alias of `@root@`, `@assets@`, and `@projectplatformcache@` has been collapsed to `@projectproductassets@` The alias of `@devroot@` and `@engroot@` has been collapsed to `@engroot@` The alias of `@devassets@` and `@projectroot@` has been collapsed to `@projectroot@` Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated use of devassets and devroot properties in python Those properties now use projectroot and engroot Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updating the alias @engroot@ alias path comment in each platform specific LocalFileIO_*.cpp file Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed hardcoded size of 9 for the product asset alias. The ResolvePath function now just appends the @projectproductassets@ alias with the input path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove duplicate @projectproductassets@ check in ProcessFileTreeRequest Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix for typos in Hydra python test Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated LocalFileIO::Copy call on Windows to use the Unicode aware CopyFileW API Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the AWSMetreicsGemAllocatorFixture to properly suppress asset cache write errors for Test file creation. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unneeded call to set the @projectproductasstes@ alias at the bottom of the AssetSeedManagerTest SetUp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added a deprecated alias map to the FileIO System When a deprecated alias is accessed, the FileIO System logs an AZ_Error and indicates the alias that should be used Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated python test scripts to use the projectroot binding Retrieving the AutomatedTesting project path based on "<devroot>/AutomatedTesting" has been removed. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated references to devroot and devgame within the codebase The GetAbsoluteDevGameFolderPath functions has been replaced with direct call to AZ::Utils::GetProjectPath The GetAbsoluteDevRootFolderPath functions has been replaced with direct calls to AZ::Utils::GetEnginePath Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated <engroot>/AutomatedTesting references to projectroot Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced references that assumes the project path is <engroot>/AutomatedTesting with <projectroot> in the AutomatedTesting python test Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Correct casing in emfxworkspace file Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed newly added AppendPathParts function Removed the Path constructors which accepts a PathIterable instance The PathIterable isn't safe to return to a user of the Path class as it might be referencing temporary paths supplied via PathView arguments Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed unused parameter warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Undid change to the LexicallyProximate function to set the path result to the base path. It needs to return the *this path if the pathResult is empty Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Moved the LocalFileIO ConvertToAbsolutePath implementations to AZ::Utils Fixed the ConvertToAbsolutePath implementation for Unix platforms to use a buffer that is size PATH_MAX(4096 on all our supported Unix platforms). Because the buffer before was AZ::IO::MaxPathLength which as a size of 1024, this was resulting in the Unix `realpath` function smashing the stack when it converts a path to an absolute path that is longer than 1024 characters Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the EditorCore.Tests to attach the AZ Environment to the EditorCore shared library that is statically loaded on launch. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed for DeprecatedAlaisesKeyVisitor Visit function causing the non string_view overloads being hidden causing a hidden base class function warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Changed the AWSMetricsGemMock to use a temporary for writing test assets Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the LocalFileIO::ResolvePath function to use HasRootPath to determine if a path starts with a root path such as "D:", "D:/" or "/" IsAbsolute was not the corect check as the path of "D:" is a relative path. To be absolute according to the Windows the path must have a root directory. i.e "D:/" or "D:\" Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed absolute path comment from LocalFile_UnixLike.cpp and LocalFile_Android.cpp FindFiles implementations Updated the ConvertToAlias to supply an AZ::IO::FixedMaxPath Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced usage of the @projectproductassets@ alias with @engroot@ when referring to the LmbrCentral source folder in the CopyDependencyBuilderTest and the SeedBuilderTests Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the ScriptCanvas Upgrade Tool to output backed up files to the Project User Path instead of the engine root Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed whitespacing issues in Application.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Remove unnecessary creation of a FixedMaxPath in the UpgradeTool.cpp Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Modified testSeedFolder variable in the SeedBuilderTests to use the @engroot@ alias instead of @projectproductassets@/.. alias when referring to the LmbrCentral Gem source path Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated references to the Project Asset Cache in the PythonTests. Those tests no longer use the logic `azlmbr.paths.projectroot / "Cache" / "pc"` to retrieve a path to the cache root but instead the `azlmbr.paths.projectproductassets` constant Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed the FileIO Deprecated Alias test on Windows Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removing @projectsourceassets@ alias, as it is only used once. Updated the PhysX EditorSystemComponent.cpp to query the ProjectPath form the SettingsRegistry. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced @projectproductassets@ alias with @products@ Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Rollback changes to the PhysX EditorSystemComponent.cpp The changes to use the ProjectPath from the SettingsRegistry has been implemented in PR #4497 Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
516 lines
26 KiB
C++
516 lines
26 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <GameState/GameStateRequestBus.h>
|
|
#include <GameStateSamples/GameStateLocalUserLobby.h>
|
|
|
|
#include <LyShine/Bus/UiCanvasBus.h>
|
|
#include <LyShine/Bus/UiCanvasManagerBus.h>
|
|
#include <LyShine/Bus/UiElementBus.h>
|
|
#include <LyShine/Bus/UiTextBus.h>
|
|
|
|
#include <LocalUser/LocalUserRequestBus.h>
|
|
|
|
#include <AzFramework/Input/Buses/Requests/InputDeviceRequestBus.h>
|
|
#include <AzFramework/Input/Buses/Requests/InputLightBarRequestBus.h>
|
|
#include <AzFramework/Input/Devices/Gamepad/InputDeviceGamepad.h>
|
|
#include <AzFramework/Input/Utils/IsAnyKeyOrButton.h>
|
|
|
|
#include <AzCore/std/sort.h>
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
namespace GameStateSamples
|
|
{
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnPushed()
|
|
{
|
|
// We could load the UI canvas here and keep it cached until OnPopped is called in order to
|
|
// speed up re-entering this game state, but doing so would consume memory for the lifetime
|
|
// of the process that is only needed while this state is active (which is not very often).
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnPopped()
|
|
{
|
|
// See comment above in OnPushed
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnEnter()
|
|
{
|
|
AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect();
|
|
AzFramework::InputDeviceNotificationBus::Handler::BusConnect();
|
|
LocalUser::LocalUserNotificationBus::Handler::BusConnect();
|
|
InputChannelEventListener::Connect();
|
|
RefreshLocalPlayerSlotAssignments();
|
|
LoadSignedInUserOverlayCanvas();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnExit()
|
|
{
|
|
UnloadSignedInUserOverlayCanvas();
|
|
InputChannelEventListener::Disconnect();
|
|
LocalUser::LocalUserNotificationBus::Handler::BusDisconnect();
|
|
AzFramework::InputDeviceNotificationBus::Handler::BusDisconnect();
|
|
AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnUpdate()
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline AZ::s32 GameStateLocalUserLobby::GetPriority() const
|
|
{
|
|
return AzFramework::InputChannelEventListener::GetPriorityFirst();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline bool GameStateLocalUserLobby::OnInputChannelEventFiltered(const AzFramework::InputChannel & inputChannel)
|
|
{
|
|
if (inputChannel.IsStateBegan() && AzFramework::IsAnyKeyOrButton(inputChannel))
|
|
{
|
|
const AzFramework::LocalUserId localUserId = inputChannel.GetInputDevice().GetAssignedLocalUserId();
|
|
if (localUserId == AzFramework::LocalUserIdAny ||
|
|
localUserId == AzFramework::LocalUserIdNone)
|
|
{
|
|
// No local user is associated with this input device yet, so prompt for user sign-in
|
|
inputChannel.GetInputDevice().PromptLocalUserSignIn();
|
|
}
|
|
else
|
|
{
|
|
// Assign the local user to the first available slot (if they haven't already been assigned one)
|
|
AZ::u32 assignedSlot = LocalUser::LocalPlayerSlotNone;
|
|
LocalUser::LocalUserRequestBus::BroadcastResult(assignedSlot,
|
|
&LocalUser::LocalUserRequests::GetLocalPlayerSlotOccupiedByLocalUserId,
|
|
localUserId);
|
|
if (assignedSlot == LocalUser::LocalPlayerSlotNone)
|
|
{
|
|
// This call to AssignLocalUserIdToLocalPlayerSlot will trigger another to
|
|
// OnLocalUserIdAssignedToLocalPlayerSlot, which is where we update the UI.
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::AssignLocalUserIdToLocalPlayerSlot,
|
|
localUserId,
|
|
LocalUser::LocalPlayerSlotAny);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Don't consume the input
|
|
return false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnInputDeviceConnectedEvent(const AzFramework::InputDevice& inputDevice)
|
|
{
|
|
const AzFramework::LocalUserId localUserId = inputDevice.GetAssignedLocalUserId();
|
|
const AzFramework::LocalUserId primaryLocalUserId = LocalUser::LocalUserRequests::GetPrimaryLocalUserId();
|
|
if (localUserId == AzFramework::LocalUserIdNone ||
|
|
localUserId == primaryLocalUserId)
|
|
{
|
|
// The connected controller does not belong to any user, or it belongs to the primary
|
|
// user which is handled in GameStatePrimaryControllerDisconnected
|
|
return;
|
|
}
|
|
|
|
// A secondary controller was connected, so assign the associated local
|
|
// user id to a free local player slot. Note that we only do this while
|
|
// in GameStateLocalUserLobby, not during gameplay, as we do not want to
|
|
// assign a local user id to a local player slot mid-game. To account
|
|
// for the case where a controller/user connects during gameplay (and
|
|
// does not disconnect by the time we return to the main menu) we call
|
|
// RefreshLocalPlayerSlotAssignments from GameStateLocalUserLobby::OnEnter.
|
|
//
|
|
// This call to AssignLocalUserIdToLocalPlayerSlot will trigger another to
|
|
// OnLocalUserIdAssignedToLocalPlayerSlot, which is where we update the UI.
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::AssignLocalUserIdToLocalPlayerSlot,
|
|
localUserId,
|
|
LocalUser::LocalPlayerSlotAny);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnInputDeviceDisconnectedEvent(const AzFramework::InputDevice& inputDevice)
|
|
{
|
|
const AzFramework::LocalUserId localUserId = inputDevice.GetAssignedLocalUserId();
|
|
const AzFramework::LocalUserId primaryLocalUserId = LocalUser::LocalUserRequests::GetPrimaryLocalUserId();
|
|
if (localUserId == AzFramework::LocalUserIdNone ||
|
|
localUserId == primaryLocalUserId)
|
|
{
|
|
// The disconnected controller does not belong to any user, or it belongs to the primary
|
|
// user which is handled in GameStatePrimaryUserMonitor::OnInputDeviceDisconnectedEvent
|
|
return;
|
|
}
|
|
|
|
// A secondary controller was disconnected, so remove the associated local
|
|
// user id from their local player slot. Note that we only do this while in
|
|
// GameStateLocalUserLobby, not during gameplay, as we don't want to remove a
|
|
// local user id from a local player slot mid-game. To account for the case
|
|
// where a user disconnects during gameplay (and does not re-connect by the
|
|
// time we exit to the main menu) we call RefreshLocalPlayerSlotAssignments
|
|
// from GameStateLocalUserLobby::OnEnter
|
|
//
|
|
// This call to RemoveLocalUserIdFromLocalPlayerSlot will trigger another to
|
|
// OnLocalUserIdRemovedFromLocalPlayerSlot, which is where we update the UI.
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::RemoveLocalUserIdFromLocalPlayerSlot,
|
|
localUserId);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnApplicationUnconstrained(AzFramework::ApplicationLifecycleEvents::Event /*lastEvent*/)
|
|
{
|
|
RefreshLocalPlayerSlotAssignments();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnLocalUserIdAssignedToLocalPlayerSlot(AzFramework::LocalUserId localUserId,
|
|
AZ::u32 newLocalPlayerSlot,
|
|
AZ::u32 previousLocalPlayerSlot)
|
|
{
|
|
RefreshSignedInUserOverlay(newLocalPlayerSlot);
|
|
RefreshSignedInUserOverlay(previousLocalPlayerSlot);
|
|
RefreshGamepadLightBarColor(localUserId, newLocalPlayerSlot);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::OnLocalUserIdRemovedFromLocalPlayerSlot(AzFramework::LocalUserId localUserId,
|
|
AZ::u32 localPlayerSlot)
|
|
{
|
|
RefreshSignedInUserOverlay(localPlayerSlot);
|
|
RefreshGamepadLightBarColor(localUserId, LocalUser::LocalPlayerSlotNone);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::LoadSignedInUserOverlayCanvas()
|
|
{
|
|
// Load the UI canvas
|
|
const char* uiCanvasAssetPath = GetSignedInUserOverlayCanvasAssetPath();
|
|
UiCanvasManagerBus::BroadcastResult(m_signedInUsersOverlayCanvasEntityId,
|
|
&UiCanvasManagerInterface::LoadCanvas,
|
|
uiCanvasAssetPath);
|
|
if (!m_signedInUsersOverlayCanvasEntityId.IsValid())
|
|
{
|
|
AZ_Warning("GameStateLocalUserLobby", false, "Could not load %s", uiCanvasAssetPath);
|
|
return;
|
|
}
|
|
|
|
// Display the overlay, set it to draw over the top of the main menu,
|
|
// and set it to stay loaded when a level unloads
|
|
UiCanvasBus::Event(m_signedInUsersOverlayCanvasEntityId, &UiCanvasInterface::SetEnabled, true);
|
|
UiCanvasBus::Event(m_signedInUsersOverlayCanvasEntityId, &UiCanvasInterface::SetDrawOrder, 10);
|
|
UiCanvasBus::Event(m_signedInUsersOverlayCanvasEntityId, &UiCanvasInterface::SetKeepLoadedOnLevelUnload, true);
|
|
|
|
RefreshAllSignedInUserOverlays();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::UnloadSignedInUserOverlayCanvas()
|
|
{
|
|
if (m_signedInUsersOverlayCanvasEntityId.IsValid())
|
|
{
|
|
// Unload the overlay
|
|
UiCanvasManagerBus::Broadcast(&UiCanvasManagerInterface::UnloadCanvas,
|
|
m_signedInUsersOverlayCanvasEntityId);
|
|
m_signedInUsersOverlayCanvasEntityId.SetInvalid();
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline const char* GameStateLocalUserLobby::GetSignedInUserOverlayCanvasAssetPath()
|
|
{
|
|
return "@products@/ui/canvases/defaultsignedinusersoverlay.uicanvas";
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::RefreshLocalPlayerSlotAssignments()
|
|
{
|
|
// Check whether local users that have been assigned to a local player slot
|
|
// are still signed in and associated with a connected input device. If not,
|
|
// remove them from the local player slot so that it becomes free for other
|
|
// players to join. Note that we ignore the primary user here, as that is a
|
|
// speacial case we handle at all times in LyPlatformServicesSystemComponent
|
|
for (AZ::u32 i = LocalUser::LocalPlayerSlotPrimary + 1; i < LocalUser::LocalPlayerSlotMax; ++i)
|
|
{
|
|
const AzFramework::LocalUserId localUserId = LocalUser::LocalUserRequests::GetLocalUserIdAt(i);
|
|
if (localUserId == AzFramework::LocalUserIdNone)
|
|
{
|
|
// No local user assigned to this slot
|
|
continue;
|
|
}
|
|
|
|
const bool isLocalUserSignedIn = IsLocalUserSignedIn(localUserId);
|
|
if (!isLocalUserSignedIn)
|
|
{
|
|
// The local user is no longer signed in, remove them from their local player slot
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::RemoveLocalUserIdFromLocalPlayerSlot,
|
|
localUserId);
|
|
continue;
|
|
}
|
|
|
|
const bool isAssignedToConnectedInputDevice = IsLocalUserAssociatedWithConnectedInputDevice(localUserId);
|
|
if (!isAssignedToConnectedInputDevice)
|
|
{
|
|
// The local user is no longer associated with a connected input device, remove them from their local player slot
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::RemoveLocalUserIdFromLocalPlayerSlot,
|
|
localUserId);
|
|
continue;
|
|
}
|
|
|
|
// The local user is still signed in and associated with a connected input device
|
|
}
|
|
|
|
// Get all connected controllers...
|
|
AZStd::vector<const AzFramework::InputDevice*> gamepadInputDevices;
|
|
AzFramework::InputDeviceRequests::InputDeviceByIdMap inputDevicesById;
|
|
AzFramework::InputDeviceRequestBus::Broadcast(&AzFramework::InputDeviceRequests::GetInputDevicesById,
|
|
inputDevicesById);
|
|
for (const auto& inputDeviceById : inputDevicesById)
|
|
{
|
|
const AzFramework::InputDevice* inputDevice = inputDeviceById.second;
|
|
if (inputDevice &&
|
|
inputDevice->IsConnected() &&
|
|
AzFramework::InputDeviceGamepad::IsGamepadDevice(inputDeviceById.first))
|
|
{
|
|
// The input device is a connected gamepad
|
|
gamepadInputDevices.push_back(inputDevice);
|
|
}
|
|
}
|
|
|
|
// ...sort them by index and then go through to check whether they have been
|
|
// assigned a local user id. If so, auto-assign their local user id into the
|
|
// first available local player slot (unless they've already been assigned).
|
|
AZStd::sort(gamepadInputDevices.begin(), gamepadInputDevices.end(),
|
|
[](const AzFramework::InputDevice* lhs, const AzFramework::InputDevice* rhs)
|
|
{
|
|
return lhs->GetInputDeviceId() < rhs->GetInputDeviceId();
|
|
});
|
|
for (const AzFramework::InputDevice* gamepadDevice : gamepadInputDevices)
|
|
{
|
|
const AzFramework::LocalUserId localUserId = gamepadDevice->GetAssignedLocalUserId();
|
|
if (localUserId == AzFramework::LocalUserIdAny ||
|
|
localUserId == AzFramework::LocalUserIdNone ||
|
|
!IsLocalUserSignedIn(localUserId))
|
|
{
|
|
// The input device has no associated local user id,
|
|
// or is associated with a user that's not signed in.
|
|
continue;
|
|
}
|
|
|
|
// Assign the local user id to a local player slot.
|
|
// If it is already assigned this will do nothing.
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::AssignLocalUserIdToLocalPlayerSlot,
|
|
localUserId,
|
|
LocalUser::LocalPlayerSlotAny);
|
|
}
|
|
|
|
// Lastly, iterate over all the local player slots again and 'collapse' them
|
|
// so that we aren't left with any gaps. For example, if after all the above
|
|
// we are left with user A in local player slot 0 and user B in local player
|
|
// slot 3, the following will result in user B being moved down into slot 1.
|
|
// Note again that we ignore the primary user here, which is a speacial case
|
|
// handled in LyPlatformServicesSystemComponent so that it'll never be empty.
|
|
for (AZ::u32 i = LocalUser::LocalPlayerSlotPrimary + 1; i < LocalUser::LocalPlayerSlotMax; ++i)
|
|
{
|
|
AzFramework::LocalUserId localUserId = LocalUser::LocalUserRequests::GetLocalUserIdAt(i);
|
|
if (localUserId == AzFramework::LocalUserIdNone)
|
|
{
|
|
// No local user assigned to this slot, look for the next occupied slot...
|
|
AZ::u32 j = i + 1;
|
|
for (; j < LocalUser::LocalPlayerSlotMax; ++j)
|
|
{
|
|
localUserId = LocalUser::LocalUserRequests::GetLocalUserIdAt(j);
|
|
if (localUserId != AzFramework::LocalUserIdNone)
|
|
{
|
|
// ...and move that local user down into the unnocupied slot.
|
|
LocalUser::LocalUserRequestBus::Broadcast(&LocalUser::LocalUserRequests::AssignLocalUserIdToLocalPlayerSlot,
|
|
localUserId,
|
|
i);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (j == LocalUser::LocalPlayerSlotMax)
|
|
{
|
|
// There are no more occupied slots, no need to continue.
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// After all this, refresh the gamepad light bar colors (if they exist)
|
|
RefreshAllGamepadLightBarColors();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline bool GameStateLocalUserLobby::IsLocalUserSignedIn(AzFramework::LocalUserId localUserId) const
|
|
{
|
|
bool isLocalUserSignedIn = false;
|
|
LocalUser::LocalUserRequestBus::BroadcastResult(isLocalUserSignedIn,
|
|
&LocalUser::LocalUserRequests::IsLocalUserSignedIn,
|
|
localUserId);
|
|
return isLocalUserSignedIn;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline bool GameStateLocalUserLobby::IsLocalUserAssociatedWithConnectedInputDevice(AzFramework::LocalUserId localUserId) const
|
|
{
|
|
AzFramework::InputDeviceRequests::InputDeviceByIdMap inputDevicesById;
|
|
AzFramework::InputDeviceRequestBus::Broadcast(&AzFramework::InputDeviceRequests::GetInputDevicesByIdWithAssignedLocalUserId,
|
|
inputDevicesById,
|
|
localUserId);
|
|
for (const auto& inputDeviceById : inputDevicesById)
|
|
{
|
|
if (inputDeviceById.second && inputDeviceById.second->IsConnected())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::RefreshAllGamepadLightBarColors()
|
|
{
|
|
AzFramework::InputDeviceRequests::InputDeviceByIdMap inputDevicesById;
|
|
AzFramework::InputDeviceRequestBus::Broadcast(&AzFramework::InputDeviceRequests::GetInputDevicesById,
|
|
inputDevicesById);
|
|
for (const auto& inputDeviceById : inputDevicesById)
|
|
{
|
|
const AzFramework::InputDevice* inputDevice = inputDeviceById.second;
|
|
if (inputDevice && AzFramework::InputDeviceGamepad::IsGamepadDevice(inputDeviceById.first))
|
|
{
|
|
AZ::u32 localPlayerSlot = LocalUser::LocalPlayerSlotNone;
|
|
LocalUser::LocalUserRequestBus::BroadcastResult(localPlayerSlot,
|
|
&LocalUser::LocalUserRequests::GetLocalPlayerSlotOccupiedByLocalUserId,
|
|
inputDevice->GetAssignedLocalUserId());
|
|
RefreshGamepadLightBarColor(inputDeviceById.first, localPlayerSlot);
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::RefreshGamepadLightBarColor(AzFramework::LocalUserId localUserId,
|
|
AZ::u32 localPlayerSlot)
|
|
{
|
|
AzFramework::InputDeviceRequests::InputDeviceByIdMap inputDevicesById;
|
|
AzFramework::InputDeviceRequestBus::Broadcast(&AzFramework::InputDeviceRequests::GetInputDevicesByIdWithAssignedLocalUserId,
|
|
inputDevicesById,
|
|
localUserId);
|
|
for (const auto& inputDeviceById : inputDevicesById)
|
|
{
|
|
if (inputDeviceById.second && AzFramework::InputDeviceGamepad::IsGamepadDevice(inputDeviceById.first))
|
|
{
|
|
RefreshGamepadLightBarColor(inputDeviceById.first, localPlayerSlot);
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::RefreshGamepadLightBarColor(const AzFramework::InputDeviceId& inputDeviceId,
|
|
AZ::u32 localPlayerSlot)
|
|
{
|
|
// Colors with a low saturation (< 75%) tend to get washed out and look mostly white.
|
|
static const AZ::Color s_gamepadLightBarColorsByLocalPlayerSlot[LocalUser::LocalPlayerSlotMax]
|
|
{
|
|
AZ::Color((AZ::u8)0, (AZ::u8)0, (AZ::u8)255, (AZ::u8)255), // Blue
|
|
AZ::Color((AZ::u8)255, (AZ::u8)0, (AZ::u8)0, (AZ::u8)255), // Red
|
|
AZ::Color((AZ::u8)0, (AZ::u8)255, (AZ::u8)0, (AZ::u8)255), // Green
|
|
#if defined(AZ_PLATFORM_PROVO)
|
|
AZ::Color((AZ::u8)255, (AZ::u8)0, (AZ::u8)127, (AZ::u8)255)// Pink
|
|
#else
|
|
AZ::Color((AZ::u8)127, (AZ::u8)255, (AZ::u8)0, (AZ::u8)255)// Yellow
|
|
#endif
|
|
};
|
|
static const AZ::Color s_gamepadLightBarColorNoLocalPlayerSlot = AZ::Color::CreateOne(); // White
|
|
|
|
const AZ::Color& lightBarColor = localPlayerSlot < LocalUser::LocalPlayerSlotMax ?
|
|
s_gamepadLightBarColorsByLocalPlayerSlot[localPlayerSlot] :
|
|
s_gamepadLightBarColorNoLocalPlayerSlot;
|
|
AzFramework::InputLightBarRequestBus::Event(inputDeviceId,
|
|
&AzFramework::InputLightBarRequests::SetLightBarColor,
|
|
lightBarColor);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::RefreshAllSignedInUserOverlays()
|
|
{
|
|
for (AZ::u32 localPlayerSlot = 0; localPlayerSlot < LocalUser::LocalPlayerSlotMax; ++localPlayerSlot)
|
|
{
|
|
RefreshSignedInUserOverlay(localPlayerSlot);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::RefreshSignedInUserOverlay(AZ::u32 localPlayerSlot)
|
|
{
|
|
if (!m_signedInUsersOverlayCanvasEntityId.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
const AzFramework::LocalUserId localUserId = LocalUser::LocalUserRequests::GetLocalUserIdAt(localPlayerSlot);
|
|
if (localUserId == AzFramework::LocalUserIdNone)
|
|
{
|
|
SetSignedInUserOverlayEnabled(localPlayerSlot, false);
|
|
return;
|
|
}
|
|
|
|
const bool isLocalUserSignedIn = IsLocalUserSignedIn(localUserId);
|
|
if (!isLocalUserSignedIn)
|
|
{
|
|
SetSignedInUserOverlayEnabled(localPlayerSlot, false);
|
|
return;
|
|
}
|
|
|
|
AZStd::string localUserName;
|
|
LocalUser::LocalUserRequestBus::BroadcastResult(localUserName,
|
|
&LocalUser::LocalUserRequests::GetLocalUserName,
|
|
localUserId);
|
|
SetSignedInUserOverlayEnabled(localPlayerSlot, true);
|
|
SetSignedInUserOverlayNameText(localPlayerSlot, localUserName);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::SetSignedInUserOverlayEnabled(AZ::u32 localPlayerSlot,
|
|
bool enabled)
|
|
{
|
|
AZ::EntityId userElementName = GetUiElementIdForLocalPlayerSlot("User", localPlayerSlot);
|
|
if (userElementName.IsValid())
|
|
{
|
|
UiElementBus::Event(userElementName, &UiElementInterface::SetIsEnabled, enabled);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline void GameStateLocalUserLobby::SetSignedInUserOverlayNameText(AZ::u32 localPlayerSlot,
|
|
const AZStd::string& localUserName)
|
|
{
|
|
AZ::EntityId userNameTextElementName = GetUiElementIdForLocalPlayerSlot("UserName", localPlayerSlot);
|
|
if (userNameTextElementName.IsValid())
|
|
{
|
|
UiTextBus::Event(userNameTextElementName, &UiTextInterface::SetText, localUserName);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
inline AZ::EntityId GameStateLocalUserLobby::GetUiElementIdForLocalPlayerSlot(const char* elementName,
|
|
AZ::u32 localPlayerSlot) const
|
|
{
|
|
char elementNameForSlot[16];
|
|
azsnprintf(elementNameForSlot, 16, "%s%d", elementName, localPlayerSlot);
|
|
|
|
AZ::EntityId elementId;
|
|
UiCanvasBus::EventResult(elementId,
|
|
m_signedInUsersOverlayCanvasEntityId,
|
|
&UiCanvasInterface::FindElementEntityIdByName,
|
|
elementNameForSlot);
|
|
return elementId;
|
|
}
|
|
}
|