diff --git a/FicsItCam.uplugin b/FicsItCam.uplugin index 6f32b5f..119e5dd 100644 --- a/FicsItCam.uplugin +++ b/FicsItCam.uplugin @@ -2,7 +2,7 @@ "FileVersion": 3, "Version": 0, "VersionName": "0.3", - "SemVersion": "0.3.1", + "SemVersion": "0.3.2", "AcceptsAnyRemoteVersion": true, "FriendlyName": "FicsIt-Cam", "Description": "This mod allows you to create beautiful camera animations in-game.", diff --git a/Source/FicsItCam/Private/Data/Objects/FICParticleSystem.cpp b/Source/FicsItCam/Private/Data/Objects/FICParticleSystem.cpp index 287d923..09797fa 100644 --- a/Source/FicsItCam/Private/Data/Objects/FICParticleSystem.cpp +++ b/Source/FicsItCam/Private/Data/Objects/FICParticleSystem.cpp @@ -83,6 +83,7 @@ TSharedRef UFICParticleSystem::CreateDetailsWidget(UFICEditorContext* I } void UFICParticleSystem::InitEditor(UFICEditorContext* Context) { + check(ParticleSystemActor == nullptr); FVector Pos = Position.Get(Context->GetCurrentFrame()); FRotator Rot = Rotation.Get(Context->GetCurrentFrame()); ParticleSystemActor = GetWorld()->SpawnActor(Pos, Rot); @@ -93,11 +94,13 @@ void UFICParticleSystem::InitEditor(UFICEditorContext* Context) { } void UFICParticleSystem::ShutdownEditor(UFICEditorContext* Context) { + check(ParticleSystemActor != nullptr); ParticleSystemActor->Destroy(); ParticleSystemActor = nullptr; } void UFICParticleSystem::EditorUpdate(UFICEditorContext* Context, TSharedRef Attribute) { + check(ParticleSystemActor != nullptr); FVector Pos = FFICAttributePosition::FromEditorAttribute(Attribute->Get("Position")); FRotator Rot = FFICAttributeRotation::FromEditorAttribute(Attribute->Get("Rotation")); bool bActive = Attribute->Get("Active").GetActiveValue(); diff --git a/Source/FicsItCam/Private/Editor/FICChangeList.cpp b/Source/FicsItCam/Private/Editor/FICChangeList.cpp index 415b0a3..2c58ba5 100644 --- a/Source/FicsItCam/Private/Editor/FICChangeList.cpp +++ b/Source/FicsItCam/Private/Editor/FICChangeList.cpp @@ -39,16 +39,19 @@ void FFICChange_ActiveFrame::UndoChange() { } void FFICChange_AddSceneObject::RedoChange() { + UObject* SceneObject = Context->FindSceneObject(SceneObjectName); if (SceneObject) return; UObject* CDO = SceneObjectClass->GetDefaultObject(); SceneObject = Cast(CDO)->CreateNewObject(AFICSubsystem::GetFICSubsystem(Context), Context->GetScene()); + Cast(SceneObject)->SetSceneObjectName(SceneObjectName); Context->AddSceneObject(SceneObject); Context->SetSelectedSceneObject(SceneObject); - Cast(SceneObject)->GetRootAttribute().Set(Snapshot.ToSharedRef()); + if (Snapshot) Cast(SceneObject)->GetRootAttribute().Set(Snapshot.ToSharedRef()); Snapshot.Reset(); } void FFICChange_AddSceneObject::UndoChange() { + UObject* SceneObject = Context->FindSceneObject(SceneObjectName); if (!SceneObject) return; Snapshot = Cast(SceneObject)->GetRootAttribute().Get(); Context->RemoveSceneObject(SceneObject); @@ -58,19 +61,22 @@ void FFICChange_AddSceneObject::UndoChange() { FFICChange_RemoveSceneObject::FFICChange_RemoveSceneObject(UFICEditorContext* InContext, UObject* InSceneObject) : Context(InContext), SceneObjectClass(InSceneObject->GetClass()), + SceneObjectName(Cast(InSceneObject)->GetSceneObjectName()), Snapshot(Cast(InSceneObject)->GetRootAttribute().Get()) {} void FFICChange_RemoveSceneObject::RedoChange() { + UObject* SceneObject = Context->FindSceneObject(SceneObjectName); if (!SceneObject) return; Snapshot = Cast(SceneObject)->GetRootAttribute().Get(); Context->RemoveSceneObject(SceneObject); - SceneObject = nullptr; } void FFICChange_RemoveSceneObject::UndoChange() { + UObject* SceneObject = Context->FindSceneObject(SceneObjectName); if (SceneObject) return; UObject* CDO = SceneObjectClass->GetDefaultObject(); SceneObject = Cast(CDO)->CreateNewObject(AFICSubsystem::GetFICSubsystem(Context), Context->GetScene()); + Cast(SceneObject)->SetSceneObjectName(SceneObjectName); Cast(SceneObject)->GetRootAttribute().Set(Snapshot.ToSharedRef()); Snapshot.Reset(); Context->AddSceneObject(SceneObject); diff --git a/Source/FicsItCam/Private/Editor/FICEditorContext.cpp b/Source/FicsItCam/Private/Editor/FICEditorContext.cpp index d566c6a..e7a4104 100644 --- a/Source/FicsItCam/Private/Editor/FICEditorContext.cpp +++ b/Source/FicsItCam/Private/Editor/FICEditorContext.cpp @@ -173,6 +173,15 @@ void UFICEditorContext::MoveSceneObject(UObject* SceneObject, int Delta) { SetSelectedSceneObject(SceneObject); } +UObject* UFICEditorContext::FindSceneObject(FString SceneObjectName) const { + for (UObject* Object : Scene->GetSceneObjects()) { + if (Cast(Object)->GetSceneObjectName() == SceneObjectName) { + return Object; + } + } + return nullptr; +} + AFICScene* UFICEditorContext::GetScene() const { return Scene; } diff --git a/Source/FicsItCam/Private/Editor/UI/FICEditor.cpp b/Source/FicsItCam/Private/Editor/UI/FICEditor.cpp index 69b4ff5..cbb2b6c 100644 --- a/Source/FicsItCam/Private/Editor/UI/FICEditor.cpp +++ b/Source/FicsItCam/Private/Editor/UI/FICEditor.cpp @@ -145,6 +145,7 @@ FMenuBarBuilder SFICEditor::CreateMenuBar() { FMenuBarBuilder MenuBarBuilder(nullptr); MenuBarBuilder.AddMenuEntry(LOCTEXT("Exit", "Exit"), LOCTEXT("ExitTT", "Closes and Exits the Editor"), FSlateIcon(), FExecuteAction::CreateLambda([this]() { TabManager->SavePersistentLayout(); + FSlateApplication::Get().ClearAllUserFocus(); AFICEditorSubsystem::GetFICEditorSubsystem(Context->GetScene()->GetWorld())->CloseEditor(); })); MenuBarBuilder.AddPullDownMenu(LOCTEXT("View", "View"), LOCTEXT("ViewTT", "Views, Panels & Windows"), FNewMenuDelegate::CreateLambda([this](FMenuBuilder& MenuBuilder) { diff --git a/Source/FicsItCam/Private/Editor/UI/FICSceneObjectOutliner.cpp b/Source/FicsItCam/Private/Editor/UI/FICSceneObjectOutliner.cpp index f5107f8..d38748b 100644 --- a/Source/FicsItCam/Private/Editor/UI/FICSceneObjectOutliner.cpp +++ b/Source/FicsItCam/Private/Editor/UI/FICSceneObjectOutliner.cpp @@ -119,6 +119,7 @@ void SFICSceneObjectOutliner::Construct(const FArguments& InArgs, UFICEditorCont if (Event.GetKey() == EKeys::Delete) { TArray> Selected; if (SceneObjectListWidget->GetSelectedItems(Selected) > 0) { + Context->ChangeList.PushChange(MakeShared(Context, Selected[0]->SceneObject)); Context->RemoveSceneObject(Selected[0]->SceneObject); } return FReply::Handled(); diff --git a/Source/FicsItCam/Private/Editor/UI/FICTimeline.cpp b/Source/FicsItCam/Private/Editor/UI/FICTimeline.cpp index b08bce9..a1d264a 100644 --- a/Source/FicsItCam/Private/Editor/UI/FICTimeline.cpp +++ b/Source/FicsItCam/Private/Editor/UI/FICTimeline.cpp @@ -65,7 +65,7 @@ void SFICTimelinePanel::Construct(const FArguments& InArgs, UFICEditorContext* I }) .MinValue(TNumericLimits::Min()) .OnValueCommitted_Lambda([this](int64 Value, ETextCommit::Type) { - Context->GetScene()->AnimationRange.Begin = Value; + Context->GetScene()->AnimationRange.SetBegin_Clamped(Value); }) ] ] @@ -305,7 +305,7 @@ void SFICTimelinePanel::Construct(const FArguments& InArgs, UFICEditorContext* I }) .MaxValue(TNumericLimits::Max()) .OnValueCommitted_Lambda([this](int64 Value, ETextCommit::Type) { - Context->GetScene()->AnimationRange.End = FMath::Clamp(Value, Context->GetScene()->AnimationRange.Begin+1, TNumericLimits::Max()); + Context->GetScene()->AnimationRange.SetEnd_Clamped(Value); }) ] ] diff --git a/Source/FicsItCam/Public/Data/FICTypes.h b/Source/FicsItCam/Public/Data/FICTypes.h index 4cc3ea4..97f44c9 100644 --- a/Source/FicsItCam/Public/Data/FICTypes.h +++ b/Source/FicsItCam/Public/Data/FICTypes.h @@ -83,6 +83,14 @@ struct FFICFrameRange { return FFICFrameRange(Begin - Frame, End - Frame); } + void SetBegin_Clamped(FICFrame InBegin, bool bInclusive = false) { + Begin = FMath::Min(InBegin, End - (bInclusive ? 0 : 1)); + } + + void SetEnd_Clamped(FICFrame InEnd, bool bInclusive = false) { + End = FMath::Max(InEnd, Begin + (bInclusive ? 0 : 1)); + } + FFICFrameRangeIterator begin() const { return FFICFrameRangeIterator(Begin); } diff --git a/Source/FicsItCam/Public/Editor/FICChangeList.h b/Source/FicsItCam/Public/Editor/FICChangeList.h index 1dc24b2..4443aca 100644 --- a/Source/FicsItCam/Public/Editor/FICChangeList.h +++ b/Source/FicsItCam/Public/Editor/FICChangeList.h @@ -1,6 +1,7 @@ #pragma once #include "Data/Attributes/FICAttribute.h" +#include "Data/Objects/FICSceneObject.h" class FFICChangeList; @@ -95,10 +96,10 @@ struct FFICChange_Attribute : public FFICChange { struct FFICChange_AddSceneObject : public FFICChange { UFICEditorContext* Context; UClass* SceneObjectClass; - UObject* SceneObject; + FString SceneObjectName; TSharedPtr Snapshot; - FFICChange_AddSceneObject(UFICEditorContext* InContext, UObject* InSceneObject) : Context(InContext), SceneObjectClass(InSceneObject->GetClass()), SceneObject(InSceneObject) {} + FFICChange_AddSceneObject(UFICEditorContext* InContext, UObject* InSceneObject) : Context(InContext), SceneObjectClass(InSceneObject->GetClass()), SceneObjectName(Cast(InSceneObject)->GetSceneObjectName()) {} virtual void RedoChange() override; virtual void UndoChange() override; @@ -110,7 +111,7 @@ struct FFICChange_AddSceneObject : public FFICChange { struct FFICChange_RemoveSceneObject : public FFICChange { UFICEditorContext* Context; - UObject* SceneObject = nullptr; + FString SceneObjectName = ""; UClass* SceneObjectClass; TSharedPtr Snapshot; diff --git a/Source/FicsItCam/Public/Editor/FICEditorContext.h b/Source/FicsItCam/Public/Editor/FICEditorContext.h index bc2ace2..171a3b5 100644 --- a/Source/FicsItCam/Public/Editor/FICEditorContext.h +++ b/Source/FicsItCam/Public/Editor/FICEditorContext.h @@ -94,6 +94,7 @@ class UFICEditorContext : public UObject, public FTickableGameObject { void AddSceneObject(UObject* SceneObject); void RemoveSceneObject(UObject* SceneObject); void MoveSceneObject(UObject* SceneObject, int Delta); + UObject* FindSceneObject(FString SceneObjectName) const; AFICScene* GetScene() const; UFICCamera* GetCamera();