mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-06 07:38:46 +00:00
CogWindow: Widgets can now be chosen and ordered by the user
This commit is contained in:
@@ -21,6 +21,7 @@ void FCogEngineWindow_Selection::Initialize()
|
|||||||
Super::Initialize();
|
Super::Initialize();
|
||||||
|
|
||||||
bHasMenu = true;
|
bHasMenu = true;
|
||||||
|
bHasWidget = true;
|
||||||
ActorClasses = { AActor::StaticClass(), ACharacter::StaticClass() };
|
ActorClasses = { AActor::StaticClass(), ACharacter::StaticClass() };
|
||||||
|
|
||||||
Config = GetConfig<UCogEngineConfig_Selection>();
|
Config = GetConfig<UCogEngineConfig_Selection>();
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ ImVec4 StatRedColor(1.0f, 0.4f, 0.3f, 1.0f);
|
|||||||
ImVec4 StatOrangeColor(1.0f, 0.7f, 0.4f, 1.0f);
|
ImVec4 StatOrangeColor(1.0f, 0.7f, 0.4f, 1.0f);
|
||||||
ImVec4 StatGreenColor(0.5f, 1.0f, 0.6f, 1.0f);
|
ImVec4 StatGreenColor(0.5f, 1.0f, 0.6f, 1.0f);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void FCogEngineWindow_Stats::Initialize()
|
||||||
|
{
|
||||||
|
Super::Initialize();
|
||||||
|
|
||||||
|
bHasWidget = true;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void FCogEngineWindow_Stats::RenderHelp()
|
void FCogEngineWindow_Stats::RenderHelp()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
virtual void Initialize() override;
|
||||||
|
|
||||||
virtual void RenderHelp() override;
|
virtual void RenderHelp() override;
|
||||||
|
|
||||||
virtual void RenderContent() override;
|
virtual void RenderContent() override;
|
||||||
|
|||||||
@@ -205,6 +205,12 @@ void UCogWindowManager::AddWindow(FCogWindow* Window, const FString& Name, bool
|
|||||||
Window->Initialize();
|
Window->Initialize();
|
||||||
Windows.Add(Window);
|
Windows.Add(Window);
|
||||||
|
|
||||||
|
if (Window->HasWidget())
|
||||||
|
{
|
||||||
|
Widgets.Add(Window);
|
||||||
|
//Widgets.Sort()
|
||||||
|
}
|
||||||
|
|
||||||
if (AddToMainMenu)
|
if (AddToMainMenu)
|
||||||
{
|
{
|
||||||
if (FMenu* Menu = AddMenu(Window->GetFullName()))
|
if (FMenu* Menu = AddMenu(Window->GetFullName()))
|
||||||
@@ -214,13 +220,6 @@ void UCogWindowManager::AddWindow(FCogWindow* Window, const FString& Name, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
|
||||||
void UCogWindowManager::AddMainMenuWidget(FCogWindow* Window)
|
|
||||||
{
|
|
||||||
Window->SetOwner(this);
|
|
||||||
MainMenuWidgets.Add(Window);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
FCogWindow* UCogWindowManager::FindWindowByID(ImGuiID ID)
|
FCogWindow* UCogWindowManager::FindWindowByID(ImGuiID ID)
|
||||||
{
|
{
|
||||||
@@ -388,6 +387,44 @@ void UCogWindowManager::RenderMainMenu()
|
|||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("Widgets"))
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < Widgets.Num(); ++i)
|
||||||
|
{
|
||||||
|
FCogWindow* Window = Widgets[i];
|
||||||
|
|
||||||
|
ImGui::PushID(i);
|
||||||
|
|
||||||
|
bool Visible = Window->GetIsWidgetVisible();
|
||||||
|
if (ImGui::Checkbox(TCHAR_TO_ANSI(*Window->GetName()), &Visible))
|
||||||
|
{
|
||||||
|
Window->SetIsWidgetVisible(Visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::IsItemActive() && ImGui::IsItemHovered() == false)
|
||||||
|
{
|
||||||
|
int iNext = i + (ImGui::GetMouseDragDelta(0).y < 0.f ? -1 : 1);
|
||||||
|
if (iNext >= 0 && iNext < Widgets.Num())
|
||||||
|
{
|
||||||
|
Widgets[i] = Widgets[iNext];
|
||||||
|
Widgets[iNext] = Window;
|
||||||
|
ImGui::ResetMouseDragDelta();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
ImGui::SameLine();
|
||||||
|
FCogWindowWidgets::HelpMarker("Drag and drop the widget name to reorder them.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
RenderMenuItem(*SettingsWindow, "Settings");
|
RenderMenuItem(*SettingsWindow, "Settings");
|
||||||
@@ -399,8 +436,19 @@ void UCogWindowManager::RenderMainMenu()
|
|||||||
const float MinCursorX = ImGui::GetCursorPosX();
|
const float MinCursorX = ImGui::GetCursorPosX();
|
||||||
float CursorX = ImGui::GetWindowWidth();
|
float CursorX = ImGui::GetWindowWidth();
|
||||||
|
|
||||||
for (FCogWindow* Window : MainMenuWidgets)
|
//------------------------------------------------------------
|
||||||
|
// Render in reverse order because it makes more sense
|
||||||
|
// when looking at the widget ordered list in the UI.
|
||||||
|
//------------------------------------------------------------
|
||||||
|
for (int32 WindowIndex = Widgets.Num() - 1; WindowIndex >= 0; WindowIndex--)
|
||||||
{
|
{
|
||||||
|
FCogWindow* Window = Widgets[WindowIndex];
|
||||||
|
|
||||||
|
if (Window->GetIsWidgetVisible() == false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
TArray<float> SubWidgetsWidths;
|
TArray<float> SubWidgetsWidths;
|
||||||
float SimCursorX = CursorX;
|
float SimCursorX = CursorX;
|
||||||
for (int32 SubWidgetIndex = 0; ; ++SubWidgetIndex)
|
for (int32 SubWidgetIndex = 0; ; ++SubWidgetIndex)
|
||||||
@@ -563,24 +611,62 @@ void UCogWindowManager::SettingsHandler_ClearAll(ImGuiContext* Context, ImGuiSet
|
|||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void UCogWindowManager::SettingsHandler_ApplyAll(ImGuiContext* Context, ImGuiSettingsHandler* Handler)
|
void UCogWindowManager::SettingsHandler_ApplyAll(ImGuiContext* Context, ImGuiSettingsHandler* Handler)
|
||||||
{
|
{
|
||||||
|
UCogWindowManager* Manager = (UCogWindowManager*)Handler->UserData;
|
||||||
|
|
||||||
|
Manager->Widgets.Sort([](const FCogWindow& Window1, const FCogWindow& Window2)
|
||||||
|
{
|
||||||
|
return Window1.GetWidgetOrderIndex() < Window2.GetWidgetOrderIndex();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void* UCogWindowManager::SettingsHandler_ReadOpen(ImGuiContext* Context, ImGuiSettingsHandler* Handler, const char* Name)
|
void* UCogWindowManager::SettingsHandler_ReadOpen(ImGuiContext* Context, ImGuiSettingsHandler* Handler, const char* Name)
|
||||||
{
|
{
|
||||||
return (void*)1;
|
if (strcmp(Name, "Windows") == 0)
|
||||||
|
{
|
||||||
|
return (void*)1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(Name, "Widgets") == 0)
|
||||||
|
{
|
||||||
|
UCogWindowManager* Manager = (UCogWindowManager*)Handler->UserData;
|
||||||
|
Manager->WidgetsOrderIndex = 0;
|
||||||
|
|
||||||
|
return (void*)2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void UCogWindowManager::SettingsHandler_ReadLine(ImGuiContext* Context, ImGuiSettingsHandler* Handler, void* Entry, const char* Line)
|
void UCogWindowManager::SettingsHandler_ReadLine(ImGuiContext* Context, ImGuiSettingsHandler* Handler, void* Entry, const char* Line)
|
||||||
{
|
{
|
||||||
ImGuiID Id;
|
if (Entry == (void*)1)
|
||||||
if (sscanf_s(Line, "0x%08X", &Id) == 1)
|
|
||||||
{
|
{
|
||||||
UCogWindowManager* Manager = (UCogWindowManager*)Handler->UserData;
|
ImGuiID Id;
|
||||||
if (FCogWindow* Window = Manager->FindWindowByID(Id))
|
if (sscanf_s(Line, "0x%08X", &Id) == 1)
|
||||||
{
|
{
|
||||||
Window->SetIsVisible(true);
|
UCogWindowManager* Manager = (UCogWindowManager*)Handler->UserData;
|
||||||
|
if (FCogWindow* Window = Manager->FindWindowByID(Id))
|
||||||
|
{
|
||||||
|
Window->SetIsVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Entry == (void*)2)
|
||||||
|
{
|
||||||
|
ImGuiID Id;
|
||||||
|
int32 Visible = false;
|
||||||
|
if (sscanf_s(Line, "0x%08X %d", &Id, &Visible) == 2)
|
||||||
|
{
|
||||||
|
UCogWindowManager* Manager = (UCogWindowManager*)Handler->UserData;
|
||||||
|
if (FCogWindow* Window = Manager->FindWindowByID(Id))
|
||||||
|
{
|
||||||
|
Window->SetWidgetOrderIndex(Manager->WidgetsOrderIndex);
|
||||||
|
Window->SetIsWidgetVisible(Visible > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Manager->WidgetsOrderIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -598,6 +684,14 @@ void UCogWindowManager::SettingsHandler_WriteAll(ImGuiContext* Context, ImGuiSet
|
|||||||
Buffer->appendf("0x%08X\n", Window->GetID());
|
Buffer->appendf("0x%08X\n", Window->GetID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Buffer->append("\n");
|
||||||
|
|
||||||
|
Buffer->appendf("[%s][Widgets]\n", Handler->TypeName);
|
||||||
|
for (FCogWindow* Window : Manager->Widgets)
|
||||||
|
{
|
||||||
|
Buffer->appendf("0x%08X %d\n", Window->GetID(), Window->GetIsWidgetVisible());
|
||||||
|
}
|
||||||
|
Buffer->append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ public:
|
|||||||
|
|
||||||
void SetIsVisible(bool Value) { bIsVisible = Value; }
|
void SetIsVisible(bool Value) { bIsVisible = Value; }
|
||||||
|
|
||||||
|
bool HasWidget() const { return bHasWidget; }
|
||||||
|
|
||||||
|
bool GetIsWidgetVisible() const { return bIsWidgetVisible; }
|
||||||
|
|
||||||
|
void SetIsWidgetVisible(bool Value) { bIsWidgetVisible = Value; }
|
||||||
|
|
||||||
|
int32 GetWidgetOrderIndex() const { return WidgetOrderIndex; }
|
||||||
|
|
||||||
|
void SetWidgetOrderIndex(int32 Value) { WidgetOrderIndex = Value; }
|
||||||
|
|
||||||
void SetOwner(UCogWindowManager* InOwner) { Owner = InOwner; }
|
void SetOwner(UCogWindowManager* InOwner) { Owner = InOwner; }
|
||||||
|
|
||||||
UCogWindowManager* GetOwner() const { return Owner; }
|
UCogWindowManager* GetOwner() const { return Owner; }
|
||||||
@@ -98,13 +108,18 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
UPROPERTY(Config)
|
|
||||||
bool bHideMenu = false;
|
bool bHideMenu = false;
|
||||||
|
|
||||||
bool bHasMenu = false;
|
bool bHasMenu = false;
|
||||||
|
|
||||||
bool bIsVisible = false;
|
bool bIsVisible = false;
|
||||||
|
|
||||||
|
bool bHasWidget = false;
|
||||||
|
|
||||||
|
bool bIsWidgetVisible = false;
|
||||||
|
|
||||||
|
int32 WidgetOrderIndex = -1;
|
||||||
|
|
||||||
ImGuiID ID;
|
ImGuiID ID;
|
||||||
|
|
||||||
FString FullName;
|
FString FullName;
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ public:
|
|||||||
|
|
||||||
virtual void AddWindow(FCogWindow* Window, const FString& Name, bool AddToMainMenu = true);
|
virtual void AddWindow(FCogWindow* Window, const FString& Name, bool AddToMainMenu = true);
|
||||||
|
|
||||||
virtual void AddMainMenuWidget(FCogWindow* Window);
|
|
||||||
|
|
||||||
virtual FCogWindow* FindWindowByID(ImGuiID ID);
|
virtual FCogWindow* FindWindowByID(ImGuiID ID);
|
||||||
|
|
||||||
virtual void CloseAllWindows();
|
virtual void CloseAllWindows();
|
||||||
@@ -132,6 +130,8 @@ protected:
|
|||||||
|
|
||||||
virtual void RenderSaveLayoutMenuItem(const UPlayerInput* PlayerInput, int LayoutIndex);
|
virtual void RenderSaveLayoutMenuItem(const UPlayerInput* PlayerInput, int LayoutIndex);
|
||||||
|
|
||||||
|
virtual void TickDPI();
|
||||||
|
|
||||||
static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*);
|
static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*);
|
||||||
|
|
||||||
static void SettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*);
|
static void SettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*);
|
||||||
@@ -142,7 +142,6 @@ protected:
|
|||||||
|
|
||||||
static void SettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf);
|
static void SettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf);
|
||||||
|
|
||||||
void TickDPI();
|
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
mutable TArray<UCogWindowConfig*> Configs;
|
mutable TArray<UCogWindowConfig*> Configs;
|
||||||
@@ -172,12 +171,14 @@ protected:
|
|||||||
|
|
||||||
TArray<FCogWindow*> Windows;
|
TArray<FCogWindow*> Windows;
|
||||||
|
|
||||||
|
TArray<FCogWindow*> Widgets;
|
||||||
|
|
||||||
|
int32 WidgetsOrderIndex = 0;
|
||||||
|
|
||||||
TArray<FCogWindow*> SpaceWindows;
|
TArray<FCogWindow*> SpaceWindows;
|
||||||
|
|
||||||
FCogWindow_Settings* SettingsWindow = nullptr;
|
FCogWindow_Settings* SettingsWindow = nullptr;
|
||||||
|
|
||||||
TArray<FCogWindow*> MainMenuWidgets;
|
|
||||||
|
|
||||||
FMenu MainMenu;
|
FMenu MainMenu;
|
||||||
|
|
||||||
int32 LayoutToLoad = -1;
|
int32 LayoutToLoad = -1;
|
||||||
|
|||||||
@@ -194,12 +194,6 @@ void ACogSampleGameState::InitializeCog()
|
|||||||
CogWindowManager->AddWindow<FCogInputWindow_Actions>("Input.Actions");
|
CogWindowManager->AddWindow<FCogInputWindow_Actions>("Input.Actions");
|
||||||
|
|
||||||
CogWindowManager->AddWindow<FCogInputWindow_Gamepad>("Input.Gamepad");
|
CogWindowManager->AddWindow<FCogInputWindow_Gamepad>("Input.Gamepad");
|
||||||
|
|
||||||
//---------------------------------------
|
|
||||||
// Main Menu Widget
|
|
||||||
//---------------------------------------
|
|
||||||
CogWindowManager->AddMainMenuWidget(SelectionWindow);
|
|
||||||
CogWindowManager->AddMainMenuWidget(StatsWindow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //ENABLE_COG
|
#endif //ENABLE_COG
|
||||||
|
|||||||
Reference in New Issue
Block a user