Skip to content

Commit

Permalink
Server status, selector on assets, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Nov 27, 2023
1 parent e1e5727 commit 9d3a4b6
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 70 deletions.
55 changes: 40 additions & 15 deletions Source/CesiumEditor/Private/CesiumIonPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "CesiumCommands.h"
#include "CesiumEditor.h"
#include "CesiumIonRasterOverlay.h"
#include "CesiumServerSelector.h"
#include "Editor.h"
#include "EditorModeManager.h"
#include "EngineUtils.h"
Expand All @@ -30,31 +31,27 @@ static FName ColumnName_Type = "Type";
static FName ColumnName_DateAdded = "DateAdded";

CesiumIonPanel::CesiumIonPanel()
: _connectionUpdatedDelegateHandle(),
_assetsUpdatedDelegateHandle(),
_pListView(nullptr),
: _pListView(nullptr),
_assets(),
_pSelection(nullptr) {
this->_connectionUpdatedDelegateHandle =
FCesiumEditorModule::ion().ConnectionUpdated.AddRaw(
_pSelection(nullptr),
_pLastServer(nullptr) {
this->_serverChangedDelegateHandle =
FCesiumEditorModule::serverManager().CurrentChanged.AddRaw(
this,
&CesiumIonPanel::Refresh);
this->_assetsUpdatedDelegateHandle =
FCesiumEditorModule::ion().AssetsUpdated.AddRaw(
this,
&CesiumIonPanel::Refresh);
&CesiumIonPanel::OnServerChanged);
this->_sortColumnName = ColumnName_DateAdded;
this->_sortMode = EColumnSortMode::Type::Descending;
}

CesiumIonPanel::~CesiumIonPanel() {
FCesiumEditorModule::ion().AssetsUpdated.Remove(
this->_assetsUpdatedDelegateHandle);
FCesiumEditorModule::ion().ConnectionUpdated.Remove(
this->_connectionUpdatedDelegateHandle);
this->Subscribe(nullptr);
FCesiumEditorModule::serverManager().CurrentChanged.Remove(
this->_serverChangedDelegateHandle);
}

void CesiumIonPanel::Construct(const FArguments& InArgs) {
this->Subscribe(FCesiumEditorModule::serverManager().GetCurrent());

// A function that returns the lambda that is used for rendering
// the sort mode indicator of the header column: If sorting is
// currently done based on the given name, then this will
Expand Down Expand Up @@ -111,6 +108,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
SVerticalBox::Slot().AutoHeight()
[
SNew(SHorizontalBox) +
SHorizontalBox::Slot().Padding(5.0f)[SNew(CesiumServerSelector)] +
// Add the refresh button at the upper left
SHorizontalBox::Slot().HAlign(HAlign_Left).Padding(5.0f)
[
Expand Down Expand Up @@ -428,6 +426,33 @@ void CesiumIonPanel::AssetSelected(
this->_pSelection = item;
}

void CesiumIonPanel::Subscribe(UCesiumIonServer* pNewServer) {
if (this->_pLastServer) {
std::shared_ptr<CesiumIonSession> pLastSession =
FCesiumEditorModule::serverManager().GetSession(this->_pLastServer);
if (pLastSession) {
pLastSession->ConnectionUpdated.RemoveAll(this);
pLastSession->AssetsUpdated.RemoveAll(this);
}
}

this->_pLastServer = pNewServer;

if (pNewServer) {
std::shared_ptr<CesiumIonSession> pSession =
FCesiumEditorModule::serverManager().GetSession(pNewServer);
pSession->ConnectionUpdated.AddRaw(this, &CesiumIonPanel::Refresh);
pSession->AssetsUpdated.AddRaw(this, &CesiumIonPanel::Refresh);
}
}

void CesiumIonPanel::OnServerChanged() {
UCesiumIonServer* pNewServer =
FCesiumEditorModule::serverManager().GetCurrent();
this->Subscribe(pNewServer);
this->Refresh();
}

void CesiumIonPanel::AddAsset(TSharedPtr<CesiumIonClient::Asset> item) {

if (isSupportedImagery(item)) {
Expand Down
7 changes: 5 additions & 2 deletions Source/CesiumEditor/Private/CesiumIonPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class FArguments;
class ITableRow;
class STableViewBase;
class UCesiumIonServer;

template <typename ItemType> class SListView;

Expand Down Expand Up @@ -43,6 +44,8 @@ class CesiumIonPanel : public SCompoundWidget {
void AssetSelected(
TSharedPtr<CesiumIonClient::Asset> item,
ESelectInfo::Type selectionType);
void Subscribe(UCesiumIonServer* pNewServer);
void OnServerChanged();

/**
* Filter the current _assets array, based on the current _searchString.
Expand Down Expand Up @@ -73,11 +76,11 @@ class CesiumIonPanel : public SCompoundWidget {
*/
void OnSearchTextChange(const FText& SearchText);

FDelegateHandle _connectionUpdatedDelegateHandle;
FDelegateHandle _assetsUpdatedDelegateHandle;
FDelegateHandle _serverChangedDelegateHandle;
TSharedPtr<SListView<TSharedPtr<CesiumIonClient::Asset>>> _pListView;
TArray<TSharedPtr<CesiumIonClient::Asset>> _assets;
TSharedPtr<CesiumIonClient::Asset> _pSelection;
TObjectPtr<UCesiumIonServer> _pLastServer;

/**
* The column name based on which the main assets list view is currently
Expand Down
34 changes: 31 additions & 3 deletions Source/CesiumEditor/Private/CesiumIonServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
#include "CesiumRuntimeSettings.h"
#include "CesiumSourceControl.h"

CesiumIonServerManager::CesiumIonServerManager() noexcept {
FAssetRegistryModule& AssetRegistryModule =
FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.GetRegistry().OnAssetAdded().AddRaw(
this,
&CesiumIonServerManager::OnAssetAddedOrRemoved);
AssetRegistryModule.GetRegistry().OnAssetRemoved().AddRaw(
this,
&CesiumIonServerManager::OnAssetAddedOrRemoved);
}

CesiumIonServerManager::~CesiumIonServerManager() noexcept {
FAssetRegistryModule* pAssetRegistryModule =
FModuleManager::GetModulePtr<FAssetRegistryModule>("AssetRegistry");
if (pAssetRegistryModule) {
pAssetRegistryModule->GetRegistry().OnAssetAdded().RemoveAll(this);
pAssetRegistryModule->GetRegistry().OnAssetRemoved().RemoveAll(this);
}
}

void CesiumIonServerManager::Initialize() {
UCesiumRuntimeSettings* pSettings =
GetMutableDefault<UCesiumRuntimeSettings>();
Expand Down Expand Up @@ -65,20 +85,23 @@ std::shared_ptr<CesiumIonSession> CesiumIonServerManager::GetCurrentSession() {

const TArray<TObjectPtr<UCesiumIonServer>>&
CesiumIonServerManager::GetServerList() {
this->RefreshServerList();
return this->_servers;
}

void CesiumIonServerManager::RefreshServerList() {
this->_servers.Empty();

TArray<FAssetData> CesiumIonServers;
FAssetRegistryModule& AssetRegistryModule =
FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.Get().GetAssetsByClass(
UCesiumIonServer::StaticClass()->GetFName(),
UCesiumIonServer::StaticClass()->GetClassPathName(),
CesiumIonServers);

for (const FAssetData& ServerAsset : CesiumIonServers) {
this->_servers.Add(Cast<UCesiumIonServer>(ServerAsset.GetAsset()));
}

return this->_servers;
}

UCesiumIonServer* CesiumIonServerManager::GetCurrent() {
Expand Down Expand Up @@ -106,3 +129,8 @@ void CesiumIonServerManager::SetCurrent(UCesiumIonServer* pServer) {
CurrentChanged.Broadcast();
}
}

void CesiumIonServerManager::OnAssetAddedOrRemoved(const FAssetData& asset) {
this->RefreshServerList();
this->ServerListChanged.Broadcast();
}
6 changes: 6 additions & 0 deletions Source/CesiumEditor/Private/CesiumIonServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ DECLARE_MULTICAST_DELEGATE(FCesiumIonServerChanged);

class CESIUMEDITOR_API CesiumIonServerManager {
public:
CesiumIonServerManager() noexcept;
~CesiumIonServerManager() noexcept;

void Initialize();

std::shared_ptr<CesiumIonSession> GetSession(UCesiumIonServer* Server);
std::shared_ptr<CesiumIonSession> GetCurrentSession();

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

UCesiumIonServer* GetCurrent();
void SetCurrent(UCesiumIonServer* pServer);
Expand All @@ -26,6 +30,8 @@ class CESIUMEDITOR_API CesiumIonServerManager {
FCesiumIonServerChanged CurrentChanged;

private:
void OnAssetAddedOrRemoved(const FAssetData& asset);

struct ServerSession {
TWeakObjectPtr<UCesiumIonServer> Server;
std::shared_ptr<CesiumIonSession> Session;
Expand Down
45 changes: 2 additions & 43 deletions Source/CesiumEditor/Private/CesiumPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "CesiumIonPanel.h"
#include "CesiumIonServer.h"
#include "CesiumRuntimeSettings.h"
#include "CesiumServerSelector.h"
#include "CesiumUtility/Uri.h"
#include "Editor.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
Expand All @@ -23,7 +24,7 @@
void CesiumPanel::Construct(const FArguments& InArgs) {
ChildSlot
[SNew(SVerticalBox) +
SVerticalBox::Slot().AutoHeight()[ServerSelector()] +
SVerticalBox::Slot().AutoHeight()[SNew(CesiumServerSelector)] +
SVerticalBox::Slot().AutoHeight()[Toolbar()] +
SVerticalBox::Slot().VAlign(VAlign_Fill)
[SNew(SScrollBox) + SScrollBox::Slot()[BasicQuickAddPanel()] +
Expand All @@ -49,48 +50,6 @@ static bool isSignedIn() {
->isConnected();
}

TSharedRef<SWidget> CesiumPanel::ServerSelector() {
TSharedPtr<SComboBox<TObjectPtr<UCesiumIonServer>>> Selector =
SNew(SComboBox<TObjectPtr<UCesiumIonServer>>)
.OptionsSource(&FCesiumEditorModule::serverManager().GetServerList())
.OnGenerateWidget(this, &CesiumPanel::OnGenerateServerEntry)
.OnSelectionChanged(this, &CesiumPanel::OnServerSelectionChanged)
.Content()[SNew(STextBlock)
.Text(this, &CesiumPanel::GetServerValueAsText)];
return Selector.ToSharedRef();
}

namespace {

FText GetNameFromCesiumIonServerAsset(
const TObjectPtr<UCesiumIonServer>& pServer) {
if (!pServer)
return FText();

return FText::FromString(
pServer->DisplayName.IsEmpty() ? pServer->GetPackage()->GetName()
: pServer->DisplayName);
}

} // namespace

FText CesiumPanel::GetServerValueAsText() const {
UCesiumIonServer* pServer = FCesiumEditorModule::serverManager().GetCurrent();
return GetNameFromCesiumIonServerAsset(pServer);
}

TSharedRef<SWidget>
CesiumPanel::OnGenerateServerEntry(TObjectPtr<UCesiumIonServer> pServerAsset) {
return SNew(STextBlock).Text(GetNameFromCesiumIonServerAsset(pServerAsset));
}

void CesiumPanel::OnServerSelectionChanged(
TObjectPtr<UCesiumIonServer> InItem,
ESelectInfo::Type InSeletionInfo) {
FCesiumEditorModule::serverManager().SetCurrent(InItem);
FCesiumEditorModule::serverManager().GetCurrentSession()->resume();
}

TSharedRef<SWidget> CesiumPanel::Toolbar() {
TSharedRef<FUICommandList> commandList = MakeShared<FUICommandList>();

Expand Down
7 changes: 0 additions & 7 deletions Source/CesiumEditor/Private/CesiumPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ class CesiumPanel : public SCompoundWidget {
const float InDeltaTime) override;

private:
TSharedRef<SWidget> ServerSelector();
TSharedRef<SWidget> Toolbar();
TSharedRef<SWidget> LoginPanel();
TSharedRef<SWidget> MainIonQuickAddPanel();
TSharedRef<SWidget> BasicQuickAddPanel();
TSharedRef<SWidget> ConnectionStatus();
TSharedRef<SWidget>
OnGenerateServerEntry(TObjectPtr<UCesiumIonServer> pServer);
FText GetServerValueAsText() const;
void OnServerSelectionChanged(
TObjectPtr<UCesiumIonServer> InItem,
ESelectInfo::Type InSeletionInfo);

void addFromIon();
void uploadToIon();
Expand Down
70 changes: 70 additions & 0 deletions Source/CesiumEditor/Private/CesiumServerSelector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2020-2023 CesiumGS, Inc. and Contributors

#include "CesiumServerSelector.h"
#include "CesiumEditor.h"
#include "CesiumIonServer.h"

void CesiumServerSelector::Construct(const FArguments& InArgs) {
ChildSlot
[SNew(SComboBox<TObjectPtr<UCesiumIonServer>>)
.OptionsSource(&FCesiumEditorModule::serverManager().GetServerList())
.OnGenerateWidget(this, &CesiumServerSelector::OnGenerateServerEntry)
.OnSelectionChanged(
this,
&CesiumServerSelector::OnServerSelectionChanged)
.Content()
[SNew(STextBlock)
.Text(this, &CesiumServerSelector::GetServerValueAsText)]];
}

namespace {

FText GetNameFromCesiumIonServerAsset(
const TObjectPtr<UCesiumIonServer>& pServer) {
if (!pServer)
return FText::FromString("Error: No Cesium ion server configured.");

std::shared_ptr<CesiumIonSession> pSession =
FCesiumEditorModule::serverManager().GetSession(pServer);

FString prefix;
FString suffix;

if (pSession->isConnecting() || pSession->isResuming()) {
suffix = " (connecting...)";
} else if (pSession->isLoadingProfile()) {
suffix = " (loading profile...)";
} else if (pSession->isConnected() && pSession->isProfileLoaded()) {
prefix = FString(UTF8_TO_TCHAR(pSession->getProfile().username.c_str()));
prefix += " @ ";
} else {
suffix = " (not connected)";
}

return FText::FromString(
prefix +
(pServer->DisplayName.IsEmpty() ? pServer->GetPackage()->GetName()
: pServer->DisplayName) +
suffix);
}

} // namespace

FText CesiumServerSelector::GetServerValueAsText() const {
UCesiumIonServer* pServer = FCesiumEditorModule::serverManager().GetCurrent();
return GetNameFromCesiumIonServerAsset(pServer);
}

TSharedRef<SWidget> CesiumServerSelector::OnGenerateServerEntry(
TObjectPtr<UCesiumIonServer> pServerAsset) {
return SNew(STextBlock).Text_Lambda([pServerAsset]() {
return GetNameFromCesiumIonServerAsset(pServerAsset);
});
}

void CesiumServerSelector::OnServerSelectionChanged(
TObjectPtr<UCesiumIonServer> InItem,
ESelectInfo::Type InSeletionInfo) {
FCesiumEditorModule::serverManager().SetCurrent(InItem);
FCesiumEditorModule::serverManager().GetCurrentSession()->resume();
}
25 changes: 25 additions & 0 deletions Source/CesiumEditor/Private/CesiumServerSelector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020-2023 CesiumGS, Inc. and Contributors

#pragma once

#include "Widgets/SCompoundWidget.h"

class FArguments;
class UCesiumIonServer;

class CesiumServerSelector : public SCompoundWidget {
SLATE_BEGIN_ARGS(CesiumServerSelector) {}
SLATE_END_ARGS()

void Construct(const FArguments& InArgs);

private:
TSharedRef<SWidget>
OnGenerateServerEntry(TObjectPtr<UCesiumIonServer> pServer);

FText GetServerValueAsText() const;

void OnServerSelectionChanged(
TObjectPtr<UCesiumIonServer> InItem,
ESelectInfo::Type InSeletionInfo);
};

0 comments on commit 9d3a4b6

Please sign in to comment.