mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
ImGui panel improvements
Slight optimizations and cleanup. Added fade-in effect.
This commit is contained in:
parent
dab5133e07
commit
aaf6e46871
@ -14,7 +14,6 @@
|
||||
#include "engine/client/cl_rcon.h"
|
||||
#include "public/include/bansystem.h"
|
||||
#include "vpc/keyvalues.h"
|
||||
#include "gameui/IConsole.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -38,7 +37,6 @@ void CHLClient::FrameStageNotify(CHLClient* pHLClient, ClientFrameStage_t frameS
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_pConsole->Think();
|
||||
CHLClient_FrameStageNotify(pHLClient, frameStage);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,12 @@ CBrowser::CBrowser(void)
|
||||
});
|
||||
|
||||
hostingServerRequestThread.detach();
|
||||
|
||||
std::thread think(&CBrowser::Think, this);
|
||||
think.detach();
|
||||
#endif // !CLIENT_DLL
|
||||
|
||||
m_pszBrowserTitle = "Server Browser";
|
||||
m_rLockedIconBlob = GetModuleResource(IDB_PNG2);
|
||||
}
|
||||
|
||||
@ -68,7 +73,7 @@ CBrowser::~CBrowser(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draws the main browser front-end
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBrowser::Draw(const char* pszTitle, bool* bDraw)
|
||||
void CBrowser::Draw(void)
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
@ -83,22 +88,20 @@ void CBrowser::Draw(const char* pszTitle, bool* bDraw)
|
||||
//ImGui::ShowDemoWindow();
|
||||
}
|
||||
|
||||
if (!ImGui::Begin(pszTitle, bDraw))
|
||||
int nVars = 0;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
if (!ImGui::Begin(m_pszBrowserTitle, &m_bActivate))
|
||||
{
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(nVars);
|
||||
return;
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (*bDraw == NULL)
|
||||
{
|
||||
m_bActivate = false;
|
||||
}
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(840, 600), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(-500, 50), ImGuiCond_FirstUseEver);
|
||||
|
||||
ImGui::Begin(pszTitle, NULL, ImGuiWindowFlags_NoScrollbar);
|
||||
ImGui::Begin(m_pszBrowserTitle, NULL, ImGuiWindowFlags_NoScrollbar);
|
||||
{
|
||||
CompMenu();
|
||||
|
||||
@ -118,6 +121,29 @@ void CBrowser::Draw(const char* pszTitle, bool* bDraw)
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(nVars);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: runs tasks for the browser while not being drawn
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBrowser::Think(void)
|
||||
{
|
||||
for (;;) // Loop running at 100-tps.
|
||||
{
|
||||
if (m_bActivate)
|
||||
{
|
||||
if (m_flFadeAlpha <= 1.f)
|
||||
{
|
||||
m_flFadeAlpha += 0.05;
|
||||
}
|
||||
}
|
||||
else // Reset to full transparent.
|
||||
{
|
||||
m_flFadeAlpha = 0.f;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -162,8 +188,15 @@ void CBrowser::ServerBrowserSection(void)
|
||||
const float fFooterHeight = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
|
||||
ImGui::BeginChild("##ServerBrowser_ServerList", { 0, -fFooterHeight }, true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
|
||||
if (m_bDefaultTheme) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); }
|
||||
else { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4.f, 0.f)); }
|
||||
int nVars = 0;
|
||||
if (m_bDefaultTheme)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 8.f, 0.f }); nVars++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4.f, 0.f)); nVars++;
|
||||
}
|
||||
|
||||
if (ImGui::BeginTable("##ServerBrowser_ServerListTable", 5, ImGuiTableFlags_Resizable))
|
||||
{
|
||||
@ -208,8 +241,8 @@ void CBrowser::ServerBrowserSection(void)
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::PopStyleVar(nVars);
|
||||
ImGui::EndTable();
|
||||
ImGui::PopStyleVar(1);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
|
@ -45,7 +45,9 @@ public:
|
||||
CBrowser(void);
|
||||
~CBrowser(void);
|
||||
|
||||
void Draw(const char* pszTitle, bool* bDraw);
|
||||
void Draw(void);
|
||||
void Think(void);
|
||||
|
||||
void CompMenu(void);
|
||||
|
||||
void ServerBrowserSection(void);
|
||||
@ -75,6 +77,8 @@ public:
|
||||
////////////////////
|
||||
public:
|
||||
bool m_bActivate = false;
|
||||
float m_flFadeAlpha = 0.f;
|
||||
const char* m_pszBrowserTitle = nullptr;
|
||||
|
||||
vector<ServerListing> m_vServerList;
|
||||
ImGuiTextFilter m_imServerBrowserFilter;
|
||||
|
@ -35,12 +35,16 @@ CConsole::CConsole(void)
|
||||
m_bAutoScroll = true;
|
||||
m_bScrollToBottom = false;
|
||||
m_bInitialized = false;
|
||||
m_pszConsoleTitle = "Console";
|
||||
|
||||
m_vsvCommands.push_back("CLEAR");
|
||||
m_vsvCommands.push_back("HELP");
|
||||
m_vsvCommands.push_back("HISTORY");
|
||||
|
||||
snprintf(m_szSummary, 256, "%llu history items", m_vsvHistory.size());
|
||||
|
||||
std::thread think(&CConsole::Think, this);
|
||||
think.detach();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -80,15 +84,12 @@ bool CConsole::Setup(void)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: game console main render loop
|
||||
// Input : *pszTitle -
|
||||
// *bDraw -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::Draw(const char* pszTitle, bool* bDraw)
|
||||
void CConsole::Draw(void)
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
Setup();
|
||||
m_pszConsoleTitle = pszTitle;
|
||||
m_bInitialized = true;
|
||||
}
|
||||
|
||||
@ -101,28 +102,27 @@ void CConsole::Draw(const char* pszTitle, bool* bDraw)
|
||||
* BASE PANEL SETUP *
|
||||
**************************/
|
||||
{
|
||||
static int nVars{};
|
||||
if (!*bDraw)
|
||||
int nVars{};
|
||||
if (!m_bActivate)
|
||||
{
|
||||
m_bActivate = false;
|
||||
return;
|
||||
}
|
||||
if (m_bDefaultTheme)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 8.f, 10.f });
|
||||
nVars = 1;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 8.f, 10.f }); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f });
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f);
|
||||
nVars = 2;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 4.f, 6.f }); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f); nVars++;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, m_flFadeAlpha); nVars++;
|
||||
}
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver);
|
||||
|
||||
BasePanel(bDraw);
|
||||
BasePanel();
|
||||
|
||||
ImGui::PopStyleVar(nVars);
|
||||
}
|
||||
@ -158,28 +158,45 @@ void CConsole::Draw(const char* pszTitle, bool* bDraw)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::Think(void)
|
||||
{
|
||||
if (m_ivConLog.size() > con_max_size_logvector->GetInt())
|
||||
{
|
||||
while (m_ivConLog.size() > con_max_size_logvector->GetInt() / 4 * 3)
|
||||
{
|
||||
m_ivConLog.erase(m_ivConLog.begin());
|
||||
m_nScrollBack++;
|
||||
}
|
||||
}
|
||||
for (;;) // Loop running at 100-tps.
|
||||
{
|
||||
if (m_ivConLog.size() > con_max_size_logvector->GetSizeT())
|
||||
{
|
||||
while (m_ivConLog.size() > con_max_size_logvector->GetSizeT() / 4 * 3)
|
||||
{
|
||||
m_ivConLog.erase(m_ivConLog.begin());
|
||||
m_nScrollBack++;
|
||||
}
|
||||
}
|
||||
|
||||
while (static_cast<int>(m_vsvHistory.size()) > 512)
|
||||
{
|
||||
m_vsvHistory.erase(m_vsvHistory.begin());
|
||||
}
|
||||
while (static_cast<int>(m_vsvHistory.size()) > 512)
|
||||
{
|
||||
m_vsvHistory.erase(m_vsvHistory.begin());
|
||||
}
|
||||
|
||||
if (m_bActivate)
|
||||
{
|
||||
if (m_flFadeAlpha <= 1.f)
|
||||
{
|
||||
m_flFadeAlpha += 0.05;
|
||||
}
|
||||
}
|
||||
else // Reset to full transparent.
|
||||
{
|
||||
m_flFadeAlpha = 0.f;
|
||||
m_bReclaimFocus = true;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draws the console's main surface
|
||||
// Input : *bDraw -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CConsole::BasePanel(bool* bDraw)
|
||||
void CConsole::BasePanel(void)
|
||||
{
|
||||
if (!ImGui::Begin(m_pszConsoleTitle, bDraw))
|
||||
if (!ImGui::Begin(m_pszConsoleTitle, &m_bActivate))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
@ -238,8 +255,6 @@ void CConsole::BasePanel(bool* bDraw)
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::PushItemWidth(footer_width_to_reserve - 80);
|
||||
if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); }
|
||||
|
||||
if (ImGui::InputText("##input", m_szInputBuf, IM_ARRAYSIZE(m_szInputBuf), m_nInputFlags, &TextEditCallbackStub, reinterpret_cast<void*>(this)))
|
||||
{
|
||||
if (m_nSuggestPos != -1)
|
||||
|
@ -45,6 +45,7 @@ private:
|
||||
vector<string> m_vsvHistory;
|
||||
int m_nHistoryPos = -1;
|
||||
int m_nScrollBack = 0;
|
||||
float m_flFadeAlpha = 0.f;
|
||||
ImGuiTextFilter m_itFilter;
|
||||
bool m_bInitialized = false;
|
||||
bool m_bDefaultTheme = false;
|
||||
@ -89,10 +90,10 @@ public:
|
||||
~CConsole(void);
|
||||
|
||||
bool Setup(void);
|
||||
void Draw(const char* pszTitle, bool* bDraw);
|
||||
void Draw(void);
|
||||
void Think(void);
|
||||
|
||||
void BasePanel(bool* bDraw);
|
||||
void BasePanel(void);
|
||||
void OptionsPanel(void);
|
||||
void SuggestPanel(void);
|
||||
|
||||
|
@ -330,6 +330,24 @@ int ConVar::GetInt(void) const
|
||||
return m_pParent->m_Value.m_nValue;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as an integer (64-bit).
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
int64_t ConVar::GetInt64(void) const
|
||||
{
|
||||
return static_cast<int64_t>(m_pParent->m_Value.m_nValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a size type.
|
||||
// Output : int
|
||||
//-----------------------------------------------------------------------------
|
||||
size_t ConVar::GetSizeT(void) const
|
||||
{
|
||||
return static_cast<size_t>(m_pParent->m_Value.m_nValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Return ConVar value as a color.
|
||||
// Output : Color
|
||||
|
@ -107,6 +107,8 @@ public:
|
||||
float GetFloat(void) const;
|
||||
double GetDouble(void) const;
|
||||
int GetInt(void) const;
|
||||
int64_t GetInt64(void) const;
|
||||
size_t GetSizeT(void) const;
|
||||
Color GetColor(void) const;
|
||||
const char* GetString(void) const;
|
||||
|
||||
|
@ -276,12 +276,12 @@ void DrawImGui()
|
||||
if (g_pBrowser->m_bActivate)
|
||||
{
|
||||
g_pInputSystem->EnableInput(false); // Disable input to game when browser is drawn.
|
||||
g_pBrowser->Draw("Server Browser", &g_pBrowser->m_bActivate);
|
||||
g_pBrowser->Draw();
|
||||
}
|
||||
if (g_pConsole->m_bActivate)
|
||||
{
|
||||
g_pInputSystem->EnableInput(false); // Disable input to game when console is drawn.
|
||||
g_pConsole->Draw("Console", &g_pConsole->m_bActivate);
|
||||
g_pConsole->Draw();
|
||||
}
|
||||
if (!g_pConsole->m_bActivate && !g_pBrowser->m_bActivate)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user