mirror of
https://github.com/Ed94/Cog.git
synced 2026-07-16 22:41:27 -07:00
First Submit
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
#include "CogWindow.h"
|
||||
|
||||
#include "CogDebugDraw.h"
|
||||
#include "CogDebugSettings.h"
|
||||
#include "CogWindowManager.h"
|
||||
#include "CogWindowWidgets.h"
|
||||
#include "Engine/World.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::SetFullName(const FString& InFullName)
|
||||
{
|
||||
FullName = InFullName;
|
||||
|
||||
TArray<FString> Path;
|
||||
int CharIndex = 0;
|
||||
if (FullName.FindLastChar(TEXT('.'), CharIndex))
|
||||
{
|
||||
Name = FullName.RightChop(CharIndex + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Name = FullName;
|
||||
}
|
||||
|
||||
ID = ImHashStr(TCHAR_TO_ANSI(*FullName));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool UCogWindow::CheckEditorVisibility()
|
||||
{
|
||||
const UWorld* World = GetWorld();
|
||||
if (World == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (World->WorldType != EWorldType::Game)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (World->WorldType == EWorldType::PIE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::Render(float DeltaTime)
|
||||
{
|
||||
ImGuiWindowFlags WindowFlags = 0;
|
||||
PreRender(WindowFlags);
|
||||
|
||||
if (ImGui::Begin(TCHAR_TO_ANSI(*GetTitle()), &bIsVisible, WindowFlags))
|
||||
{
|
||||
RenderContent();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::RenderTick(float DeltaTime)
|
||||
{
|
||||
SetSelection(FCogDebugSettings::GetSelection());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::GameTick(float DeltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::DrawMenuItem(const FString& MenuItemName)
|
||||
{
|
||||
if (bShowInsideMenu && bIsVisible == false)
|
||||
{
|
||||
static const ImVec2 TEXT_BASE_SIZE = ImGui::CalcTextSize("A");
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(TEXT_BASE_SIZE.x * 40, TEXT_BASE_SIZE.y * 1),
|
||||
ImVec2(TEXT_BASE_SIZE.x * 50, TEXT_BASE_SIZE.y * 60));
|
||||
|
||||
if (ImGui::BeginMenu(TCHAR_TO_ANSI(*MenuItemName)))
|
||||
{
|
||||
RenderContent();
|
||||
ImGui::EndMenu();
|
||||
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
bIsVisible = !bIsVisible;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::MenuItem(TCHAR_TO_ANSI(*MenuItemName), nullptr, &bIsVisible);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void UCogWindow::SetSelection(AActor* NewSelection)
|
||||
{
|
||||
if (CurrentSelection == NewSelection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AActor* OldActor = CurrentSelection.Get();
|
||||
|
||||
CurrentSelection = NewSelection;
|
||||
OnSelectionChanged(OldActor, NewSelection);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
APawn* UCogWindow::GetLocalPlayerPawn()
|
||||
{
|
||||
APlayerController* LocalPlayerController = GetLocalPlayerController();
|
||||
|
||||
if (LocalPlayerController == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
APawn* Pawn = LocalPlayerController->GetPawn();
|
||||
|
||||
return Pawn;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
APlayerController* UCogWindow::GetLocalPlayerController()
|
||||
{
|
||||
ULocalPlayer* LocalPlayer = GetLocalPlayer();
|
||||
if (LocalPlayer == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return LocalPlayer->PlayerController;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ULocalPlayer* UCogWindow::GetLocalPlayer()
|
||||
{
|
||||
const UWorld* World = GetWorld();
|
||||
if (World == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return World->GetFirstLocalPlayerFromController();
|
||||
}
|
||||
Reference in New Issue
Block a user