From 9d3a4b6c512a79e91f4113729fcb0d0e7c8aaece Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Mon, 27 Nov 2023 12:31:20 +1100 Subject: [PATCH] Server status, selector on assets, etc. --- .../CesiumEditor/Private/CesiumIonPanel.cpp | 55 +++++++++++---- Source/CesiumEditor/Private/CesiumIonPanel.h | 7 +- .../Private/CesiumIonServerManager.cpp | 34 ++++++++- .../Private/CesiumIonServerManager.h | 6 ++ Source/CesiumEditor/Private/CesiumPanel.cpp | 45 +----------- Source/CesiumEditor/Private/CesiumPanel.h | 7 -- .../Private/CesiumServerSelector.cpp | 70 +++++++++++++++++++ .../Private/CesiumServerSelector.h | 25 +++++++ 8 files changed, 179 insertions(+), 70 deletions(-) create mode 100644 Source/CesiumEditor/Private/CesiumServerSelector.cpp create mode 100644 Source/CesiumEditor/Private/CesiumServerSelector.h diff --git a/Source/CesiumEditor/Private/CesiumIonPanel.cpp b/Source/CesiumEditor/Private/CesiumIonPanel.cpp index 212f75653..02618ac69 100644 --- a/Source/CesiumEditor/Private/CesiumIonPanel.cpp +++ b/Source/CesiumEditor/Private/CesiumIonPanel.cpp @@ -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" @@ -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 @@ -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) [ @@ -428,6 +426,33 @@ void CesiumIonPanel::AssetSelected( this->_pSelection = item; } +void CesiumIonPanel::Subscribe(UCesiumIonServer* pNewServer) { + if (this->_pLastServer) { + std::shared_ptr pLastSession = + FCesiumEditorModule::serverManager().GetSession(this->_pLastServer); + if (pLastSession) { + pLastSession->ConnectionUpdated.RemoveAll(this); + pLastSession->AssetsUpdated.RemoveAll(this); + } + } + + this->_pLastServer = pNewServer; + + if (pNewServer) { + std::shared_ptr 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 item) { if (isSupportedImagery(item)) { diff --git a/Source/CesiumEditor/Private/CesiumIonPanel.h b/Source/CesiumEditor/Private/CesiumIonPanel.h index 78aaf4381..58da99149 100644 --- a/Source/CesiumEditor/Private/CesiumIonPanel.h +++ b/Source/CesiumEditor/Private/CesiumIonPanel.h @@ -11,6 +11,7 @@ class FArguments; class ITableRow; class STableViewBase; +class UCesiumIonServer; template class SListView; @@ -43,6 +44,8 @@ class CesiumIonPanel : public SCompoundWidget { void AssetSelected( TSharedPtr item, ESelectInfo::Type selectionType); + void Subscribe(UCesiumIonServer* pNewServer); + void OnServerChanged(); /** * Filter the current _assets array, based on the current _searchString. @@ -73,11 +76,11 @@ class CesiumIonPanel : public SCompoundWidget { */ void OnSearchTextChange(const FText& SearchText); - FDelegateHandle _connectionUpdatedDelegateHandle; - FDelegateHandle _assetsUpdatedDelegateHandle; + FDelegateHandle _serverChangedDelegateHandle; TSharedPtr>> _pListView; TArray> _assets; TSharedPtr _pSelection; + TObjectPtr _pLastServer; /** * The column name based on which the main assets list view is currently diff --git a/Source/CesiumEditor/Private/CesiumIonServerManager.cpp b/Source/CesiumEditor/Private/CesiumIonServerManager.cpp index 67910c799..b9086cf59 100644 --- a/Source/CesiumEditor/Private/CesiumIonServerManager.cpp +++ b/Source/CesiumEditor/Private/CesiumIonServerManager.cpp @@ -9,6 +9,26 @@ #include "CesiumRuntimeSettings.h" #include "CesiumSourceControl.h" +CesiumIonServerManager::CesiumIonServerManager() noexcept { + FAssetRegistryModule& AssetRegistryModule = + FModuleManager::LoadModuleChecked("AssetRegistry"); + AssetRegistryModule.GetRegistry().OnAssetAdded().AddRaw( + this, + &CesiumIonServerManager::OnAssetAddedOrRemoved); + AssetRegistryModule.GetRegistry().OnAssetRemoved().AddRaw( + this, + &CesiumIonServerManager::OnAssetAddedOrRemoved); +} + +CesiumIonServerManager::~CesiumIonServerManager() noexcept { + FAssetRegistryModule* pAssetRegistryModule = + FModuleManager::GetModulePtr("AssetRegistry"); + if (pAssetRegistryModule) { + pAssetRegistryModule->GetRegistry().OnAssetAdded().RemoveAll(this); + pAssetRegistryModule->GetRegistry().OnAssetRemoved().RemoveAll(this); + } +} + void CesiumIonServerManager::Initialize() { UCesiumRuntimeSettings* pSettings = GetMutableDefault(); @@ -65,20 +85,23 @@ std::shared_ptr CesiumIonServerManager::GetCurrentSession() { const TArray>& CesiumIonServerManager::GetServerList() { + this->RefreshServerList(); + return this->_servers; +} + +void CesiumIonServerManager::RefreshServerList() { this->_servers.Empty(); TArray CesiumIonServers; FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked("AssetRegistry"); AssetRegistryModule.Get().GetAssetsByClass( - UCesiumIonServer::StaticClass()->GetFName(), + UCesiumIonServer::StaticClass()->GetClassPathName(), CesiumIonServers); for (const FAssetData& ServerAsset : CesiumIonServers) { this->_servers.Add(Cast(ServerAsset.GetAsset())); } - - return this->_servers; } UCesiumIonServer* CesiumIonServerManager::GetCurrent() { @@ -106,3 +129,8 @@ void CesiumIonServerManager::SetCurrent(UCesiumIonServer* pServer) { CurrentChanged.Broadcast(); } } + +void CesiumIonServerManager::OnAssetAddedOrRemoved(const FAssetData& asset) { + this->RefreshServerList(); + this->ServerListChanged.Broadcast(); +} diff --git a/Source/CesiumEditor/Private/CesiumIonServerManager.h b/Source/CesiumEditor/Private/CesiumIonServerManager.h index 15b075542..122fe4927 100644 --- a/Source/CesiumEditor/Private/CesiumIonServerManager.h +++ b/Source/CesiumEditor/Private/CesiumIonServerManager.h @@ -12,12 +12,16 @@ DECLARE_MULTICAST_DELEGATE(FCesiumIonServerChanged); class CESIUMEDITOR_API CesiumIonServerManager { public: + CesiumIonServerManager() noexcept; + ~CesiumIonServerManager() noexcept; + void Initialize(); std::shared_ptr GetSession(UCesiumIonServer* Server); std::shared_ptr GetCurrentSession(); const TArray>& GetServerList(); + void RefreshServerList(); UCesiumIonServer* GetCurrent(); void SetCurrent(UCesiumIonServer* pServer); @@ -26,6 +30,8 @@ class CESIUMEDITOR_API CesiumIonServerManager { FCesiumIonServerChanged CurrentChanged; private: + void OnAssetAddedOrRemoved(const FAssetData& asset); + struct ServerSession { TWeakObjectPtr Server; std::shared_ptr Session; diff --git a/Source/CesiumEditor/Private/CesiumPanel.cpp b/Source/CesiumEditor/Private/CesiumPanel.cpp index 073b532e5..964a523f9 100644 --- a/Source/CesiumEditor/Private/CesiumPanel.cpp +++ b/Source/CesiumEditor/Private/CesiumPanel.cpp @@ -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" @@ -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()] + @@ -49,48 +50,6 @@ static bool isSignedIn() { ->isConnected(); } -TSharedRef CesiumPanel::ServerSelector() { - TSharedPtr>> Selector = - SNew(SComboBox>) - .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& 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 -CesiumPanel::OnGenerateServerEntry(TObjectPtr pServerAsset) { - return SNew(STextBlock).Text(GetNameFromCesiumIonServerAsset(pServerAsset)); -} - -void CesiumPanel::OnServerSelectionChanged( - TObjectPtr InItem, - ESelectInfo::Type InSeletionInfo) { - FCesiumEditorModule::serverManager().SetCurrent(InItem); - FCesiumEditorModule::serverManager().GetCurrentSession()->resume(); -} - TSharedRef CesiumPanel::Toolbar() { TSharedRef commandList = MakeShared(); diff --git a/Source/CesiumEditor/Private/CesiumPanel.h b/Source/CesiumEditor/Private/CesiumPanel.h index a6427728c..c0f7650ce 100644 --- a/Source/CesiumEditor/Private/CesiumPanel.h +++ b/Source/CesiumEditor/Private/CesiumPanel.h @@ -19,18 +19,11 @@ class CesiumPanel : public SCompoundWidget { const float InDeltaTime) override; private: - TSharedRef ServerSelector(); TSharedRef Toolbar(); TSharedRef LoginPanel(); TSharedRef MainIonQuickAddPanel(); TSharedRef BasicQuickAddPanel(); TSharedRef ConnectionStatus(); - TSharedRef - OnGenerateServerEntry(TObjectPtr pServer); - FText GetServerValueAsText() const; - void OnServerSelectionChanged( - TObjectPtr InItem, - ESelectInfo::Type InSeletionInfo); void addFromIon(); void uploadToIon(); diff --git a/Source/CesiumEditor/Private/CesiumServerSelector.cpp b/Source/CesiumEditor/Private/CesiumServerSelector.cpp new file mode 100644 index 000000000..39a91c181 --- /dev/null +++ b/Source/CesiumEditor/Private/CesiumServerSelector.cpp @@ -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>) + .OptionsSource(&FCesiumEditorModule::serverManager().GetServerList()) + .OnGenerateWidget(this, &CesiumServerSelector::OnGenerateServerEntry) + .OnSelectionChanged( + this, + &CesiumServerSelector::OnServerSelectionChanged) + .Content() + [SNew(STextBlock) + .Text(this, &CesiumServerSelector::GetServerValueAsText)]]; +} + +namespace { + +FText GetNameFromCesiumIonServerAsset( + const TObjectPtr& pServer) { + if (!pServer) + return FText::FromString("Error: No Cesium ion server configured."); + + std::shared_ptr 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 CesiumServerSelector::OnGenerateServerEntry( + TObjectPtr pServerAsset) { + return SNew(STextBlock).Text_Lambda([pServerAsset]() { + return GetNameFromCesiumIonServerAsset(pServerAsset); + }); +} + +void CesiumServerSelector::OnServerSelectionChanged( + TObjectPtr InItem, + ESelectInfo::Type InSeletionInfo) { + FCesiumEditorModule::serverManager().SetCurrent(InItem); + FCesiumEditorModule::serverManager().GetCurrentSession()->resume(); +} diff --git a/Source/CesiumEditor/Private/CesiumServerSelector.h b/Source/CesiumEditor/Private/CesiumServerSelector.h new file mode 100644 index 000000000..d0bf0e7ea --- /dev/null +++ b/Source/CesiumEditor/Private/CesiumServerSelector.h @@ -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 + OnGenerateServerEntry(TObjectPtr pServer); + + FText GetServerValueAsText() const; + + void OnServerSelectionChanged( + TObjectPtr InItem, + ESelectInfo::Type InSeletionInfo); +};