diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp index 2002109..f964a86 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp @@ -25,7 +25,77 @@ void UCogEngineWindow_Selection::RenderHelp() UCogEngineWindow_Selection::UCogEngineWindow_Selection() { bHasMenu = true; - SubClasses = { AActor::StaticClass(), ACharacter::StaticClass() }; + ActorClasses = { AActor::StaticClass(), ACharacter::StaticClass() }; +} + + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogEngineWindow_Selection::ResetConfig() +{ + Super::ResetConfig(); + + SelectedClassIndex = 0; + SelectionName = FString(); + bReapplySelection = true; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogEngineWindow_Selection::PreSaveConfig() +{ + Super::PreSaveConfig(); + + SelectionName = GetNameSafe(GetSelection()); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogEngineWindow_Selection::PostInitProperties() +{ + Super::PostInitProperties(); + + TryReapplySelection(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogEngineWindow_Selection::TryReapplySelection() const +{ + if (bReapplySelection == false) + { + return; + } + + if (SelectionName.IsEmpty()) + { + return; + } + + TSubclassOf SelectedClass = GetSelectedActorClass(); + if (SelectedClass == nullptr) + { + return; + } + + TArray Actors; + for (TActorIterator It(GetWorld(), SelectedClass); It; ++It) + { + AActor* Actor = *It; + if (GetNameSafe(Actor) == SelectionName) + { + FCogDebugSettings::SetSelection(Actor); + } + + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +TSubclassOf UCogEngineWindow_Selection::GetSelectedActorClass() const +{ + TSubclassOf SelectedClass = AActor::StaticClass(); + if (ActorClasses.IsValidIndex(SelectedClassIndex)) + { + SelectedClass = ActorClasses[SelectedClassIndex]; + } + + return SelectedClass; } //-------------------------------------------------------------------------------------------------------------------------- @@ -129,14 +199,18 @@ bool UCogEngineWindow_Selection::DrawSelectionCombo() // Actor Class Combo //------------------------ + TSubclassOf SelectedClass = GetSelectedActorClass(); + ImGui::SetNextItemWidth(-1); - if (ImGui::BeginCombo("##SelectionType", TCHAR_TO_ANSI(*GetNameSafe(SelectedSubClass)))) + if (ImGui::BeginCombo("##SelectionType", TCHAR_TO_ANSI(*GetNameSafe(SelectedClass)))) { - for (TSubclassOf ItSubClass : SubClasses) + for (int32 i = 0; i < ActorClasses.Num(); ++i) { - if (ImGui::Selectable(TCHAR_TO_ANSI(*GetNameSafe(ItSubClass)), false)) + TSubclassOf SubClass = ActorClasses[i]; + if (ImGui::Selectable(TCHAR_TO_ANSI(*GetNameSafe(SubClass)), false)) { - SelectedSubClass = ItSubClass; + SelectedClassIndex = i; + SelectedClass = SubClass; } } ImGui::EndCombo(); @@ -150,7 +224,7 @@ bool UCogEngineWindow_Selection::DrawSelectionCombo() ImGui::BeginChild("ActorList", ImVec2(-1, -1), false); TArray Actors; - for (TActorIterator It(GetWorld(), SelectedSubClass); It; ++It) + for (TActorIterator It(GetWorld(), SelectedClass); It; ++It) { AActor* Actor = *It; Actors.Add(Actor); @@ -276,12 +350,14 @@ void UCogEngineWindow_Selection::TickSelectionMode() return; } + ImDrawList* DrawList = ImGui::GetBackgroundDrawList(); DrawList->AddRect(ImVec2(0, 0), ImGui::GetIO().DisplaySize, IM_COL32(255, 0, 0, 128), 0.0f, 0, 20.0f); FCogWindowWidgets::AddTextWithShadow(DrawList, ImVec2(20, 20), IM_COL32(255, 255, 255, 255), "Picking Mode. \n[LMB] Pick \n[RMB] Cancel"); - AActor* HoveredActor = nullptr; + TSubclassOf SelectedActorClass = GetSelectedActorClass(); + AActor* HoveredActor = nullptr; FVector WorldOrigin, WorldDirection; if (UGameplayStatics::DeprojectScreenToWorld(PlayerController, FCogImguiHelper::ToVector2D(ImGui::GetMousePos()), WorldOrigin, WorldDirection)) { @@ -292,7 +368,7 @@ void UCogEngineWindow_Selection::TickSelectionMode() { if (HitResult.GetActor() != nullptr) { - if (HitResult.GetActor()->GetClass()->IsChildOf(SelectedSubClass)) + if (SelectedActorClass == nullptr || HitResult.GetActor()->GetClass()->IsChildOf(SelectedActorClass)) { HoveredActor = HitResult.GetActor(); } @@ -478,15 +554,15 @@ void UCogEngineWindow_Selection::RenderMainMenuWidget(bool Draw, float& Width) ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f)); ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); ImGui::SameLine(); - FString SelectionName = GetNameSafe(GlobalSelection); + FString CurrentSelectionName = GetNameSafe(GlobalSelection); - if (ImGui::Button(TCHAR_TO_ANSI(*SelectionName), ImVec2(SelectionButtonWidth, 0))) + if (ImGui::Button(TCHAR_TO_ANSI(*CurrentSelectionName), ImVec2(SelectionButtonWidth, 0))) { ImGui::OpenPopup("SelectionPopup"); } if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Current Selection: %s", TCHAR_TO_ANSI(*SelectionName)); + ImGui::SetTooltip("Current Selection: %s", TCHAR_TO_ANSI(*CurrentSelectionName)); } ImGui::PopStyleColor(1); @@ -514,4 +590,4 @@ void UCogEngineWindow_Selection::RenderMainMenuWidget(bool Draw, float& Width) ImGui::PopStyleColor(1); ImGui::PopStyleVar(1); } -} \ No newline at end of file +} diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h index 3d318f3..e3e78ba 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h @@ -5,7 +5,7 @@ #include "CogWindow.h" #include "CogEngineWindow_Selection.generated.h" -UCLASS() +UCLASS(Config = Cog) class COGENGINE_API UCogEngineWindow_Selection : public UCogWindow { GENERATED_BODY() @@ -16,20 +16,24 @@ public: bool GetIsSelecting() const { return bSelectionModeActive; } - void SetCurrentActorSubClass(TSubclassOf Value) { SelectedSubClass = Value; } + const TArray>& GetActorClasses() const { return ActorClasses; } - TSubclassOf GetCurrentActorSubClass() const { return SelectedSubClass; } - - const TArray>& GetActorSubClasses() const { return SubClasses; } - - void SetActorSubClasses(const TArray>& Value) { SubClasses = Value; } + void SetActorClasses(const TArray>& Value) { ActorClasses = Value; } ETraceTypeQuery GetTraceType() const { return TraceType; } void SetTraceType(ETraceTypeQuery Value) { TraceType = Value; } + void TryReapplySelection() const; + protected: + virtual void ResetConfig() override; + + virtual void PreSaveConfig() override; + + virtual void PostInitProperties() override; + virtual void RenderHelp() override; virtual void RenderTick(float DeltaTime) override; @@ -48,6 +52,8 @@ protected: private: + TSubclassOf GetSelectedActorClass() const; + void TickSelectionMode(); void ToggleSelectionMode(); @@ -58,6 +64,15 @@ private: bool ComputeBoundingBoxScreenPosition(const APlayerController* PlayerController, const FVector& Origin, const FVector& Extent, FVector2D& Min, FVector2D& Max); + UPROPERTY(Config) + bool bReapplySelection = true; + + UPROPERTY(Config) + FString SelectionName; + + UPROPERTY(Config) + int32 SelectedClassIndex = 0; + FVector LastSelectedActorLocation = FVector::ZeroVector; bool bSelectionModeActive = false; @@ -66,9 +81,7 @@ private: int32 WaitInputReleased = 0; - TSubclassOf SelectedSubClass; - - TArray> SubClasses; + TArray> ActorClasses; ETraceTypeQuery TraceType = TraceTypeQuery1; }; diff --git a/Source/CogSample/CogSampleGameState.cpp b/Source/CogSample/CogSampleGameState.cpp index 994c2db..31a7690 100644 --- a/Source/CogSample/CogSampleGameState.cpp +++ b/Source/CogSample/CogSampleGameState.cpp @@ -164,8 +164,7 @@ void ACogSampleGameState::InitializeCog() CogWindowManager->CreateWindow("Engine.Plots"); UCogEngineWindow_Selection* SelectionWindow = CogWindowManager->CreateWindow("Engine.Selection"); - SelectionWindow->SetActorSubClasses({ AActor::StaticClass(), AGameModeBase::StaticClass(), AGameStateBase::StaticClass(), ACharacter::StaticClass() }); - SelectionWindow->SetCurrentActorSubClass(ACharacter::StaticClass()); + SelectionWindow->SetActorClasses({ ACharacter::StaticClass(), AActor::StaticClass(), AGameModeBase::StaticClass(), AGameStateBase::StaticClass() }); SelectionWindow->SetTraceType(UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_Pawn)); CogWindowManager->CreateWindow("Engine.Scalability");