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
e311051148
commit
8f09ac1b86
@ -164,6 +164,8 @@ add_sources( SOURCE_GROUP "GameUI"
|
|||||||
|
|
||||||
"${ENGINE_SOURCE_DIR}/gameui/imgui_system.cpp"
|
"${ENGINE_SOURCE_DIR}/gameui/imgui_system.cpp"
|
||||||
"${ENGINE_SOURCE_DIR}/gameui/imgui_system.h"
|
"${ENGINE_SOURCE_DIR}/gameui/imgui_system.h"
|
||||||
|
"${ENGINE_SOURCE_DIR}/gameui/imgui_surface.cpp"
|
||||||
|
"${ENGINE_SOURCE_DIR}/gameui/imgui_surface.h"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -233,7 +235,6 @@ if( NOT ${PROJECT_NAME} STREQUAL "engine_ds" )
|
|||||||
add_sources( SOURCE_GROUP "Public"
|
add_sources( SOURCE_GROUP "Public"
|
||||||
"${ENGINE_SOURCE_DIR}/public/client_class.h"
|
"${ENGINE_SOURCE_DIR}/public/client_class.h"
|
||||||
"${ENGINE_SOURCE_DIR}/public/ivrenderview.h"
|
"${ENGINE_SOURCE_DIR}/public/ivrenderview.h"
|
||||||
"${ENGINE_SOURCE_DIR}/public/isurfacesystem.h" # ImGui surface
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -7,26 +7,5 @@
|
|||||||
#include "core/stdafx.h"
|
#include "core/stdafx.h"
|
||||||
#include "tier1/cvar.h"
|
#include "tier1/cvar.h"
|
||||||
#include "engine/sdk_dll.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;
|
CEngineSDK g_EngineSDK;
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
class CEngineSDK
|
class CEngineSDK
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void FixedFrame();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CEngineSDK g_EngineSDK;
|
extern CEngineSDK g_EngineSDK;
|
||||||
|
@ -56,9 +56,6 @@ bool CSourceAppSystemGroup::StaticCreate(CSourceAppSystemGroup* pSourceAppSystem
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
int CModAppSystemGroup::StaticMain(CModAppSystemGroup* pModAppSystemGroup)
|
int CModAppSystemGroup::StaticMain(CModAppSystemGroup* pModAppSystemGroup)
|
||||||
{
|
{
|
||||||
std::thread fixed(&CEngineSDK::FixedFrame, &g_EngineSDK);
|
|
||||||
fixed.detach();
|
|
||||||
|
|
||||||
int nRunResult = RUN_OK;
|
int nRunResult = RUN_OK;
|
||||||
HEbisuSDK_Init(); // Not here in retail. We init EbisuSDK here though.
|
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 ||
|
if (wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind0 ||
|
||||||
wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1)
|
wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1)
|
||||||
{
|
{
|
||||||
g_Console.m_bActivate ^= true;
|
g_Console.ToggleActive();
|
||||||
ResetInput(); // Disable input to game when console is drawn.
|
ResetInput(); // Disable input to game when console is drawn.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 ||
|
if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 ||
|
||||||
wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1)
|
wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1)
|
||||||
{
|
{
|
||||||
g_Browser.m_bActivate ^= true;
|
g_Browser.ToggleActive();
|
||||||
ResetInput(); // Disable input to game when browser is drawn.
|
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;
|
g_bBlockInput = true;
|
||||||
|
|
||||||
|
@ -43,18 +43,14 @@ static ConCommand togglebrowser("togglebrowser", CBrowser::ToggleBrowser_f, "Sho
|
|||||||
// Purpose:
|
// Purpose:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
CBrowser::CBrowser(void)
|
CBrowser::CBrowser(void)
|
||||||
: m_pszBrowserLabel("Server Browser")
|
: m_bReclaimFocusTokenField(false)
|
||||||
, m_bActivate(false)
|
|
||||||
, m_bInitialized(false)
|
|
||||||
, m_bReclaimFocus(false)
|
|
||||||
, m_bReclaimFocusTokenField(false)
|
|
||||||
, m_bQueryListNonRecursive(false)
|
, m_bQueryListNonRecursive(false)
|
||||||
, m_bQueryGlobalBanList(true)
|
, m_bQueryGlobalBanList(true)
|
||||||
, m_flFadeAlpha(0.f)
|
|
||||||
, m_HostMessageColor(1.00f, 1.00f, 1.00f, 1.00f)
|
, m_HostMessageColor(1.00f, 1.00f, 1.00f, 1.00f)
|
||||||
, m_ivHiddenServerMessageColor(0.00f, 1.00f, 0.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_szServerAddressBuffer, '\0', sizeof(m_szServerAddressBuffer));
|
||||||
memset(m_szServerEncKeyBuffer, '\0', sizeof(m_szServerEncKeyBuffer));
|
memset(m_szServerEncKeyBuffer, '\0', sizeof(m_szServerEncKeyBuffer));
|
||||||
|
|
||||||
@ -77,7 +73,7 @@ CBrowser::~CBrowser(void)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool CBrowser::Init(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),
|
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);
|
&m_idLockedIcon, &m_rLockedIconBlob.m_nWidth, &m_rLockedIconBlob.m_nHeight);
|
||||||
@ -97,26 +93,29 @@ void CBrowser::RunFrame(void)
|
|||||||
//ImGui::ShowDemoWindow();
|
//ImGui::ShowDemoWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_bInitialized)
|
if (!m_initialized)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
m_bInitialized = true;
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Animate();
|
||||||
|
RunTask();
|
||||||
|
|
||||||
int nVars = 0;
|
int nVars = 0;
|
||||||
float flWidth;
|
float flWidth;
|
||||||
float flHeight;
|
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_WindowPadding, ImVec2{ 8.f, 10.f }); nVars++;
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||||
|
|
||||||
flWidth = 621.f;
|
flWidth = 621.f;
|
||||||
flHeight = 532.f;
|
flHeight = 532.f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_Style == ImGuiStyle_t::LEGACY)
|
if (m_surfaceStyle == ImGuiStyle_t::LEGACY)
|
||||||
{
|
{
|
||||||
flWidth = 619.f;
|
flWidth = 619.f;
|
||||||
flHeight = 526.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_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_ChildBorderSize, 1.0f); nVars++;
|
||||||
}
|
}
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(flWidth, flHeight)); 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();
|
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::End();
|
||||||
ImGui::PopStyleVar(nVars);
|
ImGui::PopStyleVar(nVars);
|
||||||
@ -173,7 +172,7 @@ void CBrowser::RunTask()
|
|||||||
timer.Start();
|
timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_bActivate)
|
if (m_activated)
|
||||||
{
|
{
|
||||||
if (m_bQueryListNonRecursive)
|
if (m_bQueryListNonRecursive)
|
||||||
{
|
{
|
||||||
@ -181,41 +180,17 @@ void CBrowser::RunTask()
|
|||||||
RefreshServerList();
|
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_bReclaimFocusTokenField = true;
|
||||||
m_bQueryListNonRecursive = 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
|
// Purpose: draws the compmenu
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void CBrowser::DrawSurface(void)
|
bool CBrowser::DrawSurface(void)
|
||||||
{
|
{
|
||||||
ImGui::BeginTabBar("CompMenu");
|
ImGui::BeginTabBar("CompMenu");
|
||||||
if (ImGui::BeginTabItem("Browsing"))
|
if (ImGui::BeginTabItem("Browsing"))
|
||||||
@ -231,6 +206,8 @@ void CBrowser::DrawSurface(void)
|
|||||||
}
|
}
|
||||||
#endif // !CLIENT_DLL
|
#endif // !CLIENT_DLL
|
||||||
ImGui::EndTabBar();
|
ImGui::EndTabBar();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -261,7 +238,7 @@ void CBrowser::BrowserPanel(void)
|
|||||||
if (ImGui::BeginTable("##ServerBrowser_ServerListTable", 6, ImGuiTableFlags_Resizable))
|
if (ImGui::BeginTable("##ServerBrowser_ServerListTable", 6, ImGuiTableFlags_Resizable))
|
||||||
{
|
{
|
||||||
int nVars = 0;
|
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++;
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); nVars++;
|
||||||
}
|
}
|
||||||
@ -383,7 +360,7 @@ void CBrowser::RefreshServerList(void)
|
|||||||
void CBrowser::HiddenServersModal(void)
|
void CBrowser::HiddenServersModal(void)
|
||||||
{
|
{
|
||||||
float flHeight; // Set the padding accordingly for each theme.
|
float flHeight; // Set the padding accordingly for each theme.
|
||||||
switch (m_Style)
|
switch (m_surfaceStyle)
|
||||||
{
|
{
|
||||||
case ImGuiStyle_t::LEGACY:
|
case ImGuiStyle_t::LEGACY:
|
||||||
flHeight = 207.f;
|
flHeight = 207.f;
|
||||||
@ -829,23 +806,12 @@ void CBrowser::ProcessCommand(const char* pszCommand) const
|
|||||||
Cbuf_AddText(Cbuf_GetCurrentPlayer(), pszCommand, cmd_source_t::kCommandSrcCode);
|
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
|
// Purpose: toggles the server browser
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void CBrowser::ToggleBrowser_f()
|
void CBrowser::ToggleBrowser_f()
|
||||||
{
|
{
|
||||||
g_Browser.m_bActivate ^= true;
|
g_Browser.m_activated ^= true;
|
||||||
ResetInput(); // Disable input to game when browser is drawn.
|
ResetInput(); // Disable input to game when browser is drawn.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,22 +4,22 @@
|
|||||||
#include "windows/resource.h"
|
#include "windows/resource.h"
|
||||||
#include "networksystem/serverlisting.h"
|
#include "networksystem/serverlisting.h"
|
||||||
#include "networksystem/pylon.h"
|
#include "networksystem/pylon.h"
|
||||||
#include "public/isurfacesystem.h"
|
|
||||||
#include "thirdparty/imgui/misc/imgui_utility.h"
|
#include "thirdparty/imgui/misc/imgui_utility.h"
|
||||||
|
|
||||||
class CBrowser : public IDebugSurface
|
#include "imgui_surface.h"
|
||||||
|
|
||||||
|
class CBrowser : public CImguiSurface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CBrowser(void);
|
CBrowser(void);
|
||||||
virtual ~CBrowser(void);
|
virtual ~CBrowser(void);
|
||||||
|
|
||||||
virtual bool Init(void);
|
virtual bool Init(void);
|
||||||
virtual void Think(void);
|
|
||||||
|
|
||||||
virtual void RunFrame(void);
|
virtual void RunFrame(void);
|
||||||
virtual void RunTask(void);
|
void RunTask(void);
|
||||||
|
|
||||||
virtual void DrawSurface(void);
|
virtual bool DrawSurface(void);
|
||||||
|
|
||||||
void BrowserPanel(void);
|
void BrowserPanel(void);
|
||||||
void RefreshServerList(void);
|
void RefreshServerList(void);
|
||||||
@ -33,31 +33,21 @@ public:
|
|||||||
|
|
||||||
void ProcessCommand(const char* pszCommand) const;
|
void ProcessCommand(const char* pszCommand) const;
|
||||||
|
|
||||||
virtual void SetStyleVar(void);
|
|
||||||
|
|
||||||
inline bool IsVisible() { return m_flFadeAlpha > 0.0f; }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Command callbacks
|
// Command callbacks
|
||||||
static void ToggleBrowser_f();
|
static void ToggleBrowser_f();
|
||||||
|
|
||||||
const char* m_pszBrowserLabel;
|
|
||||||
bool m_bActivate;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void SetServerListMessage(const char* const message) { m_svServerListMessage = message; };
|
inline void SetServerListMessage(const char* const message) { m_svServerListMessage = message; };
|
||||||
inline void SetHostMessage(const char* const message) { m_svHostMessage = message; }
|
inline void SetHostMessage(const char* const message) { m_svHostMessage = message; }
|
||||||
inline void SetHostToken(const char* const message) { m_svHostToken = message; }
|
inline void SetHostToken(const char* const message) { m_svHostToken = message; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_bInitialized;
|
|
||||||
bool m_bReclaimFocus;
|
|
||||||
bool m_bReclaimFocusTokenField;
|
bool m_bReclaimFocusTokenField;
|
||||||
bool m_bQueryListNonRecursive; // When set, refreshes the server list once the next frame.
|
bool m_bQueryListNonRecursive; // When set, refreshes the server list once the next frame.
|
||||||
bool m_bQueryGlobalBanList;
|
bool m_bQueryGlobalBanList;
|
||||||
char m_szServerAddressBuffer[128];
|
char m_szServerAddressBuffer[128];
|
||||||
char m_szServerEncKeyBuffer[30];
|
char m_szServerEncKeyBuffer[30];
|
||||||
float m_flFadeAlpha;
|
|
||||||
|
|
||||||
ID3D11ShaderResourceView* m_idLockedIcon;
|
ID3D11ShaderResourceView* m_idLockedIcon;
|
||||||
MODULERESOURCE m_rLockedIconBlob;
|
MODULERESOURCE m_rLockedIconBlob;
|
||||||
@ -80,8 +70,6 @@ private:
|
|||||||
////////////////////
|
////////////////////
|
||||||
string m_svHiddenServerRequestMessage;
|
string m_svHiddenServerRequestMessage;
|
||||||
ImVec4 m_ivHiddenServerMessageColor;
|
ImVec4 m_ivHiddenServerMessageColor;
|
||||||
|
|
||||||
ImGuiStyle_t m_Style;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CBrowser g_Browser;
|
extern CBrowser g_Browser;
|
||||||
|
@ -48,8 +48,7 @@ static ConCommand con_clearhistory("con_clearhistory", CConsole::ClearHistory_f,
|
|||||||
// Purpose:
|
// Purpose:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
CConsole::CConsole(void)
|
CConsole::CConsole(void)
|
||||||
: m_pszConsoleLabel("Console")
|
: m_pszLoggingLabel("LoggingRegion")
|
||||||
, m_pszLoggingLabel("LoggingRegion")
|
|
||||||
, m_nHistoryPos(PositionMode_t::kPark)
|
, m_nHistoryPos(PositionMode_t::kPark)
|
||||||
, m_nSuggestPos(PositionMode_t::kPark)
|
, m_nSuggestPos(PositionMode_t::kPark)
|
||||||
, m_nScrollBack(0)
|
, m_nScrollBack(0)
|
||||||
@ -57,18 +56,15 @@ CConsole::CConsole(void)
|
|||||||
, m_nInputTextLen(0)
|
, m_nInputTextLen(0)
|
||||||
, m_flScrollX(0.f)
|
, m_flScrollX(0.f)
|
||||||
, m_flScrollY(0.f)
|
, m_flScrollY(0.f)
|
||||||
, m_flFadeAlpha(0.f)
|
|
||||||
, m_bInitialized(false)
|
|
||||||
, m_bReclaimFocus(false)
|
|
||||||
, m_bCopyToClipBoard(false)
|
, m_bCopyToClipBoard(false)
|
||||||
, m_bModifyInput(false)
|
, m_bModifyInput(false)
|
||||||
, m_bCanAutoComplete(false)
|
, m_bCanAutoComplete(false)
|
||||||
, m_bSuggestActive(false)
|
, m_bSuggestActive(false)
|
||||||
, m_bSuggestMoved(false)
|
, m_bSuggestMoved(false)
|
||||||
, m_bSuggestUpdate(false)
|
, m_bSuggestUpdate(false)
|
||||||
, m_Style(ImGuiStyle_t::NONE)
|
|
||||||
, m_bActivate(false)
|
|
||||||
{
|
{
|
||||||
|
m_surfaceLabel = "Console";
|
||||||
|
|
||||||
m_nInputFlags =
|
m_nInputFlags =
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue |
|
ImGuiInputTextFlags_EnterReturnsTrue |
|
||||||
ImGuiInputTextFlags_CallbackCompletion |
|
ImGuiInputTextFlags_CallbackCompletion |
|
||||||
@ -117,7 +113,7 @@ CConsole::~CConsole(void)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool CConsole::Init(void)
|
bool CConsole::Init(void)
|
||||||
{
|
{
|
||||||
SetStyleVar();
|
SetStyleVar(1200, 524, -1000, 50);
|
||||||
return LoadFlagIcons();
|
return LoadFlagIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,26 +132,28 @@ void CConsole::RunFrame(void)
|
|||||||
* BASE PANEL SETUP *
|
* BASE PANEL SETUP *
|
||||||
**************************/
|
**************************/
|
||||||
{
|
{
|
||||||
if (!m_bInitialized)
|
if (!m_initialized)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
m_bInitialized = true;
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Animate();
|
||||||
|
|
||||||
int nVars = 0;
|
int nVars = 0;
|
||||||
float flWidth;
|
float flWidth;
|
||||||
float flHeight;
|
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_WindowPadding, ImVec2{ 8.f, 10.f }); nVars++;
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||||
|
|
||||||
flWidth = 621.f;
|
flWidth = 621.f;
|
||||||
flHeight = 532.f;
|
flHeight = 532.f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_Style == ImGuiStyle_t::LEGACY)
|
if (m_surfaceStyle == ImGuiStyle_t::LEGACY)
|
||||||
{
|
{
|
||||||
flWidth = 619.f;
|
flWidth = 619.f;
|
||||||
flHeight = 526.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_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++;
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(flWidth, flHeight)); nVars++;
|
||||||
|
|
||||||
@ -182,7 +180,7 @@ void CConsole::RunFrame(void)
|
|||||||
int nVars = 0;
|
int nVars = 0;
|
||||||
if (AutoComplete())
|
if (AutoComplete())
|
||||||
{
|
{
|
||||||
if (m_Style == ImGuiStyle_t::MODERN)
|
if (m_surfaceStyle == ImGuiStyle_t::MODERN)
|
||||||
{
|
{
|
||||||
const ImGuiStyle& style = ImGui::GetStyle();
|
const ImGuiStyle& style = ImGui::GetStyle();
|
||||||
m_ivSuggestWindowPos.y = m_ivSuggestWindowPos.y + style.WindowPadding.y + 1.5f;
|
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_WindowMinSize, ImVec2(500, 37)); nVars++;
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f); nVars++;
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f); nVars++;
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_fadeAlpha); nVars++;
|
||||||
|
|
||||||
SuggestPanel();
|
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
|
// Purpose: draws the console's main surface
|
||||||
// Input : *bDraw -
|
// 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();
|
ImGui::End();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImGuiStyle& style = ImGui::GetStyle();
|
const ImGuiStyle& style = ImGui::GetStyle();
|
||||||
@ -283,7 +249,7 @@ void CConsole::DrawSurface(void)
|
|||||||
ImGuiWindow* pWindow = ImGui::GetCurrentWindow();
|
ImGuiWindow* pWindow = ImGui::GetCurrentWindow();
|
||||||
ImGuiID nID = pWindow->GetID(m_pszLoggingLabel);
|
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);
|
ImGui::SetWindowScrollY(m_szWindowLabel, m_flScrollY - m_nScrollBack * fontSize.y);
|
||||||
}
|
}
|
||||||
m_nScrollBack = 0;
|
m_nScrollBack = 0;
|
||||||
@ -321,7 +287,7 @@ void CConsole::DrawSurface(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BuildSummary();
|
BuildSummary();
|
||||||
m_bReclaimFocus = true;
|
m_reclaimFocus = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
@ -336,7 +302,7 @@ void CConsole::DrawSurface(void)
|
|||||||
BuildSummary(m_svInputConVar);
|
BuildSummary(m_svInputConVar);
|
||||||
|
|
||||||
m_bModifyInput = true;
|
m_bModifyInput = true;
|
||||||
m_bReclaimFocus = true;
|
m_reclaimFocus = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -348,10 +314,10 @@ void CConsole::DrawSurface(void)
|
|||||||
ImGui::SetItemDefaultFocus();
|
ImGui::SetItemDefaultFocus();
|
||||||
|
|
||||||
// Auto-focus input field if reclaim is demanded.
|
// Auto-focus input field if reclaim is demanded.
|
||||||
if (m_bReclaimFocus)
|
if (m_reclaimFocus)
|
||||||
{
|
{
|
||||||
ImGui::SetKeyboardFocusHere(-1); // -1 means previous widget.
|
ImGui::SetKeyboardFocusHere(-1); // -1 means previous widget.
|
||||||
m_bReclaimFocus = false;
|
m_reclaimFocus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildSuggestPanelRect();
|
BuildSuggestPanelRect();
|
||||||
@ -361,7 +327,9 @@ void CConsole::DrawSurface(void)
|
|||||||
{
|
{
|
||||||
fnHandleInput();
|
fnHandleInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -472,7 +440,7 @@ void CConsole::SuggestPanel(void)
|
|||||||
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
|
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
|
||||||
|
|
||||||
m_bCanAutoComplete = true;
|
m_bCanAutoComplete = true;
|
||||||
m_bReclaimFocus = true;
|
m_reclaimFocus = true;
|
||||||
|
|
||||||
BuildSummary(svConVar);
|
BuildSummary(svConVar);
|
||||||
}
|
}
|
||||||
@ -962,7 +930,7 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* iData)
|
|||||||
m_svInputConVar.clear();
|
m_svInputConVar.clear();
|
||||||
|
|
||||||
m_bCanAutoComplete = true;
|
m_bCanAutoComplete = true;
|
||||||
m_bReclaimFocus = true;
|
m_reclaimFocus = true;
|
||||||
}
|
}
|
||||||
m_bModifyInput = false;
|
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
|
// Purpose: toggles the console
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void CConsole::ToggleConsole_f()
|
void CConsole::ToggleConsole_f()
|
||||||
{
|
{
|
||||||
g_Console.m_bActivate ^= true;
|
g_Console.m_activated ^= true;
|
||||||
ResetInput(); // Disable input to game when console is drawn.
|
ResetInput(); // Disable input to game when console is drawn.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,31 +2,22 @@
|
|||||||
#ifndef DEDICATED
|
#ifndef DEDICATED
|
||||||
#include "common/sdkdefs.h"
|
#include "common/sdkdefs.h"
|
||||||
#include "windows/resource.h"
|
#include "windows/resource.h"
|
||||||
#include "public/isurfacesystem.h"
|
#include "imgui/misc/imgui_logger.h"
|
||||||
#include "thirdparty/imgui/misc/imgui_logger.h"
|
#include "imgui/misc/imgui_utility.h"
|
||||||
#include "thirdparty/imgui/misc/imgui_utility.h"
|
|
||||||
|
|
||||||
class CConsole : public IDebugSurface
|
#include "imgui_surface.h"
|
||||||
|
|
||||||
|
class CConsole : public CImguiSurface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum PositionMode_t
|
|
||||||
{
|
|
||||||
// Park means the position is out of screen.
|
|
||||||
kPark = -1,
|
|
||||||
kFirst,
|
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
CConsole(void);
|
CConsole(void);
|
||||||
virtual ~CConsole(void);
|
virtual ~CConsole(void);
|
||||||
|
|
||||||
virtual bool Init(void);
|
virtual bool Init(void);
|
||||||
virtual void Think(void);
|
|
||||||
|
|
||||||
virtual void RunFrame(void);
|
virtual void RunFrame(void);
|
||||||
virtual void RunTask(void);
|
virtual bool DrawSurface(void);
|
||||||
|
|
||||||
virtual void DrawSurface(void);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OptionsPanel(void);
|
void OptionsPanel(void);
|
||||||
@ -39,6 +30,8 @@ private:
|
|||||||
void ProcessCommand(string svCommand);
|
void ProcessCommand(string svCommand);
|
||||||
|
|
||||||
void BuildSummary(string svConVar = "");
|
void BuildSummary(string svConVar = "");
|
||||||
|
|
||||||
|
struct CSuggest;
|
||||||
void BuildInputFromSelected(const CSuggest& suggest, string& svInput);
|
void BuildInputFromSelected(const CSuggest& suggest, string& svInput);
|
||||||
void BuildSuggestPanelRect(void);
|
void BuildSuggestPanelRect(void);
|
||||||
|
|
||||||
@ -58,8 +51,6 @@ public:
|
|||||||
const vector<string>& GetHistory(void) const;
|
const vector<string>& GetHistory(void) const;
|
||||||
void ClearHistory(void);
|
void ClearHistory(void);
|
||||||
|
|
||||||
inline bool IsVisible() { return m_flFadeAlpha > 0.0f; }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Console command callbacks
|
// Console command callbacks
|
||||||
static void ToggleConsole_f();
|
static void ToggleConsole_f();
|
||||||
@ -74,12 +65,36 @@ private: // Internals.
|
|||||||
void ClampLogSize(void);
|
void ClampLogSize(void);
|
||||||
void ClampHistorySize(void);
|
void ClampHistorySize(void);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
private:
|
||||||
virtual void SetStyleVar(void);
|
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:
|
private:
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
const char* m_pszConsoleLabel;
|
|
||||||
const char* m_pszLoggingLabel;
|
const char* m_pszLoggingLabel;
|
||||||
char m_szInputBuf[512];
|
char m_szInputBuf[512];
|
||||||
char m_szSummary[256];
|
char m_szSummary[256];
|
||||||
@ -93,10 +108,7 @@ private:
|
|||||||
int m_nInputTextLen;
|
int m_nInputTextLen;
|
||||||
float m_flScrollX;
|
float m_flScrollX;
|
||||||
float m_flScrollY;
|
float m_flScrollY;
|
||||||
float m_flFadeAlpha;
|
|
||||||
|
|
||||||
bool m_bInitialized;
|
|
||||||
bool m_bReclaimFocus;
|
|
||||||
bool m_bCopyToClipBoard;
|
bool m_bCopyToClipBoard;
|
||||||
bool m_bModifyInput;
|
bool m_bModifyInput;
|
||||||
|
|
||||||
@ -109,7 +121,6 @@ private:
|
|||||||
vector<MODULERESOURCE> m_vFlagIcons;
|
vector<MODULERESOURCE> m_vFlagIcons;
|
||||||
vector<string> m_vHistory;
|
vector<string> m_vHistory;
|
||||||
|
|
||||||
ImGuiStyle_t m_Style;
|
|
||||||
ImVec2 m_ivSuggestWindowPos;
|
ImVec2 m_ivSuggestWindowPos;
|
||||||
ImVec2 m_ivSuggestWindowSize;
|
ImVec2 m_ivSuggestWindowSize;
|
||||||
|
|
||||||
@ -119,9 +130,6 @@ private:
|
|||||||
ImGuiInputTextFlags m_nInputFlags;
|
ImGuiInputTextFlags m_nInputFlags;
|
||||||
ImGuiWindowFlags m_nSuggestFlags;
|
ImGuiWindowFlags m_nSuggestFlags;
|
||||||
ImGuiWindowFlags m_nLoggingFlags;
|
ImGuiWindowFlags m_nLoggingFlags;
|
||||||
|
|
||||||
public:
|
|
||||||
bool m_bActivate = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
43
src/gameui/imgui_surface.cpp
Normal file
43
src/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
src/gameui/imgui_surface.h
Normal file
38
src/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();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
g_Browser.RunTask();
|
|
||||||
g_Browser.RunFrame();
|
g_Browser.RunFrame();
|
||||||
|
|
||||||
g_Console.RunTask();
|
|
||||||
g_Console.RunFrame();
|
g_Console.RunFrame();
|
||||||
|
|
||||||
ImGui::EndFrame();
|
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()
|
void ResetInput()
|
||||||
{
|
{
|
||||||
g_pInputSystem->EnableInput( // Enables the input system when both are not drawn.
|
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()
|
bool PanelsVisible()
|
||||||
{
|
{
|
||||||
if (g_Browser.m_bActivate || g_Console.m_bActivate)
|
if (g_Browser.IsActivated() || g_Console.IsActivated())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user