Cog Sample: Adding more gameplay

Cog Sample: Make Area a component instead of an actor
Cog Sample: Add Basic actor for Projectiles, Areas, etc...
Cog Sample: Start to add Projectile
Cog Sample: Start to add SpawnPrediction
This commit is contained in:
Arnaud Jamin
2023-10-26 12:33:50 -04:00
parent 07e9db10af
commit 42ca1afc6a
67 changed files with 2462 additions and 669 deletions
@@ -1,6 +1,7 @@
#include "CogEngineWindow_NetEmulation.h"
#include "CogEngineWindow_Stats.h"
#include "CogWindowWidgets.h"
#include "Engine/Engine.h"
#include "Engine/NetDriver.h"
#include "Engine/NetConnection.h"
@@ -111,7 +112,7 @@ void UCogEngineWindow_NetEmulation::DrawControls()
//-------------------------------------------------------------------------------------------
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::DragInt("Lag Min", &Settings.PktLagMin, 1.0f, 0, INT_MAX, "%d ms"))
if (ImGui::DragInt("Lag Min", &Settings.PktLagMin, 5.0f, 0, INT_MAX, "%d ms"))
{
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
}
@@ -123,7 +124,7 @@ void UCogEngineWindow_NetEmulation::DrawControls()
//-------------------------------------------------------------------------------------------
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::DragInt("Lag Max", &Settings.PktLagMax, 1.0f, 0, INT_MAX, "%d ms"))
if (ImGui::DragInt("Lag Max", &Settings.PktLagMax, 5.0f, 0, INT_MAX, "%d ms"))
{
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
}
@@ -184,7 +185,7 @@ void UCogEngineWindow_NetEmulation::DrawControls()
//-------------------------------------------------------------------------------------------
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::DragInt("Incoming Lag Min", &Settings.PktIncomingLagMin, 1.0f, 0, INT_MAX, "%d ms"))
if (ImGui::DragInt("Incoming Lag Min", &Settings.PktIncomingLagMin, 5.0f, 0, INT_MAX, "%d ms"))
{
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
}
@@ -196,7 +197,7 @@ void UCogEngineWindow_NetEmulation::DrawControls()
//-------------------------------------------------------------------------------------------
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::DragInt("Incoming Lag Max", &Settings.PktIncomingLagMax, 1.0f, 0, INT_MAX, "%d ms"))
if (ImGui::DragInt("Incoming Lag Max", &Settings.PktIncomingLagMax, 5.0f, 0, INT_MAX, "%d ms"))
{
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
}
@@ -558,40 +558,32 @@ bool UCogEngineWindow_Selection::ComputeBoundingBoxScreenPosition(const APlayerC
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Selection::RenderMainMenuWidget(bool Draw, float& Width)
float UCogEngineWindow_Selection::GetMainMenuWidgetWidth(int32 SubWidgetIndex, float MaxWidth)
{
const float PickButtonWidth = FCogWindowWidgets::GetFontWidth() * 6;
const float SelectionButtonWidth = FCogWindowWidgets::GetFontWidth() * 30;
const float ResetButtonWidth = FCogWindowWidgets::GetFontWidth() * 3;
Width = PickButtonWidth + SelectionButtonWidth + ResetButtonWidth;
if (Draw == false)
switch (SubWidgetIndex)
{
return;
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;
}
if (ImGui::BeginPopup("SelectionPopup"))
{
ImGui::BeginChild("Popup", ImVec2(Width, FCogWindowWidgets::GetFontWidth() * 40), false);
return -1.0f;
}
if (DrawSelectionCombo())
{
ImGui::CloseCurrentPopup();
}
ImGui::EndChild();
ImGui::EndPopup();
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Selection::RenderMainMenuWidget(int32 SubWidgetIndex, float Width)
{
//-----------------------------------
// Pick Button
//-----------------------------------
if (SubWidgetIndex == 0)
{
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(PickButtonWidth, 0)))
if (ImGui::Button("Pick", ImVec2(Width, 0)))
{
ActivateSelectionMode();
HackWaitInputRelease();
@@ -601,52 +593,67 @@ void UCogEngineWindow_Selection::RenderMainMenuWidget(bool Draw, float& Width)
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(2);
}
AActor* GlobalSelection = FCogDebugSettings::GetSelection();
//-----------------------------------
// Selection
//-----------------------------------
else if (SubWidgetIndex == 1)
{
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::SameLine();
FString CurrentSelectionName = GetActorName(GlobalSelection);
if (ImGui::BeginPopup("SelectionPopup"))
{
ImGui::BeginChild("Popup", ImVec2(Width, FCogWindowWidgets::GetFontWidth() * 40), false);
if (ImGui::Button(TCHAR_TO_ANSI(*CurrentSelectionName), ImVec2(SelectionButtonWidth, 0)))
{
ImGui::OpenPopup("SelectionPopup");
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Current Selection: %s", TCHAR_TO_ANSI(*CurrentSelectionName));
if (DrawSelectionCombo())
{
ImGui::CloseCurrentPopup();
}
ImGui::EndChild();
ImGui::EndPopup();
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(2);
AActor* GlobalSelection = FCogDebugSettings::GetSelection();
DrawActorContextMenu(GlobalSelection);
//-----------------------------------
// Selection
//-----------------------------------
{
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));
FString CurrentSelectionName = GetActorName(GlobalSelection);
if (ImGui::Button(TCHAR_TO_ANSI(*CurrentSelectionName), ImVec2(Width, 0.0f)))
{
ImGui::OpenPopup("SelectionPopup");
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Current Selection: %s", TCHAR_TO_ANSI(*CurrentSelectionName));
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(2);
DrawActorContextMenu(GlobalSelection);
}
}
//-----------------------------------
// Reset Button
//-----------------------------------
else if (SubWidgetIndex == 2)
{
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
ImGui::SameLine();
if (ImGui::Button("X", ImVec2(ResetButtonWidth, 0)))
//-----------------------------------
// Reset Button
//-----------------------------------
{
SetGlobalSelection(nullptr);
ImGui::CloseCurrentPopup();
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);
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Reset the selection to the controlled actor.");
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(1);
}
}
@@ -2,8 +2,10 @@
#include "CogWindowWidgets.h"
#include "Engine/Engine.h"
#include "Engine/NetDriver.h"
#include "Engine/NetConnection.h"
#include "GameFramework/PlayerState.h"
#include "Net/NetPing.h"
ImVec4 StatRedColor(1.0f, 0.4f, 0.3f, 1.0f);
ImVec4 StatOrangeColor(1.0f, 0.7f, 0.4f, 1.0f);
@@ -53,39 +55,170 @@ void UCogEngineWindow_Stats::RenderContent()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Stats::RenderMainMenuWidget(bool Draw, float& Width)
float UCogEngineWindow_Stats::GetMainMenuWidgetWidth(int32 WidgetIndex, float MaxWidth)
{
Width = FCogWindowWidgets::GetFontWidth() * 25;
const APlayerController* PlayerController = GetLocalPlayerController();
const UNetConnection* Connection = PlayerController != nullptr ? PlayerController->GetNetConnection() : nullptr;
if (Draw == false)
switch (WidgetIndex)
{
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 UCogEngineWindow_Stats::RenderMainMenuWidget(int32 WidgetIndex, float Width)
{
switch (WidgetIndex)
{
case 0: RenderMainMenuWidgetFramerate(Width); break;
case 1: RenderMainMenuWidgetPing(Width); break;
case 2: RenderMainMenuWidgetPacketLoss(Width); break;
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Stats::RenderMainMenuWidgetFramerate(float Width)
{
extern ENGINE_API float GAverageFPS;
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");
}
ImGui::PopStyleColor(2);
ImGui::PopStyleVar(2);
ImGui::SetItemTooltip("Framerate");
if (ImGui::BeginPopup("FrameratePopup"))
{
ImGui::Text("Fps");
ImGui::SameLine();
int32 MaxFps = GEngine->GetMaxFPS();
TArray<int32> Values{ 0, 10, 20, 30, 60, 120 };
if (FCogWindowWidgets::MultiChoiceButtonsInt(Values, MaxFps, ImVec2(3.5f * FCogWindowWidgets::GetFontWidth(), 0)))
{
GEngine->SetMaxFPS(MaxFps);
}
ImGui::EndPopup();
}
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Stats::RenderMainMenuWidgetPing(float Width)
{
const APlayerController* PlayerController = GetLocalPlayerController();
const APlayerState* PlayerState = PlayerController != nullptr ? PlayerController->GetPlayerState<APlayerState>() : nullptr;
if (PlayerState == nullptr)
{
return;
}
extern ENGINE_API float GAverageFPS;
ImGui::TextColored(GetFpsColor(GAverageFPS), "%3dfps ", (int32)GAverageFPS);
ImGui::SetItemTooltip("Frame Per Second");
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 (const APlayerController* PlayerController = GetLocalPlayerController())
if (ImGui::Button(TCHAR_TO_ANSI(*FString::Printf(TEXT("%3dms###PingButton"), (int32)Ping)), ImVec2(Width, 0.0f)))
{
if (const APlayerState* PlayerState = PlayerController->GetPlayerState<APlayerState>())
{
const float Ping = PlayerState->GetPingInMilliseconds();
ImGui::SameLine();
ImGui::TextColored(GetPingColor(Ping), "%3dms ", (int32)Ping);
ImGui::SetItemTooltip("Ping");
}
if (UNetConnection* Connection = PlayerController->GetNetConnection())
{
const float OutPacketLost = Connection->GetOutLossPercentage().GetAvgLossPercentage() * 100.0f;
const float InPacketLost = Connection->GetInLossPercentage().GetAvgLossPercentage() * 100.0f;
const float TotalPacketLost = OutPacketLost + InPacketLost;
ImGui::SameLine();
ImGui::TextColored(GetPacketLossColor(TotalPacketLost), "%2d%% ", (int32)TotalPacketLost);
ImGui::SetItemTooltip("Packet Loss");
}
ImGui::OpenPopup("PingPopup");
}
ImGui::PopStyleColor(2);
ImGui::PopStyleVar(2);
ImGui::SetItemTooltip("Ping");
#if DO_ENABLE_NET_TEST
if (ImGui::BeginPopup("PingPopup"))
{
FWorldContext& WorldContext = GEngine->GetWorldContextFromWorldChecked(GetWorld());
if (WorldContext.ActiveNetDrivers.Num() > 0)
{
ImGui::Text("Ping");
ImGui::SameLine();
FNamedNetDriver* SelectedNetDriver = &WorldContext.ActiveNetDrivers[0];
FPacketSimulationSettings Settings = SelectedNetDriver->NetDriver->PacketSimulationSettings;
TArray<int32> Values{ 0, 50, 100, 200, 500, 1000 };
if (FCogWindowWidgets::MultiChoiceButtonsInt(Values, Settings.PktIncomingLagMin, ImVec2(4.5f * FCogWindowWidgets::GetFontWidth(), 0)))
{
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
}
}
ImGui::EndPopup();
}
#endif //DO_ENABLE_NET_TEST
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Stats::RenderMainMenuWidgetPacketLoss(float Width)
{
const APlayerController* PlayerController = GetLocalPlayerController();
UNetConnection* Connection = PlayerController != nullptr ? PlayerController->GetNetConnection() : nullptr;
if (Connection == nullptr)
{
return;
}
const float OutPacketLost = Connection->GetOutLossPercentage().GetAvgLossPercentage() * 100.0f;
const float InPacketLost = Connection->GetInLossPercentage().GetAvgLossPercentage() * 100.0f;
const float TotalPacketLost = (OutPacketLost + InPacketLost) / 2;
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, GetPacketLossColor(TotalPacketLost));
if (ImGui::Button(TCHAR_TO_ANSI(*FString::Printf(TEXT("%2d%%###PacketLossButton"), (int32)TotalPacketLost)), ImVec2(Width, 0.0f)))
{
ImGui::OpenPopup("PacketLossPopup");
}
ImGui::PopStyleColor(2);
ImGui::PopStyleVar(2);
ImGui::SetItemTooltip("Packet Loss");
#if DO_ENABLE_NET_TEST
if (ImGui::BeginPopup("PacketLossPopup"))
{
FWorldContext& WorldContext = GEngine->GetWorldContextFromWorldChecked(GetWorld());
if (WorldContext.ActiveNetDrivers.Num() > 0)
{
ImGui::Text("Packet Loss");
ImGui::SameLine();
FNamedNetDriver* SelectedNetDriver = &WorldContext.ActiveNetDrivers[0];
FPacketSimulationSettings Settings = SelectedNetDriver->NetDriver->PacketSimulationSettings;
TArray<int32> Values{ 0, 5, 10, 20, 30, 40, 50 };
if (FCogWindowWidgets::MultiChoiceButtonsInt(Values, Settings.PktIncomingLoss, ImVec2(3.5f * FCogWindowWidgets::GetFontWidth(), 0)))
{
Settings.PktLoss = Settings.PktIncomingLoss;
SelectedNetDriver->NetDriver->SetPacketSimulationSettings(Settings);
}
}
ImGui::EndPopup();
}
#endif //DO_ENABLE_NET_TEST
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -1,6 +1,7 @@
#include "CogEngineWindow_TimeScale.h"
#include "CogEngineReplicator.h"
#include "CogWindowWidgets.h"
#include "Engine/Engine.h"
#include "Engine/World.h"
@@ -43,49 +44,11 @@ void UCogEngineWindow_TimeScale::RenderContent()
return;
}
ImGuiStyle& Style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(Style.WindowPadding.x * 0.40f, (float)(int)(Style.WindowPadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(Style.FramePadding.x * 0.40f, (float)(int)(Style.FramePadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(Style.ItemSpacing.x * 0.30f, (float)(int)(Style.ItemSpacing.y * 0.60f)));
ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(255, 255, 255, 180));
for (float TimeScale : TimingScales)
{
DrawTimeButton(Replicator, TimeScale);
ImGui::SameLine();
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(3);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_TimeScale::DrawTimeButton(ACogEngineReplicator* Replicator, float Value)
{
const bool IsSelected = FMath::IsNearlyEqual(Replicator->GetTimeDilation(), Value, 0.0001f);
if (IsSelected)
{
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
}
else
{
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(128, 128, 128, 50));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(128, 128, 128, 100));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(128, 128, 128, 150));
}
const char* Text = TCHAR_TO_ANSI(*FString::Printf(TEXT("%g"), Value).Replace(TEXT("0."), TEXT(".")));
if (ImGui::Button(Text, ImVec2(3.5f * FCogWindowWidgets::GetFontWidth(), 0)))
float Value = Replicator->GetTimeDilation();
if (FCogWindowWidgets::MultiChoiceButtonsFloat(TimingScales, Value, ImVec2(3.5f * FCogWindowWidgets::GetFontWidth(), 0)))
{
Replicator->Server_SetTimeDilation(Value);
}
if (IsSelected)
{
ImGui::PopStyleVar();
}
else
{
ImGui::PopStyleColor(3);
}
}
@@ -50,7 +50,9 @@ protected:
virtual void RenderContent() override;
virtual void RenderMainMenuWidget(bool Draw, float& Width) override;
virtual float GetMainMenuWidgetWidth(int32 SubWidgetIndex, float MaxWidth) override;
virtual void RenderMainMenuWidget(int32 SubWidgetIndex, float Width) override;
virtual bool DrawSelectionCombo();
@@ -23,5 +23,10 @@ protected:
virtual void RenderContent() override;
virtual void RenderMainMenuWidget(bool Draw, float& Width) override;
virtual float GetMainMenuWidgetWidth(int32 SubWidgetIndex, float MaxWidth) override;
virtual void RenderMainMenuWidget(int32 SubWidgetIndex, float Width) override;
void RenderMainMenuWidgetPacketLoss(float Width);
void RenderMainMenuWidgetPing(float Width);
void RenderMainMenuWidgetFramerate(float Width);
};
@@ -21,8 +21,6 @@ protected:
virtual void RenderContent() override;
virtual void DrawTimeButton(ACogEngineReplicator* Replicator, float Value);
TArray<float> TimingScales;
private:
@@ -384,21 +384,55 @@ void UCogWindowManager::RenderMainMenu()
for (UCogWindow* Window : MainMenuWidgets)
{
float Width = 0.0f;
Window->RenderMainMenuWidget(false, Width);
TArray<float> SubWidgetsWidths;
float SimCursorX = CursorX;
for (int32 SubWidgetIndex = 0; ; ++SubWidgetIndex)
{
const float MaxWidth = SimCursorX - MinCursorX;
float SubWidgetWidth = Window->GetMainMenuWidgetWidth(SubWidgetIndex, MaxWidth);
if (SubWidgetWidth == -1)
{
break;
}
//-------------------------------------------
// Stop drawing if there is not enough room
//-------------------------------------------
if (CursorX - Width < MinCursorX)
SimCursorX -= SubWidgetWidth;
SubWidgetsWidths.Add(SubWidgetWidth);
}
bool Stop = false;
for (int32 SubWidgetIndex = SubWidgetsWidths.Num() - 1; SubWidgetIndex >= 0; SubWidgetIndex--)
{
const float SubWidgetWidth = SubWidgetsWidths[SubWidgetIndex];
const float MaxWidth = CursorX - MinCursorX;
//-------------------------------------------
// Bypass this subwidget if its width is 0
//-------------------------------------------
if (SubWidgetWidth == 0)
{
continue;
}
//-------------------------------------------
// Stop drawing if there is not enough room
//-------------------------------------------
if (SubWidgetWidth > MaxWidth)
{
Stop = true;
break;
}
CursorX -= SubWidgetWidth;
ImGui::SetCursorPosX(CursorX);
Window->RenderMainMenuWidget(SubWidgetIndex, SubWidgetWidth);
}
if (Stop)
{
break;
}
CursorX -= Width;
ImGui::SetCursorPosX(CursorX);
Window->RenderMainMenuWidget(true, Width);
CursorX -= ImGui::GetStyle().ItemSpacing.x;
}
@@ -474,5 +474,99 @@ bool FCogWindowWidgets::DeleteArrayItemButton()
ImGui::SetTooltip("Delete Item");
}
return IsPressed;
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWindowWidgets::MultiChoiceButton(const char* Label, bool IsSelected, const ImVec2& Size)
{
if (IsSelected)
{
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
}
else
{
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(128, 128, 128, 50));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(128, 128, 128, 100));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(128, 128, 128, 150));
}
const bool IsPressed = ImGui::Button(Label, Size);
if (IsSelected)
{
ImGui::PopStyleVar();
}
else
{
ImGui::PopStyleColor(3);
}
return IsPressed;
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWindowWidgets::MultiChoiceButtonsInt(TArray<int32>& Values, int32& Value, const ImVec2& Size)
{
ImGuiStyle& Style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(Style.WindowPadding.x * 0.40f, (float)(int)(Style.WindowPadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(Style.FramePadding.x * 0.40f, (float)(int)(Style.FramePadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(Style.ItemSpacing.x * 0.30f, (float)(int)(Style.ItemSpacing.y * 0.60f)));
ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(255, 255, 255, 180));
bool IsPressed = false;
for (int32 i = 0; i < Values.Num(); ++i)
{
int32 ButtonValue = Values[i];
const char* Text = TCHAR_TO_ANSI(*FString::Printf(TEXT("%d"), ButtonValue));
if (MultiChoiceButton(Text, ButtonValue == Value, Size))
{
IsPressed = true;
Value = ButtonValue;
}
if (i < Values.Num() - 1)
{
ImGui::SameLine();
}
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(3);
return IsPressed;
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWindowWidgets::MultiChoiceButtonsFloat(TArray<float>& Values, float& Value, const ImVec2& Size)
{
ImGuiStyle& Style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(Style.WindowPadding.x * 0.40f, (float)(int)(Style.WindowPadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(Style.FramePadding.x * 0.40f, (float)(int)(Style.FramePadding.y * 0.60f)));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(Style.ItemSpacing.x * 0.30f, (float)(int)(Style.ItemSpacing.y * 0.60f)));
ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(255, 255, 255, 180));
bool IsPressed = false;
for (int32 i = 0; i < Values.Num(); ++i)
{
float ButtonValue = Values[i];
const char* Text = TCHAR_TO_ANSI(*FString::Printf(TEXT("%g"), ButtonValue).Replace(TEXT("0."), TEXT(".")));
if (MultiChoiceButton(Text, ButtonValue == Value, Size))
{
IsPressed = true;
Value = ButtonValue;
}
if (i < Values.Num() - 1)
{
ImGui::SameLine();
}
}
ImGui::PopStyleColor(1);
ImGui::PopStyleVar(3);
return IsPressed;
}
@@ -31,7 +31,10 @@ public:
virtual void GameTick(float DeltaTime);
/** */
virtual void RenderMainMenuWidget(bool Draw, float& Width) {}
virtual float GetMainMenuWidgetWidth(int32 SubWidgetIndex, float MaxWidth) { return -1.0f; }
/** */
virtual void RenderMainMenuWidget(int32 SubWidgetIndex, float Width) {}
ImGuiID GetID() const { return ID; }
@@ -20,6 +20,12 @@ public:
static void ToggleButton(bool* Value, const char* TextTrue, const char* TextFalse, const ImVec4& TrueColor, const ImVec4& FalseColor, const ImVec2& Size = ImVec2(0, 0));
static bool MultiChoiceButton(const char* Label, bool IsSelected, const ImVec2& Size = ImVec2(0, 0));
static bool MultiChoiceButtonsInt(TArray<int32>& Values, int32& Value, const ImVec2& Size = ImVec2(0, 0));
static bool MultiChoiceButtonsFloat(TArray<float>& Values, float& Value, const ImVec2& Size = ImVec2(0, 0));
static void SliderWithReset(const char* Name, float* Value, float Min, float Max, const float& ResetValue, const char* Format);
static void HelpMarker(const char* Text);
@@ -48,6 +48,24 @@ void UCogAbilityWindow_Cheats::ResetConfig()
void UCogAbilityWindow_Cheats::SetAsset(const UCogAbilityDataAsset* Value)
{
Asset = Value;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::GameTick(float DeltaTime)
{
Super::GameTick(DeltaTime);
TryReapplyCheats();
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::TryReapplyCheats()
{
if (bHasReappliedCheats)
{
return;
}
if (bReapplyCheatsBetweenPlays == false)
{
@@ -78,7 +96,7 @@ void UCogAbilityWindow_Cheats::SetAsset(const UCogAbilityDataAsset* Value)
return;
}
TArray<AActor*> Targets{ LocalPawn };
TArray<AActor*> Targets { LocalPawn };
for (const FString& AppliedCheatName : AppliedCheats)
{
@@ -88,6 +106,8 @@ void UCogAbilityWindow_Cheats::SetAsset(const UCogAbilityDataAsset* Value)
Replicator->ApplyCheat(LocalPawn, Targets, *Cheat);
}
}
bHasReappliedCheats = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -23,17 +23,19 @@ public:
protected:
virtual void GameTick(float DeltaTime);
virtual void ResetConfig() override;
virtual void RenderHelp() override;
virtual void RenderContent() override;
private:
bool AddCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect, bool IsPersistent);
virtual void TryReapplyCheats();
void RequestCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect);
virtual bool AddCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect, bool IsPersistent);
virtual void RequestCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect);
UPROPERTY(Config)
bool bReapplyCheatsBetweenPlays = true;
@@ -46,4 +48,6 @@ private:
UPROPERTY()
TObjectPtr<const UCogAbilityDataAsset> Asset = nullptr;
bool bHasReappliedCheats = false;
};