mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
ImGui: cleanup and improvement to surface implementation
* Properly run fade in-out animations * Make common methods/members shared * Remove extraneous SDK thread
This commit is contained in:
parent
bddde13b06
commit
44d663bf1c
@ -164,6 +164,8 @@ add_sources( SOURCE_GROUP "GameUI"
|
||||
|
||||
"${ENGINE_SOURCE_DIR}/gameui/imgui_system.cpp"
|
||||
"${ENGINE_SOURCE_DIR}/gameui/imgui_system.h"
|
||||
"${ENGINE_SOURCE_DIR}/gameui/imgui_surface.cpp"
|
||||
"${ENGINE_SOURCE_DIR}/gameui/imgui_surface.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -233,7 +235,6 @@ if( NOT ${PROJECT_NAME} STREQUAL "engine_ds" )
|
||||
add_sources( SOURCE_GROUP "Public"
|
||||
"${ENGINE_SOURCE_DIR}/public/client_class.h"
|
||||
"${ENGINE_SOURCE_DIR}/public/ivrenderview.h"
|
||||
"${ENGINE_SOURCE_DIR}/public/isurfacesystem.h" # ImGui surface
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -7,26 +7,5 @@
|
||||
#include "core/stdafx.h"
|
||||
#include "tier1/cvar.h"
|
||||
#include "engine/sdk_dll.h"
|
||||
#ifndef DEDICATED
|
||||
#include "gameui/IBrowser.h"
|
||||
#include "gameui/IConsole.h"
|
||||
#endif // !DEDICATED
|
||||
|
||||
static ConVar sdk_fixedframe_tickinterval("sdk_fixedframe_tickinterval", "0.01", FCVAR_RELEASE | FCVAR_ACCESSIBLE_FROM_THREADS, "The tick interval used by the SDK fixed frame.");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CEngineSDK::FixedFrame()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
#ifndef DEDICATED
|
||||
g_Browser.Think();
|
||||
g_Console.Think();
|
||||
#endif // !DEDICATED
|
||||
std::this_thread::sleep_for(IntervalToDuration(sdk_fixedframe_tickinterval.GetFloat()));
|
||||
}
|
||||
}
|
||||
|
||||
CEngineSDK g_EngineSDK;
|
||||
|
@ -4,7 +4,6 @@
|
||||
class CEngineSDK
|
||||
{
|
||||
public:
|
||||
void FixedFrame();
|
||||
};
|
||||
|
||||
extern CEngineSDK g_EngineSDK;
|
||||
|
@ -56,9 +56,6 @@ bool CSourceAppSystemGroup::StaticCreate(CSourceAppSystemGroup* pSourceAppSystem
|
||||
//-----------------------------------------------------------------------------
|
||||
int CModAppSystemGroup::StaticMain(CModAppSystemGroup* pModAppSystemGroup)
|
||||
{
|
||||
std::thread fixed(&CEngineSDK::FixedFrame, &g_EngineSDK);
|
||||
fixed.detach();
|
||||
|
||||
int nRunResult = RUN_OK;
|
||||
HEbisuSDK_Init(); // Not here in retail. We init EbisuSDK here though.
|
||||
|
||||
|
@ -40,19 +40,19 @@ int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
if (wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind0 ||
|
||||
wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1)
|
||||
{
|
||||
g_Console.m_bActivate ^= true;
|
||||
g_Console.ToggleActive();
|
||||
ResetInput(); // Disable input to game when console is drawn.
|
||||
}
|
||||
|
||||
if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 ||
|
||||
wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1)
|
||||
{
|
||||
g_Browser.m_bActivate ^= true;
|
||||
g_Browser.ToggleActive();
|
||||
ResetInput(); // Disable input to game when browser is drawn.
|
||||
}
|
||||
}
|
||||
|
||||
if (g_Console.m_bActivate || g_Browser.m_bActivate)
|
||||
if (g_Console.IsActivated() || g_Browser.IsActivated())
|
||||
{//////////////////////////////////////////////////////////////////////////////
|
||||
g_bBlockInput = true;
|
||||
|
||||
|
@ -43,18 +43,14 @@ static ConCommand togglebrowser("togglebrowser", CBrowser::ToggleBrowser_f, "Sho
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
CBrowser::CBrowser(void)
|
||||
: m_pszBrowserLabel("Server Browser")
|
||||
, m_bActivate(false)
|
||||
, m_bInitialized(false)
|
||||
, m_bReclaimFocus(false)
|
||||
, m_bReclaimFocusTokenField(false)
|
||||
: m_bReclaimFocusTokenField(false)
|
||||
, m_bQueryListNonRecursive(false)
|
||||
, m_bQueryGlobalBanList(true)
|
||||
, m_flFadeAlpha(0.f)
|
||||
, m_HostMessageColor(1.00f, 1.00f, 1.00f, 1.00f)
|
||||
, m_ivHiddenServerMessageColor(0.00f, 1.00f, 0.00f, 1.00f)
|
||||
, m_Style(ImGuiStyle_t::NONE)
|
||||
{
|
||||
m_surfaceLabel = "Server Browser";
|
||||
|
||||
memset(m_szServerAddressBuffer, '\0', sizeof(m_szServerAddressBuffer));
|
||||
memset(m_szServerEncKeyBuffer, '\0', sizeof(m_szServerEncKeyBuffer));
|
||||
|
||||
@ -77,7 +73,7 @@ CBrowser::~CBrowser(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CBrowser::Init(void)
|
||||
{
|
||||
SetStyleVar();
|
||||
SetStyleVar(928.f, 524.f, -500.f, 50.f);
|
||||
|
||||
bool ret = LoadTextureBuffer(reinterpret_cast<unsigned char*>(m_rLockedIconBlob.m_pData), int(m_rLockedIconBlob.m_nSize),
|
||||
&m_idLockedIcon, &m_rLockedIconBlob.m_nWidth, &m_rLockedIconBlob.m_nHeight);
|
||||
@ -97,26 +93,29 @@ void CBrowser::RunFrame(void)
|
||||
//ImGui::ShowDemoWindow();
|
||||
}
|
||||
|
||||
if (!m_bInitialized)
|
||||
if (!m_initialized)
|
||||
{
|
||||
Init();
|
||||
m_bInitialized = true;
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
Animate();
|
||||
RunTask();
|
||||
|
||||
int nVars = 0;
|
||||
float flWidth;
|
||||
float flHeight;
|
||||
if (m_Style == ImGuiStyle_t::MODERN)
|
||||
if (m_surfaceStyle == ImGuiStyle_t::MODERN)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 8.f, 10.f }); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||
|
||||
flWidth = 621.f;
|
||||
flHeight = 532.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Style == ImGuiStyle_t::LEGACY)
|
||||
if (m_surfaceStyle == ImGuiStyle_t::LEGACY)
|
||||
{
|
||||
flWidth = 619.f;
|
||||
flHeight = 526.f;
|
||||
@ -128,19 +127,19 @@ void CBrowser::RunFrame(void)
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 6.f, 6.f }); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); nVars++;
|
||||
}
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(flWidth, flHeight)); nVars++;
|
||||
|
||||
if (m_bActivate && m_bReclaimFocus) // Reclaim focus on window apparition.
|
||||
if (m_activated && m_reclaimFocus) // Reclaim focus on window apparition.
|
||||
{
|
||||
ImGui::SetNextWindowFocus();
|
||||
m_bReclaimFocus = false;
|
||||
m_reclaimFocus = false;
|
||||
}
|
||||
|
||||
if (!ImGui::Begin(m_pszBrowserLabel, &m_bActivate, ImGuiWindowFlags_NoScrollbar, &ResetInput))
|
||||
if (!ImGui::Begin(m_surfaceLabel, &m_activated, ImGuiWindowFlags_NoScrollbar, &ResetInput))
|
||||
{
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(nVars);
|
||||
@ -173,7 +172,7 @@ void CBrowser::RunTask()
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
if (m_bActivate)
|
||||
if (m_activated)
|
||||
{
|
||||
if (m_bQueryListNonRecursive)
|
||||
{
|
||||
@ -181,41 +180,17 @@ void CBrowser::RunTask()
|
||||
RefreshServerList();
|
||||
}
|
||||
}
|
||||
else // Refresh server list the next time 'm_bActivate' evaluates to true.
|
||||
else // Refresh server list the next time 'm_activated' evaluates to true.
|
||||
{
|
||||
m_bReclaimFocus = true;
|
||||
m_bReclaimFocusTokenField = true;
|
||||
m_bQueryListNonRecursive = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: think
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBrowser::Think(void)
|
||||
{
|
||||
if (m_bActivate)
|
||||
{
|
||||
if (m_flFadeAlpha < 1.f)
|
||||
{
|
||||
m_flFadeAlpha += .05f;
|
||||
m_flFadeAlpha = (std::min)(m_flFadeAlpha, 1.f);
|
||||
}
|
||||
}
|
||||
else // Reset to full transparent.
|
||||
{
|
||||
if (m_flFadeAlpha > 0.f)
|
||||
{
|
||||
m_flFadeAlpha -= .05f;
|
||||
m_flFadeAlpha = (std::max)(m_flFadeAlpha, 0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draws the compmenu
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBrowser::DrawSurface(void)
|
||||
bool CBrowser::DrawSurface(void)
|
||||
{
|
||||
ImGui::BeginTabBar("CompMenu");
|
||||
if (ImGui::BeginTabItem("Browsing"))
|
||||
@ -231,6 +206,8 @@ void CBrowser::DrawSurface(void)
|
||||
}
|
||||
#endif // !CLIENT_DLL
|
||||
ImGui::EndTabBar();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -261,7 +238,7 @@ void CBrowser::BrowserPanel(void)
|
||||
if (ImGui::BeginTable("##ServerBrowser_ServerListTable", 6, ImGuiTableFlags_Resizable))
|
||||
{
|
||||
int nVars = 0;
|
||||
if (m_Style == ImGuiStyle_t::MODERN)
|
||||
if (m_surfaceStyle == ImGuiStyle_t::MODERN)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); nVars++;
|
||||
}
|
||||
@ -383,7 +360,7 @@ void CBrowser::RefreshServerList(void)
|
||||
void CBrowser::HiddenServersModal(void)
|
||||
{
|
||||
float flHeight; // Set the padding accordingly for each theme.
|
||||
switch (m_Style)
|
||||
switch (m_surfaceStyle)
|
||||
{
|
||||
case ImGuiStyle_t::LEGACY:
|
||||
flHeight = 207.f;
|
||||
@ -829,23 +806,12 @@ void CBrowser::ProcessCommand(const char* pszCommand) const
|
||||
Cbuf_AddText(Cbuf_GetCurrentPlayer(), pszCommand, cmd_source_t::kCommandSrcCode);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the browser front-end style
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBrowser::SetStyleVar(void)
|
||||
{
|
||||
m_Style = g_pImGuiConfig->InitStyle();
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(928.f, 524.f), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(-500.f, 50.f), ImGuiCond_FirstUseEver);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: toggles the server browser
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBrowser::ToggleBrowser_f()
|
||||
{
|
||||
g_Browser.m_bActivate ^= true;
|
||||
g_Browser.m_activated ^= true;
|
||||
ResetInput(); // Disable input to game when browser is drawn.
|
||||
}
|
||||
|
||||
|
@ -4,22 +4,22 @@
|
||||
#include "windows/resource.h"
|
||||
#include "networksystem/serverlisting.h"
|
||||
#include "networksystem/pylon.h"
|
||||
#include "public/isurfacesystem.h"
|
||||
#include "thirdparty/imgui/misc/imgui_utility.h"
|
||||
|
||||
class CBrowser : public IDebugSurface
|
||||
#include "imgui_surface.h"
|
||||
|
||||
class CBrowser : public CImguiSurface
|
||||
{
|
||||
public:
|
||||
CBrowser(void);
|
||||
virtual ~CBrowser(void);
|
||||
|
||||
virtual bool Init(void);
|
||||
virtual void Think(void);
|
||||
|
||||
virtual void RunFrame(void);
|
||||
virtual void RunTask(void);
|
||||
void RunTask(void);
|
||||
|
||||
virtual void DrawSurface(void);
|
||||
virtual bool DrawSurface(void);
|
||||
|
||||
void BrowserPanel(void);
|
||||
void RefreshServerList(void);
|
||||
@ -33,31 +33,21 @@ public:
|
||||
|
||||
void ProcessCommand(const char* pszCommand) const;
|
||||
|
||||
virtual void SetStyleVar(void);
|
||||
|
||||
inline bool IsVisible() { return m_flFadeAlpha > 0.0f; }
|
||||
|
||||
public:
|
||||
// Command callbacks
|
||||
static void ToggleBrowser_f();
|
||||
|
||||
const char* m_pszBrowserLabel;
|
||||
bool m_bActivate;
|
||||
|
||||
private:
|
||||
inline void SetServerListMessage(const char* const message) { m_svServerListMessage = message; };
|
||||
inline void SetHostMessage(const char* const message) { m_svHostMessage = message; }
|
||||
inline void SetHostToken(const char* const message) { m_svHostToken = message; }
|
||||
|
||||
private:
|
||||
bool m_bInitialized;
|
||||
bool m_bReclaimFocus;
|
||||
bool m_bReclaimFocusTokenField;
|
||||
bool m_bQueryListNonRecursive; // When set, refreshes the server list once the next frame.
|
||||
bool m_bQueryGlobalBanList;
|
||||
char m_szServerAddressBuffer[128];
|
||||
char m_szServerEncKeyBuffer[30];
|
||||
float m_flFadeAlpha;
|
||||
|
||||
ID3D11ShaderResourceView* m_idLockedIcon;
|
||||
MODULERESOURCE m_rLockedIconBlob;
|
||||
@ -80,8 +70,6 @@ private:
|
||||
////////////////////
|
||||
string m_svHiddenServerRequestMessage;
|
||||
ImVec4 m_ivHiddenServerMessageColor;
|
||||
|
||||
ImGuiStyle_t m_Style;
|
||||
};
|
||||
|
||||
extern CBrowser g_Browser;
|
||||
|
@ -48,8 +48,7 @@ static ConCommand con_clearhistory("con_clearhistory", CConsole::ClearHistory_f,
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
CConsole::CConsole(void)
|
||||
: m_pszConsoleLabel("Console")
|
||||
, m_pszLoggingLabel("LoggingRegion")
|
||||
: m_pszLoggingLabel("LoggingRegion")
|
||||
, m_nHistoryPos(PositionMode_t::kPark)
|
||||
, m_nSuggestPos(PositionMode_t::kPark)
|
||||
, m_nScrollBack(0)
|
||||
@ -57,18 +56,15 @@ CConsole::CConsole(void)
|
||||
, m_nInputTextLen(0)
|
||||
, m_flScrollX(0.f)
|
||||
, m_flScrollY(0.f)
|
||||
, m_flFadeAlpha(0.f)
|
||||
, m_bInitialized(false)
|
||||
, m_bReclaimFocus(false)
|
||||
, m_bCopyToClipBoard(false)
|
||||
, m_bModifyInput(false)
|
||||
, m_bCanAutoComplete(false)
|
||||
, m_bSuggestActive(false)
|
||||
, m_bSuggestMoved(false)
|
||||
, m_bSuggestUpdate(false)
|
||||
, m_Style(ImGuiStyle_t::NONE)
|
||||
, m_bActivate(false)
|
||||
{
|
||||
m_surfaceLabel = "Console";
|
||||
|
||||
m_nInputFlags =
|
||||
ImGuiInputTextFlags_EnterReturnsTrue |
|
||||
ImGuiInputTextFlags_CallbackCompletion |
|
||||
@ -117,7 +113,7 @@ CConsole::~CConsole(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CConsole::Init(void)
|
||||
{
|
||||
SetStyleVar();
|
||||
SetStyleVar(1200, 524, -1000, 50);
|
||||
return LoadFlagIcons();
|
||||
}
|
||||
|
||||
@ -136,26 +132,28 @@ void CConsole::RunFrame(void)
|
||||
* BASE PANEL SETUP *
|
||||
**************************/
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
if (!m_initialized)
|
||||
{
|
||||
Init();
|
||||
m_bInitialized = true;
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
Animate();
|
||||
|
||||
int nVars = 0;
|
||||
float flWidth;
|
||||
float flHeight;
|
||||
if (m_Style == ImGuiStyle_t::MODERN)
|
||||
if (m_surfaceStyle == ImGuiStyle_t::MODERN)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 8.f, 10.f }); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||
|
||||
flWidth = 621.f;
|
||||
flHeight = 532.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Style == ImGuiStyle_t::LEGACY)
|
||||
if (m_surfaceStyle == ImGuiStyle_t::LEGACY)
|
||||
{
|
||||
flWidth = 619.f;
|
||||
flHeight = 526.f;
|
||||
@ -167,7 +165,7 @@ void CConsole::RunFrame(void)
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 6.f, 6.f }); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||
}
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(flWidth, flHeight)); nVars++;
|
||||
|
||||
@ -182,7 +180,7 @@ void CConsole::RunFrame(void)
|
||||
int nVars = 0;
|
||||
if (AutoComplete())
|
||||
{
|
||||
if (m_Style == ImGuiStyle_t::MODERN)
|
||||
if (m_surfaceStyle == ImGuiStyle_t::MODERN)
|
||||
{
|
||||
const ImGuiStyle& style = ImGui::GetStyle();
|
||||
m_ivSuggestWindowPos.y = m_ivSuggestWindowPos.y + style.WindowPadding.y + 1.5f;
|
||||
@ -198,7 +196,7 @@ void CConsole::RunFrame(void)
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(500, 37)); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||
|
||||
SuggestPanel();
|
||||
|
||||
@ -207,48 +205,16 @@ void CConsole::RunFrame(void)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: runs tasks for the console while not being drawn
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::RunTask(void)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: think
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::Think(void)
|
||||
{
|
||||
if (m_bActivate)
|
||||
{
|
||||
if (m_flFadeAlpha < 1.f)
|
||||
{
|
||||
m_flFadeAlpha += .05f;
|
||||
m_flFadeAlpha = (std::min)(m_flFadeAlpha, 1.f);
|
||||
}
|
||||
}
|
||||
else // Reset to full transparent.
|
||||
{
|
||||
if (m_flFadeAlpha > 0.f)
|
||||
{
|
||||
m_flFadeAlpha -= .05f;
|
||||
m_flFadeAlpha = (std::max)(m_flFadeAlpha, 0.f);
|
||||
}
|
||||
|
||||
m_bReclaimFocus = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draws the console's main surface
|
||||
// Input : *bDraw -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::DrawSurface(void)
|
||||
bool CConsole::DrawSurface(void)
|
||||
{
|
||||
if (!ImGui::Begin(m_pszConsoleLabel, &m_bActivate, ImGuiWindowFlags_None, &ResetInput))
|
||||
if (!ImGui::Begin(m_surfaceLabel, &m_activated, ImGuiWindowFlags_None, &ResetInput))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const ImGuiStyle& style = ImGui::GetStyle();
|
||||
@ -283,7 +249,7 @@ void CConsole::DrawSurface(void)
|
||||
ImGuiWindow* pWindow = ImGui::GetCurrentWindow();
|
||||
ImGuiID nID = pWindow->GetID(m_pszLoggingLabel);
|
||||
|
||||
snprintf(m_szWindowLabel, sizeof(m_szWindowLabel), "%s/%s_%08X", m_pszConsoleLabel, m_pszLoggingLabel, nID);
|
||||
snprintf(m_szWindowLabel, sizeof(m_szWindowLabel), "%s/%s_%08X", m_surfaceLabel, m_pszLoggingLabel, nID);
|
||||
ImGui::SetWindowScrollY(m_szWindowLabel, m_flScrollY - m_nScrollBack * fontSize.y);
|
||||
}
|
||||
m_nScrollBack = 0;
|
||||
@ -321,7 +287,7 @@ void CConsole::DrawSurface(void)
|
||||
}
|
||||
|
||||
BuildSummary();
|
||||
m_bReclaimFocus = true;
|
||||
m_reclaimFocus = true;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
@ -336,7 +302,7 @@ void CConsole::DrawSurface(void)
|
||||
BuildSummary(m_svInputConVar);
|
||||
|
||||
m_bModifyInput = true;
|
||||
m_bReclaimFocus = true;
|
||||
m_reclaimFocus = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -348,10 +314,10 @@ void CConsole::DrawSurface(void)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
|
||||
// Auto-focus input field if reclaim is demanded.
|
||||
if (m_bReclaimFocus)
|
||||
if (m_reclaimFocus)
|
||||
{
|
||||
ImGui::SetKeyboardFocusHere(-1); // -1 means previous widget.
|
||||
m_bReclaimFocus = false;
|
||||
m_reclaimFocus = false;
|
||||
}
|
||||
|
||||
BuildSuggestPanelRect();
|
||||
@ -361,7 +327,9 @@ void CConsole::DrawSurface(void)
|
||||
{
|
||||
fnHandleInput();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -472,7 +440,7 @@ void CConsole::SuggestPanel(void)
|
||||
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
|
||||
|
||||
m_bCanAutoComplete = true;
|
||||
m_bReclaimFocus = true;
|
||||
m_reclaimFocus = true;
|
||||
|
||||
BuildSummary(svConVar);
|
||||
}
|
||||
@ -962,7 +930,7 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData)
|
||||
m_svInputConVar.clear();
|
||||
|
||||
m_bCanAutoComplete = true;
|
||||
m_bReclaimFocus = true;
|
||||
m_reclaimFocus = true;
|
||||
}
|
||||
m_bModifyInput = false;
|
||||
}
|
||||
@ -1182,23 +1150,12 @@ void CConsole::ClampHistorySize(void)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the console front-end style
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::SetStyleVar(void)
|
||||
{
|
||||
m_Style = g_pImGuiConfig->InitStyle();
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(1200, 524), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: toggles the console
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::ToggleConsole_f()
|
||||
{
|
||||
g_Console.m_bActivate ^= true;
|
||||
g_Console.m_activated ^= true;
|
||||
ResetInput(); // Disable input to game when console is drawn.
|
||||
}
|
||||
|
||||
|
@ -2,31 +2,22 @@
|
||||
#ifndef DEDICATED
|
||||
#include "common/sdkdefs.h"
|
||||
#include "windows/resource.h"
|
||||
#include "public/isurfacesystem.h"
|
||||
#include "thirdparty/imgui/misc/imgui_logger.h"
|
||||
#include "thirdparty/imgui/misc/imgui_utility.h"
|
||||
#include "imgui/misc/imgui_logger.h"
|
||||
#include "imgui/misc/imgui_utility.h"
|
||||
|
||||
class CConsole : public IDebugSurface
|
||||
#include "imgui_surface.h"
|
||||
|
||||
class CConsole : public CImguiSurface
|
||||
{
|
||||
public:
|
||||
enum PositionMode_t
|
||||
{
|
||||
// Park means the position is out of screen.
|
||||
kPark = -1,
|
||||
kFirst,
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
CConsole(void);
|
||||
virtual ~CConsole(void);
|
||||
|
||||
virtual bool Init(void);
|
||||
virtual void Think(void);
|
||||
|
||||
virtual void RunFrame(void);
|
||||
virtual void RunTask(void);
|
||||
|
||||
virtual void DrawSurface(void);
|
||||
virtual bool DrawSurface(void);
|
||||
|
||||
private:
|
||||
void OptionsPanel(void);
|
||||
@ -39,6 +30,8 @@ private:
|
||||
void ProcessCommand(string svCommand);
|
||||
|
||||
void BuildSummary(string svConVar = "");
|
||||
|
||||
struct CSuggest;
|
||||
void BuildInputFromSelected(const CSuggest& suggest, string& svInput);
|
||||
void BuildSuggestPanelRect(void);
|
||||
|
||||
@ -58,8 +51,6 @@ public:
|
||||
const vector<string>& GetHistory(void) const;
|
||||
void ClearHistory(void);
|
||||
|
||||
inline bool IsVisible() { return m_flFadeAlpha > 0.0f; }
|
||||
|
||||
public:
|
||||
// Console command callbacks
|
||||
static void ToggleConsole_f();
|
||||
@ -74,12 +65,36 @@ private: // Internals.
|
||||
void ClampLogSize(void);
|
||||
void ClampHistorySize(void);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void SetStyleVar(void);
|
||||
private:
|
||||
enum PositionMode_t
|
||||
{
|
||||
// Park means the position is out of screen.
|
||||
kPark = -1,
|
||||
kFirst,
|
||||
};
|
||||
|
||||
struct CSuggest
|
||||
{
|
||||
CSuggest(const string& svName, int nFlags)
|
||||
{
|
||||
m_svName = svName;
|
||||
m_nFlags = nFlags;
|
||||
}
|
||||
bool operator==(const string& a) const
|
||||
{
|
||||
return m_svName.compare(a) == 0;
|
||||
}
|
||||
bool operator<(const CSuggest& a) const
|
||||
{
|
||||
return m_svName < a.m_svName;
|
||||
}
|
||||
|
||||
string m_svName;
|
||||
int m_nFlags;
|
||||
};
|
||||
|
||||
private:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
const char* m_pszConsoleLabel;
|
||||
const char* m_pszLoggingLabel;
|
||||
char m_szInputBuf[512];
|
||||
char m_szSummary[256];
|
||||
@ -93,10 +108,7 @@ private:
|
||||
int m_nInputTextLen;
|
||||
float m_flScrollX;
|
||||
float m_flScrollY;
|
||||
float m_flFadeAlpha;
|
||||
|
||||
bool m_bInitialized;
|
||||
bool m_bReclaimFocus;
|
||||
bool m_bCopyToClipBoard;
|
||||
bool m_bModifyInput;
|
||||
|
||||
@ -109,7 +121,6 @@ private:
|
||||
vector<MODULERESOURCE> m_vFlagIcons;
|
||||
vector<string> m_vHistory;
|
||||
|
||||
ImGuiStyle_t m_Style;
|
||||
ImVec2 m_ivSuggestWindowPos;
|
||||
ImVec2 m_ivSuggestWindowSize;
|
||||
|
||||
@ -119,9 +130,6 @@ private:
|
||||
ImGuiInputTextFlags m_nInputFlags;
|
||||
ImGuiWindowFlags m_nSuggestFlags;
|
||||
ImGuiWindowFlags m_nLoggingFlags;
|
||||
|
||||
public:
|
||||
bool m_bActivate = false;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
43
r5dev/gameui/imgui_surface.cpp
Normal file
43
r5dev/gameui/imgui_surface.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "imgui_surface.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
CImguiSurface::CImguiSurface()
|
||||
: m_surfaceLabel("Surface")
|
||||
, m_fadeAlpha(0.0f)
|
||||
, m_surfaceStyle(ImGuiStyle_t::NONE)
|
||||
, m_initialized(false)
|
||||
, m_activated(false)
|
||||
, m_reclaimFocus(false)
|
||||
{}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: fade surface in and out smoothly
|
||||
//-----------------------------------------------------------------------------
|
||||
void CImguiSurface::Animate()
|
||||
{
|
||||
const float deltaTime = ImGui::GetIO().DeltaTime;
|
||||
const float animSpeed = m_activated
|
||||
? IMGUI_SURFACE_FADE_ANIM_SPEED
|
||||
: -IMGUI_SURFACE_FADE_ANIM_SPEED;
|
||||
|
||||
m_fadeAlpha += animSpeed * deltaTime;
|
||||
m_fadeAlpha = ImClamp(m_fadeAlpha, 0.0f, 1.0f);
|
||||
|
||||
// Reclaim focus the next time we activate the panel
|
||||
if (!m_activated)
|
||||
m_reclaimFocus = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: sets the surface front-end style and initial positions/sizes
|
||||
//-----------------------------------------------------------------------------
|
||||
void CImguiSurface::SetStyleVar(const float width, const float height,
|
||||
const float x, const float y)
|
||||
{
|
||||
m_surfaceStyle = g_pImGuiConfig->InitStyle();
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(width, height), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_FirstUseEver);
|
||||
}
|
38
r5dev/gameui/imgui_surface.h
Normal file
38
r5dev/gameui/imgui_surface.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef IMGUI_SURFACE_H
|
||||
#define IMGUI_SURFACE_H
|
||||
|
||||
#define IMGUI_SURFACE_FADE_ANIM_SPEED 5.0f
|
||||
|
||||
#include "imgui/misc/imgui_utility.h"
|
||||
|
||||
class CImguiSurface
|
||||
{
|
||||
public:
|
||||
CImguiSurface();
|
||||
virtual ~CImguiSurface() { };
|
||||
virtual bool Init() = 0;
|
||||
|
||||
virtual void Animate();
|
||||
virtual void RunFrame() = 0;
|
||||
|
||||
virtual bool DrawSurface() = 0;
|
||||
virtual void SetStyleVar(const float width, const float height, const float x, const float y);
|
||||
|
||||
// inlines:
|
||||
inline void ToggleActive() { m_activated ^= true; }
|
||||
|
||||
inline bool IsActivated() { return m_activated; }
|
||||
inline bool IsVisible() { return m_fadeAlpha > 0.0f; }
|
||||
|
||||
protected:
|
||||
const char* m_surfaceLabel;
|
||||
|
||||
float m_fadeAlpha;
|
||||
ImGuiStyle_t m_surfaceStyle;
|
||||
|
||||
bool m_initialized;
|
||||
bool m_activated;
|
||||
bool m_reclaimFocus;
|
||||
};
|
||||
|
||||
#endif // IMGUI_SURFACE_H
|
@ -131,10 +131,7 @@ void CImguiSystem::SampleFrame()
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
g_Browser.RunTask();
|
||||
g_Browser.RunFrame();
|
||||
|
||||
g_Console.RunTask();
|
||||
g_Console.RunFrame();
|
||||
|
||||
ImGui::EndFrame();
|
||||
|
@ -1,35 +0,0 @@
|
||||
#ifndef ISURFACESYSTEM_H
|
||||
#define ISURFACESYSTEM_H
|
||||
|
||||
class IDebugSurface
|
||||
{
|
||||
public:
|
||||
virtual ~IDebugSurface() { };
|
||||
virtual bool Init() = 0;
|
||||
virtual void Think() = 0;
|
||||
virtual void RunFrame() = 0;
|
||||
virtual void RunTask() = 0;
|
||||
virtual void DrawSurface() = 0;
|
||||
virtual void SetStyleVar() = 0;
|
||||
};
|
||||
|
||||
struct CSuggest
|
||||
{
|
||||
CSuggest(const string& svName, int nFlags)
|
||||
{
|
||||
m_svName = svName;
|
||||
m_nFlags = nFlags;
|
||||
}
|
||||
bool operator==(const string& a) const
|
||||
{
|
||||
return m_svName.compare(a) == 0;
|
||||
}
|
||||
bool operator<(const CSuggest& a) const
|
||||
{
|
||||
return m_svName < a.m_svName;
|
||||
}
|
||||
string m_svName;
|
||||
int m_nFlags;
|
||||
};
|
||||
|
||||
#endif // ISURFACESYSTEM_H
|
@ -298,12 +298,12 @@ bool LoadTextureBuffer(unsigned char* buffer, int len, ID3D11ShaderResourceView*
|
||||
void ResetInput()
|
||||
{
|
||||
g_pInputSystem->EnableInput( // Enables the input system when both are not drawn.
|
||||
!g_Browser.m_bActivate && !g_Console.m_bActivate);
|
||||
!g_Browser.IsActivated() && !g_Console.IsActivated());
|
||||
}
|
||||
|
||||
bool PanelsVisible()
|
||||
{
|
||||
if (g_Browser.m_bActivate || g_Console.m_bActivate)
|
||||
if (g_Browser.IsActivated() || g_Console.IsActivated())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user