Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Adding UMG version of Mixer login pane
Browse files Browse the repository at this point in the history
  • Loading branch information
jsyarrow committed Jul 25, 2017
1 parent 45a04eb commit 0dbea1c
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Source/MixerInteractivity/Private/MixerLoginPane.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

#include "MixerLoginPane.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/PlayerState.h"
#include "Engine/World.h"
#include "STextBlock.h"
#include "SBox.h"

void UMixerLoginPane::SynchronizeProperties()
{
Super::SynchronizeProperties();
}

void UMixerLoginPane::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);

MyLoginPane.Reset();
}

#if WITH_EDITOR
const FText UMixerLoginPane::GetPaletteCategory()
{
return NSLOCTEXT("MixerInteractivity", "Mixer", "Mixer");
}
#endif

TSharedRef<SWidget> UMixerLoginPane::RebuildWidget()
{
if (!IsDesignTime())
{
MyLoginPane = SNew(SMixerLoginPane)
.UserId_UObject(this, &UMixerLoginPane::SlateGetUserId)
.OnAuthCodeReady_UObject(this, &UMixerLoginPane::SlateHandleAuthCodeReady)
.OnUIFlowFinished_UObject(this, &UMixerLoginPane::SlateHandleUIFlowFinished)
.AllowSilentLogin(AllowSilentLogin)
.BackgroundColor(BackgroundColor);
}
else
{
MyLoginPane = SNew(SBox)
.WidthOverride(350.0f)
.HeightOverride(500.0f)
.HAlign(EHorizontalAlignment::HAlign_Center)
.VAlign(EVerticalAlignment::VAlign_Center)
[
SNew(STextBlock)
.Text(NSLOCTEXT("MixerInteractivity", "Mixer_Login_Pane", "Mixer Login Pane"))
];
}

return MyLoginPane.ToSharedRef();
}

FReply UMixerLoginPane::SlateHandleAuthCodeReady(const FString& AuthCode)
{
OnAuthCodeReady.Broadcast(AuthCode);

// Report unhandled so that Slate widget will continue with login process.
return FReply::Unhandled();
}

void UMixerLoginPane::SlateHandleUIFlowFinished(bool bSucceeded)
{
OnUIFlowFinished.Broadcast(bSucceeded);
}

TSharedPtr<const FUniqueNetId> UMixerLoginPane::SlateGetUserId() const
{
TSharedPtr<const FUniqueNetId> NetId = nullptr;
APlayerController* OwningController = GetOwningPlayer();
if (OwningController != nullptr)
{
APlayerState* PlayerState = OwningController->PlayerState;
if (PlayerState)
{
NetId = PlayerState->UniqueId.GetUniqueNetId();
}
}
return NetId;
}
74 changes: 74 additions & 0 deletions Source/MixerInteractivity/Public/MixerLoginPane.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

#pragma once

#include "SMixerLoginPane.h"
#include "Components/Widget.h"
#include "MixerLoginPane.generated.h"

class APlayerController;

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMixerAuthCodeReadyEvent, const FString&, AuthCode);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMixerLoginUIFlowFinishedEvent, bool, bSucceeded);

/**
* A widget that displays browser-based UI for signing into Mixer via OAuth
*/
UCLASS()
class MIXERINTERACTIVITY_API UMixerLoginPane : public UWidget
{
GENERATED_BODY()

public:
/** Background color for web browser control when no document color is specified. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mixer", meta=(HideAlphaChannel))
FColor BackgroundColor;

/** Whether to attempt automatic signin before displaying UI. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mixer")
bool AllowSilentLogin;

public:
/** Called when an OAuth authorization code has been obtained (note: full login is not yet complete). */
UPROPERTY(BlueprintAssignable, Category = "Mixer|Event")
FOnMixerAuthCodeReadyEvent OnAuthCodeReady;

/** Called when the phase of login that requires UI is finished (note: full login is not yet complete). */
UPROPERTY(BlueprintAssignable, Category = "Mixer|Event")
FOnMixerLoginUIFlowFinishedEvent OnUIFlowFinished;

public:
//~ Begin UWidget Interface
virtual void SynchronizeProperties() override;
//~ End UWidget Interface

//~ Begin UVisual Interface
virtual void ReleaseSlateResources(bool bReleaseChildren) override;
//~ End UVisual Interface

#if WITH_EDITOR
virtual const FText GetPaletteCategory() override;
#endif

protected:
//~ Begin UWidget Interface
virtual TSharedRef<SWidget> RebuildWidget() override;
//~ End UWidget Interface

private:
FReply SlateHandleAuthCodeReady(const FString& AuthCode);
void SlateHandleUIFlowFinished(bool bSucceeded);

TSharedPtr<const FUniqueNetId> SlateGetUserId() const;

private:
TSharedPtr<SWidget> MyLoginPane;
};

0 comments on commit 0dbea1c

Please sign in to comment.