TSharedRef SGameLiftSettingsAwsAccountMenu::MakeProfileBootstrappingWidget()

in GameLiftPlugin/Source/GameLiftPlugin/Private/SMenu/SGameLiftSettingsAwsAccountMenu.cpp [411:656]


TSharedRef<SWidget> SGameLiftSettingsAwsAccountMenu::MakeProfileBootstrappingWidget()
{
	UGameLiftSettings* Settings = GetMutableDefault<UGameLiftSettings>();
	SAssignNew(CurrentBootstrapStatusWidget, SBootstrapStatus);
	StaticCastSharedPtr<SBootstrapStatus>(CurrentBootstrapStatusWidget)->UpdateState(Settings->BootstrapStatus);

	// Incomplete profile warning message
	TSharedRef<SVerticalBox> VerticalBox = SNew(SVerticalBox);

	VerticalBox->AddSlot()
	.AutoHeight()
	.Padding(SPadding::Bottom2x + SPadding::Right2x)
	[
		SNew(SBox)
		.Visibility_Lambda([&]() -> EVisibility
			{
				// If region is supported but inactive profile, only then display incomplete profile message.
				return (ShowBootstrapStatusOnly && (!ProfileSelectedActive) && ContainersRegionSupported) ? EVisibility::Visible : EVisibility::Collapsed;
			})
		[
			SNew(SSetupMessage)
			.WarningText(Settings::AwsAccount::kIncompleteDeploymentProfileText)
			.SetState(ESetupMessageState::WarningMessage)
		]
	];

	VerticalBox->AddSlot()
		.AutoHeight()
		.Padding(SPadding::Bottom2x + SPadding::Right2x)
		[
			SNew(SBox)
				.Visibility_Lambda([&]() -> EVisibility
					{
						// Only display warning message if on containers page and the region is unsupported.
						return (ShowBootstrapStatusOnly && !ContainersRegionSupported) ? EVisibility::Visible : EVisibility::Collapsed;
					})
				[
					SAssignNew(ContainersUnsupportedMessage, SSetupMessage)
						.WarningRowWidget(MakeContainersUnsupportedWidget())
				]
		];

	SAssignNew(ProfileHeaderSwitcher, SWidgetSwitcher)
		+ SWidgetSwitcher::Slot()
		[
			MakeProfileDescriptionChildWidget(
				Settings::AwsAccount::kAWSProfilesTitleText,
				Settings::AwsAccount::kAWSProfilesDescriptionText)
		]
		+ SWidgetSwitcher::Slot()
		[
			MakeProfileDescriptionChildWidget(
				Settings::AwsAccount::kProfileDetailsTitleText,
				Settings::AwsAccount::kProfileBootstrappedDescriptionText)
		];

	if (!ShowBootstrapStatusOnly)
	{
		VerticalBox->AddSlot()
			.AutoHeight()
			.Padding(SPadding::Bottom + SPadding::Right2x)
			[
				ProfileHeaderSwitcher.ToSharedRef()
			];
	}

	VerticalBox->AddSlot()
		.AutoHeight()
		.HAlign(HAlign_Right)
		.Padding(SPadding::Top_Bottom + SPadding::Right2x)
		[
			SNew(SHorizontalBox)
			.Visibility(ShowBootstrapStatusOnly ? EVisibility::Collapsed : EVisibility::Visible)

			// Set as selected button
			+ SHorizontalBox::Slot()
			.AutoWidth()
			.Padding(SPadding::Bottom + SPadding::Right2x)
			[
				SNew(SButton)
				.Text(Settings::AwsAccount::kSetProfileAsSelectedButtonText)
				.OnClicked_Raw(this, &SGameLiftSettingsAwsAccountMenu::OnSetProfileAsSelectedButtonClicked)
				.IsEnabled_Lambda([&]
				{
					UGameLiftSettings* Settings = GetMutableDefault<UGameLiftSettings>();
					return Settings->CurrentProfileName != RadioButtonSelectedProfile;
				})
				.TextStyle(FGameLiftPluginStyle::Get(), Style::Text::kButtonLight)
			]

			// bootstrap button
			+ SHorizontalBox::Slot()
			.AutoWidth()
			.Padding(SPadding::Bottom + SPadding::Right2x)
			[
				SNew(SButton)
				.Text(Settings::AwsAccount::kBootstrapProfileButtonText)
				.OnClicked_Lambda([&]()
				{
					MakeBootstrapModal();
					BootstrapModal->ShowModal();
					return FReply::Handled();
				})
				.IsEnabled_Lambda([&]
				{
					UGameLiftSettings* Settings = GetMutableDefault<UGameLiftSettings>();
					if (Settings->CurrentProfileName.IsEmpty() || !Settings->UserProfileInfoMap.Contains(Settings->CurrentProfileName)
						|| Settings->CurrentProfileName != RadioButtonSelectedProfile) // Only enable the Bootstrap profile button when the radio button is on the selected profile.
					{
						return false;
					}
					int BootstrapStatusInt = Settings->UserProfileInfoMap[Settings->CurrentProfileName].BootstrapStatus;
					return EBootstrapMessageStateFromInt(BootstrapStatusInt) != EBootstrapMessageState::InProgressMessage &&
						EBootstrapMessageStateFromInt(BootstrapStatusInt) != EBootstrapMessageState::ActiveMessage;
				})
				.ButtonStyle(FGameLiftPluginStyle::Get(), Style::Button::kSuccessButtonStyleName)
				.TextStyle(FGameLiftPluginStyle::Get(), Style::Text::kButtonLight)
			]

			//  What is bootstrapping link
			+ SHorizontalBox::Slot()
			.AutoWidth()
			.HAlign(HAlign_Fill)
			.Padding(SPadding::Top_Bottom + SPadding::Right2x)
			[
				SNew(SOnlineHyperlink)
				.Text(Settings::AwsAccount::kWhatIsBootstrappingHyperLinkText)
				.Link(Settings::AwsAccount::kWhatIsBootstrappingHyperLinkUrl)
			]
		];

	VerticalBox->AddSlot()
		.Padding(SPadding::Right2x)
		.AutoHeight()
		[
			MakeProfileTableHeader()
		];

	// Table Rows
	VerticalBox->AddSlot()
    .AutoHeight()
    [
		ProfileListContainer.ToSharedRef()
	];

	RefreshProfileList();


	VerticalBox->AddSlot()
    .Padding(SPadding::Bottom2x + SPadding::Right2x)
	[
		SNew(SBox)
		.HeightOverride(35)
		.Visibility(ShowBootstrapStatusOnly ? EVisibility::Collapsed : EVisibility::Visible)
		[
			SNew(SButton)
			.ContentPadding(SPadding::Left)
			.VAlign(VAlign_Center)
			.Text(Settings::AwsAccount::kAddAnotherProfileButtonText)
			.TextStyle(FGameLiftPluginStyle::Get(), Style::Text::kButtonNormal)
			.OnClicked_Lambda([&]
			{
				ResetAddProfileUI(true);
				ShowAddProfile = true;
				ProfileHeaderSwitcher->SetActiveWidgetIndex(1);
				return FReply::Handled();
			})
		]
	];

	VerticalBox->AddSlot()
	.AutoHeight()
	.Padding(SPadding::Top2x)
	[
		SNew(SBox)
		.Visibility_Lambda([&]() -> EVisibility {
			return (ShowAddProfile && !ShowBootstrapStatusOnly) ? EVisibility::Visible : EVisibility::Collapsed;
		})
		[
			MakeAddProfileWidget(true)
		]
	];

	if (ShowBootstrapStatusOnly) {
		VerticalBox->AddSlot()
		.AutoHeight()
		.HAlign(HAlign_Left)
		.Padding(SPadding::Top2x_Bottom2x)
		[
			SNew(STextBlock)
			.Text(Settings::AwsAccount::kCredentialProfileDescriptionText)
		];

		VerticalBox->AddSlot()
		.AutoHeight()
		.HAlign(HAlign_Left)
		.Padding(SPadding::Top_Bottom + SPadding::Right2x)
		[
			MakeOpenCredentialsPageButtonSwitcher()
		];
	} else {
		// Getting profile file path
		// Tried to use AWS SDK function Aws::Auth::ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename(), but it crashes randomly sometimes.
	    FString EnvOverridePath = FPlatformMisc::GetEnvironmentVariable(TEXT("AWS_SHARED_CREDENTIALS_FILE"));
        FString DefaultPath = FPaths::Combine(*FString(FPlatformProcess::UserDir()).Replace(TEXT("/Documents"), TEXT("")), TEXT(".aws/credentials"));
        FString	CredentialPath = EnvOverridePath.IsEmpty() ? DefaultPath : EnvOverridePath;
		VerticalBox->AddSlot()
			.AutoHeight()
			.HAlign(HAlign_Left)
			.Padding(SPadding::Top2x_Bottom2x)
			[
				SNew(SHorizontalBox)
					+ SHorizontalBox::Slot()
					.AutoWidth()
					.HAlign(HAlign_Left)
					.Padding(SPadding::Top_Bottom + SPadding::Right2x)
					[
						SNew(STextBlock)
							.Text(Settings::AwsAccount::kAWSCredentialsFileLabel)
							.TextStyle(FGameLiftPluginStyle::Get(), Style::Text::kField)
					]
					+ SHorizontalBox::Slot()
					.AutoWidth()
					.HAlign(HAlign_Left)
					.Padding(SPadding::Top_Bottom + SPadding::Right2x)
					[
						SNew(STextBlock)
							.Text(FText::FromString(CredentialPath))
							.TextStyle(FGameLiftPluginStyle::Get(), Style::Text::kField)
					]
					// Open file button
					+ SHorizontalBox::Slot()
					.AutoWidth()
					.HAlign(HAlign_Left)
					.Padding(SPadding::Right2x)
					[
						SNew(SExternalLinkButton)
							.Text(Settings::AwsAccount::kOpenFileButtonText)
							.ButtonTooltipText(Settings::AwsAccount::kOpenFileButtonHoverText)
							.FilePath(CredentialPath)
					]
			];
	}

	return VerticalBox;
}