mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 08:02:23 -07:00
Save selection window config
This commit is contained in:
@@ -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<AActor> SelectedClass = GetSelectedActorClass();
|
||||
if (SelectedClass == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TArray<AActor*> Actors;
|
||||
for (TActorIterator<AActor> It(GetWorld(), SelectedClass); It; ++It)
|
||||
{
|
||||
AActor* Actor = *It;
|
||||
if (GetNameSafe(Actor) == SelectionName)
|
||||
{
|
||||
FCogDebugSettings::SetSelection(Actor);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TSubclassOf<AActor> UCogEngineWindow_Selection::GetSelectedActorClass() const
|
||||
{
|
||||
TSubclassOf<AActor> SelectedClass = AActor::StaticClass();
|
||||
if (ActorClasses.IsValidIndex(SelectedClassIndex))
|
||||
{
|
||||
SelectedClass = ActorClasses[SelectedClassIndex];
|
||||
}
|
||||
|
||||
return SelectedClass;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -129,14 +199,18 @@ bool UCogEngineWindow_Selection::DrawSelectionCombo()
|
||||
// Actor Class Combo
|
||||
//------------------------
|
||||
|
||||
TSubclassOf<AActor> 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<AActor> ItSubClass : SubClasses)
|
||||
for (int32 i = 0; i < ActorClasses.Num(); ++i)
|
||||
{
|
||||
if (ImGui::Selectable(TCHAR_TO_ANSI(*GetNameSafe(ItSubClass)), false))
|
||||
TSubclassOf<AActor> 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<AActor*> Actors;
|
||||
for (TActorIterator<AActor> It(GetWorld(), SelectedSubClass); It; ++It)
|
||||
for (TActorIterator<AActor> 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<AActor> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AActor> Value) { SelectedSubClass = Value; }
|
||||
const TArray<TSubclassOf<AActor>>& GetActorClasses() const { return ActorClasses; }
|
||||
|
||||
TSubclassOf<AActor> GetCurrentActorSubClass() const { return SelectedSubClass; }
|
||||
|
||||
const TArray<TSubclassOf<AActor>>& GetActorSubClasses() const { return SubClasses; }
|
||||
|
||||
void SetActorSubClasses(const TArray<TSubclassOf<AActor>>& Value) { SubClasses = Value; }
|
||||
void SetActorClasses(const TArray<TSubclassOf<AActor>>& 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<AActor> 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<AActor> SelectedSubClass;
|
||||
|
||||
TArray<TSubclassOf<AActor>> SubClasses;
|
||||
TArray<TSubclassOf<AActor>> ActorClasses;
|
||||
|
||||
ETraceTypeQuery TraceType = TraceTypeQuery1;
|
||||
};
|
||||
|
||||
@@ -164,8 +164,7 @@ void ACogSampleGameState::InitializeCog()
|
||||
CogWindowManager->CreateWindow<UCogEngineWindow_Plots>("Engine.Plots");
|
||||
|
||||
UCogEngineWindow_Selection* SelectionWindow = CogWindowManager->CreateWindow<UCogEngineWindow_Selection>("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<UCogEngineWindow_Scalability>("Engine.Scalability");
|
||||
|
||||
Reference in New Issue
Block a user