Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugin_files/configs/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"option": false,
"button": "tab"
}
}
},
"kind": "screen",
"available_kinds": ["screen", "center"]
}
}
16 changes: 14 additions & 2 deletions plugin_files/translations/translation.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@
"pl": "Wyjście",
"de": "Beenden"
},
"menu.footer": {
"menu.center.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}"
},
"menu.center.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}"
},
"menu.screen.footer": {
"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": {
"menu.screen.footer.nooption": {
"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}",
Expand Down
4 changes: 3 additions & 1 deletion src/entrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ void Swiftly::Hook_GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
auto buttonStates = pawn->m_pMovementServices()->m_nButtons().m_pButtonStates();
player->SetButtons(buttonStates[0]);

if (player->HasCenterText())
if(player->menu_renderer->ShouldRenderEachTick())
player->menu_renderer->RenderMenuTick();
else if (player->HasCenterText())
player->RenderCenterText(time);

if(!pawn->m_pObserverServices()) continue;
Expand Down
195 changes: 2 additions & 193 deletions src/player/player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Player::Player(bool m_isFakeClient, int m_slot, const char* m_name, uint64 m_xui
this->language = g_Config->FetchValue<std::string>("core.language");

centerMessageEvent = g_gameEventManager->CreateEvent("show_survival_respawn_status", true);
menu_renderer = new MenuRenderer(this);

centerMessageEvent->SetUint64("duration", 1);
centerMessageEvent->SetInt("userid", this->slot);
Expand All @@ -78,18 +79,7 @@ Player::~Player()
{
this->isFakeClient = true;
g_gameEventManager->FreeEvent(centerMessageEvent);
if(menuTextID != 0) {
g_pVGUI->DeleteScreenText(menuTextID);
}
if(menuPanelID != 0) {
g_pVGUI->DeleteScreenPanel(menuPanelID);
}
if(menuFooterID != 0) {
g_pVGUI->DeleteScreenText(menuFooterID);
}
if(menuPanelExtendID != 0) {
g_pVGUI->DeleteScreenPanel(menuPanelExtendID);
}
if(menu_renderer) delete menu_renderer;
}

CBasePlayerController* Player::GetController()
Expand Down Expand Up @@ -375,187 +365,6 @@ void Player::SetButtons(uint64_t new_buttons)
}
}

bool Player::HasMenuShown() { return (this->menu != nullptr); }
Menu* Player::GetMenu() { return this->menu; }

int Player::GetPage() { return this->page; }
void Player::SetPage(int pg)
{
this->page = pg;
this->selected = 0;
this->menu->RegeneratePage(this->slot, this->page, this->selected);
this->RegenerateMenu();
}
int Player::GetSelection() { return this->selected; }
void Player::MoveSelection()
{
if (this->page == 0)
return;

int itemsPerPage = this->menu->GetItemsOnPage(this->page);
++this->selected;
if (itemsPerPage == this->selected)
this->selected = 0;

this->menu->RegeneratePage(this->slot, this->page, this->selected);
this->RegenerateMenu();
}

void Player::RegenerateMenu()
{
auto menuText = g_pVGUI->GetScreenText(menuTextID);
if(!menuText) return;

menuText->SetText(this->menu->GeneratedItems(this->slot, this->page));

auto menuFooter = g_pVGUI->GetScreenText(menuFooterID);
if(!menuFooter) return;
menuFooter->SetText(this->menu->GenerateFooter(this->page));
}

void Player::ShowMenu(std::string menuid)
{
if (this->menu != nullptr)
return;

Menu* m = g_MenuManager->FetchMenu(menuid);
if (m == nullptr)
return;

this->menu = m;
this->page = 1;
this->selected = 0;

this->menu->RegeneratePage(this->slot, this->page, this->selected);

menuTextID = g_pVGUI->RegisterScreenText();
menuPanelID = g_pVGUI->RegisterScreenPanel();
menuPanelExtendID = g_pVGUI->RegisterScreenPanel();
menuFooterID = g_pVGUI->RegisterScreenText();

auto menuText = g_pVGUI->GetScreenText(menuTextID);
auto menuPanel = g_pVGUI->GetScreenPanel(menuPanelID);
auto menuPanelExtend = g_pVGUI->GetScreenPanel(menuPanelExtendID);
auto menuFooter = g_pVGUI->GetScreenText(menuFooterID);

menuFooter->Create(Color(255,255,255,255));
menuFooter->SetupViewForPlayer(this);

menuText->Create(this->menu->GetColor());
menuText->SetupViewForPlayer(this);
RegenerateMenu();
menuText->SetPosition(0.14, 0.68);

menuFooter->SetPosition(0.14, 0.27);

menuPanel->Create(Color(18, 18, 18, 255));
menuPanel->SetupViewForPlayer(this);
menuPanel->SetText("█");
menuPanel->SetPosition(0.13, 0.7);

menuPanelExtend->Create(Color(18, 18, 18, 255));
menuPanelExtend->SetupViewForPlayer(this);
menuPanelExtend->SetText("█");
menuPanelExtend->SetPosition(0.17, 0.7);
}

void Player::HideMenu()
{
if (this->menu == nullptr)
return;

this->page = 0;
this->selected = 0;
if (this->menu->IsTemporary())
{
std::string menuID = this->menu->GetID();
g_MenuManager->UnregisterMenu(menuID);
}
this->menu = nullptr;

g_pVGUI->DeleteScreenText(menuFooterID);
g_pVGUI->DeleteScreenText(menuTextID);
g_pVGUI->DeleteScreenPanel(menuPanelID);
g_pVGUI->DeleteScreenPanel(menuPanelExtendID);

menuTextID = 0;
menuPanelID = 0;
menuFooterID = 0;
menuPanelExtendID = 0;
}

void Player::PerformMenuAction(std::string button)
{
if (!this->HasMenuShown())
return;

if (button == g_Config->FetchValue<std::string>("core.menu.buttons.scroll"))
{
CCSPlayerController* controller = this->GetPlayerController();
CSingleRecipientFilter filter(this->slot);
if (controller)
controller->EmitSoundFilter(filter, g_Config->FetchValue<std::string>("core.menu.sound.scroll.name"), 1.0, g_Config->FetchValue<double>("core.menu.sound.scroll.volume"));

this->MoveSelection();
this->RegenerateMenu();
}
else if (!g_Config->FetchValue<bool>("core.menu.buttons.exit.option") && button == g_Config->FetchValue<std::string>("core.menu.buttons.exit.button"))
{
CCSPlayerController* controller = this->GetPlayerController();
CSingleRecipientFilter filter(this->slot);
if (controller)
controller->EmitSoundFilter(filter, g_Config->FetchValue<std::string>("core.menu.sound.exit.name"), 1.0, g_Config->FetchValue<double>("core.menu.sound.exit.volume"));
this->HideMenu();
}
else if (button == g_Config->FetchValue<std::string>("core.menu.buttons.use"))
{
std::string cmd = this->GetMenu()->GetCommandFromOption(this->GetPage(), this->GetSelection());
CCSPlayerController* controller = this->GetPlayerController();
CSingleRecipientFilter filter(this->slot);
if (controller && cmd != "menuexit")
controller->EmitSoundFilter(filter, g_Config->FetchValue<std::string>("core.menu.sound.use.name"), 1.0, g_Config->FetchValue<double>("core.menu.sound.use.volume"));
if (cmd == "menunext")
{
this->SetPage(this->GetPage() + 1);
this->RegenerateMenu();
}
else if (cmd == "menuback")
{
this->SetPage(this->GetPage() - 1);
this->RegenerateMenu();
}
else if (g_Config->FetchValue<bool>("core.menu.buttons.exit.option") && cmd == "menuexit")
{
CCSPlayerController* controller = this->GetPlayerController();
CSingleRecipientFilter filter(this->slot);
if (controller)
controller->EmitSoundFilter(filter, g_Config->FetchValue<std::string>("core.menu.sound.exit.name"), 1.0, g_Config->FetchValue<double>("core.menu.sound.exit.volume"));
this->HideMenu();
}
else if (g_MenuManager->FetchMenu(cmd))
{
this->HideMenu();
this->ShowMenu(cmd);
}
else if (starts_with(cmd, "sw_"))
{
CCommand tokenizedArgs;
tokenizedArgs.Tokenize(cmd.c_str());

std::vector<std::string> cmdString = TokenizeCommand(cmd);
cmdString.erase(cmdString.begin());

std::string commandName = replace(tokenizedArgs[0], "sw_", "");

Command* cmd = g_commandsManager->FetchCommand(commandName);
if (cmd)
cmd->Execute(this->slot, cmdString, true, "sw_");
}
else if (cmd != "")
this->PerformCommand(cmd);
}
}

void Player::PerformCommand(std::string command)
{
engine->ClientCommand(this->GetSlot(), command.c_str());
Expand Down
23 changes: 2 additions & 21 deletions src/player/player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../sdk/entity/CCSPlayerPawnBase.h"
#include "../../sdk/entity/CBaseViewModel.h"
#include "../../server/menus/Menu.h"
#include "../../server/menus/MenuRenderer.h"

#include <string>
#include <public/mathlib/vector.h>
Expand Down Expand Up @@ -82,19 +83,6 @@ class Player

bool HasCenterText();

void ShowMenu(std::string menuid);
void HideMenu();
bool HasMenuShown();
Menu* GetMenu();
void RegenerateMenu();

int GetPage();
void SetPage(int pg);
int GetSelection();
void MoveSelection();

void PerformMenuAction(std::string button);

void PerformCommand(std::string command);

void SetClientConvar(std::string cmd, std::string val);
Expand All @@ -112,6 +100,7 @@ class Player
CPlayerBitVec m_selfMutes[64] = {};

std::string language = "";
MenuRenderer* menu_renderer = nullptr;

private:
int slot;
Expand All @@ -130,14 +119,6 @@ class Player

bool firstSpawn = true;

Menu* menu = nullptr;
int page = 0;
int selected = 0;
uint64_t menuTextID = 0;
uint64_t menuFooterID = 0;
uint64_t menuPanelID = 0;
uint64_t menuPanelExtendID = 0;

uint64_t buttons = 0;

std::map<std::string, std::any> internalVars;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/core/scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ class PluginMenus
public:
PluginMenus(std::string m_plugin_name);

void Register(std::string custom_id, std::string title, std::string color, std::vector<std::pair<std::string, std::string>> options);
void RegisterTemporary(std::string custom_id, std::string title, std::string color, std::vector<std::pair<std::string, std::string>> options);
void Register(std::string custom_id, std::string title, std::string color, std::vector<std::pair<std::string, std::string>> options, std::optional<std::string> okind);
void RegisterTemporary(std::string custom_id, std::string title, std::string color, std::vector<std::pair<std::string, std::string>> options, std::optional<std::string> okind);
void Unregister(std::string id);
};

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/scripting/engine/gameevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void OnClientKeyStateChange(int playerid, std::string key, bool pressed)
if (!player)
return;

player->PerformMenuAction(key);
player->menu_renderer->PerformMenuAction(key);
}

if (noReturnEvent == nullptr) noReturnEvent = new PluginEvent("core", nullptr, nullptr);
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/core/scripting/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ void PluginPlayer::HideMenu()
if (!player)
return;

if (!player->HasMenuShown())
if (!player->menu_renderer->HasMenuShown())
return;

player->HideMenu();
player->menu_renderer->HideMenu();
}

bool PluginPlayer::IsFakeClient()
Expand Down Expand Up @@ -331,10 +331,10 @@ void PluginPlayer::ShowMenu(std::string menuid)
if (!player)
return;

if (player->HasMenuShown())
if (player->menu_renderer->HasMenuShown())
return;

player->ShowMenu(menuid);
player->menu_renderer->ShowMenu(menuid);
}

void PluginPlayer::SwitchTeam(int team)
Expand Down Expand Up @@ -469,12 +469,12 @@ void PluginPlayer::PerformMenuAction(std::string action, int value)
if (!self) return;

if(action == "useOption") {
while(self->GetSelection() != value-1)
self->MoveSelection();
while(self->menu_renderer->GetSelection() != value-1)
self->menu_renderer->MoveSelection();

self->PerformMenuAction(g_Config->FetchValue<std::string>("core.menu.buttons.use"));
self->menu_renderer->PerformMenuAction(g_Config->FetchValue<std::string>("core.menu.buttons.use"));
} else if(action == "scrollToOption") {
while(self->GetSelection() != value-1)
self->MoveSelection();
while(self->menu_renderer->GetSelection() != value-1)
self->menu_renderer->MoveSelection();
}
}
Loading
Loading