added main menus, improved shading

This commit is contained in:
2025-07-18 20:37:52 +03:00
parent dddf1b5881
commit 070c3ff309
45 changed files with 859 additions and 271 deletions

View File

@@ -1,5 +1,6 @@
#include "input.h"
#include "console.h"
#include "mainmenu.h"
#include "tier0/lib.h"
#include "tier1/commandline.h"
#include "math3d.h"
@@ -109,53 +110,124 @@ EInputKey IInput_StringToKey( char *psz )
//-----------------------------------------------------------------------------
void IInput::Init( void )
{
}
CUtlVector<EInputMode> g_inputModeStack = {INPUT_MODE_GAME, INPUT_MODE_MENU};
//-----------------------------------------------------------------------------
// Key event may have different different effects based on current input mode.
//
// GAME:
// Generates command call when pressed the key. eg +forward; -left;
// Just to be sure we put ; in the end of the command.
// When user releases the key command event is not generated. But if the first
// command contains + as first character ( in case of example +forward ), then
// it fires -forward
//
// MENU:
// Sends all event to FGUI. KEY_ESCAPE key makes leave the menu and get back to
// the game.
//
// CONSOLE:
// Works as permanent input field.
//
// INPUT FIELD:
// Doesn't recieve any events except for KEY_ESCAPE and KEY_ENTER
//-----------------------------------------------------------------------------
void IInput::KeyEvent( EInputKey key, EKeyEventType event )
{
if (event == KEY_EVENT_TYPE_DOWN) {
IConsole::AddCommand(g_bindings[key]);
IConsole::AddCommand(";");
}
if (event == KEY_EVENT_TYPE_UP)
if (event == KEY_EVENT_TYPE_DOWN && key == KEY_ESCAPE)
{
auto binding = IConsole::ParseCommandLine(g_bindings[key]);
if (binding.GetSize()==0)
return;
if (binding[0].GetSize() == 0)
return;
if (binding[0][0].GetString()[0] == '+')
if (g_inputModeStack.GetSize() == 1)
{
CUtlString command = binding[0][0];
command.GetString()[0] = '-';
IConsole::AddCommand(command);
g_inputModeStack.AppendTail(INPUT_MODE_MENU);
IInput::SetInputMode(INPUT_MODE_MENU);
MainMenu()->SetVisibility(true);
return;
}
if (IConsoleUI::IsVisibile())
IConsoleUI::SetVisibility(false);
IInput::SetInputMode(g_inputModeStack[g_inputModeStack.GetSize()-2]);
g_inputModeStack.RemoveTail();
if (g_inputModeStack[g_inputModeStack.GetSize()-1] != INPUT_MODE_MENU)
{
V_printf("no menu\n");
MainMenu()->SetVisibility(false);
}
return;
};
if (event == KEY_EVENT_TYPE_DOWN && key == KEY_TILDE)
{
if (IConsoleUI::IsVisibile())
{
IInput::SetInputMode(g_inputModeStack[g_inputModeStack.GetSize()-2]);
g_inputModeStack.RemoveTail();
IConsoleUI::SetVisibility(false);
} else
{
g_inputModeStack.AppendTail(INPUT_MODE_CONSOLE);
IInput::SetInputMode(INPUT_MODE_CONSOLE);
IConsoleUI::SetVisibility(true);
}
return;
};
if (event == KEY_EVENT_TYPE_DOWN && key == KEY_F11)
{
IConsole::AddCommand("exit;");
return;
}
if (g_inputModeStack[g_inputModeStack.GetSize()-1] == INPUT_MODE_GAME)
{
if (event == KEY_EVENT_TYPE_DOWN) {
IConsole::AddCommand(g_bindings[key]);
IConsole::AddCommand(";");
}
if (event == KEY_EVENT_TYPE_UP)
{
auto binding = IConsole::ParseCommandLine(g_bindings[key]);
if (binding.GetSize()==0)
return;
if (binding[0].GetSize() == 0)
return;
if (binding[0][0].GetString()[0] == '+')
{
CUtlString command = binding[0][0];
command.GetString()[0] = '-';
IConsole::AddCommand(command);
IConsole::AddCommand(";");
}
}
}
if (g_inputModeStack[g_inputModeStack.GetSize()-1] == INPUT_MODE_MENU)
{
};
}
//-----------------------------------------------------------------------------
//
// Axis events for the input devices such as mouse and controller.
// Game needs to explicitly support all of the devices.
//-----------------------------------------------------------------------------
void IInput::AxisEvent( EInputAxis axis, float fValue )
{
if (axis == AXIS_MOUSE_X || axis == AXIS_MOUSE_Y)
if (g_inputModeStack[g_inputModeStack.GetSize()-1] == INPUT_MODE_GAME)
{
g_bController = false;
g_fAxisValues[axis] += fValue*3.09;
}
if (axis == AXIS_CONTROLLER_PITCH || axis == AXIS_CONTROLLER_YAW)
{
g_bController = true;
g_fAxisModifiers[axis] = fValue*3.09;
if (axis == AXIS_MOUSE_X || axis == AXIS_MOUSE_Y)
{
g_bController = false;
g_fAxisValues[axis] += fValue*3.09;
}
if (axis == AXIS_CONTROLLER_PITCH || axis == AXIS_CONTROLLER_YAW)
{
g_bController = true;
g_fAxisModifiers[axis] = fValue*3.09;
}
}
}
@@ -173,7 +245,6 @@ void IInput::Frame( void )
//-----------------------------------------------------------------------------
void IInput::Deinit( void )
{
}
//-----------------------------------------------------------------------------