mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-06 23:58:48 +00:00
CogWindow: simplify how CogWidgets are rendered
Remove the need to specify the widgets width to be able to right them. Instead widgets are rendered in a table which left/center/right align automatically.
This commit is contained in:
@@ -243,7 +243,7 @@ void FCogEngineWindow_Cheats::RenderContent()
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
FCogWindowWidgets::SearchBar(Filter);
|
||||
FCogWindowWidgets::SearchBar("##Filter", Filter);
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ void FCogEngineWindow_Inspector::RenderMenu()
|
||||
//-----------------------------------
|
||||
// Search
|
||||
//-----------------------------------
|
||||
FCogWindowWidgets::SearchBar(Filter, -FCogWindowWidgets::GetFontWidth() * 9);
|
||||
FCogWindowWidgets::SearchBar("##Filter", Filter, -FCogWindowWidgets::GetFontWidth() * 9);
|
||||
|
||||
//-----------------------------------
|
||||
// Options
|
||||
|
||||
@@ -184,7 +184,7 @@ void FCogEngineWindow_OutputLog::RenderContent()
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
FCogWindowWidgets::SearchBar(Filter);
|
||||
FCogWindowWidgets::SearchBar("##Filter", Filter);
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "GameFramework/Character.h"
|
||||
#include "HAL/IConsoleManager.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
FString FCogEngineWindow_Selection::ToggleSelectionModeCommand = TEXT("Cog.ToggleSelectionMode");
|
||||
@@ -25,7 +26,7 @@ void FCogEngineWindow_Selection::Initialize()
|
||||
Super::Initialize();
|
||||
|
||||
bHasMenu = true;
|
||||
bHasWidget = true;
|
||||
bHasWidget = 2;
|
||||
ActorClasses = { AActor::StaticClass(), ACharacter::StaticClass() };
|
||||
|
||||
Config = GetConfig<UCogEngineConfig_Selection>();
|
||||
@@ -294,77 +295,30 @@ void FCogEngineWindow_Selection::TickSelectionMode()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
float FCogEngineWindow_Selection::GetMainMenuWidgetWidth(int32 SubWidgetIndex, float MaxWidth)
|
||||
void FCogEngineWindow_Selection::RenderMainMenuWidget()
|
||||
{
|
||||
switch (SubWidgetIndex)
|
||||
if (ImGui::MenuItem("Pick"))
|
||||
{
|
||||
case 0: return FCogWindowWidgets::GetFontWidth() * 6;
|
||||
case 1: return FMath::Min(FMath::Max(MaxWidth, FCogWindowWidgets::GetFontWidth() * 10), FCogWindowWidgets::GetFontWidth() * 30);
|
||||
case 2: return FCogWindowWidgets::GetFontWidth() * 3;
|
||||
GetOwner()->SetActivateSelectionMode(true);
|
||||
HackWaitInputRelease();
|
||||
}
|
||||
RenderPickButtonTooltip();
|
||||
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Selection::RenderMainMenuWidget(int32 SubWidgetIndex, float Width)
|
||||
{
|
||||
//-----------------------------------
|
||||
// Pick Button
|
||||
//-----------------------------------
|
||||
if (SubWidgetIndex == 0)
|
||||
//TODO: Could be replaced by a BeginMenu
|
||||
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15);
|
||||
AActor* NewSelection = nullptr;
|
||||
if (FCogWindowWidgets::MenuActorsCombo(
|
||||
"MenuActorSelection",
|
||||
NewSelection,
|
||||
*GetWorld(),
|
||||
ActorClasses,
|
||||
Config->SelectedClassIndex,
|
||||
&Filter,
|
||||
GetLocalPlayerPawn(),
|
||||
[this](AActor& Actor) { RenderActorContextMenu(Actor); }))
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
|
||||
|
||||
if (ImGui::Button("Pick", ImVec2(Width, 0)))
|
||||
{
|
||||
GetOwner()->SetActivateSelectionMode(true);
|
||||
HackWaitInputRelease();
|
||||
}
|
||||
RenderPickButtonTooltip();
|
||||
|
||||
ImGui::PopStyleColor(1);
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
else if (SubWidgetIndex == 1)
|
||||
{
|
||||
ImGui::SetNextItemWidth(Width);
|
||||
AActor* NewSelection = nullptr;
|
||||
if (FCogWindowWidgets::MenuActorsCombo(
|
||||
"MenuActorSelection",
|
||||
NewSelection,
|
||||
*GetWorld(),
|
||||
ActorClasses,
|
||||
Config->SelectedClassIndex,
|
||||
&Filter,
|
||||
GetLocalPlayerPawn(),
|
||||
[this](AActor& Actor) { RenderActorContextMenu(Actor); }))
|
||||
{
|
||||
SetGlobalSelection(NewSelection);
|
||||
}
|
||||
}
|
||||
else if (SubWidgetIndex == 2)
|
||||
{
|
||||
//-----------------------------------
|
||||
// Reset Button
|
||||
//-----------------------------------
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
|
||||
if (ImGui::Button("X", ImVec2(Width, 0)))
|
||||
{
|
||||
SetGlobalSelection(nullptr);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::SetTooltip("Reset the selection to the controlled actor.");
|
||||
}
|
||||
ImGui::PopStyleColor(1);
|
||||
ImGui::PopStyleVar(1);
|
||||
}
|
||||
SetGlobalSelection(NewSelection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ void FCogEngineWindow_Skeleton::RenderContent()
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
FCogWindowWidgets::SearchBar(Filter);
|
||||
FCogWindowWidgets::SearchBar("##Filter", Filter);
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ void FCogEngineWindow_Stats::Initialize()
|
||||
{
|
||||
Super::Initialize();
|
||||
|
||||
bHasWidget = true;
|
||||
bHasWidget = 2;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -64,30 +64,14 @@ void FCogEngineWindow_Stats::RenderContent()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
float FCogEngineWindow_Stats::GetMainMenuWidgetWidth(const int32 SubWidgetIndex, float MaxWidth)
|
||||
void FCogEngineWindow_Stats::RenderMainMenuWidget()
|
||||
{
|
||||
const APlayerController* PlayerController = GetLocalPlayerController();
|
||||
const UNetConnection* Connection = PlayerController != nullptr ? PlayerController->GetNetConnection() : nullptr;
|
||||
|
||||
switch (SubWidgetIndex)
|
||||
{
|
||||
case 0: return FCogWindowWidgets::GetFontWidth() * 8;
|
||||
case 1: return Connection != nullptr ? FCogWindowWidgets::GetFontWidth() * 7 : 0.0f;
|
||||
case 2: return Connection != nullptr ? FCogWindowWidgets::GetFontWidth() * 7 : 0.0f;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogEngineWindow_Stats::RenderMainMenuWidget(const int32 SubWidgetIndex, const float Width)
|
||||
{
|
||||
switch (SubWidgetIndex)
|
||||
{
|
||||
case 0: RenderMainMenuWidgetFramerate(Width); break;
|
||||
case 1: RenderMainMenuWidgetPing(Width); break;
|
||||
case 2: RenderMainMenuWidgetPacketLoss(Width); break;
|
||||
}
|
||||
|
||||
RenderMainMenuWidgetFramerate(FCogWindowWidgets::GetFontWidth() * 8);
|
||||
RenderMainMenuWidgetPing(Connection != nullptr ? FCogWindowWidgets::GetFontWidth() * 7 : 0.0f);
|
||||
RenderMainMenuWidgetPacketLoss(Connection != nullptr ? FCogWindowWidgets::GetFontWidth() * 7 : 0.0f);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -96,22 +80,12 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetFramerate(const float Width)
|
||||
extern ENGINE_API float GAverageFPS;
|
||||
const int32 Fps = (int32)GAverageFPS;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, GetFpsColor(Fps));
|
||||
|
||||
if (ImGui::Button(TCHAR_TO_ANSI(*FString::Printf(TEXT("%3dfps###FramerateButton"), Fps)), ImVec2(Width, 0.0f)))
|
||||
{
|
||||
ImGui::OpenPopup("FrameratePopup");
|
||||
}
|
||||
|
||||
const bool Open = ImGui::BeginMenu(TCHAR_TO_ANSI(*FString::Printf(TEXT("%3dfps###FramerateButton"), Fps)));
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
ImGui::SetItemTooltip("Framerate");
|
||||
|
||||
if (ImGui::BeginPopup("FrameratePopup"))
|
||||
if (Open)
|
||||
{
|
||||
ImGui::Text("Fps");
|
||||
ImGui::SameLine();
|
||||
@@ -123,8 +97,10 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetFramerate(const float Width)
|
||||
GEngine->SetMaxFPS(MaxFps);
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::SetItemTooltip("Framerate");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -138,25 +114,15 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPing(const float Width)
|
||||
}
|
||||
|
||||
const float Ping = PlayerState->GetPingInMilliseconds();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, GetPingColor(Ping));
|
||||
|
||||
if (ImGui::Button(TCHAR_TO_ANSI(*FString::Printf(TEXT("%3dms###PingButton"), (int32)Ping)), ImVec2(Width, 0.0f)))
|
||||
{
|
||||
ImGui::OpenPopup("PingPopup");
|
||||
}
|
||||
|
||||
const bool Open = ImGui::BeginMenu(TCHAR_TO_ANSI(*FString::Printf(TEXT("%3dms###PingButton"), (int32)Ping)));
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
ImGui::SetItemTooltip("Ping");
|
||||
|
||||
#if DO_ENABLE_NET_TEST
|
||||
if (ImGui::BeginPopup("PingPopup"))
|
||||
if (Open)
|
||||
{
|
||||
|
||||
FWorldContext& WorldContext = GEngine->GetWorldContextFromWorldChecked(GetWorld());
|
||||
if (WorldContext.ActiveNetDrivers.Num() > 0)
|
||||
{
|
||||
@@ -171,9 +137,11 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPing(const float Width)
|
||||
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
#endif //DO_ENABLE_NET_TEST
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -208,7 +176,6 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPacketLoss(const float Width)
|
||||
#if DO_ENABLE_NET_TEST
|
||||
if (ImGui::BeginPopup("PacketLossPopup"))
|
||||
{
|
||||
|
||||
FWorldContext& WorldContext = GEngine->GetWorldContextFromWorldChecked(GetWorld());
|
||||
if (WorldContext.ActiveNetDrivers.Num() > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user