Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): VGUI #73

Merged
merged 12 commits into from
Jan 16, 2025
2 changes: 2 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ for sdk_target in MMSPlugin.sdk_targets:
"-Wno-array-bounds",
"-Wno-int-to-pointer-cast",
"-Wno-sign-compare",
"-Wno-write-strings",
"-fexceptions",
]
binary.compiler.cflags += [
Expand All @@ -58,6 +59,7 @@ for sdk_target in MMSPlugin.sdk_targets:
"-Wno-array-bounds",
"-Wno-int-to-pointer-cast",
"-Wno-sign-compare",
"-Wno-write-strings",
"-fexceptions",
]
binary.compiler.postlink += [
Expand Down
16 changes: 8 additions & 8 deletions plugin_files/translations/translation.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
"de": "Beenden"
},
"menu.footer": {
"en": "{CYCLE_BUTTON} - Cycle | {USE_BUTTON} - Select | Page {PAGE}/{MAXPAGES}",
"ro": "{CYCLE_BUTTON} - Schimbă | {USE_BUTTON} - Selectează | Pagina {PAGE}/{MAXPAGES}",
"pl": "{CYCLE_BUTTON} - Przeglądaj | {USE_BUTTON} - Wybierz | Strona {PAGE}/{MAXPAGES}",
"de": "{CYCLE_BUTTON} - Durchblättern | {USE_BUTTON} - Auswählen | Seite {PAGE}/{MAXPAGES}"
"en": "{CYCLE_BUTTON} - Cycle | {USE_BUTTON} - Select\nPage {PAGE}/{MAXPAGES}",
"ro": "{CYCLE_BUTTON} - Schimbă | {USE_BUTTON} - Selectează\nPagina {PAGE}/{MAXPAGES}",
"pl": "{CYCLE_BUTTON} - Przeglądaj | {USE_BUTTON} - Wybierz\nStrona {PAGE}/{MAXPAGES}",
"de": "{CYCLE_BUTTON} - Durchblättern | {USE_BUTTON} - Auswählen\nSeite {PAGE}/{MAXPAGES}"
},
"menu.footer.nooption": {
"en": "{CYCLE_BUTTON} - Cycle | {USE_BUTTON} - Select | {EXIT_BUTTON} - Exit | Page {PAGE}/{MAXPAGES}",
"ro": "{CYCLE_BUTTON} - Schimbă | {USE_BUTTON} - Selectează | {EXIT_BUTTON} - Ieșire | Pagina {PAGE}/{MAXPAGES}",
"pl": "{CYCLE_BUTTON} - Przeglądaj | {USE_BUTTON} - Wybierz | {EXIT_BUTTON} - Wyjście | Strona {PAGE}/{MAXPAGES}",
"de": "{CYCLE_BUTTON} - Durchblättern | {USE_BUTTON} - Auswählen | {EXIT_BUTTON} - Beenden | Seite {PAGE}/{MAXPAGES}"
"en": "{CYCLE_BUTTON} - Cycle | {USE_BUTTON} - Select\n{EXIT_BUTTON} - Exit | Page {PAGE}/{MAXPAGES}",
"ro": "{CYCLE_BUTTON} - Schimbă | {USE_BUTTON} - Selectează\n{EXIT_BUTTON} - Ieșire | Pagina {PAGE}/{MAXPAGES}",
"pl": "{CYCLE_BUTTON} - Przeglądaj | {USE_BUTTON} - Wybierz\n{EXIT_BUTTON} - Wyjście | Strona {PAGE}/{MAXPAGES}",
"de": "{CYCLE_BUTTON} - Durchblättern | {USE_BUTTON} - Auswählen\n{EXIT_BUTTON} - Beenden | Seite {PAGE}/{MAXPAGES}"
}
}
2 changes: 1 addition & 1 deletion src/core/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ void SwiftlyCommand(const CCommandContext& context, const CCommand& args)
SwiftlyResourceMonitorManager(slot, context, args[2], args[3]);
else if (subcmd == "status")
SwiftlyStatus(slot, context);
else if(subcmd == "chat")
else if (subcmd == "chat")
SwiftlyChatManager(slot, context, args[2]);
else
ShowSwiftlyCommandHelp(slot, context);
Expand Down
19 changes: 18 additions & 1 deletion src/engine/gameevents/gameevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../plugins/PluginManager.h"
#include "../../player/playermanager/PlayerManager.h"
#include "../../vendor/dynlib/module.h"
#include "../vgui/VGUI.h"

#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
Expand Down Expand Up @@ -57,6 +58,10 @@ void EventManager::RegisterGameEvents()
if (!g_gameEventManager->FindListener(this, ev.c_str()))
g_gameEventManager->AddListener(this, ev.c_str(), true);
}

if (!g_gameEventManager->FindListener(this, "player_spawn"))
g_gameEventManager->AddListener(this, "player_spawn", true);

PLUGIN_PRINT("Game Events", "Game events have been succesfully loaded.\n");
loadedGameEvents = true;
}
Expand Down Expand Up @@ -125,8 +130,10 @@ bool EventManager::OnFireEvent(IGameEvent* pEvent, bool bDontBroadcast)
{
auto slot = pEvent->GetPlayerSlot("userid");
Player* player = g_playerManager->GetPlayer(slot);
if (player)
if (player) {
player->SetFirstSpawn(false);
player->EnsureCustomView(1);
}
}
if (result != EventResult::Continue)
{
Expand All @@ -140,6 +147,8 @@ bool EventManager::OnFireEvent(IGameEvent* pEvent, bool bDontBroadcast)
RETURN_META_VALUE(MRES_IGNORED, true);
}

void RegisterTimeout(int64_t delay, std::function<void()> cb);

bool EventManager::OnPostFireEvent(IGameEvent* pEvent, bool bDontBroadcast)
{
if (!pEvent)
Expand All @@ -152,6 +161,14 @@ bool EventManager::OnPostFireEvent(IGameEvent* pEvent, bool bDontBroadcast)
std::string eventName = realGameEvent->GetName();

std::string prettyEventName = gameEventsRegister[eventName];

if(prettyEventName == "OnRoundStart") {
RegisterTimeout(100, []() -> void {
g_pVGUI->RegenerateScreenPanels();
g_pVGUI->RegenerateScreenTexts();
});
}

if (!prettyEventName.empty())
{
PluginEvent* event = new PluginEvent("core", realGameEvent, nullptr);
Expand Down
147 changes: 147 additions & 0 deletions src/engine/vgui/ScreenPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#include "ScreenPanel.h"

ScreenPanel::ScreenPanel()
{
}

ScreenPanel::~ScreenPanel()
{
if(pScreenEntity.IsValid()) {
pScreenEntity->Despawn();
}
}

void ScreenPanel::Create(Color color, int size)
{
m_col = color;
m_size = size;

pScreenEntity.Set((CPointWorldText*)(CreateEntityByName("point_worldtext").GetPtr()));
if(!pScreenEntity) return;

CEntityKeyValues* pMenuKV = new CEntityKeyValues();

pMenuKV->SetBool("enabled", false);
pMenuKV->SetFloat("world_units_per_pixel", (0.25 / 300) * size);
pMenuKV->SetInt("justify_horizontal", 0);
pMenuKV->SetInt("justify_vertical", 2);
pMenuKV->SetInt("reorient_mode", 0);
pMenuKV->SetInt("fullbright", 1);
pMenuKV->SetFloat("font_size", size);
pMenuKV->SetColor("color", color);

pScreenEntity->DispatchSpawn(pMenuKV);
}

void ScreenPanel::SetupViewForPlayer(Player* player)
{
m_player = player;

if(!pScreenEntity) return;
if(!player) return;
if(player->IsFakeClient()) return;

CBaseViewModel* pViewModel = player->EnsureCustomView(1);
if(!pViewModel) return;

pScreenEntity->SetParent(pViewModel);
pScreenEntity->m_hOwnerEntity(pViewModel->GetRefEHandle());
}

void ScreenPanel::SetText(std::string text)
{
m_text = text;

if(!pScreenEntity) return;

pScreenEntity->SetText(m_text.c_str());
pScreenEntity->Enable();
}

void ScreenPanel::SetPosition(float posX, float posY)
{
m_posX = posX;
m_posY = posY;

if(!m_player) return;
if(m_player->IsFakeClient()) return;

CCSPlayerPawn* pawn = m_player->GetPlayerPawn();
if(!pawn) return;
if(pawn->m_lifeState() == 2) {
if(m_player->GetPlayerController()->m_bControllingBot()) {
return;
} else {
auto pPawn = m_player->GetPawn();
if(!pPawn) return;

auto observerPawn = pPawn->m_pObserverServices->m_hObserverTarget();
if(!observerPawn) return;

auto observerController = ((CCSPlayerPawn*)(observerPawn.Get()))->m_hOriginalController();
if(!observerController) return;

auto observer = g_playerManager->GetPlayer(observerController->entindex() - 1);
if(!observer) return;
pawn = observer->GetPlayerPawn();
}
}
if(!pawn) return;

QAngle eyeAngles = pawn->m_angEyeAngles();
Vector fwd, right, up;
AngleVectors(eyeAngles, &fwd, &right, &up);

Vector eyePos(0.0, 0.0, 0.0);
eyePos += fwd * 7.12;
eyePos += right * (-9.3 + (posX * 18.66));
eyePos += up * (-4.82 + (posY * 10.47));

QAngle ang(0, eyeAngles.y + 270, 90 - eyeAngles.x);

eyePos += pawn->m_CBodyComponent->m_pSceneNode->m_vecAbsOrigin() + Vector(0, 0, pawn->m_vecViewOffset->m_vecZ());

pScreenEntity->Teleport(&eyePos, &ang, nullptr);
}

bool ScreenPanel::IsValidEntity()
{
return pScreenEntity.IsValid();
}

void ScreenPanel::RegeneratePanel(bool recreate)
{
if(recreate) {
if(pScreenEntity.IsValid()) pScreenEntity->Despawn();

Create(m_col, m_size);
SetupViewForPlayer(m_player);
SetText(m_text);
SetPosition(m_posX, m_posY);
} else {
SetupViewForPlayer(m_player);
SetPosition(m_posX, m_posY);
}
}

Player* ScreenPanel::GetPlayer()
{
return m_player;
}

int ScreenPanel::GetEntityIndex()
{
if(!pScreenEntity) return 0;

return pScreenEntity->GetEntityIndex().Get();
}

bool ScreenPanel::IsRenderingTo(CHandle<CBaseEntity> renderingTo)
{
return renderingTo == pRenderingTo;
}

void ScreenPanel::SetRenderingTo(CBaseEntity* ent)
{
pRenderingTo.Set(ent);
}
42 changes: 42 additions & 0 deletions src/engine/vgui/ScreenPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef _engine_vgui_screenpanel_h
#define _engine_vgui_screenpanel_h

#include <string>
#include "../../plugins/core/scripting.h"
#include "../../player/playermanager/PlayerManager.h"

#include <public/entity2/entitykeyvalues.h>
#include "../../sdk/entity/CPointWorldText.h"
#include "../../sdk/entity/CBaseViewModel.h"

class ScreenPanel
{
private:
CHandle<CPointWorldText> pScreenEntity;
CHandle<CBaseEntity> pRenderingTo;

Color m_col;
int m_size;
Player* m_player;
float m_posX;
float m_posY;
std::string m_text;

public:
ScreenPanel();
~ScreenPanel();

void Create(Color color, int size = 75);
void SetupViewForPlayer(Player* player);
void SetText(std::string text);
void SetPosition(float posX = 0.0, float posY = 0.0);
void SetRenderingTo(CBaseEntity* ent);
void RegeneratePanel(bool recreate = true);

bool IsValidEntity();
Player* GetPlayer();
int GetEntityIndex();
bool IsRenderingTo(CHandle<CBaseEntity> renderingTo);
};

#endif
Loading
Loading