cheats and window menu persistence

This commit is contained in:
Arnaud Jamin
2023-10-10 02:10:18 -04:00
parent c9a3013bb9
commit 2d5e764e19
32 changed files with 154 additions and 85 deletions
@@ -21,9 +21,9 @@ void UCogAbilityWindow_Abilities::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Abilities::PreRender(ImGuiWindowFlags& WindowFlags)
UCogAbilityWindow_Abilities::UCogAbilityWindow_Abilities()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -21,9 +21,9 @@ void UCogAbilityWindow_Attributes::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Attributes::PreRender(ImGuiWindowFlags& WindowFlags)
UCogAbilityWindow_Attributes::UCogAbilityWindow_Attributes()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -25,11 +25,29 @@ void UCogAbilityWindow_Cheats::RenderHelp()
);
}
//--------------------------------------------------------------------------------------------------------------------------
UCogAbilityWindow_Cheats::UCogAbilityWindow_Cheats()
{
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::SetCheatsAsset(const UCogAbilityDataAsset_Cheats* Value)
{
CheatsAsset = Value;
if (bReapplyCheatsBetweenPlays == false)
{
return;
}
static int32 IsFirstLaunch = true;
if (IsFirstLaunch && bReapplyCheatsBetweenLaunches == false)
{
return;
}
IsFirstLaunch = false;
if (CheatsAsset == nullptr)
{
return;
@@ -76,13 +94,30 @@ void UCogAbilityWindow_Cheats::RenderContent()
return;
}
APawn* ControlledActor = GetLocalPlayerPawn();
if (SelectedActor == ControlledActor)
if (ImGui::BeginMenuBar())
{
AppliedCheats.Empty();
if (ImGui::BeginMenu("Options"))
{
ImGui::Checkbox("Reapply Cheats Between Plays", &bReapplyCheatsBetweenPlays);
if (bReapplyCheatsBetweenPlays == false)
{
ImGui::BeginDisabled();
}
ImGui::Checkbox("Reapply Cheats Between Launches", &bReapplyCheatsBetweenLaunches);
if (bReapplyCheatsBetweenPlays == false)
{
ImGui::EndDisabled();
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
APawn* ControlledActor = GetLocalPlayerPawn();
if (ImGui::BeginTable("Cheats", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBodyUntilResize))
{
ImGui::TableSetupColumn("Toggle", ImGuiTableColumnFlags_WidthStretch);
@@ -91,15 +126,34 @@ void UCogAbilityWindow_Cheats::RenderContent()
ImGui::TableNextRow();
ImGui::TableNextColumn();
bool bHasChanged = false;
int Index = 0;
for (const FCogAbilityCheat& CheatEffect : CheatsAsset->PersistentEffects)
{
ImGui::PushID(Index);
AddCheat(ControlledActor, SelectedActor, CheatEffect, true);
bHasChanged |= AddCheat(ControlledActor, SelectedActor, CheatEffect, true);
ImGui::PopID();
Index++;
}
//----------------------------------------------------------------
// When a persistent cheat has been changed, update the applied
// cheats string array to be saved in the config later
//----------------------------------------------------------------
if (bHasChanged && SelectedActor == ControlledActor)
{
AppliedCheats.Empty();
for (const FCogAbilityCheat& CheatEffect : CheatsAsset->PersistentEffects)
{
if (ACogAbilityReplicator::IsCheatActive(SelectedActor, CheatEffect))
{
AppliedCheats.Add(CheatEffect.Name);
}
}
}
ImGui::TableNextColumn();
for (const FCogAbilityCheat& CheatEffect : CheatsAsset->InstantEffects)
@@ -115,13 +169,15 @@ void UCogAbilityWindow_Cheats::RenderContent()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Cheats::AddCheat(AActor* ControlledActor, AActor* SelectedActor, const FCogAbilityCheat& Cheat, bool IsPersistent)
bool UCogAbilityWindow_Cheats::AddCheat(AActor* ControlledActor, AActor* SelectedActor, const FCogAbilityCheat& Cheat, bool IsPersistent)
{
if (Cheat.Effect == nullptr)
{
return;
return false;
}
bool bIsPressed = false;
const FGameplayTagContainer& Tags = Cheat.Effect->GetDefaultObject<UGameplayEffect>()->InheritableGameplayEffectTags.CombinedTags;
FLinearColor Color;
@@ -146,11 +202,7 @@ void UCogAbilityWindow_Cheats::AddCheat(AActor* ControlledActor, AActor* Selecte
if (ImGui::Checkbox(TCHAR_TO_ANSI(*Cheat.Name), &isEnabled))
{
RequestCheat(ControlledActor, SelectedActor, Cheat);
}
if (isEnabled && SelectedActor == ControlledActor)
{
AppliedCheats.Add(Cheat.Name);
bIsPressed = true;
}
}
else
@@ -158,6 +210,7 @@ void UCogAbilityWindow_Cheats::AddCheat(AActor* ControlledActor, AActor* Selecte
if (ImGui::Button(TCHAR_TO_ANSI(*Cheat.Name), ImVec2(-1, 0)))
{
RequestCheat(ControlledActor, SelectedActor, Cheat);
bIsPressed = true;
}
}
@@ -176,6 +229,8 @@ void UCogAbilityWindow_Cheats::AddCheat(AActor* ControlledActor, AActor* Selecte
}
FCogWindowWidgets::PopBackColor();
return bIsPressed;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -18,9 +18,9 @@ void UCogAbilityWindow_Effects::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Effects::PreRender(ImGuiWindowFlags& WindowFlags)
UCogAbilityWindow_Effects::UCogAbilityWindow_Effects()
{
Super::PreRender(WindowFlags);
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -11,9 +11,9 @@ void UCogAbilityWindow_Tags::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogAbilityWindow_Tags::PreRender(ImGuiWindowFlags& WindowFlags)
UCogAbilityWindow_Tags::UCogAbilityWindow_Tags()
{
Super::PreRender(WindowFlags);
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -14,15 +14,15 @@ class COGABILITY_API UCogAbilityWindow_Abilities : public UCogWindow
GENERATED_BODY()
public:
UCogAbilityWindow_Abilities();
TWeakObjectPtr<UCogAbilityDataAsset_Abilities> AbilitiesAsset;
protected:
virtual void RenderHelp() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderTick(float DetlaTime) override;
virtual void RenderContent() override;
@@ -9,12 +9,14 @@ class COGABILITY_API UCogAbilityWindow_Attributes : public UCogWindow
{
GENERATED_BODY()
public:
UCogAbilityWindow_Attributes();
protected:
virtual void RenderHelp() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void DrawAttributeInfo(const UAbilitySystemComponent& AbilitySystemComponent, const FGameplayAttribute& Attribute);
@@ -15,6 +15,8 @@ class COGABILITY_API UCogAbilityWindow_Cheats : public UCogWindow
public:
UCogAbilityWindow_Cheats();
const UCogAbilityDataAsset_Cheats* GetCheatsAsset() const { return CheatsAsset.Get(); }
void SetCheatsAsset(const UCogAbilityDataAsset_Cheats* Value);
@@ -27,10 +29,16 @@ protected:
private:
void AddCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect, bool IsPersistent);
bool AddCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect, bool IsPersistent);
void RequestCheat(AActor* ControlledActor, AActor* TargetActor, const FCogAbilityCheat& CheatEffect);
UPROPERTY(Config)
bool bReapplyCheatsBetweenPlays = true;
UPROPERTY(Config)
bool bReapplyCheatsBetweenLaunches = true;
UPROPERTY(Config)
TArray<FString> AppliedCheats;
@@ -12,6 +12,8 @@ class COGABILITY_API UCogAbilityWindow_Effects : public UCogWindow
public:
UCogAbilityWindow_Effects();
FGameplayTag NegativeEffectTag;
FGameplayTag PositiveEffectTag;
@@ -20,8 +22,6 @@ protected:
virtual void RenderHelp() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void RenderEffectsTable();
@@ -9,10 +9,13 @@ class COGABILITY_API UCogAbilityWindow_Tags : public UCogWindow
{
GENERATED_BODY()
protected:
virtual void RenderHelp() override;
public:
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
UCogAbilityWindow_Tags();
protected:
virtual void RenderHelp() override;
virtual void RenderContent() override;
@@ -22,9 +22,9 @@ void UCogEngineWindow_Collisions::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Collisions::PreRender(ImGuiWindowFlags& WindowFlags)
UCogEngineWindow_Collisions::UCogEngineWindow_Collisions()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -57,9 +57,9 @@ void UCogEngineWindow_DebugSettings::PreSaveConfig()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_DebugSettings::PreRender(ImGuiWindowFlags& WindowFlags)
UCogEngineWindow_DebugSettings::UCogEngineWindow_DebugSettings()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -18,9 +18,9 @@ void UCogEngineWindow_LogCategories::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_LogCategories::PreRender(ImGuiWindowFlags& WindowFlags)
UCogEngineWindow_LogCategories::UCogEngineWindow_LogCategories()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -32,9 +32,9 @@ void UCogEngineWindow_Metrics::PreSaveConfig()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Metrics::PreRender(ImGuiWindowFlags& WindowFlags)
UCogEngineWindow_Metrics::UCogEngineWindow_Metrics()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -37,6 +37,7 @@ void UCogLogOutputDevice::Serialize(const TCHAR* Message, ELogVerbosity::Type Ve
//--------------------------------------------------------------------------------------------------------------------------
UCogEngineWindow_OutputLog::UCogEngineWindow_OutputLog()
{
bHasMenu = true;
OutputDevice.OutputLog = this;
}
@@ -148,12 +149,6 @@ void UCogEngineWindow_OutputLog::DrawRow(const char* BufferStart, const FLineInf
ImGui::PopStyleColor();
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_OutputLog::PreRender(ImGuiWindowFlags& WindowFlags)
{
WindowFlags = ImGuiWindowFlags_MenuBar;
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_OutputLog::RenderContent()
{
@@ -20,9 +20,9 @@ void UCogEngineWindow_Selection::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Selection::PreRender(ImGuiWindowFlags& WindowFlags)
UCogEngineWindow_Selection::UCogEngineWindow_Selection()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -475,7 +475,7 @@ void UCogEngineWindow_Selection::DrawMainMenuWidget(bool Draw, float& Width)
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4((ImGuiCol_FrameBg)));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyleColorVec4((ImGuiCol_FrameBgActive)));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyleColorVec4((ImGuiCol_FrameBgHovered)));
ImGui::SameLine(ImGui::GetCursorPos().x - ResetButtonWidth + (ImGui::GetStyle().WindowPadding.x - 2) * ImGui::GetWindowDpiScale());
ImGui::SameLine();
if (ImGui::Button("X", ImVec2(ResetButtonWidth, 0)))
{
FCogDebugSettings::SetSelection(nullptr);
@@ -8,12 +8,7 @@
//--------------------------------------------------------------------------------------------------------------------------
UCogEngineWindow_Skeleton::UCogEngineWindow_Skeleton()
{
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Skeleton::PreRender(ImGuiWindowFlags& WindowFlags)
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -10,12 +10,6 @@ void UCogEngineWindow_Spawns::RenderHelp()
);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Spawns::PreRender(ImGuiWindowFlags& WindowFlags)
{
Super::PreRender(WindowFlags);
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogEngineWindow_Spawns::RenderContent()
{
@@ -13,14 +13,14 @@ class COGENGINE_API UCogEngineWindow_Collisions : public UCogWindow
public:
UCogEngineWindow_Collisions();
void SetCollisionsAsset(const UCogEngineDataAsset_Collisions* Asset);
private:
virtual void RenderHelp() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
struct FChannel
@@ -9,6 +9,10 @@ class COGENGINE_API UCogEngineWindow_DebugSettings : public UCogWindow
{
GENERATED_BODY()
public:
UCogEngineWindow_DebugSettings();
protected:
virtual void RenderHelp() override;
@@ -17,8 +21,6 @@ protected:
virtual void PostInitProperties() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
private:
@@ -11,9 +11,9 @@ class COGENGINE_API UCogEngineWindow_LogCategories : public UCogWindow
public:
virtual void RenderHelp() override;
UCogEngineWindow_LogCategories();
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderHelp() override;
virtual void RenderContent() override;
};
@@ -14,6 +14,8 @@ class COGENGINE_API UCogEngineWindow_Metrics : public UCogWindow
public:
UCogEngineWindow_Metrics();
protected:
virtual void PostInitProperties() override;
@@ -22,8 +24,6 @@ protected:
virtual void RenderHelp() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void RenderTick(float DeltaTime) override;
@@ -40,8 +40,6 @@ protected:
virtual void RenderHelp() override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
private:
@@ -12,6 +12,8 @@ class COGENGINE_API UCogEngineWindow_Selection : public UCogWindow
public:
UCogEngineWindow_Selection();
bool GetIsSelecting() const { return bSelectionModeActive; }
void SetCurrentActorSubClass(TSubclassOf<AActor> Value) { SelectedSubClass = Value; }
@@ -32,8 +34,6 @@ protected:
virtual void RenderTick(float DeltaTime) override;
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void DrawMainMenuWidget(bool Draw, float& Width) override;
@@ -35,7 +35,7 @@ public:
virtual void RenderTick(float DeltaTime) override;
protected:
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void OnSelectionChanged(AActor* OldSelection, AActor* NewSelection) override;
private:
@@ -12,7 +12,7 @@ class COGENGINE_API UCogEngineWindow_Spawns : public UCogWindow
{
GENERATED_BODY()
public:
public:
const UCogEngineDataAsset_Spawns* GetSpawnsAsset() const { return SpawnAsset; }
@@ -22,8 +22,6 @@ protected:
virtual void RenderHelp();
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void RenderSpawnGroup(const FCogEngineSpawnGroup& SpawnGroup);
@@ -20,9 +20,9 @@ void UCogInputWindow_Actions::RenderHelp()
}
//--------------------------------------------------------------------------------------------------------------------------
void UCogInputWindow_Actions::PreRender(ImGuiWindowFlags& WindowFlags)
UCogInputWindow_Actions::UCogInputWindow_Actions()
{
WindowFlags = ImGuiWindowFlags_MenuBar;
bHasMenu = true;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -237,10 +237,6 @@ void UCogInputWindow_Gamepad::RenderContent()
}
}
}
else
{
ImGui::Text("No Actions in Action Asset");
}
}
else
{
@@ -15,14 +15,14 @@ class COGINPUT_API UCogInputWindow_Actions : public UCogWindow
public:
TWeakObjectPtr<UCogInputDataAsset_Actions> ActionsAsset;
UCogInputWindow_Actions();
TWeakObjectPtr<UCogInputDataAsset_Actions> ActionsAsset;
protected:
void RenderHelp();
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void RenderTick(float DeltaSeconds) override;
@@ -13,10 +13,13 @@ class COGINPUT_API UCogInputWindow_Gamepad : public UCogWindow
GENERATED_BODY()
public:
UCogInputWindow_Gamepad();
virtual void PreRender(ImGuiWindowFlags& WindowFlags) override;
virtual void RenderContent() override;
virtual void RenderTick(float DeltaSeconds) override;
TWeakObjectPtr<UCogInputDataAsset_Actions> ActionsAsset;
@@ -56,6 +56,11 @@ void UCogWindow::Render(float DeltaTime)
const FString WindowTitle = GetTitle() + "##" + Name;
if (bHasMenu && bHideMenu == false)
{
WindowFlags |= ImGuiWindowFlags_MenuBar;
}
if (ImGui::Begin(TCHAR_TO_ANSI(*WindowTitle), &bIsVisible, WindowFlags))
{
if (Owner->GetShowHelp())
@@ -77,6 +82,16 @@ void UCogWindow::Render(float DeltaTime)
}
}
if (bHasMenu)
{
if (ImGui::BeginPopupContextWindow())
{
ImGui::Checkbox("Hide Menu", &bHideMenu);
ImGui::EndPopup();
}
}
RenderContent();
ImGui::End();
}
@@ -77,12 +77,17 @@ protected:
ULocalPlayer* GetLocalPlayer();
UPROPERTY(Config)
bool bHasMenu = false;
private:
bool bIsVisible = false;
bool bShowInsideMenu = true;
bool bHideMenu = false;
ImGuiID ID;
FString FullName;