Skip to content

Commit

Permalink
Basic login and server switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Nov 24, 2023
1 parent fbad75c commit a7d0d73
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Source/CesiumEditor/Private/CesiumIonServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ CesiumIonServerManager::GetSession(UCesiumIonServer* Server) {
return Found->Session;
}

std::shared_ptr<CesiumIonSession> CesiumIonServerManager::GetCurrentSession() {
return this->GetSession(this->GetCurrent());
}

const TArray<TObjectPtr<UCesiumIonServer>>&
CesiumIonServerManager::GetServerList() {
this->_servers.Empty();
Expand Down
1 change: 1 addition & 0 deletions Source/CesiumEditor/Private/CesiumIonServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DECLARE_MULTICAST_DELEGATE(FCesiumIonServerChanged);
class CESIUMEDITOR_API CesiumIonServerManager {
public:
std::shared_ptr<CesiumIonSession> GetSession(UCesiumIonServer* Server);
std::shared_ptr<CesiumIonSession> GetCurrentSession();

const TArray<TObjectPtr<UCesiumIonServer>>& GetServerList();

Expand Down
5 changes: 3 additions & 2 deletions Source/CesiumEditor/Private/CesiumIonSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ void CesiumIonSession::connect() {

UCesiumEditorSettings* pSettings =
GetMutableDefault<UCesiumEditorSettings>();
pSettings->UserAccessTokenMap[thiz->_pServer.Get()] =
pSettings->UserAccessTokenMap.Add(
thiz->_pServer.Get(),
UTF8_TO_TCHAR(
thiz->_connection.value().getAccessToken().c_str());
thiz->_connection.value().getAccessToken().c_str()));
pSettings->Save();

thiz->ConnectionUpdated.Broadcast();
Expand Down
27 changes: 19 additions & 8 deletions Source/CesiumEditor/Private/CesiumPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ void CesiumPanel::Tick(
SCompoundWidget::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
}

static bool isSignedIn() { return FCesiumEditorModule::ion().isConnected(); }
static bool isSignedIn() {
return FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isConnected();
}

TSharedRef<SWidget> CesiumPanel::ServerSelector() {
TSharedPtr<SComboBox<TObjectPtr<UCesiumIonServer>>> Selector =
Expand Down Expand Up @@ -229,8 +233,10 @@ TSharedRef<SWidget> CesiumPanel::BasicQuickAddPanel() {
TSharedRef<SWidget> CesiumPanel::ConnectionStatus() {

auto linkVisibility = []() {
FCesiumEditorModule::ion().refreshProfileIfNeeded();
if (!FCesiumEditorModule::ion().isProfileLoaded()) {
std::shared_ptr<CesiumIonSession> pSession =
FCesiumEditorModule::serverManager().GetCurrentSession();
pSession->refreshProfileIfNeeded();
if (!pSession->isProfileLoaded()) {
return EVisibility::Collapsed;
}
if (!isSignedIn()) {
Expand All @@ -239,14 +245,17 @@ TSharedRef<SWidget> CesiumPanel::ConnectionStatus() {
return EVisibility::Visible;
};
auto linkText = []() {
auto& profile = FCesiumEditorModule::ion().getProfile();
std::shared_ptr<CesiumIonSession> pSession =
FCesiumEditorModule::serverManager().GetCurrentSession();
auto& profile = pSession->getProfile();
std::string s = "Connected to Cesium ion as " + profile.username;
return FText::FromString(UTF8_TO_TCHAR(s.c_str()));
};
auto loadingMessageVisibility = []() {
return FCesiumEditorModule::ion().isLoadingProfile()
? EVisibility::Visible
: EVisibility::Collapsed;
std::shared_ptr<CesiumIonSession> pSession =
FCesiumEditorModule::serverManager().GetCurrentSession();
return pSession->isLoadingProfile() ? EVisibility::Visible
: EVisibility::Collapsed;
};
return SNew(SVerticalBox) +
SVerticalBox::Slot()
Expand Down Expand Up @@ -291,7 +300,9 @@ void CesiumPanel::visitIon() {
NULL);
}

void CesiumPanel::signOut() { FCesiumEditorModule::ion().disconnect(); }
void CesiumPanel::signOut() {
FCesiumEditorModule::serverManager().GetCurrentSession()->disconnect();
}

void CesiumPanel::openDocumentation() {
FPlatformProcess::LaunchURL(TEXT("https://cesium.com/docs"), NULL, NULL);
Expand Down
59 changes: 41 additions & 18 deletions Source/CesiumEditor/Private/IonLoginPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ using namespace CesiumIonClient;
void IonLoginPanel::Construct(const FArguments& InArgs) {

auto visibleWhenConnecting = [this]() {
return FCesiumEditorModule::ion().isConnecting() ? EVisibility::Visible
: EVisibility::Hidden;
return FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isConnecting()
? EVisibility::Visible
: EVisibility::Hidden;
};

auto visibleWhenResuming = [this]() {
return FCesiumEditorModule::ion().isResuming() ? EVisibility::Visible
: EVisibility::Hidden;
return FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isResuming()
? EVisibility::Visible
: EVisibility::Hidden;
};

// TODO Format this, and disable clang format here
Expand Down Expand Up @@ -70,10 +76,11 @@ void IonLoginPanel::Construct(const FArguments& InArgs) {
SBorder)[SNew(SEditableText)
.IsReadOnly(true)
.Text_Lambda([this]() {
return FText::FromString(
UTF8_TO_TCHAR(FCesiumEditorModule::ion()
.getAuthorizeUrl()
.c_str()));
return FText::FromString(UTF8_TO_TCHAR(
FCesiumEditorModule::serverManager()
.GetCurrentSession()
->getAuthorizeUrl()
.c_str()));
})]] +
SHorizontalBox::Slot()
.VAlign(VAlign_Center)
Expand Down Expand Up @@ -107,8 +114,12 @@ void IonLoginPanel::Construct(const FArguments& InArgs) {
.OnClicked(this, &IonLoginPanel::SignIn)
.Text(FText::FromString(TEXT("Connect to Cesium ion")))
.IsEnabled_Lambda([this]() {
return !FCesiumEditorModule::ion().isConnecting() &&
!FCesiumEditorModule::ion().isResuming();
return !FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isConnecting() &&
!FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isResuming();
})] +
SVerticalBox::Slot()
.VAlign(VAlign_Top)
Expand All @@ -120,8 +131,12 @@ void IonLoginPanel::Construct(const FArguments& InArgs) {
.Text(FText::FromString(TEXT(
"You can now sign in with your Epic Games account!")))
.IsEnabled_Lambda([this]() {
return !FCesiumEditorModule::ion().isConnecting() &&
!FCesiumEditorModule::ion().isResuming();
return !FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isConnecting() &&
!FCesiumEditorModule::serverManager()
.GetCurrentSession()
->isResuming();
})] +
SVerticalBox::Slot()
.VAlign(VAlign_Top)
Expand Down Expand Up @@ -161,28 +176,36 @@ void IonLoginPanel::Construct(const FArguments& InArgs) {
}

FReply IonLoginPanel::SignIn() {
FCesiumEditorModule::ion().connect();
FCesiumEditorModule::serverManager().GetCurrentSession()->connect();
return FReply::Handled();
}

FReply IonLoginPanel::CopyAuthorizeUrlToClipboard() {
FText url = FText::FromString(
UTF8_TO_TCHAR(FCesiumEditorModule::ion().getAuthorizeUrl().c_str()));
FText url =
FText::FromString(UTF8_TO_TCHAR(FCesiumEditorModule::serverManager()
.GetCurrentSession()
->getAuthorizeUrl()
.c_str()));
FPlatformApplicationMisc::ClipboardCopy(*url.ToString());
return FReply::Handled();
}

void IonLoginPanel::LaunchBrowserAgain() {
FPlatformProcess::LaunchURL(
UTF8_TO_TCHAR(FCesiumEditorModule::ion().getAuthorizeUrl().c_str()),
UTF8_TO_TCHAR(FCesiumEditorModule::serverManager()
.GetCurrentSession()
->getAuthorizeUrl()
.c_str()),
NULL,
NULL);
}

void IonLoginPanel::CancelLogin() {
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> pRequest =
FHttpModule::Get().CreateRequest();
pRequest->SetURL(
UTF8_TO_TCHAR(FCesiumEditorModule::ion().getRedirectUrl().c_str()));
pRequest->SetURL(UTF8_TO_TCHAR(FCesiumEditorModule::serverManager()
.GetCurrentSession()
->getRedirectUrl()
.c_str()));
pRequest->ProcessRequest();
}

0 comments on commit a7d0d73

Please sign in to comment.