2022-09-25 13:36:55 +02:00
|
|
|
|
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
|
|
|
|
//
|
|
|
|
|
// Purpose:
|
|
|
|
|
//
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
#include "core/stdafx.h"
|
|
|
|
|
#include "tier0/commandline.h"
|
2023-01-30 20:18:11 +01:00
|
|
|
|
#include "windows/id3dx.h"
|
|
|
|
|
#include "windows/input.h"
|
2022-09-25 13:36:55 +02:00
|
|
|
|
#include "engine/sys_mainwind.h"
|
2023-07-02 11:28:07 +02:00
|
|
|
|
#include "engine/sys_engine.h"
|
2023-12-24 16:29:42 +01:00
|
|
|
|
#include "engine/keys.h"
|
2023-01-30 20:18:11 +01:00
|
|
|
|
#include "gameui/IConsole.h"
|
|
|
|
|
#include "gameui/IBrowser.h"
|
2024-04-05 18:17:12 +02:00
|
|
|
|
#include "gameui/imgui_system.h"
|
2022-09-25 13:36:55 +02:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: plays the startup video's
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
void CGame::PlayStartupVideos(void)
|
|
|
|
|
{
|
|
|
|
|
if (!CommandLine()->CheckParm("-novid"))
|
|
|
|
|
{
|
2024-01-02 15:21:36 +01:00
|
|
|
|
CGame__PlayStartupVideos();
|
2022-09-25 13:36:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-30 20:18:11 +01:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: main windows procedure
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2024-03-03 14:44:25 +01:00
|
|
|
|
LRESULT CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2023-01-30 20:18:11 +01:00
|
|
|
|
{
|
2024-02-27 17:43:18 +01:00
|
|
|
|
if (!ImguiSystem()->IsInitialized())
|
2024-01-02 15:21:36 +01:00
|
|
|
|
return CGame__WindowProc(hWnd, uMsg, wParam, lParam);
|
2023-06-19 14:03:23 +02:00
|
|
|
|
|
2024-02-27 17:43:18 +01:00
|
|
|
|
ImguiSystem()->MessageHandler(hWnd, uMsg, wParam, lParam);
|
2023-01-30 20:18:11 +01:00
|
|
|
|
|
|
|
|
|
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN)
|
|
|
|
|
{
|
2024-02-29 22:31:43 +01:00
|
|
|
|
if (wParam == g_ImGuiConfig.m_ConsoleConfig.m_nBind0 ||
|
|
|
|
|
wParam == g_ImGuiConfig.m_ConsoleConfig.m_nBind1)
|
2023-01-30 20:18:11 +01:00
|
|
|
|
{
|
2024-04-05 18:22:56 +02:00
|
|
|
|
g_Console.ToggleActive();
|
2023-01-30 20:18:11 +01:00
|
|
|
|
ResetInput(); // Disable input to game when console is drawn.
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 22:31:43 +01:00
|
|
|
|
if (wParam == g_ImGuiConfig.m_BrowserConfig.m_nBind0 ||
|
|
|
|
|
wParam == g_ImGuiConfig.m_BrowserConfig.m_nBind1)
|
2023-01-30 20:18:11 +01:00
|
|
|
|
{
|
2024-04-05 18:22:56 +02:00
|
|
|
|
g_Browser.ToggleActive();
|
2023-01-30 20:18:11 +01:00
|
|
|
|
ResetInput(); // Disable input to game when browser is drawn.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 18:22:56 +02:00
|
|
|
|
if (g_Console.IsActivated() || g_Browser.IsActivated())
|
2023-01-30 20:18:11 +01:00
|
|
|
|
{//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
g_bBlockInput = true;
|
|
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
|
{
|
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
|
case WM_RBUTTONDBLCLK:
|
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
|
case WM_MBUTTONDBLCLK:
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
|
case WM_MOUSEACTIVATE:
|
|
|
|
|
case WM_MOUSEHOVER:
|
|
|
|
|
case WM_MOUSEHWHEEL:
|
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
|
case WM_SETCURSOR:
|
|
|
|
|
uMsg = WM_NULL;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_bBlockInput = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-02 15:21:36 +01:00
|
|
|
|
return CGame__WindowProc(hWnd, uMsg, wParam, lParam);
|
2023-01-30 20:18:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 20:38:18 +02:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: gets the window rect
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-12-24 16:29:42 +01:00
|
|
|
|
void CGame::GetWindowRect(int* const x, int* const y, int* const w, int* const h) const
|
2023-09-11 20:38:18 +02:00
|
|
|
|
{
|
|
|
|
|
if (x)
|
|
|
|
|
{
|
|
|
|
|
*x = m_x;
|
|
|
|
|
}
|
|
|
|
|
if (y)
|
|
|
|
|
{
|
|
|
|
|
*y = m_y;
|
|
|
|
|
}
|
|
|
|
|
if (w)
|
|
|
|
|
{
|
|
|
|
|
*w = m_width;
|
|
|
|
|
}
|
|
|
|
|
if (h)
|
|
|
|
|
{
|
|
|
|
|
*h = m_height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-24 16:29:42 +01:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: dispatch key event
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-12-30 17:32:38 +01:00
|
|
|
|
void CGame::DispatchKeyEvent(const uint64_t currentTick, const ButtonCode_t buttonCode) const
|
2023-12-24 16:29:42 +01:00
|
|
|
|
{
|
2023-12-30 17:38:54 +01:00
|
|
|
|
// Controller 'hold' keys are delayed longer.
|
|
|
|
|
// TODO[ AMOS ]: use ConVar's instead?
|
2023-12-30 17:32:38 +01:00
|
|
|
|
const float delay = buttonCode == KEY_XBUTTON_BACK ? 1.0f : 0.2f;
|
2023-12-24 16:29:42 +01:00
|
|
|
|
KeyInfo_t& keyInfo = g_pKeyInfo[buttonCode];
|
|
|
|
|
|
2023-12-30 17:32:38 +01:00
|
|
|
|
if (!keyInfo.m_bKeyDown && ((currentTick - keyInfo.m_nEventTick) * 0.001f) >= delay)
|
2023-12-24 16:29:42 +01:00
|
|
|
|
{
|
|
|
|
|
KeyEvent_t keyEvent;
|
|
|
|
|
|
|
|
|
|
keyEvent.m_pCommand = keyInfo.m_pKeyBinding[KeyInfo_t::KEY_HELD_BIND];
|
|
|
|
|
keyEvent.m_nTick = buttonCode;
|
|
|
|
|
keyEvent.m_bDown = true;
|
|
|
|
|
|
2023-12-24 22:32:58 +01:00
|
|
|
|
v_Key_Event(keyEvent);
|
2023-12-24 16:29:42 +01:00
|
|
|
|
keyInfo.m_bKeyDown = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: dispatch all the queued up messages
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
void CGame::DispatchAllStoredGameMessages() const
|
|
|
|
|
{
|
|
|
|
|
const uint64_t ticks = Plat_MSTime();
|
|
|
|
|
const short eventCount = *g_nKeyEventCount;
|
|
|
|
|
|
|
|
|
|
for (short i = 0; i < eventCount; i++)
|
|
|
|
|
{
|
|
|
|
|
DispatchKeyEvent(ticks, g_pKeyEventTicks[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 13:36:55 +02:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2023-11-26 13:21:20 +01:00
|
|
|
|
void VGame::Detour(const bool bAttach) const
|
2022-09-25 13:36:55 +02:00
|
|
|
|
{
|
2024-01-02 15:21:36 +01:00
|
|
|
|
DetourSetup(&CGame__PlayStartupVideos, &CGame::PlayStartupVideos, bAttach);
|
|
|
|
|
DetourSetup(&CGame__WindowProc, &CGame::WindowProc, bAttach);
|
2022-09-25 13:36:55 +02:00
|
|
|
|
}
|