Skip to content

Commit

Permalink
Merge pull request #20 from sammyfreg/dev
Browse files Browse the repository at this point in the history
Update to : Dear ImGui 1.88
Update to : NetImgui 1.88
Fix for Unreal Imgui Console
  • Loading branch information
sammyfreg authored Jul 31, 2022
2 parents 84313ca + d719e2a commit 57ceb17
Show file tree
Hide file tree
Showing 25 changed files with 3,174 additions and 1,881 deletions.
4 changes: 2 additions & 2 deletions NetImgui.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 9,
"VersionName": "1.9",
"Version": 10,
"VersionName": "1.10",
"FriendlyName": "Unreal NetImgui",
"Description": "Plugin exposing Dear ImGui library for drawing 2D menus. These menus are displayed and controlled from an external application but processed from this engine code.",
"Category": "2D",
Expand Down
Binary file modified NetImguiServer/netImguiServer.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions Source/NetImgui.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
// "-netimguiserver 192.168.1.2:60" Try connecting to NetImguiServer at '192.168.1.2 : 60'
//
//-------------------------------------------------------------------------------------------------
// Dear ImGui Library : v1.86.5 (https://github.com/ocornut/imgui)
// NetImGui Library : v1.7.6 (https://github.com/sammyfreg/netImgui)
// Dear ImGui Library : v1.88 (https://github.com/ocornut/imgui)
// NetImGui Library : v1.8 (https://github.com/sammyfreg/netImgui)
//=================================================================================================

public class NetImgui : ModuleRules
Expand Down
76 changes: 38 additions & 38 deletions Source/Private/ImUnrealCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "HAL/IConsoleManager.h"
#include "Features/IModularFeatures.h"
#include "Engine/Engine.h"

#define LOCTEXT_NAMESPACE "ImguiUnrealCommand"

Expand Down Expand Up @@ -86,7 +87,6 @@ struct CommandContext
int mFilteredIndex = 0; // Item selected in the current list of commands
bool mPendingSelectCopy = false; // Request to copy the selected item into the input field
bool mPendingSelectFocus = false; // Selection changed, makes sure the item is visible in the list
IConsoleCommandExecutor* mpCmdExecutor = nullptr; // UE Object used to send the command to
};

//=================================================================================================
Expand Down Expand Up @@ -163,18 +163,6 @@ Preset::Preset(const FString& name)
StringToUTF8(mConfig.mName, mNameUTF8);
}

//=================================================================================================
// Fetch the first available 'Command Executor' and save it for running inputed commands later
//=================================================================================================
void InitializeExecutor(CommandContext& cmdContext)
{
if( cmdContext.mpCmdExecutor == nullptr ){
TArray<IConsoleCommandExecutor*> CommandExecutors = IModularFeatures::Get().GetModularFeatureImplementations<IConsoleCommandExecutor>(IConsoleCommandExecutor::ModularFeatureName());
if (CommandExecutors.IsValidIndex(0)){
cmdContext.mpCmdExecutor = CommandExecutors[0];
}
}
}

//=================================================================================================
// Find all command entries associated with this Preset
Expand Down Expand Up @@ -294,6 +282,38 @@ Preset& FindOrCreatePreset(CommandContext& cmdContext, const FString& presetName
return *pFoundPreset;
}

//=================================================================================================
// Populate the special 'History' Preset, with recently used 'Unreal Commands'
//=================================================================================================
void UpdatePresetCommandHistory(CommandContext& cmdContext)
{
Preset& presetHistory = FindOrCreatePreset(cmdContext, kPresetHistoryName);
presetHistory.mDirty = true;
presetHistory.mSortResults = false; // Want to preserve history order, not name
presetHistory.mConfig.mCommands.Reset();
presetHistory.mConfig.mFilters.Reset();
IConsoleManager::Get().GetConsoleHistory(TEXT(""), presetHistory.mConfig.mCommands);

// Invert the results, listing recent items first
int32 lastIndex = presetHistory.mConfig.mCommands.Num()-1;
for(int i=0; i<(lastIndex+1)/2; ++i){
presetHistory.mConfig.mCommands.SwapMemory(i, lastIndex-i);
}
}

//=================================================================================================
// Run a requested Unreal Command
//=================================================================================================
void ExecuteCommand(CommandContext& cmdContext, const TCHAR* pCommand)
{
IConsoleManager::Get().AddConsoleHistoryEntry(TEXT(""), pCommand);
GEngine->DeferredCommands.Add(pCommand);
// Special Case for 'History' Preset, content needs refreshing
if( cmdContext.mPresetIndex == kPresetHistoryIndex ){
UpdatePresetCommandHistory(cmdContext);
}
}

//=================================================================================================
// Handle keyboard inputs for the Window (filter selection change, command exec, ...)
//=================================================================================================
Expand Down Expand Up @@ -323,31 +343,12 @@ void UpdateInput( CommandContext& cmdContext )

//-----------------------------------------------------------------------------------------
// Execute the command entered in the 'Command Input' field
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)) && cmdContext.mpCmdExecutor ) {
cmdContext.mpCmdExecutor->Exec(UTF8_TO_TCHAR(cmdContext.mFilterConfig.mInput));
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter))) {
ExecuteCommand(cmdContext, UTF8_TO_TCHAR(cmdContext.mFilterConfig.mInput));
}
}
}

//=================================================================================================
// Populate the special 'History' Preset, with recently used 'Unreal Commands'
//=================================================================================================
void UpdatePresetCommandHistory(CommandContext& cmdContext)
{
Preset& presetHistory = FindOrCreatePreset(cmdContext, kPresetHistoryName);
presetHistory.mDirty = true;
presetHistory.mSortResults = false; // Want to preserve history order, not name
presetHistory.mConfig.mCommands.Reset();
presetHistory.mConfig.mFilters.Reset();
IConsoleManager::Get().GetConsoleHistory(TEXT(""), presetHistory.mConfig.mCommands);

// Invert the results, listing recent items first
int32 lastIndex = presetHistory.mConfig.mCommands.Num()-1;
for(int i=0; i<(lastIndex+1)/2; ++i){
presetHistory.mConfig.mCommands.SwapMemory(i, lastIndex-i);
}
}

//=================================================================================================
// Draw Console Command Window
//=================================================================================================
Expand Down Expand Up @@ -496,8 +497,8 @@ void DrawFilteredList(CommandContext& cmdContext)
}

// Handle mouse interactions
if (bClicked2x && cmdContext.mpCmdExecutor) {
cmdContext.mpCmdExecutor->Exec(*entry.mCommand);
if (bClicked2x ) {
ExecuteCommand(cmdContext, *entry.mCommand);
}
if (bClicked || bClicked2x) {
cmdContext.mFilteredIndex = i;
Expand Down Expand Up @@ -612,7 +613,6 @@ void Show(CommandContext* pCmdContext)
if (pCmdContext == nullptr) {
return;
}
InitializeExecutor(*pCmdContext);

//---------------------------------------------------------------------------------------------
// Display Unreal Command Window and refresh its content when needed
Expand Down Expand Up @@ -644,7 +644,7 @@ void Show(CommandContext* pCmdContext)
//=================================================================================================
bool& IsVisible(CommandContext* pCmdContext)
{
if (pCmdContext == nullptr || pCmdContext->mpCmdExecutor == nullptr) {
if (pCmdContext == nullptr) {
static bool sInvalid;
sInvalid = false;
return sInvalid;
Expand Down
5 changes: 2 additions & 3 deletions Source/Private/ImUnrealCommand.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
//
// @author : Sammy Fatnassi
// @date : 2022/04/03
// @version : 0.2
// @date : 2022/06/26
// @version : 0.3
// @brief : Support for 'Unreal Commands' through 'Dear ImGui UI'.
// @note : Used 'SOutputLog.cpp' and 'FConsoleCommandExecutor.cpp' as reference
// @note : This '.h/.cpp pair' is part of the 'UnrealNetImgui' library, but can be used standalone in your own Dear ImGui Unreal integration
// @usage : Search for 'IMGUI_UNREAL_COMMAND_ENABLED' in 'https://github.com/sammyfreg/UnrealNetImgui/blob/master/Source/Private/NetImguiModule.cpp'
// 1- Call 'Create()' once
Expand Down
23 changes: 12 additions & 11 deletions Source/Private/ThirdParty/DearImgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.

//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger and other debug tools: ShowMetricsWindow() and ShowStackToolWindow() will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).

//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
Expand Down Expand Up @@ -76,12 +76,13 @@
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION

//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
// #define IMGUI_USE_STB_SPRINTF
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
//#define IMGUI_USE_STB_SPRINTF

//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
Expand All @@ -95,12 +96,12 @@
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
#define IM_VEC2_CLASS_EXTRA \
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
#define IM_VEC4_CLASS_EXTRA \
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/

Expand Down
Loading

0 comments on commit 57ceb17

Please sign in to comment.