7
7
#include " CesiumCommands.h"
8
8
#include " CesiumEditor.h"
9
9
#include " CesiumIonRasterOverlay.h"
10
+ #include " CesiumIonServerSelector.h"
11
+ #include " CesiumRuntime.h"
10
12
#include " Editor.h"
11
13
#include " EditorModeManager.h"
12
14
#include " EngineUtils.h"
@@ -30,31 +32,28 @@ static FName ColumnName_Type = "Type";
30
32
static FName ColumnName_DateAdded = " DateAdded" ;
31
33
32
34
CesiumIonPanel::CesiumIonPanel ()
33
- : _connectionUpdatedDelegateHandle(),
34
- _assetsUpdatedDelegateHandle(),
35
- _pListView(nullptr ),
35
+ : _pListView(nullptr ),
36
36
_assets(),
37
- _pSelection(nullptr ) {
38
- this ->_connectionUpdatedDelegateHandle =
39
- FCesiumEditorModule::ion ().ConnectionUpdated .AddRaw (
37
+ _pSelection(nullptr ),
38
+ _pLastServer(nullptr ) {
39
+ this ->_serverChangedDelegateHandle =
40
+ FCesiumEditorModule::serverManager ().CurrentServerChanged .AddRaw (
40
41
this ,
41
- &CesiumIonPanel::Refresh);
42
- this ->_assetsUpdatedDelegateHandle =
43
- FCesiumEditorModule::ion ().AssetsUpdated .AddRaw (
44
- this ,
45
- &CesiumIonPanel::Refresh);
42
+ &CesiumIonPanel::OnServerChanged);
46
43
this ->_sortColumnName = ColumnName_DateAdded;
47
44
this ->_sortMode = EColumnSortMode::Type::Descending;
45
+ this ->OnServerChanged ();
48
46
}
49
47
50
48
CesiumIonPanel::~CesiumIonPanel () {
51
- FCesiumEditorModule::ion ().AssetsUpdated .Remove (
52
- this ->_assetsUpdatedDelegateHandle );
53
- FCesiumEditorModule::ion ().ConnectionUpdated .Remove (
54
- this ->_connectionUpdatedDelegateHandle );
49
+ this ->Subscribe (nullptr );
50
+ FCesiumEditorModule::serverManager ().CurrentServerChanged .Remove (
51
+ this ->_serverChangedDelegateHandle );
55
52
}
56
53
57
54
void CesiumIonPanel::Construct (const FArguments& InArgs) {
55
+ this ->Subscribe (FCesiumEditorModule::serverManager ().GetCurrentServer ());
56
+
58
57
// A function that returns the lambda that is used for rendering
59
58
// the sort mode indicator of the header column: If sorting is
60
59
// currently done based on the given name, then this will
@@ -111,6 +110,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
111
110
SVerticalBox::Slot ().AutoHeight ()
112
111
[
113
112
SNew (SHorizontalBox) +
113
+ SHorizontalBox::Slot ().Padding (5 .0f )[SNew (CesiumIonServerSelector)] +
114
114
// Add the refresh button at the upper left
115
115
SHorizontalBox::Slot ().HAlign (HAlign_Left).Padding (5 .0f )
116
116
[
@@ -123,7 +123,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
123
123
.Text (FText::FromString (TEXT (" Refresh" )))
124
124
.ToolTipText (FText::FromString (TEXT (" Refresh the asset list" )))
125
125
.OnClicked_Lambda ([this ]() {
126
- FCesiumEditorModule::ion ().refreshAssets ();
126
+ FCesiumEditorModule::serverManager ().GetCurrentSession ()-> refreshAssets ();
127
127
Refresh ();
128
128
return FReply::Handled ();
129
129
})
@@ -156,7 +156,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
156
156
];
157
157
// clang-format on
158
158
159
- FCesiumEditorModule::ion ().refreshAssets ();
159
+ FCesiumEditorModule::serverManager ().GetCurrentSession ()-> refreshAssets ();
160
160
}
161
161
162
162
void CesiumIonPanel::OnSortChange (
@@ -402,7 +402,11 @@ void CesiumIonPanel::ApplySorting() {
402
402
}
403
403
404
404
void CesiumIonPanel::Refresh () {
405
- const Assets& assets = FCesiumEditorModule::ion ().getAssets ();
405
+ if (!this ->_pListView )
406
+ return ;
407
+
408
+ const Assets& assets =
409
+ FCesiumEditorModule::serverManager ().GetCurrentSession ()->getAssets ();
406
410
407
411
this ->_assets .SetNum (assets.items .size ());
408
412
@@ -418,7 +422,7 @@ void CesiumIonPanel::Tick(
418
422
const FGeometry& AllottedGeometry,
419
423
const double InCurrentTime,
420
424
const float InDeltaTime) {
421
- FCesiumEditorModule::ion (). getAsyncSystem ().dispatchMainThreadTasks ();
425
+ getAsyncSystem ().dispatchMainThreadTasks ();
422
426
SCompoundWidget::Tick (AllottedGeometry, InCurrentTime, InDeltaTime);
423
427
}
424
428
@@ -428,6 +432,33 @@ void CesiumIonPanel::AssetSelected(
428
432
this ->_pSelection = item;
429
433
}
430
434
435
+ void CesiumIonPanel::Subscribe (UCesiumIonServer* pNewServer) {
436
+ if (this ->_pLastServer ) {
437
+ std::shared_ptr<CesiumIonSession> pLastSession =
438
+ FCesiumEditorModule::serverManager ().GetSession (this ->_pLastServer );
439
+ if (pLastSession) {
440
+ pLastSession->ConnectionUpdated .RemoveAll (this );
441
+ pLastSession->AssetsUpdated .RemoveAll (this );
442
+ }
443
+ }
444
+
445
+ this ->_pLastServer = pNewServer;
446
+
447
+ if (pNewServer) {
448
+ std::shared_ptr<CesiumIonSession> pSession =
449
+ FCesiumEditorModule::serverManager ().GetSession (pNewServer);
450
+ pSession->ConnectionUpdated .AddRaw (this , &CesiumIonPanel::Refresh);
451
+ pSession->AssetsUpdated .AddRaw (this , &CesiumIonPanel::Refresh);
452
+ }
453
+ }
454
+
455
+ void CesiumIonPanel::OnServerChanged () {
456
+ UCesiumIonServer* pNewServer =
457
+ FCesiumEditorModule::serverManager ().GetCurrentServer ();
458
+ this ->Subscribe (pNewServer);
459
+ this ->Refresh ();
460
+ }
461
+
431
462
void CesiumIonPanel::AddAsset (TSharedPtr<CesiumIonClient::Asset> item) {
432
463
433
464
if (isSupportedImagery (item)) {
@@ -445,7 +476,9 @@ void CesiumIonPanel::AddAsset(TSharedPtr<CesiumIonClient::Asset> item) {
445
476
}
446
477
447
478
void CesiumIonPanel::AddAssetToLevel (TSharedPtr<CesiumIonClient::Asset> item) {
448
- SelectCesiumIonToken::SelectAndAuthorizeToken ({item->id })
479
+ SelectCesiumIonToken::SelectAndAuthorizeToken (
480
+ FCesiumEditorModule::serverManager ().GetCurrentServer (),
481
+ {item->id })
449
482
.thenInMainThread ([item](const std::optional<Token>& /* maybeToken*/ ) {
450
483
// If token selection was canceled, or if an error occurred while
451
484
// selecting the token, ignore it and create the tileset anyway. It's
@@ -462,7 +495,9 @@ void CesiumIonPanel::AddAssetToLevel(TSharedPtr<CesiumIonClient::Asset> item) {
462
495
void CesiumIonPanel::AddOverlayToTerrain (
463
496
TSharedPtr<CesiumIonClient::Asset> item,
464
497
bool useAsBaseLayer) {
465
- SelectCesiumIonToken::SelectAndAuthorizeToken ({item->id })
498
+ SelectCesiumIonToken::SelectAndAuthorizeToken (
499
+ FCesiumEditorModule::serverManager ().GetCurrentServer (),
500
+ {item->id })
466
501
.thenInMainThread ([useAsBaseLayer, item](const std::optional<Token>&) {
467
502
UWorld* pCurrentWorld = GEditor->GetEditorWorldContext ().World ();
468
503
ULevel* pCurrentLevel = pCurrentWorld->GetCurrentLevel ();
0 commit comments