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

@@ -6,6 +6,7 @@
CUtlVector<CUtlString> client_CompiledFiles = {
"game/client/milmoba/player.cpp",
"game/client/milmoba/mainmenu.cpp",
};
int client_build()

View File

@@ -0,0 +1,90 @@
#include "mainmenu.h"
#include "fgui/label.h"
#include "fgui/rect.h"
#include "fgui/widget.h"
#include "interface.h"
class CMOBAMainMenuGUI: public CFGUI_Widget
{
public:
CMOBAMainMenuGUI();
virtual void Event( FGUI_Event_t event ) override;
virtual void Draw() override;
virtual void Frame() override;
private:
CFGUI_Rect *m_pBackground;
CFGUI_Label *m_pGameName;
};
CMOBAMainMenuGUI::CMOBAMainMenuGUI()
{
SetPosition(0, 0);
m_pBackground = new CFGUI_Rect;
m_pBackground->SetParent(this);
m_pBackground->SetPosition(90,90);
m_pBackground->SetSize(300, 400);
m_pBackground->SetBoxColor(0.1, 0.1, 0.1, 1);
m_pGameName = new CFGUI_Label;
m_pGameName->SetParent(this);
m_pGameName->SetFont("fonts/IBMPlexMono-Regular");
m_pGameName->SetLabel("funnygame");
m_pGameName->SetGlyphSize(24);
m_pGameName->SetPosition(100, 100);
};
void CMOBAMainMenuGUI::Event( FGUI_Event_t event )
{
}
void CMOBAMainMenuGUI::Draw()
{
}
void CMOBAMainMenuGUI::Frame()
{
}
class CMOBAMainMenu: public IMainMenu
{
public:
virtual void Init() override;
virtual void Frame() override;
virtual void Deinit() override;
virtual void SetVisibility( bool bIsVisible ) override;
private:
CMOBAMainMenuGUI *m_pMainMenu;
};
void CMOBAMainMenu::Init()
{
m_pMainMenu = new CMOBAMainMenuGUI;
m_pMainMenu->SetVisibility(true);
}
void CMOBAMainMenu::Frame()
{
}
void CMOBAMainMenu::SetVisibility( bool bIsVisible )
{
m_pMainMenu->SetVisibility(bIsVisible);
}
void CMOBAMainMenu::Deinit()
{
}
DECLARE_INTERFACE(MainMenu, CMOBAMainMenu);

View File

@@ -16,6 +16,6 @@ DECLARE_GAME_MODE(CTestGameMode, test_gamemode)
DLL_EXPORT void IGame_Load()
{
ILevel::LoadLevel("maps/test_map");
IGameModeManager::StartGameMode("test_gamemode");
GameModeManager()->StartGameMode("test_gamemode");
return;
};

View File

@@ -24,7 +24,8 @@ public:
virtual void Destroy( void ) override;
virtual void ReadParameter( const char *szName, const char *szValue ) override;
virtual void Think( float fDelta ) override;
virtual void Sync( void *pData, uint32_t nDataSize ) override;
virtual void SendToServer() override;
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) override;
void Accelerate( void );
void AirAccelerate( void );
@@ -156,6 +157,16 @@ void CMOBAPlayer::PlayerMove( void )
CategorizePosition();
}
struct PlayerMovement_t: public PacketPlayer_t
{
bool bIsForward;
bool bIsBack;
bool bIsLeft;
bool bIsRight;
float fPitch;
float fYaw;
};
void CMOBAPlayer::Think( float fDelta )
{
if (INetworking::IsClient())
@@ -173,50 +184,39 @@ void CMOBAPlayer::Think( float fDelta )
PlayerMove();
};
void CMOBAPlayer::Sync( void *pData, uint32_t nDataSize )
void CMOBAPlayer::SendToServer()
{
struct PlayerMovement_t: public PacketPlayer_t
{
bool bIsForward;
bool bIsBack;
bool bIsLeft;
bool bIsRight;
float fPitch;
float fYaw;
PlayerMovement_t movement = {
.bIsForward = bIsForward,
.bIsBack = bIsBack,
.bIsLeft = bIsLeft,
.bIsRight = bIsRight,
.fPitch = fPitch,
.fYaw = fYaw,
};
// Send data
if ( pData == NULL )
movement.type = PACKET_TYPE_PLAYER_MOVEMENT;
if (INetworking::IsClient())
{
PlayerMovement_t movement = {
.bIsForward = bIsForward,
.bIsBack = bIsBack,
.bIsLeft = bIsLeft,
.bIsRight = bIsRight,
.fPitch = fPitch,
.fYaw = fYaw,
};
movement.type = PACKET_TYPE_PLAYER_MOVEMENT;
if (INetworking::IsClient())
if (g_localClient->pBasePlayer != this)
return;
INetworking::SendData(&movement, sizeof(PlayerMovement_t), 0, MESSAGE_MODE_RELIABLE);
} else {
for (auto &client: g_clients)
{
if (g_localClient->pBasePlayer != this)
return;
INetworking::SendData(&movement, sizeof(PlayerMovement_t), 0, MESSAGE_MODE_RELIABLE);
} else {
for (auto &client: g_clients)
if (client->pBasePlayer == this)
{
if (client->pBasePlayer == this)
{
movement.playerHandle = client->playerHandle;
break;
}
movement.playerHandle = client->playerHandle;
break;
}
INetworking::SendDataEverybodyExcept(&movement, sizeof(PlayerMovement_t), this, MESSAGE_MODE_RELIABLE);
}
return;
INetworking::SendDataEverybodyExcept(&movement, sizeof(PlayerMovement_t), this, MESSAGE_MODE_RELIABLE);
}
return;
}
void CMOBAPlayer::RecieveFromServer( void *pData, uint32_t nDataSize )
{
Packet_t *pPacket = (Packet_t*)pData;
if (pPacket->type == PACKET_TYPE_PLAYER_MOVEMENT)
{